From caf84319c1614d8aa867d8db80219f4e9b1bf735 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Tue, 30 Apr 2013 11:27:35 +0000 Subject: Fix catan, catanh inaccuracy from atan2 denominators near 0 (bug 15416). --- math/s_catanl.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'math/s_catanl.c') diff --git a/math/s_catanl.c b/math/s_catanl.c index 17ab62d340..1a815ad776 100644 --- a/math/s_catanl.c +++ b/math/s_catanl.c @@ -85,14 +85,30 @@ __catanl (__complex__ long double x) } else { - long double r2, num, den, f; + long double r2, num, den, f, absx, absy; - r2 = __real__ x * __real__ x; + absx = fabsl (__real__ x); + absy = fabsl (__imag__ x); + if (absx < absy) + { + long double t = absx; + absx = absy; + absy = t; + } - den = 1 - r2 - __imag__ x * __imag__ x; + if (absx >= 1.0L) + den = (1.0L - absx) * (1.0L + absx) - absy * absy; + else if (absx >= 0.75L && absy < LDBL_EPSILON / 2.0L) + den = (1.0L - absx) * (1.0L + absx); + else if (absx >= 0.75L || absy >= 0.5L) + den = -__x2y2m1l (absx, absy); + else + den = (1.0L - absx) * (1.0L + absx) - absy * absy; __real__ res = 0.5L * __ieee754_atan2l (2.0L * __real__ x, den); + r2 = __real__ x * __real__ x; + num = __imag__ x + 1.0L; num = r2 + num * num; -- cgit 1.4.1