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]) -> u512
pub const fn from_inner(array: [u64; 8]) -> u512
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 PartialOrd for u512
impl PartialOrd for u512
Source§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 moreimpl Copy for u512
impl Eq for u512
impl StructuralPartialEq for u512
Auto Trait Implementations§
impl Freeze for u512
impl RefUnwindSafe for u512
impl Send for u512
impl Sync for u512
impl Unpin for u512
impl UnwindSafe for u512
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 64 bytes