diff --git a/src/lib.rs b/src/lib.rs index 044d2a9..b3f4dfb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -385,6 +385,9 @@ impl Ord for Ratio { // With equal numerators, the denominators can be inversely compared if self.numer == other.numer { + if self.numer.is_zero() { + return cmp::Ordering::Equal; + } let ord = self.denom.cmp(&other.denom); return if self.numer < T::zero() { ord @@ -1446,6 +1449,9 @@ mod test { assert!(_0 >= _0 && _1 >= _1); assert!(_1 >= _0 && !(_0 >= _1)); + + let _0_2: Rational = Ratio::new_raw(0, 2); + assert_eq!(_0, _0_2); } #[test] @@ -1538,7 +1544,7 @@ mod test { mod arith { use super::super::{Ratio, Rational}; - use super::{_0, _1, _1_2, _2, _3_2, _NEG1_2, to_big}; + use super::{to_big, _0, _1, _1_2, _2, _3_2, _NEG1_2}; use traits::{CheckedAdd, CheckedDiv, CheckedMul, CheckedSub}; #[test]