about summary refs log tree commit diff
path: root/math/s_ctanhf.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2015-09-17 21:21:39 +0000
committerJoseph Myers <joseph@codesourcery.com>2015-09-17 21:21:39 +0000
commit61f893789862db1dfdf188f77cd215bab0814d2c (patch)
tree9fd0f9b8395f451e24f8ce1c12253847740f8e31 /math/s_ctanhf.c
parentb8682397ab2db1aed7f25d0a0c7c81134a97c8c7 (diff)
downloadglibc-61f893789862db1dfdf188f77cd215bab0814d2c.tar.gz
glibc-61f893789862db1dfdf188f77cd215bab0814d2c.tar.xz
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/s_ctanhf.c')
-rw-r--r--math/s_ctanhf.c9
1 files changed, 8 insertions, 1 deletions
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)
 	{