pub struct DecimalSeq {
pub num_digits: usize,
pub decimal_point: i32,
pub truncated: bool,
pub digits: [u8; 768],
}
dec2flt
)Expand description
A decimal floating-point number, represented as a sequence of decimal digits.
Fields§
§num_digits: usize
dec2flt
)The number of significant digits in the decimal.
decimal_point: i32
dec2flt
)The offset of the decimal point in the significant digits.
truncated: bool
dec2flt
)If the number of significant digits stored in the decimal is truncated.
digits: [u8; 768]
dec2flt
)Buffer of the raw digits, in the range [0, 9].
Implementations§
Source§impl DecimalSeq
impl DecimalSeq
Sourcepub const MAX_DIGITS: usize = 768usize
🔬This is a nightly-only experimental API. (dec2flt
)
pub const MAX_DIGITS: usize = 768usize
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))
Sourcepub(super) const MAX_DIGITS_WITHOUT_OVERFLOW: usize = 19usize
🔬This is a nightly-only experimental API. (dec2flt
)
pub(super) const MAX_DIGITS_WITHOUT_OVERFLOW: usize = 19usize
dec2flt
)The max decimal digits that can be exactly represented in a 64-bit integer.
pub(super) const DECIMAL_POINT_RANGE: i32 = 2_047i32
dec2flt
)Sourcepub(super) fn try_add_digit(&mut self, digit: u8)
🔬This is a nightly-only experimental API. (dec2flt
)
pub(super) fn try_add_digit(&mut self, digit: u8)
dec2flt
)Append a digit to the buffer if it fits.
Sourcepub fn trim(&mut self)
🔬This is a nightly-only experimental API. (dec2flt
)
pub fn trim(&mut self)
dec2flt
)Trim trailing zeros from the buffer.
pub(super) fn round(&self) -> u64
dec2flt
)Sourcepub(super) fn left_shift(&mut self, shift: usize)
🔬This is a nightly-only experimental API. (dec2flt
)
pub(super) fn left_shift(&mut self, shift: usize)
dec2flt
)Computes decimal * 2^shift.
Sourcepub(super) fn right_shift(&mut self, shift: usize)
🔬This is a nightly-only experimental API. (dec2flt
)
pub(super) fn right_shift(&mut self, shift: usize)
dec2flt
)Computes decimal * 2^-shift.
Trait Implementations§
Source§impl Clone for DecimalSeq
impl Clone for DecimalSeq
Source§fn clone(&self) -> DecimalSeq
fn clone(&self) -> DecimalSeq
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for DecimalSeq
impl Debug for DecimalSeq
Source§impl Default for DecimalSeq
impl Default for DecimalSeq
Source§impl PartialEq for DecimalSeq
impl PartialEq for DecimalSeq
impl StructuralPartialEq for DecimalSeq
Auto Trait Implementations§
impl Freeze for DecimalSeq
impl RefUnwindSafe for DecimalSeq
impl Send for DecimalSeq
impl Sync for DecimalSeq
impl Unpin for DecimalSeq
impl UnsafeUnpin for DecimalSeq
impl UnwindSafe for DecimalSeq
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)] const IS_ZST: bool = _
#[doc(hidden)] const IS_ZST: bool = _
sized_type_properties
)Source§#[doc(hidden)] const LAYOUT: Layout = _
#[doc(hidden)] const LAYOUT: Layout = _
sized_type_properties
)Source§#[doc(hidden)] const MAX_SLICE_LEN: usize = _
#[doc(hidden)] const MAX_SLICE_LEN: usize = _
sized_type_properties
)[Self]
. Read more