```
double myPow(double x, int n) {
if (n == 0) return 1;
if (n == 1) return x;
if (n == -1) return 1/x;
double val;
if (n > 0){
val = myPow(x, n / 2);
if (n % 2 == 1){
return val*val*x;
}
else
return val*val;
}
else{
val = 1 / myPow(x, -n / 2);
if (n % 2 == -1){
return val *val / x;
}
else{
return val * val;
}
}
```

}