about summary refs log tree commit diff
path: root/math/s_catanhl.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2013-04-30 11:27:35 +0000
committerJoseph Myers <joseph@codesourcery.com>2013-04-30 11:27:35 +0000
commitcaf84319c1614d8aa867d8db80219f4e9b1bf735 (patch)
tree08263d4ddcdf643fc258daeb43718821a2e2fbde /math/s_catanhl.c
parent6dbe713d85fecc1bee99713d745413106af200b7 (diff)
downloadglibc-caf84319c1614d8aa867d8db80219f4e9b1bf735.tar.gz
glibc-caf84319c1614d8aa867d8db80219f4e9b1bf735.tar.xz
glibc-caf84319c1614d8aa867d8db80219f4e9b1bf735.zip
Fix catan, catanh inaccuracy from atan2 denominators near 0 (bug 15416).
Diffstat (limited to 'math/s_catanhl.c')
-rw-r--r--math/s_catanhl.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/math/s_catanhl.c b/math/s_catanhl.c
index 64c30b5573..ab75b807e0 100644
--- a/math/s_catanhl.c
+++ b/math/s_catanhl.c
@@ -97,7 +97,25 @@ __catanhl (__complex__ long double x)
 	      __real__ res = 0.25L * __log1pl (num / den);
 	    }
 
-	  den = 1 - __real__ x * __real__ x - i2;
+	  long double absx, absy;
+
+	  absx = fabsl (__real__ x);
+	  absy = fabsl (__imag__ x);
+	  if (absx < absy)
+	    {
+	      long double t = absx;
+	      absx = absy;
+	      absy = t;
+	    }
+
+	  if (absx >= 1.0L)
+	    den = (1.0L - absx) * (1.0L + absx) - absy * absy;
+	  else if (absx >= 0.75 && absy < LDBL_EPSILON / 2.0L)
+	    den = (1.0L - absx) * (1.0L + absx);
+	  else if (absx >= 0.75L || absy >= 0.5L)
+	    den = -__x2y2m1l (absx, absy);
+	  else
+	    den = (1.0L - absx) * (1.0L + absx) - absy * absy;
 
 	  __imag__ res = 0.5L * __ieee754_atan2l (2.0L * __imag__ x, den);
 	}