Add maths check for integer numbers on doubles

This commit is contained in:
Danny Robson 2012-04-20 18:04:40 +10:00
parent 64dd72db85
commit fc0b978ac1
2 changed files with 18 additions and 0 deletions

View File

@ -57,6 +57,18 @@ template double rootsquare (double, double);
template double rootsquare ( int, int); template double rootsquare ( int, int);
template <typename T>
bool
is_integer (const T &value) {
T integer;
return exactly_equal (std::modf (value, &integer),
static_cast<T> (0.0));
}
template bool is_integer (const double&);
template bool is_integer (const float&);
template <> template <>
bool bool
almost_equal (const float &a, const float &b) almost_equal (const float &a, const float &b)

View File

@ -49,6 +49,12 @@ T
round_pow2 (T value) pure; round_pow2 (T value) pure;
template <typename T>
bool
is_integer (const T& value) pure;
/** /**
* Check if two floating point numbers are approximately equal. Returns true * Check if two floating point numbers are approximately equal. Returns true
* if the difference is less than a percentage of each individual value. * if the difference is less than a percentage of each individual value.