1#include <Functions/FunctionFactory.h>
2#include <Functions/FunctionBinaryArithmetic.h>
3#include <numeric>
4
5
6namespace DB
7{
8
9template <typename A, typename B>
10struct 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
29struct NameLCM { static constexpr auto name = "lcm"; };
30using FunctionLCM = FunctionBinaryArithmetic<LCMImpl, NameLCM, false>;
31
32void registerFunctionLCM(FunctionFactory & factory)
33{
34 factory.registerFunction<FunctionLCM>();
35}
36
37}
38