예제 #1
0
파일: Powxn.cpp 프로젝트: kyliau/playground
 double positivePow(double x, unsigned n) {
     if (0 == n) {
         return 1;
     }
     double result = positivePow(x, n / 2);
     result *= result;
     return (n % 2 == 0) ? result : result * x;
 }
예제 #2
0
파일: 50.cpp 프로젝트: SnowyOwl-KHY/OJ
 double myPow(double x, int n) {
     if (n == 0) return 1;
     else if (n < 0) return 1 / positivePow(x, -n);
     else return positivePow(x, n);
 }
예제 #3
0
파일: Powxn.cpp 프로젝트: kyliau/playground
 double myPow(double x, int n) {
     return n > 0 ? positivePow(x, n) : 1 / positivePow(x, -n);
 }