Uint

Struct Uint 

Source
pub struct Uint<const N: usize> { /* private fields */ }
Expand description

Stack-allocated big unsigned integer.

Generic over number N of Limbs.

Implementations§

Source§

impl<const N: usize> Uint<N>

Source

pub const fn new(limbs: [Limb; N]) -> Self

Create a new Uint from the provided limbs (constant).

Source

pub const fn as_limbs(&self) -> &Limbs<N>

Returns reference to the inner Limbs array (constant).

Source

pub const fn into_limbs(self) -> Limbs<N>

Returns inner Limbs array (constant).

Source

pub const fn ge(&self, rhs: &Self) -> bool

Checks self is greater or equal then rhs (constant).

Source

pub const fn gt(&self, rhs: &Self) -> bool

Checks self is greater then rhs (constant).

Source

pub const fn le(&self, rhs: &Self) -> bool

Checks self is less or equal then rhs (constant).

Source

pub const fn lt(&self, rhs: &Self) -> bool

Checks self is less then rhs (constant).

Source

pub const fn is_zero(&self) -> bool

Checks self is zero (constant).

Source

pub const fn eq(&self, rhs: &Self) -> bool

Checks if self is equal to rhs (constant).

Source

pub const fn ne(&self, rhs: &Self) -> bool

Checks if self is not equal to rhs (constant).

Source

pub const fn get_bit(&self, i: usize) -> bool

Find the i-th bit of self.

Source

pub fn checked_mul2_assign(&mut self) -> bool

Multiplies self by 2 in-place, returning whether overflow occurred.

Source

pub fn div2_assign(&mut self)

Divide self by 2 in-place.

Source

pub const fn checked_sub(self, rhs: &Self) -> (Self, bool)

Subtract rhs from self, returning the result and whether overflow occurred (constant).

Source

pub const fn wrapping_sub(&self, rhs: &Self) -> Self

Subtract rhs from self, returning the result wrapping around the lower boundary (constant).

Source

pub const fn checked_add(self, rhs: &Self) -> (Self, bool)

Add rhs to self, returning the result and whether overflow occurred (constant).

Source

pub fn checked_add_assign(&mut self, rhs: &Self) -> bool

Add rhs to self in-place, returning whether overflow occurred.

Source

pub fn checked_sub_assign(&mut self, rhs: &Self) -> bool

Subtract rhs from self in-place, returning whether overflow occurred.

Source

pub const fn widening_mul(&self, rhs: &Self) -> (Self, Self)

Compute “wide” multiplication, with a product twice the size of the input.

Returns a tuple containing the (lo, hi) components of the product.

Basic multiplication algorithm described in wiki. It is fast enough for runtime use when optimized with loop “unrolls”, like const_for_unroll6.

Source

pub const fn mul(&self, rhs: &Self) -> Self

Multiply two numbers and panic on overflow.

Source

pub const fn add(&self, rhs: &Self) -> Self

Add two numbers and panic on overflow.

Source

pub const fn wrapping_add(&self, rhs: &Self) -> Self

Add two numbers wrapping around the upper boundary.

Source

pub const fn adc(&self, rhs: &Uint<N>, carry: bool) -> (Self, bool)

Computes a + b + carry, returning the result along with the new carry.

Source

pub const fn from_le_slice(bytes: &[u8]) -> Self

Create a new Uint from the provided little endian bytes.

Source

pub const fn from_uint<const N2: usize>(value: Uint<N2>) -> Self

Construct Self from the other Uint of different size (constant).

§Panics
  • If value is bigger than Self maximum size.
Source§

impl<const N: usize> Uint<N>

Source

pub const fn from_u8(val: u8) -> Self

Create a Uint from u8 integer (constant).

Source§

impl<const N: usize> Uint<N>

Source

pub const fn from_u16(val: u16) -> Self

Create a Uint from u16 integer (constant).

Source§

impl<const N: usize> Uint<N>

Source

pub const fn from_u32(val: u32) -> Self

Create a Uint from u32 integer (constant).

Source§

impl<const N: usize> Uint<N>

Source

pub const fn from_u64(val: u64) -> Self

Create a Uint from u64 integer (constant).

