commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oe...@apache.org
Subject [1/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
Date Sun, 20 Sep 2015 19:06:44 GMT
Repository: commons-math
Updated Branches:
  refs/heads/MATH_3_X 81ce1b183 -> df1db29ab
  refs/heads/master fb0078159 -> 2fd6c8fa1


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/73351b6a
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/73351b6a
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/73351b6a

Branch: refs/heads/master
Commit: 73351b6adbf403600521505bef288057beb2bdde
Parents: fb00781
Author: Otmar Ertl <otmar.ertl@gmail.com>
Authored: Sun Sep 20 20:11:47 2015 +0200
Committer: Otmar Ertl <otmar.ertl@gmail.com>
Committed: Sun Sep 20 20:11:47 2015 +0200

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


http://git-wip-us.apache.org/repos/asf/commons-math/blob/73351b6a/src/main/java/org/apache/commons/math4/distribution/GeometricDistribution.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/distribution/GeometricDistribution.java
b/src/main/java/org/apache/commons/math4/distribution/GeometricDistribution.java
index 5d8a40d..1eeb516 100644
--- a/src/main/java/org/apache/commons/math4/distribution/GeometricDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/GeometricDistribution.java
@@ -82,40 +82,31 @@ public class GeometricDistribution extends AbstractIntegerDistribution
{
     /** {@inheritDoc} */
     @Override
     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} */
     @Override
     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;
     }
 
     /**
@@ -125,8 +116,7 @@ public class GeometricDistribution extends AbstractIntegerDistribution
{
      */
     @Override
     public double getNumericalMean() {
-        final double p = probabilityOfSuccess;
-        return (1 - p) / p;
+        return (1 - probabilityOfSuccess) / probabilityOfSuccess;
     }
 
     /**
@@ -137,8 +127,7 @@ public class GeometricDistribution extends AbstractIntegerDistribution
{
      */
     @Override
     public double getNumericalVariance() {
-        final double p = probabilityOfSuccess;
-        return (1 - p) / (p * p);
+        return (1 - probabilityOfSuccess) / (probabilityOfSuccess * probabilityOfSuccess);
     }
 
     /**


Mime
View raw message