In a program that needs to process sin(x)/x function, I encountered NAN problem, I simplified the problem in the following code:
#include <iostream>
#include <cmath>
int main()
{
std::cout.precision(15);
//This line compiles and run in g++, but does not compile in Visual Studio 2013
std::cout << 0.0/0.0 << std::endl;
//This line compiles and run in both g++ and VS2013
std::cout << std::sin(0.0)/0.0 << std::endl;
return 0;
}
In g++, the output is: -nan -nan, in VS2013, the output is: -1.IND, because the first line does not compile so I commented it out.
My questions are:
What does this '-1.IND' mean?
It seems NAN processing is compiler dependent, should this be standardized in C++? Why?
I used this hack to deal with this problem:
double sinc(double x) { if(x == 0.0) return 1.0; return std::sin(x)/x; }
Is this the right way?
EDIT: another question, 4. why VS2013 deal with 0.0/0.0 and sin(0.0)/0.0 differently?