Source§

impl<const N: usize> Uint<N>

Source

pub const fn from_usize(val: usize) -> Self

Create a Uint from usize integer (constant).

Source§

impl<const N: usize> Uint<N>

Source

pub const fn from_u128(val: u128) -> Self

Create a Uint from a u128 integer (constant).

Source§

impl<const N: usize> Uint<N>

Source

pub const fn into_u8(self) -> u8

Create a u8 integer from Uint (constant).

§Panics
  • If Uint type is too large to fit into primitive integer.
Source§

impl<const N: usize> Uint<N>

Source

pub const fn into_u16(self) -> u16

Create a u16 integer from Uint (constant).

§Panics
  • If Uint type is too large to fit into primitive integer.
Source§

impl<const N: usize> Uint<N>

Source

pub const fn into_u32(self) -> u32

Create a u32 integer from Uint (constant).

§Panics
  • If Uint type is too large to fit into primitive integer.
Source§

impl<const N: usize> Uint<N>

Source

pub const fn into_u64(self) -> u64

Create a u64 integer from Uint (constant).

§Panics
  • If Uint type is too large to fit into primitive integer.
Source§

impl<const N: usize> Uint<N>

Source

pub const fn into_usize(self) -> usize

Create a usize integer from Uint (constant).

§Panics
  • If Uint type is too large to fit into primitive integer.
Source§

impl<const N: usize> Uint<N>

Source

pub const fn into_u128(self) -> u128

Create a u128 integer from Uint (constant).

§Panics
  • If Uint type is too large to fit into primitive integer.

Trait Implementations§

Source§

impl<const N: usize> AsMut<[u64]> for Uint<N>

Source§

fn as_mut(&mut self) -> &mut [u64]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<const N: usize> AsRef<[u64]> for Uint<N>

Source§

fn as_ref(&self) -> &[u64]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<const N: usize> BigInteger for Uint<N>

Source§

const LIMB_BITS: usize = 64usize

Number of bits in a limb.
Source§

const MAX: Self

The largest value that can be represented by this integer type.
Source§

const NUM_LIMBS: usize = N

Number of usize limbs representing Self.
Source§

const ONE: Self

The multiplicative identity element of Self, 1.
Source§

const ZERO: Self

The additive identity element of Self, 0.
Source§

fn is_odd(&self) -> bool

Returns true if this number is odd. Read more
Source§

fn is_even(&self) -> bool

Returns true if this number is even. Read more
Source§

fn is_zero(&self) -> bool

Returns true if this number is zero. Read more
Source§

fn num_bits(&self) -> usize

Return the minimum number of bits needed to encode this number. Read more
Source§

fn get_bit(&self, i: usize) -> bool

Find the i-th bit of self. Read more
Source§

fn from_bytes_le(bytes: &[u8]) -> Self

Create bigint from little-endian bytes. Read more
Source§

fn into_bytes_le(self) -> Vec<u8>

Convert bigint to little-endian bytes.
Source§

const BITS: usize = _

Number of bits in the integer.
Source§

const BYTES: usize = _

Number of bytes in the integer.
Source§

impl<B: Borrow<Self>, const N: usize> BitAnd<B> for Uint<N>

Source§

type Output = Uint<N>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: B) -> Self::Output

Performs the & operation. Read more
Source§

impl<B: Borrow<Self>, const N: usize> BitAndAssign<B> for Uint<N>

Source§

fn bitand_assign(&mut self, rhs: B)

Performs the &= operation. Read more
Source§

impl<const N: usize> BitIteratorBE for Uint<N>

Source§

fn bit_be_iter(self) -> impl Iterator<Item = bool>

Returns an iterator over the bits of the integer, starting from the most significant bit.
Source§

fn bit_be_trimmed_iter(self) -> impl Iterator<Item = bool>

Returns an iterator over the bits of the integer, starting from the most significant bit, and without leading zeroes.
Source§

impl<B: Borrow<Self>, const N: usize> BitOr<B> for Uint<N>

Source§

type Output = Uint<N>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: B) -> Self::Output

Performs the | operation. Read more
Source§

impl<B: Borrow<Self>, const N: usize> BitOrAssign<B> for Uint<N>

