public static double pow(double x, int n) {
        if (0 == n) return 1;
        else {
        	double tmp = pow(x, n/2);
        	if (0 == n % 2) {
        		return tmp * tmp;
        	} else {
        		if (n > 0) {
        			return tmp * tmp * x;
        		} else {
        			return tmp * tmp / x;
        		}
        	}
        }
    }