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

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

    You can use the isnan() function, but you need to include the C math library.

    #include 
    

    As this function is part of C99, it is not available everywhere. If your vendor does not supply the function, you can also define your own variant for compatibility.

    inline bool isnan(double x) {
        return x != x;
    }
    

提交回复
热议问题