1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

Add support for the error functions erf() and erfc().

Expose the standard error functions as SQL-callable functions. These
are expected to be useful to people working with normal distributions,
and we use them here to test the distribution from random_normal().

Since these functions are defined in the POSIX and C99 standards, they
should in theory be available on all supported platforms. If that
turns out not to be the case, more work will be needed.

On all platforms tested so far, using extra_float_digits = -1 in the
regression tests is sufficient to allow for variations between
implementations. However, past experience has shown that there are
almost certainly going to be additional unexpected portability issues,
so these tests may well need further adjustments, based on the
buildfarm results.

Dean Rasheed, reviewed by Nathan Bossart and Thomas Munro.

Discussion: https://postgr.es/m/CAEZATCXv5fi7+Vu-POiyai+ucF95+YMcCMafxV+eZuN1B-=MkQ@mail.gmail.com
This commit is contained in:
Dean Rasheed
2023-03-14 09:17:36 +00:00
parent 3a465cc678
commit d5d574146d
8 changed files with 205 additions and 1 deletions

View File

@ -2742,6 +2742,53 @@ datanh(PG_FUNCTION_ARGS)
}
/* ========== ERROR FUNCTIONS ========== */
/*
* derf - returns the error function: erf(arg1)
*/
Datum
derf(PG_FUNCTION_ARGS)
{
float8 arg1 = PG_GETARG_FLOAT8(0);
float8 result;
/*
* For erf, we don't need an errno check because it never overflows.
*/
result = erf(arg1);
if (unlikely(isinf(result)))
float_overflow_error();
PG_RETURN_FLOAT8(result);
}
/*
* derfc - returns the complementary error function: 1 - erf(arg1)
*/
Datum
derfc(PG_FUNCTION_ARGS)
{
float8 arg1 = PG_GETARG_FLOAT8(0);
float8 result;
/*
* For erfc, we don't need an errno check because it never overflows.
*/
result = erfc(arg1);
if (unlikely(isinf(result)))
float_overflow_error();
PG_RETURN_FLOAT8(result);
}
/* ========== RANDOM FUNCTIONS ========== */
/*
* initialize_drandom_seed - initialize drandom_seed if not yet done
*/