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

后端 未结 21 2193
北恋
北恋 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:42

    This works:

    #include 
    #include 
    using namespace std;
    
    int main ()
    {
      char ch='a';
      double val = nan(&ch);
      if(isnan(val))
         cout << "isnan" << endl;
    
      return 0;
    }
    

    output: isnan

提交回复
热议问题