Re: Greatest Common Divisor

Fabien COELHO <[email protected]>
Newsgroups gmane.comp.db.postgresql.devel.general
Message-ID <alpine.DEB.2.21.2001040925230.31333@pseudo>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.