[numeric.ops.gcd]

# 26 Algorithms library [[algorithms]](./#algorithms)

## 26.10 Generalized numeric operations [[numeric.ops]](numeric.ops#gcd)

### 26.10.14 Greatest common divisor [numeric.ops.gcd]

[ð](#lib:gcd)

`template<class M, class N>
  constexpr common_type_t<M, N> gcd(M m, N n);
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13274)

*Mandates*: M and N both are integer types other thancv bool[.](#1.sentence-1)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13279)

*Preconditions*: |m| and |n| are representable as a value of common_type_t<M, N>[.](#2.sentence-1)

[*Note [1](#note-1)*:

These requirements ensure, for example,
that gcd(m, m)=|m| is representable as a value of type M[.](#2.sentence-2)

â *end note*]

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13290)

*Returns*: Zero when m and n are both zero[.](#3.sentence-1)

Otherwise,
returns the greatest common divisor of |m| and |n|[.](#3.sentence-2)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13295)

*Throws*: Nothing[.](#4.sentence-1)
