Expand description
A big integer library with good performance.
The library implements efficient large integer arithmetic in pure Rust.
The two main integer types are UBig (for unsigned integers) and IBig (for signed integers).
Modular arithmetic is supported by the module modular.
To construct big integers from literals, please use the dashu-macro
crate for your convenience..
Examples
use dashu_int::{IBig, modular::ModuloRing, UBig};
let a = UBig::from(12345678u32);
let b = UBig::from(0x10ffu16);
let c = IBig::from_str_radix("-azz", 36).unwrap();
let d: UBig = "15033211231241234523452345345787".parse()?;
let e = 2u8 * &b + 1u8;
let f = a * b.pow(10);
assert_eq!(e, 0x21ff); // direct comparison with primitive integers
assert_eq!(c.to_string(), "-14255");
assert_eq!(
f.in_radix(16).to_string(),
"1589bda8effbfc495d8d73c83d8b27f94954e"
);
assert_eq!(
format!("hello {:#x}", d % 0xabcd_1234_1341_3245_1345u128),
"hello 0x1a7e7c487267d2658a93"
);
let ring = ModuloRing::new(UBig::from(10000u32));
let x = ring.convert(12345);
let y = ring.convert(55443);
assert_eq!(format!("{}", x - y), "6902 (mod 10000)");
Optional dependencies
std
(default): forstd::error::Error
and some internal usages ofstd
functions.num-traits
(default): support integral traits from cratenum-traits
.rand
(default): support random number generation based on craterand
.serde
: support serialization and deserialization based on crateserde
.
Modules
Error types.
Prepared divisor types for fast division
Integer formatting.
Modular arithmetic.
Re-exported operator traits from dashu-base
Random distributions.
Structs
Enums
An enum representing the sign of a number
Type Definitions
The primitive integer type that has exactly double the size of Word.
The primitive integer type used to construct the big integers, guaranteed to be a rust built-in unsigned integer type.