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