Struct mpmfnum::fixed::FixedContext

source ·
pub struct FixedContext { /* private fields */ }
Expand description

Rounding contexts for fixed-point numbers.

The associated storage type is Fixed.

Values rounded this context are fixed-point numbers: (-1)^s * c * 2^scale where c is a fixed-precision unsigned or signed integer and scale is a fixed integer.

A FixedContext is parameterized by

  • signedness (unsigned vs. signed),
  • scale factor (position of least-significant digit),
  • total bitwidth of the encoding,
  • rounding mode,
  • overflow behavior.

By default, the rounding mode is RoundingMode::ToZero, and the overflow handling is Overflow::Wrap. See Overflow for supported overflow behavior.

Implementations§

source§

impl FixedContext

source

pub fn new(signed: bool, scale: isize, nbits: usize) -> Self

Constructs new rounding context. The default rounding mode is truncation (see ToZero). The default overflow behavior is saturation (see Wrap).

source

pub fn with_rounding_mode(self, rm: RoundingMode) -> Self

Sets the rounding mode of this FixedContext.

source

pub fn with_overflow(self, overflow: Overflow) -> Self

Sets the overflow behavior of this FixedContext.

source

pub fn maxval(&self) -> Fixed

The maximum value in format specified by this FixedContext. If the format is unsigned, this is just 2^scale * 2^nbits - 1. If the format is signed, this is just 2^scale * 2^(nbits-1) - 1.

source

pub fn minval(&self) -> Fixed

The minimum value in a format specified by this FixedContext. If the format is unsigned, this is just 0. If the format is signed, this is just 2^scale * -2^(nbits-1).

source

pub fn zero(&self) -> Fixed

Constructs zero in the format described by FixedContext

source

pub fn quantum(&self) -> Fixed

Constructs the smallest representable difference in the format described by FixedContext.

Trait Implementations§

source§

impl Clone for FixedContext

source§

fn clone(&self) -> FixedContext

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for FixedContext

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl RoundedAbs for FixedContext

source§

fn abs<N: Real>(&self, src: &N) -> Self::Format

Performs rounded |x|.
source§

impl RoundedAcos for FixedContext

source§

fn acos<N: Real>(&self, src: &N) -> Self::Format

Performs rounded arccos(x).
source§

impl RoundedAcosh for FixedContext

source§

fn acosh<N: Real>(&self, src: &N) -> Self::Format

Performs rounded arcosh(x).
source§

impl RoundedAdd for FixedContext

source§

fn add<N1, N2>(&self, src1: &N1, src2: &N2) -> Self::Format
where N1: Real, N2: Real,

Performs rounded x + y.
source§

impl RoundedAsin for FixedContext

source§

fn asin<N: Real>(&self, src: &N) -> Self::Format

Performs rounded arcsin(x).
source§

impl RoundedAsinh for FixedContext

source§

fn asinh<N: Real>(&self, src: &N) -> Self::Format

Performs rounded arsinh(x).
source§

impl RoundedAtan for FixedContext

source§

fn atan<N: Real>(&self, src: &N) -> Self::Format

Performs rounded arctan(x).
source§

impl RoundedAtan2 for FixedContext

source§

fn atan2<N1, N2>(&self, src1: &N1, src2: &N2) -> Self::Format
where N1: Real, N2: Real,

Performs rounded arctan(y / x).
source§

impl RoundedAtanh for FixedContext

source§

fn atanh<N: Real>(&self, src: &N) -> Self::Format

Performs rounded artanh(x).
source§

impl RoundedCbrt for FixedContext

source§

fn cbrt<N: Real>(&self, src: &N) -> Self::Format

Performs rounded cbrt(x).
source§

impl RoundedCos for FixedContext

source§

fn cos<N: Real>(&self, src: &N) -> Self::Format

Performs rounded cos(x).
source§

impl RoundedCosPi for FixedContext

source§

fn cos_pi<N: Real>(&self, src: &N) -> Self::Format

Performs rounded cos(pi * x).
source§

impl RoundedCosh for FixedContext

source§

fn cosh<N: Real>(&self, src: &N) -> Self::Format

Performs rounded cosh(x).
source§

impl RoundedDiv for FixedContext

source§

fn div<N1, N2>(&self, src1: &N1, src2: &N2) -> Self::Format
where N1: Real, N2: Real,

Performs rounded x / y.
source§

impl RoundedErf for FixedContext

source§

fn erf<N: Real>(&self, src: &N) -> Self::Format

Performs rounded erf(x).
source§

impl RoundedErfc for FixedContext

source§

fn erfc<N: Real>(&self, src: &N) -> Self::Format

Performs rounded erfc(x).
source§

impl RoundedExp for FixedContext

source§

fn exp<N: Real>(&self, src: &N) -> Self::Format

Performs rounded exp(x).
source§

impl RoundedExp10m1 for FixedContext

source§

fn exp10m1<N: Real>(&self, src: &N) -> Self::Format

Performs rounded 10^x - 1.
source§

impl RoundedExp2 for FixedContext

source§

fn exp2<N: Real>(&self, src: &N) -> Self::Format

