[−][src]Macro float_eq::assert_float_eq
Asserts that two floating point expressions are equal to each other.
abs <= max_diffis an absolute epsilon comparison.rel <= max_diffis a relative epsilon comparison.ulps <= max_diffis an ULPs comparison.
When comparing composite types, variants that use a uniform max_diff
value across all fields are also available:
abs_all <= max_diffis an absolute epsilon comparison.rel_all <= max_diffis a relative epsilon comparison.ulps_all <= max_diffis 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.
Examples
let a: f32 = 4.; let b: f32 = 4.000_002_5; assert_float_eq!(a, 3.999_999_8, rel <= f32::EPSILON); assert_float_eq!(a - b, 0., abs <= 0.000_01, rel <= f32::EPSILON); assert_float_eq!(a - b, 0., abs <= 0.000_01, ulps <= 10); assert_float_eq!(a - b, 0., abs <= 0.000_01, ulps <= 10, "Checking that {} == {}", a, b); let c = [1.000_000_2f32, -2.0]; let d = [1.0f32, -2.000_002]; assert_float_eq!(c, d, abs_all <= 0.000_000_1, ulps <= [2, 8]);