Add query for decimal digits of an integer

This commit is contained in:
Danny Robson 2012-07-30 16:31:51 +10:00
parent 983b96c958
commit 20e8297768
2 changed files with 22 additions and 0 deletions

View File

@ -65,6 +65,24 @@ template bool is_integer (const double&);
template bool is_integer (const float&);
//-----------------------------------------------------------------------------
template <>
unsigned
digits (const uint32_t &v) {
return (v >= 1000000000) ? 10 :
(v >= 100000000) ? 9 :
(v >= 10000000) ? 8 :
(v >= 1000000) ? 7 :
(v >= 100000) ? 6 :
(v >= 10000) ? 5 :
(v >= 1000) ? 4 :
(v >= 100) ? 3 :
(v >= 10) ? 2 :
1;
}
//-----------------------------------------------------------------------------
template <>
bool
almost_equal (const float &a, const float &b)

View File

@ -55,6 +55,10 @@ bool
is_integer (const T& value) pure;
template <typename T>
unsigned
digits (const T& value) pure;
/**
* Check if two floating point numbers are approximately equal. Returns true