#integer #round #divide

no-std rounded-div

Get rounded result of an integer division

5 releases

0.1.3 Feb 21, 2025
0.1.2 Apr 18, 2021
0.1.1 Apr 17, 2021
0.1.0 Apr 17, 2021
0.0.0 Apr 17, 2021

#932 in Algorithms

Download history 105/week @ 2024-11-20 125/week @ 2024-11-27 61/week @ 2024-12-04 60/week @ 2024-12-11 51/week @ 2024-12-18 24/week @ 2024-12-25 90/week @ 2025-01-01 114/week @ 2025-01-08 291/week @ 2025-01-15 3980/week @ 2025-01-22 91/week @ 2025-01-29 98/week @ 2025-02-05 103/week @ 2025-02-12 315/week @ 2025-02-19 164/week @ 2025-02-26 44/week @ 2025-03-05

660 downloads per month
Used in 4 crates

MIT license

7KB
55 lines

rounded-div

Test Crates.io Version

Get rounded result of an integer division.

Usage Examples

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);

License

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

No runtime deps