Skip to content

Commit ccf8317

Browse files
committed
Auto merge of #28016 - ranma42:mini-rem-in-core, r=alexcrichton
The implementation of the remainder operation belongs to librustc_trans, but it is also stubbed out in libcore in order to expose it as a trait on primitive types. Instead of exposing some implementation details (like the upcast to `f64` in MSVC), use a minimal implementation just like that of the `Div` trait.
2 parents 40fd4d6 + 4653a8b commit ccf8317

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/libcore/ops.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ pub trait Rem<RHS=Self> {
423423
fn rem(self, rhs: RHS) -> Self::Output;
424424
}
425425

426-
macro_rules! rem_impl {
426+
macro_rules! rem_impl_integer {
427427
($($t:ty)*) => ($(
428428
/// This operation satisfies `n % d == n - (n / d) * d`. The
429429
/// result has the same sign as the left operand.
@@ -439,9 +439,28 @@ macro_rules! rem_impl {
439439
)*)
440440
}
441441

442-
rem_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
442+
rem_impl_integer! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
443+
444+
#[cfg(not(stage0))]
445+
macro_rules! rem_impl_float {
446+
($($t:ty)*) => ($(
447+
#[stable(feature = "rust1", since = "1.0.0")]
448+
impl Rem for $t {
449+
type Output = $t;
450+
451+
#[inline]
452+
fn rem(self, other: $t) -> $t { self % other }
453+
}
454+
455+
forward_ref_binop! { impl Rem, rem for $t, $t }
456+
)*)
457+
}
458+
459+
#[cfg(not(stage0))]
460+
rem_impl_float! { f32 f64 }
443461

444462
#[stable(feature = "rust1", since = "1.0.0")]
463+
#[cfg(stage0)]
445464
impl Rem for f32 {
446465
type Output = f32;
447466

@@ -463,6 +482,7 @@ impl Rem for f32 {
463482
}
464483

465484
#[stable(feature = "rust1", since = "1.0.0")]
485+
#[cfg(stage0)]
466486
impl Rem for f64 {
467487
type Output = f64;
468488

@@ -473,7 +493,9 @@ impl Rem for f64 {
473493
}
474494
}
475495

496+
#[cfg(stage0)]
476497
forward_ref_binop! { impl Rem, rem for f64, f64 }
498+
#[cfg(stage0)]
477499
forward_ref_binop! { impl Rem, rem for f32, f32 }
478500

479501
/// The `Neg` trait is used to specify the functionality of unary `-`.

0 commit comments

Comments
 (0)