bignumbe_rs

Struct Decimal

Source
pub struct Decimal;
Expand description

This type represents a decimal base. It contains more efficient overrides of the Base functions to improve performance.

Trait Implementations§

Source§

impl Base for Decimal

Source§

const NUMBER: u16 = 10u16

This contains the numeric value of the type. E.g. for binary 2, for decimal 10, etc.
Source§

fn new() -> Self

Function that can create an instance of this Base. Users should never have to manually create instances of this type. This is called implicitly on every call to BigNumBase<Self>::new() so it should be as lightweight as possible. Note that it is not called when creating a BigNumBase from another, like when performing an addition. In this case the base is simply copied over.
Source§

fn exp_range(&self) -> ExpRange

Function that fetches the non-inclusive range of the exponent for the significand in the BigNum with this base. E.g. the range for binary is [63, 64), since the range of the significand is [2^63, 2^64)
Source§

fn sig_range(&self) -> SigRange

Function that fetches the inclusive range for the significand in the BigNum with this base. E.g. for binary the range of the significand is [2^63, 2^64 - 1]
Source§

fn pow(exp: u32) -> u64

This is a function that computes Self::NUMBER ^ exp. It has a default implementation that computes the value directly. It is recommended to override this behavior if there is a trick to the exponentiation (like how for binary 2^n = (1 << n)). You can also create a gloabl const lookup table and reference that.
Source§

fn pow_u128(exp: u32) -> u128

This is a function that computes the same value as pow but in a u128 value. Mostly useful to help with multiplication/division, and as such it’s probably unnecessary to override it unless multiplication/division performance is critical
Source§

fn get_mag(sig: u64) -> u32

This is a function that computes the highest power x such that sig >= (Self::NUMBER ^ x). There is a default implementation that uses ilog, and it is recommended to use this unless there is a special way to find the magnitude (e.g. binary and decimal have specialized ilog implementations). As a special case, bases that are powers of 2 or 10 can use log arithmetic to convert. I tried this with octal and hexadecimal but it had no noticeable impact.
Source§

fn get_mag_u128(sig: u128) -> u32

This is a function that computes the same thing as get_mag but in a u128 value. Mostly useful to help with multiplication/division, and as such it’s probably unnecessary to override it unless multiplication/division performance is critical
Source§

fn calculate_ranges() -> (ExpRange, SigRange)

This function calculates the ranges for the exponent and the significand. It is not particularly efficient so if performance is a concern you should not use it. It mainly exists to facilitate the create_default_base! macro. It is recommended to store the ranges in a const and return them directly in the exp_range and sig_range methods if convenient.
Source§

fn lshift(lhs: u64, exp: u32) -> u64

This is a function that computes lhs * (Self::NUMBER ^ exp). There is a default implementation that obtains the value of Self::NUMBER ^ exp via the pow method for this type, and does a division. It is recommended to override this method if there is a trick for the division (like how in binary, lhs * (2 ^ exp) = lhs >> exp, or in octal lhs * (8 ^ exp) = lhs >> (3 * exp)
Source§

fn rshift(lhs: u64, exp: u32) -> u64

This is a function that computes lhs / (Self::NUMBER ^ exp). There is a default implementation that obtains the value of Self::NUMBER ^ exp via the pow method for this type, and does a multiplication. It is recommended to override this method if there is a trick for the division (like how in binary, lhs / (2 ^ exp) = lhs << exp, or in octal lhs / (8 ^ exp) = lhs << (3 * exp)
Source§

fn lshift_u128(lhs: u128, exp: u32) -> u128

This is a function that computes the same thing as lshift but in a u128 value. Mostly useful to help with multiplication/division, and as such it’s probably unnecessary to override it unless multiplication/division performance is critical
Source§

fn rshift_u128(lhs: u128, exp: u32) -> u128

This is a function that computes the same thing as rshift but in a u128 value. Mostly useful to help with multiplication/division, and as such it’s probably unnecessary to override it unless multiplication/division performance is critical
Source§

fn as_number(&self) -> u16

This method just fetches Self::NUMBER but is provided as an instance method for convenience. Overriding it is undefined behavior
Source§

impl Clone for Decimal

Source§

fn clone(&self) -> Decimal

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 Decimal

Source§

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

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

impl Copy for Decimal

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

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

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.