Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
14 Views

NaN bugs

I'm having some unexpected behaviour from NaN's when swithing to the Intel C++ compiler.

#include <math.h>

int main()
{

  // Comparing two NaNs should result in a False
  if (NAN == NAN) return -1;

  return 0;

}

Comparing two NaNs should result in a False but results in a True. Any ideas what's up with this?

0 Kudos
2 Replies
Highlighted
Beginner
14 Views

Here is a more complete example:

 

// NaNTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <math.h>
#include <iostream>

int _tmain(int argc, _TCHAR* argv[])
{
    if (NAN == NAN)
        std::cerr << "Bad NaN" << std::endl;
    else
        std::cout << "Good NaN" << std::endl;

    getchar();

    return 0;
}

 

Visual Studio 2013 compiler returns "Good NaN" while Intel C++ 14 compiler returns "Bad NaN" after running the above code.

0 Kudos
Highlighted
Beginner
14 Views

I just figured it out myself. The default floating point model is /fp:fast and must be set to /fp:strict or /fp:precise for NaN's to work properly.

0 Kudos