aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Common/NaNUtils.h
blob: 1c5a619e91991687ae5c7de7eed186d8487d015e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#pragma once

#include <cmath>
#include <limits>
#include <type_traits>


template <typename T>
inline bool isNaN(T x)
{
    /// 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 bool isFinite(T x)
{
    if constexpr (std::is_floating_point_v<T>)
        return std::isfinite(x);
    else
        return true;
}


template <typename T>
T NaNOrZero()
{
    if constexpr (std::is_floating_point_v<T>)
        return std::numeric_limits<T>::quiet_NaN();
    else
        return {};
}