Skip to content

Commit

Permalink
impl PartialEq<T> for NotNan<T> and OrderedFloat<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrubeck committed Jul 10, 2020
1 parent 0d683a1 commit fc9dc0c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ impl<T: Float> PartialEq for OrderedFloat<T> {
}
}

impl<T: Float> PartialEq<T> for OrderedFloat<T> {
fn eq(&self, other: &T) -> bool {
self.0 == *other
}
}

impl<T: Float> Hash for OrderedFloat<T> {
fn hash<H: Hasher>(&self, state: &mut H) {
if self.is_nan() {
Expand Down Expand Up @@ -313,6 +319,12 @@ impl<T: Float> Deref for NotNan<T> {

impl<T: Float + PartialEq> Eq for NotNan<T> {}

impl<T: Float> PartialEq<T> for NotNan<T> {
fn eq(&self, other: &T) -> bool {
self.0 == *other
}
}

/// Adds two NotNans.
///
/// Panics if the computation results in NaN
Expand Down

0 comments on commit fc9dc0c

Please sign in to comment.