> For the complete documentation index, see [llms.txt](https://chiragjain.gitbook.io/neetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://chiragjain.gitbook.io/neetcode/50-powx-n/code.md).

# CODE

```python
class Solution:
    def myPow(self, x: float, n: int) -> float:
        m, result, current_product = abs(n), 1, x
        while m > 0:
            if m % 2 == 1:
                result *= current_product
            current_product *= current_product
            m = m // 2
        return result if n > 0 else 1 / result
        
```
