Struct amplify_num::i256
source · [−]pub struct i256(_);
Expand description
Large integer type
The type is composed of little-endian ordered 64-bit words, which represents its inner representation.
Implementations
sourceimpl i256
impl i256
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 fn as_inner(&self) -> &[u64; 4]
pub fn as_inner(&self) -> &[u64; 4]
Returns the underlying array of words constituting large integer
sourcepub fn into_inner(self) -> [u64; 4]
pub 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.
sourceimpl i256
impl i256
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 abs(self) -> i256
sourcepub fn from_be_bytes(bytes: [u8; 32]) -> i256
pub fn from_be_bytes(bytes: [u8; 32]) -> i256
Creates the integer value from a byte array using big-endian encoding
sourcepub fn from_be_slice(bytes: &[u8]) -> Result<i256, ParseLengthError>
pub fn from_be_slice(bytes: &[u8]) -> Result<i256, ParseLengthError>
Creates the integer value from a byte slice using big-endian encoding
sourcepub fn from_le_bytes(bytes: [u8; 32]) -> i256
pub fn from_le_bytes(bytes: [u8; 32]) -> i256
Creates the integer value from a byte array using little-endian encoding
sourcepub fn from_le_slice(bytes: &[u8]) -> Result<i256, ParseLengthError>
pub fn from_le_slice(bytes: &[u8]) -> Result<i256, 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
sourceimpl i256
impl i256
sourcepub fn checked_add<T>(self, other: T) -> Option<i256> where
T: Into<i256>,
pub fn checked_add<T>(self, other: T) -> Option<i256> where
T: Into<i256>,
Checked integer addition. Computes self + rhs
, returning None
if
overflow occurred.
sourcepub fn saturating_add<T>(self, other: T) -> i256 where
T: Into<i256>,
pub fn saturating_add<T>(self, other: T) -> i256 where
T: Into<i256>,
Saturating integer addition. Computes self + rhs
, saturating at the
numeric bounds instead of overflowing.
sourcepub fn overflowing_add<T>(self, other: T) -> (i256, bool) where
T: Into<i256>,
pub fn overflowing_add<T>(self, other: T) -> (i256, bool) where
T: Into<i256>,
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) -> i256 where
T: Into<i256>,
pub fn wrapping_add<T>(self, other: T) -> i256 where
T: Into<i256>,
Wrapping (modular) addition. Computes self + rhs
, wrapping around at
the boundary of the type.
sourcepub fn checked_sub<T>(self, other: T) -> Option<i256> where
T: Into<i256>,
pub fn checked_sub<T>(self, other: T) -> Option<i256> where
T: Into<i256>,
Checked integer subtraction. Computes self - rhs
, returning None
if
overflow occurred.
sourcepub fn saturating_sub<T>(self, other: T) -> i256 where
T: Into<i256>,
pub fn saturating_sub<T>(self, other: T) -> i256 where
T: Into<i256>,
Saturating integer subtraction. Computes self - rhs
, saturating at the
numeric bounds instead of overflowing.
sourcepub fn overflowing_sub<T>(self, other: T) -> (i256, bool) where
T: Into<i256>,
pub fn overflowing_sub<T>(self, other: T) -> (i256, bool) where
T: Into<i256>,
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) -> i256 where
T: Into<i256>,
pub fn wrapping_sub<T>(self, other: T) -> i256 where
T: Into<i256>,
Wrapping (modular) subtraction. Computes self - rhs
, wrapping around
at the boundary of the type.
sourcepub fn checked_mul<T>(self, other: T) -> Option<i256> where
T: Into<i256>,
pub fn checked_mul<T>(self, other: T) -> Option<i256> where
T: Into<i256>,
Checked integer multiplication. Computes self * rhs
, returning None
if overflow occurred.
sourcepub fn saturating_mul<T>(self, other: T) -> i256 where
T: Into<i256>,
pub fn saturating_mul<T>(self, other: T) -> i256 where
T: Into<i256>,
Saturating integer multiplication. Computes self * rhs
, saturating at
the numeric bounds instead of overflowing.
sourcepub fn wrapping_mul<T>(self, other: T) -> i256 where
T: Into<i256>,
pub fn wrapping_mul<T>(self, other: T) -> i256 where
T: Into<i256>,
Wrapping (modular) multiplication. Computes self * rhs
, wrapping
around at the boundary of the type.
sourcepub fn overflowing_div<T>(self, other: T) -> (i256, bool) where
T: Into<i256>,
pub fn overflowing_div<T>(self, other: T) -> (i256, bool) where
T: Into<i256>,
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) -> i256 where
T: Into<i256>,
pub fn wrapping_div<T>(self, other: T) -> i256 where
T: Into<i256>,
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<i256> where
T: Into<i256>,
pub fn checked_div<T>(self, other: T) -> Option<i256> where
T: Into<i256>,
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) -> i256 where
T: Into<i256>,
pub fn saturating_div<T>(self, other: T) -> i256 where
T: Into<i256>,
Saturating integer division. Computes self / rhs
,
saturating at the numeric bounds instead of overflowing.
sourcepub fn overflowing_rem<T>(self, other: T) -> (i256, bool) where
T: Into<i256>,
pub fn overflowing_rem<T>(self, other: T) -> (i256, bool) where
T: Into<i256>,
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) -> i256 where
T: Into<i256>,
pub fn wrapping_rem<T>(self, other: T) -> i256 where
T: Into<i256>,
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<i256> where
T: Into<i256>,
pub fn checked_rem<T>(self, other: T) -> Option<i256> where
T: Into<i256>,
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) -> i256 where
T: Into<i256>,
pub fn div_euclid<T>(self, other: T) -> i256 where
T: Into<i256>,
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) -> (i256, bool) where
T: Into<i256>,
pub fn overflowing_div_euclid<T>(self, other: T) -> (i256, bool) where
T: Into<i256>,
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) -> i256 where
T: Into<i256>,
pub fn wrapping_div_euclid<T>(self, other: T) -> i256 where
T: Into<i256>,
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<i256> where
T: Into<i256>,
pub fn checked_div_euclid<T>(self, other: T) -> Option<i256> where
T: Into<i256>,
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) -> i256 where
T: Into<i256>,
pub fn rem_euclid<T>(self, other: T) -> i256 where
T: Into<i256>,
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) -> (i256, bool) where
T: Into<i256>,
pub fn overflowing_rem_euclid<T>(self, other: T) -> (i256, bool) where
T: Into<i256>,
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) -> i256 where
T: Into<i256>,
pub fn wrapping_rem_euclid<T>(self, other: T) -> i256 where
T: Into<i256>,
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<i256> where
T: Into<i256>,
pub fn checked_rem_euclid<T>(self, other: T) -> Option<i256> where
T: Into<i256>,
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<i256>
pub fn checked_shl(self, rhs: u32) -> Option<i256>
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<i256>
pub fn checked_shr(self, rhs: u32) -> Option<i256>
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) -> i256
pub fn wrapping_neg(self) -> i256
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.
sourceimpl i256
impl i256
sourcepub const MIN: i256 = { let mut min = [0u64; 4]; min[4 - 1] = 9223372036854775808; i256(min) }
pub const MIN: i256 = { let mut min = [0u64; 4]; min[4 - 1] = 9223372036854775808; i256(min) }
Minimum value
sourcepub const MAX: i256 = {
let mut max = [::core::u64::MAX; 4];
max[4 - 1] = ::core::u64::MAX >> 1;
i256(max)
}
pub const MAX: i256 = { let mut max = [::core::u64::MAX; 4]; max[4 - 1] = ::core::u64::MAX >> 1; i256(max) }
Maximum value
pub fn is_positive(&self) -> bool
pub 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
sourceimpl<T> AddAssign<T> for i256 where
T: Into<i256>,
impl<T> AddAssign<T> for i256 where
T: Into<i256>,
sourcefn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
Performs the +=
operation. Read more
sourceimpl<T> BitAndAssign<T> for i256 where
T: Into<i256>,
impl<T> BitAndAssign<T> for i256 where
T: Into<i256>,
sourcefn bitand_assign(&mut self, rhs: T)
fn bitand_assign(&mut self, rhs: T)
Performs the &=
operation. Read more
sourceimpl<T> BitOrAssign<T> for i256 where
T: Into<i256>,
impl<T> BitOrAssign<T> for i256 where
T: Into<i256>,
sourcefn bitor_assign(&mut self, rhs: T)
fn bitor_assign(&mut self, rhs: T)
Performs the |=
operation. Read more
sourceimpl<T> BitXorAssign<T> for i256 where
T: Into<i256>,
impl<T> BitXorAssign<T> for i256 where
T: Into<i256>,
sourcefn bitxor_assign(&mut self, rhs: T)
fn bitxor_assign(&mut self, rhs: T)
Performs the ^=
operation. Read more
sourceimpl<T> DivAssign<T> for i256 where
T: Into<i256>,
impl<T> DivAssign<T> for i256 where
T: Into<i256>,
sourcefn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
Performs the /=
operation. Read more
sourceimpl<T> MulAssign<T> for i256 where
T: Into<i256>,
impl<T> MulAssign<T> for i256 where
T: Into<i256>,
sourcefn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
Performs the *=
operation. Read more
sourceimpl Ord for i256
impl Ord for i256
sourceimpl PartialOrd<i256> for i256
impl PartialOrd<i256> for i256
sourcefn partial_cmp(&self, other: &i256) -> Option<Ordering>
fn partial_cmp(&self, other: &i256) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
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 · sourcefn le(&self, other: &Rhs) -> bool
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
sourceimpl<T> RemAssign<T> for i256 where
T: Into<i256>,
impl<T> RemAssign<T> for i256 where
T: Into<i256>,
sourcefn rem_assign(&mut self, rhs: T)
fn rem_assign(&mut self, rhs: T)
Performs the %=
operation. Read more
sourceimpl ShlAssign<usize> for i256
impl ShlAssign<usize> for i256
sourcefn shl_assign(&mut self, rhs: usize)
fn shl_assign(&mut self, rhs: usize)
Performs the <<=
operation. Read more
sourceimpl ShrAssign<usize> for i256
impl ShrAssign<usize> for i256
sourcefn shr_assign(&mut self, rhs: usize)
fn shr_assign(&mut self, rhs: usize)
Performs the >>=
operation. Read more
sourceimpl<T> SubAssign<T> for i256 where
T: Into<i256>,
impl<T> SubAssign<T> for i256 where
T: Into<i256>,
sourcefn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
Performs the -=
operation. Read more
impl Copy for i256
impl Eq for i256
impl StructuralEq for i256
impl StructuralPartialEq for i256
Auto Trait Implementations
impl RefUnwindSafe for i256
impl Send for i256
impl Sync for i256
impl Unpin for i256
impl UnwindSafe for i256
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more