Source§

fn bitor_assign(&mut self, rhs: B)

Performs the |= operation. Read more
Source§

impl<B: Borrow<Self>, const N: usize> BitXor<B> for Uint<N>

Source§

type Output = Uint<N>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: B) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<B: Borrow<Self>, const N: usize> BitXorAssign<B> for Uint<N>

Source§

fn bitxor_assign(&mut self, rhs: B)

Performs the ^= operation. Read more
Source§

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

Source§

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

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 N: usize> Debug for Uint<N>

Source§

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

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

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

Source§

fn default() -> Self

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

impl<const N: usize> Display for Uint<N>

Source§

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

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

impl<P: FpParams<N>, const N: usize> From<Fp<P, N>> for Uint<N>

Source§

fn from(fp: Fp<P, N>) -> Self

Converts to this type from the input type.
Source§

impl<P: FpParams<N>, const N: usize> From<Uint<N>> for Fp<P, N>

Source§

fn from(int: Uint<N>) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<Uint<N>> for u128

Source§

fn from(val: Uint<N>) -> u128

Converts to this type from the input type.
Source§

impl<const N: usize> From<Uint<N>> for u16

Source§

fn from(val: Uint<N>) -> u16

Converts to this type from the input type.
Source§

impl<const N: usize> From<Uint<N>> for u32

Source§

fn from(val: Uint<N>) -> u32

Converts to this type from the input type.
Source§

impl<const N: usize> From<Uint<N>> for u64

Source§

fn from(val: Uint<N>) -> u64

Converts to this type from the input type.
Source§

impl<const N: usize> From<Uint<N>> for u8

Source§

fn from(val: Uint<N>) -> u8

Converts to this type from the input type.
Source§

impl<const N: usize> From<Uint<N>> for usize

Source§

fn from(val: Uint<N>) -> usize

Converts to this type from the input type.
Source§

impl<const N: usize> From<u128> for Uint<N>

Source§

fn from(val: u128) -> Uint<N>

Converts to this type from the input type.
Source§

impl<const N: usize> From<u16> for Uint<N>

Source§

fn from(val: u16) -> Uint<N>

Converts to this type from the input type.
Source§

impl<const N: usize> From<u32> for Uint<N>

Source§

fn from(val: u32) -> Uint<N>

Converts to this type from the input type.
Source§

impl<const N: usize> From<u64> for Uint<N>

Source§

fn from(val: u64) -> Uint<N>

Converts to this type from the input type.
Source§

impl<const N: usize> From<u8> for Uint<N>

Source§

fn from(val: u8) -> Uint<N>

Converts to this type from the input type.
Source§

impl<const N: usize> From<usize> for Uint<N>

Source§

fn from(val: usize) -> Uint<N>

Converts to this type from the input type.
Source§

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

Source§

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

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 N: usize> Not for Uint<N>

Source§

type Output = Uint<N>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

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

Source§

fn cmp(&self, rhs: &Self) -> 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 N: usize> PartialEq for Uint<N>

Source§

fn eq(&self, other: &Uint<N>) -> 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 N: usize> PartialOrd for Uint<N>

Source§

fn partial_cmp(&self, rhs: &Self) -> 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 N: usize> Shl<u32> for Uint<N>

Source§

type Output = Uint<N>

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: u32) -> Self::Output

Performs the << operation. Read more
Source§

impl<const N: usize> ShlAssign<u32> for Uint<N>

Source§

fn shl_assign(&mut self, rhs: u32)

Performs the <<= operation. Read more
Source§

impl<const N: usize> Shr<u32> for Uint<N>

Source§

type Output = Uint<N>

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: u32) -> Self::Output

Performs the >> operation. Read more
Source§

impl<const N: usize> ShrAssign<u32> for Uint<N>

Source§

fn shr_assign(&mut self, rhs: u32)

Performs the >>= operation. Read more
Source§

impl<const N: usize> UpperHex for Uint<N>

Source§

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

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

impl<const N: usize> Zeroize for Uint<N>

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
Source§

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

Source§

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

Source§

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

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> Same for T

Source§

type Output = T

Should always be Self
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.