When compiling with Microsoft Visual C++, the compiler option /fp controls the behaviour of the generated code, and comparison of NaNs in particular. The details can be found at http://msdn2.microsoft.com/en-us/library/e7s85ffb(VS.80).aspx