summaryrefslogtreecommitdiff
path: root/math/s_catanl.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2013-04-30 11:27:35 +0000
committerJoseph Myers <joseph@codesourcery.com>2013-04-30 11:27:35 +0000
commitcaf84319c1614d8aa867d8db80219f4e9b1bf735 (patch)
tree08263d4ddcdf643fc258daeb43718821a2e2fbde /math/s_catanl.c
parent6dbe713d85fecc1bee99713d745413106af200b7 (diff)
downloadglibc-caf84319c1614d8aa867d8db80219f4e9b1bf735.tar.gz
Fix catan, catanh inaccuracy from atan2 denominators near 0 (bug 15416).
Diffstat (limited to 'math/s_catanl.c')
-rw-r--r--math/s_catanl.c22
1 files changed, 19 insertions, 3 deletions
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;