Skip to content
Snippets Groups Projects
Commit 59ba381e authored by Margherita Spalla's avatar Margherita Spalla
Browse files

'equalWithinDeltaMethod' modified to implement relative difference comparison.

Former-commit-id: 0204b870413832f5b3dbaf83786c5abbc4ed672e
parent 119a87c5
No related merge requests found
...@@ -329,9 +329,22 @@ dqm_algorithms::BinHeightThreshold::CompareBinHeightThreshold(const std::string ...@@ -329,9 +329,22 @@ dqm_algorithms::BinHeightThreshold::CompareBinHeightThreshold(const std::string
bool bool
dqm_algorithms::BinHeightThreshold::equalWithinPrecision(double a,double b) dqm_algorithms::BinHeightThreshold::equalWithinPrecision(double a,double b)
{ {
if(a>=b-precision_ && a<=b+precision_) //relative difference method (following what suggested in (non-ATLAS) web page http://floating-point-gui.de/errors/comparison/)
double absA = fabs(a);
double absB = fabs(b);
double diff = fabs(a - b);
if (a == b) { // shortcut, handles infinities
return true; return true;
return false; }
else if (a == 0 || b == 0 || diff < DBL_MIN) {
// a or b is zero or both are extremely close to it
// relative error is less meaningful here
return diff < (precision_ * DBL_MIN);
}
else { // use relative error
return (diff / std::min((absA + absB), DBL_MAX)) < precision_;
}
} }
void void
......
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