#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

#2096 in Algorithms

Download history 34/week @ 2023-11-30 29/week @ 2023-12-07 45/week @ 2023-12-14 23/week @ 2023-12-21 31/week @ 2023-12-28 57/week @ 2024-01-04 68/week @ 2024-01-11 50/week @ 2024-01-18 37/week @ 2024-01-25 34/week @ 2024-02-01 149/week @ 2024-02-08 88/week @ 2024-02-15 74/week @ 2024-02-22 85/week @ 2024-02-29 101/week @ 2024-03-07 136/week @ 2024-03-14

405 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