Crate dashu_int

source ·
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. Some utilities for fast division is provided in the module fast_div.

To construct big integers from literals, please use the dashu-macro crate for your convenience.


use dashu_int::{IBig, fast_div::ConstDivisor, UBig};

let a = UBig::from(12345678u32);
let b = IBig::from(-0x10ff);
let c = IBig::from_str_radix("-azz", 36).unwrap();
let d: UBig = "15033211231241234523452345345787".parse()?;
let e = 2 * &b - 1;
let f = a * b.pow(10);

assert_eq!(e, IBig::from(-0x21ff));
assert_eq!(c.to_string(), "-14255");
    format!("hello {:#x}", d % 0xabcd_1234_1341_3245_1345u128),
    "hello 0x1a7e7c487267d2658a93"

let ring = ConstDivisor::new(UBig::from(10000u32));
let x = ring.reduce(12345);
let y = ring.reduce(55443);
assert_eq!(format!("{}", x - y), "6902 (mod 10000)");

Optional dependencies

  • std (default): for std::error::Error and some internal usages of std functions.
  • num-traits (default): support traits from crate num-traits.
  • num-integer (default): support traits from crate num-integer.
  • num-order (default): support traits from crate num-order.
  • rand (default): support random number generation based on crate rand.
  • serde: support serialization and deserialization based on crate serde.
  • zeroize: support traits from crate zeroize


  • Prepared divisor types for fast division
  • Integer formatting.
  • Modular arithmetic.
  • Re-exported relevant operator traits from dashu-base
  • Random integers generation with the rand crate.


  • An signed arbitrary precision integer.
  • An unsigned arbitrary precision integer.


  • An enum representing the sign of a number

Type Aliases

  • 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.