diff options
Diffstat (limited to 'math/s_catanf.c')
-rw-r--r-- | math/s_catanf.c | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/math/s_catanf.c b/math/s_catanf.c index d0d188ca0b..aa71e5e63a 100644 --- a/math/s_catanf.c +++ b/math/s_catanf.c @@ -61,27 +61,45 @@ __catanf (__complex__ float x) } else { - float r2, num, den, f; + 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 r2, num, den, f; - r2 = __real__ x * __real__ x; + r2 = __real__ x * __real__ x; - den = 1 - r2 - __imag__ x * __imag__ x; + den = 1 - r2 - __imag__ x * __imag__ x; - __real__ res = 0.5f * __ieee754_atan2f (2.0f * __real__ x, den); + __real__ res = 0.5f * __ieee754_atan2f (2.0f * __real__ x, den); - num = __imag__ x + 1.0f; - num = r2 + num * num; + num = __imag__ x + 1.0f; + num = r2 + num * num; - den = __imag__ x - 1.0f; - den = r2 + den * den; + den = __imag__ x - 1.0f; + 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); + 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); + } } if (fabsf (__real__ res) < FLT_MIN) |