pub struct Tolerance<F> { /* private fields */ }Expand description
The tolerance used to compare to floating point numbers.
Generally, two numbers x and y are approximately equal if
|x - y| < max(R * (|x + y|), A)where R is the relative tolerance and A is the absolute tolerance.
The most common way to initialize this struct is to use Tolerance::<F>::default().
In that case, the relative and absolute tolerances are computed using an heuristic based
on the EPSILON and MIN_POSITIVE values of the given floating point type F.
Another common initialization is Tolerance::<F>::rel_abs(1e-4, 1e-5).set_half_precision_relative(1e-2).
This will use a sane default to manage values too close to 0.0 and
use different relative tolerances depending on the floating point precision.
Implementations§
Source§impl<F: Float> Tolerance<F>
impl<F: Float> Tolerance<F>
Sourcepub fn permissive() -> Self
pub fn permissive() -> Self
Create a tolerance with permissive precision setting.
Sourcepub fn rel_abs<FF: ToPrimitive>(relative: FF, absolute: FF) -> Self
pub fn rel_abs<FF: ToPrimitive>(relative: FF, absolute: FF) -> Self
When comparing two numbers, this uses both the relative and absolute differences.
That is, x and y are approximately equal if
|x - y| < max(R * (|x + y|), A)where R is the relative tolerance and A is the absolute tolerance.
Sourcepub fn relative<FF: ToPrimitive>(tolerance: FF) -> Self
pub fn relative<FF: ToPrimitive>(tolerance: FF) -> Self
When comparing two numbers, this uses only the relative difference.
That is, x and y are approximately equal if
|x - y| < R * max(|x|, |y|)where R is the relative tolerance.
Sourcepub fn absolute<FF: ToPrimitive>(tolerance: FF) -> Self
pub fn absolute<FF: ToPrimitive>(tolerance: FF) -> Self
When comparing two numbers, this uses only the absolute difference.
That is, x and y are approximately equal if
|x - y| < Awhere A is the absolute tolerance.
Sourcepub fn set_relative<FF: ToPrimitive>(self, tolerance: FF) -> Self
pub fn set_relative<FF: ToPrimitive>(self, tolerance: FF) -> Self
Change the relative tolerance to the given one.
Sourcepub fn set_half_precision_relative<FF: ToPrimitive>(self, tolerance: FF) -> Self
pub fn set_half_precision_relative<FF: ToPrimitive>(self, tolerance: FF) -> Self
Change the relative tolerance to the given one only if F is half precision.
Sourcepub fn set_single_precision_relative<FF: ToPrimitive>(
self,
tolerance: FF,
) -> Self
pub fn set_single_precision_relative<FF: ToPrimitive>( self, tolerance: FF, ) -> Self
Change the relative tolerance to the given one only if F is single precision.
Sourcepub fn set_double_precision_relative<FF: ToPrimitive>(
self,
tolerance: FF,
) -> Self
pub fn set_double_precision_relative<FF: ToPrimitive>( self, tolerance: FF, ) -> Self
Change the relative tolerance to the given one only if F is double precision.
Sourcepub fn set_absolute<FF: ToPrimitive>(self, tolerance: FF) -> Self
pub fn set_absolute<FF: ToPrimitive>(self, tolerance: FF) -> Self
Change the absolute tolerance to the given one.
Sourcepub fn set_half_precision_absolute<FF: ToPrimitive>(self, tolerance: FF) -> Self
pub fn set_half_precision_absolute<FF: ToPrimitive>(self, tolerance: FF) -> Self
Change the absolute tolerance to the given one only if F is half precision.
Sourcepub fn set_single_precision_absolute<FF: ToPrimitive>(
self,
tolerance: FF,
) -> Self
pub fn set_single_precision_absolute<FF: ToPrimitive>( self, tolerance: FF, ) -> Self
Change the absolute tolerance to the given one only if F is single precision.
Sourcepub fn set_double_precision_absolute<FF: ToPrimitive>(
self,
tolerance: FF,
) -> Self
pub fn set_double_precision_absolute<FF: ToPrimitive>( self, tolerance: FF, ) -> Self
Change the absolute tolerance to the given one only if F is double precision.
Trait Implementations§
impl<F: Copy> Copy for Tolerance<F>
Auto Trait Implementations§
impl<F> Freeze for Tolerance<F>where
F: Freeze,
impl<F> RefUnwindSafe for Tolerance<F>where
F: RefUnwindSafe,
impl<F> Send for Tolerance<F>where
F: Send,
impl<F> Sync for Tolerance<F>where
F: Sync,
impl<F> Unpin for Tolerance<F>where
F: Unpin,
impl<F> UnwindSafe for Tolerance<F>where
F: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more