YODA is hosted by Hepforge, IPPP Durham
YODA::CmpFloats Struct Reference

Functor to compare two floating point numbers and return whether they are fuzzily equivalent. More...

#include <Predicates.h>

Public Member Functions

 CmpFloats (double tol=1e-3, double refscale=0.0)
 
bool operator() (const double &a, const double &b)
 

Detailed Description

Functor to compare two floating point numbers and return whether they are fuzzily equivalent.

The equivalence comparison is of the form dev = |b-a|/refscale. The refscale argument may used to force the reference scale in this, otherwise (or if explicitly set to zero) it will default to (|a| + |b|)/2. The returned boolean is determined by the comparison |dev| < tol.

Definition at line 20 of file Predicates.h.

Constructor & Destructor Documentation

YODA::CmpFloats::CmpFloats ( double  tol = 1e-3,
double  refscale = 0.0 
)
inline

Definition at line 21 of file Predicates.h.

21 : _tol(tol), _refscale(refscale) {}

Member Function Documentation

bool YODA::CmpFloats::operator() ( const double &  a,
const double &  b 
)
inline

Definition at line 22 of file Predicates.h.

22  {
23  const double div = (_refscale == 0) ? 0.5*(std::abs(a)+std::abs(b)) : _refscale;
24  const double dev = (b-a)/div;
25  // std::cout << "CmpFloats: " << a << " vs. " << b << " -> dev = " << dev << std::endl;
26  return std::abs(dev) < _tol;
27  }

The documentation for this struct was generated from the following file: