Function xpct::approx_eq_f32
source · pub fn approx_eq_f32<'a>(expected: f32, ulps: i32) -> Matcher<'a, f32, f32>
Available on crate feature
float
only.Expand description
Succeeds when the actual f32
value approximately equals the expected f32
value.
To test two floating-point numbers for equality, you must specify the margin of acceptable error as a number of ULPs, which stands for Units of Least Precisions or Units in the Last Place.
Examples
use xpct::{expect, approx_eq_f32};
let actual: f32 = 0.15 + 0.15 + 0.15;
let expected: f32 = 0.1 + 0.1 + 0.25;
expect!(actual).to(approx_eq_f32(expected, 2));