Details

Bug

Status: Closed

Major

Resolution: Fixed

3.2

None

Java build 1.7.0_45b18
Description
In org.apache.commons.math3.special.Beta.regularizedBeta(double,double,double,double,int), the case
} else if (x > (a + 1.0) / (a + b + 2.0)) {
ret = 1.0  regularizedBeta(1.0  x, b, a, epsilon, maxIterations);
}
is prone to infinite recursion: If x is approximately the tested value, then 1x is approximately the tested value in the recursion. Thus, due to loss of precision after the subtraction, this condition can be true for the recursive call as well.
Example:
double x= Double.longBitsToDouble(4597303555101269224L);
double a= Double.longBitsToDouble(4634227472812299606L);
double b = Double.longBitsToDouble(4642050131540049920L);
System.out.println(x > (a + 1.0) / (a + b + 2.0));
System.out.println(1x>(b + 1.0) / (b + a + 2.0));
System.out.println(1(1x)>(a + 1.0) / (a + b + 2.0));
Possible solution: change the condition to
x > (a + 1.0) / (a + b + 2.0) && 1x<=(b + 1.0) / (b + a + 2.0)