pub struct BigUint { /* private fields */ }
Expand description
Simple wrapper around an infinitely large integer, represented as limbs of Single
.
Implementations§
source§impl BigUint
impl BigUint
sourcepub fn with_capacity(size: usize) -> BigUint
pub fn with_capacity(size: usize) -> BigUint
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: &[u32]) -> BigUint
pub fn from_limbs(limbs: &[u32]) -> BigUint
Raw constructor from custom limbs. If limbs
is empty, Zero::zero()
implementation is
used.
sourcepub fn get(&self, index: usize) -> u32
pub fn get(&self, index: usize) -> u32
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<u32>
pub fn checked_get(&self, index: usize) -> Option<u32>
A naive getter for limb at index
. Note that the order is lsb -> msb.
sourcepub fn set(&mut self, index: usize, value: u32)
pub fn set(&mut self, index: usize, value: u32)
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) -> u32
pub fn lsb(&self) -> u32
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) -> u32
pub fn msb(&self) -> u32
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: &BigUint) -> BigUint
pub fn add(self, other: &BigUint) -> BigUint
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: &BigUint) -> Result<BigUint, BigUint>
pub fn sub(self, other: &BigUint) -> Result<BigUint, BigUint>
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: &BigUint) -> BigUint
pub fn mul(self, other: &BigUint) -> BigUint
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: u32) -> BigUint
pub fn div_unit(self, other: u32) -> BigUint
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: &BigUint, rem: bool) -> Option<(BigUint, BigUint)>
pub fn div(self, other: &BigUint, rem: bool) -> Option<(BigUint, BigUint)>
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§
source§impl Decode for BigUint
impl Decode for BigUint
source§fn decode<__CodecInputEdqy>(
__codec_input_edqy: &mut __CodecInputEdqy,
) -> Result<BigUint, Error>where
__CodecInputEdqy: Input,
fn decode<__CodecInputEdqy>(
__codec_input_edqy: &mut __CodecInputEdqy,
) -> Result<BigUint, Error>where
__CodecInputEdqy: Input,
source§fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>,
) -> Result<DecodeFinished, Error>where
I: Input,
fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>,
) -> Result<DecodeFinished, Error>where
I: Input,
source§impl Encode for BigUint
impl Encode for BigUint
source§fn size_hint(&self) -> usize
fn size_hint(&self) -> usize
source§fn encode_to<__CodecOutputEdqy>(
&self,
__codec_dest_edqy: &mut __CodecOutputEdqy,
)
fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy, )
source§fn using_encoded<__CodecOutputReturn, __CodecUsingEncodedCallback>(
&self,
f: __CodecUsingEncodedCallback,
) -> __CodecOutputReturn
fn using_encoded<__CodecOutputReturn, __CodecUsingEncodedCallback>( &self, f: __CodecUsingEncodedCallback, ) -> __CodecOutputReturn
source§fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
source§impl Ord for BigUint
impl Ord for BigUint
source§impl PartialOrd for BigUint
impl PartialOrd for BigUint
impl EncodeLike for BigUint
impl Eq for BigUint
Auto Trait Implementations§
impl Freeze for BigUint
impl RefUnwindSafe for BigUint
impl Send for BigUint
impl Sync for BigUint
impl Unpin for BigUint
impl UnwindSafe for BigUint
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> CheckedConversion for T
impl<T> CheckedConversion for T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> DecodeLimit for Twhere
T: Decode,
impl<T> DecodeLimit for Twhere
T: Decode,
source§impl<T, S> EnsureFrom<S> for T
impl<T, S> EnsureFrom<S> for T
source§fn ensure_from(other: T) -> Result<Self, ArithmeticError>
fn ensure_from(other: T) -> Result<Self, ArithmeticError>
ArithmeticError
if fails. Read moresource§impl<T, S> EnsureInto<S> for T
impl<T, S> EnsureInto<S> for T
source§fn ensure_into(self) -> Result<T, ArithmeticError>
fn ensure_into(self) -> Result<T, ArithmeticError>
ArithmeticError
if fails. Read moresource§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T, Outer> IsWrappedBy<Outer> for T
impl<T, Outer> IsWrappedBy<Outer> for T
source§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
source§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
source§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
T
. Read moresource§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
source§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from
.source§impl<T, S> UniqueSaturatedInto<T> for S
impl<T, S> UniqueSaturatedInto<T> for S
source§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
T
.