Skip to content

Commit 218eb12

Browse files
committed
Correct and clarify integer division rounding docs
1 parent 1b28ffa commit 218eb12

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/libcore/num/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,15 +459,15 @@ macro_rules! int_impl {
459459
}
460460
}
461461

462-
/// Wrapping (modular) division. Computes `floor(self / other)`,
462+
/// Wrapping (modular) division. Computes `self / other`,
463463
/// wrapping around at the boundary of the type.
464464
///
465465
/// The only case where such wrapping can occur is when one
466466
/// divides `MIN / -1` on a signed type (where `MIN` is the
467467
/// negative minimal value for the type); this is equivalent
468468
/// to `-MIN`, a positive value that is too large to represent
469469
/// in the type. In such a case, this function returns `MIN`
470-
/// itself..
470+
/// itself.
471471
#[stable(feature = "num_wrapping", since = "1.2.0")]
472472
#[inline(always)]
473473
pub fn wrapping_div(self, rhs: Self) -> Self {
@@ -1031,15 +1031,15 @@ macro_rules! uint_impl {
10311031
}
10321032
}
10331033

1034-
/// Wrapping (modular) division. Computes `floor(self / other)`,
1034+
/// Wrapping (modular) division. Computes `self / other`,
10351035
/// wrapping around at the boundary of the type.
10361036
///
10371037
/// The only case where such wrapping can occur is when one
10381038
/// divides `MIN / -1` on a signed type (where `MIN` is the
10391039
/// negative minimal value for the type); this is equivalent
10401040
/// to `-MIN`, a positive value that is too large to represent
10411041
/// in the type. In such a case, this function returns `MIN`
1042-
/// itself..
1042+
/// itself.
10431043
#[stable(feature = "num_wrapping", since = "1.2.0")]
10441044
#[inline(always)]
10451045
pub fn wrapping_div(self, rhs: Self) -> Self {

src/libcore/ops.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ mul_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
315315

316316
/// The `Div` trait is used to specify the functionality of `/`.
317317
///
318+
/// For primitive integral types, this operation rounds towards zero,
319+
/// truncating any fractional part of the exact result.
320+
///
318321
/// # Examples
319322
///
320323
/// A trivial implementation of `Div`. When `Foo / Foo` happens, it ends up
@@ -369,6 +372,9 @@ div_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
369372

370373
/// The `Rem` trait is used to specify the functionality of `%`.
371374
///
375+
/// For primitive integral types, this operation satisfies `n % d == n
376+
/// - (n / d) * d`. The result has the same sign as the left operand.
377+
///
372378
/// # Examples
373379
///
374380
/// A trivial implementation of `Rem`. When `Foo % Foo` happens, it ends up

0 commit comments

Comments
 (0)