Skip to content

Commit e10ca81

Browse files
committed
Fix #49
1 parent 5e04dfc commit e10ca81

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,9 @@ impl<T: Clone + Integer> Ord for Ratio<T> {
385385

386386
// With equal numerators, the denominators can be inversely compared
387387
if self.numer == other.numer {
388+
if T::is_zero(self.numer()) {
389+
return cmp::Ordering::Equal;
390+
}
388391
let ord = self.denom.cmp(&other.denom);
389392
return if self.numer < T::zero() {
390393
ord
@@ -1446,6 +1449,9 @@ mod test {
14461449

14471450
assert!(_0 >= _0 && _1 >= _1);
14481451
assert!(_1 >= _0 && !(_0 >= _1));
1452+
1453+
let _0_2: Rational = Ratio::new_raw(0, 2);
1454+
assert_eq!(_0, _0_2);
14491455
}
14501456

14511457
#[test]
@@ -1538,7 +1544,7 @@ mod test {
15381544

15391545
mod arith {
15401546
use super::super::{Ratio, Rational};
1541-
use super::{_0, _1, _1_2, _2, _3_2, _NEG1_2, to_big};
1547+
use super::{to_big, _0, _1, _1_2, _2, _3_2, _NEG1_2};
15421548
use traits::{CheckedAdd, CheckedDiv, CheckedMul, CheckedSub};
15431549

15441550
#[test]

0 commit comments

Comments
 (0)