Re: Greatest Common Divisor
Vik Fearing <vik.fearing@2ndquadrant.com>
From: Vik Fearing <vik.fearing@2ndquadrant.com>
To: Dean Rasheed <dean.a.rasheed@gmail.com>
Cc: Fabien COELHO <coelho@cri.ensmp.fr>, Tom Lane <tgl@sss.pgh.pa.us>,
Stephen Frost <sfrost@snowman.net>, Chapman Flack <chap@anastigmatix.net>,
PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2020-01-04T21:31:43Z
Lists: pgsql-hackers
Attachments
- gcd.0007.patch (text/x-patch) patch
On 04/01/2020 20:08, Dean Rasheed wrote: > On Sat, 4 Jan 2020 at 17:55, Vik Fearing <vik.fearing@2ndquadrant.com> wrote: >> On 04/01/2020 10:37, Dean Rasheed wrote: >>> BTW, there is actually no need to restrict the inputs to integral >>> values because GCD is something that has a perfectly natural extension >>> to floating point inputs (see for example [1]). Moreover, since we >>> already have a mod(numeric, numeric) that works for arbitrary inputs, >>> Euclid's algorithm just works. >>> [...] >>> If it were more work to support non-integer inputs, I'd say that it's >>> not worth the effort, but since it's actually less work to just allow >>> it, then why not? >> >> Okay, I allow that now, but I've still left it for lcm. I can't find >> anything anywhere that defines lcm for floating point (I do find it for >> fractions) and the result of abs(a*b)/gcd(a,b) certainly doesn't match >> "lowest" in the examples I tried. >> > Here's another article on the subject: > https://www.math-only-math.com/hcf-and-lcm-of-decimals.html Yeah, my eyes weren't aligning the decimal points properly. Attached version frees up lcm to work on non-integrals. Thanks for your input! -- Vik Fearing
Commits
-
Add functions gcd() and lcm() for integer and numeric types.
- 13661ddd7eae 13.0 landed