Java ArithmeticException BigInteger would overflow supported range -
i working on algorithm check if number prime , need work big numbers therefore using biginteger class. problem exception thrown arithmeticexception biginteger overflow supported range.
exception in thread "main" java.lang.arithmeticexception: biginteger overflow supported range @ java.math.biginteger.reportoverflow(unknown source) @ java.math.biginteger.checkrange(unknown source) @ java.math.biginteger.<init>(unknown source) @ java.math.biginteger.shiftleft(unknown source) @ java.math.biginteger.pow(unknown source) @ kitas.main(kitas.java:118)
and line exception thrown:
b = biginteger.valueof(2).pow((int) (35*(math.pow(2, counter))));
once counter reaches value of 26, exception thrown.
(int) (35 * math.pow(2, 26)) == (int) (2348810240d) = integer.max_value
with result power you're trying raise 2 integer.max_value, result have on integer.max_value binary digits. biginteger
isn't big enough that, , storing numbers large pretty impractical.
nothing built java let test primality of numbers large.