public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/66736] New: float rounding differences when using constant literal versus variable
@ 2015-07-02  9:24 dhekir at gmail dot com
  2015-07-02  9:45 ` [Bug c/66736] " rguenth at gcc dot gnu.org
  2015-07-02 11:32 ` dhekir at gmail dot com
  0 siblings, 2 replies; 3+ messages in thread
From: dhekir at gmail dot com @ 2015-07-02  9:24 UTC (permalink / raw)
  To: gcc-bugs

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;
}


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/66736] float rounding differences when using constant literal versus variable
  2015-07-02  9:24 [Bug c/66736] New: float rounding differences when using constant literal versus variable dhekir at gmail dot com
@ 2015-07-02  9:45 ` rguenth at gcc dot gnu.org
  2015-07-02 11:32 ` dhekir at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-07-02  9:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66736

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
This means the math library implementation of log10f is not exact which isn't a
GCC bug.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/66736] float rounding differences when using constant literal versus variable
  2015-07-02  9:24 [Bug c/66736] New: float rounding differences when using constant literal versus variable dhekir at gmail dot com
  2015-07-02  9:45 ` [Bug c/66736] " rguenth at gcc dot gnu.org
@ 2015-07-02 11:32 ` dhekir at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: dhekir at gmail dot com @ 2015-07-02 11:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66736

--- Comment #2 from dhekir at gmail dot com ---
Isn't the library implementation of log10f used to compute the literal
constants generated in the assembly code? Would it then be a double precision
result that would be precomputed and rounded to single precision in this case?

Well, sorry for the noise, I compared the results with other compilers and,
even if the numerical results themselves were different, they were consistent
between precomputed constant literals and the underlying libc, therefore such
surprising situations do not arrive. I assumed that it was not intented in GCC
and so it would be useful to report it, but if it's not the same library
function used in both cases, that explains the issue.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-07-02 11:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-02  9:24 [Bug c/66736] New: float rounding differences when using constant literal versus variable dhekir at gmail dot com
2015-07-02  9:45 ` [Bug c/66736] " rguenth at gcc dot gnu.org
2015-07-02 11:32 ` dhekir at gmail dot com

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).