cout打印"-0"而不是"0"

Leo*_*nid 4 c++ floating-point

#include <iostream>
using namespace std;

int main()
{
    double u = 0;
    double w = -u;
    cout << w << endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

为什么这个伟大的代码输出-0而不是0像人们期望的那样?

fox*_*rot 13

用于浮点数的IEEE 754标准具有与尾数分开的符号位,其允许零为负. 维基百科应该能够帮助解释这一点.