Skip to content

Commit

Permalink
Clarify division truncates toward zero. Fixes #2856.
Browse files Browse the repository at this point in the history
  • Loading branch information
carols10cents committed Sep 16, 2022
1 parent 453d2db commit f575259
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() {

// division
let quotient = 56.7 / 32.2;
let floored = 2 / 3; // Results in 0
let truncated = -5 / 3; // Results in -1

// remainder
let remainder = 43 % 5;
Expand Down
6 changes: 3 additions & 3 deletions src/ch03-02-data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ Floating-point numbers are represented according to the IEEE-754 standard. The

#### Numeric Operations

Rust supports the basic mathematical operations you’d expect for all of the
number types: addition, subtraction, multiplication, division, and remainder.
Integer division rounds down to the nearest integer. The following code shows
Rust supports the basic mathematical operations you’d expect for all the number
types: addition, subtraction, multiplication, division, and remainder. Integer
division truncates toward zero to the nearest integer. The following code shows
how you’d use each numeric operation in a `let` statement:

<span class="filename">Filename: src/main.rs</span>
Expand Down

0 comments on commit f575259

Please sign in to comment.