Date: Mon, 6 Sep 2021 18:55:07 +0100 From: Mark Murray <markm@FreeBSD.org> To: Steve Kargl <sgk@troutmask.apl.washington.edu> Cc: freebsd-current@freebsd.org Subject: Re: BUG in libm's powf Message-ID: <AAA24AAD-86C5-4736-AD0C-EFBCA3FA59B2@FreeBSD.org> In-Reply-To: <20210906175318.GA87474@troutmask.apl.washington.edu> References: <20210906152836.GA86615@troutmask.apl.washington.edu> <01D81389-45D1-4278-8DC1-7995D34D0276@FreeBSD.org> <20210906175318.GA87474@troutmask.apl.washington.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
--Apple-Mail=_54C874FF-9B6C-4A93-88B4-E933BDD0A7E2 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Thanks! And it's committed! M > On 6 Sep 2021, at 18:53, Steve Kargl = <sgk@troutmask.apl.washington.edu> 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 = <sgk@troutmask.apl.washington.edu> 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 <math.h> >>> #include <stdio.h> >>> 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 -- Mark R V Murray --Apple-Mail=_54C874FF-9B6C-4A93-88B4-E933BDD0A7E2 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 iQEzBAEBCgAdFiEEyzPHvybPbOpU9MCxQlsJDh9CUqAFAmE2VfsACgkQQlsJDh9C UqAjVwf+OyV1HRj+qGQyQvnneKNd+FIznK82ZjKfMppRgSrHdPndUqJiMgn5VYGn SbUSQhwL0iqVUz6apIqZ7o9jQMBJE4YyemWgbcLl/l3KsgkKL6tn5n07iKFgO3EM cRBPmNGmoTaGeZLO/KhO7DXLA5OxQ3SifDK52AkODAMHwxIv//oPwq3O3tYSFnl+ C1Zx4QVZ8546UUJp5FV/MGyGZ8OU1Kf/wJPG7Tf3SHpHbAlpZQFM3XY4h70KPHme C0cdV5FK4qLtcaaERaR+dwpN7PZma4HttHNnB6deyTzQ3UKHWcoaaht8OsvUAky/ KNEx/b/5jUauEtcfjERaXmyKtLHunA== =4mRH -----END PGP SIGNATURE----- --Apple-Mail=_54C874FF-9B6C-4A93-88B4-E933BDD0A7E2--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AAA24AAD-86C5-4736-AD0C-EFBCA3FA59B2>