about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-08-21 09:31:43 -0700
committerbors <bors@rust-lang.org>2013-08-21 09:31:43 -0700
commite66478193b1ad0582cdabb5ca769a85b26ea000c (patch)
treeaaefad946232b3233fd96bfd2e01ec0140559212 /src/libstd
parentbf90634087e8f4015176d8e6be53794768d5c6ec (diff)
parentac3bc9cfcc6ac884311f9bed6853e36fd40868f4 (diff)
downloadrust-e66478193b1ad0582cdabb5ca769a85b26ea000c.tar.gz
rust-e66478193b1ad0582cdabb5ca769a85b26ea000c.zip
auto merge of #8610 : kballard/rust/mod_floor, r=alexcrichton
`mod_floor()` was incorrectly defined for uint types as `a / b` instead of `a % b`.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/num/uint_macros.rs17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs
index 2bf41f4103d..90a14503a8d 100644
--- a/src/libstd/num/uint_macros.rs
+++ b/src/libstd/num/uint_macros.rs
@@ -238,9 +238,9 @@ impl Integer for $T {
 
     /// Unsigned integer modulo operation. Returns the same result as `rem` (`%`).
     #[inline]
-    fn mod_floor(&self, other: &$T) -> $T { *self / *other }
+    fn mod_floor(&self, other: &$T) -> $T { *self % *other }
 
-    /// Calculates `div_floor` and `modulo_floor` simultaneously
+    /// Calculates `div_floor` and `mod_floor` simultaneously
     #[inline]
     fn div_mod_floor(&self, other: &$T) -> ($T,$T) {
         (*self / *other, *self % *other)
@@ -459,6 +459,19 @@ mod tests {
     }
 
     #[test]
+    fn test_div_mod_floor() {
+        assert_eq!((10 as $T).div_floor(&(3 as $T)), 3 as $T);
+        assert_eq!((10 as $T).mod_floor(&(3 as $T)), 1 as $T);
+        assert_eq!((10 as $T).div_mod_floor(&(3 as $T)), (3 as $T, 1 as $T));
+        assert_eq!((5 as $T).div_floor(&(5 as $T)), 1 as $T);
+        assert_eq!((5 as $T).mod_floor(&(5 as $T)), 0 as $T);
+        assert_eq!((5 as $T).div_mod_floor(&(5 as $T)), (1 as $T, 0 as $T));
+        assert_eq!((3 as $T).div_floor(&(7 as $T)), 0 as $T);
+        assert_eq!((3 as $T).mod_floor(&(7 as $T)), 3 as $T);
+        assert_eq!((3 as $T).div_mod_floor(&(7 as $T)), (0 as $T, 3 as $T));
+    }
+
+    #[test]
     fn test_gcd() {
         assert_eq!((10 as $T).gcd(&2), 2 as $T);
         assert_eq!((10 as $T).gcd(&3), 1 as $T);