Re: Greatest Common Divisor - Mailing list pgsql-hackers

From Vik Fearing
Subject Re: Greatest Common Divisor
Date
Msg-id 5bf72c6b-1290-2ba0-770b-8a13e899fd98@2ndquadrant.com
Whole thread Raw
In response to Re: Greatest Common Divisor  (Fabien COELHO <coelho@cri.ensmp.fr>)
Responses Re: Greatest Common Divisor  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Greatest Common Divisor  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Greatest Common Divisor  (Fabien COELHO <coelho@cri.ensmp.fr>)
List pgsql-hackers
On 03/01/2020 20:14, Fabien COELHO wrote:
>
> Bonsoir Vik,
>
>  +int4gcd_internal(int32 arg1, int32 arg2)
>  +{
>  +       int32   swap;
>  +
>  +       /*
>  +        * Put the greater value in arg1.
>  +        * This would happen automatically in the loop below, but
> avoids  an
>  +        * expensive modulo simulation on some architectures.
>  +        */
>  +       if (arg1 < arg2)
>  +       {
>  +               swap = arg1;
>  +               arg1 = arg2;
>  +               arg2 = swap;
>  +       }
>
>
> 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?


> I'm unsure about gcd(INT_MIN, 0) should error. Possibly 0 would be nicer?


What justification for that do you have?

-- 

Vik Fearing




pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Greatest Common Divisor
Next
From: Tom Lane
Date:
Subject: Re: Greatest Common Divisor