Crates.io | assert_approx_eq |
lib.rs | assert_approx_eq |
version | 1.1.0 |
source | src |
created_at | 2016-06-16 18:53:50.923982 |
updated_at | 2018-12-19 22:58:07.08891 |
description | assert approximately equal |
homepage | |
repository | https://github.com/ashleygwilliams/assert_approx_eq.git |
max_upload_size | |
id | 5396 |
size | 19,933 |
a rust macro for asserting 2 numbers are approximately equal
This crate exports a macro for asserting that two numbers are approximately equal (1.0e-6
, by default) to each other.
On panic, this macro will print the values of the expressions with their
debug representations. You can optionally add an optional diff value. If you
don't supply a diff value as an argument, 1.0e-6
is the default used.
To use this crate, add assert_approx_eq
as a dependency of your Rust project.
Then, you can use the macro as follows:
use assert_approx_eq::assert_approx_eq;
let a = 3f64;
let b = 4f64;
assert_approx_eq!(a, b); // panics
assert_approx_eq!(a, b, 2f64); //does not panic
assert_approx_eq!(a, b, 1e-3f64); // panics
You can read documentation for how to use this crate on docs.rs or view the example.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.