public double pow(double x, int n) {
		if (n < 0) {
			x = 1 / x;
			n = Math.abs(n);
		}

		if (n == 0)
			return 1;

		double result = 1;
		double temp = x;
		while (n > 0) {
			// odd number
			if (n % 2 != 0) {
				result *= temp;
			}
			temp = temp * temp;
			n /= 2;
		}
		return result;
	}