A big integer library in Rust with good performance.
Rust
107
561 commits
updated Jul 24, 2026
A big integer library with good performance.
The library implements efficient large integer arithmetic in pure Rust.
The two integer types are UBig (for unsigned integers) and IBig (for signed integers).
Modular arithmetic is implemented by the Modulo type.
use ibig::{ibig, ubig, ModuloRing, UBig};
let a = ubig!(12345678);
let b = ubig!(0x10ff);
let c = ibig!(-azz base 36);
let d: UBig = "15033211231241234523452345345787".parse()?;
let e = 2 * &b + 1;
let f = a * b.pow(10);
assert_eq!(e, ubig!(0x21ff));
assert_eq!(c.to_string(), "-14255");
assert_eq!(
f.in_radix(16).to_string(),
"1589bda8effbfc495d8d73c83d8b27f94954e"
);
assert_eq!(
format!("hello {:#x}", d % ubig!(0xabcd1234134132451345)),
"hello 0x1a7e7c487267d2658a93"
);
let ring = ModuloRing::new(&ubig!(10000));
let x = ring.from(12345);
let y = ring.from(55443);
assert_eq!(format!("{}", x - y), "6902 (mod 10000)");
std (default): for std::error::Error.rand: random number generation.serde: serialization and deserialization.Benchmarks contains a quick benchmark of Rust big integer libraries.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Rust
100.0%
A big integer library in Rust with good performance.
Rust
107
561 commits
updated Jul 24, 2026
A big integer library with good performance.
The library implements efficient large integer arithmetic in pure Rust.
The two integer types are UBig (for unsigned integers) and IBig (for signed integers).
Modular arithmetic is implemented by the Modulo type.
use ibig::{ibig, ubig, ModuloRing, UBig};
let a = ubig!(12345678);
let b = ubig!(0x10ff);
let c = ibig!(-azz base 36);
let d: UBig = "15033211231241234523452345345787".parse()?;
let e = 2 * &b + 1;
let f = a * b.pow(10);
assert_eq!(e, ubig!(0x21ff));
assert_eq!(c.to_string(), "-14255");
assert_eq!(
f.in_radix(16).to_string(),
"1589bda8effbfc495d8d73c83d8b27f94954e"
);
assert_eq!(
format!("hello {:#x}", d % ubig!(0xabcd1234134132451345)),
"hello 0x1a7e7c487267d2658a93"
);
let ring = ModuloRing::new(&ubig!(10000));
let x = ring.from(12345);
let y = ring.from(55443);
assert_eq!(format!("{}", x - y), "6902 (mod 10000)");
std (default): for std::error::Error.rand: random number generation.serde: serialization and deserialization.Benchmarks contains a quick benchmark of Rust big integer libraries.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Rust
100.0%