#assert-eq #float #floating-point #f32 #f64

no-std dev assert-eq-float

This crate provides the assert_eq_float! macros that support floats

4 releases

0.1.4 Mar 19, 2024
0.1.3 Mar 31, 2023
0.1.2 Mar 31, 2023
0.1.1 Mar 30, 2023
0.1.0 Mar 30, 2023

#602 in Rust patterns

Download history 98/week @ 2024-06-22 52/week @ 2024-06-29 58/week @ 2024-07-06 111/week @ 2024-07-13 97/week @ 2024-07-20 318/week @ 2024-07-27 77/week @ 2024-08-03 67/week @ 2024-08-10 83/week @ 2024-08-17 173/week @ 2024-08-24 90/week @ 2024-08-31 55/week @ 2024-09-07 51/week @ 2024-09-14 59/week @ 2024-09-21 43/week @ 2024-09-28 61/week @ 2024-10-05

221 downloads per month
Used in 5 crates

MIT license

12KB
155 lines

assert-eq-float

CI

This crate provides the assert_eq_float! macros that support floats.

Examples

use assert_eq_float::*;

assert_eq_float!(1.1 + 0.1, 1.2);       // error = 0.0000000000000021316282072803005
assert_eq_float!(1e100 + 2e100, 3e100); // error = 53290705182007510000000000000000000000000000000000000000000000000000000000000000000000

// other macros
debug_assert_eq_float!(0.0, 0.0);
assert_ne_float!(0.0, 0.1);
debug_assert_ne_float!(0.0, 0.1);

The default margin of error is dynamically computed by properties of IEEE 754 floating point numbers. You don't need to worry about it if you just want to check two float values are equal.

Crates.io

https://crates.io/crates/assert-eq-float

Documentation

https://docs.rs/assert-eq-float

License

MIT


lib.rs:

assert-eq-float

This crate provides the assert_eq_float! macros that support floats.

Examples

use assert_eq_float::*;

assert_eq_float!(1.1 + 0.1, 1.2);       // error = 0.0000000000000021316282072803005
assert_eq_float!(1e100 + 2e100, 3e100); // error = 53290705182007510000000000000000000000000000000000000000000000000000000000000000000000

// other macros
debug_assert_eq_float!(0.0, 0.0);
assert_ne_float!(0.0, 0.1);
debug_assert_ne_float!(0.0, 0.1);

The default margin of error is dynamically computed by properties of IEEE 754 floating point numbers. You don't need to worry about it if you just want to check two float values are equal.

Dependencies

~150KB