Gromacs  5.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Member Functions | Related Functions
gmx::test::FloatingPointTolerance Class Reference

#include <testutils/testasserts.h>

Description

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:

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.

Todo:
The factory methods that take ULP difference could be better formulated as methods that take the acceptable number of incorrect bits and/or the number of accurate bits.
See Also
FloatingPointDifference

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.
 

The documentation for this class was generated from the following files: