2018-11-26 16:20:40 +00:00
|
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include <Functions/FunctionBinaryArithmetic.h>
|
2019-07-15 14:45:56 +00:00
|
|
|
#include <numeric>
|
|
|
|
|
2018-11-26 16:20:40 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
template <typename A, typename B>
|
|
|
|
struct LCMImpl
|
|
|
|
{
|
|
|
|
using ResultType = typename NumberTraits::ResultOfAdditionMultiplication<A, B>::Type;
|
2020-02-14 07:11:37 +00:00
|
|
|
static const constexpr bool allow_fixed_string = false;
|
|
|
|
|
2018-11-26 16:20:40 +00:00
|
|
|
|
|
|
|
template <typename Result = ResultType>
|
|
|
|
static inline Result apply(A a, B b)
|
|
|
|
{
|
|
|
|
throwIfDivisionLeadsToFPE(typename NumberTraits::ToInteger<A>::Type(a), typename NumberTraits::ToInteger<B>::Type(b));
|
|
|
|
throwIfDivisionLeadsToFPE(typename NumberTraits::ToInteger<B>::Type(b), typename NumberTraits::ToInteger<A>::Type(a));
|
2019-07-15 14:45:56 +00:00
|
|
|
return std::lcm(
|
2018-11-26 16:20:40 +00:00
|
|
|
typename NumberTraits::ToInteger<Result>::Type(a),
|
|
|
|
typename NumberTraits::ToInteger<Result>::Type(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
#if USE_EMBEDDED_COMPILER
|
|
|
|
static constexpr bool compilable = false; /// exceptions (and a non-trivial algorithm)
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NameLCM { static constexpr auto name = "lcm"; };
|
|
|
|
using FunctionLCM = FunctionBinaryArithmetic<LCMImpl, NameLCM, false>;
|
|
|
|
|
|
|
|
void registerFunctionLCM(FunctionFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionLCM>();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|