Struct mpmfnum::rfloat::RFloatContext
source · pub struct RFloatContext { /* private fields */ }
Expand description
Rounding contexts for floating-point numbers with unbounded significand and unbounded exponent.
The associated storage type is RFloat
.
Values rounded under this context are base-2 numbers
in scientific notation (-1)^s * c * 2^exp
where c
is
a theoreticaly unbounded unsigned integer and the exponent
exp
is an unbounded signed integer.
An RFloatContext
takes three parameters:
- (optional) maximum precision (see
Real::prec
), - (optional) minimum absolute digit,
- and rounding mode
RoundingMode
.
The requested precision may be as small as 1 binary digit. There is no way to restrict the maximum value. Infinity and NaN will not be rounded.
There are three possible rounding behaviors:
- only
min_n
is specified, - only
max_p
is specified, - or both are specified.
In the first case, rounding will behave as with fixed-point numbers
with unbounded precision but the exponent exp
must be more than min_n
.
For example, if min_n == 1
, then the rounded result will be an integer.
In the second case, the rounding will behave as with floating-point numbers,
adjusting c
so that it has at most max_p
bits.
In the third case, min_n
takes precedence, so the result may have less
than max_p
precision even if the input has at least max_p
precision.
This behavior may be used to emulate IEEE 754 subnormalization.
At least one parameter must be given or rounding will panic.
The rounding mode affects how “lost” binary digits are handled.
The possible rounding modes that can be specified
are defined by RoundingMode
.
Implementations§
source§impl RFloatContext
impl RFloatContext
sourcepub fn new() -> Self
pub fn new() -> Self
Constructs a rounding arguments with default arguments.
Neither max_p
nor min_n
are specified so rounding
will panic. The default rounding mode is
RoundingMode::NearestTiesToEven
.
sourcepub fn with_max_p(self, max_p: usize) -> Self
pub fn with_max_p(self, max_p: usize) -> Self
Sets the maximum allowable precision.
sourcepub fn with_min_n(self, min_n: isize) -> Self
pub fn with_min_n(self, min_n: isize) -> Self
Sets the minimum least absolute digit.
sourcepub fn with_rounding_mode(self, rm: RoundingMode) -> Self
pub fn with_rounding_mode(self, rm: RoundingMode) -> Self
Sets the rounding mode.
sourcepub fn without_max_p(self) -> Self
pub fn without_max_p(self) -> Self
Clears the maximum allowable precision.
sourcepub fn without_min_n(self) -> Self
pub fn without_min_n(self) -> Self
Clears the minimum least absolute digit.
Trait Implementations§
source§impl Clone for RFloatContext
impl Clone for RFloatContext
source§fn clone(&self) -> RFloatContext
fn clone(&self) -> RFloatContext
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more