码迷,mamicode.com
首页 > 编程语言 > 详细

c++中的不是数的数nan

时间:2015-10-09 11:47:05      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:

matlab中经常碰到nan,inf等特殊“数”,而在C++中也有相应的表示:例如std::numeric_limits <float>::quiet_NaN ();可以得到浮点型的nan,

但是最近在使用中发现一个奇怪的现象,

编译环境 Ubuntu12.04 & Qt 5.0.2 & g++4.4

当g++添加fast-math编译参数时,即.pro文件中添加选项QMAKE_CXXFLAGS += -ffast-math
此时产生nan再用isnan判断的时候居然是返回false。。。

int main()
{
    const static float f_nan = std::numeric_limits <float>::quiet_NaN ();
    if (std::isnan(f_nan))
        cout<<"nan"<<endl;
    cout << "Hello World!" << endl;
    return 0;
}

运行结果:

Hello World!

 

搞不懂为什么

先mark一下

c++中的不是数的数nan

标签:

原文地址:http://www.cnblogs.com/cslxiao/p/4863313.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!