diff --git a/maths.cpp b/maths.cpp index aae28fd5..cb5d094b 100644 --- a/maths.cpp +++ b/maths.cpp @@ -57,6 +57,18 @@ template double rootsquare (double, double); template double rootsquare ( int, int); +template +bool +is_integer (const T &value) { + T integer; + return exactly_equal (std::modf (value, &integer), + static_cast (0.0)); +} + +template bool is_integer (const double&); +template bool is_integer (const float&); + + template <> bool almost_equal (const float &a, const float &b) diff --git a/maths.hpp b/maths.hpp index 5d83533f..e1473eb3 100644 --- a/maths.hpp +++ b/maths.hpp @@ -49,6 +49,12 @@ T round_pow2 (T value) pure; +template +bool +is_integer (const T& value) pure; + + + /** * Check if two floating point numbers are approximately equal. Returns true * if the difference is less than a percentage of each individual value.