about summary refs log tree commit diff
path: root/sysdeps/powerpc/fpu/e_hypot.c
diff options
context:
space:
mode:
authorAdhemerval Zanella <azanella@linux.vnet.ibm.com>2013-05-06 14:40:17 -0500
committerAdhemerval Zanella <azanella@linux.vnet.ibm.com>2013-05-06 14:40:17 -0500
commit16e616a72f9ac247520c0c7da99b99e229facdf9 (patch)
treeebecfcd57f8fec0766600b1bcc1d037fdd83ed8a /sysdeps/powerpc/fpu/e_hypot.c
parentd5e8275481e57cc7f3bd6ba435a7bbced9b97202 (diff)
downloadglibc-16e616a72f9ac247520c0c7da99b99e229facdf9.tar.gz
glibc-16e616a72f9ac247520c0c7da99b99e229facdf9.tar.xz
glibc-16e616a72f9ac247520c0c7da99b99e229facdf9.zip
PowerPC: fix hypot/hypof FP exceptions
This patch fixes hypot/hypotf spurious floating-point exceptions
generate by internal operations.
Diffstat (limited to 'sysdeps/powerpc/fpu/e_hypot.c')
-rw-r--r--sysdeps/powerpc/fpu/e_hypot.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/sysdeps/powerpc/fpu/e_hypot.c b/sysdeps/powerpc/fpu/e_hypot.c
index f23633946f..d8568d6e3f 100644
--- a/sysdeps/powerpc/fpu/e_hypot.c
+++ b/sysdeps/powerpc/fpu/e_hypot.c
@@ -26,6 +26,7 @@ static const double two600  = 4.149515568880993e+180;
 static const double two1022 = 4.49423283715579e+307;
 static const double twoM500 = 3.054936363499605e-151;
 static const double twoM600 = 2.4099198651028841e-181;
+static const double two60factor = 1.5592502418239997e+290;
 static const double pdnum   = 2.225073858507201e-308;
 
 /* __ieee754_hypot(x,y)
@@ -87,9 +88,20 @@ __ieee754_hypot (double x, double y)
       x = y;
       y = t;
     }
-  if (y == 0.0 || (x / y) > two60)
+  if (y == 0.0)
+    return x;
+  /* if y is higher enough, y * 2^60 might overflow. The tests if
+     y >= 1.7976931348623157e+308/2^60 (two60factor) and uses the
+     appropriate check to avoid the overflow exception generation.  */
+  if (y > two60factor)
     {
-      return x + y;
+      if ((x / y) > two60)
+	return x + y;
+    }
+  else
+    {
+      if (x > (y * two60))
+	return x + y;
     }
   if (x > two500)
     {