public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "dominiq at lps dot ens.fr" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-59836-4@http.gcc.gnu.org/bugzilla/> (raw) 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.
next reply other threads:[~2014-01-15 22:24 UTC|newest] Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top 2014-01-15 22:24 dominiq at lps dot ens.fr [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-59836-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).