public class MathPow {


    public static double pow(double x, double y)
    {
        double val = 0.0;
        boolean mult = false;
        if (x < 0) {
            //x = -1*x;
            x = Math.abs(x);
            mult = true;
            // if y is NOT both EVEN and non-fractional, mult 
            //  result by -1.
            //if (y == 0 || y == 2 || y == -2)
            // this is true, because the low bit will always be set
            //  if it's an odd number; also bit-wise and is faster
            //  than the modulus operator.
            if ( ((int)y & 1) == 0)
                mult = false;
        }
        val = Math.pow(x,y);
        if (mult) val *= -1;
        return val;
    }
}
