Struct predicates::float::IsClosePredicate
source ·
[−]pub struct IsClosePredicate { /* fields omitted */ }
Expand description
Predicate that ensures two numbers are “close” enough, understanding that rounding errors occur.
This is created by the predicate::float::is_close
.
Implementations
Set the amount of error allowed.
Values 1
-5
should work in most cases. Sometimes more control is needed and you will
need to set IsClosePredicate::epsilon
separately from IsClosePredicate::ulps
.
Examples
use predicates::prelude::*;
let a = 0.15_f64 + 0.15_f64 + 0.15_f64;
let predicate_fn = predicate::float::is_close(a).distance(5);
Set the absolute deviation allowed.
This is meant to handle problems near 0
. Values 1.
-5.
epislons should work in most
cases.
Examples
use predicates::prelude::*;
let a = 0.15_f64 + 0.15_f64 + 0.15_f64;
let predicate_fn = predicate::float::is_close(a).epsilon(5.0 * ::std::f64::EPSILON);
Set the relative deviation allowed.
This is meant to handle large numbers. Values 1
-5
should work in most cases.
Examples
use predicates::prelude::*;
let a = 0.15_f64 + 0.15_f64 + 0.15_f64;
let predicate_fn = predicate::float::is_close(a).ulps(5);
Trait Implementations
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
Auto Trait Implementations
impl RefUnwindSafe for IsClosePredicate
impl Send for IsClosePredicate
impl Sync for IsClosePredicate
impl Unpin for IsClosePredicate
impl UnwindSafe for IsClosePredicate
Blanket Implementations
Mutably borrows from an owned value. Read more
fn and<B>(self, other: B) -> AndPredicate<Self, B, Item> where
B: Predicate<Item>,
Self: Sized,
fn and<B>(self, other: B) -> AndPredicate<Self, B, Item> where
B: Predicate<Item>,
Self: Sized,
Compute the logical AND of two Predicate
results, returning the result. Read more
Compute the logical OR of two Predicate
results, returning the result. Read more
Compute the logical NOT of a Predicate
, returning the result. Read more