ClickHouse

Форк
0
/
isFinite.cpp 
46 строк · 1.1 Кб
1
#include <Functions/FunctionNumericPredicate.h>
2
#include <Functions/FunctionFactory.h>
3
#include <type_traits>
4

5

6
namespace DB
7
{
8
namespace
9
{
10

11
struct 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

17
    static constexpr auto name = "isFinite";
18
    template <typename T>
19
    static bool execute(const T t)
20
    {
21
        if constexpr (std::is_same_v<T, float>)
22
            return (std::bit_cast<uint32_t>(t)
23
                 & 0b01111111100000000000000000000000)
24
                != 0b01111111100000000000000000000000;
25
        else if constexpr (std::is_same_v<T, double>)
26
            return (std::bit_cast<uint64_t>(t)
27
                 & 0b0111111111110000000000000000000000000000000000000000000000000000)
28
                != 0b0111111111110000000000000000000000000000000000000000000000000000;
29
        else
30
        {
31
            (void)t;
32
            return true;
33
        }
34
    }
35
};
36

37
using FunctionIsFinite = FunctionNumericPredicate<IsFiniteImpl>;
38

39
}
40

41
REGISTER_FUNCTION(IsFinite)
42
{
43
    factory.registerFunction<FunctionIsFinite>();
44
}
45

46
}
47

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.