MATH-1067
Avoid infinite recursion. Thanks to Florian Erhard. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1546350 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c1ba07bb65
commit
aff82362cf
|
@ -51,6 +51,9 @@ If the output is not quite correct, check for invisible trailing spaces!
|
|||
</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>
|
||||
|
|
|
@ -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() {
|
||||
|
||||
|
|
|
@ -141,6 +141,19 @@ public class BetaTest {
|
|||
TestUtils.assertEquals(9.999950000166648e-6, actual, 1e-16);
|
||||
}
|
||||
|
||||
@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);
|
||||
|
|
Loading…
Reference in New Issue