Finite

Struct Finite 

Source
pub struct Finite<F: IsFinite>(/* private fields */);

Implementations§

Source§

impl<F: IsFinite> Finite<F>

Source

pub fn try_new(val: F) -> Result<Self, InfiniteError>

Attempts to create a new Finite float.

§Errors

If the value is non-finite.

Source

pub const unsafe fn unchecked(val: F) -> Self

Const-safe constructor for Finite that never checks the value.

§Safety

Ensure that the value can never be infinity or NaN.

Source

pub const fn val(self) -> F

Gets the inner value of this number.

Source§

impl<F: IsFinite> Finite<F>

Source

pub fn new(val: F) -> Self

Creates a new checked float.

§Panics

If the number is non-finite. Note that this fn will not panic in release mode, unless the strict feature flag is set.

Source§

impl<F: IsFinite + ToOrd> Finite<F>

Source

pub fn max(self, other: impl IntoInner<F>) -> Self

Returns the larger of two floating point values.

Source

pub fn min(self, other: impl IntoInner<F>) -> Self

Returns the smaller of two floating point values.

Source§

impl<F: IsFinite + Round> Finite<F>

Source

pub fn floor(self) -> Self

Rounds this floating point number to the previous whole number.

Source

pub fn ceil(self) -> Self

Rounds this floating point number to the next whole number.

Source

pub fn round(self) -> Self

Rounds this floating point number to the nearest whole number.

Source

pub fn trunc(self) -> Self

Drops the fractional part of this floating point number.

Source

pub fn fract(self) -> Self

Returns the fractional part of this floating point number.

Source§

impl<F: IsFinite + Signed> Finite<F>

Source

pub fn abs(self) -> Self

Computes the absolute value of self.

Source

pub fn signum(self) -> Self

Returns a number that represents the sign of self.

  • 1.0 if the number is positive, +0.0 or INFINITY
  • -1.0 if the number is negative, -0.0 or NEG_INFINITY
Source

pub fn is_sign_negative(self) -> bool

Returns true if self has a negative sign, including -0.0 and negative infinity.

Source

pub fn is_sign_positive(self) -> bool

Returns true if self has a positive sign, including +0.0 and positive infinity.

Source§

impl<F: IsFinite> Finite<F>

Source

pub fn try_add(self, rhs: impl IntoInner<F>) -> Result<Self, InfiniteError>
where F: Add<Output = F>,

Attempts to add two numbers.

§Errors

If the result is non-finite.

Source

pub fn try_sub(self, rhs: impl IntoInner<F>) -> Result<Self, InfiniteError>
where F: Sub<Output = F>,

Attempts to subtract two numbers.

§Errors

If the result is non-finite.

Source§

impl<F: IsFinite> Finite<F>

Source

pub fn try_neg(self) -> Result<Self, InfiniteError>
where F: Neg<Output = F>,

Attempts to negate a number.

§Errors

If the result is non-finite.

Source§

impl<F: IsFinite> Finite<F>

Source

pub fn try_mul(self, rhs: impl IntoInner<F>) -> Result<Self, InfiniteError>
where F: Mul<Output = F>,

Attempts to multiply two numbers.

§Errors

If the result is non-finite.

Source

pub fn try_div(self, rhs: impl IntoInner<F>) -> Result<Self, InfiniteError>
where F: Div<Output = F>,

Attempts to divide two numbers.

§Errors

If the result is non-finite.

Source

pub fn try_rem(self, rhs: impl IntoInner<F>) -> Result<Self, InfiniteError>
where F: Rem<Output = F>,

Attempts to find the remainder of two numbers.

§Errors

If the result is non-finite.

Source§

impl<F: IsFinite + Pow> Finite<F>

Source

pub fn try_powf(self, n: impl IntoInner<F>) -> Result<Self, InfiniteError>

Attempts to raise self to the power n.

§Errors

If the result is non-finite.

Source

pub fn try_powi(self, n: i32) -> Result<Self, InfiniteError>

Attempts to raise self to the power n.

§Errors

If the result is non-finite.

Source

pub fn powf(self, n: impl IntoInner<F>) -> Self

Raises self to the power n.

§Panics

If the result is non-finite.

Source

pub fn powi(self, n: i32) -> Self

Raises self to the power n.

§Panics

If the result is non-finite.

Source

pub fn try_recip(self) -> Result<Self, InfiniteError>

Attempts to compute the reciprocal (1/x) of self.

§Errors

If the result is non-finite.

Source

pub fn recip(self) -> Self

Computes the reciprocal (1/x) of self.

