[patch] fix decimal floating-point macros in <float.h>

Janis Johnson janis187@us.ibm.com
Thu Dec 18 23:37:00 GMT 2008


GCC was defining decimal float macro names left over from an earlier
draft of TR 24732, and incorrect values for other macros.  This patch
fixes both of those problems.

Tested with full bootstrap and regression testing on powerpc64-linux
with -m32/-m64, and by C bootstrap and running dfp tests on i686-linux
configured for bid and dpd DFP support.  OK for trunk?

2008-12-18  Janis Johnson  <janis187@us.ibm.com>

gcc/
	PR c/34252
	ginclude/float.h: Rename DECnn_DEN to DECnn_SUBNORMAL_MIN.
	real.c (decimal_single_format): Correct values of emin and emax.
	(decimal_double_format): Ditto.
	(decimal_quad_format): Ditto.
	c-cppbuiltin.c (builtin_define_decimal_float_constants): Adjust
	computation of DECnn_MIN and DECnn_MAX for corrected values of
	emin and emax.  Define __DECnn_SUBNORMAL_MIN__ instead of
	__DECnn_MIN__, and adjust its computation for the corrected value
	of emin.
	
gcc/testsuite/
	PR c/34252
	gcc.dg/dfp/decfloat-constants.c: Check for DECnn_SUBNORMAL_MIN
	instead of DECnn_DEN.  Support -DDBG to list lines that fail.

Index: gcc/ginclude/float.h
===================================================================
--- gcc/ginclude/float.h	(revision 142799)
+++ gcc/ginclude/float.h	(working copy)
@@ -214,13 +214,13 @@
 #define DEC64_MIN	__DEC64_MIN__
 #define DEC128_MIN	__DEC128_MIN__
 
-/* Minimum denormalized positive floating-point number. */
-#undef DEC32_DEN
-#undef DEC64_DEN
-#undef DEC128_DEN
-#define DEC32_DEN       __DEC32_DEN__
-#define DEC64_DEN       __DEC64_DEN__
-#define DEC128_DEN      __DEC128_DEN__
+/* Minimum subnormal positive floating-point number. */
+#undef DEC32_SUBNORMAL_MIN
+#undef DEC64_SUBNORMAL_MIN
+#undef DEC128_SUBNORMAL_MIN
+#define DEC32_SUBNORMAL_MIN       __DEC32_SUBNORMAL_MIN__
+#define DEC64_SUBNORMAL_MIN       __DEC64_SUBNORMAL_MIN__
+#define DEC128_SUBNORMAL_MIN      __DEC128_SUBNORMAL_MIN__
 
 /* The floating-point expression evaluation method.
          -1  indeterminate
Index: gcc/real.c
===================================================================
--- gcc/real.c	(revision 142799)
+++ gcc/real.c	(working copy)
@@ -4447,8 +4447,8 @@
     10, 
     7,
     7,
-    -95,
-    96,
+    -94,
+    97,
     31,
     31,
     false,
@@ -4469,8 +4469,8 @@
     10,
     16,
     16,
-    -383,
-    384,
+    -382,
+    385,
     63,
     63,
     false,
@@ -4491,8 +4491,8 @@
     10,
     34,
     34,
-    -6143,
-    6144,
+    -6142,
+    6145,
     127,
     127,
     false,
Index: gcc/c-cppbuiltin.c
===================================================================
--- gcc/c-cppbuiltin.c	(revision 142799)
+++ gcc/c-cppbuiltin.c	(working copy)
@@ -279,7 +279,7 @@
 
   /* Compute the minimum representable value.  */
   sprintf (name, "__%s_MIN__", name_prefix);
-  sprintf (buf, "1E%d%s", fmt->emin, suffix);
+  sprintf (buf, "1E%d%s", fmt->emin - 1, suffix);
   builtin_define_with_value (name, buf, 0); 
 
   /* Compute the maximum representable value.  */
@@ -292,8 +292,9 @@
 	*p++ = '.';
     }
   *p = 0;
-  /* fmt->p plus 1, to account for the decimal point.  */
-  sprintf (&buf[fmt->p + 1], "E%d%s", fmt->emax, suffix); 
+  /* fmt->p plus 1, to account for the decimal point and fmt->emax
+     minus 1 because the digits are nines, not 1.0.  */
+  sprintf (&buf[fmt->p + 1], "E%d%s", fmt->emax - 1, suffix); 
   builtin_define_with_value (name, buf, 0);
 
   /* Compute epsilon (the difference between 1 and least value greater
@@ -302,8 +303,8 @@
   sprintf (buf, "1E-%d%s", fmt->p - 1, suffix);
   builtin_define_with_value (name, buf, 0);
 
-  /* Minimum denormalized positive decimal value.  */
-  sprintf (name, "__%s_DEN__", name_prefix);
+  /* Minimum subnormal positive decimal value.  */
+  sprintf (name, "__%s_SUBNORMAL_MIN__", name_prefix);
   p = buf;
   for (digits = fmt->p; digits > 1; digits--)
     {
@@ -312,7 +313,7 @@
 	*p++ = '.';
     }
   *p = 0;
