mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-15 12:14:18 +00:00
Simplification
This commit is contained in:
parent
2c9ae14cb0
commit
3ca2c3acbc
@ -4,48 +4,33 @@
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
|
||||
#include <common/extended_types.h>
|
||||
|
||||
|
||||
template <typename T>
|
||||
inline bool isNaN(T x)
|
||||
{
|
||||
/// 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)
|
||||
{
|
||||
if constexpr (std::is_floating_point_v<T>)
|
||||
return std::isnan(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline std::enable_if_t<!std::is_floating_point_v<T>, bool> isNaN(T)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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()
|
||||
T NaNOrZero()
|
||||
{
|
||||
if constexpr (std::is_floating_point_v<T>)
|
||||
return std::numeric_limits<T>::quiet_NaN();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::enable_if_t<is_integer_v<T>, 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{};
|
||||
else
|
||||
return {};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user