Program: 57568
Project: 57568
Buggy source:
/** 
 * Returns the regularized beta function I(x, a, b). The implementation of this method is based on: <ul> <li> <a href="http://mathworld.wolfram.com/RegularizedBetaFunction.html"> Regularized Beta Function</a>.</li> <li> <a href="http://functions.wolfram.com/06.21.10.0001.01"> Regularized Beta Function</a>.</li> </ul>
 * @param x ???
 * @param a ???
 * @param b ???
 * @param epsilon When the absolute value of the nth item in theseries is less than epsilon the approximation ceases to calculate further elements in the series.
 * @param maxIterations Maximum number of "iterations" to complete. 
 * @return the regularized beta function I(x, a, b)
 * @throws MathException if the algorithm fails to converge.
 */
public static double regularizedBeta(double x,final double a,final double b,double epsilon,int maxIterations) throws MathException {
  double ret;
  if (Double.isNaN(x) || Double.isNaN(a) || Double.isNaN(b)|| (x < 0)|| (x > 1)|| (a <= 0.0)|| (b <= 0.0)) {
    ret=Double.NaN;
  }
 else {
    ContinuedFraction fraction=new ContinuedFraction(){
      protected double getB(      int n,      double x){
        double ret;
        double m;
switch (n) {
case 1:
          ret=1.0;
        break;
default :
      if (n % 2 == 0) {
        m=(n - 2.0) / 2.0;
        ret=-((a + m) * (a + b + m) * x) / ((a + (2 * m)) * (a + (2 * m) + 1.0));
      }
 else {
        m=(n - 1.0) / 2.0;
        ret=(m * (b - m) * x) / ((a + (2 * m) - 1) * (a + (2 * m)));
      }
    break;
}
return ret;
}
protected double getA(int n,double x){
double ret;
switch (n) {
case 0:
  ret=0.0;
break;
default :
ret=1.0;
break;
}
return ret;
}
}
;
ret=Math.exp((a * Math.log(x)) + (b * Math.log(1.0 - x)) - Math.log(a) - logBeta(a,b,epsilon,maxIterations)) * fraction.evaluate(x,epsilon,maxIterations);
}
return ret;
}

Fixed version (ground truth):
/** 
 * Returns the regularized beta function I(x, a, b). The implementation of this method is based on: <ul> <li> <a href="http://mathworld.wolfram.com/RegularizedBetaFunction.html"> Regularized Beta Function</a>.</li> <li> <a href="http://functions.wolfram.com/06.21.10.0001.01"> Regularized Beta Function</a>.</li> </ul>
 * @param x ???
 * @param a ???
 * @param b ???
 * @param epsilon When the absolute value of the nth item in theseries is less than epsilon the approximation ceases to calculate further elements in the series.
 * @param maxIterations Maximum number of "iterations" to complete. 
 * @return the regularized beta function I(x, a, b)
 * @throws MathException if the algorithm fails to converge.
 */
public static double regularizedBeta(double x,final double a,final double b,double epsilon,int maxIterations) throws MathException {
  double ret;
  if (Double.isNaN(x) || Double.isNaN(a) || Double.isNaN(b)|| (x < 0)|| (x > 1)|| (a <= 0.0)|| (b <= 0.0)) {
    ret=Double.NaN;
  }
 else   if (x > (a + 1.0) / (a + b + 1.0)) {
    ret=1.0 - regularizedBeta(1.0 - x,b,a,epsilon,maxIterations);
  }
 else {
    ContinuedFraction fraction=new ContinuedFraction(){
      protected double getB(      int n,      double x){
        double ret;
        double m;
switch (n) {
case 1:
          ret=1.0;
        break;
default :
      if (n % 2 == 0) {
        m=(n - 2.0) / 2.0;
        ret=-((a + m) * (a + b + m) * x) / ((a + (2 * m)) * (a + (2 * m) + 1.0));
      }
 else {
        m=(n - 1.0) / 2.0;
        ret=(m * (b - m) * x) / ((a + (2 * m) - 1) * (a + (2 * m)));
      }
    break;
}
return ret;
}
protected double getA(int n,double x){
double ret;
switch (n) {
case 0:
  ret=0.0;
break;
default :
ret=1.0;
break;
}
return ret;
}
}
;
ret=Math.exp((a * Math.log(x)) + (b * Math.log(1.0 - x)) - Math.log(a) - logBeta(a,b,epsilon,maxIterations)) * fraction.evaluate(x,epsilon,maxIterations);
}
return ret;
}