1 | #include <Functions/FunctionFactory.h> |
---|---|
2 | #include <Functions/FunctionBinaryArithmetic.h> |
3 | #include <numeric> |
4 | |
5 | |
6 | namespace DB |
7 | { |
8 | |
9 | template <typename A, typename B> |
10 | struct LCMImpl |
11 | { |
12 | using ResultType = typename NumberTraits::ResultOfAdditionMultiplication<A, B>::Type; |
13 | |
14 | template <typename Result = ResultType> |
15 | static inline Result apply(A a, B b) |
16 | { |
17 | throwIfDivisionLeadsToFPE(typename NumberTraits::ToInteger<A>::Type(a), typename NumberTraits::ToInteger<B>::Type(b)); |
18 | throwIfDivisionLeadsToFPE(typename NumberTraits::ToInteger<B>::Type(b), typename NumberTraits::ToInteger<A>::Type(a)); |
19 | return std::lcm( |
20 | typename NumberTraits::ToInteger<Result>::Type(a), |
21 | typename NumberTraits::ToInteger<Result>::Type(b)); |
22 | } |
23 | |
24 | #if USE_EMBEDDED_COMPILER |
25 | static constexpr bool compilable = false; /// exceptions (and a non-trivial algorithm) |
26 | #endif |
27 | }; |
28 | |
29 | struct NameLCM { static constexpr auto name = "lcm"; }; |
30 | using FunctionLCM = FunctionBinaryArithmetic<LCMImpl, NameLCM, false>; |
31 | |
32 | void registerFunctionLCM(FunctionFactory & factory) |
33 | { |
34 | factory.registerFunction<FunctionLCM>(); |
35 | } |
36 | |
37 | } |
38 |