Struct big_int::BigInt

source ·
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>

source

pub fn zero() -> Self

source

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

source

pub fn shl(self, amount: usize) -> Self

source

pub fn shl_assign(&mut self, amount: usize)

source

pub fn shr(self, amount: usize) -> Self

source

pub fn shr_assign(&mut self, amount: usize)

source

pub fn normalized(self) -> Self

source

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

source

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())));
source

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)
);
source

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 }>> Add for BigInt<BASE, B>

§

type Output = BigInt<BASE, B>

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, B: BigIntImplementation<{ BASE }>> AddAssign for BigInt<BASE, B>

source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
source§

impl<const BASE: usize, B: Clone + BigIntImplementation<{ BASE }>> Clone for BigInt<BASE, B>

source§

fn clone(&self) -> BigInt<BASE, B>

Returns a copy 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, B: Debug + BigIntImplementation<{ BASE }>> Debug for BigInt<BASE, B>

source§

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

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

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> Default for BigInt<BASE, B>

source§

fn default() -> Self

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

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> Deref for BigInt<BASE, B>

§

type Target = B

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> DerefMut for BigInt<BASE, B>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> Display for BigInt<BASE, B>

source§

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

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

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> Div for BigInt<BASE, B>

§

type Output = BigInt<BASE, B>

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, B: BigIntImplementation<{ BASE }>> DivAssign for BigInt<BASE, B>

source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<&[u64]> for BigInt<BASE, B>

source§

fn from(value: &[Digit]) -> Self

Converts to this type from the input type.
source§

impl<B: BigIntImplementation<256>> From<&[u8]> for BigInt<256, B>

source§

fn from(value: &[u8]) -> Self

Converts to this type from the input type.
source§

impl<const N: usize, B: BigIntImplementation<256>> From<&[u8; N]> for BigInt<256, B>

source§

fn from(value: &[u8; N]) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, const N: usize, B: BigIntImplementation<{ BASE }>> From<[u64; N]> for BigInt<BASE, B>

source§

fn from(value: [Digit; N]) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<B> for BigInt<BASE, B>

source§

fn from(value: B) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<BigInt<BASE, B>> for i128

source§

fn from(value: BigInt<BASE, B>) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<BigInt<BASE, B>> for i16

source§

fn from(value: BigInt<BASE, B>) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<BigInt<BASE, B>> for i32

source§

fn from(value: BigInt<BASE, B>) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<BigInt<BASE, B>> for i64

source§

fn from(value: BigInt<BASE, B>) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<BigInt<BASE, B>> for i8

source§

fn from(value: BigInt<BASE, B>) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<BigInt<BASE, B>> for isize

source§

fn from(value: BigInt<BASE, B>) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<BigInt<BASE, B>> for u128

source§

fn from(value: BigInt<BASE, B>) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<BigInt<BASE, B>> for u16

source§

fn from(value: BigInt<BASE, B>) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<BigInt<BASE, B>> for u32

source§

fn from(value: BigInt<BASE, B>) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<BigInt<BASE, B>> for u64

source§

fn from(value: BigInt<BASE, B>) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<BigInt<BASE, B>> for u8

source§

fn from(value: BigInt<BASE, B>) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<BigInt<BASE, B>> for usize

source§

fn from(value: BigInt<BASE, B>) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<Vec<u64>> for BigInt<BASE, B>

source§

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

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<i128> for BigInt<BASE, B>

source§

fn from(value: i128) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<i16> for BigInt<BASE, B>

source§

fn from(value: i16) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<i32> for BigInt<BASE, B>

source§

fn from(value: i32) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<i64> for BigInt<BASE, B>

source§

fn from(value: i64) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<i8> for BigInt<BASE, B>

source§

fn from(value: i8) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<isize> for BigInt<BASE, B>

source§

fn from(value: isize) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<u128> for BigInt<BASE, B>

source§

fn from(value: u128) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<u16> for BigInt<BASE, B>

source§

fn from(value: u16) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<u32> for BigInt<BASE, B>

source§

fn from(value: u32) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<u64> for BigInt<BASE, B>

source§

fn from(value: u64) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<u8> for BigInt<BASE, B>

source§

fn from(value: u8) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> From<usize> for BigInt<BASE, B>

source§

fn from(value: usize) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> FromIterator<u64> for BigInt<BASE, B>

source§

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

Creates a value from an iterator. Read more
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> FromStr for BigInt<BASE, B>

§

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, B: BigIntImplementation<{ BASE }>> Mul for BigInt<BASE, B>

§

type Output = BigInt<BASE, B>

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, B: BigIntImplementation<{ BASE }>> MulAssign for BigInt<BASE, B>

source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> Neg for BigInt<BASE, B>

§

type Output = BigInt<BASE, B>

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl<const BASE: usize, B> Ord for BigInt<BASE, B>
where B: BigIntImplementation<{ 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 + PartialOrd,

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

impl<const BASE: usize, B: PartialEq + BigIntImplementation<{ BASE }>> PartialEq for BigInt<BASE, B>

source§

fn eq(&self, other: &BigInt<BASE, B>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<const BASE: usize, B> PartialOrd for BigInt<BASE, B>
where B: BigIntImplementation<{ 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> Shl for BigInt<BASE, B>

source§

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

Shifts a Loose big int left by multiples of its BASE (not by 2).

§

type Output = BigInt<BASE, B>

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

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> ShlAssign for BigInt<BASE, B>

source§

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 }>> Shr for BigInt<BASE, B>

source§

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

Shifts a big int right by multiples of its BASE (not by 2).

§

type Output = BigInt<BASE, B>

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

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> ShrAssign for BigInt<BASE, B>

source§

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 }>> Sub for BigInt<BASE, B>

§

type Output = BigInt<BASE, B>

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, B: BigIntImplementation<{ BASE }>> SubAssign for BigInt<BASE, B>

source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
source§

impl<const BASE: usize, B: Eq + BigIntImplementation<{ BASE }>> Eq for BigInt<BASE, B>

source§

impl<const BASE: usize, B: BigIntImplementation<{ BASE }>> StructuralEq for BigInt<BASE, B>

source§

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> 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> 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,

§

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§

default 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>,

§

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>,

§

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.