Loose

Struct Loose 

Source
pub struct Loose<const BASE: usize> { /* private fields */ }
Expand description

A loosely-packed arbitrary base big int implementation. Supports any base from 2-u64::MAX.

Each digit requires 8 bytes of storage, making this a very space-inefficient implementation for smaller bases. However, the lack of additional complexity improves runtime efficiency over the tightly-packed implementation.

use big_int::prelude::*;

let a: Loose<10> = 593.into();
let b = a * 96.into();
assert_eq!(b, 56928.into());

Implementations§

Source§

impl<const BASE: usize> Loose<BASE>

Source

pub unsafe fn from_raw_parts(digits: Vec<Digit>) -> Self

Create a new loose int directly from a Vec of individual digits.

Ensure the resulting int is properly normalized, and that no digits are greater than or equal to the base, to preserve soundness.

To construct a negative int from raw parts, simply apply the negation operator (-) afterwards.

use big_int::prelude::*;

assert_eq!(
    -unsafe { Loose::<10>::from_raw_parts(vec![1, 5]) },
    (-15).into()
);

Trait Implementations§

Source§

impl<const BASE: usize> Add for Loose<BASE>

Source§

type Output = Loose<BASE>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<const BASE: usize> AddAssign for Loose<BASE>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<const BASE: usize> BigInt<BASE> for Loose<BASE>

Source§

fn normalized(self) -> Self

Return a normalized version of the int. Remove trailing zeros, and disable the parity flag if the resulting number is zero.

use big_int::prelude::*;

let n = unsafe { Loose::<10>::from_raw_parts(vec![0, 0, 8, 3]) };
assert_eq!(n.normalized(), 83.into());
Source§

type Builder = LooseBuilder<BASE>

Source§

type Denormal = Denormal<BASE, Loose<BASE>>

Source§

fn len(&self) -> usize

The length of the big int in digits. Read more
Source§

fn get_digit(&self, digit: usize) -> Option<Digit>

Get the digit of the big int at position digit, or None if the number does not have that many digits. Read more
Source§

fn set_digit(&mut self, digit: usize, value: Digit)

Set the digit of the big int to value at position digit. Read more
Source§

fn zero() -> Self

The value zero represented as a big int. Read more
Source§

fn with_sign(self, sign: Sign) -> Self

The big int with the given sign. Read more
Source§

fn sign(&self) -> Sign

The sign of the big int. Read more
Source§

fn set_sign(&mut self, sign: Sign)

Set the sign of the big int to sign. Read more
Source§

fn push_back(&mut self, digit: Digit)

Append a digit to the right side of the int. Equivalent to (int << 1) + digit Read more
Source§

unsafe fn push_front(&mut self, digit: Digit)

Append a digit to the left side of the int. Read more
Source§

unsafe fn shr_assign_inner(&mut self, amount: usize)

Divide the int by BASE^amount in place. Read more
Source§

unsafe fn shl_assign_inner(&mut self, amount: usize)

Multiply the int by BASE^amount in place. Read more
Source§

unsafe fn pop_back(&mut self) -> Option<Digit>

Pop the rightmost digit from the end of the int, and return it. Read more
Source§

unsafe fn pop_front(&mut self) -> Option<Digit>

Pop the leftmost digit from the end of the int, and return it. Read more
Source§

const BITS_PER_DIGIT: usize = _

Source§

fn get_back_inner(&self, index: usize) -> Option<Digit>

Default implementation of big_int::GetBack. Read more
Source§

fn default_inner() -> Self

Default implementation of Default. Read more
Source§

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

Default implementation of Display. Read more
Source§

fn partial_cmp_inner<RHS: BigInt<BASE>>(&self, other: &RHS) -> Option<Ordering>

Default implementation of PartialOrd. Read more
Source§

fn cmp_inner<RHS: BigInt<BASE>>(&self, other: &RHS) -> Ordering

Default implementation of Ord. Read more
Source§

fn eq_inner<RHS: BigInt<BASE>>(&self, other: &RHS) -> bool

Default implementation of PartialEq. Read more
Source§

fn neg_inner(self) -> Self::Denormal

Default implementation of Neg. Read more
Source§

fn add_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> OUT::Denormal

Default implementation of Add. Read more
Source§

unsafe fn add_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)

Default implementation of AddAssign. Read more
Source§

fn sub_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> OUT::Denormal

Default implementation of Sub. Read more
Source§

unsafe fn sub_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)

Default implementation of SubAssign. Read more
Source§

fn mul_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> OUT::Denormal

Default implementation of Mul. Read more
Source§

unsafe fn mul_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)

