From e10ca814e7b1f4d5fcc42ed5e7ceb39f8443ef5c Mon Sep 17 00:00:00 2001 From: Max Blachman Date: Mon, 17 Jun 2019 07:40:53 -0700 Subject: [PATCH 1/2] Fix #49 --- src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 044d2a9..72122b7 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 T::is_zero(self.numer()) { + 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] From f38ff9cc5911752ddcb749b018bc9f7634b251fe Mon Sep 17 00:00:00 2001 From: Max Blachman Date: Wed, 17 Jul 2019 23:02:28 -0700 Subject: [PATCH 2/2] Implement @cuviper's suggested change Co-Authored-By: Josh Stone --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 72122b7..b3f4dfb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -385,7 +385,7 @@ impl Ord for Ratio { // With equal numerators, the denominators can be inversely compared if self.numer == other.numer { - if T::is_zero(self.numer()) { + if self.numer.is_zero() { return cmp::Ordering::Equal; } let ord = self.denom.cmp(&other.denom);