pub trait RawScalarTrait:
ScalarCore
+ Arithmetic
+ NeumaierAddable
+ FpChecks
+ RawScalarTrigonometric
+ RawScalarHyperbolic
+ RawScalarPow {
type ValidationErrors: Error;
// 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_ln(self) -> Self;
fn unchecked_log2(self) -> Self;
fn unchecked_log10(self) -> 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::core::traits::validation::GuaranteesFiniteRealValues),
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§
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.
Sourcefn unchecked_ln(self) -> Self
fn unchecked_ln(self) -> Self
Computes the natural logarithm without validation.
Sourcefn unchecked_log2(self) -> Self
fn unchecked_log2(self) -> Self
Computes the base-2 logarithm without validation.
Sourcefn unchecked_log10(self) -> Self
fn unchecked_log10(self) -> Self
Computes the base-10 logarithm without validation.
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§
Sourcefn raw_negative_one(precision: u32) -> Self
fn raw_negative_one(precision: u32) -> Self
Returns negative one with the given precision.
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_ln(self) -> f64
fn unchecked_log2(self) -> f64
fn unchecked_log10(self) -> 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_ln(self) -> Self
fn unchecked_log10(self) -> Self
fn unchecked_reciprocal(self) -> Self
fn unchecked_log2(self) -> 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_ln(self) -> Self
fn unchecked_log10(self) -> Self
fn unchecked_log2(self) -> 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.