Function gcd


#include "breeze/mathematics/gcd.hpp"

template <typename T>
constexpr T gcd(T a, T b)


Returns the greatest common divisor of two integers.

If T is not an integral type the program is ill-formed. If the greatest common divisor of |a| and |b| is not representable as a value of type T, the behavior is undefined.

If both a and b are zero, returns zero. Otherwise it returns the greatest common divisor of |a| and |b|.
The intent, for both this template and breeze::lcm(), was to follow the standard specification (the initial Breeze versions followed the C++ Library Fundamental TS v2, and I meant to update them to C++17 when C++17 would be out). But I soon realized that allowing two different types for the two arguments, and using common_type for the result, made everything very hard to reason about (can you tell what the common_type of two arbitrary integral types is?). So I decided to stick to what I consider a saner specification.

Mentioned in


Line 49 in breeze/mathematics/gcd.hpp.