pub struct Octal;
Expand description
This type represents an octal base. It contains more efficient overrides of the
Base
functions to improve performance.
Trait Implementations§
Source§impl Base for Octal
impl Base for Octal
Source§const NUMBER: u16 = 8u16
const NUMBER: u16 = 8u16
This contains the numeric value of the type. E.g. for binary 2, for decimal 10,
etc.
Source§fn new() -> Self
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 from another, like when
performing an addition. In this case the base is simply copied over.
BigNumBase<Self>::new()
so it should be as lightweight as possible. Note
that it is not called when creating a BigNumBaseSource§fn exp_range(&self) -> ExpRange
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
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
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
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 criticalSource§fn rshift(lhs: u64, exp: u32) -> u64
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 rshift_u128(lhs: u128, exp: u32) -> u128
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 criticalSource§fn lshift(lhs: u64, exp: u32) -> u64
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 lshift_u128(lhs: u128, exp: u32) -> u128
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 criticalSource§fn calculate_ranges() -> (ExpRange, SigRange)
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 get_mag(sig: u64) -> u32
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
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 criticalimpl Copy for Octal
Auto Trait Implementations§
impl Freeze for Octal
impl RefUnwindSafe for Octal
impl Send for Octal
impl Sync for Octal
impl Unpin for Octal
impl UnwindSafe for Octal
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
Mutably borrows from an owned value. Read more