#integer #round #divide

no-std rounded-div

Get rounded result of an integer division

4 releases

0.1.2 Apr 18, 2021
0.1.1 Apr 17, 2021
0.1.0 Apr 17, 2021
0.0.0 Apr 17, 2021

#2088 in Algorithms

Download history 50/week @ 2024-01-03 74/week @ 2024-01-10 46/week @ 2024-01-17 42/week @ 2024-01-24 31/week @ 2024-01-31 147/week @ 2024-02-07 89/week @ 2024-02-14 71/week @ 2024-02-21 82/week @ 2024-02-28 97/week @ 2024-03-06 132/week @ 2024-03-13 186/week @ 2024-03-20 111/week @ 2024-03-27 115/week @ 2024-04-03 100/week @ 2024-04-10 71/week @ 2024-04-17

438 downloads per month
Used in 4 crates

MIT license

6KB
53 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