This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix ldexp, scalbn, scalbln for sNaN input (bug 20225) [committed]


The wrapper implementations of ldexp / scalbn / scalbln
(architecture-independent), and their float / long double variants,
return sNaN for sNaN input.  This patch fixes them to add relevant
arguments to themselves so that qNaN is returned in this case.

Tested for x86_64 and x86.  Committed.

2016-06-08  Joseph Myers  <joseph@codesourcery.com>

	[BZ #20225]
	* math/s_ldexp.c (__ldexp): Add non-finite or zero argument to
	itself.
	* math/s_ldexpf.c (__ldexpf): Likewise.
	* math/s_ldexpl.c (__ldexpl): Likewise.
	* math/w_scalbln.c (__w_scalbln): Likewise.
	* math/w_scalblnf.c (__w_scalblnf): Likewise.
	* math/w_scalblnl.c (__w_scalblnl): Likewise.
	* math/libm-test.inc (scalbn_test_data): Add sNaN tests.
	(scalbln_test_data): Likewise.

diff --git a/math/libm-test.inc b/math/libm-test.inc
index 520f141..583c27c 100644
--- a/math/libm-test.inc
+++ b/math/libm-test.inc
@@ -11117,6 +11117,8 @@ static const struct test_fi_f_data scalbn_test_data[] =
     TEST_fi_f (scalbn, minus_infty, 1, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_fi_f (scalbn, qnan_value, 1, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_fi_f (scalbn, -qnan_value, 1, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_fi_f (scalbn, snan_value, 1, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_fi_f (scalbn, -snan_value, 1, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
 
     TEST_fi_f (scalbn, 0.8L, 4, 12.8L, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_fi_f (scalbn, -0.854375L, 5, -27.34L, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
@@ -11199,6 +11201,8 @@ static const struct test_fl_f_data scalbln_test_data[] =
     TEST_fl_f (scalbln, minus_infty, 1, minus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_fl_f (scalbln, qnan_value, 1, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_fl_f (scalbln, -qnan_value, 1, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_fl_f (scalbln, snan_value, 1, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
+    TEST_fl_f (scalbln, -snan_value, 1, qnan_value, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
 
     TEST_fl_f (scalbln, 0.8L, 4, 12.8L, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_fl_f (scalbln, -0.854375L, 5, -27.34L, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
diff --git a/math/s_ldexp.c b/math/s_ldexp.c
index 0248ba2..ee53695 100644
--- a/math/s_ldexp.c
+++ b/math/s_ldexp.c
@@ -20,7 +20,7 @@ static char rcsid[] = "$NetBSD: s_ldexp.c,v 1.6 1995/05/10 20:47:40 jtc Exp $";
 
 double __ldexp(double value, int exp)
 {
-	if(!isfinite(value)||value==0.0) return value;
+	if(!isfinite(value)||value==0.0) return value + value;
 	value = __scalbn(value,exp);
 	if(!isfinite(value)||value==0.0) __set_errno (ERANGE);
 	return value;
diff --git a/math/s_ldexpf.c b/math/s_ldexpf.c
index 37af880..b83062f 100644
--- a/math/s_ldexpf.c
+++ b/math/s_ldexpf.c
@@ -23,7 +23,7 @@ static char rcsid[] = "$NetBSD: s_ldexpf.c,v 1.3 1995/05/10 20:47:42 jtc Exp $";
 
 float __ldexpf(float value, int exp)
 {
-	if(!isfinite(value)||value==(float)0.0) return value;
+	if(!isfinite(value)||value==(float)0.0) return value + value;
 	value = __scalbnf(value,exp);
 	if(!isfinite(value)||value==(float)0.0) __set_errno (ERANGE);
 	return value;
diff --git a/math/s_ldexpl.c b/math/s_ldexpl.c
index f34c805..52fb093 100644
--- a/math/s_ldexpl.c
+++ b/math/s_ldexpl.c
@@ -24,7 +24,7 @@ static char rcsid[] = "$NetBSD: $";
 
 long double __ldexpl(long double value, int exp)
 {
-	if(!isfinite(value)||value==0.0) return value;
+	if(!isfinite(value)||value==0.0) return value + value;
 	value = __scalbnl(value,exp);
 	if(!isfinite(value)||value==0.0) __set_errno (ERANGE);
 	return value;
diff --git a/math/w_scalbln.c b/math/w_scalbln.c
index 4a309b9..bcc3319 100644
--- a/math/w_scalbln.c
+++ b/math/w_scalbln.c
@@ -24,7 +24,7 @@ double
 __w_scalbln (double x, long int n)
 {
   if (!isfinite (x) || x == 0.0)
-    return x;
+    return x + x;
 
   x = __scalbln (x, n);
 
diff --git a/math/w_scalblnf.c b/math/w_scalblnf.c
index de4dc47..2a0b237 100644
--- a/math/w_scalblnf.c
+++ b/math/w_scalblnf.c
@@ -24,7 +24,7 @@ float
 __w_scalblnf (float x, long int n)
 {
   if (!isfinite (x) || x == 0.0f)
-    return x;
+    return x + x;
 
   x = __scalblnf (x, n);
 
diff --git a/math/w_scalblnl.c b/math/w_scalblnl.c
index 323abbe..8ee8130 100644
--- a/math/w_scalblnl.c
+++ b/math/w_scalblnl.c
@@ -24,7 +24,7 @@ long double
 __w_scalblnl (long double x, long int n)
 {
   if (!isfinite (x) || x == 0.0L)
-    return x;
+    return x + x;
 
   x = __scalblnl (x, n);
 

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]