aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c-family/c-cppbuiltin.cc2
-rw-r--r--gcc/testsuite/gcc.dg/c11-float-7.c24
-rw-r--r--gcc/testsuite/gcc.dg/c2x-float-12.c19
3 files changed, 44 insertions, 1 deletions
diff --git a/gcc/c-family/c-cppbuiltin.cc b/gcc/c-family/c-cppbuiltin.cc
index d4de5a0..4b8486c 100644
--- a/gcc/c-family/c-cppbuiltin.cc
+++ b/gcc/c-family/c-cppbuiltin.cc
@@ -279,7 +279,7 @@ builtin_define_float_constants (const char *name_prefix,
/* 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);
- if (fmt->pnan < fmt->p)
+ if (fmt->pnan < fmt->p && (c_dialect_cxx () || !flag_isoc2x))
/* This is an IBM extended double format, so 1.0 + any double is
representable precisely. */
sprintf (buf, "0x1p%d", fmt->emin - fmt->p);
diff --git a/gcc/testsuite/gcc.dg/c11-float-7.c b/gcc/testsuite/gcc.dg/c11-float-7.c
new file mode 100644
index 0000000..a8a7ef5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c11-float-7.c
@@ -0,0 +1,24 @@
+/* Test C11 definition of LDBL_EPSILON. Based on
+ gcc.target/powerpc/rs6000-ldouble-2.c. */
+/* { dg-do run } */
+/* { dg-options "-std=c11 -pedantic-errors" } */
+
+#include <float.h>
+
+extern void abort (void);
+extern void exit (int);
+
+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 ();
+ exit (0);
+}
diff --git a/gcc/testsuite/gcc.dg/c2x-float-12.c b/gcc/testsuite/gcc.dg/c2x-float-12.c
new file mode 100644
index 0000000..40900bd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-float-12.c
@@ -0,0 +1,19 @@
+/* Test C2x definition of LDBL_EPSILON. */
+/* { dg-do run } */
+/* { dg-options "-std=c2x -pedantic-errors" } */
+
+#include <float.h>
+
+extern void abort (void);
+extern void exit (int);
+
+int
+main (void)
+{
+ volatile long double x = 1.0L;
+ for (int i = 0; i < LDBL_MANT_DIG - 1; i++)
+ x /= 2;
+ if (x != LDBL_EPSILON)
+ abort ();
+ exit (0);
+}