{
ret = Double.NaN;
} else if (x > (a + 1.0) / (a + b + 2.0)) {
ret = 1.0 - regularizedBeta(1.0 - x, b, a, epsilon, maxIterations);
} else {
ContinuedFraction fraction = new ContinuedFraction() {
@Override
protected double getB(int n, double x) {
double ret;
double m;
if (n % 2 == 0) { // even
m = n / 2.0;
ret = (m * (b - m) * x) /
((a + (2 * m) - 1) * (a + (2 * m)));
} else {
m = (n - 1.0) / 2.0;
ret = -((a + m) * (a + b + m) * x) /
((a + (2 * m)) * (a + (2 * m) + 1.0));
}
return ret;
}
@Override
protected double getA(int n, double x) {
return 1.0;
}
};
ret = FastMath.exp((a * FastMath.log(x)) + (b * FastMath.log(1.0 - x)) -
FastMath.log(a) - logBeta(a, b, epsilon, maxIterations)) *
1.0 / fraction.evaluate(x, epsilon, maxIterations);
}
return ret;
}