[Bug c++/24479] New: GCC donot promote single precision correctly with optimization flag on

2005-10-21 Thread dyang at mathworks dot com
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 
#include 


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



[Bug c++/24479] GCC donot promote single precision correctly with optimization flag on

2005-10-21 Thread dyang at mathworks dot com


--- Comment #2 from dyang at mathworks dot com  2005-10-21 21:51 ---
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


-- 

dyang at mathworks dot com changed:

   What|Removed |Added

 Status|RESOLVED|UNCONFIRMED
 Resolution|DUPLICATE   |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24479