Calculator  Step 6
Functions
gcd.hpp File Reference

Go to the source code of this file.

Functions

template<class T >
gcd (T n, T m)
 

Function Documentation

template<class T >
T gcd ( n,
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 }