mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-18 13:42:02 +00:00
6d5bfc8c6f
* Better code [#CLICKHOUSE-2]. * Addition to prev. revision [#CLICKHOUSE-2]. * Addition to prev. revision [#CLICKHOUSE-2]. * Addition to prev. revision [#CLICKHOUSE-2].
33 lines
658 B
C++
33 lines
658 B
C++
#pragma once
|
|
|
|
#include <cmath>
|
|
#include <limits>
|
|
#include <type_traits>
|
|
|
|
|
|
/// To be sure, that this function is zero-cost for non-floating point types.
|
|
template <typename T>
|
|
inline bool isNaN(T x)
|
|
{
|
|
return std::is_floating_point<T>::value ? std::isnan(x) : false;
|
|
}
|
|
|
|
template <typename T>
|
|
inline bool isFinite(T x)
|
|
{
|
|
return std::is_floating_point<T>::value ? std::isfinite(x) : true;
|
|
}
|
|
|
|
|
|
template <typename T>
|
|
typename std::enable_if<std::is_floating_point<T>::value, T>::type NaNOrZero()
|
|
{
|
|
return std::numeric_limits<T>::quiet_NaN();
|
|
}
|
|
|
|
template <typename T>
|
|
typename std::enable_if<!std::is_floating_point<T>::value, T>::type NaNOrZero()
|
|
{
|
|
return 0;
|
|
}
|