【问题标题】:I get different output when I process the code in VS2015. Is there any explanation?当我在 VS2015 中处理代码时,我得到了不同的输出。有什么解释吗?
【发布时间】:2016-07-14 10:47:43
【问题描述】:

下面显示的代码是从here获取的。但输出有些不同。

#include <iostream>
#include <limits>

using namespace std;

int main()
{
    cout << "The quiet NaN for type float is:  "
        << numeric_limits<float>::quiet_NaN()
        << endl;
    cout << "The quiet NaN for type int is:  "
        << numeric_limits<int>::quiet_NaN()
        << endl;
    cout << "The quiet NaN for type long double is:  "
        << numeric_limits<long double>::quiet_NaN()
        << endl;
}

这是我的 VS2015 中的打印输出:

The quiet Nan for type float is :   nan  
The quiet Nan for type int is :   0  
The quiet Nan for type long double is :   nan

虽然 MSDN 文章中的输出说,它应该是:

The quiet NaN for type float is:  1.#QNAN
The quiet NaN for type int is:  0
The quiet NaN for type long double is:  1.#QNAN

这与this blog entry上显示的表格中的值一致。

【问题讨论】:

  • 微软过去常常使用 MSDN 引用中描述的那些时髦的东西。但是 C99 标准化了 NaN 值的输出应该是什么,这就是你的输出显示的内容,所以看起来微软终于赶上了 C 标准。
  • 非常高兴您回答我的问题。谢谢。
  • MS doc 中是否有任何关于更改的参考文章?
  • 此处记录了更改(使用 google 很难获得):msdn.microsoft.com/en-us/library/bb531344.aspx
  • msdn.microsoft.com/library/… 似乎已经过时,尽管提到它适用于 VS 2015 :(

标签: c++ visual-studio-2015 nan


【解决方案1】:

VS 对这些特殊 IEEE 浮点值使用的标记字符串的更改列在“Visual C++ 更改历史 2003 - 2015”中的“Infinity and NaN Formatting”下https://msdn.microsoft.com/en-us/library/bb531344.aspx

但是看起来他们错过了一些 VS2015 文档中的更新,例如https://msdn.microsoft.com/library/9e817177-0e91-48e6-b680-0531c4b26625.aspx ;我已经提交了更正,让他们知道这不太正确。

【讨论】:

    猜你喜欢
    • 2019-10-07
    • 1970-01-01
    • 1970-01-01
    • 2019-11-21
    • 1970-01-01
    • 1970-01-01
    • 2021-02-07
    • 2013-01-30
    • 1970-01-01
    相关资源
    最近更新 更多