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

#include <testutils/testasserts.h>

Description

Computes and represents a floating-point difference value.

Methods in this class do not throw, except for toString(), which may throw std::bad_alloc.

See Also
FloatingPointTolerance

Public Member Functions

 FloatingPointDifference (float ref, float value)
 Initializes a single-precision difference. More...
 
 FloatingPointDifference (double ref, double value)
 Initializes a double-precision difference. More...
 
bool isNaN () const
 Whether one or both of the compared values were NaN. More...
 
double asAbsolute () const
 Returns the difference as an absolute number (always non-negative).
 
gmx_uint64_t asUlps () const
 Returns the difference as ULPs (always non-negative). More...
 
bool signsDiffer () const
 Whether the compared values were of different sign. More...
 
bool isDouble () const
 Whether the difference is between single- or double-precision numbers.
 
std::string toString () const
 Formats the difference as a string for assertion failure messages.
 
double termMagnitude () const
 Returns the magnitude of the original second term of the difference.
 

Constructor & Destructor Documentation

gmx::test::FloatingPointDifference::FloatingPointDifference ( float  ref,
float  value 
)

Initializes a single-precision difference.

Parameters
refFirst term in difference
valueSecond term in difference

For absolute and ULP differences the two parameters are equivalent, since the difference is symmetric. For relative differences the first term is interpreted as the reference value, from which we extract the magnitude to compare with.

gmx::test::FloatingPointDifference::FloatingPointDifference ( double  ref,
double  value 
)

Initializes a double-precision difference.

Parameters
refFirst term in difference
valueSecond term in difference

For absolute and ULP differences the two parameters are equivalent, since the difference is symmetric. For relative differences the first term is interpreted as the reference value, from which we extract the magnitude to compare with.

Member Function Documentation

gmx_uint64_t gmx::test::FloatingPointDifference::asUlps ( ) const
inline

Returns the difference as ULPs (always non-negative).

The ULPs are calculated for the type that corresponds to the constructor used to initialize the difference. The ULP difference between 0.0 and -0.0 is zero.

bool gmx::test::FloatingPointDifference::isNaN ( ) const

Whether one or both of the compared values were NaN.

If this returns true, other accessors return meaningless values.

bool gmx::test::FloatingPointDifference::signsDiffer ( ) const
inline

Whether the compared values were of different sign.

0.0 and -0.0 are treated as positive and negative, respectively.


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