Skip to main content

CustomNumeric

Trait CustomNumeric 

Source
pub trait CustomNumeric:
    Sealed
    + Copy
    + Debug
    + PartialOrd
    + Display
    + Add<Output = Self>
    + Sub<Output = Self>
    + Mul<Output = Self>
    + Div<Output = Self>
    + Neg<Output = Self>
    + Zero
    + ComplexField<RealField = Self> {
    // Required methods
    fn from_f64_unchecked(x: f64) -> Self;
    fn convert_from<U>(value: U) -> Self
       where U: CustomNumeric + 'static;
    fn to_f64(self) -> f64;
    fn epsilon() -> Self;
    fn pi() -> Self;
    fn max(self, other: Self) -> Self;
    fn min(self, other: Self) -> Self;
    fn exp_m1(self) -> Self;
}
Expand description

Custom numeric trait for high-precision numerical computation

This trait provides the essential numeric operations needed for gauss module and matrix_from_gauss functions. Supports both f64 and Df64 types.

Uses standard traits for common operations:

  • num_traits::Zero for zero()
  • simba::scalar::ComplexField for mathematical functions (abs, sqrt, cos, sin, exp, etc.)
  • ComplexField::is_finite() for is_finite()

It is implemented for f64 and Df64 only (sealed), so that methods can be added without breaking code that uses it. Both are real: ComplexField::abs returns Self.

Required Methods§

Source

fn from_f64_unchecked(x: f64) -> Self

Convert from f64 to Self (direct conversion, no Option)

This is a static method that can be called as T::from_f64_unchecked(x) Renamed to avoid conflict with num_traits::FromPrimitive::from_f64

Source

fn convert_from<U>(value: U) -> Self
where U: CustomNumeric + 'static,

Convert from any CustomNumeric type to Self (generic conversion)

This allows conversion between different numeric types while preserving precision. Can be called as T::convert_from(other_numeric_value)

Source

fn to_f64(self) -> f64

Convert to f64

Source

fn epsilon() -> Self

Get machine epsilon

Source

fn pi() -> Self

Get high-precision PI constant

Source

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

Maximum of two values (not provided by ComplexField)

Source

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

Minimum of two values (not provided by ComplexField)

Source

fn exp_m1(self) -> Self

Compute exp(self) - 1 with higher precision for small values

This is more accurate than self.exp() - 1 when self is close to zero, avoiding catastrophic cancellation.

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 CustomNumeric for Compensated<f64, f64>

Df64 implementation of CustomNumeric

Source§

fn from_f64_unchecked(x: f64) -> Compensated<f64, f64>

Source§

fn convert_from<U>(value: U) -> Compensated<f64, f64>
where U: CustomNumeric + 'static,

Source§

fn to_f64(self) -> f64

Source§

fn epsilon() -> Compensated<f64, f64>

Source§

fn pi() -> Compensated<f64, f64>

Source§

fn max(self, other: Compensated<f64, f64>) -> Compensated<f64, f64>

Source§

fn min(self, other: Compensated<f64, f64>) -> Compensated<f64, f64>

Source§

fn exp_m1(self) -> Compensated<f64, f64>

Source§

impl CustomNumeric for f64

f64 implementation of CustomNumeric

Source§

fn from_f64_unchecked(x: f64) -> f64

Source§

fn convert_from<U>(value: U) -> f64
where U: CustomNumeric + 'static,

Source§

fn to_f64(self) -> f64

Source§

fn epsilon() -> f64

Source§

fn pi() -> f64

Source§

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

Source§

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

Source§

fn exp_m1(self) -> f64

Implementors§