From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26416 invoked by alias); 18 Feb 2014 10:51:09 -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 26376 invoked by uid 48); 18 Feb 2014 10:51:06 -0000 From: "dominiq at lps dot ens.fr" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/60128] [4.8/4.9 Regression] Wrong ouput using en edit descriptor Date: Tue, 18 Feb 2014 10:51:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 4.8.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dominiq at lps dot ens.fr X-Bugzilla-Status: NEW 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: Message-ID: In-Reply-To: References: 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-02/txt/msg01802.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60128 --- Comment #7 from Dominique d'Humieres --- The following patch fixes the issues reported in comment 6 --- ../_clean/libgfortran/io/write_float.def 2014-01-21 08:30:57.000000000 +0100 +++ libgfortran/io/write_float.def 2014-02-18 09:59:04.000000000 +0100 @@ -1157,10 +1153,23 @@ OUTPUT_FLOAT_FMT_G(16,L) #define EN_PREC(x,y)\ {\ - GFC_REAL_ ## x tmp; \ + GFC_REAL_ ## x tmp, one = 1.0; \ tmp = * (GFC_REAL_ ## x *)source; \ if (ISFINITE (y,tmp)) \ - nprinted = DTOA(y,0,tmp); \ + {\ + nprinted = DTOA(y,0,tmp); \ + int e = atoi (&buffer[4]); \ + if (buffer[1] == '1') \ + {\ + tmp = (calculate_exp_ ## x (-e)) * tmp; \ + tmp = one - (tmp < 0 ? -tmp : tmp); \ + if (tmp > 0) \ + e = e - 1; \ + }\ + nbefore = e%3; \ + if (nbefore < 0) \ + nbefore = 3 + nbefore; \ + }\ else\ nprinted = -1;\ }\ @@ -1172,6 +1181,7 @@ determine_en_precision (st_parameter_dt int nprinted; char buffer[10]; const size_t size = 10; + int nbefore; /* digits before decimal point - 1. */ switch (len) { @@ -1204,16 +1214,6 @@ determine_en_precision (st_parameter_dt if (nprinted == -1) return -1; - int e = atoi (&buffer[5]); - int nbefore; /* digits before decimal point - 1. */ - if (e >= 0) - nbefore = e % 3; - else - { - nbefore = (-e) % 3; - if (nbefore != 0) - nbefore = 3 - nbefore; - } int prec = f->u.real.d + nbefore; if (dtp->u.p.current_unit->round_status != ROUND_UNSPECIFIED && dtp->u.p.current_unit->round_status != ROUND_PROCDEFINED)