public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libfortran/59836] New: Wrong outputs with rounding formats for some values.
@ 2014-01-15 22:24 dominiq at lps dot ens.fr
  2014-01-16  8:37 ` [Bug libfortran/59836] [4.7/4.8/4.9 Regression] " dominiq at lps dot ens.fr
                   ` (15 more replies)
  0 siblings, 16 replies; 17+ messages in thread
From: dominiq at lps dot ens.fr @ 2014-01-15 22:24 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59836

            Bug ID: 59836
           Summary: Wrong outputs with rounding formats for some values.
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libfortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dominiq at lps dot ens.fr
                CC: jvdelisle at gcc dot gnu.org

This is a split off pr59774 comment 9. The code

 print "(ru,g45.3)", 891.1
 print "(rd,g45.3)", -891.1
end

compiled with trunk (r206559) gives the output

                                       9.    
                                      -9.    

I have also found that the code

print '(RU,F2.0)', 0.6
print '(RD,F3.0)', -0.6
end

gives

7.
-7.

Both problems occur because the Fw.d format is not properly handled when d==0.
The following patch fixes both problems

--- ../_clean/libgfortran/io/write_float.def    2014-01-04 15:51:53.000000000
+0100
+++ libgfortran/io/write_float.def    2014-01-15 22:22:17.000000000 +0100
@@ -373,7 +373,7 @@ output_float (st_parameter_dt *dtp, cons
   updown:

   rchar = '0';
-  if (w > 0 && d == 0 && p == 0)
+  if (ft != FMT_F && nbefore == 0 && w > 0 && d == 0 && p == 0)
     nbefore = 1;
   /* Scan for trailing zeros to see if we really need to round it.  */
   for(i = nbefore + nafter; i < ndigits; i++)
@@ -386,13 +386,14 @@ output_float (st_parameter_dt *dtp, cons
   do_rnd:

   if (nbefore + nafter == 0)
+    /* Handle the case Fw.0 and value < 1.0 */
     {
       ndigits = 0;
       if (nzero_real == d && digits[0] >= rchar)
     {
       /* We rounded to zero but shouldn't have */
-      nzero--;
-      nafter = 1;
+      nbefore = 1;
+          digits--;
       digits[0] = '1';
       ndigits = 1;
     }

The first patch handles the first problem by restricting the test to the E*
formats and the second one fixes the way Fw.0 handles values < 1.0 (yes, I have
seen the formatting issue for the line digits--. I'll fix it when I'll submit
the patch).
AFAICT the line nzero--; does not seem necessary, but I don't know why.

With the patch the first test gives

                                     892.    
                                    -892.    

and the second

1.
-1.

and I did not see any regression when retesting with it.


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2014-02-15 17:22 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-15 22:24 [Bug libfortran/59836] New: Wrong outputs with rounding formats for some values dominiq at lps dot ens.fr
2014-01-16  8:37 ` [Bug libfortran/59836] [4.7/4.8/4.9 Regression] " dominiq at lps dot ens.fr
2014-01-16 22:08 ` dominiq at lps dot ens.fr
2014-01-18 11:22 ` dominiq at lps dot ens.fr
2014-01-18 16:46 ` dominiq at lps dot ens.fr
2014-01-18 17:22 ` jvdelisle at gcc dot gnu.org
2014-01-18 17:44 ` dominiq at lps dot ens.fr
2014-01-18 17:46 ` dominiq at lps dot ens.fr
2014-01-19 23:18 ` jvdelisle at gcc dot gnu.org
2014-01-19 23:21 ` jvdelisle at gcc dot gnu.org
2014-01-31 10:53 ` rguenth at gcc dot gnu.org
2014-02-11  9:28 ` [Bug libfortran/59836] [4.7/4.8 " dominiq at lps dot ens.fr
2014-02-15 15:49 ` jvdelisle at gcc dot gnu.org
2014-02-15 15:58 ` jvdelisle at gcc dot gnu.org
2014-02-15 16:53 ` jvdelisle at gcc dot gnu.org
2014-02-15 16:55 ` jvdelisle at gcc dot gnu.org
2014-02-15 17:22 ` jvdelisle at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).