about summary refs log tree commit diff
path: root/math/libm-test.inc
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2016-12-07 01:16:36 +0000
committerJoseph Myers <joseph@codesourcery.com>2016-12-07 01:16:36 +0000
commit58307649fb51a3a6adc29a8659d3301393f24671 (patch)
tree2594a547d195e7f2231fcfaec9fa5fdaa2d70df4 /math/libm-test.inc
parenta91fd168a0db38563528dab1a13180fda2a5040c (diff)
downloadglibc-58307649fb51a3a6adc29a8659d3301393f24671.tar.gz
glibc-58307649fb51a3a6adc29a8659d3301393f24671.tar.xz
glibc-58307649fb51a3a6adc29a8659d3301393f24671.zip
Fix hypot sNaN handling (bug 20940).
TS 18661-1 generally defines libm functions taking sNaN arguments to
return qNaN and raise "invalid", even for the cases where a
corresponding qNaN argument would not result in a qNaN return.  This
includes hypot with one argument being an infinity and the other being
an sNaN.  This patch duly fixes hypot implementatations in glibc
(generic and powerpc) to ensure qNaN, computed by arithmetic on the
arguments, is returned in that case.

Various implementations do their checks for infinities and NaNs inline
by manipulating the representations of the arguments.  For simplicity,
this patch just uses issignaling to check for sNaN arguments.  This
could be inlined like the existing code (with due care about reversed
quiet NaN conventions, for implementations where that is relevant),
but given that all these checks are in cases where it's already known
at least one argument is not finite, which should be the uncommon
case, that doesn't seem worthwhile unless performance issues are
observed in practice.

Tested for x86_64, x86, mips64 and powerpc.

	[BZ #20940]
	* sysdeps/ieee754/dbl-64/e_hypot.c (__ieee754_hypot): Do not
	return Inf for arguments Inf and sNaN.
	* sysdeps/ieee754/flt-32/e_hypotf.c (__ieee754_hypotf): Likewise.
	* sysdeps/ieee754/ldbl-128/e_hypotl.c (__ieee754_hypotl):
	Likewise.
	* sysdeps/ieee754/ldbl-128ibm/e_hypotl.c (__ieee754_hypotl):
	Likewise.
	* sysdeps/ieee754/ldbl-96/e_hypotl.c (__ieee754_hypotl): Likewise.
	* sysdeps/powerpc/fpu/e_hypot.c (TEST_INF_NAN): Do not return Inf
	for arguments Inf and sNaN.  When returning a NaN, compute it by
	arithmetic on the arguments.
	* sysdeps/powerpc/fpu/e_hypotf.c (TEST_INF_NAN): Likewise.
	* math/libm-test.inc (pow_test_data): Add tests of sNaN arguments.
Diffstat (limited to 'math/libm-test.inc')
-rw-r--r--math/libm-test.inc52
1 files changed, 52 insertions, 0 deletions
diff --git a/math/libm-test.inc b/math/libm-test.inc
index 9123dcfc48..e973a3f6ae 100644
--- a/math/libm-test.inc
+++ b/math/libm-test.inc
@@ -8344,6 +8344,14 @@ static const struct test_ff_f_data hypot_test_data[] =
     TEST_ff_f (hypot, -qnan_value, plus_infty, plus_infty, ERRNO_UNCHANGED|NO_TEST_INLINE),
     TEST_ff_f (hypot, qnan_value, minus_infty, plus_infty, ERRNO_UNCHANGED|NO_TEST_INLINE),
     TEST_ff_f (hypot, -qnan_value, minus_infty, plus_infty, ERRNO_UNCHANGED|NO_TEST_INLINE),
+    TEST_ff_f (hypot, plus_infty, snan_value, qnan_value, INVALID_EXCEPTION|NO_TEST_INLINE),
+    TEST_ff_f (hypot, plus_infty, -snan_value, qnan_value, INVALID_EXCEPTION|NO_TEST_INLINE),
+    TEST_ff_f (hypot, minus_infty, snan_value, qnan_value, INVALID_EXCEPTION|NO_TEST_INLINE),
+    TEST_ff_f (hypot, minus_infty, -snan_value, qnan_value, INVALID_EXCEPTION|NO_TEST_INLINE),
+    TEST_ff_f (hypot, snan_value, plus_infty, qnan_value, INVALID_EXCEPTION|NO_TEST_INLINE),
+    TEST_ff_f (hypot, -snan_value, plus_infty, qnan_value, INVALID_EXCEPTION|NO_TEST_INLINE),
+    TEST_ff_f (hypot, snan_value, minus_infty, qnan_value, INVALID_EXCEPTION|NO_TEST_INLINE),
+    TEST_ff_f (hypot, -snan_value, minus_infty, qnan_value, INVALID_EXCEPTION|NO_TEST_INLINE),
 
     TEST_ff_f (hypot, 0, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_ff_f (hypot, 0, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
@@ -8361,6 +8369,22 @@ static const struct test_ff_f_data hypot_test_data[] =
     TEST_ff_f (hypot, min_subnorm_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_ff_f (hypot, -min_subnorm_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_ff_f (hypot, -min_subnorm_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (hypot, 0, snan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, 0, -snan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, minus_zero, snan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, minus_zero, -snan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, max_value, snan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, max_value, -snan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, -max_value, snan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, -max_value, -snan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, min_value, snan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, min_value, -snan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, -min_value, snan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, -min_value, -snan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, min_subnorm_value, snan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, min_subnorm_value, -snan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, -min_subnorm_value, snan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, -min_subnorm_value, -snan_value, qnan_value, INVALID_EXCEPTION),
     TEST_ff_f (hypot, qnan_value, 0, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_ff_f (hypot, -qnan_value, 0, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_ff_f (hypot, qnan_value, minus_zero, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
@@ -8377,11 +8401,39 @@ static const struct test_ff_f_data hypot_test_data[] =
     TEST_ff_f (hypot, -qnan_value, min_subnorm_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_ff_f (hypot, qnan_value, -min_subnorm_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_ff_f (hypot, -qnan_value, -min_subnorm_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (hypot, snan_value, 0, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, -snan_value, 0, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, snan_value, minus_zero, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, -snan_value, minus_zero, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, snan_value, max_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, -snan_value, max_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, snan_value, -max_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, -snan_value, -max_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, snan_value, min_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, -snan_value, min_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, snan_value, -min_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, -snan_value, -min_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, snan_value, min_subnorm_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, -snan_value, min_subnorm_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, snan_value, -min_subnorm_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, -snan_value, -min_subnorm_value, qnan_value, INVALID_EXCEPTION),
 
     TEST_ff_f (hypot, qnan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_ff_f (hypot, qnan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_ff_f (hypot, -qnan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_ff_f (hypot, -qnan_value, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_ff_f (hypot, qnan_value, snan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, qnan_value, -snan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, -qnan_value, snan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, -qnan_value, -snan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, snan_value, qnan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, snan_value, -qnan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, -snan_value, qnan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, -snan_value, -qnan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, snan_value, snan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, snan_value, -snan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, -snan_value, snan_value, qnan_value, INVALID_EXCEPTION),
+    TEST_ff_f (hypot, -snan_value, -snan_value, qnan_value, INVALID_EXCEPTION),
 
     AUTO_TESTS_ff_f (hypot),
   };