summaryrefslogtreecommitdiff
path: root/math/s_catanf.c
diff options
context:
space:
mode:
Diffstat (limited to 'math/s_catanf.c')
-rw-r--r--math/s_catanf.c83
1 files changed, 73 insertions, 10 deletions
diff --git a/math/s_catanf.c b/math/s_catanf.c
index 5a432471cd..0713565c86 100644
--- a/math/s_catanf.c
+++ b/math/s_catanf.c
@@ -20,7 +20,7 @@
#include <complex.h>
#include <math.h>
#include <math_private.h>
-
+#include <float.h>
__complex__ float
__catanf (__complex__ float x)
@@ -61,21 +61,84 @@ __catanf (__complex__ float x)
}
else
{
- float r2, num, den;
+ if (fabsf (__real__ x) >= 16.0f / FLT_EPSILON
+ || fabsf (__imag__ x) >= 16.0f / FLT_EPSILON)
+ {
+ __real__ res = __copysignf ((float) M_PI_2, __real__ x);
+ if (fabsf (__real__ x) <= 1.0f)
+ __imag__ res = 1.0f / __imag__ x;
+ else if (fabsf (__imag__ x) <= 1.0f)
+ __imag__ res = __imag__ x / __real__ x / __real__ x;
+ else
+ {
+ float h = __ieee754_hypotf (__real__ x / 2.0f,
+ __imag__ x / 2.0f);
+ __imag__ res = __imag__ x / h / h / 4.0f;
+ }
+ }
+ else
+ {
+ float den, absx, absy;
+
+ absx = fabsf (__real__ x);
+ absy = fabsf (__imag__ x);
+ if (absx < absy)
+ {
+ float t = absx;
+ absx = absy;
+ absy = t;
+ }
+
+ if (absy < FLT_EPSILON / 2.0f)
+ den = (1.0f - absx) * (1.0f + absx);
+ else if (absx >= 1.0f)
+ den = (1.0f - absx) * (1.0f + absx) - absy * absy;
+ 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;
+ if (fabsf (__imag__ x) == 1.0f
+ && fabsf (__real__ x) < FLT_EPSILON * FLT_EPSILON)
+ __imag__ res = (__copysignf (0.5f, __imag__ x)
+ * ((float) M_LN2
+ - __ieee754_logf (fabsf (__real__ x))));
+ else
+ {
+ float r2 = 0.0f, num, f;
- den = 1 - r2 - __imag__ x * __imag__ x;
+ if (fabsf (__real__ x) >= FLT_EPSILON * FLT_EPSILON)
+ r2 = __real__ x * __real__ x;
- __real__ res = 0.5 * __ieee754_atan2f (2.0 * __real__ x, den);
+ num = __imag__ x + 1.0f;
+ num = r2 + num * num;
- num = __imag__ x + 1.0;
- num = r2 + num * num;
+ den = __imag__ x - 1.0f;
+ den = r2 + den * den;
- den = __imag__ x - 1.0;
- den = r2 + den * den;
+ f = num / den;
+ if (f < 0.5f)
+ __imag__ res = 0.25f * __ieee754_logf (f);
+ else
+ {
+ num = 4.0f * __imag__ x;
+ __imag__ res = 0.25f * __log1pf (num / den);
+ }
+ }
+ }
- __imag__ res = 0.25 * __ieee754_logf (num / den);
+ if (fabsf (__real__ res) < FLT_MIN)
+ {
+ volatile float force_underflow = __real__ res * __real__ res;
+ (void) force_underflow;
+ }
+ if (fabsf (__imag__ res) < FLT_MIN)
+ {
+ volatile float force_underflow = __imag__ res * __imag__ res;
+ (void) force_underflow;
+ }
}
return res;