Calculator Step 6

- Main Page
- Classes
- Files

- File List
- File Members

Functions
gcd.hpp File Reference

Go to the source code of this file.

## Functions
template<class T >
T | gcd (T n, T m)

## Function Documentation

template<class T >

T gcd | ( | T | n,
|  | T | m
| ) |  |

Compute greatest-common-denominator.

Parameters

  n |
  m |

Definition at line 8 of file gcd.hpp.

Referenced by rational< T >::reduce().

9 {
10 static T zero{};
11 if (n < zero)
12 n = -n;
13 while (m != zero) {
14 int tmp(n % m);
15 n = m;
16 m = tmp;
17 }
18 return n;
19 }