Struct Big8x3

pub struct Big8x3 { pub(in ::num::imp::bignum::tests) size: usize, pub(in ::num::imp::bignum::tests) base: [u8; 3] }

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

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]

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

Implementations

impl Big8x3

fn from_small(v: u8) -> Big8x3

Makes a bignum from one digit.

fn from_u64(v: u64) -> Big8x3

Makes a bignum from u64 value.

fn digits(&self) -> &[u8]

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.

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

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

fn is_zero(&self) -> bool

Returns true if the bignum is zero.

fn bit_length(&self) -> usize

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

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

Adds other to itself and returns its own mutable reference.

fn add_small(&mut self, other: u8) -> &mut Big8x3
fn sub<'a>(&'a mut self, other: &Big8x3) -> &'a mut Big8x3

Subtracts other from itself and returns its own mutable reference.

fn mul_small(&mut self, other: u8) -> &mut Big8x3

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

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

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

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

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

fn mul_digits<'a>(&'a mut self, other: &[u8]) -> &'a mut Big8x3

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.

fn div_rem_small(&mut self, other: u8) -> (&mut Big8x3, u8)

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

Trait Implementations

impl Clone for Big8x3

fn clone(&self) -> Self

impl Debug for Big8x3

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

impl Eq for Big8x3

impl Ord for Big8x3

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

impl PartialEq for Big8x3

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

impl PartialOrd for Big8x3

fn partial_cmp(&self, other: &Big8x3) -> Option<Ordering>

impl UseCloned for Big8x3

Auto Trait Implementations

impl Freeze for Big8x3

impl RefUnwindSafe for Big8x3

impl Send for Big8x3

impl Sync for Big8x3

impl Unpin for Big8x3

impl UnsafeUnpin for Big8x3

impl UnwindSafe for Big8x3

Blanket Implementations

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

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Big8x3 where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Big8x3 where T: ?Sized,

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

impl<T> CloneToUninit for Big8x3 where T: Clone,

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

impl<T> From<T> for Big8x3

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> SizeHint for Big8x3 where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for Big8x3

impl<T, U> Into<U> for Big8x3 where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

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

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

impl<T, U> TryInto<U> for Big8x3 where U: TryFrom<T>,

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