c++ - 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 位数字不同)。
谁能帮助我为什么我得到不同的结果?
解决方案
推荐阅读
- spring-data-elasticsearch - 如何获取文档的 _version 的当前值
- controller - 为什么我无法连接到 Ctrl?
- c++ - 如何转换从 C++ 中的函数返回的对象
- excel - SAPUI5 - 从 Excel 读取 CSV 文件时出错 - ANSI
- java - Spring Batch:作业终止错误:IOException 从类路径资源 c:/directory/job-definition.xml 解析 XML 文档
- c++ - 访问类 Y 中类 X 的可变参数模板参数
- download - 如何下载IIB V10开发者版?
- c# - 如何保存和引用用户输入 c#(ToDo 控制台应用程序)
- r - 从数据框中删除所有包含相同元素的行,即使元素在 R 中的顺序不同
- css - 我可以从 react-bootstrap 模块编辑导航栏吗?怎么做?