Return type of gcd in C++

Torbjörn Granlund tg at gmplib.org
Tue Jun 17 14:57:48 UTC 2014


Marc Glisse <marc.glisse at inria.fr> writes:

  the C++ standard is likely to add a gcd function for builtin integer
  types, and that reminds me that gmpxx still doesn't provide such a
  function. As long as both arguments are mpz_class (or expressions),
  things are relatively clear. But what about gcd(mpz_class,short), what
  should it return? It could return an expression that evaluates to
  mpz_class, but we could also make it return unsigned short (or
  unsigned long so they all return the same thing). On the other hand,
  that might be a bit confusing. Since mpz_class%short returns an mpz
  expression, I think I will do the same for gcd, to be consistent, but
  if people have opinions on this, I am listening.

Keep in mind that (a,0) = a from the definition of gcd.  This suggests
that the result of gcd(mpz,short) need an mpz for the result.

Torbjörn
Please encrypt, key id 0xC8601622


More information about the gmp-discuss mailing list