devela::num

Trait ExtFloat

Source
pub trait ExtFloat: ExtFloatConst + Sized {
Show 67 methods // Required methods fn floor(self) -> Self; fn ceil(self) -> Self; fn round(self) -> Self; fn round_ties_away(self) -> Self; fn round_ties_even(self) -> Self; fn round_ties_odd(self) -> Self; fn trunc(self) -> Self; fn fract(self) -> Self; fn split(self) -> (Self, Self) ; fn abs(self) -> Self; fn neg_abs(self) -> Self; fn sign(self) -> Sign; fn sign_nonzero(self) -> Sign; fn signum(self) -> Self; fn flip_sign(self) -> Self; fn is_sign_positive(self) -> bool; fn is_sign_negative(self) -> bool; fn is_zero(self) -> bool; fn is_sign_positive_nonzero(self) -> bool; fn is_sign_negative_nonzero(self) -> bool; fn copysign(self, sign: Self) -> Self; fn mul_add(self, mul: Self, add: Self) -> Self; fn div_euclid(self, rhs: Self) -> Self; fn rem_euclid(self, rhs: Self) -> Self; fn scale(self, min: Self, max: Self, u: Self, v: Self) -> Self; fn lerp(self, u: Self, v: Self) -> Self; fn powf(self, y: Self) -> Self; fn powi(self, p: i32) -> Self; fn sqrt(self) -> Self; fn sqrt_fisr(self) -> Self; fn fisr(self) -> Self; fn cbrt(self) -> Self; fn hypot(self, rhs: Self) -> Self; fn exp(self) -> Self; fn exp2(self) -> Self; fn exp_m1(self) -> Self; fn ln(self) -> Self; fn ln_1p(self) -> Self; fn log(self, base: Self) -> Self; fn log2(self) -> Self; fn log10(self) -> Self; fn factorial(n: u32) -> Self; fn sin(self) -> Self; fn cos(self) -> Self; fn sin_cos(self) -> (Self, Self) ; fn tan(self) -> Self; fn asin(self) -> Self; fn acos(self) -> Self; fn atan(self) -> Self; fn atan2(self, other: Self) -> Self; fn sinh(self) -> Self; fn cosh(self) -> Self; fn tanh(self) -> Self; fn asinh(self) -> Self; fn acosh(self) -> Self; fn atanh(self) -> Self; fn clamp_nan(self, min: Self, max: Self) -> Self; fn max_nan(self, other: Self) -> Self; fn min_nan(self, other: Self) -> Self; fn clamp_total(self, min: Self, max: Self) -> Self; fn max_total(self, other: Self) -> Self; fn min_total(self, other: Self) -> Self; fn eval_poly(self, coefficients: &[Self]) -> Self; fn derivative<F>(f: F, x: Self, h: Self) -> Self where F: Fn(Self) -> Self; fn integrate<F>(f: F, x: Self, y: Self, n: usize) -> Self where F: Fn(Self) -> Self; fn partial_derivative_x<F>(f: F, x: Self, y: Self, h: Self) -> Self where F: Fn(Self, Self) -> Self; fn partial_derivative_y<F>(f: F, x: Self, y: Self, h: Self) -> Self where F: Fn(Self, Self) -> Self;
}
Expand description

Extension trait for floating-point types. Associated methods.

This trait can be more convenient to use than the Float struct, for non-const operations over primitive floating-point types.

§Features

It depends on having any _float_f[32|64] features enabled.

Float has a few more methods implemented if the dep_libm feature is enabled.

Required Methods§

Source

fn floor(self) -> Self

The largest integer less than or equal to self.

§Formula

$$ \large \lfloor x \rfloor = \max { n \in \mathbb{Z} ,|, n \leq x } $$

Source

fn ceil(self) -> Self

The smallest integer greater than or equal to self.

§Formula

$$ $$ \lceil x \rceil = \min { n \in \mathbb{Z} ,|, n \geq x } $$

Source

fn round(self) -> Self

The nearest integer to self, default rounding, same as round_ties_away

Source

fn round_ties_away(self) -> Self

The nearest integer to self, rounding ties away from 0.0.

§Formula

$$ \text{round\_ties\_away}(x) = \begin{cases} \lceil x \rceil, & \text{if } x - \lfloor x \rfloor > 0.5 \text{ or } (x - \lfloor x \rfloor = 0.5 \text{ and } x > 0) \cr \lfloor x \rfloor, & \text{if } x - \lfloor x \rfloor < 0.5 \text{ or } (x - \lfloor x \rfloor = 0.5 \text{ and } x < 0) \end{cases} $$

