小编Edv*_*n K的帖子

为什么我的int很长的算术表现为这种方式?

我正在尝试使用long long数据类型计算大整数,但是当它变得足够大(2^55)时,算术行为是无法预测的。我正在使用Microsoft Visual Studio 2017。

在第一种情况下,我2将从初始化中的long long变量m中减去。这对所有人都适用,n直到我尝试为止54,然后再将其m不减去2

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>

using namespace std;

#define LL long long

int main()
{
    LL n;
    cin >> n;
    LL m = pow(2, n + 1) - 2;
    cout << m;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是,使用此代码m确实会被减去2并按我期望的那样工作。

#include <iostream>
#include <string>
#include <algorithm>
#include <vector> …
Run Code Online (Sandbox Code Playgroud)

c++ floating-point precision long-long

31
推荐指数
3
解决办法
2741
查看次数

标签 统计

c++ ×1

floating-point ×1

long-long ×1

precision ×1