From 0a1b2ae6f6d511519ab3c0ccbf54982ae65bc444 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Thu, 21 Mar 2013 10:27:10 +0000 Subject: Fix casinh inaccuracy for argument with imaginary part 1 (bug 15287). --- math/k_casinhf.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'math/k_casinhf.c') diff --git a/math/k_casinhf.c b/math/k_casinhf.c index 7ff4b03a1c..4d1a92f813 100644 --- a/math/k_casinhf.c +++ b/math/k_casinhf.c @@ -77,6 +77,32 @@ __kernel_casinhf (__complex__ float x, int adj) else __imag__ res = __ieee754_atan2f (s, rx); } + else if (ix == 1.0f && rx < 0.5f) + { + if (rx < FLT_EPSILON / 8.0f) + { + __real__ res = __log1pf (2.0f * (rx + __ieee754_sqrtf (rx))) / 2.0f; + if (adj) + __imag__ res = __ieee754_atan2f (__ieee754_sqrtf (rx), + __copysignf (1.0f, __imag__ x)); + else + __imag__ res = __ieee754_atan2f (1.0f, __ieee754_sqrtf (rx)); + } + else + { + float d = rx * __ieee754_sqrtf (4.0f + rx * rx); + float s1 = __ieee754_sqrtf ((d + rx * rx) / 2.0f); + float s2 = __ieee754_sqrtf ((d - rx * rx) / 2.0f); + + __real__ res = __log1pf (rx * rx + d + 2.0f * (rx * s1 + s2)) / 2.0f; + if (adj) + __imag__ res = __ieee754_atan2f (rx + s1, + __copysignf (1.0f + s2, + __imag__ x)); + else + __imag__ res = __ieee754_atan2f (1.0f + s2, rx + s1); + } + } else { __real__ y = (rx - ix) * (rx + ix) + 1.0f; -- cgit 1.4.1