eckit::types namespace

Classes

template<typename T>
class CompareApproximatelyEqual
Helper class that memorizes the comparison setttings.

Functions

template<typename T>
auto is_approximately_equal(T a, T b, T epsilon = std::numeric_limits<T>::epsilon(), int maxUlpsDiff = 10) -> bool
template<typename T>
auto is_equal(const T& a, const T& b) -> bool
Compare values equality.
template<typename T>
auto is_greater_or_equal(const T& a, const T& b) -> bool
Compare values inequality: "is greater or equal to".
template<typename T>
auto is_approximately_greater_or_equal(const T& a, const T& b, T epsilon = std::numeric_limits<T>::epsilon(), int maxUlpsDiff = 10) -> bool
Compare values inequality: "is greater or approximately equal to".
template<typename T>
auto is_approximately_lesser_or_equal(const T& a, const T& b, T epsilon = std::numeric_limits<T>::epsilon(), int maxUlpsDiff = 10) -> bool
Compare values inequality: "is less or approximately equal to".
template<typename T>
auto is_strictly_greater(const T& a, const T& b, T epsilon = std::numeric_limits<T>::epsilon(), int maxUlpsDiff = 10) -> bool
Compare values inequality: "is strictly greater than".
auto is_approximately_equal(float a, float b, float epsilon, int maxUlpsDiff) -> template bool
auto is_approximately_equal(double a, double b, double epsilon, int maxUlpsDiff) -> template bool

Function documentation

template<typename T>
bool eckit::types::is_approximately_equal(T a, T b, T epsilon = std::numeric_limits<T>::epsilon(), int maxUlpsDiff = 10)

Compare 2 floats with an absolute epsilon check (values near zero), then based on ULPs

epsilon : epsilon for floating-point absolute epsilon check (should be some small multiple of std::numeric_limits<T>::epsilon()). Used to check values near zero maxUlpsDiff: maximum spacing between the floating-point numbers A and B unit in the last place or unit of least precision. defaults to 10. maxUlpsDiff can also be interpreted in terms of how many representable floats we are willing to accept between A and B. This function will allow maxUlpsDiff-1 floats between A and B.

Assumptions:

  • Bit identical numbers are equal for any epsilon.
  • A NaN is different from any number (even another NaN).
  • Infinity is different from any number but infinity (with the same sign).
  • Subnormal numbers are treated as equal to 0
  • +/-std::numeric_limits<T>::min() has ULP distance 1 from 0
  • -std::numeric_limits<T>::min() has ULP distance 2 from std::numeric_limits<T>::min()
  • ULP distance from 0 is 1 + ULP distance from std::numeric_limits<T>::min() (for positive numbers) Compares values equality within a range defined by an epsilon and a This function only has specializations for double and float

template<typename T>
bool eckit::types::is_equal(const T& a, const T& b)

Compare values equality.

template<typename T>
bool eckit::types::is_greater_or_equal(const T& a, const T& b)

Compare values inequality: "is greater or equal to".

template<typename T>
bool eckit::types::is_approximately_greater_or_equal(const T& a, const T& b, T epsilon = std::numeric_limits<T>::epsilon(), int maxUlpsDiff = 10)

Compare values inequality: "is greater or approximately equal to".

template<typename T>
bool eckit::types::is_approximately_lesser_or_equal(const T& a, const T& b, T epsilon = std::numeric_limits<T>::epsilon(), int maxUlpsDiff = 10)

Compare values inequality: "is less or approximately equal to".

template<typename T>
bool eckit::types::is_strictly_greater(const T& a, const T& b, T epsilon = std::numeric_limits<T>::epsilon(), int maxUlpsDiff = 10)

Compare values inequality: "is strictly greater than".

template bool eckit::types::is_approximately_equal(float a, float b, float epsilon, int maxUlpsDiff)

template bool eckit::types::is_approximately_equal(double a, double b, double epsilon, int maxUlpsDiff)