pub trait RawScalarTrait:
Serialize
+ for<'a> Deserialize<'a>
+ Debug
+ Display
+ Clone
+ Sync
+ Send
+ Add<Output = Self>
+ Sub<Output = Self>
+ Mul<Output = Self>
+ Div<Output = Self>
+ for<'a> Add<&'a Self, Output = Self>
+ for<'a> Sub<&'a Self, Output = Self>
+ for<'a> Mul<&'a Self, Output = Self>
+ for<'a> Div<&'a Self, Output = Self>
+ AddAssign
+ SubAssign
+ MulAssign
+ DivAssign
+ for<'a> AddAssign<&'a Self>
+ for<'a> SubAssign<&'a Self>
+ for<'a> MulAssign<&'a Self>
+ for<'a> DivAssign<&'a Self>
+ Neg<Output = Self>
+ NegAssign
+ NeumaierAddable
+ PartialEq
+ FpChecks
+ 'static {
type ValidationErrors: Error;
Show 36 methods
// Required methods
fn is_zero(&self) -> bool;
fn raw_zero(precision: u32) -> Self;
fn raw_one(precision: u32) -> Self;
fn unchecked_reciprocal(self) -> Self;
fn unchecked_exp(self) -> Self;
fn unchecked_sqrt(self) -> Self;
fn unchecked_sin(self) -> Self;
fn unchecked_asin(self) -> Self;
fn unchecked_cos(self) -> Self;
fn unchecked_acos(self) -> Self;
fn unchecked_tan(self) -> Self;
fn unchecked_atan(self) -> Self;
fn unchecked_sinh(self) -> Self;
fn unchecked_asinh(self) -> Self;
fn unchecked_cosh(self) -> Self;
fn unchecked_acosh(self) -> Self;
fn unchecked_tanh(self) -> Self;
fn unchecked_atanh(self) -> Self;
fn unchecked_ln(self) -> Self;
fn unchecked_log2(self) -> Self;
fn unchecked_log10(self) -> Self;
fn unchecked_pow_exponent_i8(self, exponent: &i8) -> Self;
fn unchecked_pow_exponent_i16(self, exponent: &i16) -> Self;
fn unchecked_pow_exponent_i32(self, exponent: &i32) -> Self;
fn unchecked_pow_exponent_i64(self, exponent: &i64) -> Self;
fn unchecked_pow_exponent_i128(self, exponent: &i128) -> Self;
fn unchecked_pow_exponent_isize(self, exponent: &isize) -> Self;
fn unchecked_pow_exponent_u8(self, exponent: &u8) -> Self;
fn unchecked_pow_exponent_u16(self, exponent: &u16) -> Self;
fn unchecked_pow_exponent_u32(self, exponent: &u32) -> Self;
fn unchecked_pow_exponent_u64(self, exponent: &u64) -> Self;
fn unchecked_pow_exponent_u128(self, exponent: &u128) -> Self;
fn unchecked_pow_exponent_usize(self, exponent: &usize) -> Self;
fn unchecked_mul_add(self, b: &Self, c: &Self) -> Self;
fn compute_hash<H: Hasher>(&self, state: &mut H);
// Provided method
fn raw_negative_one(precision: u32) -> Self { ... }
}Expand description
A baseline trait for raw scalar types, defining core operations and properties.
This trait must be implemented by the underlying number types used in a kernel,
such as like f64 or rug::Float.
It provides a standard interface for arithmetic
and a suite of unchecked_* methods for mathematical functions.
§Hashing Support
All raw scalar types (both real and complex) must implement compute_hash(),
which provides a consistent hashing mechanism. The hash implementation must ensure:
- Mathematical Equality: Values that are mathematically equal produce identical hashes
- Signed Zero Handling: Both
+0.0and-0.0hash to the same value - Finite Values Only: The hash is only well-defined for finite values (not NaN or infinity)
- Consistency: The same value always produces the same hash across multiple calls
For complex numbers, the hash is computed by sequentially hashing the real and imaginary parts, ensuring that different complex numbers produce different hashes while maintaining the equality invariant.
This enables validated wrapper types to implement Hash when their validation
policies guarantee finite values (via crate::validation::GuaranteesFiniteValues),
allowing them to be used as keys in HashMap and HashSet.
§Safety and Contracts
The unchecked_* methods are designed for performance and assume that the caller
has already validated the inputs. Calling them with invalid data (e.g., unchecked_sqrt
on a negative real number) may lead to panics, incorrect results, or undefined behavior,
depending on the underlying type’s implementation.
Required Associated Types§
Sourcetype ValidationErrors: Error
type ValidationErrors: Error
The associated error type for validation failures of this raw type.
Required Methods§
fn is_zero(&self) -> bool
fn raw_zero(precision: u32) -> Self
fn raw_one(precision: u32) -> Self
Sourcefn unchecked_reciprocal(self) -> Self
fn unchecked_reciprocal(self) -> Self
Computes the reciprocal (1/x) without validation.
Contract: The caller must ensure self is not zero.
Sourcefn unchecked_exp(self) -> Self
fn unchecked_exp(self) -> Self
Computes the exponential (e^x) without validation.
Contract: The caller must ensure the input is valid.
Sourcefn unchecked_sqrt(self) -> Self
fn unchecked_sqrt(self) -> Self
Computes the square root without validation.
Contract: For real numbers, the caller must ensure self >= 0.
fn unchecked_sin(self) -> Self
fn unchecked_asin(self) -> Self
fn unchecked_cos(self) -> Self
fn unchecked_acos(self) -> Self
fn unchecked_tan(self) -> Self
fn unchecked_atan(self) -> Self
fn unchecked_sinh(self) -> Self
fn unchecked_asinh(self) -> Self
fn unchecked_cosh(self) -> Self
fn unchecked_acosh(self) -> Self
fn unchecked_tanh(self) -> Self
fn unchecked_atanh(self) -> Self
fn unchecked_ln(self) -> Self
fn unchecked_log2(self) -> Self
fn unchecked_log10(self) -> Self
Sourcefn unchecked_pow_exponent_i8(self, exponent: &i8) -> Self
fn unchecked_pow_exponent_i8(self, exponent: &i8) -> Self
Raises self to the power of an i8 exponent without validation.
Contract: The caller must ensure the inputs are valid.
Sourcefn unchecked_pow_exponent_i16(self, exponent: &i16) -> Self
fn unchecked_pow_exponent_i16(self, exponent: &i16) -> Self
Raises self to the power of an i16 exponent without validation.
Contract: The caller must ensure the inputs are valid.
Sourcefn unchecked_pow_exponent_i32(self, exponent: &i32) -> Self
fn unchecked_pow_exponent_i32(self, exponent: &i32) -> Self
Raises self to the power of an i32 exponent without validation.
Contract: The caller must ensure the inputs are valid.
Sourcefn unchecked_pow_exponent_i64(self, exponent: &i64) -> Self
fn unchecked_pow_exponent_i64(self, exponent: &i64) -> Self
Raises self to the power of an i64 exponent without validation.
Contract: The caller must ensure the inputs are valid. For integer powers, this
includes ensuring the exponent is within the representable range of the underlying
power function (e.g., i32 for f64::powi).
Sourcefn unchecked_pow_exponent_i128(self, exponent: &i128) -> Self
fn unchecked_pow_exponent_i128(self, exponent: &i128) -> Self
Raises self to the power of an i128 exponent without validation.
Contract: The caller must ensure the inputs are valid. For integer powers, this
includes ensuring the exponent is within the representable range of the underlying
power function (e.g., i32 for f64::powi).
Sourcefn unchecked_pow_exponent_isize(self, exponent: &isize) -> Self
fn unchecked_pow_exponent_isize(self, exponent: &isize) -> Self
Raises self to the power of an isize exponent without validation.
Contract: The caller must ensure the inputs are valid. For integer powers, this
includes ensuring the exponent is within the representable range of the underlying
power function (e.g., i32 for f64::powi).
Sourcefn unchecked_pow_exponent_u8(self, exponent: &u8) -> Self
fn unchecked_pow_exponent_u8(self, exponent: &u8) -> Self
Raises self to the power of an u8 exponent without validation.
Contract: The caller must ensure the inputs are valid.
Sourcefn unchecked_pow_exponent_u16(self, exponent: &u16) -> Self
fn unchecked_pow_exponent_u16(self, exponent: &u16) -> Self
Raises self to the power of an u16 exponent without validation.
Contract: The caller must ensure the inputs are valid.
Sourcefn unchecked_pow_exponent_u32(self, exponent: &u32) -> Self
fn unchecked_pow_exponent_u32(self, exponent: &u32) -> Self
Raises self to the power of an u32 exponent without validation.
Contract: The caller must ensure the inputs are valid. For integer powers, this
includes ensuring the exponent is within the representable range of the underlying
power function (e.g., i32 for f64::powi).
Sourcefn unchecked_pow_exponent_u64(self, exponent: &u64) -> Self
fn unchecked_pow_exponent_u64(self, exponent: &u64) -> Self
Raises self to the power of an u64 exponent without validation.
Contract: The caller must ensure the inputs are valid. For integer powers, this
includes ensuring the exponent is within the representable range of the underlying
power function (e.g., i32 for f64::powi).
Sourcefn unchecked_pow_exponent_u128(self, exponent: &u128) -> Self
fn unchecked_pow_exponent_u128(self, exponent: &u128) -> Self
Raises self to the power of an u128 exponent without validation.
Contract: The caller must ensure the inputs are valid. For integer powers, this
includes ensuring the exponent is within the representable range of the underlying
power function (e.g., i32 for f64::powi).
Sourcefn unchecked_pow_exponent_usize(self, exponent: &usize) -> Self
fn unchecked_pow_exponent_usize(self, exponent: &usize) -> Self
Raises self to the power of an usize exponent without validation.
Contract: The caller must ensure the inputs are valid. For integer powers, this
includes ensuring the exponent is within the representable range of the underlying
power function (e.g., i32 for f64::powi).
Sourcefn unchecked_mul_add(self, b: &Self, c: &Self) -> Self
fn unchecked_mul_add(self, b: &Self, c: &Self) -> Self
Multiplies and adds in one fused operation, rounding to the nearest with only one rounding error.
a.mul_add(b, c) produces a result like a * &b + &c.
Contract: The caller must ensure all inputs are valid.
Sourcefn compute_hash<H: Hasher>(&self, state: &mut H)
fn compute_hash<H: Hasher>(&self, state: &mut H)
Computes a hash value for this scalar (real or complex).
This method must ensure that mathematically equal values produce the same hash, even across different representations (e.g., +0.0 and -0.0).
For complex numbers, implementations should hash the real and imaginary parts sequentially to ensure distinct complex numbers have different hashes.
§Implementation Notes
- For real numbers: Hash the value directly, normalizing signed zeros
- For complex numbers: Call
compute_hash()on real part, then imaginary part
§Debug Assertions
Implementations should include a debug assertion that the value is finite, as hashing non-finite values may lead to inconsistent results.
Provided Methods§
fn raw_negative_one(precision: u32) -> Self
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 RawScalarTrait for f64
impl RawScalarTrait for f64
Source§fn unchecked_mul_add(self, b: &Self, c: &Self) -> Self
fn unchecked_mul_add(self, b: &Self, c: &Self) -> Self
Multiplies and adds in one fused operation, rounding to the nearest with only one rounding error.
a.mul_add(b, c) produces a result like a * &b + &c.
type ValidationErrors = ErrorsValidationRawReal<f64>
fn raw_zero(_precision: u32) -> f64
fn is_zero(&self) -> bool
fn raw_one(_precision: u32) -> f64
fn unchecked_reciprocal(self) -> f64
fn unchecked_exp(self) -> f64
fn unchecked_sqrt(self) -> f64
fn unchecked_sin(self) -> f64
fn unchecked_asin(self) -> f64
fn unchecked_cos(self) -> f64
fn unchecked_acos(self) -> f64
fn unchecked_tan(self) -> f64
fn unchecked_atan(self) -> f64
fn unchecked_sinh(self) -> f64
fn unchecked_asinh(self) -> f64
fn unchecked_cosh(self) -> f64
fn unchecked_acosh(self) -> f64
fn unchecked_tanh(self) -> f64
fn unchecked_atanh(self) -> f64
fn unchecked_ln(self) -> f64
fn unchecked_log2(self) -> f64
fn unchecked_log10(self) -> f64
fn unchecked_pow_exponent_i8(self, exponent: &i8) -> f64
fn unchecked_pow_exponent_i16(self, exponent: &i16) -> f64
fn unchecked_pow_exponent_u8(self, exponent: &u8) -> f64
fn unchecked_pow_exponent_u16(self, exponent: &u16) -> f64
fn unchecked_pow_exponent_i32(self, exponent: &i32) -> Self
fn unchecked_pow_exponent_i64(self, exponent: &i64) -> f64
fn unchecked_pow_exponent_i128(self, exponent: &i128) -> f64
fn unchecked_pow_exponent_isize(self, exponent: &isize) -> f64
fn unchecked_pow_exponent_u32(self, exponent: &u32) -> f64
fn unchecked_pow_exponent_u64(self, exponent: &u64) -> f64
fn unchecked_pow_exponent_u128(self, exponent: &u128) -> f64
fn unchecked_pow_exponent_usize(self, exponent: &usize) -> f64
fn compute_hash<H: Hasher>(&self, state: &mut H)
Source§impl RawScalarTrait for Complex<f64>
impl RawScalarTrait for Complex<f64>
Source§fn unchecked_mul_add(self, b: &Self, c: &Self) -> Self
fn unchecked_mul_add(self, b: &Self, c: &Self) -> Self
Multiplies and adds in one fused operation, rounding to the nearest with only one rounding error.
a.mul_add(b, c) produces a result like a * &b + &c.
type ValidationErrors = ErrorsValidationRawComplex<ErrorsValidationRawReal<f64>>
fn raw_zero(_precision: u32) -> Self
fn is_zero(&self) -> bool
fn raw_one(_precision: u32) -> Self
fn unchecked_exp(self) -> Self
fn unchecked_sqrt(self) -> Self
fn unchecked_sin(self) -> Self
fn unchecked_asin(self) -> Self
fn unchecked_cos(self) -> Self
fn unchecked_acos(self) -> Self
fn unchecked_tan(self) -> Self
fn unchecked_atan(self) -> Self
fn unchecked_sinh(self) -> Self
fn unchecked_asinh(self) -> Self
fn unchecked_cosh(self) -> Self
fn unchecked_acosh(self) -> Self
fn unchecked_tanh(self) -> Self
fn unchecked_atanh(self) -> Self
fn unchecked_ln(self) -> Self
fn unchecked_log10(self) -> Self
fn unchecked_reciprocal(self) -> Self
fn unchecked_log2(self) -> Self
fn unchecked_pow_exponent_i8(self, exponent: &i8) -> Self
fn unchecked_pow_exponent_i16(self, exponent: &i16) -> Self
fn unchecked_pow_exponent_i32(self, exponent: &i32) -> Self
fn unchecked_pow_exponent_i64(self, exponent: &i64) -> Self
fn unchecked_pow_exponent_i128(self, exponent: &i128) -> Self
fn unchecked_pow_exponent_isize(self, exponent: &isize) -> Self
fn unchecked_pow_exponent_u8(self, exponent: &u8) -> Self
fn unchecked_pow_exponent_u16(self, exponent: &u16) -> Self
fn unchecked_pow_exponent_u32(self, exponent: &u32) -> Self
fn unchecked_pow_exponent_u64(self, exponent: &u64) -> Self
fn unchecked_pow_exponent_u128(self, exponent: &u128) -> Self
fn unchecked_pow_exponent_usize(self, exponent: &usize) -> Self
fn compute_hash<H: Hasher>(&self, state: &mut H)
Source§impl RawScalarTrait for Complex
impl RawScalarTrait for Complex
Source§fn unchecked_mul_add(self, b: &Self, c: &Self) -> Self
fn unchecked_mul_add(self, b: &Self, c: &Self) -> Self
Multiplies and adds in one fused operation, rounding to the nearest with only one rounding error.
a.mul_add(b, c) produces a result like a * &b + &c.
type ValidationErrors = ErrorsValidationRawComplex<ErrorsValidationRawReal<Float>>
fn raw_zero(precision: u32) -> Self
fn is_zero(&self) -> bool
fn raw_one(precision: u32) -> Self
fn unchecked_reciprocal(self) -> Self
fn unchecked_exp(self) -> Self
fn unchecked_sqrt(self) -> Self
fn unchecked_sin(self) -> Self
fn unchecked_asin(self) -> Self
fn unchecked_cos(self) -> Self
fn unchecked_acos(self) -> Self
fn unchecked_tan(self) -> Self
fn unchecked_atan(self) -> Self
fn unchecked_sinh(self) -> Self
fn unchecked_asinh(self) -> Self
fn unchecked_cosh(self) -> Self
fn unchecked_acosh(self) -> Self
fn unchecked_tanh(self) -> Self
fn unchecked_atanh(self) -> Self
fn unchecked_ln(self) -> Self
fn unchecked_log10(self) -> Self
fn unchecked_log2(self) -> Self
fn unchecked_pow_exponent_i8(self, exponent: &i8) -> Self
fn unchecked_pow_exponent_i16(self, exponent: &i16) -> Self
fn unchecked_pow_exponent_i32(self, exponent: &i32) -> Self
fn unchecked_pow_exponent_i64(self, exponent: &i64) -> Self
fn unchecked_pow_exponent_i128(self, exponent: &i128) -> Self
fn unchecked_pow_exponent_isize(self, exponent: &isize) -> Self
fn unchecked_pow_exponent_u8(self, exponent: &u8) -> Self
fn unchecked_pow_exponent_u16(self, exponent: &u16) -> Self
fn unchecked_pow_exponent_u32(self, exponent: &u32) -> Self
fn unchecked_pow_exponent_u64(self, exponent: &u64) -> Self
fn unchecked_pow_exponent_u128(self, exponent: &u128) -> Self
fn unchecked_pow_exponent_usize(self, exponent: &usize) -> Self
fn compute_hash<H: Hasher>(&self, state: &mut H)
Source§impl RawScalarTrait for Float
impl RawScalarTrait for Float
Source§fn unchecked_mul_add(self, b: &Self, c: &Self) -> Self
fn unchecked_mul_add(self, b: &Self, c: &Self) -> Self
Multiplies and adds in one fused operation, rounding to the nearest with only one rounding error.
a.mul_add(b, c) produces a result like a * &b + &c.