Struct Decimal

pub struct Decimal { pub exponent: i64, pub mantissa: u64, pub negative: bool, pub many_digits: bool }

A floating point number with up to 64 bits of mantissa and an i64 exponent.

Fields

exponent: i64
mantissa: u64
negative: bool
many_digits: bool

Implementations

impl Decimal

fn can_use_fast_path<F: Lemire>(&self) -> bool

Detect if the float can be accurately reconstructed from native floats.

fn try_fast_path<F: Lemire>(&self) -> Option<F>

Try turning the decimal into an exact float representation, using machine-sized integers and floats.

This is extracted into a separate function so that it can be attempted before constructing a Decimal. This only works if both the mantissa and the exponent can be exactly represented as a machine float, since IEE-754 guarantees no rounding will occur.

There is an exception: disguised fast-path cases, where we can shift powers-of-10 from the exponent to the significant digits.

Trait Implementations

impl Clone for Decimal

fn clone(&self) -> Decimal

impl Copy for Decimal

impl Debug for Decimal

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

impl Default for Decimal

fn default() -> Decimal

impl Eq for Decimal

fn assert_fields_are_eq(&self)

impl PartialEq for Decimal

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

impl StructuralPartialEq for Decimal

impl TrivialClone for Decimal

Auto Trait Implementations

impl Freeze for Decimal

impl RefUnwindSafe for Decimal

impl Send for Decimal

impl Sync for Decimal

impl Unpin for Decimal

impl UnsafeUnpin for Decimal

impl UnwindSafe for Decimal

Blanket Implementations

impl<T> Any for Decimal where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Decimal where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Decimal where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for Decimal where T: Clone,

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

impl<T> From<T> for Decimal

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Printable for Decimal where T: Copy + Debug,

impl<T> SizeHint for Decimal where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for Decimal

impl<T, U> Into<U> for Decimal where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

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

type Error = Infallible;
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto<U> for Decimal where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>