Problem
Compute x raised to the power n, where x is a floating-point number and n is an integer that may be negative. Do not use the built-in power operator or Math.pow. Answers within 10^-5 are accepted.
Example 1
- Input
- x = 2.0, n = 10
- Output
- 1024.0
Example 2
- Input
- x = 2.1, n = 3
- Output
- 9.261
Example 3
- Input
- x = 2.0, n = -2
- Output
- 0.25
- Why
- 1 / 2^2
Constraints
-100.0 < x < 100.0-2^31 <= n <= 2^31 - 1Either x is not zero or n > 0.-10^4 <= x^n <= 10^4