pub struct BigInt<const BASE: usize, B: BigIntImplementation<{ BASE }>>(/* private fields */);Expand description
A big int.
Must be constructed with a specific implementation
Implementations§
source§impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> BigInt<BASE, B>
impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> BigInt<BASE, B>
pub fn zero() -> Self
pub fn with_sign(self, sign: Sign) -> Self
pub fn shl(self, amount: usize) -> Self
pub fn shl_assign(&mut self, amount: usize)
pub fn shr(self, amount: usize) -> Self
pub fn shr_assign(&mut self, amount: usize)
pub fn normalized(self) -> Self
pub fn parse(value: &str, alphabet: &str) -> Result<Self, ParseError>
sourcepub fn div_rem(self, other: Self) -> Result<(Self, Self), BigIntError>
pub fn div_rem(self, other: Self) -> Result<(Self, Self), BigIntError>
Divide one int by another, returning the quotient & remainder as a pair,
or an error if dividing by zero. This algorithm has a different time complexity
than BigInt::div_rem_lowmem which makes it faster for most use cases, but also uses more memory.
b - base
d - number of digits in quotient
Time complexity: O(d * log(b))
Memory complexity: O(d * log(b))
use big_int::prelude::*;
let a: LooseInt<10> = 999_999_999.into();
let b = 56_789.into();
assert_eq!(a.div_rem(b), Ok((17_609.into(), 2_498.into())));sourcepub fn convert<const TO: usize, T: BigIntImplementation<{ TO }>>(
self
) -> BigInt<TO, T>
pub fn convert<const TO: usize, T: BigIntImplementation<{ TO }>>( self ) -> BigInt<TO, T>
Convert an int from its own base to another target base.
use big_int::prelude::*;
assert_eq!(
LooseInt::<10>::from(99825).convert(),
LooseInt::<16>::from(99825)
);sourcepub fn cmp_magnitude(&self, rhs: &Self) -> Ordering
pub fn cmp_magnitude(&self, rhs: &Self) -> Ordering
Compare the absolute magnitude of two big ints, ignoring their sign.
use big_int::prelude::*;
let a: TightInt<10> = (-105).into();
let b = 15.into();
assert!(a.cmp_magnitude(&b).is_gt());Trait Implementations§
source§impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> AddAssign for BigInt<BASE, B>
impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> AddAssign for BigInt<BASE, B>
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+= operation. Read moresource§impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> DivAssign for BigInt<BASE, B>
impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> DivAssign for BigInt<BASE, B>
source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
Performs the
/= operation. Read moresource§impl<const BASE: usize, const N: usize, B: BigIntImplementation<{ BASE }>> From<[u64; N]> for BigInt<BASE, B>
impl<const BASE: usize, const N: usize, B: BigIntImplementation<{ BASE }>> From<[u64; N]> for BigInt<BASE, B>
source§impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<Vec<u64>> for BigInt<BASE, B>
impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<Vec<u64>> for BigInt<BASE, B>
source§impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> FromIterator<u64> for BigInt<BASE, B>
impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> FromIterator<u64> for BigInt<BASE, B>
source§impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> MulAssign for BigInt<BASE, B>
impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> MulAssign for BigInt<BASE, B>
source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
Performs the
*= operation. Read moresource§impl<const BASE: usize, B> Ord for BigInt<BASE, B>where
B: BigIntImplementation<{ BASE }>,
impl<const BASE: usize, B> Ord for BigInt<BASE, B>where
B: BigIntImplementation<{ BASE }>,
source§impl<const BASE: usize, B: PartialEq + BigIntImplementation<{ BASE }>> PartialEq for BigInt<BASE, B>
impl<const BASE: usize, B: PartialEq + BigIntImplementation<{ BASE }>> PartialEq for BigInt<BASE, B>
source§impl<const BASE: usize, B> PartialOrd for BigInt<BASE, B>where
B: BigIntImplementation<{ BASE }>,
impl<const BASE: usize, B> PartialOrd for BigInt<BASE, B>where
B: BigIntImplementation<{ BASE }>,
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read moresource§impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> ShlAssign for BigInt<BASE, B>
impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> ShlAssign for BigInt<BASE, B>
source§fn shl_assign(&mut self, rhs: Self)
fn shl_assign(&mut self, rhs: Self)
Shifts a big int left by multiples of its BASE (not by 2).
source§impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> ShrAssign for BigInt<BASE, B>
impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> ShrAssign for BigInt<BASE, B>
source§fn shr_assign(&mut self, rhs: Self)
fn shr_assign(&mut self, rhs: Self)
Shifts a big int right by multiples of its BASE (not by 2).
source§impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> SubAssign for BigInt<BASE, B>
impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> SubAssign for BigInt<BASE, B>
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the
-= operation. Read moreimpl<const BASE: usize, B: Eq + BigIntImplementation<{ BASE }>> Eq for BigInt<BASE, B>
impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> StructuralEq for BigInt<BASE, B>
impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> StructuralPartialEq for BigInt<BASE, B>
Auto Trait Implementations§
impl<const BASE: usize, B> RefUnwindSafe for BigInt<BASE, B>where
B: RefUnwindSafe,
impl<const BASE: usize, B> Send for BigInt<BASE, B>where
B: Send,
impl<const BASE: usize, B> Sync for BigInt<BASE, B>where
B: Sync,
impl<const BASE: usize, B> Unpin for BigInt<BASE, B>where
B: Unpin,
impl<const BASE: usize, B> UnwindSafe for BigInt<BASE, B>where
B: UnwindSafe,
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