Struct predicates::float::IsClosePredicate
source · pub struct IsClosePredicate { /* private fields */ }
Available on crate feature
float-cmp
only.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§
source§impl IsClosePredicate
impl IsClosePredicate
sourcepub fn distance(self, distance: <f64 as Ulps>::U) -> Self
pub fn distance(self, distance: <f64 as Ulps>::U) -> Self
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);
sourcepub fn epsilon(self, epsilon: f64) -> Self
pub fn epsilon(self, epsilon: f64) -> Self
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 * f64::EPSILON);
sourcepub fn ulps(self, ulps: <f64 as Ulps>::U) -> Self
pub fn ulps(self, ulps: <f64 as Ulps>::U) -> Self
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§
source§impl Clone for IsClosePredicate
impl Clone for IsClosePredicate
source§fn clone(&self) -> IsClosePredicate
fn clone(&self) -> IsClosePredicate
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for IsClosePredicate
impl Debug for IsClosePredicate
source§impl Display for IsClosePredicate
impl Display for IsClosePredicate
source§impl PartialEq for IsClosePredicate
impl PartialEq for IsClosePredicate
source§fn eq(&self, other: &IsClosePredicate) -> bool
fn eq(&self, other: &IsClosePredicate) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl Predicate<f64> for IsClosePredicate
impl Predicate<f64> for IsClosePredicate
impl Copy for IsClosePredicate
impl StructuralPartialEq for IsClosePredicate
Auto Trait Implementations§
impl Freeze for IsClosePredicate
impl RefUnwindSafe for IsClosePredicate
impl Send for IsClosePredicate
impl Sync for IsClosePredicate
impl Unpin for IsClosePredicate
impl UnwindSafe for IsClosePredicate
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<P, Item> PredicateBooleanExt<Item> for P
impl<P, Item> PredicateBooleanExt<Item> for P
source§fn and<B>(self, other: B) -> AndPredicate<Self, B, Item>
fn and<B>(self, other: B) -> AndPredicate<Self, B, Item>
Compute the logical AND of two
Predicate
results, returning the result. Read moresource§fn or<B>(self, other: B) -> OrPredicate<Self, B, Item>
fn or<B>(self, other: B) -> OrPredicate<Self, B, Item>
Compute the logical OR of two
Predicate
results, returning the result. Read more