gpt4 book ai didi

c++ - 答案怎么是-0?

转载 作者:行者123 更新时间:2023-12-01 14:13:01 24 4
gpt4 key购买 nike

如果我的问题不正确,请忘记我。我是 C++ 初学者。我刚刚用c++写了一个简单的程序我的代码是:

#include<iostream>
using namespace std;
int main()
{
float a,b,c;
a=0;
b=-5;
c=a/b;
cout<<c;

}

当我运行此代码时,输​​出为 -0。答案怎么可能是 -0 而 -0 不存在?

最佳答案

How the answer could be -0 while -0 doesn't exist?

你的假设是错误的。 -0 确实存在于 float 表示中,因此答案可以是 -0。

有关引用,请参阅 IEEE-754 标准,有关“原因”,请参阅 Branch Cuts for Complex Elementary Functions or Much Ado About Nothing's Sign Bit .

关于c++ - 答案怎么是-0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63685496/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com