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

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

    There is also a header-only library present in Boost that have neat tools to deal with floating point datatypes

    #include 
    

    You get the following functions:

    template  bool isfinite(T z);
    template  bool isinf(T t);
    template  bool isnan(T t);
    template  bool isnormal(T t);
    

    If you have time then have a look at whole Math toolkit from Boost, it has many useful tools and is growing quickly.

    Also when dealing with floating and non-floating points it might be a good idea to look at the Numeric Conversions.

提交回复
热议问题