Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

NaN bugs

Inge_H_
Beginner
482 Views

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
Inge_H_
Beginner
482 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
Inge_H_
Beginner
482 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
Reply