diff --git a/src/blackmisc/mathematics.cpp b/src/blackmisc/mathematics.cpp index 2bfc1da08..dd71e7c26 100644 --- a/src/blackmisc/mathematics.cpp +++ b/src/blackmisc/mathematics.cpp @@ -62,6 +62,15 @@ namespace BlackMisc 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 */ diff --git a/src/blackmisc/mathematics.h b/src/blackmisc/mathematics.h index 5b399c5c5..9742b93a2 100644 --- a/src/blackmisc/mathematics.h +++ b/src/blackmisc/mathematics.h @@ -71,6 +71,15 @@ namespace BlackMisc */ 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 * \param value