Struct Tolerance
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§
§impl<F> Tolerance<F>where
F: Float,
impl<F> Tolerance<F>where
F: Float,
pub fn rel_abs<FF>(relative: FF, absolute: FF) -> Tolerance<F>where
FF: ToPrimitive,
pub fn rel_abs<FF>(relative: FF, absolute: FF) -> Tolerance<F>where
FF: ToPrimitive,
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.
pub fn relative<FF>(tolerance: FF) -> Tolerance<F>where
FF: ToPrimitive,
pub fn relative<FF>(tolerance: FF) -> Tolerance<F>where
FF: ToPrimitive,
When comparing two numbers, this uses only the relative difference.
That is, x
and y
are approximately equal if
|x - y| < R * (|x + y|)
where R
is the relative tolerance
.
pub fn absolute<FF>(tolerance: FF) -> Tolerance<F>where
FF: ToPrimitive,
pub fn absolute<FF>(tolerance: FF) -> Tolerance<F>where
FF: ToPrimitive,
When comparing two numbers, this uses only the absolute difference.
That is, x
and y
are approximately equal if
|x - y| < A
where A
is the absolute tolerance
.
pub fn set_relative<FF>(self, tolerance: FF) -> Tolerance<F>where
FF: ToPrimitive,
pub fn set_relative<FF>(self, tolerance: FF) -> Tolerance<F>where
FF: ToPrimitive,
Change the relative tolerance to the given one.
pub fn set_half_precision_relative<FF>(self, tolerance: FF) -> Tolerance<F>where
FF: ToPrimitive,
pub fn set_half_precision_relative<FF>(self, tolerance: FF) -> Tolerance<F>where
FF: ToPrimitive,
Change the relative tolerance to the given one only if F
is half precision.
pub fn set_single_precision_relative<FF>(self, tolerance: FF) -> Tolerance<F>where
FF: ToPrimitive,
pub fn set_single_precision_relative<FF>(self, tolerance: FF) -> Tolerance<F>where
FF: ToPrimitive,
Change the relative tolerance to the given one only if F
is single precision.
pub fn set_double_precision_relative<FF>(self, tolerance: FF) -> Tolerance<F>where
FF: ToPrimitive,
pub fn set_double_precision_relative<FF>(self, tolerance: FF) -> Tolerance<F>where
FF: ToPrimitive,
Change the relative tolerance to the given one only if F
is double precision.
pub fn set_absolute<FF>(self, tolerance: FF) -> Tolerance<F>where
FF: ToPrimitive,
pub fn set_absolute<FF>(self, tolerance: FF) -> Tolerance<F>where
FF: ToPrimitive,
Change the absolute tolerance to the given one.
pub fn set_half_precision_absolute<FF>(self, tolerance: FF) -> Tolerance<F>where
FF: ToPrimitive,
pub fn set_half_precision_absolute<FF>(self, tolerance: FF) -> Tolerance<F>where
FF: ToPrimitive,
Change the absolute tolerance to the given one only if F
is half precision.
pub fn set_single_precision_absolute<FF>(self, tolerance: FF) -> Tolerance<F>where
FF: ToPrimitive,
pub fn set_single_precision_absolute<FF>(self, tolerance: FF) -> Tolerance<F>where
FF: ToPrimitive,
Change the absolute tolerance to the given one only if F
is single precision.
pub fn set_double_precision_absolute<FF>(self, tolerance: FF) -> Tolerance<F>where
FF: ToPrimitive,
pub fn set_double_precision_absolute<FF>(self, tolerance: FF) -> Tolerance<F>where
FF: ToPrimitive,
Change the absolute tolerance to the given one only if F
is double precision.
Trait Implementations§
impl<F> Copy for Tolerance<F>where
F: Copy,
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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.