public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "dhekir at gmail dot com" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-66736-4@http.gcc.gnu.org/bugzilla/> (raw) 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 <math.h> #include <stdio.h> 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; }
next reply other threads:[~2015-07-02 9:24 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-07-02 9:24 dhekir at gmail dot com [this message] 2015-07-02 9:45 ` [Bug c/66736] " rguenth at gcc dot gnu.org 2015-07-02 11:32 ` dhekir at gmail dot com
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-66736-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).