我写以下内容c++
程序在CodeBlocks
,结果是 9183。我再次将其写入Eclipse
运行后返回9220。两者都使用MinGW
。正确的结果是9183。这段代码有什么问题?
谢谢。
源代码:
#include <iostream>
#include <set>
#include <cmath>
int main()
{
using namespace std;
set<double> set_1;
for(int a = 2; a <= 100; a++)
{
for(int b = 2; b <= 100; b++)
{
set_1.insert(pow(double(a), b));
}
}
cout << set_1.size();
return 0;
}
您可能会看到由于 CodeBlocks 在 32 位模式下编译而 Eclipse 在 64 位模式下编译而导致的精度错误:
$ g++ -m32 test.cpp
$ ./a.out
9183
$ g++ -m64 test.cpp
$ ./a.out
9220
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)