#ratio #fraction #integer #approximation

int_ratio

The type of ratios represented by two integers

1 unstable release

0.1.0 Jul 17, 2024

#404 in Math

Download history 407/week @ 2024-07-23 567/week @ 2024-07-30 144/week @ 2024-08-06 215/week @ 2024-08-13 157/week @ 2024-08-20 184/week @ 2024-08-27 366/week @ 2024-09-03 444/week @ 2024-09-10 392/week @ 2024-09-17 274/week @ 2024-09-24 99/week @ 2024-10-01 714/week @ 2024-10-08 1227/week @ 2024-10-15 703/week @ 2024-10-22 201/week @ 2024-10-29 109/week @ 2024-11-05

2,364 downloads per month

GPL-3.0-or-later OR Apache-2…

7KB
110 lines

int_ratio

Crates.io Docs.rs CI

The type of ratios and related operations.

A ratio is the result of dividing two integers, i.e., the numerator and denominator.

Examples

use int_ratio::Ratio;

let ratio = Ratio::new(1, 3); // 1 / 3
assert_eq!(ratio.mul_trunc(20), 6); // trunc(20 * 1 / 3) = trunc(6.66..) = 6
assert_eq!(ratio.mul_round(20), 7); // round(20 * 1 / 3) = round(6.66..) = 7
println!("{:?}", ratio); // Ratio(1/3 ~= 1431655765/4294967296)

No runtime deps