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>
impl<const BASE: usize> Loose<BASE>
Sourcepub unsafe fn from_raw_parts(digits: Vec<Digit>) -> Self
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> AddAssign for Loose<BASE>
impl<const BASE: usize> AddAssign for Loose<BASE>
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+= operation. Read moreSource§impl<const BASE: usize> BigInt<BASE> for Loose<BASE>
impl<const BASE: usize> BigInt<BASE> for Loose<BASE>
Source§fn normalized(self) -> Self
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());type Builder = LooseBuilder<BASE>
type Denormal = Denormal<BASE, Loose<BASE>>
Source§fn get_digit(&self, digit: usize) -> Option<Digit>
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 moreSource§fn push_back(&mut self, digit: Digit)
fn push_back(&mut self, digit: Digit)
Append a digit to the right side of the int. Equivalent to
(int << 1) + digit Read moreSource§unsafe fn push_front(&mut self, digit: Digit)
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)
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)
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>
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>
unsafe fn pop_front(&mut self) -> Option<Digit>
Pop the leftmost digit from the end of the int, and return it. Read more
const BITS_PER_DIGIT: usize = _
Source§fn get_back_inner(&self, index: usize) -> Option<Digit>
fn get_back_inner(&self, index: usize) -> Option<Digit>
Default implementation of
big_int::GetBack. Read moreSource§fn default_inner() -> Self
fn default_inner() -> Self
Default implementation of
Default. Read moreSource§fn fmt_inner(&self, f: &mut Formatter<'_>) -> Result
fn fmt_inner(&self, f: &mut Formatter<'_>) -> Result
Default implementation of
Display. Read moreSource§fn partial_cmp_inner<RHS: BigInt<BASE>>(&self, other: &RHS) -> Option<Ordering>
fn partial_cmp_inner<RHS: BigInt<BASE>>(&self, other: &RHS) -> Option<Ordering>
Default implementation of
PartialOrd. Read moreSource§fn cmp_inner<RHS: BigInt<BASE>>(&self, other: &RHS) -> Ordering
fn cmp_inner<RHS: BigInt<BASE>>(&self, other: &RHS) -> Ordering
Default implementation of
Ord. Read moreSource§fn eq_inner<RHS: BigInt<BASE>>(&self, other: &RHS) -> bool
fn eq_inner<RHS: BigInt<BASE>>(&self, other: &RHS) -> bool
Default implementation of
PartialEq. Read moreSource§fn add_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>(
self,
rhs: RHS,
) -> OUT::Denormal
fn add_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> OUT::Denormal
Default implementation of
Add. Read moreSource§unsafe fn add_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)
unsafe fn add_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)
Default implementation of
AddAssign. Read moreSource§fn sub_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>(
self,
rhs: RHS,
) -> OUT::Denormal
fn sub_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> OUT::Denormal
Default implementation of
Sub. Read moreSource§unsafe fn sub_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)
unsafe fn sub_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)
Default implementation of
SubAssign. Read moreSource§fn mul_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>(
self,
rhs: RHS,
) -> OUT::Denormal
fn mul_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> OUT::Denormal
Default implementation of
Mul. Read moreSource§unsafe fn mul_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)
unsafe fn mul_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)
Default implementation of
MulAssign. Read moreSource§fn div_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>(
self,
rhs: RHS,
) -> OUT::Denormal
fn div_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> OUT::Denormal
Default implementation of
Div. Read moreSource§unsafe fn div_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)
unsafe fn div_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)
Default implementation of
DivAssign. Read moreSource§fn from_str_inner(s: &str) -> Result<Self::Denormal, BigIntError>
fn from_str_inner(s: &str) -> Result<Self::Denormal, BigIntError>
Default implementation of
FromStr. Read moreSource§fn from_iter_inner<T: IntoIterator<Item = Digit>>(iter: T) -> Self::Denormal
fn from_iter_inner<T: IntoIterator<Item = Digit>>(iter: T) -> Self::Denormal
Default implementation of
FromIterator. Read moreSource§fn from_u128_inner(value: u128) -> Self::Denormal
fn from_u128_inner(value: u128) -> Self::Denormal
Default implementation of
From<_> for all unsigned primitive int types. Read moreSource§fn from_i128_inner(value: i128) -> Self::Denormal
fn from_i128_inner(value: i128) -> Self::Denormal
Default implementation of
From<_> for all signed primitive int types. Read moreSource§fn into_u128_inner(self) -> u128
fn into_u128_inner(self) -> u128
Default implementation of
Into<_> for all unsigned primitive int types. Read moreSource§fn into_i128_inner(self) -> i128
fn into_i128_inner(self) -> i128
Default implementation of
Into<_> for all signed primitive int types. Read moreSource§fn shl_inner(self, amount: usize) -> Self::Denormal
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>
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>
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>
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 moreSource§fn exp<RHS: BigInt<BASE>, OUT: BigInt<BASE>>(
self,
rhs: RHS,
) -> Result<OUT, BigIntError>
fn exp<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT, BigIntError>
Exponentiate the big int by
rhs. Read moreSource§fn log_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>(
self,
rhs: RHS,
) -> Result<OUT::Denormal, BigIntError>
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 moreSource§fn log<RHS: BigInt<BASE>, OUT: BigInt<BASE>>(
self,
rhs: RHS,
) -> Result<OUT, BigIntError>
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 moreSource§fn root_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>(
self,
rhs: RHS,
) -> Result<OUT::Denormal, BigIntError>
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 moreSource§fn root<RHS: BigInt<BASE>, OUT: BigInt<BASE>>(
self,
rhs: RHS,
) -> Result<OUT, BigIntError>
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 moreSource§fn iter<'a>(&'a self) -> BigIntIter<'a, BASE, Self> ⓘ
fn iter<'a>(&'a self) -> BigIntIter<'a, BASE, Self> ⓘ
Iterate over the digits of the int. Read more
Source§fn display(&self, alphabet: &str) -> Result<String, BigIntError>
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 moreSource§fn parse(value: &str, alphabet: &str) -> Result<Self::Denormal, ParseError>
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 moreSource§fn convert_inner<const TO: usize, OUT: BigInt<TO>>(self) -> OUT::Denormal
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 moreSource§fn convert<const TO: usize, OUT: BigInt<TO>>(self) -> OUT
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 moreSource§impl<const BASE: usize> DivAssign for Loose<BASE>
impl<const BASE: usize> DivAssign for Loose<BASE>
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
Performs the
/= operation. Read moreSource§impl<const BASE: usize> From<LooseBuilder<BASE>> for Loose<BASE>
impl<const BASE: usize> From<LooseBuilder<BASE>> for Loose<BASE>
Source§fn from(value: LooseBuilder<BASE>) -> Self
fn from(value: LooseBuilder<BASE>) -> Self
Converts to this type from the input type.
Source§impl<const BASE: usize> IntoIterator for Loose<BASE>
impl<const BASE: usize> IntoIterator for Loose<BASE>
Source§impl<const BASE: usize> MulAssign for Loose<BASE>
impl<const BASE: usize> MulAssign for Loose<BASE>
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
Performs the
*= operation. Read moreSource§impl<const BASE: usize> Ord for Loose<BASE>
impl<const BASE: usize> Ord for Loose<BASE>
Source§impl<const BASE: usize> PartialOrd for Loose<BASE>
impl<const BASE: usize> PartialOrd for Loose<BASE>
Source§impl<const BASE: usize> ShlAssign for Loose<BASE>
impl<const BASE: usize> ShlAssign for Loose<BASE>
Source§fn shl_assign(&mut self, rhs: Self)
fn shl_assign(&mut self, rhs: Self)
Performs the
<<= operation. Read moreSource§impl<const BASE: usize> ShrAssign for Loose<BASE>
impl<const BASE: usize> ShrAssign for Loose<BASE>
Source§fn shr_assign(&mut self, rhs: Self)
fn shr_assign(&mut self, rhs: Self)
Performs the
>>= operation. Read moreSource§impl<const BASE: usize> SubAssign for Loose<BASE>
impl<const BASE: usize> SubAssign for Loose<BASE>
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the
-= operation. Read moreimpl<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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more