Description
Implement pow(x, n), which calculates x raised to the power n (i.e., xⁿ). Use fast exponentiation for efficiency.
Examples
Input:
x = 2.00000, n = 10Output:
1024.00000Explanation:
2^10 = 1024.
Input:
x = 2.0, n = -2Output:
0.25Explanation:
Works with negative numbers.
Input:
x = -3.00000, n = 4Output:
81.00000Explanation:
(-3)^4 = (-3) × (-3) × (-3) × (-3) = 81. When a negative number is raised to an even power, the result is positive.
Constraints
- •
-100.0 < x < 100.0 - •
-2³¹ ≤ n ≤ 2³¹ - 1