Struct core::num::bignum::Big32x40

source ·
pub struct Big32x40 {
    size: usize,
    base: [Digit32; 40],
}
🔬This is a nightly-only experimental API. (core_private_bignum)
Expand description

Stack-allocated arbitrary-precision (up to certain limit) integer.

This is backed by a fixed-size array of given type (“digit”). While the array is not very large (normally some hundred bytes), copying it recklessly may result in the performance hit. Thus this is intentionally not Copy.

All operations available to bignums panic in the case of overflows. The caller is responsible to use large enough bignum types.

Fields§

§size: usize
🔬This is a nightly-only experimental API. (core_private_bignum)

One plus the offset to the maximum “digit” in use. This does not decrease, so be aware of the computation order. base[size..] should be zero.

§base: [Digit32; 40]
🔬This is a nightly-only experimental API. (core_private_bignum)

Digits. [a, b, c, ...] represents a + b*2^W + c*2^(2W) + ... where W is the number of bits in the digit type.

Implementations§

source§

impl Big32x40

source

pub fn from_small(v: Digit32) -> Big32x40

🔬This is a nightly-only experimental API. (core_private_bignum)

Makes a bignum from one digit.

source

pub fn from_u64(v: u64) -> Big32x40

🔬This is a nightly-only experimental API. (core_private_bignum)

Makes a bignum from u64 value.

source

pub fn digits(&self) -> &[Digit32]

🔬This is a nightly-only experimental API. (core_private_bignum)

Returns the internal digits as a slice [a, b, c, ...] such that the numeric value is a + b * 2^W + c * 2^(2W) + ... where W is the number of bits in the digit type.

source

pub fn get_bit(&self, i: usize) -> u8

🔬This is a nightly-only experimental API. (core_private_bignum)

Returns the i-th bit where bit 0 is the least significant one. In other words, the bit with weight 2^i.

source

pub fn is_zero(&self) -> bool

🔬This is a nightly-only experimental API. (core_private_bignum)

Returns true if the bignum is zero.

source

pub fn bit_length(&self) -> usize

🔬This is a nightly-only experimental API. (core_private_bignum)

Returns the number of bits necessary to represent this value. Note that zero is considered to need 0 bits.

source

pub fn add<'a>(&'a mut self, other: &Big32x40) -> &'a mut Big32x40

🔬This is a nightly-only experimental API. (core_private_bignum)

Adds other to itself and returns its own mutable reference.

source

pub fn add_small(&mut self, other: Digit32) -> &mut Big32x40

🔬This is a nightly-only experimental API. (core_private_bignum)
source

pub fn sub<'a>(&'a mut self, other: &Big32x40) -> &'a mut Big32x40

🔬This is a nightly-only experimental API. (core_private_bignum)

Subtracts other from itself and returns its own mutable reference.

source

pub fn mul_small(&mut self, other: Digit32) -> &mut Big32x40

🔬This is a nightly-only experimental API. (core_private_bignum)

Multiplies itself by a digit-sized other and returns its own mutable reference.

source

pub fn mul_pow2(&mut self, bits: usize) -> &mut Big32x40

🔬This is a nightly-only experimental API. (core_private_bignum)

Multiplies itself by 2^bits and returns its own mutable reference.

source

pub fn mul_pow5(&mut self, e: usize) -> &mut Big32x40

🔬This is a nightly-only experimental API. (core_private_bignum)

Multiplies itself by 5^e and returns its own mutable reference.

source

pub fn mul_digits<'a>(&'a mut self, other: &[Digit32]) -> &'a mut Big32x40

🔬This is a nightly-only experimental API. (core_private_bignum)

Multiplies itself by a number described by other[0] + other[1] * 2^W + other[2] * 2^(2W) + ... (where W is the number of bits in the digit type) and returns its own mutable reference.

source

pub fn div_rem_small(&mut self, other: Digit32) -> (&mut Big32x40, Digit32)

🔬This is a nightly-only experimental API. (core_private_bignum)

Divides itself by a digit-sized other and returns its own mutable reference and the remainder.

source

pub fn div_rem(&self, d: &Big32x40, q: &mut Big32x40, r: &mut Big32x40)

🔬This is a nightly-only experimental API. (core_private_bignum)

Divide self by another bignum, overwriting q with the quotient and r with the remainder.

Trait Implementations§

source§

impl Clone for Big32x40

source§

fn clone(&self) -> Self

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 Big32x40

source§

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

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

impl Eq for Big32x40

source§

impl Ord for Big32x40

source§

fn cmp(&self, other: &Big32x40) -> 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,

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

impl PartialEq<Big32x40> for Big32x40

source§

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

source§

fn partial_cmp(&self, other: &Big32x40) -> 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

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,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> SizedTypeProperties for T

source§

const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
source§

impl<T> SpecOptionPartialEq for Twhere T: PartialEq<T>,

source§

default fn eq(l: &Option<T>, r: &Option<T>) -> bool

🔬This is a nightly-only experimental API. (spec_option_partial_eq)
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.