Struct ordered_float::NotNan

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

A wrapper around Floats providing an implementation of Ord and Hash.

A NaN value cannot be stored in this type.

Implementations§

source§

impl<T: Float> NotNan<T>

source

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

Create a NotNan value.

Returns Err if val is NaN

source

pub unsafe fn unchecked_new(val: T) -> Self

Create a NotNan value from a value that is guaranteed to not be NaN

Behaviour is undefined if val is NaN

source

pub fn into_inner(self) -> T

Get the value out.

Trait Implementations§

source§

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

Adds two NotNans.

Panics if the computation results in NaN

§

type Output = NotNan<T>

The resulting type after applying the + operator.
source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
source§

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

Adds a float directly.

Panics if the provided value is NaN or the computation results in NaN

§

type Output = NotNan<T>

The resulting type after applying the + operator.
source§

fn add(self, other: T) -> Self

Performs the + operation. Read more
source§

impl<T: Float + AddAssign> AddAssign<NotNan<T>> for NotNan<T>

source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
source§

impl<T: Float + AddAssign> AddAssign<T> for NotNan<T>

Adds a float directly.

Panics if the provided value is NaN.

source§

fn add_assign(&mut self, other: T)

Performs the += operation. Read more
source§

impl<T: Float> AsRef<T> for NotNan<T>

source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<T: Float> Bounded for NotNan<T>

source§

fn min_value() -> Self

Returns the smallest finite number this type can represent
source§

fn max_value() -> Self

Returns the largest finite number this type can represent
source§

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

source§

fn clone(&self) -> NotNan<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 NotNan<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 NotNan<T>

source§

fn default() -> NotNan<T>

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

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

§

type Target = T

The resulting type after dereferencing.
source§

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

Dereferences the value.
source§

impl<T: Float + Display> Display for NotNan<T>

source§

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

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

impl<T: Float> Div<NotNan<T>> for NotNan<T>

§

type Output = NotNan<T>

The resulting type after applying the / operator.
source§

fn div(self, other: Self) -> Self

Performs the / operation. Read more
source§

impl<T: Float> Div<T> for NotNan<T>

Divides a float directly.

Panics if the provided value is NaN or the computation results in NaN

§

type Output = NotNan<T>

The resulting type after applying the / operator.
source§

fn div(self, other: T) -> Self

Performs the / operation. Read more
source§

impl<T: Float + DivAssign> DivAssign<NotNan<T>> for NotNan<T>

source§

fn div_assign(&mut self, other: Self)

Performs the /= operation. Read more
source§

impl<T: Float + DivAssign> DivAssign<T> for NotNan<T>

Divides a float directly.

Panics if the provided value is NaN or the computation results in NaN

source§

fn div_assign(&mut self, other: T)

Performs the /= operation. Read more
source§

impl From<NotNan<f32>> for f32

source§

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

Converts to this type from the input type.
source§

impl From<NotNan<f64>> for f64

source§

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

Converts to this type from the input type.
source§

impl<T: Float> From<T> for NotNan<T>

Creates a NotNan value from a Float.

Panics if the provided value is NaN or the computation results in NaN

source§

fn from(v: T) -> Self

Converts to this type from the input type.
source§

impl<T: Float + FromPrimitive> FromPrimitive for NotNan<T>

source§

fn from_i64(n: i64) -> Option<Self>

Converts an i64 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
source§

fn from_u64(n: u64) -> Option<Self>

Converts an u64 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
source§

fn from_isize(n: isize) -> Option<Self>

Converts an isize to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
source§

fn from_i8(n: i8) -> Option<Self>

Converts an i8 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
source§

fn from_i16(n: i16) -> Option<Self>

Converts an i16 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
source§

fn from_i32(n: i32) -> Option<Self>

Converts an i32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
source§

fn from_usize(n: usize) -> Option<Self>

Converts a usize to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
source§

fn from_u8(n: u8) -> Option<Self>

Converts an u8 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
source§

fn from_u16(n: u16) -> Option<Self>

Converts an u16 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
source§

fn from_u32(n: u32) -> Option<Self>

Converts an u32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
source§

fn from_f32(n: f32) -> Option<Self>

Converts a f32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
source§

fn from_f64(n: f64) -> Option<Self>

Converts a f64 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more
source§

fn from_i128(n: i128) -> Option<Self>

Converts an i128 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more
source§

fn from_u128(n: u128) -> Option<Self>

Converts an u128 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more
source§

impl<T: Float + FromStr> FromStr for NotNan<T>

source§

