Program: 57085
Project: 57085
Buggy source:
/** 
 * Computes x to the y power.<p> Uses the following method:<p> <ol> <li> Set u = rint(y), v = y-u <li> Compute a = v * ln(x) <li> Compute b = rint( a/ln(2) ) <li> Compute c = a - b*ln(2) <li> x<sup>y</sup> = x<sup>u</sup>  *   2<sup>b</sup> * e<sup>c</sup> </ol> if |y| > 1e8, then we compute by exp(y*ln(x))   <p> <b>Special Cases</b><p> <ul> <li>  if y is 0.0 or -0.0 then result is 1.0 <li>  if y is 1.0 then result is x <li>  if y is NaN then result is NaN <li>  if x is NaN and y is not zero then result is NaN <li>  if |x| > 1.0 and y is +Infinity then result is +Infinity <li>  if |x| < 1.0 and y is -Infinity then result is +Infinity <li>  if |x| > 1.0 and y is -Infinity then result is +0 <li>  if |x| < 1.0 and y is +Infinity then result is +0 <li>  if |x| = 1.0 and y is +/-Infinity then result is NaN <li>  if x = +0 and y > 0 then result is +0 <li>  if x = +Inf and y < 0 then result is +0 <li>  if x = +0 and y < 0 then result is +Inf <li>  if x = +Inf and y > 0 then result is +Inf <li>  if x = -0 and y > 0, finite, not odd integer then result is +0 <li>  if x = -0 and y < 0, finite, and odd integer then result is -Inf <li>  if x = -Inf and y > 0, finite, and odd integer then result is -Inf <li>  if x = -0 and y < 0, not finite odd integer then result is +Inf <li>  if x = -Inf and y > 0, not finite odd integer then result is +Inf <li>  if x < 0 and y > 0, finite, and odd integer then result is -(|x|<sup>y</sup>) <li>  if x < 0 and y > 0, finite, and not integer then result is NaN </ul>
 * @param x base to be raised
 * @param y power to which base should be raised
 * @return x<sup>y</sup>
 */
public static Dfp pow(Dfp x,final Dfp y){
  if (x.getField().getRadixDigits() != y.getField().getRadixDigits()) {
    x.getField().setIEEEFlagsBits(DfpField.FLAG_INVALID);
    final Dfp result=x.newInstance(x.getZero());
    result.nans=Dfp.QNAN;
    return x.dotrap(DfpField.FLAG_INVALID,POW_TRAP,x,result);
  }
  final Dfp zero=x.getZero();
  final Dfp one=x.getOne();
  final Dfp two=x.getTwo();
  boolean invert=false;
  int ui;
  if (y.equals(zero)) {
    return x.newInstance(one);
  }
  if (y.equals(one)) {
    if (x.isNaN()) {
      x.getField().setIEEEFlagsBits(DfpField.FLAG_INVALID);
      return x.dotrap(DfpField.FLAG_INVALID,POW_TRAP,x,x);
    }
    return x;
  }
  if (x.isNaN() || y.isNaN()) {
    x.getField().setIEEEFlagsBits(DfpField.FLAG_INVALID);
    return x.dotrap(DfpField.FLAG_INVALID,POW_TRAP,x,x.newInstance((byte)1,Dfp.QNAN));
  }
  if (x.equals(zero)) {
    if (Dfp.copysign(one,x).greaterThan(zero)) {
      if (y.greaterThan(zero)) {
        return x.newInstance(zero);
      }
 else {
        return x.newInstance(x.newInstance((byte)1,Dfp.INFINITE));
      }
    }
 else {
      if (y.classify() == Dfp.FINITE && y.rint().equals(y) && !y.remainder(two).equals(zero)) {
        if (y.greaterThan(zero)) {
          return x.newInstance(zero.negate());
        }
 else {
          return x.newInstance(x.newInstance((byte)-1,Dfp.INFINITE));
        }
      }
 else {
        if (y.greaterThan(zero)) {
          return x.newInstance(zero);
        }
 else {
          return x.newInstance(x.newInstance((byte)1,Dfp.INFINITE));
        }
      }
    }
  }
  if (x.lessThan(zero)) {
    x=x.negate();
    invert=true;
  }
  if (x.greaterThan(one) && y.classify() == Dfp.INFINITE) {
    if (y.greaterThan(zero)) {
      return y;
    }
 else {
      return x.newInstance(zero);
    }
  }
  if (x.lessThan(one) && y.classify() == Dfp.INFINITE) {
    if (y.greaterThan(zero)) {
      return x.newInstance(zero);
    }
 else {
      return x.newInstance(Dfp.copysign(y,one));
    }
  }
  if (x.equals(one) && y.classify() == Dfp.INFINITE) {
    x.getField().setIEEEFlagsBits(DfpField.FLAG_INVALID);
    return x.dotrap(DfpField.FLAG_INVALID,POW_TRAP,x,x.newInstance((byte)1,Dfp.QNAN));
  }
  if (x.classify() == Dfp.INFINITE) {
    if (invert) {
      if (y.classify() == Dfp.FINITE && y.rint().equals(y) && !y.remainder(two).equals(zero)) {
        if (y.greaterThan(zero)) {
          return x.newInstance(x.newInstance((byte)-1,Dfp.INFINITE));
        }
 else {
          return x.newInstance(zero.negate());
        }
      }
 else {
        if (y.greaterThan(zero)) {
          return x.newInstance(x.newInstance((byte)1,Dfp.INFINITE));
        }
 else {
          return x.newInstance(zero);
        }
      }
    }
 else {
      if (y.greaterThan(zero)) {
        return x;
      }
 else {
        return x.newInstance(zero);
      }
    }
  }
  if (invert && !y.rint().equals(y)) {
    x.getField().setIEEEFlagsBits(DfpField.FLAG_INVALID);
    return x.dotrap(DfpField.FLAG_INVALID,POW_TRAP,x,x.newInstance((byte)1,Dfp.QNAN));
  }
  Dfp r;
  if (y.lessThan(x.newInstance(100000000)) && y.greaterThan(x.newInstance(-100000000))) {
    final Dfp u=y.rint();
    ui=u.intValue();
    final Dfp v=y.subtract(u);
    if (v.unequal(zero)) {
      final Dfp a=v.multiply(log(x));
      final Dfp b=a.divide(x.getField().getLn2()).rint();
      final Dfp c=a.subtract(b.multiply(x.getField().getLn2()));
      r=splitPow(split(x),ui);
      r=r.multiply(pow(two,b.intValue()));
      r=r.multiply(exp(c));
    }
 else {
      r=splitPow(split(x),ui);
    }
  }
 else {
    r=exp(log(x).multiply(y));
  }
  if (invert && y.rint().equals(y) && !y.remainder(two).equals(zero)) {
    r=r.negate();
  }
  return x.newInstance(r);
}

