aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Functions/isInfinite.cpp
blob: ace2c334873e9cb7117fdcbb2c20fb548003fc7a (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
37
38
39
40
41
42
#include <Functions/FunctionNumericPredicate.h>
#include <Functions/FunctionFactory.h>
#include <type_traits>


namespace DB
{
namespace
{

struct IsInfiniteImpl
{
    static constexpr auto name = "isInfinite";
    template <typename T>
    static bool execute(const T t)
    {
        if constexpr (std::is_same_v<T, float>)
            return (std::bit_cast<uint32_t>(t)
                 & 0b01111111111111111111111111111111)
                == 0b01111111100000000000000000000000;
        else if constexpr (std::is_same_v<T, double>)
            return (std::bit_cast<uint64_t>(t)
                 & 0b0111111111111111111111111111111111111111111111111111111111111111)
                == 0b0111111111110000000000000000000000000000000000000000000000000000;
        else
        {
            (void)t;
            return false;
        }
    }
};

using FunctionIsInfinite = FunctionNumericPredicate<IsInfiniteImpl>;

}

REGISTER_FUNCTION(IsInfinite)
{
    factory.registerFunction<FunctionIsInfinite>();
}

}