mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-10-13 03:50:50 +00:00
27 lines
537 B
C++
27 lines
537 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>
|
||
|
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;
|
||
|
}
|