public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/31008] New: float value not equal to itself after assignment
@ 2007-03-01 13:42 gcczilla at achurch dot org
2007-03-01 16:43 ` [Bug c/31008] " rguenth at gcc dot gnu dot org
0 siblings, 1 reply; 2+ messages in thread
From: gcczilla at achurch dot org @ 2007-03-01 13:42 UTC (permalink / raw)
To: gcc-bugs
When compiling with optimization, it is possible to assign the value of one
float variable to another, and then have the latter value compare unequal to
the former. Take the following (contrived) testcase:
extern float sqrtf(float);
volatile int foo(int n) {
float a = sqrtf(n);
volatile float b = 0;
int c = 0;
while (b < a) {
b = a;
c++;
}
return c;
}
int main() {
return foo(32)==1 ? 0 : 1;
}
In theory, the loop in foo() should execute once, but when compiled with -O1 or
greater on i386, the loop never terminates. Examination of the generated
assembly shows that "a" is retained on the floating-point stack and never
flushed to memory, so when "b" is reloaded for the comparison, its value is
slightly less than the more-precise "a". (While libm's sqrtf() may also be at
fault for returning a value that was not properly converted to float, the same
problem exists when the test program is compiled with -ffast-math to use the
fsqrt instruction directly: the high-precision result of fsqrt is left on the
stack for the comparison, without being converted to a single-precision value.)
--
Summary: float value not equal to itself after assignment
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gcczilla at achurch dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31008
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c/31008] float value not equal to itself after assignment
2007-03-01 13:42 [Bug c/31008] New: float value not equal to itself after assignment gcczilla at achurch dot org
@ 2007-03-01 16:43 ` rguenth at gcc dot gnu dot org
0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-03-01 16:43 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from rguenth at gcc dot gnu dot org 2007-03-01 16:43 -------
*** This bug has been marked as a duplicate of 323 ***
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31008
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-03-01 16:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-01 13:42 [Bug c/31008] New: float value not equal to itself after assignment gcczilla at achurch dot org
2007-03-01 16:43 ` [Bug c/31008] " rguenth at gcc dot gnu dot org
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).