Default implementation of MulAssign. Read more
Source§

fn div_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> OUT::Denormal

Default implementation of Div. Read more
Source§

unsafe fn div_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)

Default implementation of DivAssign. Read more
Source§

fn from_str_inner(s: &str) -> Result<Self::Denormal, BigIntError>

Default implementation of FromStr. Read more
Source§

fn from_iter_inner<T: IntoIterator<Item = Digit>>(iter: T) -> Self::Denormal

Default implementation of FromIterator. Read more
Source§

fn from_u128_inner(value: u128) -> Self::Denormal

Default implementation of From<_> for all unsigned primitive int types. Read more
Source§

fn from_i128_inner(value: i128) -> Self::Denormal

Default implementation of From<_> for all signed primitive int types. Read more
Source§

fn into_u128_inner(self) -> u128

Default implementation of Into<_> for all unsigned primitive int types. Read more
Source§

fn into_i128_inner(self) -> i128

Default implementation of Into<_> for all signed primitive int types. Read more
Source§

fn is_zero(&self) -> bool

Check if the big int is zero. Read more
Source§

fn shr_inner(self, amount: usize) -> Self::Denormal

Divide the int by BASE^amount. Read more
Source§

fn shl_inner(self, amount: usize) -> Self::Denormal

Multiply the int by BASE^amount. Read more
Source§

fn div_rem_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<(OUT::Denormal, OUT::Denormal), BigIntError>

Divide one int by another, returning the quotient & remainder as a pair. Returns the result as a denormalized pair. Read more
Source§

fn div_rem<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<(OUT, OUT), BigIntError>

Divide one int by another, returning the quotient & remainder as a pair. Read more
Source§

fn exp_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT::Denormal, BigIntError>

Exponentiate the big int by rhs. Returns the result as a denormalized number. Read more
Source§

fn exp<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT, BigIntError>

Exponentiate the big int by rhs. Read more
Source§

fn log_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT::Denormal, BigIntError>

Compute the logarithm of the big int with the base rhs. Returns the result as a denormalized number. Read more
Source§

fn log<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT, BigIntError>

Compute the logarithm of the big int with the base rhs. Read more
Source§

fn root_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT::Denormal, BigIntError>

Compute the nth root of the big int, with root rhs. Returns the result as a denormalized number. Read more
Source§

fn root<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT, BigIntError>

Compute the nth root of the big int, with root rhs. Read more
Source§

fn is_even(&self) -> bool

Check if the number is even. Read more
Source§

fn iter<'a>(&'a self) -> BigIntIter<'a, BASE, Self>

Iterate over the digits of the int. Read more
Source§

fn normalize(&mut self)

Normalize a big int in place. A normalized int: Read more
Source§

fn display(&self, alphabet: &str) -> Result<String, BigIntError>

Convert a big int to a printable string using the provided alphabet alphabet. Display uses this method with the default alphabet STANDARD_ALPHABET. Read more
Source§

fn parse(value: &str, alphabet: &str) -> Result<Self::Denormal, ParseError>

Parse a big int from a value: &str, referencing the provided alphabet to determine what characters represent which digits. FromStr uses this method with the default alphabet STANDARD_ALPHABET. Read more
Source§

fn convert_inner<const TO: usize, OUT: BigInt<TO>>(self) -> OUT::Denormal

Convert an int from its own base to another target base, to another BigInt type, or both at once. Returns the result as a denormalized number. Read more
Source§

fn convert<const TO: usize, OUT: BigInt<TO>>(self) -> OUT

Convert an int from its own base to another target base, to another BigInt type, or both at once. Read more
Source§

fn cmp_magnitude<RHS: BigInt<BASE>>(&self, rhs: &RHS) -> Ordering

Compare the absolute magnitude of two big ints, ignoring their sign. Read more
Source§

fn abs(self) -> Self

Return the absolute value of the int. Read more
Source§

impl<const BASE: usize> Clone for Loose<BASE>

Source§

fn clone(&self) -> Loose<BASE>

Returns a duplicate 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<const BASE: usize> Debug for Loose<BASE>

Source§

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

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

impl<const BASE: usize> Default for Loose<BASE>

Source§

fn default() -> Self

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

impl<const BASE: usize> Display for Loose<BASE>

Source§

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

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

impl<const BASE: usize> Div for Loose<BASE>

Source§

type Output = Loose<BASE>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl<const BASE: usize> DivAssign for Loose<BASE>

Source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
Source§

impl<const BASE: usize> From<Loose<BASE>> for i128

Source§

fn from(value: Loose<BASE>) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<Loose<BASE>> for i16

Source§

