class Solution {

public:

double myPow(double x, int n) {

long int ln = n;

if (ln == 0)

{

return 1;

}

if (x == 0 && ln <0)

{

return std::numeric_limits<double>::infinity();

}

else if (x !=0 && ln <0)

{

ln= -ln;

x = 1/x;

}

double ans =1;

while (ln>0)

{

if (ln&1) ans*= x;

x = x*x;

ln >>= 1;

}

```
return ans;
}
```

};