Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ impl<T: Clone + Integer> Ord for Ratio<T> {

// 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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down