Re: Fw: [PATCH 0/3] libm: Clean up gamma functions
C Howland via Newlib <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <CANk6obSzY7iS1r9fk77=Z=yGD0+JG0kYeqLUV9RxmGG+J4uk+w@mail.gmail.com> |
> ------------------------------ > *From:* Newlib <[email protected]> on behalf of Keith Packard > via Newlib <[email protected]> > *Sent:* Wednesday, August 26, 2020 1:03 PM > *To:* [email protected] <[email protected]> > *Subject:* [PATCH 0/3] libm: Clean up gamma functions > > EXTERNAL EMAIL - This email originated from outside of CACI. Do not click > any links or attachments unless you recognize and trust the sender. > > > > > > This series cleans up some API oddities and inaccuracies in > errno/exception reporting from the various gamma related functions. > With this series applied, newlib now matches the POSIX spec (and glibc) > for tgamma/lgamma functions. I've left the 'gamma' functions BSD > compatible (tgamma instead of lgamma) to avoid changing the API. > > [PATCH 1/3] libm: Fix sign value returned from __ieee754_lgamma*_r(-0) > > Following the C spec, gamma(-0) should be -INFINITY rather than > +INFINITY, so the *signgamp value in lgamma should be -1 > rather than +1 for this case. > What C spec? Neither C99 nor C11 say so that I see for lgamma(). POSIX makes the direct statement "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." 0, regardless of sign, falls under that. https://pubs.opengroup.org/onlinepubs/9699919799/functions/lgamma.html Additionally, the Linux lgamma man page, using GLIBC, says the same thing as quoted from POSIX (not word for word, but the identical result). (POSIX does require the +-0 +-INFINITY for tgamma(). Did these get crossed up?) Craig > > [PATCH 2/3] libm: Remove __ieee754_gamma_r variants > > Back in 2002, a patch changed the various gamma functions so > that the returned abs(gamma) instead of the ln of gamma. This > left the _r variants in place, with their extra parameter to > return the sign of the resulting value. This doesn't make any > sense to me and looks like it was just a mistake. I've changed > the __ieee754_gamma functions to apply the sign value locally > and eliminated the gamma_r versions as those are no longer useful. > > [PATCH 3/3] libm: Adjust errno/exception values for gamma/lgamma > > There's a pretty detailed discussion in the commit message > here, the short version is that tgamma and lgamma are > specified with different errno/exception behaviour for > one class of inputs (negative integers). >