From nobody Mon Sep 06 15:28:36 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 D109617BA4A3 for ; Mon, 6 Sep 2021 15:28:45 +0000 (UTC) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.95.76.21]) (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 (2048 bits) client-digest SHA256) (Client CN "troutmask", Issuer "troutmask" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4H3C3c3cdHz4ZQn for ; Mon, 6 Sep 2021 15:28:44 +0000 (UTC) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.16.1/8.16.1) with ESMTPS id 186FSaoG086644 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO) for ; Mon, 6 Sep 2021 08:28:36 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.16.1/8.16.1/Submit) id 186FSaBp086643 for freebsd-current@freebsd.org; Mon, 6 Sep 2021 08:28:36 -0700 (PDT) (envelope-from sgk) Date: Mon, 6 Sep 2021 08:28:36 -0700 From: Steve Kargl To: freebsd-current@freebsd.org Subject: BUG in libm's powf Message-ID: <20210906152836.GA86615@troutmask.apl.washington.edu> 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 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Rspamd-Queue-Id: 4H3C3c3cdHz4ZQn X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=washington.edu (policy=none); spf=none (mx1.freebsd.org: domain of sgk@troutmask.apl.washington.edu has no SPF policy when checking 128.95.76.21) smtp.mailfrom=sgk@troutmask.apl.washington.edu X-Spamd-Result: default: False [-1.36 / 15.00]; MID_RHS_MATCH_FROM(0.00)[]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-0.999]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-current@freebsd.org]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; NEURAL_SPAM_SHORT(0.64)[0.643]; R_SPF_NA(0.00)[no SPF record]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:73, ipnet:128.95.0.0/16, country:US]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; DMARC_POLICY_SOFTFAIL(0.10)[washington.edu : No valid SPF, No valid DKIM,none] X-ThisMailContainsUnwantedMimeParts: N 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. Consider % cat h.c #include #include int main(void) { float x, y, z; x = 0x1.ffffecp-1F; y = -0x1.000002p+27F; z = 0x1.557a86p115F; printf("%e %e %e <-- should be %e\n", x, y, powf(x,y), z); return 0; } % cc -o h -fno-builtin h.c -lm && ./h 9.999994e-01 -1.342177e+08 inf <-- should be 5.540807e+34 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 % 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 Watch for copy and paste whitespace corruption. --- /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 <= 2**-20, suffice to compute log(x) by x-x^2/2+x^3/3-x^4/4 */ -- Steve