[−][src]Macro float_eq::debug_assert_float_eq
Asserts that two floating point expressions are equal to each other.
abs <= max_diff
is an absolute epsilon comparison.rel <= max_diff
is a relative epsilon comparison.ulps <= max_diff
is an ULPs comparison.
When comparing composite types, variants that use a uniform max_diff
value across all fields are also available:
abs_all <= max_diff
is an absolute epsilon comparison.rel_all <= max_diff
is a relative epsilon comparison.ulps_all <= max_diff
is an ULPs comparison.
On panic, this macro will print the values of the expressions with their debug
representations, with additional information from the comparison operations
(using FloatEqDebug
, FloatEqAllDebug
and FloatDiff
).
Like assert!
, this macro has a second form, where a custom panic message can
be provided.
Unlike assert_float_eq!
, debug_assert_float_eq!
statements are only enabled in
non optimized builds by default. See debug_assert_eq!
for more details.
Examples
let a: f32 = 4.; let b: f32 = 4.0000025; debug_assert_float_eq!(a, 3.9999998, rel <= f32::EPSILON); debug_assert_float_eq!(a - b, 0., abs <= 0.00001, rel <= f32::EPSILON); debug_assert_float_eq!(a - b, 0., abs <= 0.00001, ulps <= 10); debug_assert_float_eq!(a - b, 0., abs <= 0.00001, ulps <= 10, "Checking that {} == {}", a, b);