Skip to content
Snippets Groups Projects
Commit e63b2b72 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

Numeric::relativeDifference exact, w/o epsilon

parent c1f32cd3
No related branches found
No related tags found
1 merge request!2621consolidate fcts to compute and check relative differences
...@@ -27,12 +27,7 @@ void check_scalar(double a, double b, int ulp) ...@@ -27,12 +27,7 @@ void check_scalar(double a, double b, int ulp)
double Numeric::relativeDifference(double a, double b) double Numeric::relativeDifference(double a, double b)
{ {
constexpr double eps = std::numeric_limits<double>::epsilon(); return 2 * std::abs(a - b) / (std::abs(a) + std::abs(b));
const double avg_abs = (std::abs(a) + std::abs(b)) / 2.0;
// return 0.0 if relative error smaller than epsilon
if (std::abs(a - b) <= eps * avg_abs)
return 0.0;
return std::abs(a - b) / avg_abs;
} }
bool Numeric::almostEqual(double a, double b, int ulp) bool Numeric::almostEqual(double a, double b, int ulp)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment