From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 93329 invoked by alias); 2 Jul 2015 09:24:07 -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 93286 invoked by uid 48); 2 Jul 2015 09:24:03 -0000 From: "dhekir at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/66736] New: float rounding differences when using constant literal versus variable Date: Thu, 02 Jul 2015 09:24:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 5.1.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dhekir at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: 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 target_milestone 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: 2015-07/txt/msg00131.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66736 Bug ID: 66736 Summary: float rounding differences when using constant literal versus variable Product: gcc Version: 5.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: dhekir at gmail dot com Target Milestone: --- Calling function "log10f(3)" with a constant literal or via a variable, such as "float f = 3; log10f(f)" gives different rounding results, which are incorrect in the latter case. Note that the bug is not about imprecision in the result, but inconsistency between two statements which should be equivalent. The difference only appears with no optimization flag or with -O0; activating -O1 or greater makes the difference disappear. It is especially annoying (although not forbidden) that the rounding differences in this case do not respect usual order (i.e. changing the rounding mode allows one to see that FE_DOWNWARD is larger than FE_TONEAREST in the version using the variable). This behavior has been observed in several GCCs, from 4.8.4 (Ubuntu) to 5.1.1 (Fedora), including a 5.0.0 compiled from trunk, and using different versions of glibc (2.19, and also tried compiling 2.21). All of them produced the same result. Also, there are several constants for which this happen, but 3 would be one of the most notable ones. #include #include int main() { float r = log10f(3); printf("literal constant: %g (%a)\n", r, r); float x = 3; r = log10f(x); printf("with variable: %g (%a)\n", r, r); return 0; }