Skip to main content

Numeric

Trait Numeric 

Source
pub trait Numeric:
    Copy
    + Clone
    + PartialEq
    + PartialOrd
    + Debug
    + Add<Output = Self>
    + Sub<Output = Self>
    + Mul<Output = Self>
    + Div<Output = Self>
    + Neg<Output = Self>
    + AddAssign
    + SubAssign
    + MulAssign
    + DivAssign {
    const ZERO: Self;
    const ONE: Self;
    const TWO: Self;
    const HALF: Self;
    const PI: Self;
    const EPSILON: Self;
    const NAN: Self;
    const INFINITY: Self;
    const NEG_INFINITY: Self;
    const MAX: Self;
    const MIN_POSITIVE: Self;
Show 29 methods // Required methods fn from_f64(value: f64) -> Self; fn from_u64(value: u64) -> Self; fn from_usize(value: usize) -> Self; fn abs(self) -> Self; fn sqrt(self) -> Self; fn sin(self) -> Self; fn cos(self) -> Self; fn tan(self) -> Self; fn exp(self) -> Self; fn ln(self) -> Self; fn atan2(self, other: Self) -> Self; fn copysign(self, sign: Self) -> Self; fn floor(self) -> Self; fn is_nan(self) -> bool; fn is_finite(self) -> bool; // Provided methods fn signum(self) -> Self { ... } fn max(self, other: Self) -> Self { ... } fn min(self, other: Self) -> Self { ... } fn atan(self) -> Self { ... } fn asin(self) -> Self { ... } fn acos(self) -> Self { ... } fn sinh(self) -> Self { ... } fn cosh(self) -> Self { ... } fn tanh(self) -> Self { ... } fn hypot(self, other: Self) -> Self { ... } fn powf(self, n: Self) -> Self { ... } fn mul_add(self, a: Self, b: Self) -> Self { ... } fn recip(self) -> Self { ... } fn powi(self, n: i32) -> Self { ... }
}
Expand description

A floating-point scalar usable by the differentiation, integration, and approximation modules. Transcendentals come from libm, so the trait works without std.

Required Associated Constants§

Source

const ZERO: Self

The value 0.

Source

const ONE: Self

The value 1.

Source

const TWO: Self

The value 2.

Source

const HALF: Self

The value 0.5.

Source

const PI: Self

Archimedes’ constant, π.

Source

const EPSILON: Self

The difference between 1 and the next larger representable value.

Source

const NAN: Self

Not a Number.

Source

const INFINITY: Self

Positive infinity.

Source

const NEG_INFINITY: Self

Negative infinity.

Source

const MAX: Self

The largest finite value.

use multicalc::Numeric;
assert_eq!(<f64 as Numeric>::MAX, f64::MAX);
Source

const MIN_POSITIVE: Self

The smallest positive normal value.

use multicalc::Numeric;
assert_eq!(<f64 as Numeric>::MIN_POSITIVE, f64::MIN_POSITIVE);

Required Methods§

Source

fn from_f64(value: f64) -> Self

Converts from f64, narrowing if necessary. Used for table values and literals.

Source

fn from_u64(value: u64) -> Self

Converts from u64, e.g. an iteration count.

Source

fn from_usize(value: usize) -> Self

Converts from usize, e.g. a point or variable count.

Source

fn abs(self) -> Self

Absolute value.

Source

fn sqrt(self) -> Self

Square root.

Source

fn sin(self) -> Self

Sine, with self in radians.

Source

fn cos(self) -> Self

Cosine, with self in radians.

Source

fn tan(self) -> Self

Tangent, with self in radians.

Source

fn exp(self) -> Self

e raised to the power self.

Source

fn ln(self) -> Self

Natural logarithm of self.

Source

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

Four-quadrant arctangent of self / other, in radians, taking self as the y coordinate and other as the x coordinate. Result in (-π, π].

Source

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

A value with the magnitude of self and the sign of sign.

Source

fn floor(self) -> Self

The largest integer less than or equal to self.

A step function, so its derivative is zero everywhere it is differentiable; the dual implementations therefore carry a zero derivative.

Source

fn is_nan(self) -> bool

Returns true if self is NaN.

Source

fn is_finite(self) -> bool

Returns true if self is neither infinite nor NaN.

Provided Methods§

Source

fn signum(self) -> Self

Sign of self: 1 for positive, -1 for negative, 0 at zero.

The derivative is zero wherever it is defined. This default maps NaN and both zeros to 0; the f32/f64 impls override to match the primitive signum (NaN maps to NaN, signed zeros are preserved).

Source

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

The larger of self and other, compared with >.

On the autodiff scalars this selects the larger operand together with its full derivative payload. The f32/f64 impls override to match the primitive max, which returns the non-NaN operand.

Source

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

The smaller of self and other, compared with <.

On the autodiff scalars this selects the smaller operand together with its full derivative payload. The f32/f64 impls override to match the primitive min, which returns the non-NaN operand.

Source

fn atan(self) -> Self

Arctangent, in radians.

Source

fn asin(self) -> Self

Arcsine, in radians, for self in [-1, 1].

Source

fn acos(self) -> Self

Arccosine, in radians, for self in [-1, 1].

Source

fn sinh(self) -> Self

Hyperbolic sine.

Source

fn cosh(self) -> Self

Hyperbolic cosine.

Source

fn tanh(self) -> Self

Hyperbolic tangent.

Source

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

