]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Work around lgamma(NaN) bug on AIX.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 23 Feb 2026 20:30:44 +0000 (15:30 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 23 Feb 2026 20:30:50 +0000 (15:30 -0500)
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

index b5a7c57e53aa58a3bed26597d0689695ce7c51e9..641e7de21a0dad61929510f4ad46d350cd51501e 100644 (file)
@@ -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