Skip to main content

FastExpression

Trait FastExpression 

Source
pub trait FastExpression: Copy {
    type Int: PrimInt + Bounded + SaturatingAdd + SaturatingSub + SaturatingMul + NumCast + FixedInt;

    const FRAC: usize;

    // Required method
    fn evaluate_raw(self) -> Self::Int;

    // Provided method
    fn evaluate<I, const FRAC_OUT: usize>(self) -> FastFixed<I, FRAC_OUT>
       where I: Bounded + NumCast + Copy { ... }
}
Expand description

A deferred FastFixed expression.

Expressions carry the exact result of an operation (within the 64-bit intermediate type) together with its number of fractional bits, and are rounded exactly once when they are converted into a concrete FastFixed format with From/Into or FastExpression::evaluate, mirroring the deferred expression templates of the C++ library. Expressions compose: adding or subtracting two expressions yields a deferred SumExpression, while combining or comparing an expression with a FastFixed evaluates the expression in that FastFixed’s format.

Required Associated Constants§

Source

const FRAC: usize

The number of fractional bits of the raw value produced by evaluate_raw.

Required Associated Types§

Source

type Int: PrimInt + Bounded + SaturatingAdd + SaturatingSub + SaturatingMul + NumCast + FixedInt

The 64-bit intermediate integer type the expression is evaluated in.

Required Methods§

Source

fn evaluate_raw(self) -> Self::Int

Evaluates the expression to its raw value with Self::FRAC fractional bits.

Provided Methods§

Source

fn evaluate<I, const FRAC_OUT: usize>(self) -> FastFixed<I, FRAC_OUT>
where I: Bounded + NumCast + Copy,

Evaluates the expression into the given FastFixed format, rounding half to even exactly once and saturating when the value does not fit.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<L, R> FastExpression for SumExpression<L, R>
where L: FastExpression, R: FastExpression<Int = L::Int>,

Source§

const FRAC: usize

Source§

type Int = <L as FastExpression>::Int

Source§

impl<T, const FL: usize, U, const FR: usize> FastExpression for MulExpression<FastFixed<T, FL>, FastFixed<U, FR>>
where T: PromoteMul<U> + Zero + PartialOrd + NumCast + Copy, U: Zero + PartialOrd + NumCast + Copy, <T as PromoteMul<U>>::Output: FastInt,

Source§

const FRAC: usize

Source§

type Int = <<T as PromoteMul<U>>::Output as FastInt>::Intermediate