首页 > 解决方案 > pow() 函数在 C++ 中返回不同的结果

问题描述

我们知道unsigned long long int的范围是 0 到 18,446,744,073,709,551,615

意味着,unsigned long long int能够轻松处理 19-20 位数字。

所以,我想知道为什么我的这个程序返回不同的值。

程序 :

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ulli;
int main()
{
    double a,b;
    cin>>a>>b;
    ulli result = (ulli)pow(a,b);
    cout<<"result = "<<result<<"\n";
}

给出这个输入后: a=15 , b=15

预期输出为:4378938903808593 75 (18位数字)

但是,它给出的是:结果 = 4378938903808593 92 (最后 2 位数字不同)。

谁能帮助我为什么我得到不同的结果?

标签: c++powunsigned-long-long-int

解决方案


推荐阅读