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

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.

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

Always positive absolute difference between two values.

Implementations should be the equivalent of:

(self - other).abs()

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 either 0.0 or -0.0
  • None if either argument is NaN
  • None if the arguments have differing signs
  • Some(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)
}

The tolerance used by an abs comparison, displayed when an assert fails.

The tolerance used by an rmax comparison, displayed when an assert fails.

Returns tol scaled by the magnitude of the larger operand.

The tolerance used by an rmin comparison, displayed when an assert fails.

Returns tol scaled by the magnitude of the smaller operand.

The tolerance used by an r1st comparison, displayed when an assert fails.

Returns tol scaled by the magnitude of the first operand.

The tolerance used by an r2nd comparison, displayed when an assert fails.

Returns tol scaled by the magnitude of the second operand.

The tolerance used by an ulps comparison, displayed when an assert fails.

Provided Methods

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.

Implementations on Foreign Types

Implementors