CMS 3D CMS Logo

closeWithinTolerance.h
Go to the documentation of this file.
1 #ifndef NPSTAT_CLOSEWITHINTOLERANCE_HH_
2 #define NPSTAT_CLOSEWITHINTOLERANCE_HH_
3 
15 #include <cmath>
16 #include <algorithm>
18 
19 namespace npstat {
25  inline bool closeWithinTolerance(const double& a, const double& b, const double& tol) {
26  if (tol < 0.0)
28  "In npstat::closeWithinTolerance: "
29  "negative tolerance is not allowed");
30  if (a == b)
31  return true;
32  else
33  return fabs(a - b) / std::max(fabs(a), fabs(b)) <= tol;
34  }
35 } // namespace npstat
36 
37 #endif // NPSTAT_CLOSEWITHINTOLERANCE_HH_
bool closeWithinTolerance(const double &a, const double &b, const double &tol)
Exceptions for the npstat namespace.
double b
Definition: hdecay.h:118
double a
Definition: hdecay.h:119