ClickHouse
46 строк · 1.1 Кб
1#include <Functions/FunctionNumericPredicate.h>
2#include <Functions/FunctionFactory.h>
3#include <type_traits>
4
5
6namespace DB
7{
8namespace
9{
10
11struct IsFiniteImpl
12{
13/// Better implementation, because isinf, isfinite, isnan are not inlined for unknown reason.
14/// Assuming IEEE 754.
15/// NOTE gcc 7 doesn't vectorize this loop.
16
17static constexpr auto name = "isFinite";
18template <typename T>
19static bool execute(const T t)
20{
21if constexpr (std::is_same_v<T, float>)
22return (std::bit_cast<uint32_t>(t)
23& 0b01111111100000000000000000000000)
24!= 0b01111111100000000000000000000000;
25else if constexpr (std::is_same_v<T, double>)
26return (std::bit_cast<uint64_t>(t)
27& 0b0111111111110000000000000000000000000000000000000000000000000000)
28!= 0b0111111111110000000000000000000000000000000000000000000000000000;
29else
30{
31(void)t;
32return true;
33}
34}
35};
36
37using FunctionIsFinite = FunctionNumericPredicate<IsFiniteImpl>;
38
39}
40
41REGISTER_FUNCTION(IsFinite)
42{
43factory.registerFunction<FunctionIsFinite>();
44}
45
46}
47