pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Fabien COELHO <coelho@cri.ensmp.fr>
To: Vik Fearing <vik.fearing@2ndquadrant.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Stephen Frost <sfrost@snowman.net>
Cc: Dean Rasheed <dean.a.rasheed@gmail.com>
Cc: Chapman Flack <chap@anastigmatix.net>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: Greatest Common Divisor
Date: Fri, 3 Jan 2020 20:14:13 +0100 (CET)
Message-ID: <alpine.DEB.2.21.2001032010470.12030@pseudo> (raw)
In-Reply-To: <6855727c-3836-21cc-18f9-e79227b99079@2ndquadrant.com>
References: <adbd3e0b-e3f1-5bbc-21db-03caf1cef0f7@2ndquadrant.com>
	<alpine.DEB.2.21.1912281848540.24861@pseudo>
	<dbf86808-91fa-3262-f939-2ef3d38ec242@2ndquadrant.com>
	<alpine.DEB.2.21.1912290815520.889@pseudo>
	<5E08D947.9000902@anastigmatix.net>
	<alpine.DEB.2.21.1912291755510.14206@pseudo>
	<CAEZATCX9YgkWupVFcJ5ixkEJMyf2X5ZecN8K5r12oOB8mDHzWQ@mail.gmail.com>
	<20200102145712.GN3195@tamriel.snowman.net>
	<16242.1577977961@sss.pgh.pa.us>
	<6855727c-3836-21cc-18f9-e79227b99079@2ndquadrant.com>


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.





view thread (70+ messages)  latest in thread

Message-ID: <alpine.DEB.2.21.2001032010470.12030@pseudo>
Permalink:  ../alpine.DEB.2.21.2001032010470.12030@pseudo/
Also on:    postgresql.org/message-id/alpine.DEB.2.21.2001032010470.12030@pseudo

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: coelho@cri.ensmp.fr, vik.fearing@2ndquadrant.com, tgl@sss.pgh.pa.us, sfrost@snowman.net, dean.a.rasheed@gmail.com, chap@anastigmatix.net, pgsql-hackers@lists.postgresql.org
  Subject: Re: Greatest Common Divisor
  In-Reply-To: <alpine.DEB.2.21.2001032010470.12030@pseudo>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox