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

# pow(x, n)

```java
class Solution {
    public double myPow(double x, int n) {
        if (n > 0) {
            return pow(x, n);
        }
        else {
            return 1.0 / pow(x, n);
        }
    }

    public static double pow(double x, int n) {
        if (n == 0) {
            return 1;
        }
        double y = pow(x, n/2);
        if (n % 2 == 0) {
            return y * y;
        }
        else {
            return y * y * x;
        }
    }

}
```