fn from(value: Loose<BASE>) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<Loose<BASE>> for i32

Source§

fn from(value: Loose<BASE>) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<Loose<BASE>> for i64

Source§

fn from(value: Loose<BASE>) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<Loose<BASE>> for i8

Source§

fn from(value: Loose<BASE>) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<Loose<BASE>> for isize

Source§

fn from(value: Loose<BASE>) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<Loose<BASE>> for u128

Source§

fn from(value: Loose<BASE>) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<Loose<BASE>> for u16

Source§

fn from(value: Loose<BASE>) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<Loose<BASE>> for u32

Source§

fn from(value: Loose<BASE>) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<Loose<BASE>> for u64

Source§

fn from(value: Loose<BASE>) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<Loose<BASE>> for u8

Source§

fn from(value: Loose<BASE>) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<Loose<BASE>> for usize

Source§

fn from(value: Loose<BASE>) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<LooseBuilder<BASE>> for Loose<BASE>

Source§

fn from(value: LooseBuilder<BASE>) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<Vec<u64>> for Loose<BASE>

Source§

fn from(value: Vec<Digit>) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<i128> for Loose<BASE>

Source§

fn from(value: i128) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<i16> for Loose<BASE>

Source§

fn from(value: i16) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<i32> for Loose<BASE>

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<i64> for Loose<BASE>

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<i8> for Loose<BASE>

Source§

fn from(value: i8) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<isize> for Loose<BASE>

Source§

fn from(value: isize) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<u128> for Loose<BASE>

Source§

fn from(value: u128) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<u16> for Loose<BASE>

Source§

fn from(value: u16) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<u32> for Loose<BASE>

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<u64> for Loose<BASE>

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<u8> for Loose<BASE>

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<usize> for Loose<BASE>

Source§

fn from(value: usize) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> FromIterator<u64> for Loose<BASE>

Source§

fn from_iter<T: IntoIterator<Item = Digit>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<const BASE: usize> FromStr for Loose<BASE>

Source§

type Err = BigIntError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl<const BASE: usize> GetBack for Loose<BASE>

Source§

type Item = u64

Source§

fn get_back(&self, index: usize) -> Option<Digit>

Safely retrieve items from a collection with negative indexing. Returns None if the index is larger than the length of the collection.
Source§

impl<const BASE: usize> IntoIterator for Loose<BASE>

Source§

type Item = u64

The type of the elements being iterated over.
Source§

type IntoIter = BigIntIntoIter<BASE, Loose<BASE>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<const BASE: usize> Mul for Loose<BASE>

Source§

type Output = Loose<BASE>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<const BASE: usize> MulAssign for Loose<BASE>

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl<const BASE: usize> Neg for Loose<BASE>

Source§

type Output = Loose<BASE>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<const BASE: usize> Ord for Loose<BASE>

Source§

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

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

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

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

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

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

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

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

impl<const BASE: usize> PartialEq for Loose<BASE>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const BASE: usize> PartialOrd for Loose<BASE>

Source§

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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<const BASE: usize> Shl for Loose<BASE>

Source§

type Output = Loose<BASE>

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

fn shl(self, rhs: Self) -> Self::Output

Performs the << operation. Read more
Source§

impl<const BASE: usize> ShlAssign for Loose<BASE>

Source§

fn shl_assign(&mut self, rhs: Self)

Performs the <<= operation. Read more
Source§

impl<const BASE: usize> Shr for Loose<BASE>

Source§

type Output = Loose<BASE>

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

fn shr(self, rhs: Self) -> Self::Output

Performs the >> operation. Read more
Source§

impl<const BASE: usize> ShrAssign for Loose<BASE>

Source§

fn shr_assign(&mut self, rhs: Self)

Performs the >>= operation. Read more
Source§

impl<const BASE: usize> Sub for Loose<BASE>

Source§

type Output = Loose<BASE>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<const BASE: usize> SubAssign for Loose<BASE>

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl<const BASE: usize> Eq for Loose<BASE>

Auto Trait Implementations§

§

impl<const BASE: usize> Freeze for Loose<BASE>

§

impl<const BASE: usize> RefUnwindSafe for Loose<BASE>

§

impl<const BASE: usize> Send for Loose<BASE>

§

impl<const BASE: usize> Sync for Loose<BASE>

§

impl<const BASE: usize> Unpin for Loose<BASE>

§

impl<const BASE: usize> UnwindSafe for Loose<BASE>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> ToOwned for T
where T: Clone,

Source§

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

Source§

fn to_string(&self) -> String

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

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

impl<T> UnsafeInto<T> for T

Source§

unsafe fn unsafe_into(self) -> T