|| (x > 1) || (a <= 0.0) || (b <= 0.0)) {
ret = Double.NaN;
} else if (x > (a + 1.0) / (a + b + 2.0)) {
ret = 1.0 - regularizedBeta(1.0 - x, b, a);
} else {
ContinuedFraction fraction = new ContinuedFraction() {
protected double getA(int n, double x) {
return 1.0;
}
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.0 * m) - 1.0) * (a + (2.0 * m)));
} else {
m = (n - 1.0) / 2.0;
ret = -((a + m) * (a + b + m) * x)
/ ((a + (2.0 * m)) * (a + (2.0 * m) + 1.0));
}
return ret;
}
};
ret = Math.exp((a * Math.log(x)) + (b * Math.log(1.0 - x))
- Math.log(a) - logBeta(a, b))
/ fraction.evaluate(x);
}
return ret;
}