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-numbers.git
commit b55d79113c63ac51b58a873115d8cc461197bfb1 Author: Alex Herbert <aherb...@apache.org> AuthorDate: Fri Jul 5 14:18:24 2024 +0100 PMD fix: Use final --- .../java/org/apache/commons/numbers/gamma/BoostBeta.java | 15 +++++++-------- .../java/org/apache/commons/numbers/gamma/BoostErf.java | 14 +++++++------- .../java/org/apache/commons/numbers/gamma/BoostGamma.java | 12 ++++++------ 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/BoostBeta.java b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/BoostBeta.java index 8ecc7637..d6b6f233 100644 --- a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/BoostBeta.java +++ b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/BoostBeta.java @@ -655,7 +655,7 @@ final class BoostBeta { } } else { // Sidestep on a, and then use the series representation: - double prefix; + final double prefix; if (normalised) { prefix = 1; } else { @@ -710,7 +710,7 @@ final class BoostBeta { } } else { // Sidestep to improve errors: - double prefix; + final double prefix; if (normalised) { prefix = 1; } else { @@ -732,7 +732,7 @@ final class BoostBeta { // Note: // median ~ (a - 1/3) / (a + b - 2/3) ~ a / (a + b) // if x > a / (a + b) => a - (a + b) * x < 0 - double lambda; + final double lambda; if (a < b) { lambda = a - (a + b) * x; } else { @@ -777,7 +777,7 @@ final class BoostBeta { --n; } final double bbar = b - n; - double prefix; + final double prefix; if (normalised) { prefix = 1; } else { @@ -1146,14 +1146,13 @@ final class BoostBeta { // final double bm1 = b - 1; final double t = a + bm1 / 2; - double lx; - double u; + final double lx; if (y < 0.35) { lx = Math.log1p(-y); } else { lx = Math.log(x); } - u = -t * lx; + final double u = -t * lx; // and from from 9.2: final double h = BoostGamma.regularisedGammaPrefix(b, u); if (h <= Double.MIN_NORMAL) { @@ -1329,7 +1328,7 @@ final class BoostBeta { final int m = n; final int k = m / 2; - double aN; + final double aN; if ((m & 0x1) == 0) { // even // m = 2k diff --git a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/BoostErf.java b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/BoostErf.java index 48709f2b..b349ab98 100644 --- a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/BoostErf.java +++ b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/BoostErf.java @@ -430,9 +430,9 @@ final class BoostErf { // negate the result if z is outside that range. This is a simple // application of the erfc reflection formula: erfc(-z) = 2 - erfc(z) // - double p; - double q; - double s; + final double p; + final double q; + final double s; if (z > 1) { q = 2 - z; p = 1 - q; @@ -480,9 +480,9 @@ final class BoostErf { // negate the result if z is outside that range. This is a simple // application of the erf reflection formula: erf(-z) = -erf(z) // - double p; - double q; - double s; + final double p; + final double q; + final double s; if (z < 0) { p = -z; q = 1 - p; @@ -506,7 +506,7 @@ final class BoostErf { * @return the inverse */ private static double erfInvImp(double p, double q) { - double result; + final double result; if (p <= 0.5) { // diff --git a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/BoostGamma.java b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/BoostGamma.java index 6ae16914..0958129a 100644 --- a/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/BoostGamma.java +++ b/commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/BoostGamma.java @@ -755,7 +755,7 @@ final class BoostGamma { * @return log gamma value */ static double lgamma(double z, int[] sign) { - double result = 0; + double result; int sresult = 1; if (z <= -ROOT_EPSILON) { // reflection formula: @@ -1010,7 +1010,7 @@ final class BoostGamma { // This helper calculates tgamma(1+dz)-1 without cancellation errors, // used by the upper incomplete gamma with z < 1: // - double result; + final double result; if (dz < 0) { if (dz < -0.5) { // Best method is simply to subtract 1 from tgamma: @@ -1234,8 +1234,8 @@ final class BoostGamma { return Math.exp(result); } - boolean isInt; - boolean isHalfInt; + final boolean isInt; + final boolean isHalfInt; // Update. x must be safe for exp(-x). Change to -x > LOG_MIN_VALUE. final boolean isSmallA = (a < 30) && (a <= x + 1) && (-x > LOG_MIN_VALUE); if (isSmallA) { @@ -1246,7 +1246,7 @@ final class BoostGamma { isInt = isHalfInt = false; } - int evalMethod; + final int evalMethod; if (isInt && (x > 0.6)) { // calculate Q via finite sum: @@ -1678,7 +1678,7 @@ final class BoostGamma { return 0; } final double alz = a * Math.log(z); - double prefix; + final double prefix; if (z >= 1) { if ((alz < LOG_MAX_VALUE) && (-z > LOG_MIN_VALUE)) {