Struct scrypto::math::bnum_integer::I320
source · #[repr(transparent)]pub struct I320(pub BInt<5>);
Expand description
Provides safe integer arithmetic.
Operations like +
, ‘-’, ‘*’, or ‘/’ sometimes produce overflow
which is detected and results in a panic, in of silently
wrapping around.
The bit length of output type will be the greater one in the math operation, and if any of the types was signed, then the resulting type will be signed too, otherwise the output type is unsigned.
The underlying value can be retrieved through the .0
index of the
I320
tuple.
§Layout
I320
will have the same methods and traits as
the built-in counterpart.
Tuple Fields§
§0: BInt<5>
Implementations§
source§impl I320
impl I320
sourcepub const fn count_ones(self) -> u32
pub const fn count_ones(self) -> u32
Returns the number of ones in the binary representation of self
.
sourcepub const fn count_zeros(self) -> u32
pub const fn count_zeros(self) -> u32
Returns the number of zeros in the binary representation of self
.
sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
Returns the number of trailing zeros in the binary representation of self
.
sourcepub const fn swap_bytes(self) -> I320
pub const fn swap_bytes(self) -> I320
Reverses the byte order of the integer.
sourcepub const fn reverse_bits(self) -> I320
pub const fn reverse_bits(self) -> I320
Reverses the bit pattern of the integer.
sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
Returns the number of leading zeros in the binary representation of self
.
sourcepub const fn from_be(x: I320) -> I320
pub const fn from_be(x: I320) -> I320
Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
sourcepub const fn from_le(x: I320) -> I320
pub const fn from_le(x: I320) -> I320
Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
source§impl I320
impl I320
sourcepub fn abs(self) -> I320
pub fn abs(self) -> I320
Computes the absolute value of self
, with overflow causing panic.
The only case where such overflow can occur is when one takes the absolute value of the negative minimal value for the type this is a positive value that is too large to represent in the type. In such a case, this function panics.
sourcepub fn signum(self) -> I320
pub fn signum(self) -> I320
Returns a number representing sign of self
.
0
if the number is zero1
if the number is positive-1
if the number is negative
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
positive.
Trait Implementations§
source§impl Add<I320> for PreciseDecimal
impl Add<I320> for PreciseDecimal
source§impl Add<PreciseDecimal> for I320
impl Add<PreciseDecimal> for I320
§type Output = PreciseDecimal
type Output = PreciseDecimal
+
operator.source§fn add(self, other: PreciseDecimal) -> <I320 as Add<PreciseDecimal>>::Output
fn add(self, other: PreciseDecimal) -> <I320 as Add<PreciseDecimal>>::Output
+
operation. Read moresource§impl AddAssign<&I320> for I320
impl AddAssign<&I320> for I320
source§fn add_assign(&mut self, other: &I320)
fn add_assign(&mut self, other: &I320)
+=
operation. Read moresource§impl AddAssign<I320> for Decimal
impl AddAssign<I320> for Decimal
source§fn add_assign(&mut self, other: I320)
fn add_assign(&mut self, other: I320)
+=
operation. Read moresource§impl AddAssign<I320> for PreciseDecimal
impl AddAssign<I320> for PreciseDecimal
source§fn add_assign(&mut self, other: I320)
fn add_assign(&mut self, other: I320)
+=
operation. Read moresource§impl AddAssign for I320
impl AddAssign for I320
source§fn add_assign(&mut self, other: I320)
fn add_assign(&mut self, other: I320)
+=
operation. Read moresource§impl BitAndAssign for I320
impl BitAndAssign for I320
source§fn bitand_assign(&mut self, other: I320)
fn bitand_assign(&mut self, other: I320)
&=
operation. Read moresource§impl BitOrAssign for I320
impl BitOrAssign for I320
source§fn bitor_assign(&mut self, other: I320)
fn bitor_assign(&mut self, other: I320)
|=
operation. Read moresource§impl BitXorAssign for I320
impl BitXorAssign for I320
source§fn bitxor_assign(&mut self, other: I320)
fn bitxor_assign(&mut self, other: I320)
^=
operation. Read moresource§impl CheckedAdd<Decimal> for I320
impl CheckedAdd<Decimal> for I320
source§impl CheckedAdd<I320> for Decimal
impl CheckedAdd<I320> for Decimal
source§impl CheckedAdd<I320> for PreciseDecimal
impl CheckedAdd<I320> for PreciseDecimal
type Output = PreciseDecimal
fn checked_add( self, other: I320 ) -> Option<<PreciseDecimal as CheckedAdd<I320>>::Output>
source§impl CheckedAdd<PreciseDecimal> for I320
impl CheckedAdd<PreciseDecimal> for I320
type Output = PreciseDecimal
fn checked_add( self, other: PreciseDecimal ) -> Option<<I320 as CheckedAdd<PreciseDecimal>>::Output>
source§impl CheckedAdd for I320
impl CheckedAdd for I320
source§impl CheckedDiv<Decimal> for I320
impl CheckedDiv<Decimal> for I320
source§impl CheckedDiv<I320> for Decimal
impl CheckedDiv<I320> for Decimal
source§impl CheckedDiv<I320> for PreciseDecimal
impl CheckedDiv<I320> for PreciseDecimal
type Output = PreciseDecimal
fn checked_div( self, other: I320 ) -> Option<<PreciseDecimal as CheckedDiv<I320>>::Output>
source§impl CheckedDiv<PreciseDecimal> for I320
impl CheckedDiv<PreciseDecimal> for I320
type Output = PreciseDecimal
fn checked_div( self, other: PreciseDecimal ) -> Option<<I320 as CheckedDiv<PreciseDecimal>>::Output>
source§impl CheckedDiv for I320
impl CheckedDiv for I320
source§impl CheckedMul<Decimal> for I320
impl CheckedMul<Decimal> for I320
source§impl CheckedMul<I320> for Decimal
impl CheckedMul<I320> for Decimal
source§impl CheckedMul<I320> for PreciseDecimal
impl CheckedMul<I320> for PreciseDecimal
type Output = PreciseDecimal
fn checked_mul( self, other: I320 ) -> Option<<PreciseDecimal as CheckedMul<I320>>::Output>
source§impl CheckedMul<PreciseDecimal> for I320
impl CheckedMul<PreciseDecimal> for I320
type Output = PreciseDecimal
fn checked_mul( self, other: PreciseDecimal ) -> Option<<I320 as CheckedMul<PreciseDecimal>>::Output>
source§impl CheckedMul for I320
impl CheckedMul for I320
source§impl CheckedNeg for I320
impl CheckedNeg for I320
type Output = I320
fn checked_neg(self) -> Option<<I320 as CheckedNeg>::Output>
source§impl CheckedSub<Decimal> for I320
impl CheckedSub<Decimal> for I320
source§impl CheckedSub<I320> for Decimal
impl CheckedSub<I320> for Decimal
source§impl CheckedSub<I320> for PreciseDecimal
impl CheckedSub<I320> for PreciseDecimal
type Output = PreciseDecimal
fn checked_sub( self, other: I320 ) -> Option<<PreciseDecimal as CheckedSub<I320>>::Output>
source§impl CheckedSub<PreciseDecimal> for I320
impl CheckedSub<PreciseDecimal> for I320
type Output = PreciseDecimal
fn checked_sub( self, other: PreciseDecimal ) -> Option<<I320 as CheckedSub<PreciseDecimal>>::Output>
source§impl CheckedSub for I320
impl CheckedSub for I320
source§impl Div<I320> for PreciseDecimal
impl Div<I320> for PreciseDecimal
source§impl Div<PreciseDecimal> for I320
impl Div<PreciseDecimal> for I320
§type Output = PreciseDecimal
type Output = PreciseDecimal
/
operator.source§fn div(self, other: PreciseDecimal) -> <I320 as Div<PreciseDecimal>>::Output
fn div(self, other: PreciseDecimal) -> <I320 as Div<PreciseDecimal>>::Output
/
operation. Read moresource§impl DivAssign<&I320> for I320
impl DivAssign<&I320> for I320
source§fn div_assign(&mut self, other: &I320)
fn div_assign(&mut self, other: &I320)
/=
operation. Read moresource§impl DivAssign<I320> for Decimal
impl DivAssign<I320> for Decimal
source§fn div_assign(&mut self, other: I320)
fn div_assign(&mut self, other: I320)
/=
operation. Read moresource§impl DivAssign<I320> for PreciseDecimal
impl DivAssign<I320> for PreciseDecimal
source§fn div_assign(&mut self, other: I320)
fn div_assign(&mut self, other: I320)
/=
operation. Read moresource§impl DivAssign for I320
impl DivAssign for I320
source§fn div_assign(&mut self, other: I320)
fn div_assign(&mut self, other: I320)
/=
operation. Read moresource§impl FromPrimitive for I320
impl FromPrimitive for I320
source§fn from_u8(n: u8) -> Option<I320>
fn from_u8(n: u8) -> Option<I320>
u8
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_u16(n: u16) -> Option<I320>
fn from_u16(n: u16) -> Option<I320>
u16
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_u32(n: u32) -> Option<I320>
fn from_u32(n: u32) -> Option<I320>
u32
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_u64(n: u64) -> Option<I320>
fn from_u64(n: u64) -> Option<I320>
u64
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_u128(n: u128) -> Option<I320>
fn from_u128(n: u128) -> Option<I320>
u128
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read moresource§fn from_usize(n: usize) -> Option<I320>
fn from_usize(n: usize) -> Option<I320>
usize
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_i8(n: i8) -> Option<I320>
fn from_i8(n: i8) -> Option<I320>
i8
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_i16(n: i16) -> Option<I320>
fn from_i16(n: i16) -> Option<I320>
i16
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_i32(n: i32) -> Option<I320>
fn from_i32(n: i32) -> Option<I320>
i32
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_i64(n: i64) -> Option<I320>
fn from_i64(n: i64) -> Option<I320>
i64
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_i128(n: i128) -> Option<I320>
fn from_i128(n: i128) -> Option<I320>
i128
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read moresource§fn from_isize(n: isize) -> Option<I320>
fn from_isize(n: isize) -> Option<I320>
isize
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§impl Mul<I320> for PreciseDecimal
impl Mul<I320> for PreciseDecimal
source§impl Mul<PreciseDecimal> for I320
impl Mul<PreciseDecimal> for I320
§type Output = PreciseDecimal
type Output = PreciseDecimal
*
operator.source§fn mul(self, other: PreciseDecimal) -> <I320 as Mul<PreciseDecimal>>::Output
fn mul(self, other: PreciseDecimal) -> <I320 as Mul<PreciseDecimal>>::Output
*
operation. Read moresource§impl MulAssign<&I320> for I320
impl MulAssign<&I320> for I320
source§fn mul_assign(&mut self, other: &I320)
fn mul_assign(&mut self, other: &I320)
*=
operation. Read moresource§impl MulAssign<I320> for Decimal
impl MulAssign<I320> for Decimal
source§fn mul_assign(&mut self, other: I320)
fn mul_assign(&mut self, other: I320)
*=
operation. Read moresource§impl MulAssign<I320> for PreciseDecimal
impl MulAssign<I320> for PreciseDecimal
source§fn mul_assign(&mut self, other: I320)
fn mul_assign(&mut self, other: I320)
*=
operation. Read moresource§impl MulAssign for I320
impl MulAssign for I320
source§fn mul_assign(&mut self, other: I320)
fn mul_assign(&mut self, other: I320)
*=
operation. Read moresource§impl Ord for I320
impl Ord for I320
source§impl PartialEq for I320
impl PartialEq for I320
source§impl PartialOrd for I320
impl PartialOrd for I320
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 RemAssign<&I320> for I320
impl RemAssign<&I320> for I320
source§fn rem_assign(&mut self, other: &I320)
fn rem_assign(&mut self, other: &I320)
%=
operation. Read moresource§impl RemAssign for I320
impl RemAssign for I320
source§fn rem_assign(&mut self, other: I320)
fn rem_assign(&mut self, other: I320)
%=
operation. Read moresource§impl ShlAssign<u32> for I320
impl ShlAssign<u32> for I320
source§fn shl_assign(&mut self, other: u32)
fn shl_assign(&mut self, other: u32)
<<=
operation. Read moresource§impl ShrAssign<u32> for I320
impl ShrAssign<u32> for I320
source§fn shr_assign(&mut self, other: u32)
fn shr_assign(&mut self, other: u32)
>>=
operation. Read moresource§impl Sub<I320> for PreciseDecimal
impl Sub<I320> for PreciseDecimal
source§impl Sub<PreciseDecimal> for I320
impl Sub<PreciseDecimal> for I320
§type Output = PreciseDecimal
type Output = PreciseDecimal
-
operator.source§fn sub(self, other: PreciseDecimal) -> <I320 as Sub<PreciseDecimal>>::Output
fn sub(self, other: PreciseDecimal) -> <I320 as Sub<PreciseDecimal>>::Output
-
operation. Read moresource§impl SubAssign<&I320> for I320
impl SubAssign<&I320> for I320
source§fn sub_assign(&mut self, other: &I320)
fn sub_assign(&mut self, other: &I320)
-=
operation. Read moresource§impl SubAssign<I320> for Decimal
impl SubAssign<I320> for Decimal
source§fn sub_assign(&mut self, other: I320)
fn sub_assign(&mut self, other: I320)
-=
operation. Read moresource§impl SubAssign<I320> for PreciseDecimal
impl SubAssign<I320> for PreciseDecimal
source§fn sub_assign(&mut self, other: I320)
fn sub_assign(&mut self, other: I320)
-=
operation. Read moresource§impl SubAssign for I320
impl SubAssign for I320
source§fn sub_assign(&mut self, other: I320)
fn sub_assign(&mut self, other: I320)
-=
operation. Read moresource§impl ToPrimitive for I320
impl ToPrimitive for I320
source§fn to_u8(&self) -> Option<u8>
fn to_u8(&self) -> Option<u8>
self
to a u8
. If the value cannot be
represented by a u8
, then None
is returned.source§fn to_u16(&self) -> Option<u16>
fn to_u16(&self) -> Option<u16>
self
to a u16
. If the value cannot be
represented by a u16
, then None
is returned.source§fn to_u32(&self) -> Option<u32>
fn to_u32(&self) -> Option<u32>
self
to a u32
. If the value cannot be
represented by a u32
, then None
is returned.source§fn to_u64(&self) -> Option<u64>
fn to_u64(&self) -> Option<u64>
self
to a u64
. If the value cannot be
represented by a u64
, then None
is returned.source§fn to_u128(&self) -> Option<u128>
fn to_u128(&self) -> Option<u128>
self
to a u128
. If the value cannot be
represented by a u128
(u64
under the default implementation), then
None
is returned. Read moresource§fn to_usize(&self) -> Option<usize>
fn to_usize(&self) -> Option<usize>
self
to a usize
. If the value cannot be
represented by a usize
, then None
is returned.source§fn to_i8(&self) -> Option<i8>
fn to_i8(&self) -> Option<i8>
self
to an i8
. If the value cannot be
represented by an i8
, then None
is returned.source§fn to_i16(&self) -> Option<i16>
fn to_i16(&self) -> Option<i16>
self
to an i16
. If the value cannot be
represented by an i16
, then None
is returned.source§fn to_i32(&self) -> Option<i32>
fn to_i32(&self) -> Option<i32>
self
to an i32
. If the value cannot be
represented by an i32
, then None
is returned.source§fn to_i64(&self) -> Option<i64>
fn to_i64(&self) -> Option<i64>
self
to an i64
. If the value cannot be
represented by an i64
, then None
is returned.source§fn to_i128(&self) -> Option<i128>
fn to_i128(&self) -> Option<i128>
self
to an i128
. If the value cannot be
represented by an i128
(i64
under the default implementation), then
None
is returned. Read moresource§fn to_isize(&self) -> Option<isize>
fn to_isize(&self) -> Option<isize>
self
to an isize
. If the value cannot be
represented by an isize
, then None
is returned.source§impl TryFrom<I320> for PreciseDecimal
impl TryFrom<I320> for PreciseDecimal
§type Error = ParsePreciseDecimalError
type Error = ParsePreciseDecimalError
source§fn try_from(
val: I320
) -> Result<PreciseDecimal, <PreciseDecimal as TryFrom<I320>>::Error>
fn try_from( val: I320 ) -> Result<PreciseDecimal, <PreciseDecimal as TryFrom<I320>>::Error>
impl Copy for I320
impl Eq for I320
Auto Trait Implementations§
impl RefUnwindSafe for I320
impl Send for I320
impl Sync for I320
impl Unpin for I320
impl UnwindSafe for I320
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
self
to type T
. The semantics of numeric casting with the as
operator are followed, so <T as As>::as_::<U>
can be used in the same way as T as U
for numeric conversions. Read moresource§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<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.