libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
jmmcg::LIBJMMCG_VER_NAMESPACE::binary Namespace Reference

Functions

template<class V >
constexpr V gcd (const V x, const V y) noexcept(true) __attribute__((const))
 Binary Greatest Common Divisor Algorithm. More...
 

Function Documentation

◆ gcd()

template<class V >
constexpr V jmmcg::LIBJMMCG_VER_NAMESPACE::binary::gcd ( const V  x,
const V  y 
) const
inlineconstexprnoexcept

Binary Greatest Common Divisor Algorithm.

This method is best suited to integers.

A one-liner for fun! (But it's slower, as it's got an extra jump...) for (u=x,v=y;v;r=uv,u=v,v=r);

Thanks to Knuth, et al for Euclid's Algorithm and the Binary GCD algorithm. See his book "Seminumerical Algorithms. Vol 2", pg 320.

Parameters
xA value greater that zero.
yA value greater that zero.
See also
euclid::gcd()

Definition at line 78 of file gcd.hpp.