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/05 02:31:53 UTC

[commons-numbers] 01/03: Remove odd/even edge cases.

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 8950a68339b4d96172a53a736ba422cff5a09e98
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Thu Dec 5 01:43:09 2019 +0000

    Remove odd/even edge cases.
    
    The C99 reference states that the sign of the parts is undefined for
    some edge cases. These should be tested separately.
    
    Fix testCosh for cis check using the even property of the function and
    the conjugate equality.
---
 .../commons/numbers/complex/CStandardTest.java      | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

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 4bbb80b..141448f 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
@@ -200,8 +200,9 @@ public class CStandardTest {
      */
     private static void assertOddOrEven(UnaryOperator<Complex> operation, boolean odd) {
         // Edge cases
-        final double[] parts = {Double.NEGATIVE_INFINITY, -1, -0.0, 0.0, 1,
-                                Double.POSITIVE_INFINITY, Double.NaN};
+        //final double[] parts = {Double.NEGATIVE_INFINITY, -1, -0.0, 0.0, 1,
+        //                        Double.POSITIVE_INFINITY, Double.NaN};
+        final double[] parts = {-2, -1, -0.0, 0.0, 1, 2};
         for (final double x : parts) {
             for (final double y : parts) {
                 assertOddOrEven(x, y, operation, odd);
@@ -244,6 +245,10 @@ public class CStandardTest {
             c2 = c2.negate();
         }
 
+        // Note: It is not possible to satisfy the conjugate equality
+        // and be an even function with regard to zero.
+        
+        
         // Test for binary equality
         if (!equals(c1.getReal(), c2.getReal()) ||
             !equals(c1.getImaginary(), c2.getImaginary())) {
@@ -616,7 +621,7 @@ public class CStandardTest {
     @Test
     public void testAsinh() {
         assertConjugateEquality(Complex::asinh);
-        //assertOddOrEven(Complex::asinh, ODD);
+        assertOddOrEven(Complex::asinh, ODD);
         assertComplex(Complex.ZERO, Complex::asinh, Complex.ZERO);
         assertComplex(negZeroZero, Complex::asinh, negZeroZero);
         assertComplex(zeroNaN, Complex::asinh, NAN);
@@ -642,7 +647,7 @@ public class CStandardTest {
     @Test
     public void testAtanh() {
         assertConjugateEquality(Complex::atanh);
-        //assertOddOrEven(Complex::atanh, ODD);
+        assertOddOrEven(Complex::atanh, ODD);
         assertComplex(Complex.ZERO, Complex::atanh, Complex.ZERO);
         assertComplex(negZeroZero, Complex::atanh, negZeroZero);
         assertComplex(zeroNaN, Complex::atanh, zeroNaN);
@@ -669,7 +674,7 @@ public class CStandardTest {
     @Test
     public void testCosh() {
         assertConjugateEquality(Complex::cosh);
-        //assertOddOrEven(Complex::cosh, EVEN);
+        assertOddOrEven(Complex::cosh, EVEN);
         assertComplex(Complex.ZERO, Complex::cosh, Complex.ONE);
         assertComplex(negZeroZero, Complex::cosh, oneNegZero);
         assertComplex(zeroInf, Complex::cosh, nanZero);
@@ -688,9 +693,9 @@ public class CStandardTest {
         for (int i = 1; i < 10; i++) {
             final double y = i * 0.5;
             assertComplex(complex(inf, y), Complex::cosh, Complex.ofCis(y).multiply(inf));
+            assertComplex(complex(-inf, -y), Complex::cosh, Complex.ofCis(y).multiply(inf));
             assertComplex(complex(inf, -y), Complex::cosh, Complex.ofCis(-y).multiply(inf));
-            assertComplex(complex(-inf, y), Complex::cosh, Complex.ofCis(y).multiply(-inf));
-            assertComplex(complex(-inf, -y), Complex::cosh, Complex.ofCis(-y).multiply(-inf));
+            assertComplex(complex(-inf, y), Complex::cosh, Complex.ofCis(-y).multiply(inf));
         }
         assertComplex(negInfInf, Complex::cosh, infNaN);
         assertComplex(infInf, Complex::cosh, infNaN);
@@ -708,7 +713,7 @@ public class CStandardTest {
     @Test
     public void testSinh() {
         assertConjugateEquality(Complex::sinh);
-        //assertOddOrEven(Complex::sinh, ODD);
+        assertOddOrEven(Complex::sinh, ODD);
         assertComplex(Complex.ZERO, Complex::sinh, Complex.ZERO);
         assertComplex(negZeroZero, Complex::sinh, negZeroZero);
         assertComplex(zeroInf, Complex::sinh, zeroNaN);