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;
}
--
Summary: GCC donot promote single precision correctly with
optimization flag on
Product: gcc
Version: 3.4.4
Status: UNCONFIRMED
Severity: critical
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: dyang at mathworks dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24479