Move the check for a finite value known to be positive to a method.
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 5a322c3..33e8a4d 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
@@ -2995,8 +2995,7 @@
final double x = Math.abs(real);
// Handle inf or nan.
- // Deliberate logic inversion using x to match !Double.isFinite(x) knowing x is absolute.
- if (!(x <= Double.MAX_VALUE) || !Double.isFinite(imaginary)) {
+ if (!isPosFinite(x) || !Double.isFinite(imaginary)) {
if (isPosInfinite(x)) {
if (Double.isFinite(imaginary)) {
// The sign is copied from sin(2y)
@@ -3222,6 +3221,18 @@
}
/**
+ * Check that an absolute value is finite. Used to replace {@link Double#isFinite()}
+ * when the input value is known to be positive (i.e. in the case where it has been
+ * set using {@link Math#abs(double)}).
+ *
+ * @param d Value.
+ * @return {@code true} if {@code d} is +finite.
+ */
+ private static boolean isPosFinite(double d) {
+ return d <= Double.MAX_VALUE;
+ }
+
+ /**
* Create a complex number given the real and imaginary parts, then multiply by {@code -i}.
* This is used in functions that implement trigonomic identities. It is the functional
* equivalent of: