1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Arbitrary precision rational implementation, as a part of the `dashu` library for arbitrary-precision mathematics. See [Docs.rs](https://docs.rs/dashu-ratio/latest/dashu_ratio/) for the full documentation.
- -----
Exact rational arithmetic, recovering the human-intended fraction from a float, and
the `Relaxed` form that skips auto-reduction until you ask for it:
```rust
use dashu::rbig;
use dashu_ratio::{RBig, Relaxed};
// Compile-time rational literal
let exact = rbig!(22 / 7);
// Recover the human-intended rational from a float
let r = RBig::simplest_from_f32(22. / 7.).unwrap();
assert_eq!(r, exact);
// Relaxed: skip auto-reduction for speed, canonicalize at the end
let relaxed: Relaxed = rbig!(~108 / 72); // no auto-reduction yet
let reduced: RBig = relaxed.canonicalize();
assert_eq!(reduced.numerator(), &3u8.into()); // 108/72 = 3/2
// Exact arithmetic; Display prints numerator/denominator
let sum = rbig!(1 / 2) + rbig!(1 / 3);
assert_eq!(sum.to_string(), "5/6");
// parse rationals from strings too
let _parsed: RBig = "-22/7".parse().unwrap();
```
*
Relevant benchmark will be implemented in the [built-in benchmark](../benchmark/).
See the [top-level readme](../README.md).