Math.pow(23,29)%91 的结果为什么是错误的?
public class T1 {
public static void main(String[] args) {
double c = Math.pow(23,29)%91.0;
System.out.println(c);
}
}
输出:28.0
int c = (int)Math.pow(23,29)%91;
System.out.println(c);
输出 36
然而这都不是正确答案
正确取余后的值是4才对
伊谢尔伦2017-04-18 10:55:16
Insufficient precision, 23 ^ 29
是个40位
Decimal number,
double
There are only 15 significant digits, so the exact value at the end cannot be expressed at all
int
The maximum value is only 10 digits, so the assignment has already overflowed
PHP中文网2017-04-18 10:55:16
Double is a floating point number. It is best to use BigInteger to solve your problem.