为什么我得到:
34458730320
3446590374
如果我运行:
#include <stdio.h>
int main()
{
printf("%llu\n",10248428203192896360LLU/594823321LLU*2LLU);
printf("%llu\n",2LLU*10248428203192896360LLU/594823321LLU);
return 0;
}
我预计第二个是正确的(在 Mathematica、Matlab 中检查)。
最佳答案
整数值
2LLU * 10248428203192896360LLU
溢出 64 位,编译器应该对此发出警告。第一个是正确的
10248428203192896360LLU / 594823321LLU * 2LLU
因为除法是精确的,没有余数,所以除法后加倍也没关系。
关于c - 无符号 long long 不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55838309/