#[repr(transparent)]
pub struct NonNanFloat<T: Float>(_);
Expand description

Wrapper for non-NaN floats that implements Eq and Ord.

Implementations§

source§

impl<T: Float> NonNanFloat<T>

source

pub fn try_new(val: T) -> Result<Self, FloatIsNan>

Try to wrap a float, returning an Error if the float is NaN.

source

pub fn new(val: T) -> Self

Try to wrap a float, panicking if the float is NaN.

source

pub fn into_inner(&self) -> T

Trait Implementations§

source§

impl<T: Float> Add<NonNanFloat<T>> for NonNanFloat<T>

§

type Output = NonNanFloat<T>

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
source§

impl<T: Clone + Float> Clone for NonNanFloat<T>

source§

fn clone(&self) -> NonNanFloat<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug + Float> Debug for NonNanFloat<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Default + Float> Default for NonNanFloat<T>

source§

fn default() -> NonNanFloat<T>

Returns the “default value” for a type. Read more
source§

impl<T: Float> Deref for NonNanFloat<T>

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl From<NonNanFloat<f32>> for f32

source§

fn from(value: NonNanFloat<f32>) -> Self

Converts to this type from the input type.
source§

impl From<NonNanFloat<f64>> for f64

source§

fn from(value: NonNanFloat<f64>) -> Self

Converts to this type from the input type.
source§

impl Hash for NonNanFloat<f32>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Hash for NonNanFloat<f64>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T: Float> NumInRange for NonNanFloat<T>where NonNanFloat<T>: Steppable,

source§

fn min_value() -> Self

Return the minimum possible value the number can take.
source§

fn max_value() -> Self

Return the maximum possible value the number can take.
source§

const MIN_DECR_IS_UNDERFLOW: bool = false

Whether caling Steppable::step_decr on the min value would underflow the type.
source§

const MAX_INCR_IS_OVERFLOW: bool = false

Whether caling Steppable::step_incr on the max value would overflow the type.
source§

impl<T: Float> Ord for NonNanFloat<T>

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl<T: PartialEq + Float> PartialEq<NonNanFloat<T>> for NonNanFloat<T>

source§

fn eq(&self, other: &NonNanFloat<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Float> PartialEq<T> for NonNanFloat<T>

source§

fn eq(&self, other: &T) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: PartialOrd + Float> PartialOrd<NonNanFloat<T>> for NonNanFloat<T>

source§

fn partial_cmp(&self, other: &NonNanFloat<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T: Float> PartialOrd<T> for NonNanFloat<T>

source§

fn partial_cmp(&self, other: &T) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Steppable for NonNanFloat<f32>

Considerations for stepping floating-point types:

  • Steps are performed to the next possible representable value, so the size of the step varies with the original number’s magnitude.
  • Approximations and floating-point error can lead to miniscule gaps and other unexpected behaviors. For example, 0.3-0.2-0.1=-2.7755575615628914e-17 will not be contained in a nonnegative range starting at 0.
source§

fn step_incr(&self) -> Self

Return the smallest possible value larger than the input value. Should saturate at the maximum possible value.
source§

fn step_decr(&self) -> Self

Return the largest possible value smaller than the input value. Should saturate at the minimum possible value.
source§

fn range_size<B: Borrow<Self>, R: RangeBounds<B>>( range: R ) -> Result<Self, RangeOperationError>

Return the size of the range.
source§

fn range_tuple_size<N: Borrow<Self>>( start: N, end: N ) -> Result<Self, RangeOperationError>

Functions like Self::range_size given input start..=end.
source§

impl Steppable for NonNanFloat<f64>

Considerations for stepping floating-point types:

  • Steps are performed to the next possible representable value, so the size of the step varies with the original number’s magnitude.
  • Approximations and floating-point error can lead to miniscule gaps and other unexpected behaviors. For example, 0.3-0.2-0.1=-2.7755575615628914e-17 will not be contained in a nonnegative range starting at 0.
source§

fn step_incr(&self) -> Self

Return the smallest possible value larger than the input value. Should saturate at the maximum possible value.
source§

fn step_decr(&self) -> Self

Return the largest possible value smaller than the input value. Should saturate at the minimum possible value.
source§

fn range_size<B: Borrow<Self>, R: RangeBounds<B>>( range: R ) -> Result<Self, RangeOperationError>

Return the size of the range.
source§

fn range_tuple_size<N: Borrow<Self>>( start: N, end: N ) -> Result<Self, RangeOperationError>

Functions like Self::range_size given input start..=end.
source§

impl TryFrom<f32> for NonNanFloat<f32>

§

type Error = FloatIsNan

The type returned in the event of a conversion error.
source§

fn try_from(value: f32) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<f64> for NonNanFloat<f64>

§

type Error = FloatIsNan

The type returned in the event of a conversion error.
source§

fn try_from(value: f64) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<T: Copy + Float> Copy for NonNanFloat<T>

source§

impl<T: Float> Eq for NonNanFloat<T>

source§

impl<T: Float> StructuralPartialEq for NonNanFloat<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for NonNanFloat<T>where T: RefUnwindSafe,

§

impl<T> Send for NonNanFloat<T>where T: Send,

§

impl<T> Sync for NonNanFloat<T>where T: Sync,

§

impl<T> Unpin for NonNanFloat<T>where T: Unpin,

§

impl<T> UnwindSafe for NonNanFloat<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.