【发布时间】:2016-02-10 18:58:22
【问题描述】:
我的数据类型为 unsigned __int128 data;,所以我认为这不是类型问题,但我不知道为什么会发生这种情况
#include <stdio.h>
int main(int argc, char *argv[]) {
unsigned __int128 z = 1911602146;
unsigned __int128 n = 4003562209;
//case 1
unsigned __int128 result = fmod((pow(z, 2) * 2), n);
printf("%d\n", result);
//case 2
unsigned __int128 result_2 = fmod(pow(z, 2), n);
printf("%d\n", result_2);
}
返回:
-669207835 => this is the correct option and it should be 7629321670
-480306461
【问题讨论】:
-
为什么对无符号整数数据使用浮点函数?
-
试试
result = (z*z* 2) % n。 -
这仍然返回负数
-
%d仅用于打印int
标签: c int modulus negative-number int128