Re: Greatest Common Divisor - Mailing list pgsql-hackers

From Fabien COELHO
Subject Re: Greatest Common Divisor
Date
Msg-id alpine.DEB.2.21.2001040925230.31333@pseudo
Whole thread Raw
In response to Re: Greatest Common Divisor  (Vik Fearing <vik.fearing@2ndquadrant.com>)
Responses Re: Greatest Common Divisor
List pgsql-hackers
Bonjour Vik,

>> The point of swapping is to a void possibly expensive modulo, but this
>> should be done on absolute values, otherwise it may not achieve its
>> purpose as stated by the comment?
>
> Ah, true.  How widespread are these architectures that need this special
> treatment?  Is it really worth handling?

Dunno. AFAICR it was with sparc architectures 25 years ago.

Also I do not like much relying on the subtleties of C99 % wrt negative 
numbers to have the algorithm work, I'd be much at ease to deal with sign 
and special values at the beginning of the function and proceed with 
positive numbers afterwards.

>> I'm unsure about gcd(INT_MIN, 0) should error. Possibly 0 would be nicer?
>
>
> What justification for that do you have?

ISTM that the current implementation has:

   \forall int4 n, n \neq MIN_INT4, \gcd(n, 0) = 0 ?

In which case applying the same rule for min int seems ok.

-- 
Fabien Coelho - CRI, MINES ParisTech

pgsql-hackers by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: pgsql: Add basic TAP tests for psql's tab-completion logic.
Next
From: Fabien COELHO
Date:
Subject: Re: Greatest Common Divisor