Performs rounded 2^x.
source§

impl RoundedExp2m1 for FixedContext

source§

fn exp2m1<N: Real>(&self, src: &N) -> Self::Format

Performs rounded 2^x - 1.
source§

impl RoundedExpm1 for FixedContext

source§

fn expm1<N: Real>(&self, src: &N) -> Self::Format

Performs rounded e^x - 1.
source§

impl RoundedFMA for FixedContext

source§

fn fma<N1, N2, N3>(&self, src1: &N1, src2: &N2, src3: &N3) -> Self::Format
where N1: Real, N2: Real, N3: Real,

Performs rounded a*b + c.
source§

impl RoundedFmod for FixedContext

source§

fn fmod<N1, N2>(&self, src1: &N1, src2: &N2) -> Self::Format
where N1: Real, N2: Real,

Performs rounded fmod(x, y).
source§

impl RoundedGamma for FixedContext

source§

fn tgamma<N: Real>(&self, src: &N) -> Self::Format

Performs rounded tgamma(x).
source§

impl RoundedHypot for FixedContext

source§

fn hypot<N1, N2>(&self, src1: &N1, src2: &N2) -> Self::Format
where N1: Real, N2: Real,

Performs rounded sqrt(x^2 + y^2).
source§

impl RoundedLgamma for FixedContext

source§

fn lgamma<N: Real>(&self, src: &N) -> Self::Format

Performs rounded lgamma(x).
source§

impl RoundedLog for FixedContext

source§

fn log<N: Real>(&self, src: &N) -> Self::Format

Performs rounded ln(x).
source§

impl RoundedLog10 for FixedContext

source§

fn log10<N: Real>(&self, src: &N) -> Self::Format

Performs rounded log10(x).
source§

impl RoundedLog10p1 for FixedContext

source§

fn log10p1<N: Real>(&self, src: &N) -> Self::Format

Performs rounded log10(x + 1).
source§

impl RoundedLog1p for FixedContext

source§

fn log1p<N: Real>(&self, src: &N) -> Self::Format

Performs rounded log(x + 1).
source§

impl RoundedLog2 for FixedContext

source§

fn log2<N: Real>(&self, src: &N) -> Self::Format

Performs rounded log2(x).
source§

impl RoundedLog2p1 for FixedContext

source§

fn log2p1<N: Real>(&self, src: &N) -> Self::Format

Performs rounded log2(x + 1).
source§

impl RoundedMul for FixedContext

source§

fn mul<N1, N2>(&self, src1: &N1, src2: &N2) -> Self::Format
where N1: Real, N2: Real,

Performs rounded x * y.
source§

impl RoundedNeg for FixedContext

source§

fn neg<N: Real>(&self, src: &N) -> Self::Format

Performs rounded -x.
source§

impl RoundedPow for FixedContext

source§

fn pow<N1, N2>(&self, src1: &N1, src2: &N2) -> Self::Format
where N1: Real, N2: Real,

Performs rounded x ^ y.
source§

impl RoundedRecip for FixedContext

source§

fn recip<N: Real>(&self, src: &N) -> Self::Format

Performs rounded 1/x.
source§

impl RoundedRecipSqrt for FixedContext

source§

fn recip_sqrt<N: Real>(&self, src: &N) -> Self::Format

Performs rounded 1/sqrt(x).
source§

impl RoundedRemainder for FixedContext

source§

fn remainder<N1, N2>(&self, src1: &N1, src2: &N2) -> Self::Format
where N1: Real, N2: Real,

Performs rounded remainder(x, y).
source§

impl RoundedSin for FixedContext

source§

fn sin<N: Real>(&self, src: &N) -> Self::Format

Performs rounded sin(x).
source§

impl RoundedSinPi for FixedContext

source§

fn sin_pi<N: Real>(&self, src: &N) -> Self::Format

Performs rounded sin(pi * x).
source§

impl RoundedSinh for FixedContext

source§

fn sinh<N: Real>(&self, src: &N) -> Self::Format

Performs rounded sinh(x).
source§

impl RoundedSqrt for FixedContext

source§

fn sqrt<N: Real>(&self, src: &N) -> Self::Format

Performs rounded sqrt(x).
source§

impl RoundedSub for FixedContext

source§

fn sub<N1, N2>(&self, src1: &N1, src2: &N2) -> Self::Format
where N1: Real, N2: Real,

Performs rounded x - y.
source§

impl RoundedTan for FixedContext

source§

fn tan<N: Real>(&self, src: &N) -> Self::Format

Performs rounded tan(x).
source§

impl RoundedTanPi for FixedContext

source§

fn tan_pi<N: Real>(&self, src: &N) -> Self::Format

Performs rounded tan(pi * x).
source§

impl RoundedTanh for FixedContext

source§

fn tanh<N: Real>(&self, src: &N) -> Self::Format

Performs rounded tanh(x).
source§

impl RoundingContext for FixedContext

§

type Format = Fixed

Result type of operations under this context.
source§

fn round<T: Real>(&self, val: &T) -> Self::Format

Rounds any Real value to a RoundingContext::Format value, rounding according to this RoundingContext.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Az for T

source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.