Proposal: Make gcd total

Ross Paterson ross at
Sun May 29 12:54:17 CEST 2011

On 29 May 2011 01:21, wren ng thornton wrote:
>On 5/28/11 8:38 AM, Daniel Fischer wrote:
>> (By the way, non-negative, like the current positive, is not entirely true,
>> for bounded signed integer types [with twos' complement representation],
>> gcd minBound minBound = gcd minBound 0 = minBound<  0,
>> should that special case be mentioned or should we ignore it like we
>> currently do?)
> That's a sticky issue, but one that needs to be documented. Given that
> the result is always positive with the exception of gcd 0 0, gcd
> minBound minBound, gcd minBound 0, and gcd 0 minBound, I think these
> corner cases should be specifically enumerated.

There is a difference: gcd 0 0 follows from a general rule, but the
minBound ones are the sort of corner wierdness we get for using
fixed-size types.  (That is, the former should be mentioned as a
non-obvious consequence, the latter as an exception/bug.)  Incidentally,
gcd (minBound::Int) n currently gives negative results for quite a few
values of n.

More information about the Libraries mailing list