Skip to content

Commit dd2e244

Browse files
authored
Merge pull request #1073 from notriddle/patch-1
Add note about the sign of the remainder
2 parents f65652f + 0b7f340 commit dd2e244

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/expressions/operator-expr.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,18 @@ The operands of all of these operators are evaluated in [value expression contex
192192
| `-` | Subtraction | | Subtraction | `std::ops::Sub` | `std::ops::SubAssign` |
193193
| `*` | Multiplication | | Multiplication | `std::ops::Mul` | `std::ops::MulAssign` |
194194
| `/` | Division* | | Division | `std::ops::Div` | `std::ops::DivAssign` |
195-
| `%` | Remainder | | Remainder | `std::ops::Rem` | `std::ops::RemAssign` |
195+
| `%` | Remainder** | | Remainder | `std::ops::Rem` | `std::ops::RemAssign` |
196196
| `&` | Bitwise AND | [Logical AND] | | `std::ops::BitAnd` | `std::ops::BitAndAssign` |
197197
| <code>&#124;</code> | Bitwise OR | [Logical OR] | | `std::ops::BitOr` | `std::ops::BitOrAssign` |
198198
| `^` | Bitwise XOR | [Logical XOR] | | `std::ops::BitXor` | `std::ops::BitXorAssign` |
199199
| `<<` | Left Shift | | | `std::ops::Shl` | `std::ops::ShlAssign` |
200-
| `>>` | Right Shift** | | | `std::ops::Shr` | `std::ops::ShrAssign` |
200+
| `>>` | Right Shift*** | | | `std::ops::Shr` | `std::ops::ShrAssign` |
201201

202202
\* Integer division rounds towards zero.
203203

204-
\*\* Arithmetic right shift on signed integer types, logical right shift on
204+
\*\* Rust uses a remainder defined with [truncating division](https://en.wikipedia.org/wiki/Modulo_operation#Variants_of_the_definition). Given `remainder = dividend % divisor`, the remainder will have the same sign as the dividend.
205+
206+
\*\*\* Arithmetic right shift on signed integer types, logical right shift on
205207
unsigned integer types.
206208

207209
Here are examples of these operators being used.

0 commit comments

Comments
 (0)