Struct kaspa_math::Uint256

source ·
pub struct Uint256(pub [u64; 4]);
Expand description

Little-endian large integer type

Tuple Fields§

§0: [u64; 4]

Implementations§

source§

impl Uint256

source

pub const ZERO: Self = _

source

pub const MIN: Self = Self::ZERO

source

pub const MAX: Self = _

source

pub const BITS: u32 = 256u32

source

pub const BYTES: usize = 32usize

source

pub const LIMBS: usize = 4usize

source

pub fn from_u64(n: u64) -> Self

source

pub fn from_u128(n: u128) -> Self

source

pub fn as_u128(self) -> u128

source

pub fn as_u64(self) -> u64

source

pub fn is_zero(self) -> bool

source

pub fn bits(&self) -> u32

Return the least number of bits needed to represent the number

source

pub fn leading_zeros(&self) -> u32

source

pub fn overflowing_shl(self, s: u32) -> (Self, bool)

source

pub fn wrapping_shl(self, s: u32) -> Self

source

pub fn overflowing_shr(self, s: u32) -> (Self, bool)

source

pub fn overflowing_add(self, other: Self) -> (Self, bool)

source

pub fn overflowing_add_u64(self, other: u64) -> (Self, bool)

source

pub fn overflowing_sub(self, other: Self) -> (Self, bool)

source

pub fn overflowing_mul_u64(self, other: u64) -> (Self, bool)

Multiplication by u64

source

pub fn carrying_mul_u64(self, other: u64) -> (Self, u64)

source

pub fn overflowing_mul(self, other: Self) -> (Self, bool)

source

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

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

source

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

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

source

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

Convert’s the Uint into little endian byte array

source

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

Convert’s the Uint into big endian byte array

source

pub fn to_be_bytes_var(self) -> Vec<u8>

source

pub fn div_rem_u64(self, other: u64) -> (Self, u64)

source

pub fn as_f64(&self) -> f64

source

pub fn div_rem(self, other: Self) -> (Self, Self)

source

pub fn mod_inverse(self, prime: Self) -> Option<Self>

Assumes self < prime

source

pub fn iter_be_bits(self) -> impl ExactSizeIterator<Item = bool> + FusedIterator

source

pub fn from_hex(hex: &str) -> Result<Self, Error>

Converts a Self::BYTES*2 hex string interpreted as big endian, into a Uint

source

pub fn from_be_bytes_var(bytes: &[u8]) -> Result<Self, TryFromSliceError>

source§

impl Uint256

source

pub fn from_compact_target_bits(bits: u32) -> Self

source

pub fn compact_target_bits(self) -> u32

Computes the target value in float format from BigInt format.

Trait Implementations§

source§

impl Add<Uint256> for Uint256

§

type Output = Uint256

The resulting type after applying the + operator.
source§

fn add(self, other: Uint256) -> Uint256

Performs the + operation. Read more
source§

impl Add<u64> for Uint256

§

type Output = Uint256

The resulting type after applying the + operator.
source§

fn add(self, other: u64) -> Uint256

Performs the + operation. Read more
source§

impl Binary for Uint256

source§

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

Formats the value using the given formatter.
source§

impl BitAnd<Uint256> for Uint256

§

type Output = Uint256

The resulting type after applying the & operator.
source§

fn bitand(self, other: Uint256) -> Uint256

Performs the & operation. Read more
source§

impl BitOr<Uint256> for Uint256

§

type Output = Uint256

The resulting type after applying the | operator.
source§

fn bitor(self, other: Uint256) -> Uint256

Performs the | operation. Read more
source§

impl BitXor<Uint256> for Uint256

§

type Output = Uint256

The resulting type after applying the ^ operator.
source§

fn bitxor(self, other: Uint256) -> Uint256

Performs the ^ operation. Read more
source§

impl Clone for Uint256

source§

fn clone(&self) -> Uint256

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 Uint256

source§

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

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

impl Default for Uint256

source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Uint256

source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Uint256

source§

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

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

impl Div<Uint256> for Uint256

§

type Output = Uint256

The resulting type after applying the / operator.
source§

fn div(self, other: Uint256) -> Uint256

Performs the / operation. Read more
source§

impl Div<u64> for Uint256

§

type Output = Uint256

The resulting type after applying the / operator.
source§

fn div(self, other: u64) -> Uint256

Performs the / operation. Read more
source§

impl From<Uint256> for Uint256

source§

fn from(inner: Uint256) -> Self

Converts to this type from the input type.
source§

impl From<Uint256> for Uint256

source§

fn from(v: Uint256) -> Self

Converts to this type from the input type.
source§

impl From<Uint256> for Uint320

source§

fn from(u: Uint256) -> Self

Converts to this type from the input type.
source§

impl From<u64> for Uint256

source§

fn from(x: u64) -> Self

Converts to this type from the input type.
source§

impl Hash for Uint256

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 LowerHex for Uint256

source§

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

Formats the value using the given formatter.
source§

impl Mul<Uint256> for Uint256

§

type Output = Uint256

The resulting type after applying the * operator.
source§

fn mul(self, other: Uint256) -> Uint256

Performs the * operation. Read more
source§

