Struct Uint

Source
pub struct Uint<const LEN: usize>(pub [u64; LEN]);
Expand description

A static length bigint based on an array of u64s.

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>

These functions directly correspond to the Rust standard unsigned integers.

Source

pub const fn from_u64_array(x: [u64; LEN]) -> Uint<LEN>

Source

pub const fn to_u64_array(self) -> [u64; LEN]

Source

pub const fn zero() -> Uint<LEN>

Source

pub const fn max_value() -> Uint<LEN>

Source

pub const fn one() -> Uint<LEN>

Source

pub const fn is_zero(self) -> bool

Source

pub const fn const_not(self) -> Uint<LEN>

Source

pub const fn const_or(self, rhs: Uint<LEN>) -> Uint<LEN>

Source

pub const fn const_and(self, rhs: Uint<LEN>) -> Uint<LEN>

Source

pub const fn const_xor(self, rhs: Uint<LEN>) -> Uint<LEN>

Source

pub const fn overflowing_add(self, rhs: Uint<LEN>) -> (Uint<LEN>, bool)

Source

pub const fn wrapping_add(self, rhs: Uint<LEN>) -> Uint<LEN>

Source

pub const fn checked_add(self, rhs: Uint<LEN>) -> Option<Uint<LEN>>

Source

pub const fn overflowing_sub(self, rhs: Uint<LEN>) -> (Uint<LEN>, bool)

Source

pub const fn wrapping_sub(self, rhs: Uint<LEN>) -> Uint<LEN>

Source

pub const fn checked_sub(self, rhs: Uint<LEN>) -> Option<Uint<LEN>>

Source

pub const fn overflowing_mul(self, rhs: Uint<LEN>) -> (Uint<LEN>, bool)

Source

pub const fn wrapping_mul(self, rhs: Uint<LEN>) -> Uint<LEN>

Source

pub const fn checked_mul(self, rhs: Uint<LEN>) -> Option<Uint<LEN>>

Source

pub const fn checked_shl(self, s: usize) -> Option<Uint<LEN>>

Source

pub const fn checked_shr(self, s: usize) -> Option<Uint<LEN>>

Source

pub const fn checked_rotl(self, s: usize) -> Option<Uint<LEN>>

§Panics

If s >= Self::bw()

Source§

impl<const LEN: usize> Uint<LEN>

special functions

Source

pub const fn bw() -> usize

Returns the bitwidth of Self

Source

pub const fn lsb(&self) -> bool

Returns the least significant bit

Source

pub const fn msb(&self) -> bool

Returns the most significant bit

Source

pub const fn lz(&self) -> usize

Returns the number of leading zero bits

Source

pub const fn tz(&self) -> usize

Returns the number of trailing zero bits

Source

pub const fn count_ones(&self) -> usize

Returns the number of set ones

Source

pub const fn sig_bits(&self) -> usize

Returns the number of significant bits

Source

pub const fn sig_digits(&self) -> usize

Returns the number of significant u64 digits

Source

pub const fn const_eq(&self, rhs: &Uint<LEN>) -> bool

Equality comparison

Source

pub const fn const_lt(&self, rhs: &Uint<LEN>) -> bool

Less-than comparison

Source

pub const fn const_le(&self, rhs: &Uint<LEN>) -> bool

Less-or-equal comparison

Source

pub const fn const_gt(&self, rhs: &Uint<LEN>) -> bool

Greater-than comparison

Source

pub const fn const_ge(&self, rhs: &Uint<LEN>) -> bool

Greater-or-equal comparison

Source

pub const fn resize_to_u64(&self) -> u64

Source

pub const fn from_u64(x: u64) -> Uint<LEN>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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()

Source

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().

Source

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> BitAnd for Uint<LEN>

Source§

type Output = Uint<LEN>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Uint<LEN>) -> <Uint<LEN> as BitAnd>::Output

Performs the & operation. Read more
Source§

impl<const LEN: usize> BitAndAssign for Uint<LEN>

Source§

fn bitand_assign(&mut self, rhs: Uint<LEN>)

Performs the &= operation. Read more
Source§

impl<const LEN: usize> BitOr for Uint<LEN>

Source§

type Output = Uint<LEN>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Uint<LEN>) -> <Uint<LEN> as BitOr>::Output

Performs the | operation. Read more
Source§

impl<const LEN: usize> BitOrAssign for Uint<LEN>

Source§

fn bitor_assign(&mut self, rhs: Uint<LEN>)

Performs the |= operation. Read more
Source§

impl<const LEN: usize> BitXor for Uint<LEN>

Source§

type Output = Uint<LEN>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Uint<LEN>) -> <Uint<LEN> as BitXor>::Output

Performs the ^ operation. Read more
Source§

impl<const LEN: usize> BitXorAssign for Uint<LEN>

Source§

fn bitxor_assign(&mut self, rhs: Uint<LEN>)

Performs the ^= operation. Read more
Source§

impl<const LEN: usize> Clone for Uint<LEN>

Source§

fn clone(&self) -> Uint<LEN>

Returns a duplicate 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<const LEN: usize> Debug for Uint<LEN>

Source§

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

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

impl<const LEN: usize> Default for Uint<LEN>

Source§

fn default() -> Uint<LEN>

Returns the “default value” for a type. Read more
Source§

impl<const LEN: usize> Hash for Uint<LEN>

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<const LEN: usize> Not for Uint<LEN>

Source§

type Output = Uint<LEN>

The resulting type after applying the ! operator.
Source§

fn not(self) -> <Uint<LEN> as Not>::Output

Performs the unary ! operation. Read more
Source§

impl<const LEN: usize> Ord for Uint<LEN>

Source§

fn cmp(&self, other: &Uint<LEN>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<const LEN: usize> PartialEq for Uint<LEN>

Source§

fn eq(&self, other: &Uint<LEN>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const LEN: usize> PartialOrd for Uint<LEN>

Source§

fn partial_cmp(&self, other: &Uint<LEN>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<const LEN: usize> Copy for Uint<LEN>

Source§

impl<const LEN: usize> Eq for Uint<LEN>

Source§

impl<const LEN: usize> StructuralPartialEq for Uint<LEN>

Auto Trait Implementations§

§

impl<const LEN: usize> Freeze for Uint<LEN>

§

impl<const LEN: usize> RefUnwindSafe for Uint<LEN>

§

impl<const LEN: usize> Send for Uint<LEN>

§

impl<const LEN: usize> Sync for Uint<LEN>

§

impl<const LEN: usize> Unpin for Uint<LEN>

§

impl<const LEN: usize> UnwindSafe for Uint<LEN>

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.