8 releases
0.1.8 | Nov 1, 2020 |
---|---|
0.1.7 | Oct 28, 2020 |
#14 in #approximate
4,029 downloads per month
Used in 90 crates
(17 directly)
6KB
82 lines
approx_eq
This crate provides a macro to check whether two numbers are approximately equal. It does so by checking that the relative difference between the two numbers is less than some upper limit.
To use this in your Rust program, add the following to your Cargo.toml
file:
// Cargo.toml
[dependencies]
approx_eq = "0.1"
Using this macro is easy!
// main.rs
use approx_eq::assert_approx_eq;
fn main() {
assert_approx_eq!(1., 0.99999999999); // should pass
assert_approx_eq!(1., 0.99999999999, 1e-5); // should pass
assert_approx_eq!(1., 0.99999999999, 1e-20); // should fail
assert_approx_eq!(1., 2.) // should fail
}