Crates.io | int_ratio |
lib.rs | int_ratio |
version | 0.1.0 |
source | src |
created_at | 2024-07-17 06:50:39.401171 |
updated_at | 2024-07-17 06:50:39.401171 |
description | The type of ratios represented by two integers. |
homepage | https://github.com/arceos-org/arceos |
repository | https://github.com/arceos-org/int_ratio |
max_upload_size | |
id | 1305883 |
size | 8,853 |
The type of ratios and related operations.
A ratio is the result of dividing two integers, i.e., the numerator and denominator.
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)