Big Int
Simple library for arbitrary-precision, arbitrary-base arithmetic, supporting arbitrarily large integers of any base from 2 to u64::MAX
.
use *;
let mut a: = "9000000000000000000000000000000000000000".parse.unwrap;
a /= 13.into;
assert_eq!;
let mut b: = a.convert;
assert_eq!;
b >>= 16.into;
let c: = b.convert;
assert_eq!;
let mut d: = c.convert;
d += vec!.into;
assert_eq!;
let e: = d.convert;
assert_eq!;
This crate contains five primary big int implementations:
LooseBytes<BASE>
- A collection of loosely packed 8-bit byte values representing each digit. Slightly memory inefficient, but with minimal performance overhead. Capable of representing any base from 2-256.LooseShorts<BASE>
- A collection of loosely packed 16-bit short values representing each digit. Somewhat memory inefficient, but with minimal performance overhead. Capable of representing any base from 2-65536.LooseWords<BASE>
- A collection of loosely packed 32-bit word values representing each digit. Fairly memory inefficient, but with minimal performance overhead. Capable of representing any base from 2-2^32.Loose<BASE>
- A collection of loosely packed 64-bit ints representing each digit. Very memory inefficient, but with minimal performance overhead. Capable of representing any base from 2-2^64.Tight<BASE>
- A collection of tightly packed bits representing each digit. Maximally memory efficient, and capable of representing any base from 2-2^64. However, the additional indirection adds some performance overhead.
Ints support most basic arithmetic operations, including addition, subtraction, multiplication,
division, exponentiation, logarithm, nth root, and left/right shifting. Notably, shifting acts on the BASE
of the associated number, increasing or decreasing the magnitude by powers of BASE
as opposed to powers of 2.