Fixed unintended integer division error in PoissonDistribution sampling method.

JIRA: MATH-1056
Reported and patched by Sean Owen.


git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1540217 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Phil Steitz 2013-11-08 23:27:49 +00:00
parent 5ee76f095e
commit d252a811a2
2 changed files with 4 additions and 1 deletions

View File

@ -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="psteitz" type="fix" issue="MATH-1056" due-to="Sean Owen">
Fixed unintended integer division error in PoissonDistribution sampling method.
</action>
<action dev="tn" type="fix" issue="MATH-1057">
Fixed failing unit tests for "BOBYQAOptimizer" when executed with a Oracle/Sun JVM 1.5.
</action>

View File

@ -321,7 +321,7 @@ public class PoissonDistribution extends AbstractIntegerDistribution {
final double delta = FastMath.sqrt(lambda * FastMath.log(32 * lambda / FastMath.PI + 1));
final double halfDelta = delta / 2;
final double twolpd = 2 * lambda + delta;
final double a1 = FastMath.sqrt(FastMath.PI * twolpd) * FastMath.exp(1 / 8 * lambda);
final double a1 = FastMath.sqrt(FastMath.PI * twolpd) * FastMath.exp(1 / (8 * lambda));
final double a2 = (twolpd / delta) * FastMath.exp(-delta * (1 + delta) / twolpd);
final double aSum = a1 + a2 + 1;
final double p1 = a1 / aSum;