about summary refs log tree commit diff
path: root/math/s_catanf.c
diff options
context:
space:
mode:
Diffstat (limited to 'math/s_catanf.c')
-rw-r--r--math/s_catanf.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/math/s_catanf.c b/math/s_catanf.c
index aa71e5e63a..698e2af461 100644
--- a/math/s_catanf.c
+++ b/math/s_catanf.c
@@ -78,14 +78,30 @@ __catanf (__complex__ float x)
 	}
       else
 	{
-	  float r2, num, den, f;
+	  float r2, num, den, f, absx, absy;
 
-	  r2 = __real__ x * __real__ x;
+	  absx = fabsf (__real__ x);
+	  absy = fabsf (__imag__ x);
+	  if (absx < absy)
+	    {
+	      float t = absx;
+	      absx = absy;
+	      absy = t;
+	    }
 
-	  den = 1 - r2 - __imag__ x * __imag__ x;
+	  if (absx >= 1.0f)
+	    den = (1.0f - absx) * (1.0f + absx) - absy * absy;
+	  else if (absx >= 0.75f && absy < FLT_EPSILON / 2.0f)
+	    den = (1.0f - absx) * (1.0f + absx);
+	  else if (absx >= 0.75f || absy >= 0.5f)
+	    den = -__x2y2m1f (absx, absy);
+	  else
+	    den = (1.0f - absx) * (1.0f + absx) - absy * absy;
 
 	  __real__ res = 0.5f * __ieee754_atan2f (2.0f * __real__ x, den);
 
+	  r2 = __real__ x * __real__ x;
+
 	  num = __imag__ x + 1.0f;
 	  num = r2 + num * num;