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/04 21:53:54 UTC

[commons-numbers] 04/06: [NUMBERS-78] Increase edge case coverage of pow.

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 2065d65e9d656c92f0c7d4718e548cbcd8edc5f5
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Wed Dec 4 20:51:29 2019 +0000

    [NUMBERS-78] Increase edge case coverage of pow.
---
 .../apache/commons/numbers/complex/ComplexTest.java | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

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 005d7b3..78c61d7 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
@@ -855,6 +855,17 @@ public class ComplexTest {
     }
 
     @Test
+    public void testPowComplexRealZero() {
+        // Hits the edge case when real == 0 but imaginary != 0
+        final Complex x = Complex.ofCartesian(0, 1);
+        final Complex z = Complex.ofCartesian(2, 3);
+        final Complex c = x.pow(z);
+        // Answer from g++
+        Assertions.assertEquals(-0.008983291021129429, c.getReal());
+        Assertions.assertEquals(1.1001358594835313e-18, c.getImaginary());
+    }
+
+    @Test
     public void testPowComplexZeroBase() {
         final double x = Double.MIN_VALUE;
         assertPowComplexZeroBase(0, 0, NAN);
@@ -870,6 +881,16 @@ public class ComplexTest {
     }
 
     @Test
+    public void testPowScalerRealZero() {
+        // Hits the edge case when real == 0 but imaginary != 0
+        final Complex x = Complex.ofCartesian(0, 1);
+        final Complex c = x.pow(2);
+        // Answer from g++
+        Assertions.assertEquals(-1, c.getReal());
+        Assertions.assertEquals(1.2246467991473532e-16, c.getImaginary());
+    }
+
+    @Test
     public void testPowScalarZeroBase() {
         final double x = Double.MIN_VALUE;
         assertPowScalarZeroBase(0, NAN);