Fixed version (ground truth):
/** 
 * Computes x to the y power.<p> Uses the following method: <ol> <li> Set u = rint(y), v = y-u <li> Compute a = v * ln(x) <li> Compute b = rint( a/ln(2) ) <li> Compute c = a - b*ln(2) <li> x<sup>y</sup> = x<sup>u</sup>  *   2<sup>b</sup> * e<sup>c</sup> </ol> if   {@code |y| > 1e8}, then we compute by   {@code exp(y*ln(x))}<p> <b>Special Cases</b> <ul> <li>  if y is 0.0 or -0.0 then result is 1.0 <li>  if y is 1.0 then result is x <li>  if y is NaN then result is NaN <li>  if x is NaN and y is not zero then result is NaN <li>  if   {@code |x| > 1.0} and y is +Infinity then result is +Infinity<li>  if  {@code |x| < 1.0} and y is -Infinity then result is +Infinity<li>  if  {@code |x| > 1.0} and y is -Infinity then result is +0<li>  if  {@code |x| < 1.0} and y is +Infinity then result is +0<li>  if  {@code |x| = 1.0} and y is +/-Infinity then result is NaN<li>  if  {@code x = +0} and {@code y > 0} then result is +0<li>  if  {@code x = +Inf} and {@code y < 0} then result is +0<li>  if  {@code x = +0} and {@code y < 0} then result is +Inf<li>  if  {@code x = +Inf} and {@code y > 0} then result is +Inf<li>  if  {@code x = -0} and {@code y > 0}, finite, not odd integer then result is +0 <li>  if   {@code x = -0} and {@code y < 0}, finite, and odd integer then result is -Inf <li>  if   {@code x = -Inf} and {@code y > 0}, finite, and odd integer then result is -Inf <li>  if   {@code x = -0} and {@code y < 0}, not finite odd integer then result is +Inf <li>  if   {@code x = -Inf} and {@code y > 0}, not finite odd integer then result is +Inf <li>  if   {@code x < 0} and {@code y > 0}, finite, and odd integer then result is -(|x|<sup>y</sup>) <li>  if   {@code x < 0} and {@code y > 0}, finite, and not integer then result is NaN </ul>
 * @param x base to be raised
 * @param y power to which base should be raised
 * @return x<sup>y</sup>
 */
