This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
fix LDBL_EPSILON on powerpc with 128-bit long double
- From: gkeating at apple dot com (Geoffrey Keating)
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 6 Jan 2005 16:17:43 -0800 (PST)
- Subject: fix LDBL_EPSILON on powerpc with 128-bit long double
The C standard gives a definition for LDBL_EPSILON that means it
should be very small for the 128-bit long double.
Bootstrapped & tested on powerpc-darwin.
--
- Geoffrey Keating <geoffk@apple.com>
===File ~/patches/darwin-3894597.patch======================
2004-12-16 Geoffrey Keating <geoffk@apple.com>
* c-cppbuiltin.c (builtin_define_float_constants): Set __*_EPSILON__
for IBM long double format correctly.
Index: gcc/testsuite/ChangeLog
2004-12-16 Geoffrey Keating <geoffk@apple.com>
* gcc.dg/rs6000-ldouble-2.c: New.
Index: gcc/c-cppbuiltin.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-cppbuiltin.c,v
retrieving revision 1.7.4.7.2.8
diff -u -p -u -p -r1.7.4.7.2.8 c-cppbuiltin.c
--- gcc/c-cppbuiltin.c 11 Nov 2004 01:11:37 -0000 1.7.4.7.2.8
+++ gcc/c-cppbuiltin.c 16 Dec 2004 23:25:59 -0000
@@ -223,7 +223,12 @@ builtin_define_float_constants (const ch
/* 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: gcc/testsuite/gcc.dg/rs6000-ldouble-2.c
===================================================================
RCS file: gcc/testsuite/gcc.dg/rs6000-ldouble-2.c
diff -N gcc/testsuite/gcc.dg/rs6000-ldouble-2.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/gcc.dg/rs6000-ldouble-2.c 16 Dec 2004 23:26:03 -0000
@@ -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;
+}
============================================================