1 | #include <Functions/FunctionFactory.h> |
---|---|
2 | #include <Functions/FunctionBinaryArithmetic.h> |
3 | |
4 | namespace DB |
5 | { |
6 | |
7 | template <typename A, typename B> |
8 | struct DivideFloatingImpl |
9 | { |
10 | using ResultType = typename NumberTraits::ResultOfFloatingPointDivision<A, B>::Type; |
11 | static const constexpr bool allow_decimal = true; |
12 | |
13 | template <typename Result = ResultType> |
14 | static inline NO_SANITIZE_UNDEFINED Result apply(A a, B b) |
15 | { |
16 | return static_cast<Result>(a) / b; |
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 * left, llvm::Value * right, bool) |
23 | { |
24 | if (left->getType()->isIntegerTy()) |
25 | throw Exception("DivideFloatingImpl expected a floating-point type", ErrorCodes::LOGICAL_ERROR); |
26 | return b.CreateFDiv(left, right); |
27 | } |
28 | #endif |
29 | }; |
30 | |
31 | struct NameDivide { static constexpr auto name = "divide"; }; |
32 | using FunctionDivide = FunctionBinaryArithmetic<DivideFloatingImpl, NameDivide>; |
33 | |
34 | void registerFunctionDivide(FunctionFactory & factory) |
35 | { |
36 | factory.registerFunction<FunctionDivide>(); |
37 | } |
38 | |
39 | } |
40 |