commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aherb...@apache.org
Subject [commons-numbers] 01/02: Move the check for a finite value known to be positive to a method.
Date Mon, 03 Feb 2020 16:59:47 GMT
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 25f71b03fc7f730eb7239376dbd4921aea336c17
Author: aherbert <aherbert@apache.org>
AuthorDate: Mon Feb 3 16:58:21 2020 +0000

    Move the check for a finite value known to be positive to a method.
---
 .../java/org/apache/commons/numbers/complex/Complex.java  | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 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 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 @@ public final class Complex implements Serializable  {
         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 @@ public final class Complex implements Serializable  {
     }
 
     /**
+     * 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:


Mime
View raw message