I recently downloaded the intel c++ compiler 8.0 evaluation version and used it to compile my program in vs.net 2003. I found the releaseconfiguration did not produce the correct results. The debug configuration of the intel compiler and both the debug and release configurations of the vs.net compiler produced the expected results. As I tracked down the part of the code that caused the problem, it seemed to be a problem of the compiler.
I created a very simple program.
int _tmain(int argc, _TCHAR* argv)
double x =NaN;
double y = 1.0;
if (x < y)
cout << x << " is less than " << y << endl;
cout << x << " is not less than " << y << endl;
x isa quietNaN (Not-a-Number). The value of the expression "NaN < 1.0" should be false.
If it is compiled correctly, the program should output "1.#QNAN is not less than 1".
But when I turned on the "/O2" optimization option in the DEBUG configuration, the compiled program output "1.#QNAN is less than 1".
Any floating point comparisoninstruction involving NaN followed by "fnstsw ax" and "sahf" sets the C, Z, and P flags. The P flag indicates that an operand is NaN.
But the assembly code in the disassembly window showed that the parity flagwas not checked in the optimized code. In the unoptimized code, the parity flag was checked explicitly.