We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 42d0183 commit 21689e0Copy full SHA for 21689e0
include/boost/int128/numeric.hpp
@@ -251,6 +251,40 @@ constexpr TargetType saturate_cast(const int128_t value) noexcept
251
}
252
253
254
+namespace detail {
255
+
256
+constexpr std::uint64_t gcd64(std::uint64_t x, std::uint64_t y) noexcept
257
+{
258
+ if (x == 0)
259
+ {
260
+ return y;
261
+ }
262
+ if (y == 0)
263
264
+ return x;
265
266
267
+ const auto s {impl::countr_impl(x | y)};
268
+ x >>= impl::countr_impl(x);
269
270
+ do
271
272
+ y >>= impl::countr_impl(y);
273
+ if (x > y)
274
275
+ const auto temp {x};
276
+ x = y;
277
+ y = temp;
278
279
280
+ y -= x;
281
+ } while (y);
282
283
+ return x << s;
284
+}
285
286
+} // namespace detail
287
288
constexpr uint128_t gcd(uint128_t a, uint128_t b) noexcept
289
{
290
// Base case
0 commit comments