pub trait Scalar:
Copy
+ Clone
+ Debug
+ Display
+ PartialOrd
+ Add<Output = Self>
+ Sub<Output = Self>
+ Mul<Output = Self>
+ Div<Output = Self>
+ Neg<Output = Self>
+ AddAssign
+ SubAssign
+ MulAssign
+ DivAssign
+ Sum
+ Send
+ Sync
+ 'static {
const ZERO: Self;
const ONE: Self;
const TWO: Self;
const HALF: Self;
const EPSILON: Self;
const INFINITY: Self;
const NEG_INFINITY: Self;
const NAN: Self;
const PI: Self;
const E: Self;
const SQRT_2: Self;
const LN_2: Self;
Show 55 methods
// Required methods
fn from_f64(x: f64) -> Self;
fn from_f32(x: f32) -> Self;
fn from_i32(x: i32) -> Self;
fn from_usize(n: usize) -> Self;
fn to_f64(self) -> f64;
fn to_f32(self) -> f32;
fn abs(self) -> Self;
fn sqrt(self) -> Self;
fn cbrt(self) -> Self;
fn powi(self, n: i32) -> Self;
fn powf(self, n: Self) -> Self;
fn hypot(self, other: Self) -> Self;
fn sin(self) -> Self;
fn cos(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 exp(self) -> Self;
fn exp2(self) -> Self;
fn exp_m1(self) -> Self;
fn ln(self) -> Self;
fn log2(self) -> Self;
fn log10(self) -> Self;
fn ln_1p(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 max(self, other: Self) -> Self;
fn min(self, other: Self) -> Self;
fn clamp(self, min: Self, max: Self) -> Self;
fn copysign(self, sign: Self) -> Self;
fn is_finite(self) -> bool;
fn is_nan(self) -> bool;
fn is_infinite(self) -> bool;
fn is_sign_positive(self) -> bool;
fn is_sign_negative(self) -> bool;
fn floor(self) -> Self;
fn ceil(self) -> Self;
fn round(self) -> Self;
fn trunc(self) -> Self;
fn fract(self) -> Self;
fn gamma_fn(self) -> Self;
fn ln_gamma(self) -> Self;
fn erf_fn(self) -> Self;
fn erfc_fn(self) -> Self;
fn mul_add(self, a: Self, b: Self) -> Self;
// Provided methods
fn sq(self) -> Self { ... }
fn recip(self) -> Self { ... }
fn sincos(self) -> (Self, Self) { ... }
fn signum(self) -> Self { ... }
}Expand description
A real scalar type suitable for numerical computation.
This trait provides all mathematical operations needed by numerical methods, including basic arithmetic, trigonometric functions, and special functions.
§Example
use numra_core::Scalar;
fn quadratic_formula<S: Scalar>(a: S, b: S, c: S) -> Option<(S, S)> {
let discriminant = b * b - S::from_f64(4.0) * a * c;
if discriminant < S::ZERO {
return None;
}
let sqrt_d = discriminant.sqrt();
let two_a = S::TWO * a;
Some(((-b + sqrt_d) / two_a, (-b - sqrt_d) / two_a))
}Required Associated Constants§
Sourceconst NEG_INFINITY: Self
const NEG_INFINITY: Self
Negative infinity
Required Methods§
Sourcefn from_usize(n: usize) -> Self
fn from_usize(n: usize) -> Self
Create from usize
Sourcefn is_infinite(self) -> bool
fn is_infinite(self) -> bool
Is the value infinite?
Sourcefn is_sign_positive(self) -> bool
fn is_sign_positive(self) -> bool
Is the sign positive (including +0)?
Sourcefn is_sign_negative(self) -> bool
fn is_sign_negative(self) -> bool
Is the sign negative (including -0)?
Provided Methods§
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.