Struct amplify_num::i256

source ·
pub struct i256(/* 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 i256

source

pub fn as_ptr(&self) -> *const u64

Converts the object to a raw pointer

source

pub fn as_mut_ptr(&mut self) -> *mut u64

Converts the object to a mutable raw pointer

source

pub const fn as_inner(&self) -> &[u64; 4]

Returns the underlying array of words constituting large integer

source

pub const fn into_inner(self) -> [u64; 4]

Returns the underlying array of words constituting large integer

source

pub const fn from_inner(array: [u64; 4]) -> Self

Constructs integer type from the underlying array of words.

source§

impl i256

source

pub const ZERO: i256 = _

Zero value

source

pub const ONE: i256 = _

Value for 1

source

pub const BITS: u32 = 256u32

Bit dimension

source

pub const BYTES: u8 = 32u8

Length of the integer in bytes

source

pub const INNER_LEN: u8 = 4u8

Length of the inner representation in 64-bit words

source

pub const fn bit(&self, index: usize) -> bool

Returns whether specific bit number is set to 1 or not

source

pub const fn low_u32(&self) -> u32

Returns lower 32 bits of the number as u32

source

pub const fn low_u64(&self) -> u64

Returns lower 64 bits of the number as u32

source

pub fn leading_ones(&self) -> u32

Returns the number of leading ones in the binary representation of self.

source

pub fn leading_zeros(&self) -> u32

Returns the number of leading zeros in the binary representation of self.

source

pub fn trailing_ones(&self) -> u32

Returns the number of trailing ones in the binary representation of self.

source

pub fn trailing_zeros(&self) -> u32

Returns the number of trailing zeros in the binary representation of self.

source

pub fn is_zero(&self) -> bool

source

pub fn is_positive(&self) -> bool

source

pub fn abs(self) -> i256

source

pub fn from_be_bytes(bytes: [u8; 32]) -> i256

Creates the integer value from a byte array using big-endian encoding

source

pub fn from_be_slice(bytes: &[u8]) -> Result<i256, ParseLengthError>

Creates the integer value from a byte slice using big-endian encoding

source

pub fn from_le_bytes(bytes: [u8; 32]) -> i256

Creates the integer value from a byte array using little-endian encoding

source

pub fn from_le_slice(bytes: &[u8]) -> Result<i256, ParseLengthError>

Creates the integer value from a byte slice using little-endian encoding

source

pub fn to_be_bytes(self) -> [u8; 32]

Convert the integer into a byte array using big-endian encoding

source

pub fn to_le_bytes(self) -> [u8; 32]

Convert a integer into a byte array using little-endian encoding

source§

impl i256

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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).

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source§

impl i256

source

pub const MIN: i256 = _

Minimum value

source

pub const MAX: i256 = _

Maximum value

source

pub fn is_negative(&self) -> bool

source

pub fn bits_required(&self) -> usize

Return the least number of bits needed to represent the number

source

pub fn overflowing_mul<T>(self, other: T) -> (i256, bool)
where T: Into<i256>,

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.

Trait Implementations§

source§

impl<T> Add<T> for i256
where T: Into<i256>,

§

type Output = i256

The resulting type after applying the + operator.
source§

fn add(self, other: T) -> i256

Performs the + operation. Read more
source§

impl<T> AddAssign<T> for i256
where T: Into<i256>,

source§

fn add_assign(&mut self, rhs: T)

Performs the += operation. Read more
source§

impl<T> BitAnd<T> for i256
where T: Into<i256>,

§

type Output = i256

The resulting type after applying the & operator.
source§

fn bitand(self, other: T) -> i256

Performs the & operation. Read more
source§

impl<T> BitAndAssign<T> for i256
where T: Into<i256>,

source§

fn bitand_assign(&mut self, rhs: T)

Performs the &= operation. Read more
source§

impl<T> BitOr<T> for i256
where T: Into<i256>,

§

type Output = i256

The resulting type after applying the | operator.
source§

fn bitor(self, other: T) -> i256

Performs the | operation. Read more
source§

impl<T> BitOrAssign<T> for i256
where T: Into<i256>,

source§

fn bitor_assign(&mut self, rhs: T)

Performs the |= operation. Read more
source§

impl<T> BitXor<T> for i256
where T: Into<i256>,

§

type Output = i256

The resulting type after applying the ^ operator.
source§

fn bitxor(self, other: T) -> i256

Performs the ^ operation. Read more
source§

impl<T> BitXorAssign<T> for i256
where T: Into<i256>,

source§

fn bitxor_assign(&mut self, rhs: T)

Performs the ^= operation. Read more
source§

impl Clone for i256

source§

fn clone(&self) -> i256

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for i256

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for i256

source§

fn default() -> i256

Returns the “default value” for a type. Read more
source§

impl Display for i256

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Div<T> for i256
where T: Into<i256>,

§

type Output = i256

The resulting type after applying the / operator.
source§

fn div(self, other: T) -> i256

Performs the / operation. Read more
source§

impl<T> DivAssign<T> for i256
where T: Into<i256>,

source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
source§

impl From<bool> for i256

source§

fn from(init: bool) -> i256

Converts to this type from the input type.
source§

impl From<i128> for i256

source§

fn from(init: i128) -> i256

Converts to this type from the input type.
source§

impl From<i16> for i256

source§

fn from(init: i16) -> i256

Converts to this type from the input type.
source§

impl From<i32> for i256

source§

fn from(init: i32) -> i256

Converts to this type from the input type.
source§

impl From<i64> for i256

source§

fn from(init: i64) -> i256

Converts to this type from the input type.
source§

impl From<i8> for i256

source§

fn from(init: i8) -> i256

Converts to this type from the input type.
source§

impl From<u128> for i256

source§

fn from(init: u128) -> i256

Converts to this type from the input type.
source§

impl From<u16> for i256

source§

fn from(init: u16) -> i256

Converts to this type from the input type.
source§

impl From<u32> for i256

source§

fn from(init: u32) -> i256

Converts to this type from the input type.
source§

impl From<u64> for i256

source§

fn from(init: u64) -> i256

Converts to this type from the input type.
source§

impl From<u8> for i256

source§

fn from(init: u8) -> i256

Converts to this type from the input type.
source§

impl Hash for i256

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Index<Range<usize>> for i256

§

type Output = [u64]

The returned type after indexing.
source§

fn index(&self, index: Range<usize>) -> &[u64]

Performs the indexing (container[index]) operation. Read more
source§

impl Index<RangeFrom<usize>> for i256

§

type Output = [u64]

The returned type after indexing.
source§

fn index(&self, index: RangeFrom<usize>) -> &[u64]

Performs the indexing (container[index]) operation. Read more
source§

impl Index<RangeFull> for i256

§

type Output = [u64]

The returned type after indexing.
source§

fn index(&self, _: RangeFull) -> &[u64]

Performs the indexing (container[index]) operation. Read more
source§

impl Index<RangeTo<usize>> for i256

§

type Output = [u64]

The returned type after indexing.
source§

fn index(&self, index: RangeTo<usize>) -> &[u64]

Performs the indexing (container[index]) operation. Read more
source§

impl Index<usize> for i256

§

type Output = u64

The returned type after indexing.
source§

fn index(&self, index: usize) -> &u64

Performs the indexing (container[index]) operation. Read more
source§

impl<T> Mul<T> for i256
where T: Into<i256>,

§

type Output = i256

The resulting type after applying the * operator.
source§

fn mul(self, other: T) -> i256

Performs the * operation. Read more
source§

impl<T> MulAssign<T> for i256
where T: Into<i256>,

source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
source§

impl Neg for i256

§

type Output = i256

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl Not for i256

§

type Output = i256

The resulting type after applying the ! operator.
source§

fn not(self) -> i256

Performs the unary ! operation. Read more
source§

impl Ord for i256

source§

fn cmp(&self, other: &i256) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for i256

source§

fn eq(&self, other: &i256) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for i256

source§

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 · source§

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T> Rem<T> for i256
where T: Into<i256>,

§

type Output = i256

The resulting type after applying the % operator.
source§

fn rem(self, other: T) -> i256

Performs the % operation. Read more
source§

impl<T> RemAssign<T> for i256
where T: Into<i256>,

source§

fn rem_assign(&mut self, rhs: T)

Performs the %= operation. Read more
source§

impl Shl<usize> for i256

§

type Output = i256

The resulting type after applying the << operator.
source§

fn shl(self, shift: usize) -> i256

Performs the << operation. Read more
source§

impl ShlAssign<usize> for i256

source§

fn shl_assign(&mut self, rhs: usize)

Performs the <<= operation. Read more
source§

impl Shr<usize> for i256

§

type Output = i256

The resulting type after applying the >> operator.
source§

fn shr(self, shift: usize) -> i256

Performs the >> operation. Read more
source§

impl ShrAssign<usize> for i256

source§

fn shr_assign(&mut self, rhs: usize)

Performs the >>= operation. Read more
source§

impl<T> Sub<T> for i256
where T: Into<i256>,

§

type Output = i256

The resulting type after applying the - operator.
source§

fn sub(self, other: T) -> i256

Performs the - operation. Read more
source§

impl<T> SubAssign<T> for i256
where T: Into<i256>,

source§

fn sub_assign(&mut self, rhs: T)

Performs the -= operation. Read more
source§

impl<'a> TryFrom<&'a [u64]> for i256

§

type Error = ParseLengthError

The type returned in the event of a conversion error.
source§

fn try_from(data: &'a [u64]) -> Result<i256, Self::Error>

Performs the conversion.
source§

impl Copy for i256

source§

impl Eq for i256

source§

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.