My code gives timeout error .So,pls give any solutions..............

This is my code....

double myPow(double x, int n) {

double ans=1;

```
if(n<0){
n=n*(-1);
x=1/x;
}
while(n){
if(n & 1)
ans*=x;
x=x*x;
n=n>>1;
}
return ans;
```

}