Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F19251734
closeWithinTolerance.hh
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
1014 B
Referenced Files
None
Subscribers
None
closeWithinTolerance.hh
View Options
#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
Details
Attached
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)
Attached To
Mode
rNPSTATSVN npstatsvn
Attached
Detach File
Event Timeline
Log In to Comment