[−][src]Macro float_eq::float_eq
Checks if two floating point expressions are equal to each other.
Comparisons are applied in order from left to right, shortcutting to return early if a positive result is found.
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.
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) ); 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]) );