#include <stdio.h> #define OP(x) ((x) * .29425635593220338949) int main (void) { double a = 5671.92506245995003720887; double b = OP (a); printf ("%d %d\n", (int) OP (a), (int) b); return 0; } On an i386 (gcc 2.95.4, 3.3), the output is: 1668 1669 Clearly, looking at the code, these 2 numbers should be equal! However, on a sparc (gcc 2.95.3), the output is correct: 1669 1669
This is a non bug, read <http://gcc.gnu.org/bugs.html#nonbugs_general> Also read bug 323 which is a dup of. *** This bug has been marked as a duplicate of 323 ***
Subject: Re: Unexpected loss of floating point precision in assignment Hello, I'm confused: > ------- Additional Comments From pinskia@gcc.gnu.org: > This is a non bug, read > <http://gcc.gnu.org/bugs.html#nonbugs_general> > I understand that floating point arithmetic is inaccurate but I don't understand how _assigning_ a floating point value to a variable before use could be any different from the implicit assignment of the value to a temporary variable (done by the compiler). > *** This bug has been marked as a duplicate of 323 But this has nothing to do with optimization levels. I'm compiling with optimization off. http://search.yahoo.com.au - Yahoo! Search - Looking for more? Try the new Yahoo! Search
assigning it to a temporary variable forces (by placing in memory by having no optimizations) a change in floating point precision and causes rounding to take place which causes more havoc than you think so this is still a dup of bug 323.