about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorWilliam Throwe <wtt6@cornell.edu>2015-07-12 20:28:16 -0400
committerWilliam Throwe <wtt6@cornell.edu>2015-07-12 20:28:16 -0400
commit7824956effbfaccea5f6ce0b973c26cb58d241f9 (patch)
treef9239bce45d1603c74a0ecd8bcbb4fbcbe943bbd /src
parent218eb1277d95090c7db5ba0242194b497784d04e (diff)
downloadrust-7824956effbfaccea5f6ce0b973c26cb58d241f9.tar.gz
rust-7824956effbfaccea5f6ce0b973c26cb58d241f9.zip
Move rounding discussion to integer Div/Rem impls
Diffstat (limited to 'src')
-rw-r--r--src/libcore/ops.rs30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs
index 6f15a6bffa8..76d3c1df159 100644
--- a/src/libcore/ops.rs
+++ b/src/libcore/ops.rs
@@ -315,9 +315,6 @@ mul_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
 
 /// The `Div` trait is used to specify the functionality of `/`.
 ///
-/// For primitive integral types, this operation rounds towards zero,
-/// truncating any fractional part of the exact result.
-///
 /// # Examples
 ///
 /// A trivial implementation of `Div`. When `Foo / Foo` happens, it ends up
@@ -354,7 +351,25 @@ pub trait Div<RHS=Self> {
     fn div(self, rhs: RHS) -> Self::Output;
 }
 
-macro_rules! div_impl {
+macro_rules! div_impl_integer {
+    ($($t:ty)*) => ($(
+        /// This operation rounds towards zero, truncating any
+        /// fractional part of the exact result.
+        #[stable(feature = "rust1", since = "1.0.0")]
+        impl Div for $t {
+            type Output = $t;
+
+            #[inline]
+            fn div(self, other: $t) -> $t { self / other }
+        }
+
+        forward_ref_binop! { impl Div, div for $t, $t }
+    )*)
+}
+
+div_impl_integer! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
+
+macro_rules! div_impl_float {
     ($($t:ty)*) => ($(
         #[stable(feature = "rust1", since = "1.0.0")]
         impl Div for $t {
@@ -368,13 +383,10 @@ macro_rules! div_impl {
     )*)
 }
 
-div_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
+div_impl_float! { f32 f64 }
 
 /// The `Rem` trait is used to specify the functionality of `%`.
 ///
-/// For primitive integral types, this operation satisfies `n % d == n
-/// - (n / d) * d`.  The result has the same sign as the left operand.
-///
 /// # Examples
 ///
 /// A trivial implementation of `Rem`. When `Foo % Foo` happens, it ends up
@@ -413,6 +425,8 @@ pub trait Rem<RHS=Self> {
 
 macro_rules! rem_impl {
     ($($t:ty)*) => ($(
+        /// This operation satisfies `n % d == n - (n / d) * d`.  The
+        /// result has the same sign as the left operand.
         #[stable(feature = "rust1", since = "1.0.0")]
         impl Rem for $t {
             type Output = $t;