impl Mul<u64> for Uint256

§

type Output = Uint256

The resulting type after applying the * operator.
source§

fn mul(self, other: u64) -> Uint256

Performs the * operation. Read more
source§

impl Not for Uint256

§

type Output = Uint256

The resulting type after applying the ! operator.
source§

fn not(self) -> Uint256

Performs the unary ! operation. Read more
source§

impl Ord for Uint256

source§

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

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

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

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

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

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

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

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

impl PartialEq<Uint256> for Uint256

source§

fn eq(&self, other: &Uint256) -> 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 PartialEq<u128> for Uint256

source§

fn eq(&self, other: &u128) -> 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 PartialEq<u64> for Uint256

source§

fn eq(&self, other: &u64) -> 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<Uint256> for Uint256

source§

fn partial_cmp(&self, other: &Uint256) -> 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 PartialOrd<u128> for Uint256

source§

fn partial_cmp(&self, other: &u128) -> 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 PartialOrd<u64> for Uint256

source§

fn partial_cmp(&self, other: &u64) -> 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<'a> Product<&'a Uint256> for Uint256

source§

fn product<I: Iterator<Item = &'a Self>>(iter: I) -> Self

Method which takes an iterator and generates Self from the elements by multiplying the items.
source§

impl Product<Uint256> for Uint256

source§

fn product<I: Iterator<Item = Self>>(iter: I) -> Self

Method which takes an iterator and generates Self from the elements by multiplying the items.
source§

impl Rem<Uint256> for Uint256

§

type Output = Uint256

The resulting type after applying the % operator.
source§

fn rem(self, other: Uint256) -> Uint256

Performs the % operation. Read more
source§

impl Rem<u64> for Uint256

§

type Output = u64

The resulting type after applying the % operator.
source§

fn rem(self, other: u64) -> u64

Performs the % operation. Read more
source§

impl Serialize for Uint256

source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
source§

impl Shl<u32> for Uint256

§

type Output = Uint256

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

fn shl(self, shift: u32) -> Uint256

Performs the << operation. Read more
source§

impl Shr<u32> for Uint256

§

type Output = Uint256

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

fn shr(self, shift: u32) -> Uint256

Performs the >> operation. Read more
source§

impl Sub<Uint256> for Uint256

§

type Output = Uint256

The resulting type after applying the - operator.
source§

fn sub(self, other: Uint256) -> Uint256

Performs the - operation. Read more
source§

impl<'a> Sum<&'a Uint256> for Uint256

source§

fn sum<I: Iterator<Item = &'a Self>>(iter: I) -> Self

Method which takes an iterator and generates Self from the elements by “summing up” the items.
source§

impl Sum<Uint256> for Uint256

source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Method which takes an iterator and generates Self from the elements by “summing up” the items.
source§

impl TryFrom<Uint256> for Uint192

§

type Error = TryFromIntError

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

fn try_from(value: Uint256) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Uint256> for u128

§

type Error = TryFromIntError

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

fn try_from(value: Uint256) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Uint320> for Uint256

§

type Error = TryFromIntError

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

fn try_from(value: Uint320) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Copy for Uint256

source§

impl Eq for Uint256

source§

impl StructuralEq for Uint256

source§

impl StructuralPartialEq for Uint256

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T, U> ExactFrom<T> for Uwhere U: TryFrom<T>,

source§

fn exact_from(value: T) -> U

source§

impl<T, U> ExactInto<U> for Twhere U: ExactFrom<T>,

source§

fn exact_into(self) -> U

source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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> OverflowingInto<U> for Twhere U: OverflowingFrom<T>,

source§

impl<T, U> RoundingInto<U> for Twhere U: RoundingFrom<T>,

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> SaturatingInto<U> for Twhere U: SaturatingFrom<T>,

source§

impl<T> ToBinaryString for Twhere T: Binary,

source§

fn to_binary_string(&self) -> String

Returns the String produced by Ts Binary implementation.

Examples
use malachite_base::strings::ToBinaryString;

assert_eq!(5u64.to_binary_string(), "101");
assert_eq!((-100i16).to_binary_string(), "1111111110011100");
source§

impl<T> ToDebugString for Twhere T: Debug,

source§

fn to_debug_string(&self) -> String

Returns the String produced by Ts Debug implementation.

Examples
use malachite_base::strings::ToDebugString;

assert_eq!([1, 2, 3].to_debug_string(), "[1, 2, 3]");
assert_eq!(
    [vec![2, 3], vec![], vec![4]].to_debug_string(),
    "[[2, 3], [], [4]]"
);
assert_eq!(Some(5).to_debug_string(), "Some(5)");
source§

impl<T> ToLowerHexString for Twhere T: LowerHex,

source§

fn to_lower_hex_string(&self) -> String

Returns the String produced by Ts LowerHex implementation.

Examples
use malachite_base::strings::ToLowerHexString;

assert_eq!(50u64.to_lower_hex_string(), "32");
assert_eq!((-100i16).to_lower_hex_string(), "ff9c");
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

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

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T, U> WrappingInto<U> for Twhere U: WrappingFrom<T>,

source§

fn wrapping_into(self) -> U

source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,