mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
Updated to use Richard Harris' approximation formula
This commit is contained in:
parent
d7c203c3e9
commit
d7b8b01f3e
@ -18,27 +18,19 @@
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
|
||||
// !TBD Need to clean this all up
|
||||
#define CATCH_absTol 1e-10
|
||||
#define CATCH_relTol 1e-10
|
||||
|
||||
inline double catch_max( double x, double y )
|
||||
{
|
||||
return x > y ? x : y;
|
||||
}
|
||||
namespace Detail
|
||||
{
|
||||
class Approx
|
||||
{
|
||||
public:
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// !TBD more generic
|
||||
explicit Approx
|
||||
(
|
||||
double d
|
||||
)
|
||||
: m_d( d )
|
||||
: m_epsilon( 1e-10 ),
|
||||
m_scale( 1.0 ),
|
||||
m_d( d )
|
||||
{
|
||||
}
|
||||
|
||||
@ -50,10 +42,8 @@ namespace Catch
|
||||
const Approx& rhs
|
||||
)
|
||||
{
|
||||
// !TBD Use proper tolerance
|
||||
// From: http://realtimecollisiondetection.net/blog/?p=89
|
||||
// see also: http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
|
||||
return fabs( lhs - rhs.m_d ) <= catch_max( CATCH_absTol, CATCH_relTol * catch_max( fabs(lhs), fabs(rhs.m_d) ) );
|
||||
// Thanks to Richard Harris for his help refining this formula
|
||||
return fabs( lhs - rhs.m_d ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( fabs(lhs), fabs(rhs.m_d) ) );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
@ -64,9 +54,11 @@ namespace Catch
|
||||
const Approx& rhs
|
||||
)
|
||||
{
|
||||
return ! operator==( lhs, rhs );
|
||||
return !operator==( lhs, rhs );
|
||||
}
|
||||
|
||||
double m_epsilon;
|
||||
double m_scale;
|
||||
double m_d;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user