Struct amplify_num::u512
source · pub struct u512(/* 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 u512
impl u512
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; 8]
pub const fn as_inner(&self) -> &[u64; 8]
Returns the underlying array of words constituting large integer
sourcepub const fn into_inner(self) -> [u64; 8]
pub const fn into_inner(self) -> [u64; 8]
Returns the underlying array of words constituting large integer
sourcepub const fn from_inner(array: [u64; 8]) -> Self
pub const fn from_inner(array: [u64; 8]) -> Self
Constructs integer type from the underlying array of words.
source§impl u512
impl u512
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) -> u512
sourcepub fn from_be_bytes(bytes: [u8; 64]) -> u512
pub fn from_be_bytes(bytes: [u8; 64]) -> u512
Creates the integer value from a byte array using big-endian encoding
sourcepub fn from_be_slice(bytes: &[u8]) -> Result<u512, ParseLengthError>
pub fn from_be_slice(bytes: &[u8]) -> Result<u512, ParseLengthError>
Creates the integer value from a byte slice using big-endian encoding
sourcepub fn from_le_bytes(bytes: [u8; 64]) -> u512
pub fn from_le_bytes(bytes: [u8; 64]) -> u512
Creates the integer value from a byte array using little-endian encoding
sourcepub fn from_le_slice(bytes: &[u8]) -> Result<u512, ParseLengthError>
pub fn from_le_slice(bytes: &[u8]) -> Result<u512, ParseLengthError>
Creates the integer value from a byte slice using little-endian encoding
sourcepub fn to_be_bytes(self) -> [u8; 64]
pub fn to_be_bytes(self) -> [u8; 64]
Convert the integer into a byte array using big-endian encoding
sourcepub fn to_le_bytes(self) -> [u8; 64]
pub fn to_le_bytes(self) -> [u8; 64]
Convert a integer into a byte array using little-endian encoding
source§impl u512
impl u512
sourcepub fn checked_add<T>(self, other: T) -> Option<u512>
pub fn checked_add<T>(self, other: T) -> Option<u512>
Checked integer addition. Computes self + rhs
, returning None
if
overflow occurred.
sourcepub fn saturating_add<T>(self, other: T) -> u512
pub fn saturating_add<T>(self, other: T) -> u512
Saturating integer addition. Computes self + rhs
, saturating at the
numeric bounds instead of overflowing.
sourcepub fn overflowing_add<T>(self, other: T) -> (u512, bool)
pub fn overflowing_add<T>(self, other: T) -> (u512, 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) -> u512
pub fn wrapping_add<T>(self, other: T) -> u512
Wrapping (modular) addition. Computes self + rhs
, wrapping around at
the boundary of the type.
sourcepub fn checked_sub<T>(self, other: T) -> Option<u512>
pub fn checked_sub<T>(self, other: T) -> Option<u512>
Checked integer subtraction. Computes self - rhs
, returning None
if
overflow occurred.
sourcepub fn saturating_sub<T>(self, other: T) -> u512
pub fn saturating_sub<T>(self, other: T) -> u512
Saturating integer subtraction. Computes self - rhs
, saturating at the
numeric bounds instead of overflowing.
sourcepub fn overflowing_sub<T>(self, other: T) -> (u512, bool)
pub fn overflowing_sub<T>(self, other: T) -> (u512, 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) -> u512
pub fn wrapping_sub<T>(self, other: T) -> u512
Wrapping (modular) subtraction. Computes self - rhs
, wrapping around
at the boundary of the type.
sourcepub fn checked_mul<T>(self, other: T) -> Option<u512>
pub fn checked_mul<T>(self, other: T) -> Option<u512>
Checked integer multiplication. Computes self * rhs
, returning None
if overflow occurred.
sourcepub fn saturating_mul<T>(self, other: T) -> u512
pub fn saturating_mul<T>(self, other: T) -> u512
Saturating integer multiplication. Computes self * rhs
, saturating at
the numeric bounds instead of overflowing.
sourcepub fn wrapping_mul<T>(self, other: T) -> u512
pub fn wrapping_mul<T>(self, other: T) -> u512
Wrapping (modular) multiplication. Computes self * rhs
, wrapping
around at the boundary of the type.
sourcepub fn overflowing_div<T>(self, other: T) -> (u512, bool)
pub fn overflowing_div<T>(self, other: T) -> (u512, 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) -> u512
pub fn wrapping_div<T>(self, other: T) -> u512
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<u512>
pub fn checked_div<T>(self, other: T) -> Option<u512>
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) -> u512
pub fn saturating_div<T>(self, other: T) -> u512
Saturating integer division. Computes self / rhs
,
saturating at the numeric bounds instead of overflowing.
sourcepub fn overflowing_rem<T>(self, other: T) -> (u512, bool)
pub fn overflowing_rem<T>(self, other: T) -> (u512, 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) -> u512
pub fn wrapping_rem<T>(self, other: T) -> u512
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<u512>
pub fn checked_rem<T>(self, other: T) -> Option<u512>
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) -> u512
pub fn div_euclid<T>(self, other: T) -> u512
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) -> (u512, bool)
pub fn overflowing_div_euclid<T>(self, other: T) -> (u512, 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) -> u512
pub fn wrapping_div_euclid<T>(self, other: T) -> u512
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<u512>
pub fn checked_div_euclid<T>(self, other: T) -> Option<u512>
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) -> u512
pub fn rem_euclid<T>(self, other: T) -> u512
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) -> (u512, bool)
pub fn overflowing_rem_euclid<T>(self, other: T) -> (u512, 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) -> u512
pub fn wrapping_rem_euclid<T>(self, other: T) -> u512
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<u512>
pub fn checked_rem_euclid<T>(self, other: T) -> Option<u512>
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<u512>
pub fn checked_shl(self, rhs: u32) -> Option<u512>
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<u512>
pub fn checked_shr(self, rhs: u32) -> Option<u512>
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) -> u512
pub fn wrapping_neg(self) -> u512
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 u512
impl u512
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 u512
impl<T> AddAssign<T> for u512
source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
+=
operation. Read moresource§impl<T> BitAndAssign<T> for u512
impl<T> BitAndAssign<T> for u512
source§fn bitand_assign(&mut self, rhs: T)
fn bitand_assign(&mut self, rhs: T)
&=
operation. Read moresource§impl<T> BitOrAssign<T> for u512
impl<T> BitOrAssign<T> for u512
source§fn bitor_assign(&mut self, rhs: T)
fn bitor_assign(&mut self, rhs: T)
|=
operation. Read moresource§impl<T> BitXorAssign<T> for u512
impl<T> BitXorAssign<T> for u512
source§fn bitxor_assign(&mut self, rhs: T)
fn bitxor_assign(&mut self, rhs: T)
^=
operation. Read moresource§impl<T> DivAssign<T> for u512
impl<T> DivAssign<T> for u512
source§fn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
/=
operation. Read moresource§impl<T> MulAssign<T> for u512
impl<T> MulAssign<T> for u512
source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
*=
operation. Read moresource§impl Ord for u512
impl Ord for u512
source§impl PartialEq for u512
impl PartialEq for u512
source§impl PartialOrd for u512
impl PartialOrd for u512
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 moresource§impl<T> RemAssign<T> for u512
impl<T> RemAssign<T> for u512
source§fn rem_assign(&mut self, rhs: T)
fn rem_assign(&mut self, rhs: T)
%=
operation. Read moresource§impl ShlAssign<usize> for u512
impl ShlAssign<usize> for u512
source§fn shl_assign(&mut self, rhs: usize)
fn shl_assign(&mut self, rhs: usize)
<<=
operation. Read moresource§impl ShrAssign<usize> for u512
impl ShrAssign<usize> for u512
source§fn shr_assign(&mut self, rhs: usize)
fn shr_assign(&mut self, rhs: usize)
>>=
operation. Read moresource§impl<T> SubAssign<T> for u512
impl<T> SubAssign<T> for u512
source§fn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
-=
operation. Read more