2018-11-26 16:20:40 +00:00
|
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include <Functions/FunctionBinaryArithmetic.h>
|
2021-01-24 18:28:12 +00:00
|
|
|
#include <Functions/GCDLCMImpl.h>
|
2019-07-15 14:45:56 +00:00
|
|
|
|
2021-05-08 18:19:45 +00:00
|
|
|
#include <boost/integer/common_factor.hpp>
|
2021-05-07 00:00:26 +00:00
|
|
|
|
2018-11-26 16:20:40 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2020-08-19 11:52:17 +00:00
|
|
|
|
2020-09-07 18:00:37 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2021-01-24 18:28:12 +00:00
|
|
|
struct NameGCD { static constexpr auto name = "gcd"; };
|
|
|
|
|
2018-11-26 16:20:40 +00:00
|
|
|
template <typename A, typename B>
|
2021-01-24 18:28:12 +00:00
|
|
|
struct GCDImpl : public GCDLCMImpl<A, B, GCDImpl<A, B>, NameGCD>
|
2018-11-26 16:20:40 +00:00
|
|
|
{
|
2021-01-24 18:28:12 +00:00
|
|
|
using ResultType = typename GCDLCMImpl<A, B, GCDImpl, NameGCD>::ResultType;
|
2018-11-26 16:20:40 +00:00
|
|
|
|
2021-01-24 18:28:12 +00:00
|
|
|
static ResultType applyImpl(A a, B b)
|
2018-11-26 16:20:40 +00:00
|
|
|
{
|
2021-01-24 18:28:12 +00:00
|
|
|
using Int = typename NumberTraits::ToInteger<ResultType>::Type;
|
2022-05-30 03:36:26 +00:00
|
|
|
return boost::integer::gcd(Int(a), Int(b)); // NOLINT(clang-analyzer-core.UndefinedBinaryOperatorResult)
|
2018-11-26 16:20:40 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-01-30 04:57:14 +00:00
|
|
|
using FunctionGCD = BinaryArithmeticOverloadResolver<GCDImpl, NameGCD, false, false>;
|
2018-11-26 16:20:40 +00:00
|
|
|
|
2020-09-07 18:00:37 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 16:20:40 +00:00
|
|
|
void registerFunctionGCD(FunctionFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionGCD>();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|