diff options
author | Joseph Myers <joseph@codesourcery.com> | 2016-06-08 21:32:57 +0000 |
---|---|---|
committer | Joseph Myers <joseph@codesourcery.com> | 2016-06-08 21:32:57 +0000 |
commit | 9946e7a949d3b0f2795d930aa2f2ce7bda5e4f8a (patch) | |
tree | b4d6e0cee63b44011a3cfbf6e4be60db0cd51de4 | |
parent | 40720ec9f98d57214d73d6fa98019e684f2eb45a (diff) | |
download | glibc-9946e7a949d3b0f2795d930aa2f2ce7bda5e4f8a.tar.gz glibc-9946e7a949d3b0f2795d930aa2f2ce7bda5e4f8a.tar.xz glibc-9946e7a949d3b0f2795d930aa2f2ce7bda5e4f8a.zip |
Fix ldexp, scalbn, scalbln for sNaN input (bug 20225).
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. [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.
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | math/libm-test.inc | 4 | ||||
-rw-r--r-- | math/s_ldexp.c | 2 | ||||
-rw-r--r-- | math/s_ldexpf.c | 2 | ||||
-rw-r--r-- | math/s_ldexpl.c | 2 | ||||
-rw-r--r-- | math/w_scalbln.c | 2 | ||||
-rw-r--r-- | math/w_scalblnf.c | 2 | ||||
-rw-r--r-- | math/w_scalblnl.c | 2 |
8 files changed, 21 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog index 201516873b..cf5e480bbf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 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. + [BZ #20224] * sysdeps/i386/fpu/s_cbrtl.S (__cbrtl): Add non-finite or zero argument to itself. diff --git a/math/libm-test.inc b/math/libm-test.inc index 520f141446..583c27cfc0 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 0248ba2c44..ee53695d71 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 37af88004f..b83062fe35 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 f34c805bda..52fb093171 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 4a309b900d..bcc33191d9 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 de4dc47382..2a0b237352 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 323abbece1..8ee8130d72 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); |