ClickHouse/src/Functions/gcd.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
843 B
C++
Raw Normal View History

#include <Functions/FunctionFactory.h>
#include <Functions/FunctionBinaryArithmetic.h>
#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
namespace DB
{
2020-09-07 18:00:37 +00:00
namespace
{
struct NameGCD { static constexpr auto name = "gcd"; };
template <typename A, typename B>
struct GCDImpl : public GCDLCMImpl<A, B, GCDImpl<A, B>, NameGCD>
{
using ResultType = typename GCDLCMImpl<A, B, GCDImpl, NameGCD>::ResultType;
static ResultType applyImpl(A a, B b)
{
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)
}
};
using FunctionGCD = BinaryArithmeticOverloadResolver<GCDImpl, NameGCD, false, false>;
2020-09-07 18:00:37 +00:00
}
REGISTER_FUNCTION(GCD)
{
factory.registerFunction<FunctionGCD>();
}
}