From d252a811a239387fdbce0f6fe70be9507d9f2e26 Mon Sep 17 00:00:00 2001 From: Phil Steitz Date: Fri, 8 Nov 2013 23:27:49 +0000 Subject: [PATCH] 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 --- src/changes/changes.xml | 3 +++ .../apache/commons/math3/distribution/PoissonDistribution.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 3c4df2dd3..a11ce3ae3 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -51,6 +51,9 @@ If the output is not quite correct, check for invisible trailing spaces! + + Fixed unintended integer division error in PoissonDistribution sampling method. + Fixed failing unit tests for "BOBYQAOptimizer" when executed with a Oracle/Sun JVM 1.5. diff --git a/src/main/java/org/apache/commons/math3/distribution/PoissonDistribution.java b/src/main/java/org/apache/commons/math3/distribution/PoissonDistribution.java index 22a1b6a41..bbafc1448 100644 --- a/src/main/java/org/apache/commons/math3/distribution/PoissonDistribution.java +++ b/src/main/java/org/apache/commons/math3/distribution/PoissonDistribution.java @@ -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;