public double pow1(double x, int n){ // deal with negativity in one statement
        if(n == 1) return x;
        if(n == 0) return 1.0;
        if(n == -1) return 1.0 / x;
        double y = pow1(x, n / 2);
        if(n % 2 == 0) {
            return y * y;
        }else{
            return y * y * pow1(x, n - 2*(n/2));
        }
    }