2018-11-26 16:20:40 +00:00
|
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include <Functions/FunctionUnaryArithmetic.h>
|
|
|
|
#include <DataTypes/NumberTraits.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
template <typename A>
|
|
|
|
struct NegateImpl
|
|
|
|
{
|
2021-09-10 11:49:22 +00:00
|
|
|
using ResultType = std::conditional_t<is_decimal<A>, A, typename NumberTraits::ResultOfNegate<A>::Type>;
|
2020-02-14 08:17:32 +00:00
|
|
|
static constexpr const bool allow_fixed_string = false;
|
2021-08-30 06:37:23 +00:00
|
|
|
static const constexpr bool allow_string_integer = false;
|
2018-11-26 16:20:40 +00:00
|
|
|
|
2018-12-26 23:55:09 +00:00
|
|
|
static inline NO_SANITIZE_UNDEFINED ResultType apply(A a)
|
2018-11-26 16:20:40 +00:00
|
|
|
{
|
2020-09-11 11:13:41 +00:00
|
|
|
#if defined (__GNUC__) && __GNUC__ >= 10
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wvector-operation-performance"
|
|
|
|
#endif
|
2020-09-11 11:24:42 +00:00
|
|
|
return -static_cast<ResultType>(a);
|
2020-09-11 11:13:41 +00:00
|
|
|
#if defined (__GNUC__) && __GNUC__ >= 10
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#endif
|
2018-11-26 16:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if USE_EMBEDDED_COMPILER
|
|
|
|
static constexpr bool compilable = true;
|
|
|
|
|
|
|
|
static inline llvm::Value * compile(llvm::IRBuilder<> & b, llvm::Value * arg, bool)
|
|
|
|
{
|
|
|
|
return arg->getType()->isIntegerTy() ? b.CreateNeg(arg) : b.CreateFNeg(arg);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NameNegate { static constexpr auto name = "negate"; };
|
|
|
|
using FunctionNegate = FunctionUnaryArithmetic<NegateImpl, NameNegate, true>;
|
|
|
|
|
|
|
|
template <> struct FunctionUnaryArithmeticMonotonicity<NameNegate>
|
|
|
|
{
|
|
|
|
static bool has() { return true; }
|
|
|
|
static IFunction::Monotonicity get(const Field &, const Field &)
|
|
|
|
{
|
2021-09-29 16:01:26 +00:00
|
|
|
return { .is_monotonic = true, .is_positive = false };
|
2018-11-26 16:20:40 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(Negate)
|
2018-11-26 16:20:40 +00:00
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionNegate>();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|