Source

fn round_ties_even(self) -> Self

The nearest integer to self, rounding ties to the nearest even integer.

§Formula

$$ \text{round\_ties\_even}(x) = \begin{cases} \lceil x \rceil, & \text{if } x - \lfloor x \rfloor > 0.5 \cr \lfloor x \rfloor, & \text{if } x - \lfloor x \rfloor < 0.5 \cr \lfloor x \rfloor, & \text{if } x - \lfloor x \rfloor = 0.5 \text{ and } \lfloor x \rfloor \text{ is even} \cr \lceil x \rceil, & \text{if } x - \lfloor x \rfloor = 0.5 \text{ and } \lfloor x \rfloor \text{ is odd} \end{cases} $$

Source

fn round_ties_odd(self) -> Self

The nearest integer to self, rounding ties to the nearest odd integer.

§Formula

$$ \text{round\_ties\_odd}(x) = \begin{cases} \lceil x \rceil, & \text{if } x - \lfloor x \rfloor > 0.5 \cr \lfloor x \rfloor, & \text{if } x - \lfloor x \rfloor < 0.5 \cr \lfloor x \rfloor, & \text{if } x - \lfloor x \rfloor = 0.5 \text{ and } \lfloor x \rfloor \text{ is odd} \cr \lceil x \rceil, & \text{if } x - \lfloor x \rfloor = 0.5 \text{ and } \lfloor x \rfloor \text{ is even} \end{cases} $$

Source

fn trunc(self) -> Self

The integral part of self.

§Formula

$$ \text{trunc}(x) = \begin{cases} \lfloor x \rfloor, & \text{if } x \geq 0 \ \lceil x \rceil, & \text{if } x < 0 \end{cases} $$

Source

fn fract(self) -> Self

The fractional part of self.

§Formula

$$ \text{fract}(x) = x - \text{trunc}(x) $$

Source

fn split(self) -> (Self, Self)

The integral and fractional parts ox self.

§Formula

$$ \text{split}(x) = (\text{trunc}(x), \text{fract}(x)) $$

Source

fn abs(self) -> Self

The absolute value of self.

Source

fn neg_abs(self) -> Self

The negative absolute value of self.

Source

fn sign(self) -> Sign

Returns the Sign of self.

Source

fn sign_nonzero(self) -> Sign

Returns the Sign of self, except for zero.

Source

fn signum(self) -> Self

A number that represents the sign of self.

Source

fn flip_sign(self) -> Self

Flips the sign of self.

Source

fn is_sign_positive(self) -> bool

Returns true if self has a positive sign.

Source

fn is_sign_negative(self) -> bool

Returns true if self has a negative sign.

Source

fn is_zero(self) -> bool

Returns true if self is either 0.0 or -0.0.

Source

fn is_sign_positive_nonzero(self) -> bool

Returns true if self has a positive sign and is not zero.

Source

fn is_sign_negative_nonzero(self) -> bool

Returns true if self has a negative sign and is not zero.

Source

fn copysign(self, sign: Self) -> Self

A number composed of a magnitude of self and the sign of sign.

Source

fn mul_add(self, mul: Self, add: Self) -> Self

Fused multiply-add. Computes (self * mul) + add with only one rounding error.

With either std or dep_libm enabled it leverages compiler intrinsics, otherwise it uses mul_add_fallback.

Source

fn div_euclid(self, rhs: Self) -> Self

The euclidean division.

Source

fn rem_euclid(self, rhs: Self) -> Self

The least nonnegative remainder of self % rhs.

Source

fn scale(self, min: Self, max: Self, u: Self, v: Self) -> Self

Returns self between [min..=max] scaled to a new range [u..=v].

Values of self outside [min..=max] are not clamped and will result in extrapolation.

§Formula

$$ \large \text{scale}(x, min, max, u, v) = (v - u) \frac{x - min}{max - min} + u $$

Source

fn lerp(self, u: Self, v: Self) -> Self

Calculates a linearly interpolated value between u..=v based on the percentage self between [0..=1].

Values of self outside [0..=1] are not clamped and will result in extrapolation.

§Formula

$$ \large \text{lerp}(x, u, v) = (1 - x) \cdot u + x \cdot v $$

Source

fn powf(self, y: Self) -> Self

Raises self to the y floating point power.

