为什么我在使用带 pow 的地板时会得到意外的输出
Why am I getting unexpected output when using floor with pow?
所以,我在代码块上运行了这段代码:
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int a;
a=pow(10,9);
cout<<a<<endl;
a=ceil(pow(10,9));
cout<<a<<endl;
a=floor(pow(10,9));
cout<<a<<endl;
return 0;
}
我得到的输出为:
999999999
100000000
100000000
由于截断效应,第一个输出不是 10^9,这意味着 pow(10,9) 类似于999999999.99999..,但是为什么这个东西的地板是1000000000??
实际上,int
的最大值是 2,147,483,647,因此不应该有溢出或截断(这是一个int
)。我的输出正是:
1000000000 1000000000 1000000000
相关文章:
- 更改.cpp程序的输入文件中数据的位置会意外更改输出
- 字符串比较中的意外输出
- 每次在 c++ 中输出不同(意外行为)
- 来自 decltype 的意外输出类型
- 字符数组到十六进制字符串的转换 - 意外输出
- 使用 boost::regex 从目录中获取带有一些正则表达式的文件名称时出现意外输出
- 使用后序遍历递归的深度优先搜索会产生意外输出
- C++的意外输出
- 标准输出C++意外行为
- 贝金纳C++练习解决方案的意外输出
- 无效* 转换获得意外输出
- 以下程序的意外输出
- 意外输出:矢量矢量(功率集)
- 基本 int 数组提供意外输出
- 线程的意外输出
- 减法中的意外输出
- 带有左移操作员C 的意外输出
- C strncpy意外输出
- 意外输出..函数绑定在虚拟表中的发生方式
- 星号的意外输出