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

Functions

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

Function Documentation

◆ gcd()

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

Euclid's Greatest Common Divisor Algorithm.

This is best used for the general case of finding the gcd. The Binary method may be faster than Euclid's Algorithm.

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
binary::gcd()

Definition at line 45 of file gcd.hpp.