From fc0b978ac15ac3fa6976d9280749ddce41d6bc22 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 20 Apr 2012 18:04:40 +1000 Subject: [PATCH] Add maths check for integer numbers on doubles --- maths.cpp | 12 ++++++++++++ maths.hpp | 6 ++++++ 2 files changed, 18 insertions(+) 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.