Last updated 2 years ago
Fast Exponentiation Formula
double myPow(double x, int n) { if(n == 0) return 1; double temp = myPow(x, n / 2); return temp * temp * ((n & 1) ? ((n >= 0) ? x : (1 / x)) : 1); }
double myPow(double x, int n) { if(n == 0) return 1; double temp = myPow(x, n / 2); if(n & 1) { if(n >= 0) return temp * temp * x; else return temp * temp / x; } else return temp * temp; }