ClickHouse

Форк
0
/
negate.cpp 
46 строк · 1.2 Кб
1
#include <Functions/FunctionFactory.h>
2
#include <Functions/FunctionUnaryArithmetic.h>
3
#include <DataTypes/NumberTraits.h>
4

5
namespace DB
6
{
7

8
template <typename A>
9
struct NegateImpl
10
{
11
    using ResultType = std::conditional_t<is_decimal<A>, A, typename NumberTraits::ResultOfNegate<A>::Type>;
12
    static constexpr const bool allow_string_or_fixed_string = false;
13

14
    static inline NO_SANITIZE_UNDEFINED ResultType apply(A a)
15
    {
16
        return -static_cast<ResultType>(a);
17
    }
18

19
#if USE_EMBEDDED_COMPILER
20
    static constexpr bool compilable = true;
21

22
    static inline llvm::Value * compile(llvm::IRBuilder<> & b, llvm::Value * arg, bool)
23
    {
24
        return arg->getType()->isIntegerTy() ? b.CreateNeg(arg) : b.CreateFNeg(arg);
25
    }
26
#endif
27
};
28

29
struct NameNegate { static constexpr auto name = "negate"; };
30
using FunctionNegate = FunctionUnaryArithmetic<NegateImpl, NameNegate, true>;
31

32
template <> struct FunctionUnaryArithmeticMonotonicity<NameNegate>
33
{
34
    static bool has() { return true; }
35
    static IFunction::Monotonicity get(const Field &, const Field &)
36
    {
37
        return { .is_monotonic = true, .is_positive = false, .is_strict = true };
38
    }
39
};
40

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

46
}
47

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

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

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

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