c++cdebuggingfloating-point

Float values behaving differently across the release and debug builds


My application is generating different floating point values when I compile it in release mode and in debug mode. The only reason that I found out is I save a binary trace log and the one from the release build is ever so slightly off from the debug build, it looks like the bottom two bits of the 32 bit float values are different about 1/2 of the cases.

Would you consider this "difference" to be a bug or would this type of difference be expected. Would this be a compiler bug or an internal library bug.

For example:

LEFTPOS and SPACING are defined floating point values.
float def_x;
int xpos;

def_x = LEFTPOS + (xpos * (SPACING / 2));

The issue is in regards to the X360 compiler.


Solution

  • Release mode may have a different FP strategy set. There are different floating point arithmetic modes depending on the level of optimization you'd like. MSVC, for example, has strict, fast, and precise modes.