fn from_str(src: &str) -> Result<Self, Self::Err>

Convert a &str to NotNan. Returns an error if the string fails to parse, or if the resulting value is NaN

use ordered_float::NotNan;

assert!("-10".parse::<NotNan<f32>>().is_ok());
assert!("abc".parse::<NotNan<f32>>().is_err());
assert!("NaN".parse::<NotNan<f32>>().is_err());
§

type Err = ParseNotNanError<<T as FromStr>::Err>

The associated error which can be returned from parsing.
source§

impl<T: Float> Hash for NotNan<T>

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> Mul<NotNan<T>> for NotNan<T>

§

type Output = NotNan<T>

The resulting type after applying the * operator.
source§

fn mul(self, other: Self) -> Self

Performs the * operation. Read more
source§

impl<T: Float> Mul<T> for NotNan<T>

Multiplies a float directly.

Panics if the provided value is NaN or the computation results in NaN

§

type Output = NotNan<T>

The resulting type after applying the * operator.
source§

fn mul(self, other: T) -> Self

Performs the * operation. Read more
source§

impl<T: Float + MulAssign> MulAssign<NotNan<T>> for NotNan<T>

source§

fn mul_assign(&mut self, other: Self)

Performs the *= operation. Read more
source§

impl<T: Float + MulAssign> MulAssign<T> for NotNan<T>

Multiplies a float directly.

Panics if the provided value is NaN.

source§

fn mul_assign(&mut self, other: T)

Performs the *= operation. Read more
source§

impl<T: Float> Neg for NotNan<T>

§

type Output = NotNan<T>

The resulting type after applying the - operator.
source§

fn neg(self) -> Self

Performs the unary - operation. Read more
source§

impl<T: Float> Num for NotNan<T>

§

type FromStrRadixErr = ParseNotNanError<<T as Num>::FromStrRadixErr>

source§

