Trait big_int::BigIntImplementation
source · pub trait BigIntImplementation<const BASE: usize>{
type Builder: BigIntBuilder<{ BASE }> + Build<Self>;
type DigitIterator<'a>: DoubleEndedIterator<Item = Digit>
where Self: 'a;
Show 18 methods
// Required methods
fn len(&self) -> usize;
fn get_digit(&self, digit: usize) -> Option<Digit>;
fn set_digit(&mut self, digit: usize, value: Digit);
fn zero() -> Self;
fn sign(&self) -> Sign;
fn with_sign(self, sign: Sign) -> Self;
fn set_sign(&mut self, sign: Sign);
fn push_back(&mut self, digit: Digit);
unsafe fn push_front(&mut self, digit: Digit);
fn iter<'a>(&'a self) -> Self::DigitIterator<'a>;
// Provided methods
fn shr(self, amount: usize) -> Self { ... }
fn shr_assign(&mut self, amount: usize) { ... }
fn shl(self, amount: usize) -> Self { ... }
fn shl_assign(&mut self, amount: usize) { ... }
fn normalized(self) -> Self { ... }
fn normalize(&mut self) { ... }
fn display(&self, alphabet: &str) -> Result<String, BigIntError> { ... }
fn parse(value: &str, alphabet: &str) -> Result<Self, ParseError> { ... }
}Required Associated Types§
type Builder: BigIntBuilder<{ BASE }> + Build<Self>
type DigitIterator<'a>: DoubleEndedIterator<Item = Digit> where Self: 'a
Required Methods§
sourcefn 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 / the digit is negative.
sourcefn set_digit(&mut self, digit: usize, value: Digit)
fn set_digit(&mut self, digit: usize, value: Digit)
Set the digit of the big int to value at position digit.
Return Some(Digit) of the digit’s existing value, or None if no digit was
set.
sourcefn 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
sourceunsafe 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. Will denormalize if the appended digit is a zero; make sure to call .normalize() afterwards to prevent undefined functionality.
fn iter<'a>(&'a self) -> Self::DigitIterator<'a>
Provided Methods§
sourcefn shr(self, amount: usize) -> Self
fn shr(self, amount: usize) -> Self
Divide the int by BASE^amount.
Note: works in powers of BASE, not in powers of 2.
Defined in terms of shr_assign; exactly one of shr or shr_assign must be defined.
sourcefn shr_assign(&mut self, amount: usize)
fn shr_assign(&mut self, amount: usize)
Divide the int by BASE^amount in place.
Note: works in powers of BASE, not in powers of 2.
Defined in terms of shr; exactly one of shr or shr_assign must be defined.
sourcefn shl(self, amount: usize) -> Self
fn shl(self, amount: usize) -> Self
Multiply the int by BASE^amount.
Note: works in powers of BASE, not in powers of 2.
Defined in terms of shl_assign; exactly one of shl or shl_assign must be defined.
sourcefn shl_assign(&mut self, amount: usize)
fn shl_assign(&mut self, amount: usize)
Multiply the int by BASE^amount in place.
Note: works in powers of BASE, not in powers of 2.
Defined in terms of shl; exactly one of shl or shl_assign must be defined.
sourcefn 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 = BigInt::from(unsafe { Loose::<10>::from_raw_parts(vec![0, 0, 8, 3]) });
assert_eq!(n.normalized(), 83.into());sourcefn normalize(&mut self)
fn normalize(&mut self)
Normalize a Loose big int in place. Remove trailing zeros, and disable the parity flag
if the resulting number is zero.
use big_int::prelude::*;
let mut n = BigInt::from(unsafe { Loose::<10>::from_raw_parts(vec![0, 0, 8, 3]) });
n.normalize();
assert_eq!(n, 83.into());sourcefn 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.
use big_int::prelude::*;
assert_eq!(
LooseInt::<10>::from(6012).display(STANDARD_ALPHABET).unwrap(),
"6012".to_string()
);sourcefn parse(value: &str, alphabet: &str) -> Result<Self, ParseError>
fn parse(value: &str, alphabet: &str) -> Result<Self, ParseError>
Parse a Loose 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.
use big_int::prelude::*;
assert_eq!(LooseInt::parse("125", STANDARD_ALPHABET), Ok(LooseInt::<10>::from(125)));