With either std or dep_libm enabled it leverages compiler intrinsics, otherwise it’s equal to powf_series.

Source

fn powi(self, p: i32) -> Self

Raises self to the p integer power.

Source

fn sqrt(self) -> Self

The square root.

With either std or dep_libm enabled it leverages compiler intrinsics, otherwise it’s equal to sqrt_nr.

Source

fn sqrt_fisr(self) -> Self

The square root calculated using the fast inverse square root algorithm.

Source

fn fisr(self) -> Self

$ 1 / \sqrt{x} $ the fast inverse square root algorithm.

Source

fn cbrt(self) -> Self

The cubic root.

With either std or dep_libm enabled it leverages compiler intrinsics, otherwise it’s equal to cbrt_nr.

Source

fn hypot(self, rhs: Self) -> Self

The hypothenuse (the euclidean distance).

With either std or dep_libm enabled it leverages compiler intrinsics, otherwise it’s equal to hypot_nr.

Source

fn exp(self) -> Self

$e^x$ (the exponential function).

The maximum values with a representable result are: 88.722… for f32 and 709.782… for f64.

With both std and dep_libm disabled it leverages exp_series with exp_series_terms.

Source

fn exp2(self) -> Self

$2^x$.

With both std and dep_libm disabled it leverages exp2_series with exp2_series_terms.

Source

fn exp_m1(self) -> Self

The exponential minus 1, more accurately.

With both std and dep_libm disabled it leverages exp_m1_series with exp_series_terms.

Source

fn ln(self) -> Self

The natural logarithm of self.

With both std and dep_libm disabled it leverages ln_series with ln_series_terms.

Source

fn ln_1p(self) -> Self

The natural logarithm of self plus 1, more accurately.

With both std and dep_libm disabled it leverages ln_1p_series with ln_series_terms.

Source

fn log(self, base: Self) -> Self

The logarithm of self with respect to an arbitrary base.

With both std and dep_libm disabled it leverages log_series with ln_series_terms.

Source

fn log2(self) -> Self

The base 2 logarithm of self.

With both std and dep_libm disabled it leverages log2_series with ln_series_terms.

Source

fn log10(self) -> Self

The base 10 logarithm of self.

With both std and dep_libm disabled it leverages log10_series with ln_series_terms.

Source

fn factorial(n: u32) -> Self

The factorial.

The maximum values with a representable result are: 34 for f32 and 170 for f64.

Source

fn sin(self) -> Self

The sine.

With both std and dep_libm disabled it leverages sin_series with 8 terms.

Source

fn cos(self) -> Self

The cosine.

With both std and dep_libm disabled it leverages cos_series with 8 terms.

Source

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

Both the sine and cosine.

With both std and dep_libm disabled it leverages sin_cos_series with 8 terms.

Source

fn tan(self) -> Self

The tangent.

With both std and dep_libm disabled it leverages tan_series with 8 terms.

Source

fn asin(self) -> Self

The arc sine.

With both std and dep_libm disabled it leverages asin_series with asin_series_terms.

Source

fn acos(self) -> Self

The arc cosine.

With both std and dep_libm disabled it leverages acos_series with acos_series_terms.

Source

fn atan(self) -> Self

The arc tangent.

With both std and dep_libm disabled it leverages atan_series with atan_series_terms.

Source

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

The arc tangent of two variables.

With both std and dep_libm disabled it leverages atan2_series with atan_series_terms.

Source

fn sinh(self) -> Self

The hyperbolic sine.

With both std and dep_libm disabled it leverages sinh_series with exp_series_terms.

Source

fn cosh(self) -> Self

The hyperbolic cosine.

With both std and dep_libm disabled it leverages cosh_series with exp_series_terms.

Source

fn tanh(self) -> Self

The hyperbolic tangent.

With both std and dep_libm disabled it leverages cosh_series with exp_series_terms.

Source

fn asinh(self) -> Self

The inverse hyperbolic sine of self.

With both std and dep_libm disabled it leverages asinh_series with ln_series_terms.

Source

fn acosh(self) -> Self

The inverse hyperbolic cosine of self.

With both std and dep_libm disabled it leverages acosh_series with ln_series_terms.

Source

fn atanh(self) -> Self

The inverse hyperbolic tangent of self.

With both std and dep_libm disabled it leverages atanh_series with ln_series_terms.

Source

fn clamp_nan(self, min: Self, max: Self) -> Self

The clamped value, propagating NaN.

Source

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

The maximum of two numbers, propagating NaN.

Source

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

