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
22 changes: 21 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::fmt;
use std::io;
use std::mem;
use unreachable::unreachable;
use num_traits::Float;
use num_traits::{Bounded, Float};

// masks for the parts of the IEEE 754 float
const SIGN_MASK: u64 = 0x8000000000000000u64;
Expand Down Expand Up @@ -137,6 +137,16 @@ impl<T: Float> DerefMut for OrderedFloat<T> {

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

impl<T: Float> Bounded for OrderedFloat<T> {
fn min_value() -> Self {
OrderedFloat(T::min_value())
}

fn max_value() -> Self {
OrderedFloat(T::max_value())
}
}

/// A wrapper around Floats providing an implementation of Ord and Hash.
///
/// A NaN value cannot be stored in this type.
Expand Down Expand Up @@ -516,6 +526,16 @@ impl<T: Float> Neg for NotNaN<T> {
}
}

impl<T: Float> Bounded for NotNaN<T> {
fn min_value() -> Self {
NotNaN(T::min_value())
}

fn max_value() -> Self {
NotNaN(T::max_value())
}
}

/// An error indicating an attempt to construct NotNaN from a NaN
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct FloatIsNaN;
Expand Down