# gcd 0 0

**George Russell
**
ger@tzi.de

*Tue, 11 Dec 2001 18:18:31 +0100*

S.D.Mechveliani wrote
>* Does the Report specify that gcd 0 0 is not defined?
*Yes. The Report definition says
gcd :: (Integral a) => a -> a -> a
gcd 0 0 = error "Prelude.gcd: gcd 0 0 is undefined"
gcd x y = gcd' (abs x) (abs y)
where gcd' x 0 = x
gcd' x y = gcd' y (x `rem` y)
On reflection, this is quite right. a divides b <=> there is an
integer n with na = b. Thus any integer divides 0, and so the
"greatest common divisor" would have to be the greatest integer,
which is nonsense.
Of course if you adopt Stephan Kahrs definition of "greatest", taken with respect
to the partial order a<=b <=> a divides b, then gcd 0 0 = 0, because 0 is indeed
the greatest integer in this ordering. Mathematically this makes sense, but it's not necessarily
what people expect.