[patch,libfortran] PR37834 write(*,'(f0.0)') 0.0 prints "." instead of "0."

Jerry DeLisle jvdelisle@verizon.net
Sun Oct 19 04:23:00 GMT 2008


Hi folks,

The following patch fixes the test case for this PR by setting width to 2 for 
the special case of w == 0 and value of zero.

I also handles one other special case with f1.0 as format specifier.  Before 
this patch, gfortran would print '.' which seems of not much value.  The 
standard (10.5.1.2.1) referenced in the commented code implies that the decimal 
point can be optional for input fields.  Then, for output fields it says "The 
optional zero shall appear if there would otherwise be no digits in the output 
field."

Therefore, I suggest we emit '0' instead of '.' in this case.

   write(*,'(f0.0)') 0.0
   write(*,'(f1.0)') 0.0
   end

Before patch this produces:

$ ./a.out
.
.

After patch we get:

$ ./a.out
0.
0

Regression tested on x86-64.

OK to commit with an appropriate test case?

Jerry

Index: write_float.def
===================================================================
--- write_float.def	(revision 141207)
+++ write_float.def	(working copy)
@@ -119,6 +119,22 @@ output_float (st_parameter_dt *dtp, cons
  	sign = calculate_sign (dtp, sign_bit);
        else
  	sign = calculate_sign (dtp, 0);
+
+      /* Handle special cases.  */
+      if (w == 0)
+	w = 2;
+
+      /* For this one we choose to not output a decimal point.
+	 F95 10.5.1.2.1  */
+      if (w == 1 && ft == FMT_F)
+	{
+	  out = write_block (dtp, w);
+	  if (out == NULL)
+	    return;
+	  *out = '0';
+	  return;
+	}
+	
      }

    /* Normalize the fractional component.  */






More information about the Fortran mailing list