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: Tue, 22 Feb 2011 21:05:23 -0800
- Subject: [patch,libgfortran] PR47567 Wrong output for small absolute values with F editing
Hi all,
After a lot of thought and the persistence of the OP, I think now the right
thing to do is to get rid of the special handling we have for a zero F editing
with width of one. Otherwise, we add additional special handling for width 2.
The attached patch does this and simplifies the code.
Regression tested on x86-64. Revised test case attached.
OK for trunk?
Jerry
2011-02-22 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libgfortran/47567
* io/write_float.def (output_float): Remove special case handling of
zero with width 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") call abort
write (str,'(f0.2)') x
if (str.ne.".00") call abort
write (str,'(f0.3)') x
if (str.ne.".000") call abort
write (str,'(f0.4)') x
if (str.ne.".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."*") 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
write (str,'(F3.0)') -0.0
if (str.ne."-0.") call abort
write (str,'(F2.0)') -0.0
if (str.ne."**") call abort
write (str,'(F1.0)') -0.0
if (str.ne."*") call abort
write (str,'(F0.1)') -0.0
if (str.ne."-.0") call abort
write (str,'(F3.1)') -0.0
if (str.ne."-.0") call abort
write (str,'(F2.1)') -0.0
if (str.ne."**") call abort
write (str,'(F1.1)') -0.0
if (str.ne."*") call abort
END
Index: io/write_float.def
===================================================================
--- io/write_float.def (revision 170426)
+++ io/write_float.def (working copy)
@@ -117,25 +117,6 @@ output_float (st_parameter_dt *dtp, const fnode *f
/* Handle special cases. */
if (w == 0)
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 */
- if (w == 1 && ft == FMT_F)
- {
- out = write_block (dtp, w);
- if (out == NULL)
- return FAILURE;
-
- if (unlikely (is_char4_unit (dtp)))
- {
- gfc_char4_t *out4 = (gfc_char4_t *) out;
- *out4 = '0';
- return SUCCESS;
- }
-
- *out = '0';
- return SUCCESS;
- }
}
/* Normalize the fractional component. */