From 61f893789862db1dfdf188f77cd215bab0814d2c Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Thu, 17 Sep 2015 21:21:39 +0000 Subject: 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 . Tested for x86_64. 2015-09-17 Joseph Myers Andreas Schwab [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. --- math/s_ctanl.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'math/s_ctanl.c') 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) -- cgit v1.2.3