If n < 0, set x = 1 / x and n = -n.
Initialize result = 1.
While n > 0: if n is odd, multiply result by x. Square x. Divide n by 2.
Return result.
(Fast exponentiation with negatives)
If n < 0, set x = 1 / x and n = -n.
Initialize result = 1.
While n > 0: if n is odd, multiply result by x. Square x. Divide n by 2.
Return result.