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 |
#80 in Algorithms
124,018 downloads per month
Used in 171 crates
(5 directly)
18KB
300 lines
rust-muldiv
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));