Greatest Common Divisor

Vik Fearing <vik.fearing@2ndquadrant.com>

From: Vik Fearing <vik.fearing@2ndquadrant.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2019-12-28T16:58:52Z
Lists: pgsql-hackers

Attachments

I recently came across the need for a gcd function (actually I needed
lcm) and was surprised that we didn't have one.


So here one is, using the basic Euclidean algorithm.  I made one for
smallint, integer, and bigint.

-- 

Vik Fearing                                          +33 6 46 75 15 36
http://2ndQuadrant.fr     PostgreSQL : Expertise, Formation et Support

Commits

  1. Add functions gcd() and lcm() for integer and numeric types.