dashu-ratio
Arbitrary precision rational implementation, as a part of the dashu library for arbitrary-precision mathematics. See Docs.rs for the full documentation.
Features
- Supports
no_stdand written in pure Rust. - Support a relaxed verion of rational numbers for fast computation.
- Support for Diophantine Approximation of floating point numbers.
- Rational numbers with small numerators and denominators are inlined on stack.
- Efficient integer parsing and printing with base 2~36.
- Developer friendly debug printing for float numbers.
Quick example
Exact rational arithmetic, recovering the human-intended fraction from a float, and
the Relaxed form that skips auto-reduction until you ask for it:
use rbig;
use ;
// Compile-time rational literal
let exact = rbig!;
// Recover the human-intended rational from a float
let r = simplest_from_f32.unwrap;
assert_eq!;
// Relaxed: skip auto-reduction for speed, canonicalize at the end
let relaxed: Relaxed = rbig!; // no auto-reduction yet
let reduced: RBig = relaxed.canonicalize;
assert_eq!; // 108/72 = 3/2
// Exact arithmetic; Display prints numerator/denominator
let sum = rbig! + rbig!;
assert_eq!;
// parse rationals from strings too
let _parsed: RBig = "-22/7".parse.unwrap;
Optional dependencies
std(default): enablestdsupport for dependencies.
Performance
Relevant benchmark will be implemented in the built-in benchmark.
License
See the top-level readme.