Re: Greatest Common Divisor
Vik Fearing <vik.fearing@2ndquadrant.com>
From: Vik Fearing <vik.fearing@2ndquadrant.com>
To: Fabien COELHO <coelho@cri.ensmp.fr>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, Stephen Frost <sfrost@snowman.net>,
Dean Rasheed <dean.a.rasheed@gmail.com>,
Chapman Flack <chap@anastigmatix.net>,
PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2020-01-04T02:32:34Z
Lists: pgsql-hackers
Attachments
- gcd.0005.patch (text/x-patch) patch
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?
Here is an updated patch fixing that.
--
Vik Fearing
Commits
-
Add functions gcd() and lcm() for integer and numeric types.
- 13661ddd7eae 13.0 landed