Re: compiling newlib
Keith Packard via Newlib <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <[email protected]> |
Paul Zimmermann <[email protected]> writes: > thank you Jeff for your answer. > > In return I found I believe an issue with newlib's tgammaf function, for > input -0, where it gives +inf instead of -inf: Yeah, it's easy to fix the underlying __ieee754_lgamma functions to adjust the sign of the return: There's a bit of a mess with the gamma functions. There are _r versions of these functions that pass through the sign return pointer instead of applying it locally as they should. That reduces the set of gamma functions as follows: Reentrant functions: double float __ieee754_lgamma_r __ieee754_lgammaf_r __ieee754_gamma __ieee754_gammaf lgamma_r lgammaf_r tgamma tgammaf gamma/gammaf should be alternate names for tgamma/tgammaf, and would thus be re-entrant. Non-reentrant functions: __ieee754_lgamma __ieee754_lgammaf lgamma lgammaf -- -keith
0001-libm-Fix-sign-value-returned-from-__ieee754_lgamma-_.patch
(text/x-diff, 1.5 KB)
From 0cba5165a7f6cd69aca95bf82a9f1437bfa144dc Mon Sep 17 00:00:00 2001 From: Keith Packard <[email protected]> Date: Tue, 25 Aug 2020 09:32:35 -0700 Subject: [PATCH] libm: Fix sign value returned from __ieee754_lgamma*_r(-0) The sign of the INFINITY returned from these cases needs to match the sign of the zero. Signed-off-by: Keith Packard <[email protected]> --- newlib/libm/math/er_lgamma.c | 6 +++++- newlib/libm/math/erf_lgamma.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/newlib/libm/math/er_lgamma.c b/newlib/libm/math/er_lgamma.c index 386a8a73b..36408382f 100644 --- a/newlib/libm/math/er_lgamma.c +++ b/newlib/libm/math/er_lgamma.c @@ -225,7 +225,11 @@ static double zero= 0.00000000000000000000e+00; *signgamp = 1; ix = hx&0x7fffffff; if(ix>=0x7ff00000) return x*x; - if((ix|lx)==0) return one/zero; + if((ix|lx)==0) { + if(hx<0) + *signgamp = -1; + return one/zero; + } if(ix<0x3b900000) { /* |x|<2**-70, return -log(|x|) */ if(hx<0) { *signgamp = -1; diff --git a/newlib/libm/math/erf_lgamma.c b/newlib/libm/math/erf_lgamma.c index 3c6ba02af..a45423949 100644 --- a/newlib/libm/math/erf_lgamma.c +++ b/newlib/libm/math/erf_lgamma.c @@ -160,7 +160,11 @@ static float zero= 0.0000000000e+00; *signgamp = 1; ix = hx&0x7fffffff; if(ix>=0x7f800000) return x*x; - if(ix==0) return one/zero; + if(ix==0) { + if(hx<0) + *signgamp = -1; + return one/zero; + } if(ix<0x1c800000) { /* |x|<2**-70, return -log(|x|) */ if(hx<0) { *signgamp = -1; -- 2.28.0
signature.asc
(application/pgp-signature, 832 B)
-----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEw4O3eCVWE9/bQJ2R2yIaaQAAABEFAl9FRJIACgkQ2yIaaQAA ABFQ/Q/5AdcY2OOL8AOsX+fk4k8mYthS/+TjfiJzL5MbtRRmWu82VI1EfbkFG7cz SiYnZDRPgVDcyFjiloYg483nU3faa+cpblYaX05pvswyua7N1gceugHB122z/bzb 66kNdWWBgJBY92ei38GhwTVI8HXUUf+wTjNqgCE5vTa9vfvqvg3ZoQJd8sW8mBhA IyCb2jxZ/QtjyTS0n/bNR5dvW3DB8z0R24l4tgj4zXQfg+Hq1vMadxNTrVM7aq86 Zc2iL+9MJmADSCpL2S517SisNDLRATun1IbW7gTa6i+kqkFtNpZ9ltkHnePZaTxa yuJXlCTX/jzNjtiO/h0g4DVzWruexR/Y2bbTBs1hkNjv0zN19m9xaoiNgysKtg2N YMC78uuQvM/1/SVIsuFFzUYnr/kK9RZvx/aIScwKJpE2ZvZcsijeaVVBAbbFtQd2 i94Eteu0H130kmm5fvWLFUwCJeU6X/G2M06Y0g62Xq/V6012ExHhfQpJezhtknmp imwUCkuidIlI0+bRXJcZd0Y7+z98zJVm36SgIDZPMlSTqALmZEG4DWhhdiRSUK4+ juMAiEBL/dn8zDQeruXkCpfrHG/Lv/VrV2Jgvc6mUhrRQzGIgXB2LBn6powrjndH dfJsK1y5/3HxAwiPspGszEk/690WvXhQhPJgtatduGbP8RI8+Fc= =Rrgm -----END PGP SIGNATURE-----