puremp
Pure-Rust, MIT-licensed, arbitrary-precision arithmetic — integers, rationals, and MPFR-class floating point — with no foreign-code dependencies. Usable as a Rust crate, a C library, and a command-line calculator.
Status: early scaffold. The integer and rational layers are implemented and tested; the fast algorithms (sub-quadratic multiply/divide, subquadratic GCD) and the floating-point arithmetic layer are on the way. See
ROADMAP.mdfor the design and milestone plan.
Why
A GMP + MPFR-class toolkit that is:
- Pure, safe Rust — no C, no inline assembly, no intrinsics. The only
unsafein the crate is the opt-in C ABI module. - Clean-room & MIT-licensed — algorithms come from the open literature (Knuth; Brent & Zimmermann's Modern Computer Arithmetic; the HAC), never from GMP/MPFR source. Use it anywhere, including closed-source projects.
no_std+alloc— runs on bare metal with an allocator; no OS assumptions in the core. Verified on 32-bitthumbv7em-none-eabiin CI.
Quick start (Rust)
[]
= "0"
use ;
let big = from_i64.pow;
assert_eq!;
let sum = new? // 1/2
.add; // + 1/3
assert_eq!;
# Ok::
Quick start (CLI)
$ cargo run --bin puremp
puremp> 2 ** 100
1267650600228229401496703205376
puremp> x = 1000
puremp> x * x - 1
999999
puremp> (2**64) * (2**64)
340282366920938463463374607431768211456
puremp> :quit
Supports + - * / % **, parentheses, unary minus, decimal literals, and
name = expr variables (/ and % are truncated integer division).
Quick start (C)
Build the static and/or shared library and link against the header in
include/puremp.h:
$ cargo rustc --lib --release --features ffi --crate-type staticlib
$ cargo rustc --lib --release --features ffi --crate-type cdylib
$ cc myprog.c -I include target/release/libpuremp.a -lpthread -ldl -lm -o myprog
int
Feature flags
| Feature | Default | Enables |
|---|---|---|
std |
✔ | std::error::Error, the CLI, system I/O (implies alloc) |
alloc |
✔ | Heap-backed arbitrary-precision types (required by every layer) |
int |
✔ | Nat and Int |
rational |
✔ | Rational (implies int) |
float |
✔ | Float (implies int) |
ffi |
The C ABI module (include/puremp.h) |
|
cli |
✔ | The puremp binary |
For a bare no_std build: --no-default-features (add --features int for the
integer types).
License
MIT — see LICENSE.