1 | #include <Functions/FunctionFactory.h> |
---|---|
2 | #include <Functions/FunctionBinaryArithmetic.h> |
3 | |
4 | #include "intDiv.h" |
5 | |
6 | |
7 | namespace DB |
8 | { |
9 | |
10 | template <typename A, typename B> |
11 | struct DivideIntegralOrZeroImpl |
12 | { |
13 | using ResultType = typename NumberTraits::ResultOfIntegerDivision<A, B>::Type; |
14 | |
15 | template <typename Result = ResultType> |
16 | static inline Result apply(A a, B b) |
17 | { |
18 | if (unlikely(divisionLeadsToFPE(a, b))) |
19 | return 0; |
20 | |
21 | return DivideIntegralImpl<A, B>::template apply<Result>(a, b); |
22 | } |
23 | |
24 | #if USE_EMBEDDED_COMPILER |
25 | static constexpr bool compilable = false; /// TODO implement the checks |
26 | #endif |
27 | }; |
28 | |
29 | struct NameIntDivOrZero { static constexpr auto name = "intDivOrZero"; }; |
30 | using FunctionIntDivOrZero = FunctionBinaryArithmetic<DivideIntegralOrZeroImpl, NameIntDivOrZero>; |
31 | |
32 | void registerFunctionIntDivOrZero(FunctionFactory & factory) |
33 | { |
34 | factory.registerFunction<FunctionIntDivOrZero>(); |
35 | } |
36 | |
37 | } |
38 |