I'm trying to figure out the following issue related to BigIntegers in Java 7 x64. I am attempting to calculate a number to an extremely high power. Code is below, followed by a description of the problem.
import java.math.BigInteger;
public class main {
public static void main(String[] args) {
// Demo calculation; Desired calculation: BigInteger("4096").pow(800*600)
BigInteger images = new BigInteger("2").pow(15544);
System.out.println(
"The number of possible 16 bpc color 800x600 images is: "
+ images.toString());
}
}
I am encountering issues printing the result of this operation. When this code executes it prints the message but not the value of images.toString()
.
To isolate the problem I started calculating powers of two instead of the desired calculation listed in the comment on that line. On the two systems I have tested this on, 2^15544
is the smallest calculation that triggers the problem; 2^15543
works fine.
I'm no where close to hitting the memory limit on the host systems and I don't believe that I am even close to the VM limit (at any rate running with the VM arguments -Xmx1024M
-Xms1024M
has no effect).
After poking around the internet looking for answers I have come to suspect that I am hitting a limit in either BigInteger
or String
related to the maximum size of an array (Integer.MAX_VALUE
) that those types use for internal data storage. If the problem is in String
I think it would be possible to extend BigInteger
and write a print method that spews out a few chars at a time until the entire BigInteger
is printed, but I rather suspect that the problem lies elsewhere.
Thank you for taking the time to read my question.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…