CMath::epsilonEqual fuzzy comparison function for doubles

refs #81
This commit is contained in:
Klaus Basan
2013-12-20 22:43:47 +00:00
committed by Mathew Sutcliffe
parent b0e212998f
commit 2cdc2abeb5
2 changed files with 18 additions and 0 deletions

View File

@@ -62,6 +62,15 @@ namespace BlackMisc
return rv; return rv;
} }
/*
* Equal, considering equal
*/
bool CMath::epsilonEqual(double v1, double v2, double epsilon)
{
if (v1 == v2) return true;
return qAbs(v1-v2) <= epsilon;
}
/* /*
* To radians * To radians
*/ */

View File

@@ -71,6 +71,15 @@ namespace BlackMisc
*/ */
static double roundEpsilon(double value, double epsilon); static double roundEpsilon(double value, double epsilon);
/*!
* \brief Epsilon safe equal
* \param v1
* \param v2
* \param epsilon
* \return
*/
static bool epsilonEqual(double v1, double v2, double epsilon = 1E-06);
/*! /*!
* \brief Nearest integer not greater in magnitude than value, correcting for epsilon * \brief Nearest integer not greater in magnitude than value, correcting for epsilon
* \param value * \param value