#integer #round #divide #division

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

#973 in Algorithms

Download history 112/week @ 2025-01-06 173/week @ 2025-01-13 4144/week @ 2025-01-20 79/week @ 2025-01-27 77/week @ 2025-02-03 124/week @ 2025-02-10 215/week @ 2025-02-17 244/week @ 2025-02-24 85/week @ 2025-03-03 130/week @ 2025-03-10 518/week @ 2025-03-17 642/week @ 2025-03-24 127/week @ 2025-03-31 59/week @ 2025-04-07 58/week @ 2025-04-14 48/week @ 2025-04-21

331 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