Exponentiation

From Algorithmist
Jump to navigation Jump to search

The classic method of calculating exponentiation:

  1. Start your output number at 1.
  2. If the exponent is odd, multiply the output by the base, and subtract 1 from the exponent.
  3. Divide the exponent by 2, and multiply the base by itself.
  4. If the exponent is still greater than 0, loop back to step 2.