Add error functions: erf() and erfc()
Dean Rasheed <dean.a.rasheed@gmail.com>
From: Dean Rasheed <dean.a.rasheed@gmail.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2023-02-27T12:54:35Z
Lists: pgsql-hackers
Attachments
Now that we have random_normal(), it seems like it would be useful to add the error functions erf() and erfc(), which I think are potentially useful to the people who will find random_normal() useful, and possibly others. An immediate use for erf() is that it allows us to do a Kolmogorov-Smirnov test for random_normal(), similar to the one for random(). Both of these functions are defined in POSIX and C99, so in theory they should be available on all platforms. If that turns out not to be the case, then there's a commonly used implementation (e.g., see [1]), which we could include. I played around with that (replacing the direct bit manipulation stuff with frexp()/ldexp(), see pg_erf.c attached), and it appeared to be accurate to +/-1 ULP across the full range of inputs. Hopefully we won't need that though. I tested this on a couple of different platforms and found I needed to reduce extra_float_digits to -1 to get the regression tests to pass consistently, due to rounding errors. It wouldn't surprise me if that needs to be reduced further, though perhaps it's not necessary to have so many tests (I included one test value from each branch, while testing the hand-rolled implementation). Regards, Dean [1] https://github.com/lsds/musl/blob/master/src/math/erf.c
Commits
-
Add support for the error functions erf() and erfc().
- d5d574146d71 16.0 landed