From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2375 invoked by alias); 14 Jun 2011 07:19:18 -0000 Received: (qmail 2356 invoked by uid 22791); 14 Jun 2011 07:19:16 -0000 X-SWARE-Spam-Status: No, hits=0.8 required=5.0 tests=AWL,BAYES_50 X-Spam-Check-By: sourceware.org Received: from sv13.net-housting.de (HELO sv13.net-housting.de) (178.248.244.23) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 14 Jun 2011 07:18:52 +0000 Received: from localhost (mailscan.hofmeirmedia.net [172.30.129.51]) by sv13.net-housting.de (Postfix) with ESMTP id 5241528232B5D; Tue, 14 Jun 2011 09:18:50 +0200 (CEST) Received: from sv13.net-housting.de ([172.30.129.23]) by localhost (mailscan.hofmeirmedia.net [172.30.129.51]) (amavisd-new, port 10024) with ESMTP id xZ8lw5rRTapP; Tue, 14 Jun 2011 09:18:48 +0200 (CEST) Received: from mail-vw0-f47.google.com (mail-vw0-f47.google.com [209.85.212.47]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by sv13.net-housting.de (Postfix) with ESMTPSA id AD5522810F866; Tue, 14 Jun 2011 09:18:47 +0200 (CEST) Received: by vws2 with SMTP id 2so4874381vws.20 for ; Tue, 14 Jun 2011 00:18:38 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.50.132 with SMTP id z4mr2342891vcf.161.1308035918658; Tue, 14 Jun 2011 00:18:38 -0700 (PDT) Received: by 10.220.81.6 with HTTP; Tue, 14 Jun 2011 00:18:38 -0700 (PDT) In-Reply-To: <4DF6E8CF.4070401@charter.net> References: <4DE8D8D6.5030506@charter.net> <4DF25409.1080509@charter.net> <4DF6E8CF.4070401@charter.net> Date: Tue, 14 Jun 2011 08:30:00 -0000 Message-ID: Subject: Re: [patch, libgfortran] PR48906 Wrong rounding results with -m32 From: Thomas Henlich To: jerry DeLisle Cc: gfortran , Janne Blomqvist , gcc patches Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-06/txt/msg01012.txt.bz2 On Tue, Jun 14, 2011 at 06:51, jerry DeLisle wrote: >> It should be easy to implement: >> >> After the switch between F and E editing, we just need to shift the >> decimal point and decrement the exponent. No new rounding is required, >> because we keep the number of significant digits. >> > > OK, after a little bit of experimentation, I have arrived at the updated > patch attached. > > This has been regression tested and passes all test cases I am aware of. = =A0I > also have included a new test case gcc/testsuite/gfortran.dg/fmt_g.f90. > > OK for trunk? I have reviewed your patch, and I noticed that you placed the digit-shifting code quite at the top of output_float(), where the final value of e is not even known. Due to rounding, e can be modified after this point, so your code will generate invalid output in some cases, for example: print "(-2PG0)", nearest(0.1d0, -1.0d0) ! 1.0000000000000000E+001 expected .0099999999999999992E+001 Please put the code where at belongs, after the switch between F and E editing (based on the final value of e). The same applies to the scale factor in general, e.g. print "(-2pg12.3)", 0.096 ! 1.00E+01 expected 0.001E+02 print "(-1pg12.3)", 0.0996 ! 1.00E+00 expected 0.010E+01 print "(-2pg12.3)", 0.09996 ! 1.00E+01 expected 0.100 print "(-1pg12.3)", 0.09996 ! 1.00E+00 expected 0.100 print "(1pg12.3)", 0.099996 ! 1.000E-01 expected 0.100 print "(2pg12.3)", 0.099996 ! 10.00E-02 expected 0.100 print "(-2pg12.3)", 999.6 ! 0.100E+04 expected 0.001E+06 print "(-1pg12.3)", 999.6 ! 0.100E+04 expected 0.010E+05 print "(1pg12.3)", 999.6 ! 0.100E+04 expected 9.996E+02 print "(2pg12.3)", 999.6 ! 0.100E+04 expected 99.96E+01 Please revise your code to fix this. A working approach I have outlined in http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D48906#c28 and an (alpha) implementation is here: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D48906#c31 Thomas