Struct DecimalSeq

Source
pub struct DecimalSeq {
    pub num_digits: usize,
    pub decimal_point: i32,
    pub truncated: bool,
    pub digits: [u8; 768],
}
🔬This is a nightly-only experimental API. (dec2flt)
Expand description

A decimal floating-point number, represented as a sequence of decimal digits.

Fields§

§num_digits: usize
🔬This is a nightly-only experimental API. (dec2flt)

The number of significant digits in the decimal.

§decimal_point: i32
🔬This is a nightly-only experimental API. (dec2flt)

The offset of the decimal point in the significant digits.

§truncated: bool
🔬This is a nightly-only experimental API. (dec2flt)

If the number of significant digits stored in the decimal is truncated.

§digits: [u8; 768]
🔬This is a nightly-only experimental API. (dec2flt)

Buffer of the raw digits, in the range [0, 9].

Implementations§

Source§

impl DecimalSeq

Source

pub const MAX_DIGITS: usize = 768usize

🔬This is a nightly-only experimental API. (dec2flt)

The maximum number of digits required to unambiguously round up to a 64-bit float.

For an IEEE 754 binary64 float, this required 767 digits. So we store the max digits + 1.

We can exactly represent a float in radix b from radix 2 if b is divisible by 2. This function calculates the exact number of digits required to exactly represent that float.

According to the “Handbook of Floating Point Arithmetic”, for IEEE754, with emin being the min exponent, p2 being the precision, and b being the radix, the number of digits follows as:

−emin + p2 + ⌊(emin + 1) log(2, b) − log(1 − 2^(−p2), b)⌋

For f32, this follows as: emin = -126 p2 = 24

For f64, this follows as: emin = -1022 p2 = 53

In Python: -emin + p2 + math.floor((emin+ 1)*math.log(2, b)-math.log(1-2**(-p2), b))

Source

pub(super) const MAX_DIGITS_WITHOUT_OVERFLOW: usize = 19usize

🔬This is a nightly-only experimental API. (dec2flt)

The max decimal digits that can be exactly represented in a 64-bit integer.

Source

pub(super) const DECIMAL_POINT_RANGE: i32 = 2_047i32

🔬This is a nightly-only experimental API. (dec2flt)
Source

pub(super) fn try_add_digit(&mut self, digit: u8)

🔬This is a nightly-only experimental API. (dec2flt)

Append a digit to the buffer if it fits.

Source

pub fn trim(&mut self)

🔬This is a nightly-only experimental API. (dec2flt)

Trim trailing zeros from the buffer.

Source

pub(super) fn round(&self) -> u64

🔬This is a nightly-only experimental API. (dec2flt)
Source

pub(super) fn left_shift(&mut self, shift: usize)

🔬This is a nightly-only experimental API. (dec2flt)

Computes decimal * 2^shift.

Source

pub(super) fn right_shift(&mut self, shift: usize)

🔬This is a nightly-only experimental API. (dec2flt)

Computes decimal * 2^-shift.

Trait Implementations§

Source§

impl Clone for DecimalSeq

Source§

fn clone(&self) -> DecimalSeq

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 DecimalSeq

Source§

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

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

impl Default for DecimalSeq

Source§

fn default() -> Self

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

impl PartialEq for DecimalSeq

Source§

fn eq(&self, other: &DecimalSeq) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for DecimalSeq

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> 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit #126799)
Performs copy-assignment from self to dest. Read more
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> SizedTypeProperties for T

Source§

#[doc(hidden)] const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
Source§

#[doc(hidden)] const LAYOUT: Layout = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)] const MAX_SLICE_LEN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
The largest safe length for a [Self]. Read more
Source§

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

Source§

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>,

Source§

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.