From: Tom Lane Date: Mon, 23 Feb 2026 20:30:44 +0000 (-0500) Subject: Work around lgamma(NaN) bug on AIX. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d743545d8471dbb0016313885392211f58ef2b1c;p=thirdparty%2Fpostgresql.git 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 --- 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