Achieving Consistent Floating-Point Results (/Op)

Floating-point numbers stored in memory use either 32, 64, or 80 bits, depending on whether they are of type float, type double, or type long double. The 80x87 family of coprocessors uses 80-bit registers for all operations. If a value of type float or type double is kept in these registers through a number of operations, it will be more accurate than if that value is moved to and from memory between operations.

Because of the difference in precision between memory and register representation of a floating-point number, a value stored in memory is not always equal to the same value in the 80x87 register.

The difference in precision primarily affects strict equality or strict inequality tests (== and !=); however, relational tests of magnitude (>, >=, <=, and <) can behave erroneously if the coprocessor is able to maintain significant digits that memory variables cannot.

You can avoid the difference in precision by using the /Op option. This option forces floating-point values to be written to memory between floating-point operations. While storing these values to memory reduces the precision of floating-point expressions, it also ensures that these expressions will produce consistent results regardless of the rest of the code.

You can change the handling of floating-point results on a function-by-function basis using the optimize pragma with the p option.

Note:

Using the /Op option suppresses other optimizations because the floating-point registers are not available for storage of intermediate results. Because you suppress these optimizations, code compiled with the /Op option executes more slowly than code compiled without this option.