Skip to content

Commit 5f552a5

Browse files
committed
Auto merge of #26981 - wthrowe:div_docs, r=Gankro
This resolves #26845. I'm not entirely satisfied with the placement of the rounding discussion in the docs for the `Div` and `Rem` traits, but I couldn't come up with anywhere better to put it. Suggestions are welcome. I didn't add any discussion of rounding to the `checked_div` (or rem) or `wrapping_div` documentation because those seem to make it pretty clear that they do the same thing as `Div`.
2 parents c044791 + 7824956 commit 5f552a5

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
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: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,10 @@ pub trait Div<RHS=Self> {
351351
fn div(self, rhs: RHS) -> Self::Output;
352352
}
353353

354-
macro_rules! div_impl {
354+
macro_rules! div_impl_integer {
355355
($($t:ty)*) => ($(
356+
/// This operation rounds towards zero, truncating any
357+
/// fractional part of the exact result.
356358
#[stable(feature = "rust1", since = "1.0.0")]
357359
impl Div for $t {
358360
type Output = $t;
@@ -365,7 +367,23 @@ macro_rules! div_impl {
365367
)*)
366368
}
367369

368-
div_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
370+
div_impl_integer! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
371+
372+
macro_rules! div_impl_float {
373+
($($t:ty)*) => ($(
374+
#[stable(feature = "rust1", since = "1.0.0")]
375+
impl Div for $t {
376+
type Output = $t;
377+
378+
#[inline]
379+
fn div(self, other: $t) -> $t { self / other }
380+
}
381+
382+
forward_ref_binop! { impl Div, div for $t, $t }
383+
)*)
384+
}
385+
386+
div_impl_float! { f32 f64 }
369387

370388
/// The `Rem` trait is used to specify the functionality of `%`.
371389
///
@@ -407,6 +425,8 @@ pub trait Rem<RHS=Self> {
407425

408426
macro_rules! rem_impl {
409427
($($t:ty)*) => ($(
428+
/// This operation satisfies `n % d == n - (n / d) * d`. The
429+
/// result has the same sign as the left operand.
410430
#[stable(feature = "rust1", since = "1.0.0")]
411431
impl Rem for $t {
412432
type Output = $t;

0 commit comments

Comments
 (0)