CustomNumeric

Trait CustomNumeric 

Source
pub trait CustomNumeric:
    Copy
    + Debug
    + PartialOrd
    + Display
    + Add<Output = Self>
    + Sub<Output = Self>
    + Mul<Output = Self>
    + Div<Output = Self>
    + Neg<Output = Self>
    + Zero
    + ComplexField {
    // Required methods
    fn from_f64_unchecked(x: f64) -> Self;
    fn convert_from<U: CustomNumeric + 'static>(value: U) -> Self;
    fn to_f64(self) -> f64;
    fn epsilon() -> Self;
    fn pi() -> Self;
    fn max(self, other: Self) -> Self;
    fn min(self, other: Self) -> Self;
    fn is_valid(&self) -> bool;
    fn abs_as_same_type(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()

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: CustomNumeric + 'static>(value: U) -> Self

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 is_valid(&self) -> bool

Check if the value is valid (not NaN/infinite)

Source

fn abs_as_same_type(self) -> Self

Check if the value is finite (not NaN or infinite) Get absolute value as the same type (convenience method)

This method wraps ComplexField::abs() and converts the result back to Self to avoid type conversion issues in generic code. Note: Only abs() has this problem - other math functions (exp, cos, sin, sqrt) already return Self directly from 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", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl CustomNumeric for f64

f64 implementation of CustomNumeric

Source§

fn from_f64_unchecked(x: f64) -> Self

Source§

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

Source§

fn to_f64(self) -> f64

Source§

fn epsilon() -> Self

Source§

fn pi() -> Self

Source§

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

Source§

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

Source§

fn is_valid(&self) -> bool

Source§

fn abs_as_same_type(self) -> Self

Source§

fn exp_m1(self) -> Self

Implementors§

Source§

impl CustomNumeric for Df64

Df64 implementation of CustomNumeric