RealScalar

Trait RealScalar 

Source
pub trait RealScalar:
    Clone
    + Copy
    + Sync
    + Send
    + Sized
    + Any
    + Debug
    + Display
    + Sum
    + Product
    + Float
    + FloatConst
    + FromPrimitive
    + ToPrimitive
    + AsPrimitive<f32>
    + AsPrimitive<f64>
    + NumAssign
    + NumAssignRef
    + Default
    + Signed
    + 'static
    + RealField
    + ConstOne
    + ConstZero
    + Memorable
    + BitWidthConvertible<Width32 = f32, Width64 = f64> {
    type C: ComplexScalar<R = Self>;

    // Required methods
    fn into_ratio(self) -> Option<Ratio<BigInt>>;
    fn from_ratio(ratio: Ratio<BigInt>) -> Option<Self>;
    fn standard_random() -> Self;
    fn uniform_random(min: Self, max: Self) -> Self;
    fn is_close(self, other: impl RealScalar) -> bool;
    fn is_close_with_tolerance(
        self,
        other: impl RealScalar,
        rtol: Self,
        atol: Self,
    ) -> bool;
}
Expand description

A generic real number within the OpenQudit library.

Required Associated Types§

Source

type C: ComplexScalar<R = Self>

The complex number type associated with this real number.

Required Methods§

Source

fn into_ratio(self) -> Option<Ratio<BigInt>>

Convert this scalar to a rational number representation

Source

fn from_ratio(ratio: Ratio<BigInt>) -> Option<Self>

Create a scalar from a rational number representation

Source

fn standard_random() -> Self

Generate a random value from the standard normal distribution (mean=0, std=1)

Source

fn uniform_random(min: Self, max: Self) -> Self

Generate a random value from a uniform distribution in the given range [min, max)

Source

fn is_close(self, other: impl RealScalar) -> bool

Check if two values are close using default tolerances

Source

fn is_close_with_tolerance( self, other: impl RealScalar, rtol: Self, atol: Self, ) -> bool

Check if two values are close with custom tolerances Uses the formula: abs(a - b) <= (atol + rtol * abs(b))

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

Source§

type C = Complex<f32>

Source§

fn into_ratio(self) -> Option<Ratio<BigInt>>

Source§

fn from_ratio(ratio: Ratio<BigInt>) -> Option<Self>

Source§

fn standard_random() -> Self

Source§

fn uniform_random(min: Self, max: Self) -> Self

Source§

fn is_close(self, other: impl RealScalar) -> bool

Source§

fn is_close_with_tolerance( self, other: impl RealScalar, rtol: Self, atol: Self, ) -> bool

Source§

impl RealScalar for f64

Source§

type C = Complex<f64>

Source§

fn into_ratio(self) -> Option<Ratio<BigInt>>

Source§

fn from_ratio(ratio: Ratio<BigInt>) -> Option<Self>

Source§

fn standard_random() -> Self

Source§

fn uniform_random(min: Self, max: Self) -> Self

Source§

fn is_close(self, other: impl RealScalar) -> bool

Source§

fn is_close_with_tolerance( self, other: impl RealScalar, rtol: Self, atol: Self, ) -> bool

Implementors§