diff options
Diffstat (limited to 'src/libnum')
| -rw-r--r-- | src/libnum/bigint.rs | 41 | ||||
| -rw-r--r-- | src/libnum/rational.rs | 6 |
2 files changed, 9 insertions, 38 deletions
diff --git a/src/libnum/bigint.rs b/src/libnum/bigint.rs index 5716a1dedf3..89ad2b5d1bc 100644 --- a/src/libnum/bigint.rs +++ b/src/libnum/bigint.rs @@ -92,15 +92,11 @@ pub struct BigUint { impl Eq for BigUint { #[inline] - fn eq(&self, other: &BigUint) -> bool { self.equals(other) } -} - -impl TotalEq for BigUint { - #[inline] - fn equals(&self, other: &BigUint) -> bool { + fn eq(&self, other: &BigUint) -> bool { match self.cmp(other) { Equal => true, _ => false } } } +impl TotalEq for BigUint {} impl Ord for BigUint { #[inline] @@ -852,31 +848,9 @@ fn get_radix_base(radix: uint) -> (uint, uint) { } /// A Sign is a `BigInt`'s composing element. -#[deriving(Eq, Clone, Show)] +#[deriving(Eq, Ord, TotalEq, TotalOrd, Clone, Show)] pub enum Sign { Minus, Zero, Plus } -impl Ord for Sign { - #[inline] - fn lt(&self, other: &Sign) -> bool { - match self.cmp(other) { Less => true, _ => false} - } -} - -impl TotalEq for Sign { - #[inline] - fn equals(&self, other: &Sign) -> bool { *self == *other } -} -impl TotalOrd for Sign { - #[inline] - fn cmp(&self, other: &Sign) -> Ordering { - match (*self, *other) { - (Minus, Minus) | (Zero, Zero) | (Plus, Plus) => Equal, - (Minus, Zero) | (Minus, Plus) | (Zero, Plus) => Less, - _ => Greater - } - } -} - impl Neg<Sign> for Sign { /// Negate Sign value. #[inline] @@ -898,16 +872,13 @@ pub struct BigInt { impl Eq for BigInt { #[inline] - fn eq(&self, other: &BigInt) -> bool { self.equals(other) } -} - -impl TotalEq for BigInt { - #[inline] - fn equals(&self, other: &BigInt) -> bool { + fn eq(&self, other: &BigInt) -> bool { match self.cmp(other) { Equal => true, _ => false } } } +impl TotalEq for BigInt {} + impl Ord for BigInt { #[inline] fn lt(&self, other: &BigInt) -> bool { diff --git a/src/libnum/rational.rs b/src/libnum/rational.rs index a71674c4122..6fb3d492432 100644 --- a/src/libnum/rational.rs +++ b/src/libnum/rational.rs @@ -147,20 +147,20 @@ macro_rules! cmp_impl { cmp_impl!(impl $imp, $($method -> bool),+) }; // return something other than a Ratio<T> - (impl $imp:ident, $($method:ident -> $res:ty),+) => { + (impl $imp:ident, $($method:ident -> $res:ty),*) => { impl<T: Mul<T,T> + $imp> $imp for Ratio<T> { $( #[inline] fn $method(&self, other: &Ratio<T>) -> $res { (self.numer * other.denom). $method (&(self.denom*other.numer)) } - )+ + )* } }; } cmp_impl!(impl Eq, eq, ne) -cmp_impl!(impl TotalEq, equals) cmp_impl!(impl Ord, lt, gt, le, ge) +cmp_impl!(impl TotalEq, ) cmp_impl!(impl TotalOrd, cmp -> cmp::Ordering) /* Arithmetic */ |
