Florian Erhard created MATH-1067:
------------------------------------

             Summary: Stack overflow in Beta.regularizedBeta
                 Key: MATH-1067
                 URL: https://issues.apache.org/jira/browse/MATH-1067
             Project: Commons Math
          Issue Type: Bug
    Affects Versions: 3.2
         Environment: Java build 1.7.0_45-b18
            Reporter: Florian Erhard


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 
1-x 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(1-x>(b + 1.0) / (b + a + 2.0));
System.out.println(1-(1-x)>(a + 1.0) / (a + b + 2.0));

Possible solution: change the condition to
x > (a + 1.0) / (a + b + 2.0) && 1-x<=(b + 1.0) / (b + a + 2.0)



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Reply via email to