pub struct Big32x40 {
size: usize,
base: [Digit32; 40],
}
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
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]
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
impl Big32x40
sourcepub fn from_small(v: Digit32) -> Big32x40
🔬This is a nightly-only experimental API. (core_private_bignum
)
pub fn from_small(v: Digit32) -> Big32x40
core_private_bignum
)Makes a bignum from one digit.
sourcepub fn from_u64(v: u64) -> Big32x40
🔬This is a nightly-only experimental API. (core_private_bignum
)
pub fn from_u64(v: u64) -> Big32x40
core_private_bignum
)Makes a bignum from u64
value.
sourcepub fn digits(&self) -> &[Digit32]
🔬This is a nightly-only experimental API. (core_private_bignum
)
pub fn digits(&self) -> &[Digit32]
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.
sourcepub fn get_bit(&self, i: usize) -> u8
🔬This is a nightly-only experimental API. (core_private_bignum
)
pub fn get_bit(&self, i: usize) -> u8
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
.
sourcepub fn is_zero(&self) -> bool
🔬This is a nightly-only experimental API. (core_private_bignum
)
pub fn is_zero(&self) -> bool
core_private_bignum
)Returns true
if the bignum is zero.
sourcepub fn bit_length(&self) -> usize
🔬This is a nightly-only experimental API. (core_private_bignum
)
pub fn bit_length(&self) -> usize
core_private_bignum
)Returns the number of bits necessary to represent this value. Note that zero is considered to need 0 bits.
sourcepub fn add<'a>(&'a mut self, other: &Big32x40) -> &'a mut Big32x40
🔬This is a nightly-only experimental API. (core_private_bignum
)
pub fn add<'a>(&'a mut self, other: &Big32x40) -> &'a mut Big32x40
core_private_bignum
)Adds other
to itself and returns its own mutable reference.
pub fn add_small(&mut self, other: Digit32) -> &mut Big32x40
core_private_bignum
)sourcepub fn sub<'a>(&'a mut self, other: &Big32x40) -> &'a mut Big32x40
🔬This is a nightly-only experimental API. (core_private_bignum
)
pub fn sub<'a>(&'a mut self, other: &Big32x40) -> &'a mut Big32x40
core_private_bignum
)Subtracts other
from itself and returns its own mutable reference.
sourcepub fn mul_small(&mut self, other: Digit32) -> &mut Big32x40
🔬This is a nightly-only experimental API. (core_private_bignum
)
pub fn mul_small(&mut self, other: Digit32) -> &mut Big32x40
core_private_bignum
)Multiplies itself by a digit-sized other
and returns its own
mutable reference.
sourcepub fn mul_pow2(&mut self, bits: usize) -> &mut Big32x40
🔬This is a nightly-only experimental API. (core_private_bignum
)
pub fn mul_pow2(&mut self, bits: usize) -> &mut Big32x40
core_private_bignum
)Multiplies itself by 2^bits
and returns its own mutable reference.
sourcepub fn mul_pow5(&mut self, e: usize) -> &mut Big32x40
🔬This is a nightly-only experimental API. (core_private_bignum
)
pub fn mul_pow5(&mut self, e: usize) -> &mut Big32x40
core_private_bignum
)Multiplies itself by 5^e
and returns its own mutable reference.
sourcepub fn mul_digits<'a>(&'a mut self, other: &[Digit32]) -> &'a mut Big32x40
🔬This is a nightly-only experimental API. (core_private_bignum
)
pub fn mul_digits<'a>(&'a mut self, other: &[Digit32]) -> &'a mut Big32x40
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.
sourcepub fn div_rem_small(&mut self, other: Digit32) -> (&mut Big32x40, Digit32)
🔬This is a nightly-only experimental API. (core_private_bignum
)
pub fn div_rem_small(&mut self, other: Digit32) -> (&mut Big32x40, Digit32)
core_private_bignum
)Divides itself by a digit-sized other
and returns its own
mutable reference and the remainder.
Trait Implementations§
source§impl Ord for Big32x40
impl Ord for Big32x40
source§impl PartialEq<Big32x40> for Big32x40
impl PartialEq<Big32x40> for Big32x40
source§impl PartialOrd<Big32x40> for Big32x40
impl PartialOrd<Big32x40> for Big32x40
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 more