predicates::float

Function is_close

Source
pub fn is_close(target: f64) -> IsClosePredicate
Expand description

Create a new Predicate that ensures two numbers are “close” enough, understanding that rounding errors occur.

§Examples

use predicates::prelude::*;

let a = 0.15_f64 + 0.15_f64 + 0.15_f64;
let b = 0.1_f64 + 0.1_f64 + 0.25_f64;
let predicate_fn = predicate::float::is_close(a);
assert_eq!(true, predicate_fn.eval(&b));
assert_eq!(false, predicate_fn.distance(0).eval(&b));