§Panics

If the result is non-finite.

Source

pub fn try_sqrt(self) -> Result<Self, InfiniteError>

Attempts to find the square root of a number.

§Errors

If the result is non-finite.

Source

pub fn sqrt(self) -> Self

Computes the square root of a number.

§Panics

If the result is non-finite.

Source

pub fn cbrt(self) -> Self

Computes the cube root of a number.

Source

pub fn try_hypot(self, other: impl IntoInner<F>) -> Result<Self, InfiniteError>

Attempts to calculate the length of the hypotenuse of a right-angle triangle given legs of length x and y.

Equivalent to sqrt(x^2 + y^2).

§Errors

If the result is non-finite.

Source

pub fn hypot(self, other: impl IntoInner<F>) -> Self

Calculates the length of the hypotenuse of a right-angle triangle given legs of length x and y.

§Panics

If the result is non-finite.

Source§

impl<F: IsFinite + Exp> Finite<F>

Source

pub fn try_exp(self) -> Result<Self, InfiniteError>

Attempts to find e^(self), the exponential function.

§Errors

If the result is non-finite.

Source

pub fn try_exp2(self) -> Result<Self, InfiniteError>

Attempts to find 2^(self).

§Errors

If the result is non-finite.

Source

pub fn try_exp_m1(self) -> Result<Self, InfiniteError>

Attempts to find e^(self) - 1 in a way that is accurate even if the number is close to zero.

§Errors

If the result is non-finite.

Source

pub fn exp(self) -> Self

Computes e^(self), the exponential function.

§Panics

If the result is non-finite.

Source

pub fn exp2(self) -> Self

Computes 2^(self).

§Panics

If the result is non-finite.

Source

pub fn exp_m1(self) -> Self

Computes e^(self) - 1 more accurately than performing the operations separately.

§Panics

If the result is non-finite.

Source

pub fn try_log(self, b: impl IntoInner<F>) -> Result<Self, InfiniteError>

Attempts to find the log base b of self.

§Errors

If the result is non-finite.

Source

pub fn try_ln(self) -> Result<Self, InfiniteError>

Attempts to find the natural log (base e) of self.

§Errors

If the result is non-finite.

Source

pub fn try_log2(self) -> Result<Self, InfiniteError>

Attempts to find the log base 2 of self.

§Errors

If the result is non-finite.

Source

pub fn try_log10(self) -> Result<Self, InfiniteError>

Attempts to find the log base 10 of self.

§Errors

If the result is non-finite.

Source

pub fn try_ln_1p(self) -> Result<Self, InfiniteError>

Attempts to find ln(1+n) (natural logarithm) more accurately than if the operations were performed separately.

§Errors

If the result is non-finite.

Source

pub fn log(self, b: impl IntoInner<F>) -> Self

Computes the log base b of self.

§Panics

If the result is non-finite.

Source

pub fn ln(self) -> Self

Computes the natural log (base e) of self.

§Panics

If the result is non-finite.

Source

pub fn log2(self) -> Self

Computes the log base 2 of self.

§Panics

If the result is non-finite.

Source

pub fn log10(self) -> Self

Computes the log base 10 of self.

§Panics

If the result is non-finite.

Source

pub fn ln_1p(self) -> Self

Computes ln(1+n) (natural logarithm) more accurately than if the operations were performed separately.

§Panics

If the result is non-finite.

Source§

impl<F: IsFinite + Trig> Finite<F>

Source

pub fn sin(self) -> Self

Computes the sine of a number.

Source

pub fn cos(self) -> Self

Computes the cosine of a number.

Source

pub fn sin_cos(self) -> (Self, Self)

Computes the sine and cosine of a number simultaneously.

Source

pub fn try_tan(self) -> Result<Self, InfiniteError>

Attempts to compute the tangent of a number (in radians).

§Errors

If the result is non-finite.

Source

pub fn tan(self) -> Self

Computes the tangent of a number.

§Panics

If the result is non-finite.

Source

pub fn try_asin(self) -> Result<Self, InfiniteError>

Attempts to compute the arcsine of a number (in radians).

§Errors

If the result is non-finite (caused if the magnitude of the input exceeds 1).

Source

pub fn try_acos(self) -> Result<Self, InfiniteError>

Attempts to compute the arccosine of a number (in radians).

§Errors

If the result is non-finite (caused if the magnitude of the input exceeds 1).

Source

pub fn asin(self) -> Self

Computes the arcsine of a number.

§Panics

If the result is non-finite (caused if the magnitude of the input exceeds 1).

Source