Euclidean distance √(self² + other²), scaled to avoid overflow and underflow.

Source

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

self raised to a floating-point power, via exp(n · ln self). Defined for self > 0; the f32/f64 impls override for negative bases and edge cases.

Source

fn mul_add(self, a: Self, b: Self) -> Self

self * a + b. The f32/f64 impls fuse the operation for extra precision.

Source

fn recip(self) -> Self

The reciprocal 1 / self.

Source

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

self raised to an integer power, by exponentiation-by-squaring.

The zero exponent gives Numeric::ONE; a negative exponent inverts the result. Built from * and / alone, so any Numeric (including a dual number) gets a correct derivative without overriding this method.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Numeric for f32

Source§

const ZERO: Self = 0.0

Source§

const ONE: Self = 1.0

Source§

const TWO: Self = 2.0

Source§

const HALF: Self = 0.5

Source§

const PI: Self = core::f32::consts::PI

Source§

const EPSILON: Self = f32::EPSILON

Source§

const NAN: Self = f32::NAN

Source§

const INFINITY: Self = f32::INFINITY

Source§

const NEG_INFINITY: Self = f32::NEG_INFINITY

Source§

const MAX: Self = f32::MAX

Source§

const MIN_POSITIVE: Self = f32::MIN_POSITIVE

Source§

fn from_f64(value: f64) -> Self

Source§

fn from_u64(value: u64) -> Self

Source§

fn from_usize(value: usize) -> Self

Source§

fn abs(self) -> Self

Source§

fn sqrt(self) -> Self

Source§

fn sin(self) -> Self

Source§

fn cos(self) -> Self

Source§

fn tan(self) -> Self

Source§

fn exp(self) -> Self

Source§

fn ln(self) -> Self

Source§

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

Source§

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

Source§

fn floor(self) -> Self

Source§

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

Source§

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

Source§

fn signum(self) -> Self

Source§

fn atan(self) -> Self

Source§

fn asin(self) -> Self

Source§

fn acos(self) -> Self

Source§

fn sinh(self) -> Self

Source§

fn cosh(self) -> Self

Source§

fn tanh(self) -> Self

Source§

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

Source§

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

Source§

fn mul_add(self, a: Self, b: Self) -> Self

Source§

fn recip(self) -> Self

Source§

fn is_nan(self) -> bool

Source§

fn is_finite(self) -> bool

Source§

impl Numeric for f64

Source§

const ZERO: Self = 0.0

Source§

const ONE: Self = 1.0

Source§

const TWO: Self = 2.0

Source§

const HALF: Self = 0.5

Source§

const PI: Self = core::f64::consts::PI

Source§

const EPSILON: Self = f64::EPSILON

Source§

const NAN: Self = f64::NAN

Source§

const INFINITY: Self = f64::INFINITY

Source§

const NEG_INFINITY: Self = f64::NEG_INFINITY

Source§

const MAX: Self = f64::MAX

Source§

const MIN_POSITIVE: Self = f64::MIN_POSITIVE

Source§

fn from_f64(value: f64) -> Self

Source§

fn from_u64(value: u64) -> Self

Source§

fn from_usize(value: usize) -> Self

Source§

fn abs(self) -> Self

Source§

fn sqrt(self) -> Self

Source§

fn sin(self) -> Self

Source§

fn cos(self) -> Self

Source§

fn tan(self) -> Self

Source§

fn exp(self) -> Self

Source§

fn ln(self) -> Self

Source§

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

Source§

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

Source§

fn floor(self) -> Self

Source§

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

Source§

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

Source§

fn signum(self) -> Self

Source§

fn atan(self) -> Self

Source§

fn asin(self) -> Self

Source§

fn acos(self) -> Self

Source§

fn sinh(self) -> Self

Source§

fn cosh(self) -> Self

Source§

fn tanh(self) -> Self

Source§

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

Source§

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

Source§

fn mul_add(self, a: Self, b: Self) -> Self

Source§

fn recip(self) -> Self

Source§

fn is_nan(self) -> bool

Source§

fn is_finite(self) -> bool

Implementors§

Source§

impl<T: Numeric, const N: usize> Numeric for Jet<T, N>

Source§

const ZERO: Self

Source§

const ONE: Self

Source§

const TWO: Self

Source§

const HALF: Self

Source§

const PI: Self

Source§

const EPSILON: Self

Source§

const NAN: Self

Source§

const INFINITY: Self

Source§

const NEG_INFINITY: Self

Source§

const MAX: Self

Source§

const MIN_POSITIVE: Self

Source§

impl<T: Numeric> Numeric for Dual<T>

Source§

const ZERO: Self

Source§

const ONE: Self

Source§

const TWO: Self

Source§

const HALF: Self

Source§

const PI: Self

Source§

const EPSILON: Self

Source§

const NAN: Self

Source§

const INFINITY: Self

Source§

const NEG_INFINITY: Self

Source§

const MAX: Self

Source§

const MIN_POSITIVE: Self

Source§

impl<T: Numeric> Numeric for HyperDual<T>

Source§

const ZERO: Self

Source§

const ONE: Self

Source§

const TWO: Self

Source§

const HALF: Self

Source§

const PI: Self

Source§

const EPSILON: Self

Source§

const NAN: Self

Source§

const INFINITY: Self

Source§

const NEG_INFINITY: Self

Source§

const MAX: Self

Source§

const MIN_POSITIVE: Self