ClickHouse/dbms/src/Functions/lcm.cpp
alexey-milovidov e00ce0bb57
Every function in its own file, part 7 (#3666)
* Every function in its own file, part 7 [#CLICKHOUSE-2]

* Every function in its own file, part 7 [#CLICKHOUSE-2]

* Every function in its own file, part 7 [#CLICKHOUSE-2]

* Every function in its own file, part 7 [#CLICKHOUSE-2]

* Every function in its own file, part 7 [#CLICKHOUSE-2]

* Fixed build #3666
2018-11-26 19:20:40 +03:00

37 lines
1.1 KiB
C++

#include <Functions/FunctionFactory.h>
#include <Functions/FunctionBinaryArithmetic.h>
#include <boost/integer/common_factor.hpp>
namespace DB
{
template <typename A, typename B>
struct LCMImpl
{
using ResultType = typename NumberTraits::ResultOfAdditionMultiplication<A, B>::Type;
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));
return boost::integer::lcm(
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>();
}
}