about summary refs log tree commit diff
path: root/math/s_catanl.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2013-05-01 10:07:00 +0000
committerJoseph Myers <joseph@codesourcery.com>2013-05-01 10:07:00 +0000
commit10de07f5fdd9eaf3a808d4461401f5b661095614 (patch)
tree844a1ed48df767e65d46a429f0e1b062e0e2fad5 /math/s_catanl.c
parentcb4d54147e620f4267d1c675bf2daec0a8e7c809 (diff)
downloadglibc-10de07f5fdd9eaf3a808d4461401f5b661095614.tar.gz
glibc-10de07f5fdd9eaf3a808d4461401f5b661095614.tar.xz
glibc-10de07f5fdd9eaf3a808d4461401f5b661095614.zip
Fix catan, catanh spurious underflows (bug 15423).
Diffstat (limited to 'math/s_catanl.c')
-rw-r--r--math/s_catanl.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/math/s_catanl.c b/math/s_catanl.c
index 1a815ad776..9bb5e012e6 100644
--- a/math/s_catanl.c
+++ b/math/s_catanl.c
@@ -85,7 +85,7 @@ __catanl (__complex__ long double x)
 	}
       else
 	{
-	  long double r2, num, den, f, absx, absy;
+	  long double den, absx, absy;
 
 	  absx = fabsl (__real__ x);
 	  absy = fabsl (__imag__ x);
@@ -96,10 +96,10 @@ __catanl (__complex__ long double x)
 	      absy = t;
 	    }
 
-	  if (absx >= 1.0L)
-	    den = (1.0L - absx) * (1.0L + absx) - absy * absy;
-	  else if (absx >= 0.75L && absy < LDBL_EPSILON / 2.0L)
+	  if (absy < LDBL_EPSILON / 2.0L)
 	    den = (1.0L - absx) * (1.0L + absx);
+	  else if (absx >= 1.0L)
+	    den = (1.0L - absx) * (1.0L + absx) - absy * absy;
 	  else if (absx >= 0.75L || absy >= 0.5L)
 	    den = -__x2y2m1l (absx, absy);
 	  else
@@ -107,21 +107,31 @@ __catanl (__complex__ long double x)
 
 	  __real__ res = 0.5L * __ieee754_atan2l (2.0L * __real__ x, den);
 
-	  r2 = __real__ x * __real__ x;
+	  if (fabsl (__imag__ x) == 1.0L
+	      && fabsl (__real__ x) < LDBL_EPSILON * LDBL_EPSILON)
+	    __imag__ res = (__copysignl (0.5L, __imag__ x)
+			    * (M_LN2l - __ieee754_logl (fabsl (__real__ x))));
+	  else
+	    {
+	      long double r2 = 0.0L, num, f;
 
-	  num = __imag__ x + 1.0L;
-	  num = r2 + num * num;
+	      if (fabsl (__real__ x) >= LDBL_EPSILON * LDBL_EPSILON)
+		r2 = __real__ x * __real__ x;
 
-	  den = __imag__ x - 1.0L;
-	  den = r2 + den * den;
+	      num = __imag__ x + 1.0L;
+	      num = r2 + num * num;
 
-	  f = num / den;
-	  if (f < 0.5L)
-	    __imag__ res = 0.25L * __ieee754_logl (f);
-	  else
-	    {
-	      num = 4.0L * __imag__ x;
-	      __imag__ res = 0.25L * __log1pl (num / den);
+	      den = __imag__ x - 1.0L;
+	      den = r2 + den * den;
+
+	      f = num / den;
+	      if (f < 0.5L)
+		__imag__ res = 0.25L * __ieee754_logl (f);
+	      else
+		{
+		  num = 4.0L * __imag__ x;
+		  __imag__ res = 0.25L * __log1pl (num / den);
+		}
 	    }
 	}