Divisibility of a java.math.BigInteger object

S

Stefan Ram

Calculating the remainder of a java.math.BigInteger object
seems to be slow. For a number > 100, it would be sufficient
and possibly faster to just extract the two least significant
digits and compare them with »00«. But I can not directly
access the internal representation of a java.math.BigInteger
object. Does anyone see a possibility to accelerate such a
divisibility test for a java.math.BigInteger object using the
same tricks one uses when testing this by mental arithmetic?

(This is not premature optimization. I already have a program
that is too slow, and a profiler showed that it spends a
significant amount of time in java.math.BigInteger.remainder:

java.math.BigInteger.remainder 1.35 %
java.math.BigInteger.<init> 1.01 %
java.math.BigInteger.add 1.01 %
java.math.BigInteger.divide 0.68 %
java.math.BigInteger.valueOf 0.68 %
java.math.BigInteger.subtract 0.34 %
java.math.BigInteger.multiply 0.34 %

Because the profiler also includes program startup and other
phases of the process, the percentage of the
java.math.BigInteger.remainder operation is larger then shown
above when put in relation to the actual calculation phase.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top