Celeritas
0.5.0-56+6b053cd
|
Functor for noninfinite floating point equality. More...
#include <SoftEqual.hh>
Public Types | |
Type aliases | |
using | value_type = RealType |
Public Member Functions | |
CELER_CONSTEXPR_FUNCTION | SoftEqual () |
Construct with default relative/absolute precision. | |
CELER_FUNCTION | SoftEqual (value_type rel) |
Construct with scaled absolute precision. | |
CELER_FUNCTION | SoftEqual (value_type rel, value_type abs) |
Construct with both relative and absolute precision. More... | |
bool CELER_FUNCTION | operator() (value_type a, value_type b) const |
Compare two values, implicitly casting arguments. | |
CELER_CONSTEXPR_FUNCTION value_type | rel () const |
Relative allowable error. | |
CELER_CONSTEXPR_FUNCTION value_type | abs () const |
Absolute tolerance. | |
Functor for noninfinite floating point equality.
This function-like class considers an absolute tolerance for values near zero, and a relative tolerance for values far from zero. It correctly returns "false" if either value being compared is NaN. The call operator is commutative: eq(a,b)
should always give the same as eq(b,a)
.
The actual comparison is:
\[ |a - b| < \max(\epsilon_r \max(|a|, |b|), \epsilon_a) \]
a == b || soft_eq(a, b)
. CELER_FUNCTION celeritas::SoftEqual< RealType >::SoftEqual | ( | value_type | rel, |
value_type | abs | ||
) |
Construct with both relative and absolute precision.
rel | tolerance of relative error (default 1.0e-12 for doubles) |
abs | threshold for absolute error when comparing small quantities (default 1.0e-14 for doubles) |