From owner-dev-commits-src-all@freebsd.org Mon Feb 15 18:13:27 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 4CB08534FB3; Mon, 15 Feb 2021 18:13:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DfXKM1mCgz4svC; Mon, 15 Feb 2021 18:13:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 24B9F22068; Mon, 15 Feb 2021 18:13:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 11FIDRgg093486; Mon, 15 Feb 2021 18:13:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 11FIDR9h093485; Mon, 15 Feb 2021 18:13:27 GMT (envelope-from git) Date: Mon, 15 Feb 2021 18:13:27 GMT Message-Id: <202102151813.11FIDR9h093485@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dimitry Andric Subject: git: 720600023287 - stable/13 - Fix incorrect powf(3) result with x near 1 and |y| much larger than 1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dim X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 720600023287cd029894b79477fb2bd4a5183ba4 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Feb 2021 18:13:27 -0000 The branch stable/13 has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=720600023287cd029894b79477fb2bd4a5183ba4 commit 720600023287cd029894b79477fb2bd4a5183ba4 Author: Steve Kargl AuthorDate: 2021-02-08 19:45:30 +0000 Commit: Dimitry Andric CommitDate: 2021-02-15 18:08:20 +0000 Fix incorrect powf(3) result with x near 1 and |y| much larger than 1 This adjusts the check to trigger overflow/underflow to a slightly lower value. Before: powf(9.999995e-01, -1.342177e+08) -> inf After: powf(9.999995e-01, -1.342177e+08) -> 1.858724e+31 (cherry picked from commit 93fc67896550548f91b307dbe3053f11db5d4a8a) Add test case for 93fc67896550 (incorrect powf(3) result) This adds the test case to contrib/netbsd-tests/lib/libm/t_pow.c, as it is currently the only place testing pow(3) and friends. (cherry picked from commit 51af03328755c9095e94d20858a8d10acfe412ae) --- contrib/netbsd-tests/lib/libm/t_pow.c | 22 ++++++++++++++++++++++ lib/msun/src/e_powf.c | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/contrib/netbsd-tests/lib/libm/t_pow.c b/contrib/netbsd-tests/lib/libm/t_pow.c index 7afee9f6dffa..09e72be7311b 100644 --- a/contrib/netbsd-tests/lib/libm/t_pow.c +++ b/contrib/netbsd-tests/lib/libm/t_pow.c @@ -637,6 +637,27 @@ ATF_TC_BODY(powf_zero_y, tc) } } +ATF_TC(powf_near_one_x_huge_y); +ATF_TC_HEAD(powf_near_one_x_huge_y, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test powf(->1, huge) != inf"); +} + +ATF_TC_BODY(powf_near_one_x_huge_y, tc) +{ + const float x = 0x1.ffffeep-1f; /* 9.999995e-01f */ + const float y = -0x1.000002p+27f; /* -1.342177e+08f */ + const float e = 0x1.d53532p+103f; /* 1.858724e+31f */ + const float ulp = __FLT_EPSILON__; + float z; + + z = powf(x, y); + + ATF_CHECK(isinf(z) == 0); + ATF_CHECK(fabsf(z - e) <= 2 * ulp); +} + + ATF_TP_ADD_TCS(tp) { @@ -661,6 +682,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, powf_one_pos_x); ATF_TP_ADD_TC(tp, powf_zero_x); ATF_TP_ADD_TC(tp, powf_zero_y); + ATF_TP_ADD_TC(tp, powf_near_one_x_huge_y); return atf_no_error(); } diff --git a/lib/msun/src/e_powf.c b/lib/msun/src/e_powf.c index 53f1d37d6bec..33eedad50b16 100644 --- a/lib/msun/src/e_powf.c +++ b/lib/msun/src/e_powf.c @@ -136,7 +136,7 @@ __ieee754_powf(float x, float y) /* |y| is huge */ if(iy>0x4d000000) { /* if |y| > 2**27 */ /* over/underflow if x is not close to one */ - if(ix<0x3f7ffff8) return (hy<0)? sn*huge*huge:sn*tiny*tiny; + if(ix<0x3f7ffff7) 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 */