diff --git a/src/lib.rs b/src/lib.rs index 5afa427..5a512e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -124,18 +124,22 @@ impl PartialOrd for OrderedFloat { Some(self.cmp(other)) } + #[inline] fn lt(&self, other: &Self) -> bool { - !(self >= other) + !self.ge(other) } + #[inline] fn le(&self, other: &Self) -> bool { - other >= self + other.ge(self) } + #[inline] fn gt(&self, other: &Self) -> bool { - !(other >= self) + !other.ge(self) } + #[inline] fn ge(&self, other: &Self) -> bool { // We consider all NaNs equal, and NaN is the largest possible // value. Thus if self is NaN we always return true. Otherwise @@ -147,7 +151,9 @@ impl PartialOrd for OrderedFloat { } impl Ord for OrderedFloat { + #[inline] fn cmp(&self, other: &Self) -> Ordering { + #[allow(clippy::comparison_chain)] if self < other { Ordering::Less } else if self > other { diff --git a/tests/test.rs b/tests/test.rs index 752ecbf..5626d1c 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -26,13 +26,14 @@ fn test_total_order() { let numberline = [ (-f32::INFINITY, 0), (-1.0, 1), - (-0.0, 2), (0.0, 2), + (-0.0, 2), + (0.0, 2), (1.0, 3), (f32::INFINITY, 4), (f32::NAN, 5), (-f32::NAN, 5), ]; - + for &(fi, i) in &numberline { for &(fj, j) in &numberline { assert_eq!(OrderedFloat(fi) < OrderedFloat(fj), i < j);