Skip to content

Commit

Permalink
Merge pull request #60 from wookietreiber/topic/neg
Browse files Browse the repository at this point in the history
adds neg for ordered float
  • Loading branch information
mbrubeck committed May 20, 2019
2 parents 7723213 + 9013e4c commit 06afbc9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/lib.rs
Expand Up @@ -186,6 +186,14 @@ impl<T: Float + FromStr> FromStr for OrderedFloat<T> {
}
}

impl<T: Float> Neg for OrderedFloat<T> {
type Output = Self;

fn neg(self) -> Self {
OrderedFloat(-self.0)
}
}

/// A wrapper around Floats providing an implementation of Ord and Hash.
///
/// A NaN value cannot be stored in this type.
Expand Down
10 changes: 10 additions & 0 deletions tests/test.rs
Expand Up @@ -535,3 +535,13 @@ fn test_add_fails_on_nan() {
let b = NotNan::new(std::f32::NEG_INFINITY).unwrap();
let _c = a + b;
}

#[test]
fn ordered_f32_neg() {
assert_eq!(OrderedFloat(-7.0f32), -OrderedFloat(7.0f32));
}

#[test]
fn ordered_f64_neg() {
assert_eq!(OrderedFloat(-7.0f64), -OrderedFloat(7.0f64));
}

0 comments on commit 06afbc9

Please sign in to comment.