```
public class Solution {
public double MyPow(double x, int n) {
if(n==0) return 1;
if(n<0){
n=-n;
x =1/x;
}
var ret = n%2 == 0? MyPow(x*x, n/2): MyPow(x*x, n/2) * x;
return double.IsInfinity(ret)? 0:ret;
}
}
```