double denominatorValue = Math.pow(denominator, power); double numeratorValue = Math.pow(numerator, power); if (numeratorValue > Integer.MAX_VALUE || denominatorValue > Integer.MAX_VALUE) { throw new ArithmeticException("Integer overflow");
Fraction f = this.multiplyBy(this); if ((power % 2) == 0) { return f.pow(power/2); } else { return f.pow(power/2).multiplyBy(this);
    public Fraction pow(int power) {        if (power == 1) {            return this;        } else if (power == 0) {            return ONE;        } else {            double denominatorValue = Math.pow(denominator, power);            double numeratorValue = Math.pow(numerator, power);            if (numeratorValue > Integer.MAX_VALUE || denominatorValue > Integer.MAX_VALUE) {                throw new ArithmeticException("Integer overflow");            }            if (power < 0) {                return getFraction((int) Math.pow(denominator, -power),                     (int) Math.pow(numerator, -power));            }            return getFraction((int) Math.pow(numerator, power),                 (int) Math.pow(denominator, power));        }    }