diff options
author | Joseph Myers <joseph@codesourcery.com> | 2013-04-30 11:27:35 +0000 |
---|---|---|
committer | Joseph Myers <joseph@codesourcery.com> | 2013-04-30 11:27:35 +0000 |
commit | caf84319c1614d8aa867d8db80219f4e9b1bf735 (patch) | |
tree | 08263d4ddcdf643fc258daeb43718821a2e2fbde /math/s_catan.c | |
parent | 6dbe713d85fecc1bee99713d745413106af200b7 (diff) | |
download | glibc-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_catan.c')
-rw-r--r-- | math/s_catan.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/math/s_catan.c b/math/s_catan.c index 4b7fbad30a..3a041f2245 100644 --- a/math/s_catan.c +++ b/math/s_catan.c @@ -77,14 +77,30 @@ __catan (__complex__ double x) } else { - double r2, num, den, f; + double r2, num, den, f, absx, absy; - r2 = __real__ x * __real__ x; + absx = fabs (__real__ x); + absy = fabs (__imag__ x); + if (absx < absy) + { + double t = absx; + absx = absy; + absy = t; + } - den = 1 - r2 - __imag__ x * __imag__ x; + if (absx >= 1.0) + den = (1.0 - absx) * (1.0 + absx) - absy * absy; + else if (absx >= 0.75 && absy < DBL_EPSILON / 2.0) + den = (1.0 - absx) * (1.0 + absx); + else if (absx >= 0.75 || absy >= 0.5) + den = -__x2y2m1 (absx, absy); + else + den = (1.0 - absx) * (1.0 + absx) - absy * absy; __real__ res = 0.5 * __ieee754_atan2 (2.0 * __real__ x, den); + r2 = __real__ x * __real__ x; + num = __imag__ x + 1.0; num = r2 + num * num; |