This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/60128] [4.8/4.9 Regression] Wrong ouput using en edit descriptor


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60128

--- Comment #7 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
The following patch fixes the issues reported in comment 6

--- ../_clean/libgfortran/io/write_float.def    2014-01-21 08:30:57.000000000
+0100
+++ libgfortran/io/write_float.def    2014-02-18 09:59:04.000000000 +0100
@@ -1157,10 +1153,23 @@ OUTPUT_FLOAT_FMT_G(16,L)

 #define EN_PREC(x,y)\
 {\
-    GFC_REAL_ ## x tmp;                \
+    GFC_REAL_ ## x tmp, one = 1.0;                \
     tmp = * (GFC_REAL_ ## x *)source;                \
     if (ISFINITE (y,tmp))                    \
-      nprinted = DTOA(y,0,tmp);                    \
+      {\
+    nprinted = DTOA(y,0,tmp);                    \
+    int e = atoi (&buffer[4]); \
+    if (buffer[1] == '1') \
+      {\
+        tmp = (calculate_exp_ ## x (-e)) * tmp; \ 
+        tmp = one - (tmp < 0 ? -tmp : tmp); \
+        if (tmp > 0) \
+          e = e - 1; \
+      }\
+    nbefore = e%3; \
+    if (nbefore < 0) \
+      nbefore = 3 + nbefore; \
+      }\
     else\
       nprinted = -1;\
 }\
@@ -1172,6 +1181,7 @@ determine_en_precision (st_parameter_dt 
   int nprinted;
   char buffer[10];
   const size_t size = 10;
+  int nbefore; /* digits before decimal point - 1.  */

   switch (len)
     {
@@ -1204,16 +1214,6 @@ determine_en_precision (st_parameter_dt 
   if (nprinted == -1)
     return -1;

-  int e = atoi (&buffer[5]);
-  int nbefore; /* digits before decimal point - 1.  */
-  if (e >= 0)
-    nbefore = e % 3;
-  else
-    {
-      nbefore = (-e) % 3;
-      if (nbefore != 0)
-    nbefore = 3 - nbefore;
-    }
   int prec = f->u.real.d + nbefore;
   if (dtp->u.p.current_unit->round_status != ROUND_UNSPECIFIED
       && dtp->u.p.current_unit->round_status != ROUND_PROCDEFINED)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]