commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject [commons-statistics] branch master updated: Ensure "double" arithmetics.
Date Fri, 29 Nov 2019 13:36:36 GMT
This is an automated email from the ASF dual-hosted git repository.

erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-statistics.git


The following commit(s) were added to refs/heads/master by this push:
     new cb0d142  Ensure "double" arithmetics.
cb0d142 is described below

commit cb0d142c3e4ed39cb85b4beafeb9a7473f9d903f
Author: Gilles Sadowski <gilles@harfang.homelinux.org>
AuthorDate: Fri Nov 29 14:35:42 2019 +0100

    Ensure "double" arithmetics.
    
    Reported by "sonarcloud.io".
---
 .../commons/statistics/distribution/BinomialDistribution.java      | 2 +-
 .../commons/statistics/distribution/SaddlePointExpansionUtils.java | 7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/BinomialDistribution.java
b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/BinomialDistribution.java
index 77fffc5..7846f1e 100644
--- a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/BinomialDistribution.java
+++ b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/BinomialDistribution.java
@@ -102,7 +102,7 @@ public class BinomialDistribution extends AbstractDiscreteDistribution
{
             ret = 1.0;
         } else {
             ret = 1.0 - RegularizedBeta.value(probabilityOfSuccess,
-                                              x + 1.0, numberOfTrials - x);
+                                              x + 1.0, (double) numberOfTrials - x);
         }
         return ret;
     }
diff --git a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/SaddlePointExpansionUtils.java
b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/SaddlePointExpansionUtils.java
index e0f2608..948d97b 100644
--- a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/SaddlePointExpansionUtils.java
+++ b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/SaddlePointExpansionUtils.java
@@ -185,10 +185,11 @@ final class SaddlePointExpansionUtils {
                 ret = n * Math.log(p);
             }
         } else {
+            final double nMx = (double) n - x;
             ret = getStirlingError(n) - getStirlingError(x) -
-                  getStirlingError(n - x) - getDeviancePart(x, n * p) -
-                  getDeviancePart(n - x, n * q);
-            final double f = (TWO_PI * x * (n - x)) / n;
+                  getStirlingError(nMx) - getDeviancePart(x, n * p) -
+                  getDeviancePart(nMx, n * q);
+            final double f = (TWO_PI * x * nMx) / n;
             ret = -0.5 * Math.log(f) + ret;
         }
         return ret;


Mime
View raw message