欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > c/c++ >内容正文

c/c++

C++11判断inf, nan

发布时间:2025/3/21 c/c++ 56 豆豆
生活随笔 收集整理的这篇文章主要介绍了 C++11判断inf, nan 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

参考链接:http://en.cppreference.com/w/cpp/numeric/math/isinf

程序中碰到nan却找不到哪里出错是最让人头疼的问题之一,最近在cppreference上找到相关的库函数可以对异常状态进行判断。
判断inf

如果是inf则返回true, 其他情况(包括nan)返回false

bool isinf( float arg );
bool isinf( double arg );
bool isinf( long double arg );
bool isinf( Integral arg );

如果是有限数返回true,其他情况(包括nan)返回false

bool isfinite( float arg );
bool isfinite( double arg );
bool isfinite( long double arg );
bool isfinite( Integral arg );

判断nan

bool isnan( float arg );
bool isnan( double arg );
bool isnan( long double arg );
bool isnan( Integral arg );
 

总结

以上是生活随笔为你收集整理的C++11判断inf, nan的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。