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 970512c6d4a6084f17084e07ecc4f3423ae21b74 Author: Alex Herbert <aherb...@apache.org> AuthorDate: Tue Dec 24 14:45:40 2019 +0000 Use final. --- .../apache/commons/numbers/complex/Complex.java | 10 +++--- .../numbers/complex/ComplexEdgeCaseTest.java | 42 +++++++++++----------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java index a223f2a..8db24d6 100644 --- a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java +++ b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java @@ -2159,7 +2159,7 @@ public final class Complex implements Serializable { // Find the larger magnitude. if (x < y) { - double tmp = x; + final double tmp = x; x = y; y = tmp; } @@ -2185,8 +2185,8 @@ public final class Complex implements Serializable { re = x; } else { // Do scaling - int expx = Math.getExponent(x); - int expy = Math.getExponent(y); + final int expx = Math.getExponent(x); + final int expy = Math.getExponent(y); if (2 * (expx - expy) > PRECISION_1) { // y can be ignored re = log.apply(x); @@ -2205,8 +2205,8 @@ public final class Complex implements Serializable { // underflow scale = expx + 2; } - double sx = Math.scalb(x, -scale); - double sy = Math.scalb(y, -scale); + final double sx = Math.scalb(x, -scale); + final double sy = Math.scalb(y, -scale); re = scale * logOf2 + 0.5 * log.apply(sx * sx + sy * sy); } } diff --git a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexEdgeCaseTest.java b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexEdgeCaseTest.java index df20dc9..90ca920 100644 --- a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexEdgeCaseTest.java +++ b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexEdgeCaseTest.java @@ -139,10 +139,10 @@ public class ComplexEdgeCaseTest { // A medium value is used to test outside the range of the CReferenceTest. // The results have been generated using g++ -std=c++11 acos. // xp1 * xm1 will overflow: - double huge = Math.sqrt(Double.MAX_VALUE) * 2; - double big = Math.sqrt(Double.MAX_VALUE) / 8; - double medium = 100; - double small = Math.sqrt(Double.MIN_NORMAL) * 4; + final double huge = Math.sqrt(Double.MAX_VALUE) * 2; + final double big = Math.sqrt(Double.MAX_VALUE) / 8; + final double medium = 100; + final double small = Math.sqrt(Double.MIN_NORMAL) * 4; assertComplex(huge, big, name, operation, 0.06241880999595735, -356.27960012801969); assertComplex(huge, medium, name, operation, 3.7291703656001039e-153, -356.27765080781188); assertComplex(huge, small, name, operation, 2.2250738585072019e-308, -356.27765080781188); @@ -172,10 +172,10 @@ public class ComplexEdgeCaseTest { // This method is essentially the same as acos and the edge cases are the same. // The results have been generated using g++ -std=c++11 asin. - double huge = Math.sqrt(Double.MAX_VALUE) * 2; - double big = Math.sqrt(Double.MAX_VALUE) / 8; - double medium = 100; - double small = Math.sqrt(Double.MIN_NORMAL) * 4; + final double huge = Math.sqrt(Double.MAX_VALUE) * 2; + final double big = Math.sqrt(Double.MAX_VALUE) / 8; + final double medium = 100; + final double small = Math.sqrt(Double.MIN_NORMAL) * 4; assertComplex(huge, big, name, operation, 1.5083775167989393, 356.27960012801969); assertComplex(huge, medium, name, operation, 1.5707963267948966, 356.27765080781188); assertComplex(huge, small, name, operation, 1.5707963267948966, 356.27765080781188); @@ -209,9 +209,9 @@ public class ComplexEdgeCaseTest { // A medium value is used to test outside the range of the CReferenceTest. // It hits an edge case when x is big and y > 1. // The results have been generated using g++ -std=c++11 atanh. - double big = Math.sqrt(Double.MAX_VALUE) / 2; - double medium = 100; - double small = Math.sqrt(Double.MIN_NORMAL) * 2; + final double big = Math.sqrt(Double.MAX_VALUE) / 2; + final double medium = 100; + final double small = Math.sqrt(Double.MIN_NORMAL) * 2; assertComplex(big, big, name, operation, 7.4583407312002067e-155, 1.5707963267948966); assertComplex(big, medium, name, operation, 1.4916681462400417e-154, 1.5707963267948966); assertComplex(big, small, name, operation, 1.4916681462400417e-154, 1.5707963267948966); @@ -235,9 +235,9 @@ public class ComplexEdgeCaseTest { // Implementation defers to java.util.Math. // Hit edge cases for extreme values. - double big = Double.MAX_VALUE; - double medium = 2; - double small = Double.MIN_NORMAL; + final double big = Double.MAX_VALUE; + final double medium = 2; + final double small = Double.MIN_NORMAL; assertComplex(big, big, name, operation, -inf, inf); assertComplex(big, medium, name, operation, -inf, inf); assertComplex(big, small, name, operation, inf, inf); @@ -258,9 +258,9 @@ public class ComplexEdgeCaseTest { // Implementation defers to java.util.Math. // Hit edge cases for extreme values. - double big = Double.MAX_VALUE; - double medium = 2; - double small = Double.MIN_NORMAL; + final double big = Double.MAX_VALUE; + final double medium = 2; + final double small = Double.MIN_NORMAL; assertComplex(big, big, name, operation, -inf, inf); assertComplex(big, medium, name, operation, -inf, inf); assertComplex(big, small, name, operation, inf, inf); @@ -422,10 +422,10 @@ public class ComplexEdgeCaseTest { */ private static void assertLog(double x, double y, long maxUlps) { // Compute the best value we can - BigDecimal bx = BigDecimal.valueOf(x); - BigDecimal by = BigDecimal.valueOf(y); - double real = 0.5 * Math.log1p(bx.multiply(bx).add(by.multiply(by)).subtract(BigDecimal.ONE).doubleValue()); - double imag = Math.atan2(y, x); + final BigDecimal bx = BigDecimal.valueOf(x); + final BigDecimal by = BigDecimal.valueOf(y); + final double real = 0.5 * Math.log1p(bx.multiply(bx).add(by.multiply(by)).subtract(BigDecimal.ONE).doubleValue()); + final double imag = Math.atan2(y, x); assertComplex(x, y, "log", Complex::log, real, imag, maxUlps); }