pub fn acos(self) -> Self

Computes the arccosine of a number.

§Panics

If the result is non-finite (caused if the magnitude of the input exceeds 1).

Source

pub fn atan(self) -> Self

Computes the arctangent of a number.

Source

pub fn try_atan2(self, other: impl IntoInner<F>) -> Result<Self, InfiniteError>

Attempts to compute the four quadrant arctangent of self (y) and other (x) in radians.

§Errors

If the result is non-finite.

Source

pub fn atan2(self, other: impl IntoInner<F>) -> Self

Computes the four quadrant arctangent of self (y) and other (x) in radians.

§Panics

If the result is non-finite.

Trait Implementations§

Source§

impl<F: IsFinite + Add<Output = F>, Rhs: IntoInner<F>> Add<Rhs> for Finite<F>

Source§

type Output = Finite<F>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<F: IsFinite + Add<Output = F>, Rhs: IntoInner<F>> AddAssign<Rhs> for Finite<F>

Source§

fn add_assign(&mut self, rhs: Rhs)

Performs the += operation. Read more
Source§

impl<F: Clone + IsFinite> Clone for Finite<F>

Source§

fn clone(&self) -> Finite<F>

Returns a duplicate 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<F: Debug + IsFinite> Debug for Finite<F>

Source§

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

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

impl<F: Default + IsFinite> Default for Finite<F>

Source§

fn default() -> Finite<F>

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

impl<F: IsFinite + Div<Output = F>, Rhs: IntoInner<F>> Div<Rhs> for Finite<F>

Source§

type Output = Finite<F>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Rhs) -> Self

Performs the / operation. Read more
Source§

impl<F: IsFinite + Div<Output = F>, Rhs: IntoInner<F>> DivAssign<Rhs> for Finite<F>

Source§

fn div_assign(&mut self, rhs: Rhs)

Performs the /= operation. Read more
Source§

impl<F: IsFinite + Mul<Output = F>, Rhs: IntoInner<F>> Mul<Rhs> for Finite<F>

Source§

type Output = Finite<F>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Rhs) -> Self

Performs the * operation. Read more
Source§

impl<F: IsFinite + Mul<Output = F>, Rhs: IntoInner<F>> MulAssign<Rhs> for Finite<F>

Source§

fn mul_assign(&mut self, rhs: Rhs)

Performs the *= operation. Read more
Source§

impl<F: IsFinite + Neg<Output = F>> Neg for Finite<F>

Source§

type Output = Finite<F>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl<F: IsFinite + ToOrd> Ord for Finite<F>

Source§

fn cmp(&self, rhs: &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<F: IsFinite + ToOrd, Rhs: IntoInner<F> + Copy> PartialEq<Rhs> for Finite<F>

Source§

fn eq(&self, rhs: &Rhs) -> 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<F: IsFinite + ToOrd, Rhs: IntoInner<F> + Copy> PartialOrd<Rhs> for Finite<F>

Source§

fn partial_cmp(&self, rhs: &Rhs) -> 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<F: IsFinite + Rem<Output = F>, Rhs: IntoInner<F>> Rem<Rhs> for Finite<F>

Source§

type Output = Finite<F>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Rhs) -> Self

Performs the % operation. Read more
Source§

impl<F: IsFinite + Rem<Output = F>, Rhs: IntoInner<F>> RemAssign<Rhs> for Finite<F>

Source§

fn rem_assign(&mut self, rhs: Rhs)

Performs the %= operation. Read more
Source§

impl<F: IsFinite + Sub<Output = F>, Rhs: IntoInner<F>> Sub<Rhs> for Finite<F>

Source§

type Output = Finite<F>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Rhs) -> Self

Performs the - operation. Read more
Source§

impl<F: IsFinite + Sub<Output = F>, Rhs: IntoInner<F>> SubAssign<Rhs> for Finite<F>

Source§

fn sub_assign(&mut self, rhs: Rhs)

Performs the -= operation. Read more
Source§

impl<F: Copy + IsFinite> Copy for Finite<F>

Source§

impl<F: IsFinite + ToOrd> Eq for Finite<F>

Auto Trait Implementations§

§

impl<F> Freeze for Finite<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for Finite<F>
where F: RefUnwindSafe,

§

impl<F> Send for Finite<F>
where F: Send,

§

impl<F> Sync for Finite<F>
where F: Sync,

§

impl<F> Unpin for Finite<F>
where F: Unpin,

§

impl<F> UnwindSafe for Finite<F>
where F: 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> ToOwned for T
where T: Clone,

Source§

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 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.