Skip to main content

Scalar

Trait Scalar 

Source
pub trait Scalar:
    Signed
    + Pow<Self, Output = Self, Output = Self>
    + Pow<i32>
    + FromPrimitive
    + ToPrimitive
    + Display
    + Debug
    + Copy
    + PartialEq
    + PartialOrd
    + AddAssign
    + SubAssign
    + MulAssign
    + DivAssign
    + Send
    + Sync
    + 'static {
    const EPSILON: Self;
    const INFINITY: Self;
    const NAN: Self;

    // Required methods
    fn is_nan(self) -> bool;
    fn sqrt(self) -> Self;
    fn exp(self) -> Self;
    fn sin(self) -> Self;
    fn cos(self) -> Self;
    fn max(self, other: Self) -> Self;
}
Expand description

A scalar type suitable for numerical computations in ODE solvers.

This trait aggregates the crate-local numeric requirements shared across diffsol.

§Implementations

DiffSol provides implementations for f64 and f32.

§Examples

use diffsol_la::Scalar;

fn compute<T: Scalar>(x: T, y: T) -> T {
    x * x + y
}

Required Associated Constants§

Source

const EPSILON: Self

Machine epsilon for this scalar type (smallest representable positive value such that 1.0 + EPSILON != 1.0).

Source

const INFINITY: Self

Positive infinity value for this scalar type.

Source

const NAN: Self

Not-a-Number (NaN) value for this scalar type.

Required Methods§

Source

fn is_nan(self) -> bool

Check if this value is NaN.

Source

fn sqrt(self) -> Self

Square root.

Source

fn exp(self) -> Self

Exponential.

Source

fn sin(self) -> Self

Sine.

Source

fn cos(self) -> Self

Cosine.

Source

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

Maximum of two values.

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 Scalar for f32

Source§

const EPSILON: f32 = f32::EPSILON

Source§

const INFINITY: f32 = f32::INFINITY

Source§

const NAN: f32 = f32::NAN

Source§

fn is_nan(self) -> bool

Source§

fn sqrt(self) -> f32

Source§

fn exp(self) -> f32

Source§

fn sin(self) -> f32

Source§

fn cos(self) -> f32

Source§

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

Source§

impl Scalar for f64

Source§

const EPSILON: f64 = f64::EPSILON

Source§

const INFINITY: f64 = f64::INFINITY

Source§

const NAN: f64 = f64::NAN

Source§

fn is_nan(self) -> bool

Source§

fn sqrt(self) -> f64

Source§

fn exp(self) -> f64

Source§

fn sin(self) -> f64

Source§

fn cos(self) -> f64

Source§

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

Implementors§