Trait float_eq::FloatEqAll
source · [−]pub trait FloatEqAll<Rhs: ?Sized = Self> {
type AllTol: ?Sized + FloatEqUlpsTol;
Show 14 methods
fn eq_abs_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool;
fn eq_rmax_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool;
fn eq_rmin_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool;
fn eq_r1st_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool;
fn eq_r2nd_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool;
fn eq_ulps_all(&self, other: &Rhs, tol: &UlpsTol<Self::AllTol>) -> bool;
fn ne_abs_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool { ... }
fn eq_rel_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool { ... }
fn ne_rel_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool { ... }
fn ne_rmax_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool { ... }
fn ne_rmin_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool { ... }
fn ne_r1st_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool { ... }
fn ne_r2nd_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool { ... }
fn ne_ulps_all(&self, other: &Rhs, tol: &UlpsTol<Self::AllTol>) -> bool { ... }
}
Expand description
Compare IEEE floating point values for equality using a uniform tolerance.
This trait is used in the implementation of the float_eq!
and assert_float_eq!
families of macros to provide the *_all
variants of comparison algorithms
for homogeneous types.
To implement this trait over a new type, see How to compare custom types.
Examples
let a = [1.000_000_2f32, -2.0];
let b = [1.0f32, -2.000_002];
assert!(a.eq_abs_all(&b, &0.000_002));
assert!(a.ne_abs_all(&b, &0.000_001));
assert!(a.eq_rmax_all(&b, &0.000_001));
assert!(a.ne_rmax_all(&b, &0.000_000_5));
assert!(a.eq_ulps_all(&b, &8));
assert!(a.ne_ulps_all(&b, &7));
Required Associated Types
type AllTol: ?Sized + FloatEqUlpsTol
type AllTol: ?Sized + FloatEqUlpsTol
Type of the maximum allowed difference between each of two values’ fields for them to be considered equal.
Required Methods
fn eq_abs_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool
fn eq_abs_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool
Check whether self
is equal to other
, using an absolute tolerance
comparison.
This must use the same algorithm as FloatEq::eq_abs
.
fn eq_rmax_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool
fn eq_rmax_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool
Check whether self
is equal to other
, using a relative tolerance
comparison.
This must use the same algorithm as FloatEq::eq_rmax
.
fn eq_rmin_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool
fn eq_rmin_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool
Check whether self
is equal to other
, using a relative tolerance
comparison.
This must use the same algorithm as FloatEq::eq_rmin
.
fn eq_r1st_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool
fn eq_r1st_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool
Check whether self
is equal to other
, using a relative tolerance
comparison.
This must use the same algorithm as FloatEq::eq_r1st
.
fn eq_r2nd_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool
fn eq_r2nd_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool
Check whether self
is equal to other
, using a relative tolerance
comparison.
This must use the same algorithm as FloatEq::eq_r2nd
.
Check whether self
is equal to other
, using an ULPs comparison.
This must use the same algorithm as FloatEq::eq_ulps
.
Provided Methods
fn ne_abs_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool
fn ne_abs_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool
Check whether self
is not equal to other
, using an absolute tolerance
comparison.
Equal to !self.eq_abs_all(other, tol)
, there is no need to reimplement
this for your own types.
fn eq_rel_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool
fn eq_rel_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool
Check whether self
is equal to other
, using a relative tolerance
comparison.
Equal to self.eq_rmax_all(other, tol)
, there is no need to reimplement
this for your own types.
fn ne_rel_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool
fn ne_rel_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool
Check whether self
is not equal to other
, using a relative tolerance
comparison.
Equal to !self.eq_rel_all(other, tol)
, there is no need to reimplement
this for your own types.
fn ne_rmax_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool
fn ne_rmax_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool
Check whether self
is not equal to other
, using a relative tolerance
comparison.
Equal to !self.eq_rmax_all(other, tol)
, there is no need to reimplement
this for your own types.
fn ne_rmin_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool
fn ne_rmin_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool
Check whether self
is not equal to other
, using a relative tolerance
comparison.
Equal to !self.eq_rmin_all(other, tol)
, there is no need to reimplement
this for your own types.
fn ne_r1st_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool
fn ne_r1st_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool
Check whether self
is not equal to other
, using a relative tolerance
comparison.
Equal to !self.eq_r1st_all(other, tol)
, there is no need to reimplement
this for your own types.
fn ne_r2nd_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool
fn ne_r2nd_all(&self, other: &Rhs, tol: &Self::AllTol) -> bool
Check whether self
is not equal to other
, using a relative tolerance
comparison.
Equal to !self.eq_r2nd_all(other, tol)
, there is no need to reimplement
this for your own types.
Check whether self
is not equal to other
, using an ULPs comparison.
Equal to !self.eq_ulps_all(other, tol)
, there is no need to reimplement
this for your own types.