#integer-arithmetic #arithmetic #integer #no-std #numeric

no-std muldiv

Provides a trait for numeric types to perform combined multiplication and division with overflow protection

6 releases (2 stable)

1.0.1 Oct 28, 2022
1.0.0 Oct 13, 2020
0.2.1 Dec 29, 2019
0.2.0 May 11, 2018
0.1.0 Feb 25, 2016

#121 in Algorithms

Download history 22760/week @ 2023-12-05 21241/week @ 2023-12-12 19237/week @ 2023-12-19 18022/week @ 2023-12-26 26435/week @ 2024-01-02 27802/week @ 2024-01-09 27447/week @ 2024-01-16 28158/week @ 2024-01-23 24543/week @ 2024-01-30 25712/week @ 2024-02-06 21134/week @ 2024-02-13 18524/week @ 2024-02-20 23776/week @ 2024-02-27 29449/week @ 2024-03-05 29915/week @ 2024-03-12 27718/week @ 2024-03-19

114,439 downloads per month
Used in 155 crates (4 directly)

MIT license

18KB
300 lines

rust-muldiv crates.io Actions Status docs.rs

Provides a trait for numeric types to perform combined multiplication and division with overflow protection.

LICENSE

rust-muldiv is licensed under the MIT license (LICENSE or http://opensource.org/licenses/MIT).

Contribution

Any kinds of contributions are welcome as a pull request.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in rust-muldiv by you shall be licensed under the MIT license as above, without any additional terms or conditions.


lib.rs:

Provides a trait for numeric types to perform combined multiplication and division with overflow protection.

The MulDiv trait provides functions for performing combined multiplication and division for numeric types and comes with implementations for all the primitive integer types. Three variants with different rounding characteristics are provided: mul_div_floor(), mul_div_round() and mul_div_ceil().

Example

extern crate muldiv;
use muldiv::MulDiv;
// Calculates 127 * 23 / 42 rounded down
let x = 127u8.mul_div_floor(23, 42);
assert_eq!(x, Some(69));

No runtime deps