commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aherb...@apache.org
Subject [commons-numbers] 06/08: Fix sinh conjugate and odd equality for infinite real, finite imaginary.
Date Thu, 05 Dec 2019 16:50:40 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 5af4d3c2ad599fa28a0b7f9a67eda34e1aa682e6
Author: aherbert <aherbert@apache.org>
AuthorDate: Thu Dec 5 12:36:59 2019 +0000

    Fix sinh conjugate and odd equality for infinite real, finite imaginary.
---
 .../java/org/apache/commons/numbers/complex/Complex.java  | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 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 aa169e5..f0efa8b 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
@@ -1511,9 +1511,16 @@ public final class Complex implements Serializable  {
                     return constructor.create(real, imaginary);
                 }
                 // inf * cis(y)
-                final double re = real * Math.cos(imaginary);
-                final double im = real * Math.sin(imaginary);
-                return constructor.create(re, im);
+                // ISO C99: Preserve the equality
+                // sinh(conj(z)) = conj(sinh(z))
+                // and the odd function: f(z) = -f(-z)
+                // by always computing on a positive valued Complex number.
+                // Math.cos(-x) == Math.cos(x) so ignore sign transform.
+                final double signIm = imaginary < 0 ? -1 : 1;
+                final double re = Double.POSITIVE_INFINITY * Math.cos(imaginary);
+                final double im = Double.POSITIVE_INFINITY * Math.sin(imaginary * signIm);
+                // Transform back
+                return constructor.create(real < 0 ? -re : re, im * signIm);
             }
             // imaginary is infinite or NaN
             return constructor.create(Double.POSITIVE_INFINITY, Double.NaN);
@@ -1879,7 +1886,7 @@ public final class Complex implements Serializable  {
      * <pre>
      * real    imaginary    g(z)
      * +       +            identity
-     * -       +            negateReal
+     * -       +            negateReal (negate && conjugate)
      * +       -            conjugate
      * -       -            negate
      * </pre>


Mime
View raw message