about summary refs log tree commit diff
path: root/math/s_casinh.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2013-01-04 13:25:17 +0000
committerJoseph Myers <joseph@codesourcery.com>2013-01-04 13:25:17 +0000
commitcdc1c96fbafce8c16ee0e75d466f4358e6a860db (patch)
treee6f6446e5081847ac19a5236c891d39e64c0a360 /math/s_casinh.c
parent6420d207bb10d966163c52e4e607a1e48e6bb13f (diff)
downloadglibc-cdc1c96fbafce8c16ee0e75d466f4358e6a860db.tar.gz
glibc-cdc1c96fbafce8c16ee0e75d466f4358e6a860db.tar.xz
glibc-cdc1c96fbafce8c16ee0e75d466f4358e6a860db.zip
Fix casinh, casin inaccuracy from cancellation (bug 14994).
Diffstat (limited to 'math/s_casinh.c')
-rw-r--r--math/s_casinh.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/math/s_casinh.c b/math/s_casinh.c
index 8c4aa19f63..acdf1a1e5a 100644
--- a/math/s_casinh.c
+++ b/math/s_casinh.c
@@ -62,20 +62,24 @@ __casinh (__complex__ double x)
     }
   else
     {
+      double rx, ix;
       __complex__ double y;
 
-      __real__ y = (__real__ x - __imag__ x) * (__real__ x + __imag__ x) + 1.0;
-      __imag__ y = 2.0 * __real__ x * __imag__ x;
+      /* Avoid cancellation by reducing to the first quadrant.  */
+      rx = fabs (__real__ x);
+      ix = fabs (__imag__ x);
+
+      __real__ y = (rx - ix) * (rx + ix) + 1.0;
+      __imag__ y = 2.0 * rx * ix;
 
       y = __csqrt (y);
 
-      __real__ y += __real__ x;
-      __imag__ y += __imag__ x;
+      __real__ y += rx;
+      __imag__ y += ix;
 
       res = __clog (y);
 
-      /* Ensure zeros have correct sign and results are correct if
-	 very close to branch cuts.  */
+      /* Give results the correct sign for the original argument.  */
       __real__ res = __copysign (__real__ res, __real__ x);
       __imag__ res = __copysign (__imag__ res, __imag__ x);
     }