28 return std::abs(a - b);
34 constexpr
double eps = std::numeric_limits<double>::epsilon();
35 const double avg_abs = (std::abs(a) + std::abs(b)) / 2.0;
37 if (std::abs(a - b) <=
eps * avg_abs)
39 return std::abs(a - b) / avg_abs;
46 double a_t = std::max(a, std::numeric_limits<double>::min());
47 double b_t = std::max(b, std::numeric_limits<double>::min());
48 return std::abs(std::log(a_t) - std::log(b_t));
Defines constants and "almost equal" in namespace Numeric.
Floating-point epsilon, tolerances, almost-equal.
double GetRelativeDifference(double a, double b)
Returns the safe relative difference, which is 2(|a-b|)/(|a|+|b|) except in special cases.
double GetAbsoluteDifference(double a, double b)
Returns the absolute value of the difference between a and b.
double GetLogDifference(double a, double b)
Returns the difference of the logarithm; input values are truncated at the minimum positive value.