diff options
author | Joseph Myers <joseph@codesourcery.com> | 2015-09-17 21:21:39 +0000 |
---|---|---|
committer | Joseph Myers <joseph@codesourcery.com> | 2015-09-17 21:21:39 +0000 |
commit | 61f893789862db1dfdf188f77cd215bab0814d2c (patch) | |
tree | 9fd0f9b8395f451e24f8ce1c12253847740f8e31 /math | |
parent | b8682397ab2db1aed7f25d0a0c7c81134a97c8c7 (diff) | |
download | glibc-61f893789862db1dfdf188f77cd215bab0814d2c.tar glibc-61f893789862db1dfdf188f77cd215bab0814d2c.tar.gz glibc-61f893789862db1dfdf188f77cd215bab0814d2c.tar.bz2 glibc-61f893789862db1dfdf188f77cd215bab0814d2c.zip |
Fix sign of zero part from ctan / ctanh when argument infinite (bug 17118).
C99/C11 Annex G specifies the sign of the zero part of the result of
ctan (x +/- i * Inf) and ctanh (+/-Inf + i * y). This patch fixes glibc
to follow that specification, along the lines I described in my review
of Andreas's previous patch for this issue
<https://sourceware.org/ml/libc-alpha/2014-08/msg00142.html>.
Tested for x86_64.
2015-09-17 Joseph Myers <joseph@codesourcery.com>
Andreas Schwab <schwab@suse.de>
[BZ #17118]
* math/s_ctan.c (__ctan): Determine sign of zero real part of
result when imaginary part of argument is infinite using sine and
cosine.
* math/s_ctanf.c (__ctanf): Likewise.
* math/s_ctanl.c (__ctanl): Likewise.
* math/s_ctanh.c (__ctanh): Determine sign of zero imaginary part
of result when real part of argument is infinite using sine and
cosine.
* math/s_ctanhf.c (__ctanhf): Likewise.
* math/s_ctanhl.c (__ctanhl): Likewise.
* math/libm-test.inc (ctan_test_data): Add more tests of ctan.
(ctanh_test_data): Add more tests of ctanh.
Diffstat (limited to 'math')
-rw-r--r-- | math/libm-test.inc | 128 | ||||
-rw-r--r-- | math/s_ctan.c | 9 | ||||
-rw-r--r-- | math/s_ctanf.c | 9 | ||||
-rw-r--r-- | math/s_ctanh.c | 9 | ||||
-rw-r--r-- | math/s_ctanhf.c | 9 | ||||
-rw-r--r-- | math/s_ctanhl.c | 9 | ||||
-rw-r--r-- | math/s_ctanl.c | 9 |
7 files changed, 176 insertions, 6 deletions
diff --git a/math/libm-test.inc b/math/libm-test.inc index 5594b9d638..42d608595b 100644 --- a/math/libm-test.inc +++ b/math/libm-test.inc @@ -6551,13 +6551,73 @@ static const struct test_c_c_data ctan_test_data[] = { TEST_c_c (ctan, 0, plus_infty, 0.0, 1.0), TEST_c_c (ctan, 1, plus_infty, 0.0, 1.0), + TEST_c_c (ctan, 2, plus_infty, minus_zero, 1.0), + TEST_c_c (ctan, 3, plus_infty, minus_zero, 1.0), + TEST_c_c (ctan, 4, plus_infty, 0.0, 1.0), + TEST_c_c (ctan, min_value, plus_infty, 0.0, 1.0), + TEST_c_c (ctan, min_subnorm_value, plus_infty, 0.0, 1.0), + TEST_c_c (ctan, 0x1p127, plus_infty, 0.0, 1.0), + TEST_c_c (ctan, 0x1.11p127, plus_infty, minus_zero, 1.0), +#ifndef TEST_FLOAT + TEST_c_c (ctan, 0x1p1023, plus_infty, minus_zero, 1.0), + TEST_c_c (ctan, 0x1.5p1023, plus_infty, 0.0, 1.0), +#endif +#if defined TEST_LDOUBLE && LDBL_MAX_EXP >= 16384 + TEST_c_c (ctan, 0x1p16383L, plus_infty, 0.0, 1.0), + TEST_c_c (ctan, 0x1.2p16383L, plus_infty, minus_zero, 1.0), +#endif TEST_c_c (ctan, minus_zero, plus_infty, minus_zero, 1.0), TEST_c_c (ctan, -1, plus_infty, minus_zero, 1.0), + TEST_c_c (ctan, -2, plus_infty, 0.0, 1.0), + TEST_c_c (ctan, -3, plus_infty, 0.0, 1.0), + TEST_c_c (ctan, -4, plus_infty, minus_zero, 1.0), + TEST_c_c (ctan, -min_value, plus_infty, minus_zero, 1.0), + TEST_c_c (ctan, -min_subnorm_value, plus_infty, minus_zero, 1.0), + TEST_c_c (ctan, -0x1p127, plus_infty, minus_zero, 1.0), + TEST_c_c (ctan, -0x1.11p127, plus_infty, 0.0, 1.0), +#ifndef TEST_FLOAT + TEST_c_c (ctan, -0x1p1023, plus_infty, 0.0, 1.0), + TEST_c_c (ctan, -0x1.5p1023, plus_infty, minus_zero, 1.0), +#endif +#if defined TEST_LDOUBLE && LDBL_MAX_EXP >= 16384 + TEST_c_c (ctan, -0x1p16383L, plus_infty, minus_zero, 1.0), + TEST_c_c (ctan, -0x1.2p16383L, plus_infty, 0.0, 1.0), +#endif TEST_c_c (ctan, 0, minus_infty, 0.0, -1.0), TEST_c_c (ctan, 1, minus_infty, 0.0, -1.0), + TEST_c_c (ctan, 2, minus_infty, minus_zero, -1.0), + TEST_c_c (ctan, 3, minus_infty, minus_zero, -1.0), + TEST_c_c (ctan, 4, minus_infty, 0.0, -1.0), + TEST_c_c (ctan, min_value, minus_infty, 0.0, -1.0), + TEST_c_c (ctan, min_subnorm_value, minus_infty, 0.0, -1.0), + TEST_c_c (ctan, 0x1p127, minus_infty, 0.0, -1.0), + TEST_c_c (ctan, 0x1.11p127, minus_infty, minus_zero, -1.0), +#ifndef TEST_FLOAT + TEST_c_c (ctan, 0x1p1023, minus_infty, minus_zero, -1.0), + TEST_c_c (ctan, 0x1.5p1023, minus_infty, 0.0, -1.0), +#endif +#if defined TEST_LDOUBLE && LDBL_MAX_EXP >= 16384 + TEST_c_c (ctan, 0x1p16383L, minus_infty, 0.0, -1.0), + TEST_c_c (ctan, 0x1.2p16383L, minus_infty, minus_zero, -1.0), +#endif TEST_c_c (ctan, minus_zero, minus_infty, minus_zero, -1.0), TEST_c_c (ctan, -1, minus_infty, minus_zero, -1.0), + TEST_c_c (ctan, -2, minus_infty, 0.0, -1.0), + TEST_c_c (ctan, -3, minus_infty, 0.0, -1.0), + TEST_c_c (ctan, -4, minus_infty, minus_zero, -1.0), + TEST_c_c (ctan, -min_value, minus_infty, minus_zero, -1.0), + TEST_c_c (ctan, -min_subnorm_value, minus_infty, minus_zero, -1.0), + TEST_c_c (ctan, -0x1p127, minus_infty, minus_zero, -1.0), + TEST_c_c (ctan, -0x1.11p127, minus_infty, 0.0, -1.0), +#ifndef TEST_FLOAT + TEST_c_c (ctan, -0x1p1023, minus_infty, 0.0, -1.0), + TEST_c_c (ctan, -0x1.5p1023, minus_infty, minus_zero, -1.0), +#endif +#if defined TEST_LDOUBLE && LDBL_MAX_EXP >= 16384 + TEST_c_c (ctan, -0x1p16383L, minus_infty, minus_zero, -1.0), + TEST_c_c (ctan, -0x1.2p16383L, minus_infty, 0.0, -1.0), +#endif TEST_c_c (ctan, plus_infty, 0, qnan_value, qnan_value, INVALID_EXCEPTION), TEST_c_c (ctan, plus_infty, 2, qnan_value, qnan_value, INVALID_EXCEPTION), @@ -6569,7 +6629,11 @@ static const struct test_c_c_data ctan_test_data[] = TEST_c_c (ctan, minus_infty, -2, qnan_value, qnan_value, INVALID_EXCEPTION), TEST_c_c (ctan, qnan_value, plus_infty, 0.0, 1.0, IGNORE_ZERO_INF_SIGN), + TEST_c_c (ctan, plus_infty, plus_infty, 0.0, 1.0, IGNORE_ZERO_INF_SIGN), + TEST_c_c (ctan, minus_infty, plus_infty, 0.0, 1.0, IGNORE_ZERO_INF_SIGN), TEST_c_c (ctan, qnan_value, minus_infty, 0.0, -1.0, IGNORE_ZERO_INF_SIGN), + TEST_c_c (ctan, plus_infty, minus_infty, 0.0, -1.0, IGNORE_ZERO_INF_SIGN), + TEST_c_c (ctan, minus_infty, minus_infty, 0.0, -1.0, IGNORE_ZERO_INF_SIGN), TEST_c_c (ctan, 0, qnan_value, 0.0, qnan_value), TEST_c_c (ctan, minus_zero, qnan_value, minus_zero, qnan_value), @@ -6598,12 +6662,72 @@ static const struct test_c_c_data ctanh_test_data[] = { TEST_c_c (ctanh, plus_infty, 0, 1.0, 0.0), TEST_c_c (ctanh, plus_infty, 1, 1.0, 0.0), + TEST_c_c (ctanh, plus_infty, 2, 1.0, minus_zero), + TEST_c_c (ctanh, plus_infty, 3, 1.0, minus_zero), + TEST_c_c (ctanh, plus_infty, 4, 1.0, 0.0), + TEST_c_c (ctanh, plus_infty, min_value, 1.0, 0.0), + TEST_c_c (ctanh, plus_infty, min_subnorm_value, 1.0, 0.0), + TEST_c_c (ctanh, plus_infty, 0x1p127, 1.0, 0.0), + TEST_c_c (ctanh, plus_infty, 0x1.11p127, 1.0, minus_zero), +#ifndef TEST_FLOAT + TEST_c_c (ctanh, plus_infty, 0x1p1023, 1.0, minus_zero), + TEST_c_c (ctanh, plus_infty, 0x1.5p1023, 1.0, 0.0), +#endif +#if defined TEST_LDOUBLE && LDBL_MAX_EXP >= 16384 + TEST_c_c (ctanh, plus_infty, 0x1p16383L, 1.0, 0.0), + TEST_c_c (ctanh, plus_infty, 0x1.2p16383L, 1.0, minus_zero), +#endif TEST_c_c (ctanh, plus_infty, minus_zero, 1.0, minus_zero), TEST_c_c (ctanh, plus_infty, -1, 1.0, minus_zero), + TEST_c_c (ctanh, plus_infty, -2, 1.0, 0.0), + TEST_c_c (ctanh, plus_infty, -3, 1.0, 0.0), + TEST_c_c (ctanh, plus_infty, -4, 1.0, minus_zero), + TEST_c_c (ctanh, plus_infty, -min_value, 1.0, minus_zero), + TEST_c_c (ctanh, plus_infty, -min_subnorm_value, 1.0, minus_zero), + TEST_c_c (ctanh, plus_infty, -0x1p127, 1.0, minus_zero), + TEST_c_c (ctanh, plus_infty, -0x1.11p127, 1.0, 0.0), +#ifndef TEST_FLOAT + TEST_c_c (ctanh, plus_infty, -0x1p1023, 1.0, 0.0), + TEST_c_c (ctanh, plus_infty, -0x1.5p1023, 1.0, minus_zero), +#endif +#if defined TEST_LDOUBLE && LDBL_MAX_EXP >= 16384 + TEST_c_c (ctanh, plus_infty, -0x1p16383L, 1.0, minus_zero), + TEST_c_c (ctanh, plus_infty, -0x1.2p16383L, 1.0, 0.0), +#endif TEST_c_c (ctanh, minus_infty, 0, -1.0, 0.0), TEST_c_c (ctanh, minus_infty, 1, -1.0, 0.0), + TEST_c_c (ctanh, minus_infty, 2, -1.0, minus_zero), + TEST_c_c (ctanh, minus_infty, 3, -1.0, minus_zero), + TEST_c_c (ctanh, minus_infty, 4, -1.0, 0.0), + TEST_c_c (ctanh, minus_infty, min_value, -1.0, 0.0), + TEST_c_c (ctanh, minus_infty, min_subnorm_value, -1.0, 0.0), + TEST_c_c (ctanh, minus_infty, 0x1p127, -1.0, 0.0), + TEST_c_c (ctanh, minus_infty, 0x1.11p127, -1.0, minus_zero), +#ifndef TEST_FLOAT + TEST_c_c (ctanh, minus_infty, 0x1p1023, -1.0, minus_zero), + TEST_c_c (ctanh, minus_infty, 0x1.5p1023, -1.0, 0.0), +#endif +#if defined TEST_LDOUBLE && LDBL_MAX_EXP >= 16384 + TEST_c_c (ctanh, minus_infty, 0x1p16383L, -1.0, 0.0), + TEST_c_c (ctanh, minus_infty, 0x1.2p16383L, -1.0, minus_zero), +#endif TEST_c_c (ctanh, minus_infty, minus_zero, -1.0, minus_zero), TEST_c_c (ctanh, minus_infty, -1, -1.0, minus_zero), + TEST_c_c (ctanh, minus_infty, -2, -1.0, 0.0), + TEST_c_c (ctanh, minus_infty, -3, -1.0, 0.0), + TEST_c_c (ctanh, minus_infty, -4, -1.0, minus_zero), + TEST_c_c (ctanh, minus_infty, -min_value, -1.0, minus_zero), + TEST_c_c (ctanh, minus_infty, -min_subnorm_value, -1.0, minus_zero), + TEST_c_c (ctanh, minus_infty, -0x1p127, -1.0, minus_zero), + TEST_c_c (ctanh, minus_infty, -0x1.11p127, -1.0, 0.0), +#ifndef TEST_FLOAT + TEST_c_c (ctanh, minus_infty, -0x1p1023, -1.0, 0.0), + TEST_c_c (ctanh, minus_infty, -0x1.5p1023, -1.0, minus_zero), +#endif +#if defined TEST_LDOUBLE && LDBL_MAX_EXP >= 16384 + TEST_c_c (ctanh, minus_infty, -0x1p16383L, -1.0, minus_zero), + TEST_c_c (ctanh, minus_infty, -0x1.2p16383L, -1.0, 0.0), +#endif TEST_c_c (ctanh, 0, plus_infty, qnan_value, qnan_value, INVALID_EXCEPTION), TEST_c_c (ctanh, 2, plus_infty, qnan_value, qnan_value, INVALID_EXCEPTION), @@ -6615,7 +6739,11 @@ static const struct test_c_c_data ctanh_test_data[] = TEST_c_c (ctanh, -2, minus_infty, qnan_value, qnan_value, INVALID_EXCEPTION), TEST_c_c (ctanh, plus_infty, qnan_value, 1.0, 0.0, IGNORE_ZERO_INF_SIGN), + TEST_c_c (ctanh, plus_infty, plus_infty, 1.0, 0.0, IGNORE_ZERO_INF_SIGN), + TEST_c_c (ctanh, plus_infty, minus_infty, 1.0, 0.0, IGNORE_ZERO_INF_SIGN), TEST_c_c (ctanh, minus_infty, qnan_value, -1.0, 0.0, IGNORE_ZERO_INF_SIGN), + TEST_c_c (ctanh, minus_infty, plus_infty, -1.0, 0.0, IGNORE_ZERO_INF_SIGN), + TEST_c_c (ctanh, minus_infty, minus_infty, -1.0, 0.0, IGNORE_ZERO_INF_SIGN), TEST_c_c (ctanh, qnan_value, 0, qnan_value, 0.0), TEST_c_c (ctanh, qnan_value, minus_zero, qnan_value, minus_zero), diff --git a/math/s_ctan.c b/math/s_ctan.c index bcf5cfcec0..7ed6abd814 100644 --- a/math/s_ctan.c +++ b/math/s_ctan.c @@ -32,7 +32,14 @@ __ctan (__complex__ double x) { if (__isinf_ns (__imag__ x)) { - __real__ res = __copysign (0.0, __real__ x); + if (isfinite (__real__ x) && fabs (__real__ x) > 1.0) + { + double sinrx, cosrx; + __sincos (__real__ x, &sinrx, &cosrx); + __real__ res = __copysign (0.0, sinrx * cosrx); + } + else + __real__ res = __copysign (0.0, __real__ x); __imag__ res = __copysign (1.0, __imag__ x); } else if (__real__ x == 0.0) diff --git a/math/s_ctanf.c b/math/s_ctanf.c index 683ab6e544..d87f775f23 100644 --- a/math/s_ctanf.c +++ b/math/s_ctanf.c @@ -32,7 +32,14 @@ __ctanf (__complex__ float x) { if (__isinf_nsf (__imag__ x)) { - __real__ res = __copysignf (0.0, __real__ x); + if (isfinite (__real__ x) && fabsf (__real__ x) > 1.0f) + { + float sinrx, cosrx; + __sincosf (__real__ x, &sinrx, &cosrx); + __real__ res = __copysignf (0.0f, sinrx * cosrx); + } + else + __real__ res = __copysignf (0.0, __real__ x); __imag__ res = __copysignf (1.0, __imag__ x); } else if (__real__ x == 0.0) diff --git a/math/s_ctanh.c b/math/s_ctanh.c index 76a0501a73..a41cd1a0a6 100644 --- a/math/s_ctanh.c +++ b/math/s_ctanh.c @@ -33,7 +33,14 @@ __ctanh (__complex__ double x) if (__isinf_ns (__real__ x)) { __real__ res = __copysign (1.0, __real__ x); - __imag__ res = __copysign (0.0, __imag__ x); + if (isfinite (__imag__ x) && fabs (__imag__ x) > 1.0) + { + double sinix, cosix; + __sincos (__imag__ x, &sinix, &cosix); + __imag__ res = __copysign (0.0, sinix * cosix); + } + else + __imag__ res = __copysign (0.0, __imag__ x); } else if (__imag__ x == 0.0) { diff --git a/math/s_ctanhf.c b/math/s_ctanhf.c index 9d15c3ef0c..3ce8ac1ac4 100644 --- a/math/s_ctanhf.c +++ b/math/s_ctanhf.c @@ -33,7 +33,14 @@ __ctanhf (__complex__ float x) if (__isinf_nsf (__real__ x)) { __real__ res = __copysignf (1.0, __real__ x); - __imag__ res = __copysignf (0.0, __imag__ x); + if (isfinite (__imag__ x) && fabsf (__imag__ x) > 1.0f) + { + float sinix, cosix; + __sincosf (__imag__ x, &sinix, &cosix); + __imag__ res = __copysignf (0.0f, sinix * cosix); + } + else + __imag__ res = __copysignf (0.0, __imag__ x); } else if (__imag__ x == 0.0) { diff --git a/math/s_ctanhl.c b/math/s_ctanhl.c index 9c15bb3a4a..2fc54a85d0 100644 --- a/math/s_ctanhl.c +++ b/math/s_ctanhl.c @@ -40,7 +40,14 @@ __ctanhl (__complex__ long double x) if (__isinf_nsl (__real__ x)) { __real__ res = __copysignl (1.0, __real__ x); - __imag__ res = __copysignl (0.0, __imag__ x); + if (isfinite (__imag__ x) && fabsl (__imag__ x) > 1.0L) + { + long double sinix, cosix; + __sincosl (__imag__ x, &sinix, &cosix); + __imag__ res = __copysignl (0.0L, sinix * cosix); + } + else + __imag__ res = __copysignl (0.0, __imag__ x); } else if (__imag__ x == 0.0) { diff --git a/math/s_ctanl.c b/math/s_ctanl.c index 48ab81b64b..9090c1ad96 100644 --- a/math/s_ctanl.c +++ b/math/s_ctanl.c @@ -39,7 +39,14 @@ __ctanl (__complex__ long double x) { if (__isinf_nsl (__imag__ x)) { - __real__ res = __copysignl (0.0, __real__ x); + if (isfinite (__real__ x) && fabsl (__real__ x) > 1.0L) + { + long double sinrx, cosrx; + __sincosl (__real__ x, &sinrx, &cosrx); + __real__ res = __copysignl (0.0L, sinrx * cosrx); + } + else + __real__ res = __copysignl (0.0, __real__ x); __imag__ res = __copysignl (1.0, __imag__ x); } else if (__real__ x == 0.0) |