Re: gamma() and lgamma() functions
Dean Rasheed <dean.a.rasheed@gmail.com>
From: Dean Rasheed <dean.a.rasheed@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Peter Eisentraut <peter@eisentraut.org>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2024-09-06T09:42:57Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Add support for gamma() and lgamma() functions.
- a3b6dfd41069 18.0 landed
Attachments
- v3-gamma-and-lgamma.patch (text/x-patch) patch v3
On Wed, 4 Sept 2024 at 19:21, Tom Lane <tgl@sss.pgh.pa.us> wrote: > > >> I'm not sure why you are doing the testing for special values (NaN etc.) > >> yourself when the C library function already does it. For example, if I > >> remove the isnan(arg1) check in your dlgamma(), then it still behaves > >> the same in all tests. > > > It's useful to do that so that we don't need to assume that every > > platform conforms to the POSIX standard, and because it simplifies the > > later overflow checks. This is consistent with the approach taken in > > other functions, such as dexp(), dsin(), dcos(), etc. > > dexp() and those other functions date from the late stone age, before > it was safe to assume that libm's behavior matched the POSIX specs. > Today I think we can assume that, at least till proven differently. > There's not necessarily anything wrong with what you've coded, but > I don't buy this argument for it. > OK, thinking about this some more, I think we should reserve overflow errors for genuine overflows, which I take to mean cases where the exact mathematical result should be finite, but is too large to be represented in a double. In particular, this means that zero and negative integer inputs are not genuine overflows, but should return NaN or +/-Inf, as described in the POSIX spec. Doing that, and assuming that tgamma() and lgamma() behave according to spec, leads to the attached, somewhat simpler patch. Regards, Dean