This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch, libgfortran] PR47567 Wrong output for small absolute values with F editing
- From: Jerry DeLisle <jvdelisle at frontier dot com>
- To: gfortran <fortran at gcc dot gnu dot org>
- Cc: gcc patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 18 Feb 2011 17:41:52 -0800
- Subject: [patch, libgfortran] PR47567 Wrong output for small absolute values with F editing
This small patch adjusts the processor generated width for F0.d formatting to
accommodate negative signs on zero.
Regression tested on x86-64. Updated test case provided.
OK for trunk?
Regards,
Jerry
2011-02-18 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libgfortran/47567
* io/write_float.def (output_float): Adjust width for F0.d to
allow space for negative signs on zero.
Index: write_float.def
===================================================================
--- write_float.def (revision 170273)
+++ write_float.def (working copy)
@@ -116,7 +116,7 @@ output_float (st_parameter_dt *dtp, const fnode *f
/* Handle special cases. */
if (w == 0)
- w = d + 1;
+ w = d + (sign != S_NONE ? 2 : 1) + (d == 0 ? 1 : 0);
/* For this one we choose to not output a decimal point.
F95 10.5.1.2.1 */
! { dg-do run )
! PR39304 write of 0.0 with F0.3 gives **
! Test case developed from case provided by reporter.
REAL :: x
CHARACTER(80) :: str
x = 0.0
write (str,'(f0.0)') x
if (str.ne."0.") call abort
write (str,'(f0.1)') x
if (str.ne."0.0") call abort
write (str,'(f0.2)') x
if (str.ne."0.00") call abort
write (str,'(f0.3)') x
if (str.ne."0.000") call abort
write (str,'(f0.4)') x
if (str.ne."0.0000") call abort
write (str,'(F0.0)') 0.0
if (str.ne."0.") call abort
write (str,'(F0.0)') 0.001
if (str.ne."0.") call abort
write (str,'(F0.0)') 0.01
if (str.ne."0.") call abort
write (str,'(F0.0)') 0.1
if (str.ne."0.") call abort
write (str,'(F1.0)') -0.0
if (str.ne."0") call abort
write (str,'(F1.0)') 0.001
if (str.ne."*") call abort
write (str,'(F1.0)') 0.01
if (str.ne."*") call abort
write (str,'(F1.0)') 0.1
if (str.ne."*") call abort
write (str,'(F2.0)') -0.001
if (str.ne."*") call abort
write (str,'(F2.0)') -0.01
if (str.ne."**") call abort
write (str,'(F2.0)') -0.1
if (str.ne."**") call abort
write (str,'(F0.2)') 0.0
if (str.ne.".00") call abort
write (str,'(F0.0)') -0.0
if (str.ne."-0.") call abort
write (str,'(F0.1)') -0.0
if (str.ne."-.0") call abort
write (str,'(F0.2)') -0.0
if (str.ne."-.00") call abort
write (str,'(F0.3)') -0.0
if (str.ne."-.000") call abort
END