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 2019/12/09 11:58:54 UTC

[commons-numbers] branch master updated (e804844 -> 563d896)

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 e804844  Exclude check for equality with positive infinity in Complex sqrt.
     new 69499d3  sqrt() handling of zero extends to all real numbers (imaginary == 0)
     new 563d896  Removed conjugate() method.

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:
 .../apache/commons/numbers/complex/Complex.java    | 23 ++++++++--------------
 .../commons/numbers/complex/CStandardTest.java     |  4 ++--
 .../commons/numbers/complex/ComplexTest.java       | 10 +++++-----
 3 files changed, 15 insertions(+), 22 deletions(-)


[commons-numbers] 02/02: Removed conjugate() 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 563d896b2a5c435f66af6dc215290637c1498ba3
Author: aherbert <ah...@apache.org>
AuthorDate: Mon Dec 9 11:58:50 2019 +0000

    Removed conjugate() method.
---
 .../java/org/apache/commons/numbers/complex/Complex.java    | 13 +------------
 .../org/apache/commons/numbers/complex/CStandardTest.java   |  4 ++--
 .../org/apache/commons/numbers/complex/ComplexTest.java     | 10 +++++-----
 3 files changed, 8 insertions(+), 19 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 b4f1e8b..4459dc4 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
@@ -357,19 +357,8 @@ public final class Complex implements Serializable  {
      *
      * @return the conjugate (z&#773;) of this complex object.
      */
-    public Complex conjugate() {
-        return new Complex(real, -imaginary);
-    }
-
-    /**
-     * Returns the conjugate of this complex number
-     * (C++11 grammar).
-     *
-     * @return the conjugate of this complex object.
-     * @see #conjugate()
-     */
     public Complex conj() {
-        return conjugate();
+        return new Complex(real, -imaginary);
     }
 
     /**
diff --git a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CStandardTest.java b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CStandardTest.java
index 23321e2..11a0bc2 100644
--- a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CStandardTest.java
+++ b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CStandardTest.java
@@ -283,8 +283,8 @@ public class CStandardTest {
      */
     private static void assertConjugateEquality(Complex z,
             UnaryOperator<Complex> operation, UnspecifiedSign sign) {
-        final Complex c1 = operation.apply(z.conjugate());
-        final Complex c2 = operation.apply(z).conjugate();
+        final Complex c1 = operation.apply(z.conj());
+        final Complex c2 = operation.apply(z).conj();
         final Complex t1 = sign.removeSign(c1);
         final Complex t2 = sign.removeSign(c2);
 
diff --git a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexTest.java b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexTest.java
index 13bd820..4647052 100644
--- a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexTest.java
+++ b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexTest.java
@@ -248,23 +248,23 @@ public class ComplexTest {
     @Test
     public void testConjugate() {
         final Complex x = Complex.ofCartesian(3.0, 4.0);
-        final Complex z = x.conjugate();
+        final Complex z = x.conj();
         Assertions.assertEquals(3.0, z.getReal());
         Assertions.assertEquals(-4.0, z.getImaginary());
     }
 
     @Test
     public void testConjugateNaN() {
-        final Complex z = NAN.conjugate();
+        final Complex z = NAN.conj();
         Assertions.assertTrue(z.isNaN());
     }
 
     @Test
     public void testConjugateInfiinite() {
         Complex z = Complex.ofCartesian(0, inf);
-        Assertions.assertEquals(neginf, z.conjugate().getImaginary(), 0);
+        Assertions.assertEquals(neginf, z.conj().getImaginary(), 0);
         z = Complex.ofCartesian(0, neginf);
-        Assertions.assertEquals(inf, z.conjugate().getImaginary(), 0);
+        Assertions.assertEquals(inf, z.conj().getImaginary(), 0);
     }
 
     @Test
@@ -1285,7 +1285,7 @@ public class ComplexTest {
             final Complex z = Complex.ofCartesian(rng.nextDouble(), rng.nextDouble());
             Assertions.assertEquals(z.getReal(), z.real(), "real");
             Assertions.assertEquals(z.getImaginary(), z.imag(), "imag");
-            Assertions.assertEquals(z.conjugate(), z.conj(), "conj");
+            Assertions.assertEquals(z.conj(), z.conj(), "conj");
         }
     }
 


[commons-numbers] 01/02: sqrt() handling of zero extends to all real numbers (imaginary == 0)

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 69499d3ab2b66185c5f0bbb8a850d2c4fc540d85
Author: aherbert <ah...@apache.org>
AuthorDate: Mon Dec 9 11:54:25 2019 +0000

    sqrt() handling of zero extends to all real numbers (imaginary == 0)
---
 .../main/java/org/apache/commons/numbers/complex/Complex.java  | 10 +++++++---
 1 file changed, 7 insertions(+), 3 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 4a4ee76..b4f1e8b 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
@@ -1714,9 +1714,13 @@ public final class Complex implements Serializable  {
         }
         if (Double.isFinite(real)) {
             if (Double.isFinite(imaginary)) {
-                // Handle zero
-                if (real == 0 && imaginary == 0) {
-                    return new Complex(0, imaginary);
+                // Edge case for real numbers
+                if (imaginary == 0) {
+                    final double sqrtAbs = Math.sqrt(Math.abs(real));
+                    if (real < 0) {
+                        return new Complex(0, Math.copySign(sqrtAbs, imaginary));
+                    }
+                    return new Complex(sqrtAbs, Math.copySign(0, imaginary));
                 }
                 final double abs = getAbsolute(real, imaginary);
                 final double av = (Math.abs(real) + abs) / 2;