#ratio #fraction #integer #approximation

int_ratio

The type of ratios represented by two integers

1 unstable release

0.1.0 Jul 17, 2024

#679 in Math

Download history 126/week @ 2024-08-18 185/week @ 2024-08-25 347/week @ 2024-09-01 480/week @ 2024-09-08 275/week @ 2024-09-15 350/week @ 2024-09-22 117/week @ 2024-09-29 594/week @ 2024-10-06 1128/week @ 2024-10-13 789/week @ 2024-10-20 380/week @ 2024-10-27 79/week @ 2024-11-03 274/week @ 2024-11-10 547/week @ 2024-11-17 338/week @ 2024-11-24 437/week @ 2024-12-01

1,615 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