From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3987 invoked by alias); 11 Dec 2012 22:33:40 -0000 Received: (qmail 3917 invoked by uid 48); 11 Dec 2012 22:33:25 -0000 From: "anlauf at gmx dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/55539] [4.8 Regression] -fno-sign-zero may generate output with the wrong sign Date: Tue, 11 Dec 2012 22:33: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-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: anlauf at gmx dot de X-Bugzilla-Status: NEW X-Bugzilla-Priority: P4 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.8.0 X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 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 X-SW-Source: 2012-12/txt/msg01180.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55539 --- Comment #3 from Harald Anlauf 2012-12-11 22:33:21 UTC --- (In reply to comment #2) I played a little bit with the code and found that the following patch appears to fix my problem: Index: libgfortran/io/write_float.def =================================================================== --- libgfortran/io/write_float.def (revision 194417) +++ libgfortran/io/write_float.def (working copy) @@ -492,7 +492,7 @@ /* To format properly, we need to know if the rounded result is zero and if so, we set the zero_flag which may have been already set for actual zero. */ - if (i == ndigits) + if (i == ndigits && (digits[i] == '0' || digits[i] == '.')) { zero_flag = true; /* The output is zero, so set the sign according to the sign bit unless Testcase: implicit none real :: x = 0.5 + epsilon(0.) character(len=80) :: line print '(7f5.1)', x, -x write (line,'(2f5.1)') x, -x print '(A)', line if (line /= " 0.5 -0.5") call abort () print '(7f5.0)', x, -x write (line,'(2f5.0)') x, -x print '(A)', line if (line /= " 1. -1.") call abort () end Strangely enough I needed to add some epsilon to 0.5 so that the second test passes, because the exact value 0.5 appears to get rounded down to 0 in formatted output.