pub struct Big8x3 {
size: usize,
base: [u8; 3],
}
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: [u8; 3]
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 Big8x3
impl Big8x3
sourcepub fn from_small(v: u8) -> Big8x3
🔬This is a nightly-only experimental API. (core_private_bignum
)
pub fn from_small(v: u8) -> Big8x3
core_private_bignum
)Makes a bignum from one digit.
sourcepub fn from_u64(v: u64) -> Big8x3
🔬This is a nightly-only experimental API. (core_private_bignum
)
pub fn from_u64(v: u64) -> Big8x3
core_private_bignum
)Makes a bignum from u64
value.
sourcepub fn digits(&self) -> &[u8]
🔬This is a nightly-only experimental API. (core_private_bignum
)
pub fn digits(&self) -> &[u8]
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: &Big8x3) -> &'a mut Big8x3
🔬This is a nightly-only experimental API. (core_private_bignum
)
pub fn add<'a>(&'a mut self, other: &Big8x3) -> &'a mut Big8x3
core_private_bignum
)Adds other
to itself and returns its own mutable reference.
pub fn add_small(&mut self, other: u8) -> &mut Big8x3
core_private_bignum
)sourcepub fn sub<'a>(&'a mut self, other: &Big8x3) -> &'a mut Big8x3
🔬This is a nightly-only experimental API. (core_private_bignum
)
pub fn sub<'a>(&'a mut self, other: &Big8x3) -> &'a mut Big8x3
core_private_bignum
)Subtracts other
from itself and returns its own mutable reference.
sourcepub fn mul_small(&mut self, other: u8) -> &mut Big8x3
🔬This is a nightly-only experimental API. (core_private_bignum
)
pub fn mul_small(&mut self, other: u8) -> &mut Big8x3
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 Big8x3
🔬This is a nightly-only experimental API. (core_private_bignum
)
pub fn mul_pow2(&mut self, bits: usize) -> &mut Big8x3
core_private_bignum
)Multiplies itself by 2^bits
and returns its own mutable reference.
sourcepub fn mul_pow5(&mut self, e: usize) -> &mut Big8x3
🔬This is a nightly-only experimental API. (core_private_bignum
)
pub fn mul_pow5(&mut self, e: usize) -> &mut Big8x3
core_private_bignum
)Multiplies itself by 5^e
and returns its own mutable reference.
sourcepub fn mul_digits<'a>(&'a mut self, other: &[u8]) -> &'a mut Big8x3
🔬This is a nightly-only experimental API. (core_private_bignum
)
pub fn mul_digits<'a>(&'a mut self, other: &[u8]) -> &'a mut Big8x3
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: u8) -> (&mut Big8x3, u8)
🔬This is a nightly-only experimental API. (core_private_bignum
)
pub fn div_rem_small(&mut self, other: u8) -> (&mut Big8x3, u8)
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 Big8x3
impl Ord for Big8x3
source§impl PartialEq<Big8x3> for Big8x3
impl PartialEq<Big8x3> for Big8x3
source§impl PartialOrd<Big8x3> for Big8x3
impl PartialOrd<Big8x3> for Big8x3
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