Struct sp_arithmetic::biguint::BigUint
source · [−]pub struct BigUint { /* private fields */ }
Expand description
Simple wrapper around an infinitely large integer, represented as limbs of Single
.
Implementations
sourceimpl BigUint
impl BigUint
sourcepub fn with_capacity(size: usize) -> Self
pub fn with_capacity(size: usize) -> Self
Create a new instance with size
limbs. This prevents any number with zero limbs to be
created.
The behavior of the type is undefined with zero limbs.
sourcepub fn from_limbs(limbs: &[Single]) -> Self
pub fn from_limbs(limbs: &[Single]) -> Self
Raw constructor from custom limbs. If limbs
is empty, Zero::zero()
implementation is
used.
sourcepub fn get(&self, index: usize) -> Single
pub fn get(&self, index: usize) -> Single
A naive getter for limb at index
. Note that the order is lsb -> msb.
Panics
This panics if index is out of range.
sourcepub fn checked_get(&self, index: usize) -> Option<Single>
pub fn checked_get(&self, index: usize) -> Option<Single>
A naive getter for limb at index
. Note that the order is lsb -> msb.
sourcepub fn set(&mut self, index: usize, value: Single)
pub fn set(&mut self, index: usize, value: Single)
A naive setter for limb at index
. Note that the order is lsb -> msb.
Panics
This panics if index is out of range.
sourcepub fn lsb(&self) -> Single
pub fn lsb(&self) -> Single
returns the least significant limb of the number.
Panics
While the constructor of the type prevents this, this can panic if self
has no digits.
sourcepub fn msb(&self) -> Single
pub fn msb(&self) -> Single
returns the most significant limb of the number.
Panics
While the constructor of the type prevents this, this can panic if self
has no digits.
sourcepub fn lstrip(&mut self)
pub fn lstrip(&mut self)
Strips zeros from the left side (the most significant limbs) of self
, if any.
sourcepub fn lpad(&mut self, size: usize)
pub fn lpad(&mut self, size: usize)
Zero-pad self
from left to reach size
limbs. Will not make any difference if self
is already bigger than size
limbs.
sourcepub fn add(self, other: &Self) -> Self
pub fn add(self, other: &Self) -> Self
Adds self
with other
. self and other do not have to have any particular size. Given
that the n = max{size(self), size(other)}
, it will produce a number with n + 1
limbs.
This function does not strip the output and returns the original allocated n + 1
limbs. The caller may strip the output if desired.
Taken from “The Art of Computer Programming” by D.E. Knuth, vol 2, chapter 4.
sourcepub fn sub(self, other: &Self) -> Result<Self, Self>
pub fn sub(self, other: &Self) -> Result<Self, Self>
Subtracts other
from self
. self and other do not have to have any particular size.
Given that the n = max{size(self), size(other)}
, it will produce a number of size n
.
If other
is bigger than self
, Err(B - borrow)
is returned.
Taken from “The Art of Computer Programming” by D.E. Knuth, vol 2, chapter 4.
sourcepub fn mul(self, other: &Self) -> Self
pub fn mul(self, other: &Self) -> Self
Multiplies n-limb number self
with m-limb number other
.
The resulting number will always have n + m
limbs.
This function does not strip the output and returns the original allocated n + m
limbs. The caller may strip the output if desired.
Taken from “The Art of Computer Programming” by D.E. Knuth, vol 2, chapter 4.
sourcepub fn div_unit(self, other: Single) -> Self
pub fn div_unit(self, other: Single) -> Self
Divides self
by a single limb other
. This can be used in cases where the original
division cannot work due to the divisor (other
) being just one limb.
Invariant: other
cannot be zero.
sourcepub fn div(self, other: &Self, rem: bool) -> Option<(Self, Self)>
pub fn div(self, other: &Self, rem: bool) -> Option<(Self, Self)>
Divides an n + m
limb self by a n
limb other
. The result is a m + 1
limb
quotient and a n
limb remainder, if enabled by passing true
in rem
argument, both
in the form of an option’s Ok
.
- requires
other
to be stripped and have no leading zeros. - requires
self
to be stripped and have no leading zeros. - requires
other
to have at least two limbs. - requires
self
to have a greater length compared toother
.
All arguments are examined without being stripped for the above conditions. If any of
the above fails, None
is returned.`
Taken from “The Art of Computer Programming” by D.E. Knuth, vol 2, chapter 4.
Trait Implementations
sourceimpl Ord for BigUint
impl Ord for BigUint
sourceimpl PartialOrd<BigUint> for BigUint
impl PartialOrd<BigUint> for BigUint
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Eq for BigUint
Auto Trait Implementations
impl RefUnwindSafe for BigUint
impl Send for BigUint
impl Sync for BigUint
impl Unpin for BigUint
impl UnwindSafe for BigUint
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
sourcefn saturated_from<T>(t: T) -> Self where
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Self where
Self: UniqueSaturatedFrom<T>,
Convert from a value of T
into an equivalent instance of Self
. Read more
sourcefn saturated_into<T>(self) -> T where
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> T where
Self: UniqueSaturatedInto<T>,
Consume self to return an equivalent value of T
. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T, S> UniqueSaturatedInto<T> for S where
T: Bounded,
S: TryInto<T>,
impl<T, S> UniqueSaturatedInto<T> for S where
T: Bounded,
S: TryInto<T>,
sourcefn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
Consume self to return an equivalent value of T
.