aboutsummaryrefslogtreecommitdiff
path: root/math/s_catanhf.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_catanhf.c
parent6dbe713d85fecc1bee99713d745413106af200b7 (diff)
downloadglibc-caf84319c1614d8aa867d8db80219f4e9b1bf735.tar
glibc-caf84319c1614d8aa867d8db80219f4e9b1bf735.tar.gz
glibc-caf84319c1614d8aa867d8db80219f4e9b1bf735.tar.bz2
glibc-caf84319c1614d8aa867d8db80219f4e9b1bf735.zip
Fix catan, catanh inaccuracy from atan2 denominators near 0 (bug 15416).
Diffstat (limited to 'math/s_catanhf.c')
-rw-r--r--math/s_catanhf.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/math/s_catanhf.c b/math/s_catanhf.c
index 3e87942369..249deb5669 100644
--- a/math/s_catanhf.c
+++ b/math/s_catanhf.c
@@ -90,7 +90,25 @@ __catanhf (__complex__ float x)
__real__ res = 0.25f * __log1pf (num / den);
}
- den = 1 - __real__ x * __real__ x - i2;
+ float absx, absy;
+
+ absx = fabsf (__real__ x);
+ absy = fabsf (__imag__ x);
+ if (absx < absy)
+ {
+ float t = absx;
+ absx = absy;
+ absy = t;
+ }
+
+ if (absx >= 1.0f)
+ den = (1.0f - absx) * (1.0f + absx) - absy * absy;
+ else if (absx >= 0.75f && absy < FLT_EPSILON / 2.0f)
+ den = (1.0f - absx) * (1.0f + absx);
+ else if (absx >= 0.75f || absy >= 0.5f)
+ den = -__x2y2m1f (absx, absy);
+ else
+ den = (1.0f - absx) * (1.0f + absx) - absy * absy;
__imag__ res = 0.5f * __ieee754_atan2f (2.0f * __imag__ x, den);
}