Gromacs
5.1
|
#include <testutils/testasserts.h>
Specifies a floating-point comparison tolerance and checks whether a difference is within the tolerance.
The related functions section lists methods that can be construct methods using less parameters than the full constructor, and with more obvious semantics. These should be preferred over using the constructor directly.
Several types of tolerances are possible:
0.0
and -0.0
are treated as equal for the ULP check.0.0
and -0.0
: a value with a different sign than the zero will fail the check).Either an absolute or a ULP tolerance must always be specified. If both are specified, then the check passes if either of the tolerances is satisfied.
Any combination of absolute and ULP tolerance can be combined with the sign check. In this case, the sign check must succeed for the check to pass, even if other tolerances are satisfied.
The tolerances can be specified separately for single and double precision comparison. Different initialization functions have different semantics on how the provided tolerance values are interpreted; check their documentation.
Methods in this class do not throw, except for toString(), which may throw std::bad_alloc.
Public Member Functions | |
FloatingPointTolerance (float singleAbsoluteTolerance, double doubleAbsoluteTolerance, gmx_uint64_t singleUlpTolerance, gmx_uint64_t doubleUlpTolerance, bool bSignMustMatch) | |
Creates a tolerance with the specified values. More... | |
bool | isWithin (const FloatingPointDifference &difference) const |
Checks whether a difference is within the specified tolerance. More... | |
std::string | toString (const FloatingPointDifference &difference) const |
Formats the tolerance as a string for assertion failure messages. | |
Related Functions | |
(Note that these are not member functions.) | |
static FloatingPointTolerance | ulpTolerance (gmx_uint64_t ulpDiff) |
Creates a tolerance that only allows a specified ULP difference. More... | |
FloatingPointTolerance | relativeToleranceAsFloatingPoint (double magnitude, double tolerance) |
Creates a tolerance that allows a difference in two compared values that is relative to the given magnitude. More... | |
static FloatingPointTolerance | relativeToleranceAsPrecisionDependentUlp (double magnitude, gmx_uint64_t singleUlpDiff, gmx_uint64_t doubleUlpDiff) |
Creates a tolerance that allows a precision-dependent relative difference in a complex computation. More... | |
static FloatingPointTolerance | absoluteTolerance (double tolerance) |
Creates a tolerance that allows a specified absolute difference. | |
static FloatingPointTolerance | relativeToleranceAsUlp (double magnitude, gmx_uint64_t ulpDiff) |
Creates a tolerance that allows a relative difference in a complex computation. More... | |
static FloatingPointTolerance | defaultRealTolerance () |
Returns the default tolerance for comparing real numbers. | |