Trait NumberInstance

Source
pub trait NumberInstance:
    Sized
    + Copy
    + Default
    + From<Boolean>
    + Into<Number>
    + Add<Output = Self>
    + AddAssign
    + Sub<Output = Self>
    + SubAssign
    + Mul<Output = Self>
    + MulAssign
    + Div<Output = Self>
    + DivAssign
    + Product
    + Sum
    + Debug
    + Display {
    type Abs: NumberInstance;
    type Exp: NumberInstance;
    type Log: NumberInstance;
    type Round: NumberInstance;
    type Class: NumberClass<Instance = Self>;

    // Required methods
    fn class(&self) -> Self::Class;
    fn into_type(
        self,
        dtype: Self::Class,
    ) -> <Self::Class as NumberClass>::Instance;
    fn abs(self) -> Self::Abs;
    fn exp(self) -> Self::Exp;
    fn ln(self) -> Self::Log;
    fn log<N>(self, base: N) -> Self::Log
       where N: NumberInstance,
             Float: From<N>;
    fn pow(self, exp: Number) -> Self;
    fn round(self) -> Self::Round;

    // Provided methods
    fn and(self, other: Self) -> Self
       where Boolean: CastFrom<Self> { ... }
    fn not(self) -> Self
       where Boolean: CastFrom<Self> { ... }
    fn or(self, other: Self) -> Self
       where Boolean: CastFrom<Self> { ... }
    fn xor(self, other: Self) -> Self
       where Boolean: CastFrom<Self> { ... }
}
Expand description

Defines common operations on numeric types supported by Number.

Required Associated Types§

Required Methods§

Source

fn class(&self) -> Self::Class

Get an impl of NumberClass describing this number.

Source

fn into_type(self, dtype: Self::Class) -> <Self::Class as NumberClass>::Instance

Cast this number into the specified NumberClass.

Source

fn abs(self) -> Self::Abs

Calculate the absolute value of this number.

Source

fn exp(self) -> Self::Exp

Raise e to the power of this number.

Source

fn ln(self) -> Self::Log

Compute the natural logarithm of this number.

Source

fn log<N>(self, base: N) -> Self::Log
where N: NumberInstance, Float: From<N>,

Compute the logarithm of this number with respect to the given base.

Source

fn pow(self, exp: Number) -> Self

Raise this number to the given exponent.

Panics: if the given exponent is a complex number.

Source

fn round(self) -> Self::Round

Return this number rounded to the nearest integer.

Provided Methods§

Source

fn and(self, other: Self) -> Self
where Boolean: CastFrom<Self>,

Return true if self and other are nonzero.

Source

fn not(self) -> Self
where Boolean: CastFrom<Self>,

Return true if this number is zero.

Source

fn or(self, other: Self) -> Self
where Boolean: CastFrom<Self>,

Return true if self or other is nonzero.

Source

fn xor(self, other: Self) -> Self
where Boolean: CastFrom<Self>,

Return true if exactly one of self and other is zero.

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.

Implementors§