c-cppbuiltin.c (builtin_define_float_constants): Set __*_EPSILON__ for IBM long doubl...
authorGeoffrey Keating <geoffk@apple.com>
Fri, 7 Jan 2005 00:19:23 +0000 (00:19 +0000)
committerGeoffrey Keating <geoffk@gcc.gnu.org>
Fri, 7 Jan 2005 00:19:23 +0000 (00:19 +0000)
* c-cppbuiltin.c (builtin_define_float_constants): Set __*_EPSILON__
for IBM long double format correctly.

From-SVN: r93021

gcc/ChangeLog
gcc/c-cppbuiltin.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/rs6000-ldouble-2.c [new file with mode: 0644]

index bdadf4a91472ae89f797a38f35385f4f3dc20f74..44ef9c7cb30253b8e8aeb35cb10db97d66092e09 100644 (file)
@@ -1,3 +1,8 @@
+2005-01-06  Geoffrey Keating  <geoffk@apple.com>
+
+       * c-cppbuiltin.c (builtin_define_float_constants): Set __*_EPSILON__
+       for IBM long double format correctly.
+
 2005-01-06  Daniel Berlin <dberlin@dberlin.org>
        
        Fix PR tree-optimization/18792
index cedf9e7a46e3e1fb3d3d266e5bbbfca3ba72e435..2c9039ef45fa697df3d04daf9791a2fec632394a 100644 (file)
@@ -219,7 +219,12 @@ builtin_define_float_constants (const char *name_prefix, const char *fp_suffix,
   /* The difference between 1 and the least value greater than 1 that is
      representable in the given floating point type, b**(1-p).  */
   sprintf (name, "__%s_EPSILON__", name_prefix);
-  sprintf (buf, "0x1p%d", (1 - fmt->p) * fmt->log2_b);
+  if (fmt->pnan < fmt->p)
+    /* This is an IBM extended double format, so 1.0 + any double is
+       representable precisely.  */
+      sprintf (buf, "0x1p%d", (fmt->emin - fmt->p) * fmt->log2_b);
+    else      
+      sprintf (buf, "0x1p%d", (1 - fmt->p) * fmt->log2_b);
   builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix);
 
   /* For C++ std::numeric_limits<T>::denorm_min.  The minimum denormalized
index d5638925572a4f2f62bcbc19dda9fbc47ced0abf..bb8bf45d9145ca3ed14c7afe2105be6f9cdb554a 100644 (file)
@@ -1,3 +1,7 @@
+2005-01-06  Geoffrey Keating  <geoffk@apple.com>
+
+       * gcc.dg/rs6000-ldouble-2.c: New.
+
 2005-01-06  Mark Mitchell  <mark@codesourcery.com>
 
         PR c++/19244
diff --git a/gcc/testsuite/gcc.dg/rs6000-ldouble-2.c b/gcc/testsuite/gcc.dg/rs6000-ldouble-2.c
new file mode 100644 (file)
index 0000000..3ef5131
--- /dev/null
@@ -0,0 +1,22 @@
+/* { dg-do run { target powerpc*-*-darwin* powerpc*-*-aix* powerpc64-*-linux rs6000-*-* } } */
+/* { dg-options "-mlong-double-128" } */
+
+/* Check that LDBL_EPSILON is right for 'long double'.  */
+
+#include <float.h>
+
+extern void abort (void);
+
+int main(void)
+{
+  volatile long double ee = 1.0;
+  long double eps = ee;
+  while (ee + 1.0 != 1.0)
+    {
+      eps = ee;
+      ee = eps / 2;
+    }
+  if (eps != LDBL_EPSILON)
+    abort ();
+  return 0;
+}