From owner-dev-commits-src-branches@freebsd.org Thu Feb 18 18:12:57 2021 Return-Path: Delivered-To: dev-commits-src-branches@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 B02CF543E42; Thu, 18 Feb 2021 18:12:57 +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 4DhN9P48Fqz3D88; Thu, 18 Feb 2021 18:12:57 +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 8133A1CA6E; Thu, 18 Feb 2021 18:12:57 +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 11IICvVp060174; Thu, 18 Feb 2021 18:12:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 11IICvvv060173; Thu, 18 Feb 2021 18:12:57 GMT (envelope-from git) Date: Thu, 18 Feb 2021 18:12:57 GMT Message-Id: <202102181812.11IICvvv060173@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: 97232b0dc031 - stable/13 - Fix incorrect hypotl(3) result with subnormal numbers 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: 97232b0dc03146c0e6466a4886edaaca4f95c3a7 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Feb 2021 18:12:57 -0000 The branch stable/13 has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=97232b0dc03146c0e6466a4886edaaca4f95c3a7 commit 97232b0dc03146c0e6466a4886edaaca4f95c3a7 Author: Dimitry Andric AuthorDate: 2021-02-10 22:28:43 +0000 Commit: Dimitry Andric CommitDate: 2021-02-18 18:08:27 +0000 Fix incorrect hypotl(3) result with subnormal numbers This adjusts the factor used to scale the subnormal numbers, so it becomes the right value after adjusting its exponent. Thanks to Steve Kargl for finding the most elegant fix. Also enable the hypot tests, and add a test case for this bug. PR: 253313 (cherry picked from commit d3338f3355a612cf385632291f46c5777bba8d18) Fix lib/msun/test builds on platforms without 80-bit long doubles After d3338f3355a612cf385632291f46c5777bba8d18, the lib/msun test case 'hypotl_near_underflow' would fail to compile on platforms where long doubles weren't 80 bit, like on x86. Disable this particular test on such platforms for now. PR: 253313 (cherry picked from commit 25120662284466ecef976df8f86e97bafdedf991) --- contrib/netbsd-tests/lib/libm/t_hypot.c | 24 ++++++++++++++++++++++++ lib/msun/src/e_hypotl.c | 2 +- lib/msun/tests/Makefile | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/contrib/netbsd-tests/lib/libm/t_hypot.c b/contrib/netbsd-tests/lib/libm/t_hypot.c index deb7e86ad5ac..cbb056ee470e 100644 --- a/contrib/netbsd-tests/lib/libm/t_hypot.c +++ b/contrib/netbsd-tests/lib/libm/t_hypot.c @@ -70,12 +70,36 @@ ATF_TC_BODY(pr50698, tc) ATF_CHECK(!isnan(val)); } +#if __LDBL_MANT_DIG__ == 64 +ATF_TC(hypotl_near_underflow); +ATF_TC_HEAD(hypotl_near_underflow, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test hypotl near underflow"); +} + +ATF_TC_BODY(hypotl_near_underflow, tc) +{ + volatile long double a = 0x1.b2933cafa0bb7p-16383L; + volatile long double b = 0x1.fffffffffffffp-16351L; + volatile long double e = 0x1.fffffffffffffp-16351L; + volatile long double ulp = __LDBL_EPSILON__; + + volatile long double val = hypotl(a, b); + + ATF_CHECK(!isinf(val)); + ATF_CHECK(fabsl(val - e) <= 2 * ulp); +} +#endif /* __LDBL_MANT_DIG__ == 64 */ + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, hypot_integer); ATF_TP_ADD_TC(tp, hypotf_integer); ATF_TP_ADD_TC(tp, pr50698); +#if __LDBL_MANT_DIG__ == 64 + ATF_TP_ADD_TC(tp, hypotl_near_underflow); +#endif /* __LDBL_MANT_DIG__ == 64 */ return atf_no_error(); } diff --git a/lib/msun/src/e_hypotl.c b/lib/msun/src/e_hypotl.c index 9189b1fab54d..fc43538dfa65 100644 --- a/lib/msun/src/e_hypotl.c +++ b/lib/msun/src/e_hypotl.c @@ -82,7 +82,7 @@ hypotl(long double x, long double y) man_t manh, manl; GET_LDBL_MAN(manh,manl,b); if((manh|manl)==0) return a; - t1=0; + t1=1; SET_HIGH_WORD(t1,ESW(MAX_EXP-2)); /* t1=2^(MAX_EXP-2) */ b *= t1; a *= t1; diff --git a/lib/msun/tests/Makefile b/lib/msun/tests/Makefile index 5e9c54189bb7..67a38855309e 100644 --- a/lib/msun/tests/Makefile +++ b/lib/msun/tests/Makefile @@ -31,6 +31,7 @@ NETBSD_ATF_TESTS_C+= erf_test NETBSD_ATF_TESTS_C+= exp_test NETBSD_ATF_TESTS_C+= fmod_test NETBSD_ATF_TESTS_C+= fe_round_test +NETBSD_ATF_TESTS_C+= hypot_test NETBSD_ATF_TESTS_C+= infinity_test NETBSD_ATF_TESTS_C+= ilogb_test NETBSD_ATF_TESTS_C+= ldexp_test