项目作者: KSXGitHub

项目描述 :
Get rounded result of an integer division
高级语言: Rust
项目地址: git://github.com/KSXGitHub/rounded-div.git
创建时间: 2021-04-17T01:37:55Z
项目社区:https://github.com/KSXGitHub/rounded-div

开源协议:MIT License

下载


rounded-div

Test
Crates.io Version

Get rounded result of an integer division.

Usage Examples

const fn rounded_div_*

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

trait RoundedDiv

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

License

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