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

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

    There is an std::isnan if you compiler supports c99 extensions, but I'm not sure if mingw does.

    Here is a small function which should work if your compiler doesn't have the standard function:

    bool custom_isnan(double var)
    {
        volatile double d = var;
        return d != d;
    }
    

提交回复
热议问题