Struct ordered_float::NotNan [−][src]
#[repr(transparent)]pub struct NotNan<T>(_);
Expand description
A wrapper around floats providing an implementation of Eq, Ord and Hash.
A NaN value cannot be stored in this type.
use ordered_float::NotNan; let mut v = [ NotNan::new(2.0).unwrap(), NotNan::new(1.0).unwrap(), ]; v.sort(); assert_eq!(v, [1.0, 2.0]);
Because NotNan implements Ord and Eq, it can be used as a key in a HashSet,
HashMap, BTreeMap, or BTreeSet (unlike the primitive f32 or f64 types):
let mut s: HashSet<NotNan<f32>> = HashSet::new(); let key = NotNan::new(1.0).unwrap(); s.insert(key); assert!(s.contains(&key));
Arithmetic on NotNan values will panic if it produces a NaN value:
let a = NotNan::new(std::f32::INFINITY).unwrap(); let b = NotNan::new(std::f32::NEG_INFINITY).unwrap(); // This will panic: let c = a + b;
Implementations
impl<T: Float> NotNan<T>[src]
impl<T: Float> NotNan<T>[src]pub fn new(val: T) -> Result<Self, FloatIsNan>[src]
pub fn new(val: T) -> Result<Self, FloatIsNan>[src]Create a NotNan value.
Returns Err if val is NaN
impl<T> NotNan<T>[src]
impl<T> NotNan<T>[src]pub fn into_inner(self) -> T[src]
pub fn into_inner(self) -> T[src]Get the value out.
pub const unsafe fn new_unchecked(val: T) -> Self[src]
pub const unsafe fn new_unchecked(val: T) -> Self[src]Create a NotNan value from a value that is guaranteed to not be NaN
Safety
Behaviour is undefined if val is NaN
pub const unsafe fn unchecked_new(val: T) -> Self[src]
👎 Deprecated since 2.5.0: Please use the new_unchecked function instead.
pub const unsafe fn unchecked_new(val: T) -> Self[src]Please use the new_unchecked function instead.
Create a NotNan value from a value that is guaranteed to not be NaN
Safety
Behaviour is undefined if val is NaN
Trait Implementations
impl<T: Float> Add<T> for NotNan<T>[src]
impl<T: Float> Add<T> for NotNan<T>[src]Adds a float directly.
Panics if the provided value is NaN or the computation results in NaN
impl<T: Float + AddAssign> AddAssign<&'_ NotNan<T>> for NotNan<T>[src]
impl<T: Float + AddAssign> AddAssign<&'_ NotNan<T>> for NotNan<T>[src]fn add_assign(&mut self, other: &Self)[src]
fn add_assign(&mut self, other: &Self)[src]Performs the += operation. Read more
impl<T: Float + AddAssign> AddAssign<&'_ T> for NotNan<T>[src]
impl<T: Float + AddAssign> AddAssign<&'_ T> for NotNan<T>[src]fn add_assign(&mut self, other: &T)[src]
fn add_assign(&mut self, other: &T)[src]Performs the += operation. Read more
impl<T: Float + AddAssign> AddAssign<NotNan<T>> for NotNan<T>[src]
impl<T: Float + AddAssign> AddAssign<NotNan<T>> for NotNan<T>[src]fn add_assign(&mut self, other: Self)[src]
fn add_assign(&mut self, other: Self)[src]Performs the += operation. Read more
impl<T: Float + AddAssign> AddAssign<T> for NotNan<T>[src]
impl<T: Float + AddAssign> AddAssign<T> for NotNan<T>[src]fn add_assign(&mut self, other: T)[src]
fn add_assign(&mut self, other: T)[src]Performs the += operation. Read more
impl<T: Float> Div<T> for NotNan<T>[src]
impl<T: Float> Div<T> for NotNan<T>[src]Divides a float directly.
Panics if the provided value is NaN or the computation results in NaN
impl<T: Float + DivAssign> DivAssign<&'_ NotNan<T>> for NotNan<T>[src]
impl<T: Float + DivAssign> DivAssign<&'_ NotNan<T>> for NotNan<T>[src]fn div_assign(&mut self, other: &Self)[src]
fn div_assign(&mut self, other: &Self)[src]Performs the /= operation. Read more
impl<T: Float + DivAssign> DivAssign<&'_ T> for NotNan<T>[src]
impl<T: Float + DivAssign> DivAssign<&'_ T> for NotNan<T>[src]fn div_assign(&mut self, other: &T)[src]
fn div_assign(&mut self, other: &T)[src]Performs the /= operation. Read more
impl<T: Float + DivAssign> DivAssign<NotNan<T>> for NotNan<T>[src]
impl<T: Float + DivAssign> DivAssign<NotNan<T>> for NotNan<T>[src]fn div_assign(&mut self, other: Self)[src]
fn div_assign(&mut self, other: Self)[src]Performs the /= operation. Read more
impl<T: Float + DivAssign> DivAssign<T> for NotNan<T>[src]
impl<T: Float + DivAssign> DivAssign<T> for NotNan<T>[src]fn div_assign(&mut self, other: T)[src]
fn div_assign(&mut self, other: T)[src]Performs the /= operation. Read more
impl<T: Float + FromPrimitive> FromPrimitive for NotNan<T>[src]
impl<T: Float + FromPrimitive> FromPrimitive for NotNan<T>[src]fn from_i64(n: i64) -> Option<Self>[src]
fn from_i64(n: i64) -> Option<Self>[src]Converts an i64 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned. Read more
fn from_u64(n: u64) -> Option<Self>[src]
fn from_u64(n: u64) -> Option<Self>[src]Converts an u64 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned. Read more
fn from_isize(n: isize) -> Option<Self>[src]
fn from_isize(n: isize) -> Option<Self>[src]Converts an isize to return an optional value of this type. If the
value cannot be represented by this type, then None is returned. Read more
fn from_i8(n: i8) -> Option<Self>[src]
fn from_i8(n: i8) -> Option<Self>[src]Converts an i8 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned. Read more
fn from_i16(n: i16) -> Option<Self>[src]
fn from_i16(n: i16) -> Option<Self>[src]Converts an i16 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned. Read more
fn from_i32(n: i32) -> Option<Self>[src]
fn from_i32(n: i32) -> Option<Self>[src]Converts an i32 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned. Read more
fn from_usize(n: usize) -> Option<Self>[src]
fn from_usize(n: usize) -> Option<Self>[src]Converts a usize to return an optional value of this type. If the
value cannot be represented by this type, then None is returned. Read more
fn from_u8(n: u8) -> Option<Self>[src]
fn from_u8(n: u8) -> Option<Self>[src]Converts an u8 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned. Read more
fn from_u16(n: u16) -> Option<Self>[src]
fn from_u16(n: u16) -> Option<Self>[src]Converts an u16 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned. Read more
fn from_u32(n: u32) -> Option<Self>[src]
fn from_u32(n: u32) -> Option<Self>[src]Converts an u32 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned. Read more
fn from_f32(n: f32) -> Option<Self>[src]
fn from_f32(n: f32) -> Option<Self>[src]Converts a f32 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned. Read more
fn from_f64(n: f64) -> Option<Self>[src]
fn from_f64(n: f64) -> Option<Self>[src]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
impl<T: Float + FromStr> FromStr for NotNan<T>[src]
impl<T: Float + FromStr> FromStr for NotNan<T>[src]fn from_str(src: &str) -> Result<Self, Self::Err>[src]
fn from_str(src: &str) -> Result<Self, Self::Err>[src]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::Err>
type Err = ParseNotNanError<T::Err>The associated error which can be returned from parsing.
impl<T: Float> Mul<T> for NotNan<T>[src]
impl<T: Float> Mul<T> for NotNan<T>[src]Multiplies a float directly.
Panics if the provided value is NaN or the computation results in NaN
impl<T: Float + MulAssign> MulAssign<&'_ NotNan<T>> for NotNan<T>[src]
impl<T: Float + MulAssign> MulAssign<&'_ NotNan<T>> for NotNan<T>[src]fn mul_assign(&mut self, other: &Self)[src]
fn mul_assign(&mut self, other: &Self)[src]Performs the *= operation. Read more
impl<T: Float + MulAssign> MulAssign<&'_ T> for NotNan<T>[src]
impl<T: Float + MulAssign> MulAssign<&'_ T> for NotNan<T>[src]fn mul_assign(&mut self, other: &T)[src]
fn mul_assign(&mut self, other: &T)[src]Performs the *= operation. Read more
impl<T: Float + MulAssign> MulAssign<NotNan<T>> for NotNan<T>[src]
impl<T: Float + MulAssign> MulAssign<NotNan<T>> for NotNan<T>[src]fn mul_assign(&mut self, other: Self)[src]
fn mul_assign(&mut self, other: Self)[src]Performs the *= operation. Read more
impl<T: Float + MulAssign> MulAssign<T> for NotNan<T>[src]
impl<T: Float + MulAssign> MulAssign<T> for NotNan<T>[src]fn mul_assign(&mut self, other: T)[src]
fn mul_assign(&mut self, other: T)[src]Performs the *= operation. Read more
impl<T: Float> Num for NotNan<T>[src]
impl<T: Float> Num for NotNan<T>[src]type FromStrRadixErr = ParseNotNanError<T::FromStrRadixErr>
fn from_str_radix(src: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>[src]
fn from_str_radix(src: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>[src]Convert from a string and radix (typically 2..=36). Read more
impl<T: Float> NumCast for NotNan<T>[src]
impl<T: Float> NumCast for NotNan<T>[src]fn from<F: ToPrimitive>(n: F) -> Option<Self>[src]
fn from<F: ToPrimitive>(n: F) -> Option<Self>[src]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
impl<T: Float> Ord for NotNan<T>[src]
impl<T: Float> Ord for NotNan<T>[src]impl<T: PartialOrd> PartialOrd<NotNan<T>> for NotNan<T>[src]
impl<T: PartialOrd> PartialOrd<NotNan<T>> for NotNan<T>[src]fn partial_cmp(&self, other: &NotNan<T>) -> Option<Ordering>[src]
fn partial_cmp(&self, other: &NotNan<T>) -> Option<Ordering>[src]This method returns an ordering between self and other values if one exists. Read more
#[must_use]fn lt(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool1.0.0[src]This method tests less than (for self and other) and is used by the < operator. Read more
#[must_use]fn le(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool1.0.0[src]This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
impl<T: Float> Rem<T> for NotNan<T>[src]
impl<T: Float> Rem<T> for NotNan<T>[src]Calculates % with a float directly.
Panics if the provided value is NaN or the computation results in NaN
impl<T: Float + RemAssign> RemAssign<&'_ NotNan<T>> for NotNan<T>[src]
impl<T: Float + RemAssign> RemAssign<&'_ NotNan<T>> for NotNan<T>[src]fn rem_assign(&mut self, other: &Self)[src]
fn rem_assign(&mut self, other: &Self)[src]Performs the %= operation. Read more
impl<T: Float + RemAssign> RemAssign<&'_ T> for NotNan<T>[src]
impl<T: Float + RemAssign> RemAssign<&'_ T> for NotNan<T>[src]fn rem_assign(&mut self, other: &T)[src]
fn rem_assign(&mut self, other: &T)[src]Performs the %= operation. Read more
impl<T: Float + RemAssign> RemAssign<NotNan<T>> for NotNan<T>[src]
impl<T: Float + RemAssign> RemAssign<NotNan<T>> for NotNan<T>[src]fn rem_assign(&mut self, other: Self)[src]
fn rem_assign(&mut self, other: Self)[src]Performs the %= operation. Read more
impl<T: Float + RemAssign> RemAssign<T> for NotNan<T>[src]
impl<T: Float + RemAssign> RemAssign<T> for NotNan<T>[src]fn rem_assign(&mut self, other: T)[src]
fn rem_assign(&mut self, other: T)[src]Performs the %= operation. Read more
impl<T: Float + Signed> Signed for NotNan<T>[src]
impl<T: Float + Signed> Signed for NotNan<T>[src]fn is_positive(&self) -> bool[src]
fn is_positive(&self) -> bool[src]Returns true if the number is positive and false if the number is zero or negative.
fn is_negative(&self) -> bool[src]
fn is_negative(&self) -> bool[src]Returns true if the number is negative and false if the number is zero or positive.
impl<T: Float> Sub<T> for NotNan<T>[src]
impl<T: Float> Sub<T> for NotNan<T>[src]Subtracts a float directly.
Panics if the provided value is NaN or the computation results in NaN
impl<T: Float + SubAssign> SubAssign<&'_ NotNan<T>> for NotNan<T>[src]
impl<T: Float + SubAssign> SubAssign<&'_ NotNan<T>> for NotNan<T>[src]fn sub_assign(&mut self, other: &Self)[src]
fn sub_assign(&mut self, other: &Self)[src]Performs the -= operation. Read more
impl<T: Float + SubAssign> SubAssign<&'_ T> for NotNan<T>[src]
impl<T: Float + SubAssign> SubAssign<&'_ T> for NotNan<T>[src]fn sub_assign(&mut self, other: &T)[src]
fn sub_assign(&mut self, other: &T)[src]Performs the -= operation. Read more
impl<T: Float + SubAssign> SubAssign<NotNan<T>> for NotNan<T>[src]
impl<T: Float + SubAssign> SubAssign<NotNan<T>> for NotNan<T>[src]fn sub_assign(&mut self, other: Self)[src]
fn sub_assign(&mut self, other: Self)[src]Performs the -= operation. Read more
impl<T: Float + SubAssign> SubAssign<T> for NotNan<T>[src]
impl<T: Float + SubAssign> SubAssign<T> for NotNan<T>[src]fn sub_assign(&mut self, other: T)[src]
fn sub_assign(&mut self, other: T)[src]Performs the -= operation. Read more
impl<T: Float + Sum> Sum<NotNan<T>> for NotNan<T>[src]
impl<T: Float + Sum> Sum<NotNan<T>> for NotNan<T>[src]Adds a float directly.
Panics if the provided value is NaN.
impl<T: Float> ToPrimitive for NotNan<T>[src]
impl<T: Float> ToPrimitive for NotNan<T>[src]fn to_i64(&self) -> Option<i64>[src]
fn to_i64(&self) -> Option<i64>[src]Converts the value of self to an i64. If the value cannot be
represented by an i64, then None is returned. Read more
fn to_u64(&self) -> Option<u64>[src]
fn to_u64(&self) -> Option<u64>[src]Converts the value of self to a u64. If the value cannot be
represented by a u64, then None is returned. Read more
fn to_isize(&self) -> Option<isize>[src]
fn to_isize(&self) -> Option<isize>[src]Converts the value of self to an isize. If the value cannot be
represented by an isize, then None is returned. Read more
fn to_i8(&self) -> Option<i8>[src]
fn to_i8(&self) -> Option<i8>[src]Converts the value of self to an i8. If the value cannot be
represented by an i8, then None is returned. Read more
fn to_i16(&self) -> Option<i16>[src]
fn to_i16(&self) -> Option<i16>[src]Converts the value of self to an i16. If the value cannot be
represented by an i16, then None is returned. Read more
fn to_i32(&self) -> Option<i32>[src]
fn to_i32(&self) -> Option<i32>[src]Converts the value of self to an i32. If the value cannot be
represented by an i32, then None is returned. Read more
fn to_usize(&self) -> Option<usize>[src]
fn to_usize(&self) -> Option<usize>[src]Converts the value of self to a usize. If the value cannot be
represented by a usize, then None is returned. Read more
fn to_u8(&self) -> Option<u8>[src]
fn to_u8(&self) -> Option<u8>[src]Converts the value of self to a u8. If the value cannot be
represented by a u8, then None is returned. Read more
fn to_u16(&self) -> Option<u16>[src]
fn to_u16(&self) -> Option<u16>[src]Converts the value of self to a u16. If the value cannot be
represented by a u16, then None is returned. Read more
fn to_u32(&self) -> Option<u32>[src]
fn to_u32(&self) -> Option<u32>[src]Converts the value of self to a u32. If the value cannot be
represented by a u32, then None is returned. Read more
fn to_f32(&self) -> Option<f32>[src]
fn to_f32(&self) -> Option<f32>[src]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. Read more
fn to_f64(&self) -> Option<f64>[src]
fn to_f64(&self) -> Option<f64>[src]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
impl<T: Copy> Copy for NotNan<T>[src]
impl<T: Float + PartialEq> Eq for NotNan<T>[src]
impl<T> StructuralPartialEq for NotNan<T>[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for NotNan<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for NotNan<T> where
T: Send,
T: Send,
impl<T> Sync for NotNan<T> where
T: Sync,
T: Sync,
impl<T> Unpin for NotNan<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for NotNan<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]pub fn borrow_mut(&mut self) -> &mut T[src]
pub fn borrow_mut(&mut self) -> &mut T[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone, [src]
impl<T> ToOwned for T where
T: Clone, [src]type Owned = T
type Owned = TThe resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn to_owned(&self) -> T[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)[src]
pub fn clone_into(&self, target: &mut T)[src]🔬 This is a nightly-only experimental API. (toowned_clone_into)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T> NumAssign for T where
T: Num + NumAssignOps<T>, [src]
T: Num + NumAssignOps<T>,
impl<T, Rhs> NumAssignOps<Rhs> for T where
T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>, [src]
T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>,
impl<T> NumAssignRef for T where
T: NumAssign + for<'r> NumAssignOps<&'r T>, [src]
T: NumAssign + for<'r> NumAssignOps<&'r T>,
impl<T, Rhs, Output> NumOps<Rhs, Output> for T where
T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>, [src]
T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,
impl<T> NumRef for T where
T: Num + for<'r> NumOps<&'r T, T>, [src]
T: Num + for<'r> NumOps<&'r T, T>,
impl<T, Base> RefNum<Base> for T where
T: NumOps<Base, Base> + for<'r> NumOps<&'r Base, Base>, [src]
T: NumOps<Base, Base> + for<'r> NumOps<&'r Base, Base>,