public static Dfp pow(Dfp x,final Dfp y){
  if (x.getField().getRadixDigits() != y.getField().getRadixDigits()) {
    x.getField().setIEEEFlagsBits(DfpField.FLAG_INVALID);
    final Dfp result=x.newInstance(x.getZero());
    result.nans=Dfp.QNAN;
    return x.dotrap(DfpField.FLAG_INVALID,POW_TRAP,x,result);
  }
  final Dfp zero=x.getZero();
  final Dfp one=x.getOne();
  final Dfp two=x.getTwo();
  boolean invert=false;
  int ui;
  if (y.equals(zero)) {
    return x.newInstance(one);
  }
  if (y.equals(one)) {
    if (x.isNaN()) {
      x.getField().setIEEEFlagsBits(DfpField.FLAG_INVALID);
      return x.dotrap(DfpField.FLAG_INVALID,POW_TRAP,x,x);
    }
    return x;
  }
  if (x.isNaN() || y.isNaN()) {
    x.getField().setIEEEFlagsBits(DfpField.FLAG_INVALID);
    return x.dotrap(DfpField.FLAG_INVALID,POW_TRAP,x,x.newInstance((byte)1,Dfp.QNAN));
  }
  if (x.equals(zero)) {
    if (Dfp.copysign(one,x).greaterThan(zero)) {
      if (y.greaterThan(zero)) {
        return x.newInstance(zero);
      }
 else {
        return x.newInstance(x.newInstance((byte)1,Dfp.INFINITE));
      }
    }
 else {
      if (y.classify() == Dfp.FINITE && y.rint().equals(y) && !y.remainder(two).equals(zero)) {
        if (y.greaterThan(zero)) {
          return x.newInstance(zero.negate());
        }
 else {
          return x.newInstance(x.newInstance((byte)-1,Dfp.INFINITE));
        }
      }
 else {
        if (y.greaterThan(zero)) {
          return x.newInstance(zero);
        }
 else {
          return x.newInstance(x.newInstance((byte)1,Dfp.INFINITE));
        }
      }
    }
  }
  if (x.lessThan(zero)) {
    x=x.negate();
    invert=true;
  }
  if (x.greaterThan(one) && y.classify() == Dfp.INFINITE) {
    if (y.greaterThan(zero)) {
      return y;
    }
 else {
      return x.newInstance(zero);
    }
  }
  if (x.lessThan(one) && y.classify() == Dfp.INFINITE) {
    if (y.greaterThan(zero)) {
      return x.newInstance(zero);
    }
 else {
      return x.newInstance(Dfp.copysign(y,one));
    }
  }
  if (x.equals(one) && y.classify() == Dfp.INFINITE) {
    x.getField().setIEEEFlagsBits(DfpField.FLAG_INVALID);
    return x.dotrap(DfpField.FLAG_INVALID,POW_TRAP,x,x.newInstance((byte)1,Dfp.QNAN));
  }
  if (x.classify() == Dfp.INFINITE) {
    if (invert) {
      if (y.classify() == Dfp.FINITE && y.rint().equals(y) && !y.remainder(two).equals(zero)) {
        if (y.greaterThan(zero)) {
          return x.newInstance(x.newInstance((byte)-1,Dfp.INFINITE));
        }
 else {
          return x.newInstance(zero.negate());
        }
      }
 else {
        if (y.greaterThan(zero)) {
          return x.newInstance(x.newInstance((byte)1,Dfp.INFINITE));
        }
 else {
          return x.newInstance(zero);
        }
      }
    }
 else {
      if (y.greaterThan(zero)) {
        return x;
      }
 else {
        return x.newInstance(zero);
      }
    }
  }
  if (invert && !y.rint().equals(y)) {
    x.getField().setIEEEFlagsBits(DfpField.FLAG_INVALID);
    return x.dotrap(DfpField.FLAG_INVALID,POW_TRAP,x,x.newInstance((byte)1,Dfp.QNAN));
  }
  Dfp r;
  if (y.lessThan(x.newInstance(100000000)) && y.greaterThan(x.newInstance(-100000000))) {
    final Dfp u=y.rint();
    ui=u.intValue();
    final Dfp v=y.subtract(u);
    if (v.unequal(zero)) {
      final Dfp a=v.multiply(log(x));
      final Dfp b=a.divide(x.getField().getLn2()).rint();
      final Dfp c=a.subtract(b.multiply(x.getField().getLn2()));
      r=splitPow(split(x),ui);
      r=r.multiply(pow(two,b.intValue()));
      r=r.multiply(exp(c));
    }
 else {
      r=splitPow(split(x),ui);
    }
  }
 else {
    r=exp(log(x).multiply(y));
  }
  if (invert && y.rint().equals(y) && !y.remainder(two).equals(zero)) {
    r=r.negate();
  }
  return x.newInstance(r);
}