aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2021-02-10 22:28:43 +0000
committerDimitry Andric <dim@FreeBSD.org>2021-02-10 22:28:43 +0000
commitd3338f3355a612cf385632291f46c5777bba8d18 (patch)
treea15a53955218da243ebaefd9bc07b74f07769d09 /contrib
parenta6dc68c0e0f8a24ffaf0b4e78e58141ef7897047 (diff)
downloadsrc-d3338f3355a612cf385632291f46c5777bba8d18.tar.gz
src-d3338f3355a612cf385632291f46c5777bba8d18.zip
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 MFC after: 1 week
Diffstat (limited to 'contrib')
-rw-r--r--contrib/netbsd-tests/lib/libm/t_hypot.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/contrib/netbsd-tests/lib/libm/t_hypot.c b/contrib/netbsd-tests/lib/libm/t_hypot.c
index deb7e86ad5ac..075c5c83fe14 100644
--- a/contrib/netbsd-tests/lib/libm/t_hypot.c
+++ b/contrib/netbsd-tests/lib/libm/t_hypot.c
@@ -70,12 +70,32 @@ ATF_TC_BODY(pr50698, tc)
ATF_CHECK(!isnan(val));
}
+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);
+}
+
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);
+ ATF_TP_ADD_TC(tp, hypotl_near_underflow);
return atf_no_error();
}