Struct CheckedFloat

Source
pub struct CheckedFloat<T: Float, C: FloatChecker<T>>(/* private fields */);
Expand description

A checked floating point type.

Every instance of CheckedFloat is guaranteed to satisfy the property given by the provided FloatChecker. In particular, this can be used to have a floating point type that forbids values like NaN, infinity, negatives, etc. all by providing different checkers.

CheckedFloat supports all the typical operations of a normal float type. However, all operations that yield another float type (e.g., add, sub, sin, etc.) instead yield a custom Result type specified by the FloatChecker.

All methods from the Float type are supported by this wrapper in checked context. For documentation, see the original method definitions in Float.

CheckedFloat also supports an implementation of Ord, which allows for directly sorting CheckedFloat collections. The convention for this implementation has ordering -NaN < -Inf < ... < -0 = +0 < ... < +Inf < +NaN.

CheckedFloat::get can be used to get the underlying float value.

Implementations§

Source§

impl<T: Float, C: FloatChecker<T>> CheckedFloat<T, C>

Source

pub fn new(value: T) -> Result<Self, C::Error>

Source

pub fn get(self) -> T

Source

pub fn classify(self) -> FpCategory

Source

pub fn integer_decode(self) -> (u64, i16, i8)

Source

pub fn is_finite(self) -> bool

Source

pub fn is_infinite(self) -> bool

Source

pub fn is_nan(self) -> bool

Source

pub fn is_normal(self) -> bool

Source

pub fn is_sign_negative(self) -> bool

Source

pub fn is_sign_positive(self) -> bool

Source

pub fn is_zero(self) -> bool

Source

pub fn is_one(self) -> bool

Source

pub fn infinity() -> Result<Self, C::Error>

Source

pub fn max_value() -> Result<Self, C::Error>

Source

pub fn min_positive_value() -> Result<Self, C::Error>

Source

pub fn min_value() -> Result<Self, C::Error>

Source

pub fn nan() -> Result<Self, C::Error>

Source

pub fn neg_infinity() -> Result<Self, C::Error>

Source

pub fn neg_zero() -> Result<Self, C::Error>

Source

pub fn zero() -> Result<Self, C::Error>

Source

pub fn one() -> Result<Self, C::Error>

Source

pub fn epsilon() -> Result<Self, C::Error>

Source

pub fn abs(self) -> Result<Self, C::Error>

Source

pub fn acos(self) -> Result<Self, C::Error>

Source

pub fn acosh(self) -> Result<Self, C::Error>

Source

pub fn asin(self) -> Result<Self, C::Error>

Source

pub fn asinh(self) -> Result<Self, C::Error>

Source

pub fn atan(self) -> Result<Self, C::Error>

Source

pub fn atanh(self) -> Result<Self, C::Error>

Source

pub fn cbrt(self) -> Result<Self, C::Error>

Source

pub fn ceil(self) -> Result<Self, C::Error>

Source

pub fn cos(self) -> Result<Self, C::Error>

Source

pub fn cosh(self) -> Result<Self, C::Error>

Source

pub fn exp(self) -> Result<Self, C::Error>

Source

pub fn exp2(self) -> Result<Self, C::Error>

Source

pub fn exp_m1(self) -> Result<Self, C::Error>

Source

pub fn floor(self) -> Result<Self, C::Error>

Source

pub fn fract(self) -> Result<Self, C::Error>

Source

pub fn ln(self) -> Result<Self, C::Error>

Source

pub fn ln_1p(self) -> Result<Self, C::Error>

Source

pub fn log10(self) -> Result<Self, C::Error>

Source

pub fn log2(self) -> Result<Self, C::Error>

Source

pub fn neg(self) -> Result<Self, C::Error>

Source

pub fn recip(self) -> Result<Self, C::Error>

Source

pub fn round(self) -> Result<Self, C::Error>

Source

pub fn signum(self) -> Result<Self, C::Error>

Source

pub fn sin(self) -> Result<Self, C::Error>

Source

pub fn sinh(self) -> Result<Self, C::Error>

Source

pub fn sqrt(self) -> Result<Self, C::Error>

Source

pub fn tan(self) -> Result<Self, C::Error>

Source

pub fn tanh(self) -> Result<Self, C::Error>

Source

pub fn trunc(self) -> Result<Self, C::Error>

Source

pub fn to_degrees(self) -> Result<Self, C::Error>

Source

pub fn to_radians(self) -> Result<Self, C::Error>

Source

pub fn abs_sub(self, other: Self) -> Result<Self, C::Error>

Source

pub fn add(self, other: Self) -> Result<Self, C::Error>

Source

pub fn atan2(self, other: Self) -> Result<Self, C::Error>

Source

pub fn div(self, other: Self) -> Result<Self, C::Error>

Source

pub fn hypot(self, other: Self) -> Result<Self, C::Error>

Source

pub fn log(self, base: Self) -> Result<Self, C::Error>

Source

pub fn mul(self, other: Self) -> Result<Self, C::Error>

Source

pub fn powf(self, n: Self) -> Result<Self, C::Error>

Source

pub fn rem(self, other: Self) -> Result<Self, C::Error>

Source

pub fn sub(self, other: Self) -> Result<Self, C::Error>

Source

pub fn copysign(self, sign: Self) -> Result<Self, C::Error>

Source

pub fn mul_add(self, a: Self, b: Self) -> Result<Self, C::Error>

Source

pub fn powi(self, n: i32) -> Result<Self, C::Error>

Source

pub fn sin_cos(self) -> (Result<Self, C::Error>, Result<Self, C::Error>)

Trait Implementations§

Source§

impl<T: Float, C: FloatChecker<T>> Clone for CheckedFloat<T, C>

Source§

fn clone(&self) -> Self

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: Float + Debug, C: FloatChecker<T>> Debug for CheckedFloat<T, C>

Source§

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

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

impl<T: Float + Display, C: FloatChecker<T>> Display for CheckedFloat<T, C>

Source§

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

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

impl<T: Float, C: FloatChecker<T>> Ord for CheckedFloat<T, C>

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) -> Self
where Self: Sized,

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

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

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

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

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

impl<T: Float, C: FloatChecker<T>> PartialEq for CheckedFloat<T, C>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Float, C: FloatChecker<T>> PartialOrd for CheckedFloat<T, C>

Source§

fn partial_cmp(&self, other: &Self) -> 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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: Float, C: FloatChecker<T>> Copy for CheckedFloat<T, C>

Source§

impl<T: Float, C: FloatChecker<T>> Eq for CheckedFloat<T, C>

Auto Trait Implementations§

§

impl<T, C> Freeze for CheckedFloat<T, C>
where T: Freeze,

§

impl<T, C> RefUnwindSafe for CheckedFloat<T, C>

§

impl<T, C> Send for CheckedFloat<T, C>
where T: Send, C: Send,

§

impl<T, C> Sync for CheckedFloat<T, C>
where T: Sync, C: Sync,

§

impl<T, C> Unpin for CheckedFloat<T, C>
where T: Unpin, C: Unpin,

§

impl<T, C> UnwindSafe for CheckedFloat<T, C>
where T: UnwindSafe, C: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.