Page MenuHomeHEPForge

closeWithinTolerance.hh
No OneTemporary

Size
1014 B
Referenced Files
None
Subscribers
None

closeWithinTolerance.hh

#ifndef NPSTAT_CLOSEWITHINTOLERANCE_HH_
#define NPSTAT_CLOSEWITHINTOLERANCE_HH_
/*!
// \file closeWithinTolerance.hh
//
// \brief Determine if two doubles are within requested relative tolerance
// of each other
//
// Author: I. Volobouev
//
// July 2012
*/
#include <cmath>
#include <algorithm>
#include <stdexcept>
namespace npstat {
/**
// Check if two doubles are within certain relative tolerance from
// each other. The "tol" argument which specifies the tolerance
// must be non-negative.
*/
inline bool closeWithinTolerance(const double& a, const double& b,
const double& tol)
{
if (tol < 0.0)
throw std::invalid_argument("In npstat::closeWithinTolerance: "
"negative tolerance is not allowed");
if (a == b)
return true;
else
return fabs(a - b)/std::max(fabs(a), fabs(b)) <= tol;
}
}
#endif // NPSTAT_CLOSEWITHINTOLERANCE_HH_

File Metadata

Mime Type
text/x-c
Expires
Tue, Sep 30, 6:09 AM (1 d, 10 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6528841
Default Alt Text
closeWithinTolerance.hh (1014 B)

Event Timeline