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
impl FixedContext
sourcepub fn with_rounding_mode(self, rm: RoundingMode) -> Self
pub fn with_rounding_mode(self, rm: RoundingMode) -> Self
Sets the rounding mode of this FixedContext
.
sourcepub fn with_overflow(self, overflow: Overflow) -> Self
pub fn with_overflow(self, overflow: Overflow) -> Self
Sets the overflow behavior of this FixedContext
.
sourcepub fn maxval(&self) -> Fixed
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
.
sourcepub fn minval(&self) -> Fixed
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)
.
sourcepub fn zero(&self) -> Fixed
pub fn zero(&self) -> Fixed
Constructs zero in the format described by FixedContext
sourcepub fn quantum(&self) -> Fixed
pub fn quantum(&self) -> Fixed
Constructs the smallest representable difference in
the format described by FixedContext
.
Trait Implementations§
source§impl Clone for FixedContext
impl Clone for FixedContext
source§fn clone(&self) -> FixedContext
fn clone(&self) -> FixedContext
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more