From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from elaine.keithp.com (home.keithp.com [63.227.221.253]) by sourceware.org (Postfix) with ESMTPS id 8D5883857C41 for ; Tue, 25 Aug 2020 17:04:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8D5883857C41 Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 61F2C3F2D5DB; Tue, 25 Aug 2020 10:04:20 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id PtPFqenbl4LO; Tue, 25 Aug 2020 10:04:19 -0700 (PDT) Received: from keithp.com (koto.keithp.com [10.0.0.2]) by elaine.keithp.com (Postfix) with ESMTPSA id 312633F2D5D2; Tue, 25 Aug 2020 10:04:19 -0700 (PDT) Received: by keithp.com (Postfix, from userid 1000) id 0DF2E1582201; Tue, 25 Aug 2020 10:04:19 -0700 (PDT) From: "Keith Packard" To: Paul Zimmermann , Jeff Johnston Cc: newlib@sourceware.org Subject: Re: compiling newlib In-Reply-To: References: Date: Tue, 25 Aug 2020 10:04:18 -0700 Message-ID: <875z96fyi5.fsf@keithp.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Aug 2020 17:04:23 -0000 --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Paul Zimmermann 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: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-libm-Fix-sign-value-returned-from-__ieee754_lgamma-_.patch Content-Transfer-Encoding: quoted-printable From=200cba5165a7f6cd69aca95bf82a9f1437bfa144dc Mon Sep 17 00:00:00 2001 From: Keith Packard 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 =2D-- 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 =2D-- a/newlib/libm/math/er_lgamma.c +++ b/newlib/libm/math/er_lgamma.c @@ -225,7 +225,11 @@ static double zero=3D 0.00000000000000000000e+00; *signgamp =3D 1; ix =3D hx&0x7fffffff; if(ix>=3D0x7ff00000) return x*x; =2D if((ix|lx)=3D=3D0) return one/zero; + if((ix|lx)=3D=3D0) { + if(hx<0) + *signgamp =3D -1; + return one/zero; + } if(ix<0x3b900000) { /* |x|<2**-70, return -log(|x|) */ if(hx<0) { *signgamp =3D -1; diff --git a/newlib/libm/math/erf_lgamma.c b/newlib/libm/math/erf_lgamma.c index 3c6ba02af..a45423949 100644 =2D-- a/newlib/libm/math/erf_lgamma.c +++ b/newlib/libm/math/erf_lgamma.c @@ -160,7 +160,11 @@ static float zero=3D 0.0000000000e+00; *signgamp =3D 1; ix =3D hx&0x7fffffff; if(ix>=3D0x7f800000) return x*x; =2D if(ix=3D=3D0) return one/zero; + if(ix=3D=3D0) { + if(hx<0) + *signgamp =3D -1; + return one/zero; + } if(ix<0x1c800000) { /* |x|<2**-70, return -log(|x|) */ if(hx<0) { *signgamp =3D -1; =2D-=20 2.28.0 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable 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 =20=20=20=20=20=20=20=20 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=20=20=20=20=20=20=20=20 lgamma lgammaf =2D-=20 =2Dkeith --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----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----- --==-=-=--