为什么将地板与战俘一起使用时会得到意外的输出? [英] Why am I getting unexpected output when using floor with pow?
本文介绍了为什么将地板与战俘一起使用时会得到意外的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我在代码块上运行了这段代码:
So, I ran this code on my code blocks:
#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?
1st output was not 10^9 due to truncation effect,which means that pow(10,9) was something like 999999999.99999.., but then how come floor of this thing is 1000000000 ??
推荐答案
实际上, int
的最大值为2,147,483,647,因此不应有溢出或截断(这是 int
).而我的输出正是:
Actually, the maximum value for int
is 2,147,483,647, therefore there should be no overflow or truncation (it's an int
). And my output is exactly:
100000000010000000001000000000
1000000000 1000000000 1000000000
这篇关于为什么将地板与战俘一起使用时会得到意外的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文