You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2020/02/03 16:59:46 UTC

[commons-numbers] branch master updated (8af1a5d -> 97b2499)

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git.


    from 8af1a5d  Change tanh to use the identities for all computations.
     new 25f71b0  Move the check for a finite value known to be positive to a method.
     new 97b2499  Use final.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/commons/numbers/complex/Complex.java   | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)


[commons-numbers] 01/02: Move the check for a finite value known to be positive to a method.

Posted by ah...@apache.org.
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 <ah...@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:


[commons-numbers] 02/02: Use final.

Posted by ah...@apache.org.
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 97b24998940dd6607d4e07cbf4f63eca9b16ecde
Author: aherbert <ah...@apache.org>
AuthorDate: Mon Feb 3 16:59:42 2020 +0000

    Use final.
---
 .../src/main/java/org/apache/commons/numbers/complex/Complex.java     | 4 ++--
 1 file changed, 2 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 33e8a4d..cae5385 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
@@ -2829,8 +2829,8 @@ public final class Complex implements Serializable  {
         }
 
         // Compute with positive values and determine sign at the end
-        double x = Math.abs(real);
-        double y = Math.abs(imaginary);
+        final double x = Math.abs(real);
+        final double y = Math.abs(imaginary);
 
         // Compute
         double t;