Skip to content

Commit

Permalink
Silence clippy, fmt, and add missing inline directives
Browse files Browse the repository at this point in the history
  • Loading branch information
orlp committed Oct 10, 2023
1 parent 06884ae commit 71770b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,22 @@ impl<T: FloatCore> PartialOrd for OrderedFloat<T> {
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
Expand All @@ -147,7 +151,9 @@ impl<T: FloatCore> PartialOrd for OrderedFloat<T> {
}

impl<T: FloatCore> Ord for OrderedFloat<T> {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
#[allow(clippy::comparison_chain)]
if self < other {
Ordering::Less
} else if self > other {
Expand Down
5 changes: 3 additions & 2 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 71770b3

Please sign in to comment.