Loading...
Searching...
No Matches
Opm::cmp Namespace Reference

In the namespace cmp are implemented functions for approximate comparison of double values based on absolute and relative difference. More...

## Functions

template<typename T >
bool | scalar_equal (T value1, T value2, T abs_eps, T rel_eps)
template<typename T >
bool | scalar_equal (T value1, T value2)
template<typename T >
bool | vector_equal (const std::vector< T > &v1, const std::vector< T > &v2, T abs_eps, T rel_eps)
template<typename T >
bool | vector_equal (const std::vector< T > &v1, const std::vector< T > &v2)
template<typename T >
bool | array_equal (const T *p1, const T *p2, size_t num_elements, T abs_eps, T rel_eps)
template<typename T >
bool | array_equal (const T *p1, const T *p2, size_t num_elements)

## Variables

const double | default_abs_epsilon = 1e-8
const double | default_rel_epsilon = 1e-5

## Detailed Description

In the namespace cmp are implemented functions for approximate comparison of double values based on absolute and relative difference.

There are three functions:

scalar_equal<T>() : Compare two <T> values.

ptr_equal<T>(): This compares all the element in the two T * pointers.

vector_equal<T>(): This compares all the elements in two std::vector<T> instances.

For both vector_equal<T>() and ptr_equal<T>() the actual comparison is based on the scalar_equal<T>() function. All functions exist as two overloads, one which takes explicit input values for the absolute and relative epsilon, and one which uses default values.

The comparison functions are implemented as templates, with the following caveats:

1. The static_assert() in scalar_equal<T> ensures that only floating point types can be used.
2. The default epsilon values are of type double - irrespective of the type of data being compared.

For more details of floating point comparison please consult this reference:

https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/