6 releases (2 stable)

1.1.0 Dec 19, 2018
1.0.0 Mar 27, 2017
0.2.2 Jun 16, 2016
0.1.0 Jun 16, 2016

#2 in #asserting

Download history 33817/week @ 2023-11-07 37680/week @ 2023-11-14 28546/week @ 2023-11-21 27497/week @ 2023-11-28 29366/week @ 2023-12-05 26947/week @ 2023-12-12 20329/week @ 2023-12-19 10016/week @ 2023-12-26 25822/week @ 2024-01-02 26862/week @ 2024-01-09 28959/week @ 2024-01-16 27988/week @ 2024-01-23 32170/week @ 2024-01-30 26958/week @ 2024-02-06 31084/week @ 2024-02-13 29480/week @ 2024-02-20

125,124 downloads per month
Used in 227 crates (208 directly)

MIT/Apache

8KB
56 lines

assert_approx_eq

a rust macro for asserting 2 numbers are approximately equal

crates.io badge travis badge appveyor badge

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.

Usage

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.

License

Licensed under either of

at your option.

Contribution

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.

No runtime deps