#include #include #include namespace DB { template struct MinusImpl { using ResultType = typename NumberTraits::ResultOfSubtraction::Type; static const constexpr bool allow_decimal = true; static const constexpr bool allow_fixed_string = false; template static inline NO_SANITIZE_UNDEFINED Result apply(A a, B b) { if constexpr (is_big_int_v || is_big_int_v) { using CastA = std::conditional_t, uint8_t, std::conditional_t, B, A>>; using CastB = std::conditional_t, uint8_t, std::conditional_t, A, B>>; return static_cast(static_cast(a)) - static_cast(static_cast(b)); } else return static_cast(a) - b; } /// Apply operation and check overflow. It's used for Deciamal operations. @returns true if overflowed, false otherwise. template static inline bool apply(A a, B b, Result & c) { return common::subOverflow(static_cast(a), b, c); } #if USE_EMBEDDED_COMPILER static constexpr bool compilable = true; static inline llvm::Value * compile(llvm::IRBuilder<> & b, llvm::Value * left, llvm::Value * right, bool) { return left->getType()->isIntegerTy() ? b.CreateSub(left, right) : b.CreateFSub(left, right); } #endif }; struct NameMinus { static constexpr auto name = "minus"; }; using FunctionMinus = FunctionBinaryArithmetic; void registerFunctionMinus(FunctionFactory & factory) { factory.registerFunction(); } }