You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2013/11/28 12:41:12 UTC

svn commit: r1546350 - in /commons/proper/math/trunk/src: changes/changes.xml main/java/org/apache/commons/math3/special/Beta.java test/java/org/apache/commons/math3/special/BetaTest.java

Author: erans
Date: Thu Nov 28 11:41:12 2013
New Revision: 1546350

URL: http://svn.apache.org/r1546350
Log:
MATH-1067
Avoid infinite recursion. Thanks to Florian Erhard.

Modified:
    commons/proper/math/trunk/src/changes/changes.xml
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Beta.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/special/BetaTest.java

Modified: commons/proper/math/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1546350&r1=1546349&r2=1546350&view=diff
==============================================================================
--- commons/proper/math/trunk/src/changes/changes.xml (original)
+++ commons/proper/math/trunk/src/changes/changes.xml Thu Nov 28 11:41:12 2013
@@ -51,6 +51,9 @@ If the output is not quite correct, chec
   </properties>
   <body>
     <release version="3.3" date="TBD" description="TBD">
+      <action dev="erans" type="fix" issue="MATH-1067" due-to="Florian Erhard">
+        Avoid infinite recursion in "Beta.regularizedBeta" (package "o.a.c.m.special");
+      </action>
       <action dev="erans" type="add" issue="MATH-1014">
         Refactoring of curve fitters (package "o.a.c.m.fitting").
       </action>

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Beta.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Beta.java?rev=1546350&r1=1546349&r2=1546350&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Beta.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/special/Beta.java Thu Nov 28 11:41:12 2013
@@ -189,11 +189,12 @@ public class Beta {
             Double.isNaN(b) ||
             x < 0 ||
             x > 1 ||
-            a <= 0.0 ||
-            b <= 0.0) {
+            a <= 0 ||
+            b <= 0) {
             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 if (x > (a + 1) / (2 + b + a) &&
+                   1 - x <= (b + 1) / (2 + b + a)) {
+            ret = 1 - regularizedBeta(1 - x, b, a, epsilon, maxIterations);
         } else {
             ContinuedFraction fraction = new ContinuedFraction() {
 

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/special/BetaTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/special/BetaTest.java?rev=1546350&r1=1546349&r2=1546350&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/special/BetaTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/special/BetaTest.java Thu Nov 28 11:41:12 2013
@@ -142,6 +142,19 @@ public class BetaTest {
     }
 
     @Test
+    public void testMath1067() {
+        final double x = 0.22580645161290325;
+        final double a = 64.33333333333334;
+        final double b = 223;
+
+        try {
+            final double r = Beta.regularizedBeta(x, a, b, 1e-14, 10000);
+        } catch (StackOverflowError error) {
+            Assert.fail("Infinite recursion");
+        }
+    }
+
+    @Test
     public void testLogBetaNanPositive() {
         testLogBeta(Double.NaN, Double.NaN, 2.0);
     }