MATH-1021
Reordering can prevent some overflow occurrences (fix suggested by Brian Bloniarz). Added unit test. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1512546 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6d66a863b5
commit
f1467e45ab
3
pom.xml
3
pom.xml
|
@ -150,6 +150,9 @@
|
|||
<contributor>
|
||||
<name>Michael Bjorkegren</name>
|
||||
</contributor>
|
||||
<contributor>
|
||||
<name>Brian Bloniarz</name>
|
||||
</contributor>
|
||||
<contributor>
|
||||
<name>John Bollinger</name>
|
||||
</contributor>
|
||||
|
|
|
@ -51,6 +51,9 @@ If the output is not quite correct, check for invisible trailing spaces!
|
|||
</properties>
|
||||
<body>
|
||||
<release version="x.y" date="TBD" description="TBD">
|
||||
<action dev="erans" type="fix" issue="MATH-1021" due-to="Brian Bloniarz">
|
||||
Fixed overflow in "HypergeometricDistribution".
|
||||
</action>
|
||||
<action dev="erans" type="fix" issue="MATH-1020">
|
||||
Fixed "nextPermutation" method (in "o.a.c.m.random.RandomDataGenerator").
|
||||
This bug does not affect applications using a previous version of
|
||||
|
|
|
@ -265,7 +265,7 @@ public class HypergeometricDistribution extends AbstractIntegerDistribution {
|
|||
* size {@code n}, the mean is {@code n * m / N}.
|
||||
*/
|
||||
public double getNumericalMean() {
|
||||
return (double) (getSampleSize() * getNumberOfSuccesses()) / (double) getPopulationSize();
|
||||
return getSampleSize() * (getNumberOfSuccesses() / (double) getPopulationSize());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -284,4 +284,18 @@ public class HypergeometricDistributionTest extends IntegerDistributionAbstractT
|
|||
double upper = 1.0 - dist.cumulativeProbability(k) + dist.probability(k);
|
||||
Assert.assertTrue(Precision.compareTo(1.0, upper, 1) == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMath1021() {
|
||||
final int N = 43130568;
|
||||
final int m = 42976365;
|
||||
final int n = 50;
|
||||
final HypergeometricDistribution dist = new HypergeometricDistribution(N, m, n);
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
final int sample = dist.sample();
|
||||
Assert.assertTrue("sample=" + sample, 0 <= sample);
|
||||
Assert.assertTrue("sample=" + sample, sample <= n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue