This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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]

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


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. */





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