Please run the following code through gcc with -O3 flag, then run the executable. The expected result is -13275031.0, but the result from the code is -13275030.0. That is because the result from the addition (a+0.5) was stored in a signle precision, not double precision as ISO C++ standard mandates. This is causing numerical problems with our product. This bug might be associated with other math built-in functions. #include <math.h> #include <stdio.h> inline float foof(float a) { float b = floor(a + 0.5); return b; } int main(void) { float a = -13275031.0f; a = foof(a); printf("%f\n", a); return 0; }
*** This bug has been marked as a duplicate of 323 ***
I am quite surprised when i saw this bug report was marked as duplicate with #323. I have to reopen the bug and here is the reason. With bug 323, it is caused by hardware using excessive precision so that it leads to different answers depending on if the excessive precision value gets to be stored in a 64bit memory or not. The bug I reported is that the double value out of a double precision addition (a + 0.5) is stored into a 64 bits memory (as double value), but when optimization (-O3) is used, the double value is actually stored in a 32 bits memory (a single precision value). This is clearly a violation of ISO C++ standard. It has nothing to do with bug 323. Plesae reconsider your decision on this one. Dongzhe
Fixed in 4.1.0 by: 2005-10-05 Dale Johannesen <dalej@apple.com> * convert.c (convert_to_real): Don't convert (float)floor(double d) to floorf((float)d).