fn from_str_radix(src: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>

Convert from a string and radix (typically 2..=36). Read more
source§

impl<T: Float> NumCast for NotNan<T>

source§

fn from<F: ToPrimitive>(n: F) -> Option<Self>

Creates a number from another value that can be converted into a primitive via the ToPrimitive trait. If the source value cannot be represented by the target type, then None is returned. Read more
source§

impl<T: Float> One for NotNan<T>

source§

fn one() -> Self

Returns the multiplicative identity element of Self, 1. Read more
source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
source§

fn is_one(&self) -> boolwhere Self: PartialEq<Self>,

Returns true if self is equal to the multiplicative identity. Read more
source§

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

source§

fn cmp(&self, other: &NotNan<T>) -> 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<NotNan<T>> for NotNan<T>

source§

fn eq(&self, other: &NotNan<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<NotNan<T>> for NotNan<T>

source§

fn partial_cmp(&self, other: &NotNan<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<'a, T: Float + Product> Product<&'a NotNan<T>> for NotNan<T>

source§

fn product<I: Iterator<Item = &'a NotNan<T>>>(iter: I) -> Self

Method which takes an iterator and generates Self from the elements by multiplying the items.
source§

impl<T: Float + Product> Product<NotNan<T>> for NotNan<T>

source§

fn product<I: Iterator<Item = NotNan<T>>>(iter: I) -> Self

Method which takes an iterator and generates Self from the elements by multiplying the items.
source§

impl<T: Float> Rem<NotNan<T>> for NotNan<T>

§

type Output = NotNan<T>

The resulting type after applying the % operator.
source§

fn rem(self, other: Self) -> Self

Performs the % operation. Read more
source§

impl<T: Float> Rem<T> for NotNan<T>

Calculates % with a float directly.

Panics if the provided value is NaN or the computation results in NaN

§

type Output = NotNan<T>

The resulting type after applying the % operator.
source§

fn rem(self, other: T) -> Self

Performs the % operation. Read more
source§

impl<T: Float + RemAssign> RemAssign<NotNan<T>> for NotNan<T>

source§

fn rem_assign(&mut self, other: Self)

Performs the %= operation. Read more
source§

impl<T: Float + RemAssign> RemAssign<T> for NotNan<T>

Calculates %= with a float directly.

Panics if the provided value is NaN or the computation results in NaN

source§

fn rem_assign(&mut self, other: T)

Performs the %= operation. Read more
source§

impl<T: Float + Signed> Signed for NotNan<T>

source§

fn abs(&self) -> Self

Computes the absolute value. Read more
source§

fn abs_sub(&self, other: &Self) -> Self

The positive difference of two numbers. Read more
source§

fn signum(&self) -> Self

Returns the sign of the number. Read more
source§

fn is_positive(&self) -> bool

Returns true if the number is positive and false if the number is zero or negative.
source§

fn is_negative(&self) -> bool

Returns true if the number is negative and false if the number is zero or positive.
source§

impl<T: Float> Sub<NotNan<T>> for NotNan<T>

§

type Output = NotNan<T>

The resulting type after applying the - operator.
source§

fn sub(self, other: Self) -> Self

Performs the - operation. Read more
source§

impl<T: Float> Sub<T> for NotNan<T>

Subtracts a float directly.

Panics if the provided value is NaN or the computation results in NaN

§

type Output = NotNan<T>

The resulting type after applying the - operator.
source§

fn sub(self, other: T) -> Self

Performs the - operation. Read more
source§

impl<T: Float + SubAssign> SubAssign<NotNan<T>> for NotNan<T>

source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more
source§

impl<T: Float + SubAssign> SubAssign<T> for NotNan<T>

Subtracts a float directly.

Panics if the provided value is NaN or the computation results in NaN

source§

fn sub_assign(&mut self, other: T)

Performs the -= operation. Read more
source§

impl<'a, T: Float + Sum> Sum<&'a NotNan<T>> for NotNan<T>

source§

fn sum<I: Iterator<Item = &'a NotNan<T>>>(iter: I) -> Self

Method which takes an iterator and generates Self from the elements by “summing up” the items.
source§

impl<T: Float + Sum> Sum<NotNan<T>> for NotNan<T>

source§

fn sum<I: Iterator<Item = NotNan<T>>>(iter: I) -> Self

Method which takes an iterator and generates Self from the elements by “summing up” the items.
source§

impl<T: Float> ToPrimitive for NotNan<T>

source§

fn to_i64(&self) -> Option<i64>

Converts the value of self to an i64. If the value cannot be represented by an i64, then None is returned.
source§

fn to_u64(&self) -> Option<u64>

Converts the value of self to a u64. If the value cannot be represented by a u64, then None is returned.
source§

fn to_isize(&self) -> Option<isize>

Converts the value of self to an isize. If the value cannot be represented by an isize, then None is returned.
source§

fn to_i8(&self) -> Option<i8>

Converts the value of self to an i8. If the value cannot be represented by an i8, then None is returned.
source§

fn to_i16(&self) -> Option<i16>

Converts the value of self to an i16. If the value cannot be represented by an i16, then None is returned.
source§

fn to_i32(&self) -> Option<i32>

Converts the value of self to an i32. If the value cannot be represented by an i32, then None is returned.
source§

fn to_usize(&self) -> Option<usize>

Converts the value of self to a usize. If the value cannot be represented by a usize, then None is returned.
source§

fn to_u8(&self) -> Option<u8>

Converts the value of self to a u8. If the value cannot be represented by a u8, then None is returned.
source§

fn to_u16(&self) -> Option<u16>

Converts the value of self to a u16. If the value cannot be represented by a u16, then None is returned.
source§

fn to_u32(&self) -> Option<u32>

Converts the value of self to a u32. If the value cannot be represented by a u32, then None is returned.
source§

fn to_f32(&self) -> Option<f32>

Converts the value of self to an f32. Overflows may map to positive or negative inifinity, otherwise None is returned if the value cannot be represented by an f32.
source§

fn to_f64(&self) -> Option<f64>

Converts the value of self to an f64. Overflows may map to positive or negative inifinity, otherwise None is returned if the value cannot be represented by an f64. Read more
source§

fn to_i128(&self) -> Option<i128>

Converts the value of self to an i128. If the value cannot be represented by an i128 (i64 under the default implementation), then None is returned. Read more
source§

fn to_u128(&self) -> Option<u128>

Converts the value of self to a u128. If the value cannot be represented by a u128 (u64 under the default implementation), then None is returned. Read more
source§

impl<T: Float> Zero for NotNan<T>

source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
source§

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

source§

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

source§

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for NotNan<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<!> for T

source§

fn from(t: !) -> T

Converts to this type from the input type.
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> LowerBounded for Twhere T: Bounded,

source§

fn min_value() -> T

Returns the smallest finite number this type can represent
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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.
source§

impl<T> UpperBounded for Twhere T: Bounded,

source§

fn max_value() -> T

Returns the largest finite number this type can represent
source§

impl<T> NumAssign for Twhere T: Num + NumAssignOps<T>,

source§

impl<T, Rhs> NumAssignOps<Rhs> for Twhere T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>,

source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for Twhere T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,