#integer #round #divide

无需std rounded-div

获取整数除法的舍入结果

4个版本

0.1.2 2021年4月18日
0.1.1 2021年4月17日
0.1.0 2021年4月17日
0.0.0 2021年4月17日

#2376 in 算法

Download history 135/week @ 2024-03-30 104/week @ 2024-04-06 87/week @ 2024-04-13 115/week @ 2024-04-20 70/week @ 2024-04-27 47/week @ 2024-05-04 68/week @ 2024-05-11 41/week @ 2024-05-18 92/week @ 2024-05-25 83/week @ 2024-06-01 72/week @ 2024-06-08 67/week @ 2024-06-15 46/week @ 2024-06-22 49/week @ 2024-06-29 101/week @ 2024-07-06 53/week @ 2024-07-13

263 每月下载量
4 crates 中使用

MIT 许可证

6KB
53

rounded-div

Test Crates.io Version

获取整数除法的舍入结果。

用法示例

const fn rounded_div_*

assert_eq!(rounded_div::i32( 59, 4),  15); // 59/4 is equal to 14.75 which is closer to 15
assert_eq!(rounded_div::i32( 58, 4),  15); // 58/4 is equal to 14.5 which is rounded to 15
assert_eq!(rounded_div::i32( 57, 4),  14); // 57/4 is equal to 14.25 which is closer to 14
assert_eq!(rounded_div::i32(-59, 4), -15);
assert_eq!(rounded_div::i32(-58, 4), -15);
assert_eq!(rounded_div::i32(-57, 4), -14);

trait RoundedDiv

use rounded_div::RoundedDiv;
assert_eq!( 59i32.rounded_div(4),  15); // 59/4 is equal to 14.75 which is closer to 15
assert_eq!( 58i32.rounded_div(4),  15); // 58/4 is equal to 14.5 which is rounded to 15
assert_eq!( 57i32.rounded_div(4),  14); // 57/4 is equal to 14.25 which is closer to 14
assert_eq!(-59i32.rounded_div(4), -15);
assert_eq!(-58i32.rounded_div(4), -15);
assert_eq!(-57i32.rounded_div(4), -14);

许可证

MIT © Hoàng Văn Khải.

无运行时依赖