The minimum of two numbers, propagating NaN.

Source

fn clamp_total(self, min: Self, max: Self) -> Self

The clamped value, using total order.

§Features

This will only work if the corresponding _cmp_[f32|f64] feature is enabled, otherwise it will return NaN.

Source

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

The maximum of two numbers using total order.

§Features

This will only work if the corresponding _cmp_[f32|f64] feature is enabled, otherwise it will return NaN.

Source

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

The minimum of two numbers using total order.

§Features

This will only work if the corresponding _cmp_[f32|f64] feature is enabled, otherwise it will return NaN.

Source

fn eval_poly(self, coefficients: &[Self]) -> Self

Evaluates a polynomial at the self point value, using Horner’s method.

Source

fn derivative<F>(f: F, x: Self, h: Self) -> Self
where F: Fn(Self) -> Self,

Approximates the derivative of the 1D function f at x point using step size h.

Uses the finite difference method.

See also the [autodiff] attr macro, enabled with the nightly_autodiff feature.

Source

fn integrate<F>(f: F, x: Self, y: Self, n: usize) -> Self
where F: Fn(Self) -> Self,

Approximates the integral of the 1D function f over the range [x, y] using n subdivisions.

Uses the Riemann Sum.

Source

fn partial_derivative_x<F>(f: F, x: Self, y: Self, h: Self) -> Self
where F: Fn(Self, Self) -> Self,

Approximates the partial derivative of the 2D function f at point (x, y) with step size h, differentiating over x.

Source

fn partial_derivative_y<F>(f: F, x: Self, y: Self, h: Self) -> Self
where F: Fn(Self, Self) -> Self,

Approximates the partial derivative of the 2D function f at point (x, y) with step size h, differentiating over x.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl ExtFloat for f32

Available on crate feature _float_f32 only.
Source§

fn floor(self) -> Self

Source§

fn ceil(self) -> Self

Source§

fn round(self) -> Self

Source§

fn round_ties_away(self) -> Self

Source§

fn round_ties_even(self) -> Self

Source§

fn round_ties_odd(self) -> Self

Source§

fn trunc(self) -> Self

Source§

fn fract(self) -> Self

Source§

fn split(self) -> (Self, Self)

Source§

fn abs(self) -> Self

Source§

fn neg_abs(self) -> Self

Source§

fn sign(self) -> Sign

Source§

fn sign_nonzero(self) -> Sign

Source§

fn signum(self) -> Self

Source§

fn flip_sign(self) -> Self

Source§

fn is_sign_positive(self) -> bool

Source§

fn is_sign_negative(self) -> bool

Source§

fn is_zero(self) -> bool

Source§

fn is_sign_positive_nonzero(self) -> bool

Source§

fn is_sign_negative_nonzero(self) -> bool

Source§

fn copysign(self, sign: Self) -> Self

Source§

fn mul_add(self, mul: Self, add: Self) -> Self

Source§

fn div_euclid(self, rhs: Self) -> Self

Source§

fn rem_euclid(self, rhs: Self) -> Self

Source§

fn scale(self, min: Self, max: Self, u: Self, v: Self) -> Self

Source§

fn lerp(self, u: Self, v: Self) -> Self

Source§

fn powf(self, y: Self) -> Self

Source§

fn powi(self, p: i32) -> Self

Source§

fn sqrt(self) -> Self

Source§

fn sqrt_fisr(self) -> Self

Source§

fn fisr(self) -> Self

Source§

fn cbrt(self) -> Self

Source§

fn hypot(self, rhs: Self) -> Self

Source§

fn exp(self) -> Self

Source§

fn exp2(self) -> Self

Source§

fn exp_m1(self) -> Self

Source§

fn ln(self) -> Self

Source§

fn ln_1p(self) -> Self

Source§

fn log(self, base: Self) -> Self

Source§

fn log2(self) -> Self

Source§

fn log10(self) -> Self

Source§

fn factorial(a: u32) -> Self

Source§

fn sin(self) -> Self

Source§

fn cos(self) -> Self

Source§

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

Source§

fn tan(self) -> Self

Source§

fn asin(self) -> Self

Source§

fn acos(self) -> Self

Source§

fn atan(self) -> Self

Source§

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

Source§

fn sinh(self) -> Self

Source§

fn cosh(self) -> Self

Source§

fn tanh(self) -> Self

Source§

fn asinh(self) -> Self

Source§

fn acosh(self) -> Self

Source§

fn atanh(self) -> Self

