From nobody Tue Sep 07 08:00:24 2021 X-Original-To: freebsd-current@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id C60DC17B97E8 for ; Tue, 7 Sep 2021 08:00:27 +0000 (UTC) (envelope-from markm@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4H3d3v58zfz3k3b; Tue, 7 Sep 2021 08:00:27 +0000 (UTC) (envelope-from markm@FreeBSD.org) Received: from smtpclient.apple (unknown [IPv6:2a02:8011:300b:42:3945:6114:66c5:7d7c]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: markm) by smtp.freebsd.org (Postfix) with ESMTPSA id 141872BD0D; Tue, 7 Sep 2021 08:00:26 +0000 (UTC) (envelope-from markm@FreeBSD.org) Content-Type: multipart/signed; boundary="Apple-Mail=_4A7A40C0-32F8-4D72-82D1-26C88E567736"; protocol="application/pgp-signature"; micalg=pgp-sha512 List-Id: Discussions about the use of FreeBSD-current List-Archive: https://lists.freebsd.org/archives/freebsd-current List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-current@freebsd.org Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Subject: Re: BUG in libm's powf From: Mark Murray In-Reply-To: Date: Tue, 7 Sep 2021 09:00:24 +0100 Cc: Steve Kargl , freebsd-current@freebsd.org Message-Id: References: <20210906152836.GA86615@troutmask.apl.washington.edu> <01D81389-45D1-4278-8DC1-7995D34D0276@FreeBSD.org> <20210906175318.GA87474@troutmask.apl.washington.edu> <20210906180459.GA87487@troutmask.apl.washington.edu> To: Gordon Bergling X-Mailer: Apple Mail (2.3654.120.0.1.13) X-ThisMailContainsUnwantedMimeParts: N --Apple-Mail=_4A7A40C0-32F8-4D72-82D1-26C88E567736 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On 6 Sep 2021, at 21:22, Gordon Bergling wrote: >=20 > could you turn to test program into an AFT test to prevent further = regressions? Certainly! M >=20 > =E2=80=94Gordon >=20 >> Am 06.09.2021 um 20:04 schrieb Steve Kargl = : >>=20 >> No, thank you for the quick response. >>=20 >> Of course, a one character diff might be easier to review. :-) >>=20 >> -- >> steve >>=20 >> On Mon, Sep 06, 2021 at 06:55:07PM +0100, Mark Murray wrote: >>> Thanks! >>>=20 >>> And it's committed! >>>=20 >>> M >>>=20 >>>> On 6 Sep 2021, at 18:53, Steve Kargl = wrote: >>>>=20 >>>> Fine with me. I don't have a phabricator account and >>>> bugzilla reports seems to get lost in the ether. >>>>=20 >>>> -- >>>> steve >>>>=20 >>>> On Mon, Sep 06, 2021 at 06:45:11PM +0100, Mark Murray wrote: >>>>> Hi >>>>>=20 >>>>> I've opened a Phab ticket for this. I hope that's OK? >>>>>=20 >>>>> https://reviews.freebsd.org/D31865 >>>>>=20 >>>>> M >>>>>=20 >>>>>> On 6 Sep 2021, at 16:28, Steve Kargl = wrote: >>>>>>=20 >>>>>> Paul Zimmermann has identified a bug in Openlibm's powf(), >>>>>> which is identical to FreeBSD's libm. Both derived from >>>>>> fdlibm. https://github.com/JuliaMath/openlibm/issues/212. >>>>>>=20 >>>>>> Consider >>>>>>=20 >>>>>> % cat h.c >>>>>> #include >>>>>> #include >>>>>> int >>>>>> main(void) >>>>>> { >>>>>> float x, y, z; >>>>>> x =3D 0x1.ffffecp-1F; >>>>>> y =3D -0x1.000002p+27F; >>>>>> z =3D 0x1.557a86p115F; >>>>>> printf("%e %e %e <-- should be %e\n", x, y, powf(x,y), z); >>>>>> return 0; >>>>>> } >>>>>>=20 >>>>>> % cc -o h -fno-builtin h.c -lm && ./h >>>>>> 9.999994e-01 -1.342177e+08 inf <-- should be 5.540807e+34 >>>>>>=20 >>>>>> Note, clang seems to have a builtin for powf(), but one cannot >>>>>> count of clang being the only consumer of libm. With the patch >>>>>> at the end of this email, I get >>>>>>=20 >>>>>> % cc -o h -fno-builtin h.c -L/home/kargl/trunk/math/libm/msun = -lmath && ./h >>>>>> 9.999994e-01 -1.342177e+08 5.540807e+34 <-- should be = 5.540807e+34 >>>>>>=20 >>>>>> Watch for copy and paste whitespace corruption. >>>>>>=20 >>>>>> --- /usr/src/lib/msun/src/e_powf.c 2021-02-21 = 03:29:00.956878000 -0800 >>>>>> +++ src/e_powf.c 2021-09-06 08:17:09.800008000 -0700 >>>>>> @@ -136,7 +136,7 @@ >>>>>> /* |y| is huge */ >>>>>> if(iy>0x4d000000) { /* if |y| > 2**27 */ >>>>>> /* over/underflow if x is not close to one */ >>>>>> - if(ix<0x3f7ffff7) return (hy<0)? = sn*huge*huge:sn*tiny*tiny; >>>>>> + if(ix<0x3f7ffff6) return (hy<0)? = sn*huge*huge:sn*tiny*tiny; >>>>>> if(ix>0x3f800007) return (hy>0)? sn*huge*huge:sn*tiny*tiny; >>>>>> /* now |1-x| is tiny <=3D 2**-20, suffice to compute >>>>>> log(x) by x-x^2/2+x^3/3-x^4/4 */ >>>>>>=20 >>>>>>=20 >>>>>> -- >>>>>> Steve >>>>>>=20 >>>>>=20 >>>>> -- >>>>> Mark R V Murray >>>>>=20 >>>>=20 >>>>=20 >>>>=20 >>>> -- >>>> Steve >>>>=20 >>>=20 >>> -- >>> Mark R V Murray >>>=20 >>=20 >>=20 >>=20 >> -- >> Steve >>=20 >=20 -- Mark R V Murray --Apple-Mail=_4A7A40C0-32F8-4D72-82D1-26C88E567736 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.2 Comment: GPGTools - http://gpgtools.org iQEzBAEBCgAdFiEEyzPHvybPbOpU9MCxQlsJDh9CUqAFAmE3HBgACgkQQlsJDh9C UqDG9gf/T0G4KdTGPNMwq+dluUJyADTKzQyKfbMZWvaT8BmKa4KuMSzmlcuFfEmO j4BV/F+ppYdWjNUQqLmCdnfZqsO9V7TWsMYjnsswTKPMIi/2wxVNni54teVfmXt3 LFtdgjki3XKxBnq1XvuKnNsE3PTjJG4TYb8+NZJvHuDNSux5bIZHs06lmFbUW+Er 1KvBDU60O5bHPfIQkSlozfM5G+ApwvNQtY2IgVnkSf9I6usVVPHhZ40t6YicCVc+ +fTz3tHF2o3tKypbxS7vlBPrrXW1PZtWXkwP+BH5j/Fh+FLSaFsqrpBCnrtIfzbc BSRzhNtjrQnkKs5zrbeIWnNENGxogw== =jpbp -----END PGP SIGNATURE----- --Apple-Mail=_4A7A40C0-32F8-4D72-82D1-26C88E567736--