about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-08-27 15:13:30 +0000
committerbors <bors@rust-lang.org>2015-08-27 15:13:30 +0000
commitccf831769459fb1b306387e6796a0155d63eb012 (patch)
treed22daff7d6306623a89bd28f89e3b469b24f00ae /src
parent40fd4d678706af0684cee1e95304352a6ca02837 (diff)
parent4653a8b3fd69dbab366a8ec67ae9cf68dc128c43 (diff)
downloadrust-ccf831769459fb1b306387e6796a0155d63eb012.tar.gz
rust-ccf831769459fb1b306387e6796a0155d63eb012.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/libcore/ops.rs26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs
index 7c386c6c33e..3fb720ab6c8 100644
--- a/src/libcore/ops.rs
+++ b/src/libcore/ops.rs
@@ -423,7 +423,7 @@ pub trait Rem<RHS=Self> {
     fn rem(self, rhs: RHS) -> Self::Output;
 }
 
-macro_rules! rem_impl {
+macro_rules! rem_impl_integer {
     ($($t:ty)*) => ($(
         /// This operation satisfies `n % d == n - (n / d) * d`.  The
         /// result has the same sign as the left operand.
@@ -439,9 +439,28 @@ macro_rules! rem_impl {
     )*)
 }
 
-rem_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
+rem_impl_integer! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
+
+#[cfg(not(stage0))]
+macro_rules! rem_impl_float {
+    ($($t:ty)*) => ($(
+        #[stable(feature = "rust1", since = "1.0.0")]
+        impl Rem for $t {
+            type Output = $t;
+
+            #[inline]
+            fn rem(self, other: $t) -> $t { self % other }
+        }
+
+        forward_ref_binop! { impl Rem, rem for $t, $t }
+    )*)
+}
+
+#[cfg(not(stage0))]
+rem_impl_float! { f32 f64 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
+#[cfg(stage0)]
 impl Rem for f32 {
     type Output = f32;
 
@@ -463,6 +482,7 @@ impl Rem for f32 {
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
+#[cfg(stage0)]
 impl Rem for f64 {
     type Output = f64;
 
@@ -473,7 +493,9 @@ impl Rem for f64 {
     }
 }
 
+#[cfg(stage0)]
 forward_ref_binop! { impl Rem, rem for f64, f64 }
+#[cfg(stage0)]
 forward_ref_binop! { impl Rem, rem for f32, f32 }
 
 /// The `Neg` trait is used to specify the functionality of unary `-`.