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

source

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.

source

pub fn with_max_p(self, max_p: usize) -> Self

Sets the maximum allowable precision.

source

pub fn with_min_n(self, min_n: isize) -> Self

Sets the minimum least absolute digit.

source

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

Sets the rounding mode.

source

pub fn without_max_p(self) -> Self

Clears the maximum allowable precision.

source

pub fn without_min_n(self) -> Self

Clears the minimum least absolute digit.

source

pub fn round_params<T: Real>(&self, num: &T) -> (Option<usize>, isize)

Rounding parameters necessary to complete rounding under this context for a given Real: the maximum precision p allowed and the minimum absolute digit n.

Trait Implementations§

source§

impl Clone for RFloatContext

source§

fn clone(&self) -> RFloatContext

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 RFloatContext

source§

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

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

impl Default for RFloatContext

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl RoundingContext for RFloatContext

§

type Format = RFloat

Result type of operations under this context.
source§

fn round<T: Real>(&self, num: &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.