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

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

    As for me the solution could be a macro to make it explicitly inline and thus fast enough. It also works for any float type. It bases on the fact that the only case when a value is not equals itself is when the value is not a number.

    #ifndef isnan
      #define isnan(a) (a != a)
    #endif
    

提交回复
热议问题