pub struct u256(/* private fields */);Expand description
Large integer type
The type is composed of little-endian ordered 64-bit words, which represents its inner representation.
Implementations§
Source§impl u256
impl u256
Sourcepub fn as_mut_ptr(&mut self) -> *mut u64
pub fn as_mut_ptr(&mut self) -> *mut u64
Converts the object to a mutable raw pointer
Sourcepub const fn as_inner(&self) -> &[u64; 4]
pub const fn as_inner(&self) -> &[u64; 4]
Returns the underlying array of words constituting large integer
Sourcepub const fn into_inner(self) -> [u64; 4]
pub const fn into_inner(self) -> [u64; 4]
Returns the underlying array of words constituting large integer
Sourcepub const fn from_inner(array: [u64; 4]) -> Self
pub const fn from_inner(array: [u64; 4]) -> Self
Constructs integer type from the underlying array of words.
Source§impl u256
impl u256
Sourcepub const fn bit(&self, index: usize) -> bool
pub const fn bit(&self, index: usize) -> bool
Returns whether specific bit number is set to 1 or not
Sourcepub fn leading_ones(&self) -> u32
pub fn leading_ones(&self) -> u32
Returns the number of leading ones in the binary representation of
self.
Sourcepub fn leading_zeros(&self) -> u32
pub fn leading_zeros(&self) -> u32
Returns the number of leading zeros in the binary representation of
self.
Sourcepub fn trailing_ones(&self) -> u32
pub fn trailing_ones(&self) -> u32
Returns the number of trailing ones in the binary representation of
self.
Sourcepub fn trailing_zeros(&self) -> u32
pub fn trailing_zeros(&self) -> u32
Returns the number of trailing zeros in the binary representation of
self.
pub fn is_zero(&self) -> bool
pub fn is_positive(&self) -> bool
pub fn abs(self) -> u256
Sourcepub fn from_be_bytes(bytes: [u8; 32]) -> u256
pub fn from_be_bytes(bytes: [u8; 32]) -> u256
Creates the integer value from a byte array using big-endian encoding
Sourcepub fn from_be_slice(bytes: &[u8]) -> Result<u256, ParseLengthError>
pub fn from_be_slice(bytes: &[u8]) -> Result<u256, ParseLengthError>
Creates the integer value from a byte slice using big-endian encoding
Sourcepub fn from_le_bytes(bytes: [u8; 32]) -> u256
pub fn from_le_bytes(bytes: [u8; 32]) -> u256
Creates the integer value from a byte array using little-endian encoding
Sourcepub fn from_le_slice(bytes: &[u8]) -> Result<u256, ParseLengthError>
pub fn from_le_slice(bytes: &[u8]) -> Result<u256, ParseLengthError>
Creates the integer value from a byte slice using little-endian encoding
Sourcepub fn to_be_bytes(self) -> [u8; 32]
pub fn to_be_bytes(self) -> [u8; 32]
Convert the integer into a byte array using big-endian encoding
Sourcepub fn to_le_bytes(self) -> [u8; 32]
pub fn to_le_bytes(self) -> [u8; 32]
Convert a integer into a byte array using little-endian encoding
Source§impl u256
impl u256
Sourcepub fn checked_add<T>(self, other: T) -> Option<u256>
pub fn checked_add<T>(self, other: T) -> Option<u256>
Checked integer addition. Computes self + rhs, returning None if
overflow occurred.
Sourcepub fn saturating_add<T>(self, other: T) -> u256
pub fn saturating_add<T>(self, other: T) -> u256
Saturating integer addition. Computes self + rhs, saturating at the
numeric bounds instead of overflowing.
Sourcepub fn overflowing_add<T>(self, other: T) -> (u256, bool)
pub fn overflowing_add<T>(self, other: T) -> (u256, bool)
Calculates self + rhs
Returns a tuple of the addition along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.
Sourcepub fn wrapping_add<T>(self, other: T) -> u256
pub fn wrapping_add<T>(self, other: T) -> u256
Wrapping (modular) addition. Computes self + rhs, wrapping around at
the boundary of the type.
Sourcepub fn checked_sub<T>(self, other: T) -> Option<u256>
pub fn checked_sub<T>(self, other: T) -> Option<u256>
Checked integer subtraction. Computes self - rhs, returning None if
overflow occurred.
Sourcepub fn saturating_sub<T>(self, other: T) -> u256
pub fn saturating_sub<T>(self, other: T) -> u256
Saturating integer subtraction. Computes self - rhs, saturating at the
numeric bounds instead of overflowing.
Sourcepub fn overflowing_sub<T>(self, other: T) -> (u256, bool)
pub fn overflowing_sub<T>(self, other: T) -> (u256, bool)
Calculates self - rhs
Returns a tuple of the subtraction along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.
Sourcepub fn wrapping_sub<T>(self, other: T) -> u256
pub fn wrapping_sub<T>(self, other: T) -> u256
Wrapping (modular) subtraction. Computes self - rhs, wrapping around
at the boundary of the type.
Sourcepub fn checked_mul<T>(self, other: T) -> Option<u256>
pub fn checked_mul<T>(self, other: T) -> Option<u256>
Checked integer multiplication. Computes self * rhs, returning None
if overflow occurred.
Sourcepub fn saturating_mul<T>(self, other: T) -> u256
pub fn saturating_mul<T>(self, other: T) -> u256
Saturating integer multiplication. Computes self * rhs, saturating at
the numeric bounds instead of overflowing.
Sourcepub fn wrapping_mul<T>(self, other: T) -> u256
pub fn wrapping_mul<T>(self, other: T) -> u256
Wrapping (modular) multiplication. Computes self * rhs, wrapping
around at the boundary of the type.
Sourcepub fn overflowing_div<T>(self, other: T) -> (u256, bool)
pub fn overflowing_div<T>(self, other: T) -> (u256, bool)
Calculates self / rhs
Returns a tuple of the divisor along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.
Sourcepub fn wrapping_div<T>(self, other: T) -> u256
pub fn wrapping_div<T>(self, other: T) -> u256
Wrapping (modular) division. Calculates self / rhs,
wrapping around at the boundary of the type.
The only case where such wrapping can occur is when one divides
MIN / -1 on a signed type (where MIN is the negative minimal value for
the type); this is equivalent to -MIN, a positive value that is
too large to represent in the type.
In such a case, this function returns MIN itself.
Sourcepub fn checked_div<T>(self, other: T) -> Option<u256>
pub fn checked_div<T>(self, other: T) -> Option<u256>
Checked integer division. Computes self / rhs,
returning None if rhs == 0 or the division results in overflow.
Sourcepub fn saturating_div<T>(self, other: T) -> u256
pub fn saturating_div<T>(self, other: T) -> u256
Saturating integer division. Computes self / rhs,
saturating at the numeric bounds instead of overflowing.
Sourcepub fn overflowing_rem<T>(self, other: T) -> (u256, bool)
pub fn overflowing_rem<T>(self, other: T) -> (u256, bool)
Calculates the remainder when self is divided by rhs.
Returns a tuple of the remainder after dividing along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would occur then 0 is returned.
Sourcepub fn wrapping_rem<T>(self, other: T) -> u256
pub fn wrapping_rem<T>(self, other: T) -> u256
Wrapping (modular) remainder. Computes self % rhs, wrapping around at the boundary of the type.
Such wrap-around never actually occurs mathematically; implementation artifacts make x % y invalid for MIN / -1 on a signed type (where MIN is the negative minimal value). In such a case, this function returns 0.
Sourcepub fn checked_rem<T>(self, other: T) -> Option<u256>
pub fn checked_rem<T>(self, other: T) -> Option<u256>
Checked integer remainder. Computes self % rhs,
returning None if rhs == 0 or the division results in overflow.
Sourcepub fn div_euclid<T>(self, other: T) -> u256
pub fn div_euclid<T>(self, other: T) -> u256
Calculates the quotient of Euclidean division of self by rhs.
This computes the integer q such that self = q * rhs + r,
with r = self.rem_euclid(rhs) and 0 <= r < abs(rhs).
In other words, the result is self / rhs rounded to the integer q
such that self >= q * rhs. If self > 0,
this is equal to round towards zero (the default in Rust);
if self < 0, this is equal to round towards +/- infinity.
Sourcepub fn overflowing_div_euclid<T>(self, other: T) -> (u256, bool)
pub fn overflowing_div_euclid<T>(self, other: T) -> (u256, bool)
Calculates the quotient of Euclidean division self.div_euclid(rhs).
Returns a tuple of the divisor along with a boolean indicating
whether an arithmetic overflow would occur.
If an overflow would occur then self is returned.
Sourcepub fn wrapping_div_euclid<T>(self, other: T) -> u256
pub fn wrapping_div_euclid<T>(self, other: T) -> u256
Wrapping Euclidean division. Computes self.div_euclid(rhs),
wrapping around at the boundary of the type.
Wrapping will only occur in MIN / -1 on a signed type
(where MIN is the negative minimal value for the type).
This is equivalent to -MIN, a positive value
that is too large to represent in the type.
In this case, this method returns MIN itself.
Sourcepub fn checked_div_euclid<T>(self, other: T) -> Option<u256>
pub fn checked_div_euclid<T>(self, other: T) -> Option<u256>
Checked Euclidean division. Computes self.div_euclid(rhs),
returning None if rhs == 0 or the division results in overflow.
Sourcepub fn rem_euclid<T>(self, other: T) -> u256
pub fn rem_euclid<T>(self, other: T) -> u256
Calculates the least nonnegative remainder of self (mod rhs).
This is done as if by the Euclidean division algorithm –
given r = self.rem_euclid(rhs), self = rhs * self.div_euclid(rhs) + r, and 0 <= r < abs(rhs).
Sourcepub fn overflowing_rem_euclid<T>(self, other: T) -> (u256, bool)
pub fn overflowing_rem_euclid<T>(self, other: T) -> (u256, bool)
Overflowing Euclidean remainder. Calculates self.rem_euclid(rhs).
Returns a tuple of the remainder after dividing along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would occur then 0 is returned.
Sourcepub fn wrapping_rem_euclid<T>(self, other: T) -> u256
pub fn wrapping_rem_euclid<T>(self, other: T) -> u256
Wrapping Euclidean remainder. Computes self.rem_euclid(rhs),
wrapping around at the boundary of the type.
Wrapping will only occur in MIN % -1 on a signed type
(where MIN is the negative minimal value for the type).
In this case, this method returns 0.
Sourcepub fn checked_rem_euclid<T>(self, other: T) -> Option<u256>
pub fn checked_rem_euclid<T>(self, other: T) -> Option<u256>
Checked Euclidean remainder. Computes self.rem_euclid(rhs),
returning None if rhs == 0 or the division results in overflow.
Sourcepub fn checked_shl(self, rhs: u32) -> Option<u256>
pub fn checked_shl(self, rhs: u32) -> Option<u256>
Checked shift left. Computes self << rhs, returning None if rhs is larger than or equal to the number of bits in self.
Sourcepub fn checked_shr(self, rhs: u32) -> Option<u256>
pub fn checked_shr(self, rhs: u32) -> Option<u256>
Checked shift right. Computes self >> rhs, returning None if rhs is larger than or equal to the number of bits in self.
Sourcepub fn wrapping_neg(self) -> u256
pub fn wrapping_neg(self) -> u256
Wrapping (modular) negation. Computes -self, wrapping around at the boundary of the type. Since unsigned types do not have negative equivalents all applications of this function will wrap (except for -0). For values smaller than the corresponding signed type’s maximum the result is the same as casting the corresponding signed value. Any larger values are equivalent to MAX + 1 - (val - MAX - 1) where MAX is the corresponding signed type’s maximum.
Source§impl u256
impl u256
pub const fn is_negative(&self) -> bool
Sourcepub fn bits_required(&self) -> usize
pub fn bits_required(&self) -> usize
Return the least number of bits needed to represent the number
Trait Implementations§
Source§impl<T> AddAssign<T> for u256
impl<T> AddAssign<T> for u256
Source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
+= operation. Read moreSource§impl<T> BitAndAssign<T> for u256
impl<T> BitAndAssign<T> for u256
Source§fn bitand_assign(&mut self, rhs: T)
fn bitand_assign(&mut self, rhs: T)
&= operation. Read moreSource§impl<T> BitOrAssign<T> for u256
impl<T> BitOrAssign<T> for u256
Source§fn bitor_assign(&mut self, rhs: T)
fn bitor_assign(&mut self, rhs: T)
|= operation. Read moreSource§impl<T> BitXorAssign<T> for u256
impl<T> BitXorAssign<T> for u256
Source§fn bitxor_assign(&mut self, rhs: T)
fn bitxor_assign(&mut self, rhs: T)
^= operation. Read moreSource§impl<T> DivAssign<T> for u256
impl<T> DivAssign<T> for u256
Source§fn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
/= operation. Read moreSource§impl<T> MulAssign<T> for u256
impl<T> MulAssign<T> for u256
Source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
*= operation. Read moreSource§impl Ord for u256
impl Ord for u256
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for u256
impl PartialOrd for u256
Source§impl<T> RemAssign<T> for u256
impl<T> RemAssign<T> for u256
Source§fn rem_assign(&mut self, rhs: T)
fn rem_assign(&mut self, rhs: T)
%= operation. Read moreSource§impl ShlAssign<usize> for u256
impl ShlAssign<usize> for u256
Source§fn shl_assign(&mut self, rhs: usize)
fn shl_assign(&mut self, rhs: usize)
<<= operation. Read moreSource§impl ShrAssign<usize> for u256
impl ShrAssign<usize> for u256
Source§fn shr_assign(&mut self, rhs: usize)
fn shr_assign(&mut self, rhs: usize)
>>= operation. Read moreSource§impl<T> SubAssign<T> for u256
impl<T> SubAssign<T> for u256
Source§fn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
-= operation. Read more