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

§

type Output = Uint<LEN>

The resulting type after applying the & operator.
source§

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

Performs the & operation. Read more
source§

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

source§

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

Performs the &= operation. Read more
source§

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

§

type Output = Uint<LEN>

The resulting type after applying the | operator.
source§

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

Performs the | operation. Read more
source§

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

source§

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

Performs the |= operation. Read more
source§

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

§

type Output = Uint<LEN>

The resulting type after applying the ^ operator.
source§

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

Performs the ^ operation. Read more
source§

impl<const LEN: usize> BitXorAssign<Uint<LEN>> 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 copy 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>

§

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) -> Selfwhere Self: Sized,

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

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

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

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

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

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

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<const LEN: usize> PartialOrd<Uint<LEN>> 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

This method 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

This method 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

This method 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

This method 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> StructuralEq for Uint<LEN>

source§

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

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.