#include #include #include #include namespace DB { template struct MultiplyImpl { using ResultType = typename NumberTraits::ResultOfAdditionMultiplication::Type; static const constexpr bool allow_fixed_string = false; static const constexpr bool allow_string_integer = false; template static NO_SANITIZE_UNDEFINED Result apply(A a, B b) { if constexpr (is_big_int_v || is_big_int_v) { using CastA = std::conditional_t, B, A>; using CastB = 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 Decimal operations. @returns true if overflowed, false otherwise. template static bool apply(A a, B b, Result & c) { if constexpr (std::is_same_v || std::is_same_v) { c = static_cast(a) * b; return false; } else return common::mulOverflow(static_cast(a), b, c); } #if USE_EMBEDDED_COMPILER static constexpr bool compilable = true; static llvm::Value * compile(llvm::IRBuilder<> & b, llvm::Value * left, llvm::Value * right, bool) { return left->getType()->isIntegerTy() ? b.CreateMul(left, right) : b.CreateFMul(left, right); } #endif }; struct NameMultiply { static constexpr auto name = "multiply"; }; using FunctionMultiply = BinaryArithmeticOverloadResolver; REGISTER_FUNCTION(Multiply) { factory.registerFunction(); } }