Checking if a double (or float) is NaN in C++

后端 未结 21 1869
北恋
北恋 2020-11-22 05:10

Is there an isnan() function?

PS.: I\'m in MinGW (if that makes a difference).

I had this solved by using isnan() from , which doe

21条回答
  •  粉色の甜心
    2020-11-22 05:44

    This detects infinity and also NaN in Visual Studio by checking it is within double limits:

    //#include 
    double x, y = -1.1; x = sqrt(y);
    if (x >= DBL_MIN && x <= DBL_MAX )
        cout << "DETECTOR-2 of errors FAILS" << endl;
    else
        cout << "DETECTOR-2 of errors OK" << endl;
    

提交回复
热议问题