From d743545d8471dbb0016313885392211f58ef2b1c Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 23 Feb 2026 15:30:44 -0500 Subject: [PATCH] Work around lgamma(NaN) bug on AIX. lgamma(NaN) should produce NaN, but on older versions of AIX it reports an ERANGE error. While that's been fixed in the latest version of libm, it'll take awhile for the fix to propagate. This workaround is harmless even when the underlying bug does get fixed. Discussion: https://postgr.es/m/3603369.1771877682@sss.pgh.pa.us --- src/backend/utils/adt/float.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c index b5a7c57e53a..641e7de21a0 100644 --- a/src/backend/utils/adt/float.c +++ b/src/backend/utils/adt/float.c @@ -2852,6 +2852,12 @@ dlgamma(PG_FUNCTION_ARGS) float8 arg1 = PG_GETARG_FLOAT8(0); float8 result; + /* On some versions of AIX, lgamma(NaN) fails with ERANGE */ +#if defined(_AIX) + if (isnan(arg1)) + PG_RETURN_FLOAT8(arg1); +#endif + /* * Note: lgamma may not be thread-safe because it may write to a global * variable signgam, which may not be thread-local. However, this doesn't