This is an automated email from the ASF dual-hosted git repository. aherbert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-statistics.git
commit 4d4fb521e25ebe4b371ec8e7c235347f40b858a7 Author: aherbert <aherb...@apache.org> AuthorDate: Wed Jun 24 13:48:30 2020 +0100 Simplify chebyshevApplies condition: Instead of testing the values are not infinite or NaN, test if the values are finite. Note: Double.isFinite was introduced in Java 1.8 and so was unavailable in the original code from commons-math. --- .../statistics/distribution/AbstractContinuousDistribution.java | 4 ++-- .../statistics/distribution/AbstractDiscreteDistribution.java | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/AbstractContinuousDistribution.java b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/AbstractContinuousDistribution.java index 0d8f3f7..62cdc6b 100644 --- a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/AbstractContinuousDistribution.java +++ b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/AbstractContinuousDistribution.java @@ -99,8 +99,8 @@ abstract class AbstractContinuousDistribution final double mu = getMean(); final double sig = Math.sqrt(getVariance()); - final boolean chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) || - Double.isInfinite(sig) || Double.isNaN(sig)); + final boolean chebyshevApplies = Double.isFinite(mu) && + Double.isFinite(sig); if (lowerBound == Double.NEGATIVE_INFINITY) { if (chebyshevApplies) { diff --git a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/AbstractDiscreteDistribution.java b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/AbstractDiscreteDistribution.java index abc16ca..5821181 100644 --- a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/AbstractDiscreteDistribution.java +++ b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/AbstractDiscreteDistribution.java @@ -83,11 +83,10 @@ abstract class AbstractDiscreteDistribution // cf. AbstractRealDistribution.inverseCumulativeProbability(double) final double mu = getMean(); final double sigma = Math.sqrt(getVariance()); - final boolean chebyshevApplies = !(Double.isInfinite(mu) || - Double.isNaN(mu) || - Double.isInfinite(sigma) || - Double.isNaN(sigma) || - sigma == 0.0); + final boolean chebyshevApplies = Double.isFinite(mu) && + Double.isFinite(sigma) && + sigma != 0.0; + if (chebyshevApplies) { double k = Math.sqrt((1.0 - p) / p); double tmp = mu - k * sigma;