Trait float_eq::AssertFloatEq
source · [−]pub trait AssertFloatEq<Rhs: ?Sized = Self>: FloatEq<Rhs> {
type DebugAbsDiff: Debug + Sized + FloatEqDebugUlpsDiff;
type DebugTol: Debug + FloatEqUlpsTol;
fn debug_abs_diff(&self, other: &Rhs) -> Self::DebugAbsDiff;
fn debug_ulps_diff(&self, other: &Rhs) -> DebugUlpsDiff<Self::DebugAbsDiff>;
fn debug_abs_tol(&self, other: &Rhs, tol: &Self::Tol) -> Self::DebugTol;
fn debug_rmax_tol(&self, other: &Rhs, tol: &Self::Tol) -> Self::DebugTol;
fn debug_rmin_tol(&self, other: &Rhs, tol: &Self::Tol) -> Self::DebugTol;
fn debug_r1st_tol(&self, other: &Rhs, tol: &Self::Tol) -> Self::DebugTol;
fn debug_r2nd_tol(&self, other: &Rhs, tol: &Self::Tol) -> Self::DebugTol;
fn debug_ulps_tol(
&self,
other: &Rhs,
tol: &UlpsTol<Self::Tol>
) -> UlpsTol<Self::DebugTol>
where
UlpsTol<Self::DebugTol>: Sized;
fn debug_rel_tol(&self, other: &Rhs, tol: &Self::Tol) -> Self::DebugTol { ... }
}
Expand description
Debug context for when an assert fails.
This trait is used by assert_float_eq!
and assert_float_ne!
.
To implement this trait over a new type, see How to compare custom types.
Required Associated Types
sourcetype DebugAbsDiff: Debug + Sized + FloatEqDebugUlpsDiff
type DebugAbsDiff: Debug + Sized + FloatEqDebugUlpsDiff
The absolute difference between two values, displayed to the user via
fmt::Debug
when an assert fails.
This is usually the wider of Self
and Rhs
.
sourcetype DebugTol: Debug + FloatEqUlpsTol
type DebugTol: Debug + FloatEqUlpsTol
The per-field tolerance value used for comparison between two values,
displayed to the user via fmt::Debug
when an assert fails.
This should match Self::Tol
.
Required Methods
sourcefn debug_abs_diff(&self, other: &Rhs) -> Self::DebugAbsDiff
fn debug_abs_diff(&self, other: &Rhs) -> Self::DebugAbsDiff
Always positive absolute difference between two values.
Implementations should be the equivalent of:
(self - other).abs()
sourcefn debug_ulps_diff(&self, other: &Rhs) -> DebugUlpsDiff<Self::DebugAbsDiff>
fn debug_ulps_diff(&self, other: &Rhs) -> DebugUlpsDiff<Self::DebugAbsDiff>
Always positive absolute difference between two values in terms of ULPs.
For primitive values, this should be a partial function that returns:
Some(0)
if both arguments are either0.0
or-0.0
None
if either argument isNaN
None
if the arguments have differing signsSome(bitwise-difference)
otherwise
For composite types, this should return per-field recursively calculated results in order to present the most possible context to the user.
Implementations over primitive types should be the equivalent of (using
f32
as an example):
if self == other {
Some(0)
} else if self.is_nan() || other.is_nan() {
None
} else if self.is_sign_positive() != other.is_sign_positive() {
None
} else {
let a = self.to_bits();
let b = other.to_bits();
let max = a.max(b);
let min = a.min(b);
Some(max - min)
}
sourcefn debug_abs_tol(&self, other: &Rhs, tol: &Self::Tol) -> Self::DebugTol
fn debug_abs_tol(&self, other: &Rhs, tol: &Self::Tol) -> Self::DebugTol
The tolerance used by an abs
comparison, displayed when an assert fails.
sourcefn debug_rmax_tol(&self, other: &Rhs, tol: &Self::Tol) -> Self::DebugTol
fn debug_rmax_tol(&self, other: &Rhs, tol: &Self::Tol) -> Self::DebugTol
The tolerance used by an rmax
comparison, displayed when an assert fails.
Returns tol
scaled by the magnitude of the larger operand.
sourcefn debug_rmin_tol(&self, other: &Rhs, tol: &Self::Tol) -> Self::DebugTol
fn debug_rmin_tol(&self, other: &Rhs, tol: &Self::Tol) -> Self::DebugTol
The tolerance used by an rmin
comparison, displayed when an assert fails.
Returns tol
scaled by the magnitude of the smaller operand.
sourcefn debug_r1st_tol(&self, other: &Rhs, tol: &Self::Tol) -> Self::DebugTol
fn debug_r1st_tol(&self, other: &Rhs, tol: &Self::Tol) -> Self::DebugTol
The tolerance used by an r1st
comparison, displayed when an assert fails.
Returns tol
scaled by the magnitude of the first operand.
sourcefn debug_r2nd_tol(&self, other: &Rhs, tol: &Self::Tol) -> Self::DebugTol
fn debug_r2nd_tol(&self, other: &Rhs, tol: &Self::Tol) -> Self::DebugTol
The tolerance used by an r2nd
comparison, displayed when an assert fails.
Returns tol
scaled by the magnitude of the second operand.
Provided Methods
sourcefn debug_rel_tol(&self, other: &Rhs, tol: &Self::Tol) -> Self::DebugTol
fn debug_rel_tol(&self, other: &Rhs, tol: &Self::Tol) -> Self::DebugTol
The tolerance used by a rel
comparison, displayed when an assert fails.
Equivalent to self.debug_rmax_tol(self, other, tol)
, there is
no need to reimplement this for your own types.