Source§

fn clamp_nan(self, min: Self, max: Self) -> Self

Source§

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

Source§

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

Source§

fn clamp_total(self, min: Self, max: Self) -> Self

Source§

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

Source§

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

Source§

fn eval_poly(self, coefficients: &[Self]) -> Self

Source§

fn derivative<F>(f: F, x: Self, h: Self) -> Self
where F: Fn(Self) -> Self,

Source§

fn integrate<F>(f: F, x: Self, y: Self, n: usize) -> Self
where F: Fn(Self) -> Self,

Source§

fn partial_derivative_x<F>(f: F, x: Self, y: Self, h: Self) -> Self
where F: Fn(Self, Self) -> Self,

Source§

fn partial_derivative_y<F>(f: F, x: Self, y: Self, h: Self) -> Self
where F: Fn(Self, Self) -> Self,

Source§

impl ExtFloat for f64

Available on crate feature _float_f64 only.
Source§

fn floor(self) -> Self

Source§

fn ceil(self) -> Self

Source§

fn round(self) -> Self

Source§

fn round_ties_away(self) -> Self

Source§

fn round_ties_even(self) -> Self

Source§

fn round_ties_odd(self) -> Self

Source§

fn trunc(self) -> Self

Source§

fn fract(self) -> Self

Source§

fn split(self) -> (Self, Self)

Source§

fn abs(self) -> Self

Source§

fn neg_abs(self) -> Self

Source§

fn sign(self) -> Sign

Source§

fn sign_nonzero(self) -> Sign

Source§

fn signum(self) -> Self

Source§

fn flip_sign(self) -> Self

Source§

fn is_sign_positive(self) -> bool

Source§

fn is_sign_negative(self) -> bool

Source§

fn is_zero(self) -> bool

Source§

fn is_sign_positive_nonzero(self) -> bool

Source§

fn is_sign_negative_nonzero(self) -> bool

Source§

fn copysign(self, sign: Self) -> Self

Source§

fn mul_add(self, mul: Self, add: Self) -> Self

Source§

fn div_euclid(self, rhs: Self) -> Self

Source§

fn rem_euclid(self, rhs: Self) -> Self

Source§

fn scale(self, min: Self, max: Self, u: Self, v: Self) -> Self

Source§

fn lerp(self, u: Self, v: Self) -> Self

Source§

fn powf(self, y: Self) -> Self

Source§

fn powi(self, p: i32) -> Self

Source§

fn sqrt(self) -> Self

Source§

fn sqrt_fisr(self) -> Self

Source§

fn fisr(self) -> Self

Source§

fn cbrt(self) -> Self

Source§

fn hypot(self, rhs: Self) -> Self

Source§

fn exp(self) -> Self

Source§

fn exp2(self) -> Self

Source§

fn exp_m1(self) -> Self

Source§

fn ln(self) -> Self

Source§

fn ln_1p(self) -> Self

Source§

fn log(self, base: Self) -> Self

Source§

fn log2(self) -> Self

Source§

fn log10(self) -> Self

Source§

fn factorial(a: u32) -> Self

Source§

fn sin(self) -> Self

Source§

fn cos(self) -> Self

Source§

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

Source§

fn tan(self) -> Self

Source§

fn asin(self) -> Self

Source§

fn acos(self) -> Self

Source§

fn atan(self) -> Self

Source§

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

Source§

fn sinh(self) -> Self

Source§

fn cosh(self) -> Self

Source§

fn tanh(self) -> Self

Source§

fn asinh(self) -> Self

Source§

fn acosh(self) -> Self

Source§

fn atanh(self) -> Self

Source§

fn clamp_nan(self, min: Self, max: Self) -> Self

Source§

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

Source§

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

Source§

fn clamp_total(self, min: Self, max: Self) -> Self

Source§

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

Source§

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

Source§

fn eval_poly(self, coefficients: &[Self]) -> Self

Source§

fn derivative<F>(f: F, x: Self, h: Self) -> Self
where F: Fn(Self) -> Self,

Source§

fn integrate<F>(f: F, x: Self, y: Self, n: usize) -> Self
where F: Fn(Self) -> Self,

Source§

fn partial_derivative_x<F>(f: F, x: Self, y: Self, h: Self) -> Self
where F: Fn(Self, Self) -> Self,

Source§

fn partial_derivative_y<F>(f: F, x: Self, y: Self, h: Self) -> Self
where F: Fn(Self, Self) -> Self,

Implementors§