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, libgfortran] Improvement to float output


The attached patch checks for zero precision of formatted output of floats and outputs asterisks for e,g, and d formats.

With the following program gfortran currently gives a runtime internal error stating:

Internal Error: printf is broken

Which is not true.

program test
 50 FORMAT (g20.0)
 print '(a)', "01234567890123456789"
 write(*,50) -8.0D0
end program test

I would count the fix as simple and obvious. With this patch, the output is:

01234567890123456789
********************

This follows ifort example.

I will commit to trunk as obvious in a day or so unless objections.

NIST tested, regression tested.

Regards,

Jerry

2006-04-03 Jerry DeLisle <jvdelisle@gcc.gnu.org>

	* io/write.c (output_float): Add test for case of zero digits
	specified in fmt_d, fmt_e, and fmt_g and output asterisks.
Index: io/write.c
===================================================================
*** io/write.c	(revision 112632)
--- io/write.c	(working copy)
*************** output_float (st_parameter_dt *dtp, cons
--- 407,425 ----
  
    nzero_real = -1;
  
    /* We should always know the field width and precision.  */
    if (d < 0)
      internal_error (&dtp->common, "Unspecified precision");
+   
+   /* Zero decimal digits are meaningless unless F format.  */
+   if (d == 0 && ft != FMT_F )
+     {
+       out = write_block (dtp, w);
+ 	if (out == NULL)
+ 	  return;
+       memset (out, '*', w);
+       return;
+     }
  
    /* Use sprintf to print the number in the format +D.DDDDe+ddd
       For an N digit exponent, this gives us (32-6)-N digits after the

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