-  sprintf (&buf[fmt->p], "1E%d%s", fmt->emin, suffix); 
+  sprintf (&buf[fmt->p], "1E%d%s", fmt->emin - 1, suffix); 
   builtin_define_with_value (name, buf, 0);
 }
 
Index: gcc/testsuite/gcc.dg/dfp/decfloat-constants.c
===================================================================
--- gcc/testsuite/gcc.dg/dfp/decfloat-constants.c	(revision 142799)
+++ gcc/testsuite/gcc.dg/dfp/decfloat-constants.c	(working copy)
@@ -14,36 +14,50 @@
 #include <float.h>
 
 extern void abort (void);
+static int failcnt;
 
+/* Support compiling the test to report individual failures; default is
+   to abort as soon as a check fails.  */
+#ifdef DBG
+#include <stdio.h>
+#define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; }
+#else
+#define FAILURE abort ();
+#endif
+
 int main ()
 {
-  if (DEC32_MANT_DIG != 7) abort();
-  if (DEC64_MANT_DIG != 16) abort();
-  if (DEC128_MANT_DIG != 34) abort();
+  if (DEC32_MANT_DIG != 7) FAILURE
+  if (DEC64_MANT_DIG != 16) FAILURE
+  if (DEC128_MANT_DIG != 34) FAILURE
 
-  if (DEC32_MIN_EXP != -95) abort();
-  if (DEC64_MIN_EXP != -383) abort();
-  if (DEC128_MIN_EXP != -6143) abort();
+  if (DEC32_MIN_EXP != -94) FAILURE
+  if (DEC64_MIN_EXP != -382) FAILURE
+  if (DEC128_MIN_EXP != -6142) FAILURE
 
-  if (DEC32_MAX_EXP != 96) abort();
-  if (DEC64_MAX_EXP != 384) abort();
-  if (DEC128_MAX_EXP != 6144) abort();
+  if (DEC32_MAX_EXP != 97) FAILURE
+  if (DEC64_MAX_EXP != 385) FAILURE
+  if (DEC128_MAX_EXP != 6145) FAILURE
 
-  if (DEC32_MAX != 9.999999E96DF) abort();
-  if (DEC64_MAX != 9.999999999999999E384DD) abort();
-  if (DEC128_MAX != 9.999999999999999999999999999999999E6144DL) abort();
+  if (DEC32_MAX != 9.999999E96DF) FAILURE
+  if (DEC64_MAX != 9.999999999999999E384DD) FAILURE
+  if (DEC128_MAX != 9.999999999999999999999999999999999E6144DL) FAILURE
 
-  if (DEC32_EPSILON != 1E-6DF) abort();
-  if (DEC64_EPSILON != 1E-15DD) abort();
-  if (DEC128_EPSILON != 1E-33DL) abort();
+  if (DEC32_EPSILON != 1E-6DF) FAILURE
+  if (DEC64_EPSILON != 1E-15DD) FAILURE
+  if (DEC128_EPSILON != 1E-33DL) FAILURE
   
-  if (DEC32_MIN != 1E-95DF) abort();
-  if (DEC64_MIN != 1E-383DD) abort();
-  if (DEC128_MIN != 1E-6143DL) abort();
+  if (DEC32_MIN != 1E-95DF) FAILURE
+  if (DEC64_MIN != 1E-383DD) FAILURE
+  if (DEC128_MIN != 1E-6143DL) FAILURE
 
-  if (DEC32_DEN != 0.000001E-95DF) abort();
-  if (DEC64_DEN != 0.000000000000001E-383DD) abort();
-  if (DEC128_DEN != 0.000000000000000000000000000000001E-6143DL) abort();
+  if (DEC32_SUBNORMAL_MIN != 0.000001E-95DF) FAILURE
+  if (DEC64_SUBNORMAL_MIN != 0.000000000000001E-383DD) FAILURE
+  if (DEC128_SUBNORMAL_MIN != 0.000000000000000000000000000000001E-6143DL)
+    FAILURE
 
+  if (failcnt != 0)
+    abort ();
+
   return 0;
 }




More information about the Gcc-patches mailing list