aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Functions/gcd.cpp
diff options
context:
space:
mode:
authorvitalyisaev <vitalyisaev@ydb.tech>2023-11-14 09:58:56 +0300
committervitalyisaev <vitalyisaev@ydb.tech>2023-11-14 10:20:20 +0300
commitc2b2dfd9827a400a8495e172a56343462e3ceb82 (patch)
treecd4e4f597d01bede4c82dffeb2d780d0a9046bd0 /contrib/clickhouse/src/Functions/gcd.cpp
parentd4ae8f119e67808cb0cf776ba6e0cf95296f2df7 (diff)
downloadydb-c2b2dfd9827a400a8495e172a56343462e3ceb82.tar.gz
YQ Connector: move tests from yql to ydb (OSS)
Перенос папки с тестами на Коннектор из папки yql в папку ydb (синхронизируется с github).
Diffstat (limited to 'contrib/clickhouse/src/Functions/gcd.cpp')
-rw-r--r--contrib/clickhouse/src/Functions/gcd.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/contrib/clickhouse/src/Functions/gcd.cpp b/contrib/clickhouse/src/Functions/gcd.cpp
new file mode 100644
index 0000000000..0cd017bb0b
--- /dev/null
+++ b/contrib/clickhouse/src/Functions/gcd.cpp
@@ -0,0 +1,37 @@
+#include <Functions/FunctionFactory.h>
+#include <Functions/FunctionBinaryArithmetic.h>
+#include <Functions/GCDLCMImpl.h>
+
+#include <boost/integer/common_factor.hpp>
+
+
+namespace DB
+{
+
+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;
+ return boost::integer::gcd(Int(a), Int(b)); // NOLINT(clang-analyzer-core.UndefinedBinaryOperatorResult)
+ }
+};
+
+using FunctionGCD = BinaryArithmeticOverloadResolver<GCDImpl, NameGCD, false, false>;
+
+}
+
+REGISTER_FUNCTION(GCD)
+{
+ factory.registerFunction<FunctionGCD>();
+}
+
+}