Simplification

This commit is contained in:
Alexey Milovidov 2021-05-06 18:30:42 +03:00
parent 2c9ae14cb0
commit 3ca2c3acbc

View File

@ -4,48 +4,33 @@
#include <limits>
#include <type_traits>
#include <common/extended_types.h>
/// To be sure, that this function is zero-cost for non-floating point types.
template <typename T>
inline std::enable_if_t<std::is_floating_point_v<T>, bool> isNaN(T x)
{
return std::isnan(x);
}
template <typename T>
inline std::enable_if_t<!std::is_floating_point_v<T>, bool> isNaN(T)
inline bool isNaN(T x)
{
return false;
/// To be sure, that this function is zero-cost for non-floating point types.
if constexpr (std::is_floating_point_v<T>)
return std::isnan(x);
else
return false;
}
template <typename T>
inline std::enable_if_t<std::is_floating_point_v<T>, bool> isFinite(T x)
{
return std::isfinite(x);
}
template <typename T>
inline std::enable_if_t<!std::is_floating_point_v<T>, bool> isFinite(T)
inline bool isFinite(T x)
{
return true;
if constexpr (std::is_floating_point_v<T>)
return std::isfinite(x);
else
return true;
}
template <typename T>
std::enable_if_t<std::is_floating_point_v<T>, T> NaNOrZero()
{
return std::numeric_limits<T>::quiet_NaN();
}
template <typename T>
std::enable_if_t<is_integer_v<T>, T> NaNOrZero()
T NaNOrZero()
{
return T{0};
}
template <typename T>
std::enable_if_t<std::is_class_v<T> && !is_integer_v<T>, T> NaNOrZero()
{
return T{};
if constexpr (std::is_floating_point_v<T>)
return std::numeric_limits<T>::quiet_NaN();
else
return {};
}