The Ruby test suite started to fail with following error: ~~~ 1) Math.lgamma returns [Infinity, 1] when passed -1 FAILED Expected [Infinity, -1] == [Infinity, 1] to be truthy but was false ~~~ From the list of modified dependencies, the glibc-2.42.9000-8.fc44 is my best bet. The changelog mentions: "math: Use lgamma from CORE-MATH" which might be related. Reproducible: Always
The gamma function has a pole at -1, so the sign is mathematically undefined. I don't see POSIX requirement for any specific result here, either. https://en.wikipedia.org/wiki/Gamma_function
The following is failing: ====================================================================== #include <math.h> #include <stdlib.h> #include <stdio.h> #define MY_ASSERT(expr) \ do { \ if (!(expr)) { \ fprintf(stderr, "At line [%d] expr \"" #expr "\" failed\n", __LINE__); \ abort(); \ } \ } while(0) int main(void) { int sign = 0; double ret = lgamma_r(-1, &sign); MY_ASSERT(ret == HUGE_VAL); MY_ASSERT(sign == 1); } ====================================================================== With glibc glibc-2.42.9000-8.fc44.x86_64: ====================================================================== At line [17] expr "sign == 1" failed Aborted ====================================================================== POSIX.1-2024 explicitly says (e.g. https://pubs.opengroup.org/onlinepubs/9799919799/functions/lgamma.html) If \(x\) is a non-positive integer, a pole error shall occur and lgamma(), lgammaf(), and lgammal() shall return +HUGE_VAL, +HUGE_VALF, and +HUGE_VALL, respectively. So lgamma(-1) shall return +HUGE_VAL , so the sign of the return value shall be positive.
The return value is HUGE_VAL according to the test, so it is positive. POSIX does not say anything about the sign.
Ah... actually If \(x\) is NaN, -Inf, or a negative integer, the value of signgam is unspecified. So looks like this should be fixed in ruby side.
ref: https://github.com/ruby/ruby/blob/cdcb490d2bceb4ff8d6fce349047a2b722e6ae87/math.c#L1103
Filed: https://bugs.ruby-lang.org/issues/21666
Thanks!