From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17017 invoked by alias); 15 Jan 2014 22:24:33 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 16976 invoked by uid 48); 15 Jan 2014 22:24:28 -0000 From: "dominiq at lps dot ens.fr" To: gcc-bugs@gcc.gnu.org Subject: [Bug libfortran/59836] New: Wrong outputs with rounding formats for some values. Date: Wed, 15 Jan 2014 22:24:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libfortran X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dominiq at lps dot ens.fr X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-01/txt/msg01638.txt.bz2 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.