i256

Struct 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]) -> i256

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>,

Source§

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>,

Source§

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>,

Source§

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>,

Source§

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 duplicate 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<(), Error>

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<(), Error>

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

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

Source§

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>(&self, state: &mut __H)
where __H: Hasher,

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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>,

Source§

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

Source§

type Output = i256

The resulting type after applying the - operator.
Source§

fn neg(self) -> <i256 as Neg>::Output

Performs the unary - operation. Read more
Source§

impl Not for i256

Source§

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,

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

impl PartialEq for i256

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

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

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

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

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>,

Source§

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

Source§

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

Source§

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>,

Source§

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

Source§

type Error = ParseLengthError

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

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

Performs the conversion.
Source§

impl Copy for i256

Source§

impl Eq for i256

Source§

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

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>,

Source§

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.

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: 32 bytes