diff options
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/num/bigint.rs | 4 | ||||
| -rw-r--r-- | src/libstd/num/rational.rs | 18 |
2 files changed, 20 insertions, 2 deletions
diff --git a/src/libstd/num/bigint.rs b/src/libstd/num/bigint.rs index 3ea94eababb..e97b3b5eeec 100644 --- a/src/libstd/num/bigint.rs +++ b/src/libstd/num/bigint.rs @@ -428,7 +428,7 @@ impl Integer for BigUint { /// Returns `true` if the number can be divided by `other` without leaving a remainder #[inline(always)] - fn divisible_by(&self, other: &BigUint) -> bool { (*self % *other).is_zero() } + fn is_multiple_of(&self, other: &BigUint) -> bool { (*self % *other).is_zero() } /// Returns `true` if the number is divisible by `2` #[inline(always)] @@ -973,7 +973,7 @@ impl Integer for BigInt { /// Returns `true` if the number can be divided by `other` without leaving a remainder #[inline(always)] - fn divisible_by(&self, other: &BigInt) -> bool { self.data.divisible_by(&other.data) } + fn is_multiple_of(&self, other: &BigInt) -> bool { self.data.is_multiple_of(&other.data) } /// Returns `true` if the number is divisible by `2` #[inline(always)] diff --git a/src/libstd/num/rational.rs b/src/libstd/num/rational.rs index 34308988fa5..a7c170c1cd6 100644 --- a/src/libstd/num/rational.rs +++ b/src/libstd/num/rational.rs @@ -203,6 +203,9 @@ impl<T: Copy + Num + Ord> } } +impl<T: Copy + Num + Ord> + Num for Ratio<T> {} + /* Utils */ impl<T: Copy + Num + Ord> Round for Ratio<T> { @@ -242,6 +245,12 @@ impl<T: Copy + Num + Ord> } } +impl<T: Copy + Num + Ord> Fractional for Ratio<T> { + #[inline] + fn recip(&self) -> Ratio<T> { + Ratio::new_raw(self.denom, self.numer) + } +} /* String conversions */ impl<T: ToStr> ToStr for Ratio<T> { @@ -447,6 +456,15 @@ mod test { } #[test] + fn test_recip() { + assert_eq!(_1 * _1.recip(), _1); + assert_eq!(_2 * _2.recip(), _1); + assert_eq!(_1_2 * _1_2.recip(), _1); + assert_eq!(_3_2 * _3_2.recip(), _1); + assert_eq!(_neg1_2 * _neg1_2.recip(), _1); + } + + #[test] fn test_to_from_str() { fn test(r: Rational, s: ~str) { assert_eq!(FromStr::from_str(s), Some(r)); |
