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§
Sourceconst NEG_INFINITY: Self
const NEG_INFINITY: Self
Negative infinity.
Sourceconst MAX: Self
const MAX: Self
The largest finite value.
use multicalc::Numeric;
assert_eq!(<f64 as Numeric>::MAX, f64::MAX);Sourceconst MIN_POSITIVE: Self
const MIN_POSITIVE: Self
The smallest positive normal value.
use multicalc::Numeric;
assert_eq!(<f64 as Numeric>::MIN_POSITIVE, f64::MIN_POSITIVE);Required Methods§
Sourcefn from_f64(value: f64) -> Self
fn from_f64(value: f64) -> Self
Converts from f64, narrowing if necessary. Used for table values and literals.
Sourcefn from_usize(value: usize) -> Self
fn from_usize(value: usize) -> Self
Converts from usize, e.g. a point or variable count.
Sourcefn atan2(self, other: Self) -> Self
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 (-π, π].
Provided Methods§
Sourcefn signum(self) -> Self
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).
Sourcefn max(self, other: Self) -> Self
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.
Sourcefn min(self, other: Self) -> Self
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.
Sourcefn hypot(self, other: Self) -> Self
fn hypot(self, other: Self) -> Self
Euclidean distance √(self² + other²), scaled to avoid overflow and underflow.
Sourcefn powf(self, n: Self) -> Self
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.
Sourcefn mul_add(self, a: Self, b: Self) -> Self
fn mul_add(self, a: Self, b: Self) -> Self
self * a + b. The f32/f64 impls fuse the operation for extra precision.
Sourcefn powi(self, n: i32) -> Self
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".