maths: move is_integer into headers to avoid param explosion

This commit is contained in:
Danny Robson 2016-05-12 17:34:47 +10:00
parent 60286202fd
commit e71bd9f621
2 changed files with 15 additions and 18 deletions

View File

@ -57,22 +57,6 @@ template uint32_t util::log2 (uint32_t);
template uint64_t util::log2 (uint64_t);
///////////////////////////////////////////////////////////////////////////////
template <typename T>
bool
util::is_integer (const T &value)
{
T integer;
return exactly_equal (std::modf (value, &integer),
static_cast<T> (0.0));
}
//-----------------------------------------------------------------------------
template bool util::is_integer (const double&);
template bool util::is_integer (const float&);
///////////////////////////////////////////////////////////////////////////////
namespace util {
template <>

View File

@ -263,8 +263,21 @@ namespace util {
///////////////////////////////////////////////////////////////////////////////
// Properties
template <typename T>
bool
is_integer (const T& value);
constexpr
std::enable_if_t<std::is_integral<T>::value, bool>
is_integer (T)
{
return true;
}
template <typename T>
constexpr
std::enable_if_t<std::is_floating_point<T>::value, bool>
is_integer (T t)
{
T i = 0;
return exactly_equal (std::modf (t, &i), T{0});
}
//-----------------------------------------------------------------------------