35#ifndef NEKTAR_LIB_UTILITIES_REALCOMPARISON_H
36#define NEKTAR_LIB_UTILITIES_REALCOMPARISON_H
56 const T diff = std::abs(lhs - rhs);
57 const T scale = (std::min)(std::abs(lhs), std::abs(rhs));
58 const T eps = std::numeric_limits<T>::epsilon();
65 return diff / (scale * eps);
72 class = std::enable_if_t<
73 std::is_floating_point_v<
typename std::remove_cv<
74 typename std::remove_reference<T1>::type>::type> &&
75 std::is_same_v<
typename std::remove_cv<
76 typename std::remove_reference<T1>::type>::type,
77 typename std::remove_cv<
78 typename std::remove_reference<T2>::type>::type>>>
84 ASSERTL1(factor >= 1,
"real comparison factor needs to be >= 1");
92 class = std::enable_if_t<
93 std::is_floating_point_v<
typename std::remove_cv<
94 typename std::remove_reference<T1>::type>::type> &&
95 std::is_same_v<
typename std::remove_cv<
96 typename std::remove_reference<T1>::type>::type,
97 typename std::remove_cv<
98 typename std::remove_reference<T2>::type>::type>>>
103 ASSERTL1(tol >= 0,
"real comparison tolerance needs to be >= 0");
105 return std::abs(lhs - rhs) < tol;
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
T EpsilonDifference(T lhs, T rhs)
bool IsRealClose(T1 &&lhs, T2 &&rhs, const NekDouble tol=NekConstants::kNekMachineEpsilon)
compare reals of same type with absolute tolerance
bool IsRealEqual(T1 &&lhs, T2 &&rhs, const unsigned int factor=NekConstants::kNekFloatCompFact)
compare reals of same type with relative tolerance
static const unsigned int kNekFloatCompFact
static const NekDouble kNekMachineEpsilon