Calculating powers of integers

The Solution to Calculating powers of integers is

Integers are only 32 bits. This means that its max value is 2^31 -1. As you see, for very small numbers, you quickly have a result which can't be represented by an integer anymore. That's why Math.pow uses double.

If you want arbitrary integer precision, use BigInteger.pow. But it's of course less efficient.

~ Answered on 2011-11-09 20:47:26

Most Viewed Questions: