You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2017/05/09 15:11:28 UTC

[2/2] commons-numbers git commit: Unnecessary variable.

Unnecessary variable.


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

Branch: refs/heads/task_NUMBERS-33__Gamma
Commit: cad5798e0539f90155cca086b3cf6c8098f80fd8
Parents: 5944675
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Tue May 9 17:10:49 2017 +0200
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Tue May 9 17:10:49 2017 +0200

----------------------------------------------------------------------
 .../commons/numbers/gamma/RegularizedGamma.java | 28 +++++++-------------
 1 file changed, 10 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/cad5798e/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/RegularizedGamma.java
----------------------------------------------------------------------
diff --git a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/RegularizedGamma.java b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/RegularizedGamma.java
index 5e24715..19a34a3 100644
--- a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/RegularizedGamma.java
+++ b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/RegularizedGamma.java
@@ -96,19 +96,17 @@ public abstract class RegularizedGamma {
                             double x,
                             double epsilon,
                             int maxIterations) {
-            double ret;
-
             if (Double.isNaN(a) ||
                 Double.isNaN(x) ||
                 a <= 0 ||
                 x < 0) {
-                ret = Double.NaN;
+                return Double.NaN;
             } else if (x == 0) {
-                ret = 0;
+                return 0;
             } else if (x >= a + 1) {
                 // Q should converge faster in this case.
                 final RegularizedGamma.Q q = new RegularizedGamma.Q();
-                ret = 1 - q.value(a, x, epsilon, maxIterations);
+                return 1 - q.value(a, x, epsilon, maxIterations);
             } else {
                 // Series.
                 double n = 0; // current element index
@@ -127,13 +125,11 @@ public abstract class RegularizedGamma {
                 if (n >= maxIterations) {
                     throw new GammaException(GammaException.CONVERGENCE, maxIterations);
                 } else if (Double.isInfinite(sum)) {
-                    ret = 1;
+                    return 1;
                 } else {
-                    ret = Math.exp(-x + (a * Math.log(x)) - LOG_GAMMA.value(a)) * sum;
+                    return Math.exp(-x + (a * Math.log(x)) - LOG_GAMMA.value(a)) * sum;
                 }
             }
-
-            return ret;
         }
     }
 
@@ -176,19 +172,17 @@ public abstract class RegularizedGamma {
                             double x,
                             double epsilon,
                             int maxIterations) {
-            double ret;
-
             if (Double.isNaN(a) ||
                 Double.isNaN(x) ||
                 a <= 0 ||
                 x < 0) {
-                ret = Double.NaN;
+                return Double.NaN;
             } else if (x == 0) {
-                ret = 1;
+                return 1;
             } else if (x < a + 1) {
                 // P should converge faster in this case.
                 final RegularizedGamma.P p = new RegularizedGamma.P();
-                ret = 1 - p.value(a, x, epsilon, maxIterations);
+                return 1 - p.value(a, x, epsilon, maxIterations);
             } else {
                 final ContinuedFraction cf = new ContinuedFraction() {
                         /** {@inheritDoc} */
@@ -204,11 +198,9 @@ public abstract class RegularizedGamma {
                         }
                     };
 
-                ret = 1 / cf.evaluate(x, epsilon, maxIterations);
-                ret = Math.exp(-x + (a * Math.log(x)) - LOG_GAMMA.value(a)) * ret;
+                return Math.exp(-x + (a * Math.log(x)) - LOG_GAMMA.value(a)) /
+                    cf.evaluate(x, epsilon, maxIterations);
             }
-
-            return ret;
         }
     }
 }