92. Pow(x, n)

Medium · Math

Implement a function to compute x raised to the power of n (x^n). The exponent n can be negative, and you must handle it correctly. You cannot use built-in exponentiation functions like Math.pow() or the ** operator.

Your solution should be efficient and handle edge cases including negative exponents, zero exponent, and the minimum 32-bit signed integer.

Examples

Example 1
Input: x = 2.0, n = 10
Output: 1024.0
Explanation: 2^10 = 1024
Example 2
Input: x = 2.0, n = -2
Output: 0.25
Explanation: 2^(-2) = 1/(2^2) = 1/4 = 0.25

Constraints