Re: Greatest Common Divisor - Mailing list pgsql-hackers

From Fabien COELHO
Subject Re: Greatest Common Divisor
Date
Msg-id alpine.DEB.2.21.2001032010470.12030@pseudo
Whole thread Raw
In response to Re: Greatest Common Divisor  (Vik Fearing <vik.fearing@2ndquadrant.com>)
Responses Re: Greatest Common Divisor  (Vik Fearing <vik.fearing@2ndquadrant.com>)
Re: Greatest Common Divisor  (Vik Fearing <vik.fearing@2ndquadrant.com>)
List pgsql-hackers
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?

> gcd() is now strictly positive, so INT_MIN is no longer a valid result.

Ok.

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

-- 
Fabien.



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: Greatest Common Divisor
Next
From: Robbie Harwood
Date:
Subject: Re: weird libpq GSSAPI comment