public double pow(double x, int n) {
		if (n == 0)
			return 1;

		if (n == 1)
			return x;

		if (n == -1) {
			if (x != 0) {
				return 1 / x;
			} else {
				return Integer.MAX_VALUE;
			}
		}

		// n>=2 || n<=-2;
		double square = x * x;
		if (n > 0) {
			int powerForSquare = n / 2;
			int restPower = n % 2;

			return pow(square, powerForSquare) * pow(x, restPower);
		} else {
			int tmpN = -n;
			int powerForSquare = tmpN / 2;
			int restPower = tmpN % 2;

			return 1 / (pow(square, powerForSquare) * pow(x, restPower));
		}
	}