TTS v3.0.0
The Tiny Test System
 
Loading...
Searching...
No Matches
Precision Tests Macros

Macros for performing tests taking floating-point precision into account. More...

Macros

#define TTS_ABSOLUTE_EQUAL(L, R, N, ...)
 Checks if the absolute distance between values is less or equal to a threshold.
 
#define TTS_IEEE_EQUAL(L, R, ...)
 Checks if two values are exactly within 0 ULP.
 
#define TTS_RELATIVE_EQUAL(L, R, N, ...)
 Checks if values are within a given relative distance expressed as a percentage.
 
#define TTS_ULP_EQUAL(L, R, N, ...)
 Checks if two values are within a given ULP distance.
 
#define TTS_ULP_RANGE_CHECK(Producer, RefType, NewType, RefFunc, NewFunc, Ulpmax)
 Generate a range based test between two functions.
 

Macro Definition Documentation

◆ TTS_ABSOLUTE_EQUAL

#define TTS_ABSOLUTE_EQUAL (   L,
  R,
  N,
  ... 
)

#include <tts/test/precision.hpp>

Checks if the absolute distance between values is less or equal to a threshold.

This comparison is performed by using the proper tts::absolute_distance overload.

Parameters
L,RExpressions to compare.
NMaximum absolute distance accepted between L and R.
...Optional tag. If equals to REQUIRED, this test will stop the program if it fails.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
TTS_CASE("Absolute distance")
{
TTS_ABSOLUTE_EQUAL(-2., 2.f, 4.);
TTS_ABSOLUTE_EQUAL('A', 80LL, 15, REQUIRED);
};
#define TTS_ABSOLUTE_EQUAL(L, R, N,...)
Checks if the absolute distance between values is less or equal to a threshold.
Definition precision.hpp:79
#define TTS_CASE(ID)
Introduces a new test scenario and registers it into the current test driver.
Definition case.hpp:139

◆ TTS_IEEE_EQUAL

#define TTS_IEEE_EQUAL (   L,
  R,
  ... 
)

#include <tts/test/precision.hpp>

Checks if two values are exactly within 0 ULP.

This also allow for infinites and NaNs to be compared equal if both values are the same infinites or are both $NaN$. This comparison is performed by using the proper tts::ulp_distance overload.

Parameters
L,RExpressions to compare.
...Optional tag. If equals to REQUIRED, this test will stop the program if it fails.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
TTS_CASE("ULP distance")
{
float x = std::numeric_limits<float>::quiet_NaN();
TTS_IEEE_EQUAL(1.f, 1.f);
TTS_IEEE_EQUAL(2., 2.);
TTS_IEEE_EQUAL(65, 'A');
};
#define TTS_IEEE_EQUAL(L, R,...)
Checks if two values are exactly within 0 ULP.
Definition precision.hpp:168

◆ TTS_RELATIVE_EQUAL

#define TTS_RELATIVE_EQUAL (   L,
  R,
  N,
  ... 
)

#include <tts/test/precision.hpp>

Checks if values are within a given relative distance expressed as a percentage.

This comparison is performed by using the proper tts::relative_distance overload.

Parameters
L,RExpressions to compare.
NMaximum relative percentage accepted between L and R.
...Optional tag. If equals to REQUIRED, this test will stop the program if it fails.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
TTS_CASE("Relative distance")
{
TTS_RELATIVE_EQUAL(42.f, 42.f, 0);
TTS_RELATIVE_EQUAL('A', 80LL, 18.75);
TTS_RELATIVE_EQUAL(1., 2.f, 100.);
TTS_RELATIVE_EQUAL(1, 10, 900., REQUIRED);
};
#define TTS_RELATIVE_EQUAL(L, R, N,...)
Checks if values are within a given relative distance expressed as a percentage.
Definition precision.hpp:101

◆ TTS_ULP_EQUAL

#define TTS_ULP_EQUAL (   L,
  R,
  N,
  ... 
)

#include <tts/test/precision.hpp>

Checks if two values are within a given ULP distance.

This comparison is performed by using the proper tts::ulp_distance overload.

Parameters
L,RExpressions to compare.
NMaximum ULPs accepted between L and R.
...Optional tag. If equals to REQUIRED, this test will stop the program if it fails.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
TTS_CASE("ULP distance")
{
float a {1};
float eps = std::numeric_limits<float>::epsilon();
float qnan = std::numeric_limits<float>::quiet_NaN();
float inf = std::numeric_limits<float>::infinity();
float minf = -inf;
TTS_ULP_EQUAL(a, a, 0.);
TTS_ULP_EQUAL(a, qnan, inf);
TTS_ULP_EQUAL(qnan, qnan, 0.);
TTS_ULP_EQUAL(a, inf, inf);
TTS_ULP_EQUAL(inf, inf, inf);
TTS_ULP_EQUAL(minf, minf, inf);
TTS_ULP_EQUAL(a, a - eps, 1);
TTS_ULP_EQUAL(a, a + eps, 0.5);
TTS_ULP_EQUAL(a, a + 3 * eps, 1.5, REQUIRED);
};
#define TTS_ULP_EQUAL(L, R, N,...)
Checks if two values are within a given ULP distance.
Definition precision.hpp:123

◆ TTS_ULP_RANGE_CHECK

#define TTS_ULP_RANGE_CHECK (   Producer,
  RefType,
  NewType,
  RefFunc,
  NewFunc,
  Ulpmax 
)

#include <tts/test/ranges.hpp>

Generate a range based test between two functions.

Evaluates the histogram of ULP difference between two functions run on the same data set and that they lie in a given ULP distance.

Parameters
ProducerData set generator to use.
RefTypeType to use as reference function input.
NewTypeType to use as challenger function input.
RefFuncReference function to compare to.
NewFuncChallenger function to be compared to the reference one.
UlpmaxMaximal ULPs acceptable for passing the test.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
float ok_x(float x) { return x; }
float bad_x(float x) { return x + x * 1e-7f; }
TTS_CASE("Test range check")
{
[](auto, auto i, auto c) { return (100.f * i) / c; }, float, float, ok_x, bad_x, 2.);
};
#define TTS_ULP_RANGE_CHECK(Producer, RefType, NewType, RefFunc, NewFunc, Ulpmax)
Generate a range based test between two functions.
Definition ranges.hpp:195