Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ksxgithub/rounded-div
Get rounded result of an integer division
https://github.com/ksxgithub/rounded-div
binary crates division integer library round rust
Last synced: 2 months ago
JSON representation
Get rounded result of an integer division
- Host: GitHub
- URL: https://github.com/ksxgithub/rounded-div
- Owner: KSXGitHub
- License: mit
- Created: 2021-04-17T01:37:55.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-03-13T10:57:06.000Z (almost 2 years ago)
- Last Synced: 2024-10-26T11:21:26.560Z (2 months ago)
- Topics: binary, crates, division, integer, library, round, rust
- Language: Rust
- Homepage: https://crates.io/crates/rounded-div
- Size: 42 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# rounded-div
[![Test](https://github.com/KSXGitHub/rounded-div/workflows/Test/badge.svg)](https://github.com/KSXGitHub/rounded-div/actions?query=workflow%3ATest)
[![Crates.io Version](https://img.shields.io/crates/v/rounded-div?logo=rust)](https://crates.io/crates/rounded-div)Get rounded result of an integer division.
## Usage Examples
### `const fn rounded_div_*`
```rust
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`
```rust
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](https://git.io/JO4Rf) © [Hoàng Văn Khải](https://ksxgithub.github.io/).