You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oe...@apache.org on 2015/09/20 21:06:48 UTC

[5/8] [math] code cleanup in GeometricDistribution.java as proposed by Gilles: * removed needless declaration of a local variable "p" with the same value as the "probabilityOfSuccess" field * remove needless local variable "ret" ("return" statements can

code cleanup in GeometricDistribution.java as proposed by Gilles: * removed needless declaration of a local variable "p" with the same value as the "probabilityOfSuccess" field * remove needless local variable "ret" ("return" statements can be used directly in each way of the alternatives)


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/ecb52999
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/ecb52999
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/ecb52999

Branch: refs/heads/MATH_3_X
Commit: ecb52999cb3b5265caf22aa6f608a0a2048db107
Parents: 81ce1b1
Author: Otmar Ertl <ot...@gmail.com>
Authored: Sun Sep 20 20:11:47 2015 +0200
Committer: Otmar Ertl <ot...@gmail.com>
Committed: Sun Sep 20 20:46:41 2015 +0200

----------------------------------------------------------------------
 .../distribution/GeometricDistribution.java     | 27 ++++++--------------
 1 file changed, 8 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/ecb52999/src/main/java/org/apache/commons/math3/distribution/GeometricDistribution.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math3/distribution/GeometricDistribution.java b/src/main/java/org/apache/commons/math3/distribution/GeometricDistribution.java
index f82a3ec..19797c5 100644
--- a/src/main/java/org/apache/commons/math3/distribution/GeometricDistribution.java
+++ b/src/main/java/org/apache/commons/math3/distribution/GeometricDistribution.java
@@ -81,39 +81,30 @@ public class GeometricDistribution extends AbstractIntegerDistribution {
 
     /** {@inheritDoc} */
     public double probability(int x) {
-        double ret;
         if (x < 0) {
-            ret = 0.0;
+            return 0.0;
         } else {
-            final double p = probabilityOfSuccess;
-            ret = FastMath.pow(1 - p, x) * p;
+            return FastMath.pow(1 - probabilityOfSuccess, x) * probabilityOfSuccess;
         }
-        return ret;
     }
 
     /** {@inheritDoc} */
     @Override
     public double logProbability(int x) {
-        double ret;
         if (x < 0) {
-            ret = Double.NEGATIVE_INFINITY;
+            return Double.NEGATIVE_INFINITY;
         } else {
-            final double p = probabilityOfSuccess;
-            ret = x * FastMath.log1p(-p) + FastMath.log(p);
+            return x * FastMath.log1p(-probabilityOfSuccess) + FastMath.log(probabilityOfSuccess);
         }
-        return ret;
     }
 
     /** {@inheritDoc} */
     public double cumulativeProbability(int x) {
-        double ret;
         if (x < 0) {
-            ret = 0.0;
+            return 0.0;
         } else {
-            final double p = probabilityOfSuccess;
-            ret = 1.0 - FastMath.pow(1 - p, x + 1);
+            return 1.0 - FastMath.pow(1 - probabilityOfSuccess, x + 1);
         }
-        return ret;
     }
 
     /**
@@ -122,8 +113,7 @@ public class GeometricDistribution extends AbstractIntegerDistribution {
      * For probability parameter {@code p}, the mean is {@code (1 - p) / p}.
      */
     public double getNumericalMean() {
-        final double p = probabilityOfSuccess;
-        return (1 - p) / p;
+        return (1 - probabilityOfSuccess) / probabilityOfSuccess;
     }
 
     /**
@@ -133,8 +123,7 @@ public class GeometricDistribution extends AbstractIntegerDistribution {
      * {@code (1 - p) / (p * p)}.
      */
     public double getNumericalVariance() {
-        final double p = probabilityOfSuccess;
-        return (1 - p) / (p * p);
+        return (1 - probabilityOfSuccess) / (probabilityOfSuccess * probabilityOfSuccess);
     }
 
     /**