pub struct I256(/* private fields */);
Expand description
Little-endian 256-bit signed integer.
Implementations§
Source§impl I256
impl I256
Sourcepub fn from_raw(raw: U256) -> I256
pub fn from_raw(raw: U256) -> I256
Coerces an unsigned integer into a signed one. If the unsigned integer
is greater than the greater than or equal to 1 << 255
, then the result
will overflow into a negative value.
Sourcepub fn into_raw(self) -> U256
pub fn into_raw(self) -> U256
Returns the signed integer as a unsigned integer. If the value of self
negative, then the two’s complement of its absolute value will be
returned.
Sourcepub fn as_i32(&self) -> i32
pub fn as_i32(&self) -> i32
Conversion to i32 with overflow checking
§Panics
Panics if the number is outside the range [i32::MIN
, i32::MAX
].
Sourcepub fn as_u32(&self) -> u32
pub fn as_u32(&self) -> u32
Conversion to u32 with overflow checking
§Panics
Panics if the number is outside the range [0
, u32::MAX
].
Sourcepub fn as_i64(&self) -> i64
pub fn as_i64(&self) -> i64
Conversion to i64 with overflow checking
§Panics
Panics if the number is outside the range [i64::MIN
, i64::MAX
].
Sourcepub fn as_u64(&self) -> u64
pub fn as_u64(&self) -> u64
Conversion to u64 with overflow checking
§Panics
Panics if the number is outside the range [0
, u64::MAX
].
Sourcepub fn as_i128(&self) -> i128
pub fn as_i128(&self) -> i128
Conversion to i128 with overflow checking
§Panics
Panics if the number is outside the range [i128::MIN
, i128::MAX
].
Sourcepub fn as_u128(&self) -> u128
pub fn as_u128(&self) -> u128
Conversion to u128 with overflow checking
§Panics
Panics if the number is outside the range [0
, u128::MAX
].
Sourcepub fn as_isize(&self) -> usize
pub fn as_isize(&self) -> usize
Conversion to isize with overflow checking
§Panics
Panics if the number is outside the range [isize::MIN
, isize::MAX
].
Sourcepub fn as_usize(&self) -> usize
pub fn as_usize(&self) -> usize
Conversion to usize with overflow checking
§Panics
Panics if the number is outside the range [0
, usize::MAX
].
Sourcepub fn from_dec_str(value: &str) -> Result<I256, ParseI256Error>
pub fn from_dec_str(value: &str) -> Result<I256, ParseI256Error>
Convert from a decimal string.
Sourcepub fn from_hex_str(value: &str) -> Result<I256, ParseI256Error>
pub fn from_hex_str(value: &str) -> Result<I256, ParseI256Error>
Convert from a hexadecimal string.
Sourcepub fn is_positive(self) -> bool
pub fn is_positive(self) -> bool
Returns true
if self
is positive and false
if the number is zero
or negative.
Sourcepub fn is_negative(self) -> bool
pub fn is_negative(self) -> bool
Returns true
if self
is negative and false
if the number is zero
or negative.
Sourcepub fn is_zero(self) -> bool
pub fn is_zero(self) -> bool
Returns true
if self
is negative and false
if the number is zero
or positive.
Sourcepub fn overflowing_abs(self) -> (I256, bool)
pub fn overflowing_abs(self) -> (I256, bool)
Computes the absolute value of self.
Returns a tuple of the absolute version of self along with a boolean
indicating whether an overflow happened. If self is the minimum value
(e.g., I256::MIN
for values of type I256
), then the minimum value
will be returned again and true will be returned for an overflow
happening.
Sourcepub fn checked_abs(self) -> Option<I256>
pub fn checked_abs(self) -> Option<I256>
Checked absolute value. Computes self.abs()
, returning None
if
self == MIN
.
Sourcepub fn saturating_abs(self) -> I256
pub fn saturating_abs(self) -> I256
Saturating absolute value. Computes self.abs()
, returning MAX
if
self == MIN
instead of overflowing.
Sourcepub fn wrapping_abs(self) -> I256
pub fn wrapping_abs(self) -> I256
Wrapping absolute value. Computes self.abs()
, wrapping around at the
boundary of the type.
Sourcepub fn overflowing_neg(self) -> (I256, bool)
pub fn overflowing_neg(self) -> (I256, bool)
Negates self, overflowing if this is equal to the minimum value.
Returns a tuple of the negated version of self
along with a boolean
indicating whether an overflow happened. If self
is the minimum value,
then the minimum value will be returned again and true
will be
returned for an overflow happening.
Sourcepub fn checked_neg(self) -> Option<I256>
pub fn checked_neg(self) -> Option<I256>
Checked negation. Computes self.neg()
, returning None
if
self == MIN
.
Sourcepub fn saturating_neg(self) -> I256
pub fn saturating_neg(self) -> I256
Saturating negation. Computes self.neg()
, returning MAX
if
self == MIN
instead of overflowing.
Sourcepub fn wrapping_neg(self) -> I256
pub fn wrapping_neg(self) -> I256
Wrapping negation. Computes self.neg()
, returning MIN
if
self == MIN
instead of overflowing.
Sourcepub fn count_ones(&self) -> u32
pub fn count_ones(&self) -> u32
Returns the number of ones in the binary representation of self
.
Sourcepub fn count_zeros(&self) -> u32
pub fn count_zeros(&self) -> u32
Returns the number of zeros 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_zeros(&self) -> u32
pub fn trailing_zeros(&self) -> u32
Returns the number of leading zeros in the binary representation of
self
.
Sourcepub fn to_big_endian(&self, bytes: &mut [u8])
pub fn to_big_endian(&self, bytes: &mut [u8])
Write to the slice in big-endian format.
Sourcepub fn to_little_endian(&self, bytes: &mut [u8])
pub fn to_little_endian(&self, bytes: &mut [u8])
Write to the slice in little-endian format.
Sourcepub fn overflowing_add(self, rhs: I256) -> (I256, bool)
pub fn overflowing_add(self, rhs: I256) -> (I256, 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 checked_add(self, other: I256) -> Option<I256>
pub fn checked_add(self, other: I256) -> Option<I256>
Checked addition. Returns None if overflow occurred.
Sourcepub fn saturating_add(self, other: I256) -> I256
pub fn saturating_add(self, other: I256) -> I256
Addition which saturates at the maximum value (Self::max_value()).
Sourcepub fn wrapping_add(self, other: I256) -> I256
pub fn wrapping_add(self, other: I256) -> I256
Wrapping addition.
Sourcepub fn overflowing_sub(self, rhs: I256) -> (I256, bool)
pub fn overflowing_sub(self, rhs: I256) -> (I256, 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 checked_sub(self, other: I256) -> Option<I256>
pub fn checked_sub(self, other: I256) -> Option<I256>
Checked subtraction. Returns None if overflow occurred.
Sourcepub fn saturating_sub(self, other: I256) -> I256
pub fn saturating_sub(self, other: I256) -> I256
Subtraction which saturates at zero.
Sourcepub fn wrapping_sub(self, other: I256) -> I256
pub fn wrapping_sub(self, other: I256) -> I256
Wrapping subtraction.
Sourcepub fn overflowing_mul(self, rhs: I256) -> (I256, bool)
pub fn overflowing_mul(self, rhs: I256) -> (I256, bool)
Calculates self
* rhs
Returns a tuple of the multiplication 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 checked_mul(self, other: I256) -> Option<I256>
pub fn checked_mul(self, other: I256) -> Option<I256>
Checked multiplication. Returns None if overflow occurred.
Sourcepub fn saturating_mul(self, rhs: I256) -> I256
pub fn saturating_mul(self, rhs: I256) -> I256
Multiplication which saturates at the maximum value.
Sourcepub fn wrapping_mul(self, rhs: I256) -> I256
pub fn wrapping_mul(self, rhs: I256) -> I256
Wrapping multiplication.
Sourcepub fn overflowing_div(self, rhs: I256) -> (I256, bool)
pub fn overflowing_div(self, rhs: I256) -> (I256, bool)
Calculates self
/ rhs
Returns a tuple of the division 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 checked_div(self, rhs: I256) -> Option<I256>
pub fn checked_div(self, rhs: I256) -> Option<I256>
Checked division. Returns None if overflow occurred or if rhs == 0.
Sourcepub fn saturating_div(self, rhs: I256) -> I256
pub fn saturating_div(self, rhs: I256) -> I256
Division which saturates at the maximum value.
Sourcepub fn wrapping_div(self, rhs: I256) -> I256
pub fn wrapping_div(self, rhs: I256) -> I256
Wrapping division.
Sourcepub fn overflowing_rem(self, rhs: I256) -> (I256, bool)
pub fn overflowing_rem(self, rhs: I256) -> (I256, bool)
Calculates self
% rhs
Returns a tuple of the remainder 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 checked_rem(self, rhs: I256) -> Option<I256>
pub fn checked_rem(self, rhs: I256) -> Option<I256>
Checked remainder. Returns None if overflow occurred or rhs == 0
Sourcepub fn wrapping_rem(self, rhs: I256) -> I256
pub fn wrapping_rem(self, rhs: I256) -> I256
Wrapping remainder. Returns the result of the operation % regardless of whether or not the division overflowed.
Sourcepub fn div_euclid(self, rhs: I256) -> I256
pub fn div_euclid(self, rhs: I256) -> I256
Calculates the quotient of Euclidean division of self by rhs.
This computes the integer n
such that self = n * rhs + self.rem_euclid(rhs)
,
with 0 <= self.rem_euclid(rhs) < rhs
.
In other words, the result is self / rhs
rounded to the integer n
such that self >= n * 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 rem_euclid(self, rhs: I256) -> I256
pub fn rem_euclid(self, rhs: I256) -> I256
Calculates the least non-negative 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_div_euclid(self, rhs: I256) -> (I256, bool)
pub fn overflowing_div_euclid(self, rhs: I256) -> (I256, 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 checked_div_euclid(self, rhs: I256) -> Option<I256>
pub fn checked_div_euclid(self, rhs: I256) -> Option<I256>
Checked Euclidean division. Computes self.div_euclid(rhs)
,
returning None if rhs == 0
or the division results in overflow.
Sourcepub fn wrapping_div_euclid(self, rhs: I256) -> I256
pub fn wrapping_div_euclid(self, rhs: I256) -> I256
Wrapping Euclidean division.
Computes self.div_euclid(rhs)
, wrapping around at the boundary of the type.
Wrapping only occurs 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 overflowing_rem_euclid(self, rhs: I256) -> (I256, bool)
pub fn overflowing_rem_euclid(self, rhs: I256) -> (I256, 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.
Panics if rhs == 0
Sourcepub fn wrapping_rem_euclid(self, rhs: I256) -> I256
pub fn wrapping_rem_euclid(self, rhs: I256) -> 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
.
Panics when rhs == 0
Sourcepub fn checked_rem_euclid(self, rhs: I256) -> Option<I256>
pub fn checked_rem_euclid(self, rhs: I256) -> Option<I256>
Checked Euclidean remainder. Computes self.rem_euclid(rhs)
,
returning None
if rhs == 0
or the division results in overflow.
Sourcepub fn overflowing_pow(self, exp: u32) -> (I256, bool)
pub fn overflowing_pow(self, exp: u32) -> (I256, bool)
Raises self to the power of exp
.
Returns a tuple of the exponentiation along with a bool indicating whether an overflow happened.
Sourcepub fn checked_pow(self, exp: u32) -> Option<I256>
pub fn checked_pow(self, exp: u32) -> Option<I256>
Raises self to the power of exp
. Returns None if overflow occurred.
Sourcepub fn saturating_pow(self, exp: u32) -> I256
pub fn saturating_pow(self, exp: u32) -> I256
Raises self to the power of exp
, saturating at the numeric bounds
instead of overflowing.
Sourcepub fn wrapping_pow(self, exp: u32) -> I256
pub fn wrapping_pow(self, exp: u32) -> I256
Wrapping powolute value. Computes self.pow()
, wrapping around at the
boundary of the type.
Trait Implementations§
Source§impl AddAssign for I256
impl AddAssign for I256
Source§fn add_assign(&mut self, rhs: I256)
fn add_assign(&mut self, rhs: I256)
+=
operation. Read moreSource§impl BitAndAssign for I256
impl BitAndAssign for I256
Source§fn bitand_assign(&mut self, rhs: I256)
fn bitand_assign(&mut self, rhs: I256)
&=
operation. Read moreSource§impl BitOrAssign for I256
impl BitOrAssign for I256
Source§fn bitor_assign(&mut self, rhs: I256)
fn bitor_assign(&mut self, rhs: I256)
|=
operation. Read moreSource§impl BitXorAssign for I256
impl BitXorAssign for I256
Source§fn bitxor_assign(&mut self, rhs: I256)
fn bitxor_assign(&mut self, rhs: I256)
^=
operation. Read moreSource§impl<'de> Deserialize<'de> for I256
impl<'de> Deserialize<'de> for I256
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<I256, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<I256, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl DivAssign for I256
impl DivAssign for I256
Source§fn div_assign(&mut self, rhs: I256)
fn div_assign(&mut self, rhs: I256)
/=
operation. Read moreSource§impl MulAssign for I256
impl MulAssign for I256
Source§fn mul_assign(&mut self, rhs: I256)
fn mul_assign(&mut self, rhs: I256)
*=
operation. Read moreSource§impl Ord for I256
impl Ord for I256
Source§impl PartialOrd for I256
impl PartialOrd for I256
Source§impl RemAssign for I256
impl RemAssign for I256
Source§fn rem_assign(&mut self, rhs: I256)
fn rem_assign(&mut self, rhs: I256)
%=
operation. Read moreSource§impl Serialize for I256
impl Serialize for I256
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Source§impl ShlAssign<U256> for I256
impl ShlAssign<U256> for I256
Source§fn shl_assign(&mut self, rhs: U256)
fn shl_assign(&mut self, rhs: U256)
<<=
operation. Read moreSource§impl ShlAssign<i128> for I256
impl ShlAssign<i128> for I256
Source§fn shl_assign(&mut self, rhs: i128)
fn shl_assign(&mut self, rhs: i128)
<<=
operation. Read moreSource§impl ShlAssign<i16> for I256
impl ShlAssign<i16> for I256
Source§fn shl_assign(&mut self, rhs: i16)
fn shl_assign(&mut self, rhs: i16)
<<=
operation. Read moreSource§impl ShlAssign<i32> for I256
impl ShlAssign<i32> for I256
Source§fn shl_assign(&mut self, rhs: i32)
fn shl_assign(&mut self, rhs: i32)
<<=
operation. Read moreSource§impl ShlAssign<i64> for I256
impl ShlAssign<i64> for I256
Source§fn shl_assign(&mut self, rhs: i64)
fn shl_assign(&mut self, rhs: i64)
<<=
operation. Read moreSource§impl ShlAssign<i8> for I256
impl ShlAssign<i8> for I256
Source§fn shl_assign(&mut self, rhs: i8)
fn shl_assign(&mut self, rhs: i8)
<<=
operation. Read moreSource§impl ShlAssign<isize> for I256
impl ShlAssign<isize> for I256
Source§fn shl_assign(&mut self, rhs: isize)
fn shl_assign(&mut self, rhs: isize)
<<=
operation. Read moreSource§impl ShlAssign<u128> for I256
impl ShlAssign<u128> for I256
Source§fn shl_assign(&mut self, rhs: u128)
fn shl_assign(&mut self, rhs: u128)
<<=
operation. Read moreSource§impl ShlAssign<u16> for I256
impl ShlAssign<u16> for I256
Source§fn shl_assign(&mut self, rhs: u16)
fn shl_assign(&mut self, rhs: u16)
<<=
operation. Read moreSource§impl ShlAssign<u32> for I256
impl ShlAssign<u32> for I256
Source§fn shl_assign(&mut self, rhs: u32)
fn shl_assign(&mut self, rhs: u32)
<<=
operation. Read moreSource§impl ShlAssign<u64> for I256
impl ShlAssign<u64> for I256
Source§fn shl_assign(&mut self, rhs: u64)
fn shl_assign(&mut self, rhs: u64)
<<=
operation. Read moreSource§impl ShlAssign<u8> for I256
impl ShlAssign<u8> for I256
Source§fn shl_assign(&mut self, rhs: u8)
fn shl_assign(&mut self, rhs: u8)
<<=
operation. Read moreSource§impl ShlAssign<usize> for I256
impl ShlAssign<usize> for I256
Source§fn shl_assign(&mut self, rhs: usize)
fn shl_assign(&mut self, rhs: usize)
<<=
operation. Read moreSource§impl ShlAssign for I256
impl ShlAssign for I256
Source§fn shl_assign(&mut self, rhs: I256)
fn shl_assign(&mut self, rhs: I256)
<<=
operation. Read moreSource§impl ShrAssign<U256> for I256
impl ShrAssign<U256> for I256
Source§fn shr_assign(&mut self, rhs: U256)
fn shr_assign(&mut self, rhs: U256)
>>=
operation. Read moreSource§impl ShrAssign<i128> for I256
impl ShrAssign<i128> for I256
Source§fn shr_assign(&mut self, rhs: i128)
fn shr_assign(&mut self, rhs: i128)
>>=
operation. Read moreSource§impl ShrAssign<i16> for I256
impl ShrAssign<i16> for I256
Source§fn shr_assign(&mut self, rhs: i16)
fn shr_assign(&mut self, rhs: i16)
>>=
operation. Read moreSource§impl ShrAssign<i32> for I256
impl ShrAssign<i32> for I256
Source§fn shr_assign(&mut self, rhs: i32)
fn shr_assign(&mut self, rhs: i32)
>>=
operation. Read moreSource§impl ShrAssign<i64> for I256
impl ShrAssign<i64> for I256
Source§fn shr_assign(&mut self, rhs: i64)
fn shr_assign(&mut self, rhs: i64)
>>=
operation. Read moreSource§impl ShrAssign<i8> for I256
impl ShrAssign<i8> for I256
Source§fn shr_assign(&mut self, rhs: i8)
fn shr_assign(&mut self, rhs: i8)
>>=
operation. Read moreSource§impl ShrAssign<isize> for I256
impl ShrAssign<isize> for I256
Source§fn shr_assign(&mut self, rhs: isize)
fn shr_assign(&mut self, rhs: isize)
>>=
operation. Read moreSource§impl ShrAssign<u128> for I256
impl ShrAssign<u128> for I256
Source§fn shr_assign(&mut self, rhs: u128)
fn shr_assign(&mut self, rhs: u128)
>>=
operation. Read moreSource§impl ShrAssign<u16> for I256
impl ShrAssign<u16> for I256
Source§fn shr_assign(&mut self, rhs: u16)
fn shr_assign(&mut self, rhs: u16)
>>=
operation. Read moreSource§impl ShrAssign<u32> for I256
impl ShrAssign<u32> for I256
Source§fn shr_assign(&mut self, rhs: u32)
fn shr_assign(&mut self, rhs: u32)
>>=
operation. Read moreSource§impl ShrAssign<u64> for I256
impl ShrAssign<u64> for I256
Source§fn shr_assign(&mut self, rhs: u64)
fn shr_assign(&mut self, rhs: u64)
>>=
operation. Read moreSource§impl ShrAssign<u8> for I256
impl ShrAssign<u8> for I256
Source§fn shr_assign(&mut self, rhs: u8)
fn shr_assign(&mut self, rhs: u8)
>>=
operation. Read moreSource§impl ShrAssign<usize> for I256
impl ShrAssign<usize> for I256
Source§fn shr_assign(&mut self, rhs: usize)
fn shr_assign(&mut self, rhs: usize)
>>=
operation. Read moreSource§impl ShrAssign for I256
impl ShrAssign for I256
Source§fn shr_assign(&mut self, rhs: I256)
fn shr_assign(&mut self, rhs: I256)
>>=
operation. Read moreSource§impl SubAssign for I256
impl SubAssign for I256
Source§fn sub_assign(&mut self, rhs: I256)
fn sub_assign(&mut self, rhs: I256)
-=
operation. Read moreimpl Copy for I256
impl Eq for I256
impl StructuralPartialEq for I256
Auto Trait Implementations§
impl Freeze for I256
impl RefUnwindSafe for I256
impl Send for I256
impl Sync for I256
impl Unpin for I256
impl UnwindSafe for I256
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,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.