diff mbox

[libfortran] PR 52608 F formatting with scale factor

Message ID CAO9iq9HJUYWdD8PxsGFLXB5q0rXiRZRWSeQMHzCE45ci8edDnQ@mail.gmail.com
State New
Headers show

Commit Message

Janne Blomqvist March 17, 2012, 5:23 p.m. UTC
Hi,

a recent patch by yours truly caused incorrect output for the
combination of scale factor, the value containing initial zeroes, and
F editing. Fixed by moving the removal of the initial zeros until
after the scale factor has been applied to the value. Committed the
patch below as obvious after regtesting and running the NIST
testsuite.

Comments

Janne Blomqvist March 17, 2012, 6:24 p.m. UTC | #1
On Sat, Mar 17, 2012 at 19:23, Janne Blomqvist
<blomqvist.janne@gmail.com> wrote:
> Hi,
>
> a recent patch by yours truly caused incorrect output for the
> combination of scale factor, the value containing initial zeroes, and
> F editing. Fixed by moving the removal of the initial zeros until
> after the scale factor has been applied to the value. Committed the
> patch below as obvious after regtesting and running the NIST
> testsuite.

And upon request, a testcase reduced from the NIST testsuite, which
caught the bug in the first place:

2012-03-17  Janne Blomqvist  <jb@gcc.gnu.org>

        PR libfortran/52608
        * gfortran.dh/pr52608.f90: New test.

! { dg-do run }
! PR 52608
! Testcase reduced from NIST testsuite FM110
program fm110_snippet
  implicit none
  real :: aavs
  character(len=100) :: s(2), s2(2)
  AAVS = .087654
35043 FORMAT (" ",16X,"COMPUTED: ",22X,1P/26X,F5.4,3X,2P,F5.3,+3P," ",&
           (23X,F6.2),3X)
5043 FORMAT (17X,"CORRECT:  ",/24X,&
          "  .8765   8.765                         87.65")
  WRITE (s,35043) AAVS,AAVS,AAVS
  WRITE (s2,5043)
  if (s(2) /= s2(2)) call abort()
end program fm110_snippet


Committed as obvious.
diff mbox

Patch

Index: ChangeLog
===================================================================
--- ChangeLog   (revision 185485)
+++ ChangeLog   (working copy)
@@ -1,3 +1,9 @@ 
+2012-03-17  Janne Blomqvist  <jb@gcc.gnu.org>
+
+       PR libfortran/52608
+       * io/write_float.def (output_float): Move removal of initial zeros
+       until after the scale factor has been applied.
+
 2012-03-16  Janne Blomqvist  <jb@gcc.gnu.org>

        * io/unix.h (struct stream): Rename to stream_vtable.
Index: io/write_float.def
===================================================================
--- io/write_float.def  (revision 185485)
+++ io/write_float.def  (working copy)
@@ -180,12 +180,6 @@  output_float (st_parameter_dt *dtp, cons
       /* Make sure the decimal point is a '.'; depending on the
         locale, this might not be the case otherwise.  */
       digits[nbefore] = '.';
-      if (digits[0] == '0' && nbefore == 1)
-       {
-         digits++;
-         nbefore--;
-         ndigits--;
-       }
       if (p != 0)
        {
          if (p > 0)
@@ -229,6 +223,13 @@  output_float (st_parameter_dt *dtp, cons
          nafter = d;
        }

+      while (digits[0] == '0' && nbefore > 0)
+       {
+         digits++;
+         nbefore--;
+         ndigits--;
+       }
+
       expchar = 0;
       /* If we need to do rounding ourselves, get rid of the dot by
         moving the fractional part.  */