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:27 UTC

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

Repository: commons-numbers
Updated Branches:
  refs/heads/task_NUMBERS-33__Gamma 842119c50 -> cad5798e0


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

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

----------------------------------------------------------------------
 .../java/org/apache/commons/numbers/gamma/Gamma.java     | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/5944675f/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Gamma.java
----------------------------------------------------------------------
diff --git a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Gamma.java b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Gamma.java
index 8906734..1cd5424 100644
--- a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Gamma.java
+++ b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/Gamma.java
@@ -55,7 +55,6 @@ public class Gamma {
             return Double.NaN;
         }
 
-        final double ret;
         final double absX = Math.abs(x);
         if (absX <= 20) {
             if (x >= 1) {
@@ -73,7 +72,7 @@ public class Gamma {
                     t -= 1;
                     prod *= t;
                 }
-                ret = prod / (1 + INV_GAMMA_1P_M1.value(t - 1));
+                return prod / (1 + INV_GAMMA_1P_M1.value(t - 1));
             } else {
                 /*
                  * From the recurrence relation
@@ -88,7 +87,7 @@ public class Gamma {
                     t += 1;
                     prod *= t;
                 }
-                ret = 1 / (prod * (1 + INV_GAMMA_1P_M1.value(t)));
+                return 1 / (prod * (1 + INV_GAMMA_1P_M1.value(t)));
             }
         } else {
             final double y = absX + LANCZOS_G + 0.5;
@@ -96,7 +95,7 @@ public class Gamma {
                                     Math.pow(y, absX + 0.5) *
                                     Math.exp(-y) * LANCZOS_APPROXIMATION.value(absX);
             if (x > 0) {
-                ret = gammaAbs;
+                return gammaAbs;
             } else {
                 /*
                  * From the reflection formula
@@ -106,10 +105,8 @@ public class Gamma {
                  * it is found
                  * Gamma(x) = -pi / [x * sin(pi * x) * Gamma(-x)].
                  */
-                ret = -Math.PI / (x * Math.sin(Math.PI * x) * gammaAbs);
+                return -Math.PI / (x * Math.sin(Math.PI * x) * gammaAbs);
             }
         }
-
-        return ret;
     }
 }


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

Posted by er...@apache.org.
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;
         }
     }
 }