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/29 22:06:02 UTC

[commons-numbers] 05/07: Remove reciprocal().

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 6bd37c999531d107275de3d53e63a37ba6aafc6f
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sun Dec 29 21:45:30 2019 +0000

    Remove reciprocal().
    
    This is not a ISO C99 method and is easily implemented using
    Complex.ONE.divide(z).
---
 .../apache/commons/numbers/complex/Complex.java    | 20 -------
 .../commons/numbers/complex/ComplexTest.java       | 61 ----------------------
 2 files changed, 81 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 4302a89..f492988 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
@@ -730,26 +730,6 @@ public final class Complex implements Serializable  {
     }
 
     /**
-     * Returns the multiplicative inverse of this instance \( z \).
-     * \[ \frac{1}{z} = \frac{1}{a + i b} = \frac{a}{a^2+b^2} - i \frac{b}{a^2+b^2} \]
-     * This method produces the same result as:
-     * <pre>
-     *  Complex.ONE.divide(this)
-     * </pre>
-     *
-     * @return \( 1 / z \)
-     * @see #divide(Complex)
-     * @see <a href="http://mathworld.wolfram.com/MultiplicativeInverse.html">Multiplicative inverse</a>
-     */
-    public Complex reciprocal() {
-        // Note that this cannot be optimised assuming a=1 and b=0.
-        // These preserve compatibility with the divide method:
-        // 1. create NaNs for infinite parts c or d: 0.0 * inf = nan
-        // 2. maintain signs when either c or d are negative signed and the other part is zero
-        return divide(1.0, 0.0, real, imaginary);
-    }
-
-    /**
      * Test for equality with another object. If the other object is a {@code Complex} then a
      * comparison is made of the real and imaginary parts; otherwise {@code false} is returned.
      *
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 ad07c10..577c986 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
@@ -566,67 +566,6 @@ public class ComplexTest {
     }
 
     @Test
-    public void testReciprocal() {
-        final Complex z = Complex.ofCartesian(5.0, 6.0);
-        final Complex act = z.reciprocal();
-        final double expRe = 5.0 / 61.0;
-        final double expIm = -6.0 / 61.0;
-        Assertions.assertEquals(expRe, act.getReal());
-        Assertions.assertEquals(expIm, act.getImaginary());
-    }
-
-    @Test
-    public void testReciprocalReciprocal() {
-        final Complex z = Complex.ofCartesian(5.0, 6.0);
-        final Complex zRR = z.reciprocal().reciprocal();
-        final double tol = 1e-14;
-        Assertions.assertEquals(zRR.getReal(), z.getReal(), tol);
-        Assertions.assertEquals(zRR.getImaginary(), z.getImaginary(), tol);
-    }
-
-    @Test
-    public void testReciprocalReal() {
-        final Complex z = Complex.ofCartesian(-2.0, 0.0);
-        Assertions.assertTrue(Complex.equals(Complex.ofCartesian(-0.5, 0.0), z.reciprocal()));
-    }
-
-    @Test
-    public void testReciprocalImaginary() {
-        final Complex z = Complex.ofCartesian(0.0, -2.0);
-        Assertions.assertEquals(Complex.ofCartesian(0.0, 0.5), z.reciprocal());
-    }
-
-    @Test
-    public void testReciprocalNaN() {
-        Assertions.assertTrue(NAN.reciprocal().isNaN());
-    }
-
-    @Test
-    public void testReciprocalZero() {
-        final Complex z = Complex.ZERO.reciprocal();
-        Assertions.assertEquals(inf, z.getReal());
-        Assertions.assertEquals(nan, z.getImaginary());
-    }
-
-    @Test
-    public void testReciprocalMatchesDivide() {
-        final double[] parts = {Double.NEGATIVE_INFINITY, -1, -0.0, 0.0, 1, Math.PI, Double.POSITIVE_INFINITY, Double.NaN};
-        for (final double x : parts) {
-            for (final double y : parts) {
-                final Complex z = Complex.ofCartesian(x, y);
-                Assertions.assertEquals(Complex.ONE.divide(z), z.reciprocal(), () -> z.toString());
-            }
-        }
-        final UniformRandomProvider rng = RandomSource.create(RandomSource.SPLIT_MIX_64);
-        for (int i = 0; i < 10; i++) {
-            final double x = -1 + rng.nextDouble() * 2;
-            final double y = -1 + rng.nextDouble() * 2;
-            final Complex z = Complex.ofCartesian(x, y);
-            Assertions.assertEquals(Complex.ONE.divide(z), z.reciprocal());
-        }
-    }
-
-    @Test
     public void testMultiply() {
         final Complex x = Complex.ofCartesian(3.0, 4.0);
         final Complex y = Complex.ofCartesian(5.0, 6.0);