为什么在使用带有电源的地板时会出现意外的输出?

时间:2014-12-15 08:00:39

标签: c++ pow floor

所以,我在我的代码块上运行了这段代码:

#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 ..,但那么这个东西的楼是怎么来的10亿?

1 个答案:

答案 0 :(得分:-1)

实际上,int的最大值是2,147,483,647,因此不应该有溢出或截断(它是int)。我的输出正是:

  

10亿   10亿   十亿

相关问题