Struct u64_array_bigints::Uint
source · pub struct Uint<const LEN: usize>(pub [u64; LEN]);
Expand description
A static length bigint based on an array of u64
s.
Note: LEN
must satisfy LEN > 0
and (LEN * 64usize) <= (isize::MAX as usize)
. Users should preferrably use from_u64_array
instead of direct
tuple struct construction of the Uint
, because the invariants are checked
automatically by from_u64_array
and prevents later panics.
Tuple Fields§
§0: [u64; LEN]
Implementations§
source§impl<const LEN: usize> Uint<LEN>
impl<const LEN: usize> Uint<LEN>
These functions directly correspond to the Rust standard unsigned integers.
pub const fn from_u64_array(x: [u64; LEN]) -> Uint<LEN>
pub const fn to_u64_array(self) -> [u64; LEN]
pub const fn zero() -> Uint<LEN>
pub const fn max_value() -> Uint<LEN>
pub const fn one() -> Uint<LEN>
pub const fn is_zero(self) -> bool
pub const fn const_not(self) -> Uint<LEN>
pub const fn const_or(self, rhs: Uint<LEN>) -> Uint<LEN>
pub const fn const_and(self, rhs: Uint<LEN>) -> Uint<LEN>
pub const fn const_xor(self, rhs: Uint<LEN>) -> Uint<LEN>
pub const fn overflowing_add(self, rhs: Uint<LEN>) -> (Uint<LEN>, bool)
pub const fn wrapping_add(self, rhs: Uint<LEN>) -> Uint<LEN>
pub const fn checked_add(self, rhs: Uint<LEN>) -> Option<Uint<LEN>>
pub const fn overflowing_sub(self, rhs: Uint<LEN>) -> (Uint<LEN>, bool)
pub const fn wrapping_sub(self, rhs: Uint<LEN>) -> Uint<LEN>
pub const fn checked_sub(self, rhs: Uint<LEN>) -> Option<Uint<LEN>>
pub const fn overflowing_mul(self, rhs: Uint<LEN>) -> (Uint<LEN>, bool)
pub const fn wrapping_mul(self, rhs: Uint<LEN>) -> Uint<LEN>
pub const fn checked_mul(self, rhs: Uint<LEN>) -> Option<Uint<LEN>>
pub const fn checked_shl(self, s: usize) -> Option<Uint<LEN>>
pub const fn checked_shr(self, s: usize) -> Option<Uint<LEN>>
source§impl<const LEN: usize> Uint<LEN>
impl<const LEN: usize> Uint<LEN>
special functions
sourcepub const fn count_ones(&self) -> usize
pub const fn count_ones(&self) -> usize
Returns the number of set ones
sourcepub const fn sig_digits(&self) -> usize
pub const fn sig_digits(&self) -> usize
Returns the number of significant u64
digits
pub const fn resize_to_u64(&self) -> u64
pub const fn from_u64(x: u64) -> Uint<LEN>
sourcepub const fn overflowing_short_cin_mul(
self,
cin: u64,
rhs: u64
) -> (Uint<LEN>, u64)
pub const fn overflowing_short_cin_mul( self, cin: u64, rhs: u64 ) -> (Uint<LEN>, u64)
Returns a tuple of cin + (self * rhs)
and the overflow. The
intermediates are effectively zero extended.
sourcepub const fn overflowing_short_mul_add(
self,
lhs: Uint<LEN>,
rhs: u64
) -> (Uint<LEN>, bool)
pub const fn overflowing_short_mul_add( self, lhs: Uint<LEN>, rhs: u64 ) -> (Uint<LEN>, bool)
Returns self + (lhs * rhs)
and if overflow occured. The
intermediates are effectively zero extended.
sourcepub const fn overflowing_mul_add(
self,
lhs: Uint<LEN>,
rhs: Uint<LEN>
) -> (Uint<LEN>, bool)
pub const fn overflowing_mul_add( self, lhs: Uint<LEN>, rhs: Uint<LEN> ) -> (Uint<LEN>, bool)
Returns a tuple of self + (lhs * rhs)
and if overflow occured.
sourcepub const fn checked_short_divide(self, div: u64) -> Option<(Uint<LEN>, u64)>
pub const fn checked_short_divide(self, div: u64) -> Option<(Uint<LEN>, u64)>
Returns a tuple of the quotient and remainder of self
divided by
div
. div
is zero extended. Returns None
if div == 0
.
sourcepub const fn panicking_short_divide(self, div: u64) -> (Uint<LEN>, u64)
pub const fn panicking_short_divide(self, div: u64) -> (Uint<LEN>, u64)
because unwrap
is not const
on stable, this exists for
checked_short_divide(..).unwrap()
sourcepub const fn divide(self, div: Uint<LEN>) -> Option<(Uint<LEN>, Uint<LEN>)>
pub const fn divide(self, div: Uint<LEN>) -> Option<(Uint<LEN>, Uint<LEN>)>
Divides self
by div
and returns a tuple of the quotient to and
remainder. Returns None
if div.is_zero()
.
sourcepub fn rand_using<R>(rng: &mut R) -> Uint<LEN>where
R: RngCore,
pub fn rand_using<R>(rng: &mut R) -> Uint<LEN>where R: RngCore,
Randomly-assigns self
using a rand_core::RngCore
random number
generator
Trait Implementations§
source§impl<const LEN: usize> BitAndAssign<Uint<LEN>> for Uint<LEN>
impl<const LEN: usize> BitAndAssign<Uint<LEN>> for Uint<LEN>
source§fn bitand_assign(&mut self, rhs: Uint<LEN>)
fn bitand_assign(&mut self, rhs: Uint<LEN>)
&=
operation. Read moresource§impl<const LEN: usize> BitOrAssign<Uint<LEN>> for Uint<LEN>
impl<const LEN: usize> BitOrAssign<Uint<LEN>> for Uint<LEN>
source§fn bitor_assign(&mut self, rhs: Uint<LEN>)
fn bitor_assign(&mut self, rhs: Uint<LEN>)
|=
operation. Read moresource§impl<const LEN: usize> BitXorAssign<Uint<LEN>> for Uint<LEN>
impl<const LEN: usize> BitXorAssign<Uint<LEN>> for Uint<LEN>
source§fn bitxor_assign(&mut self, rhs: Uint<LEN>)
fn bitxor_assign(&mut self, rhs: Uint<LEN>)
^=
operation. Read moresource§impl<const LEN: usize> Ord for Uint<LEN>
impl<const LEN: usize> Ord for Uint<LEN>
source§impl<const LEN: usize> PartialEq<Uint<LEN>> for Uint<LEN>
impl<const LEN: usize> PartialEq<Uint<LEN>> for Uint<LEN>
source§impl<const LEN: usize> PartialOrd<Uint<LEN>> for Uint<LEN>
impl<const LEN: usize> PartialOrd<Uint<LEN>> for Uint<LEN>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more