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:50 UTC
[commons-numbers] branch master updated (3861867 -> 2026f96)
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 3861867 Allow floating-point error in the log10 test.
new 13a3d64 Javadoc correction
new cbe47a6 Use conjugate not conj
new 75b94a2 [NUMBERS-78] Increase coverage of reciprocal
new 2065d65 [NUMBERS-78] Increase edge case coverage of pow.
new d258522 [NUMBERS-78] Increase edge case coverage of atanh.
new 2026f96 Use add(double), subtract and subtractFromReal(double).
The 6 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 | 29 +++++++++++-----
.../commons/numbers/complex/CStandardTest.java | 4 +--
.../commons/numbers/complex/ComplexTest.java | 40 ++++++++++++++++++++++
3 files changed, 63 insertions(+), 10 deletions(-)
[commons-numbers] 06/06: Use add(double),
subtract and subtractFromReal(double).
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 2026f96c3d8465eda9e494756d29427e1bb9840f
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Wed Dec 4 21:52:56 2019 +0000
Use add(double), subtract and subtractFromReal(double).
Use this in preference to add(ONE), subtract(ONE) and ONE.subtract(z).
The add is faster.
The subtract preserves the sign of an imaginary zero.
The subtractFromReal negates the sign of the imaginary if it is zero.
---
.../main/java/org/apache/commons/numbers/complex/Complex.java | 9 +++------
1 file changed, 3 insertions(+), 6 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 b14ff97..1a7abfe 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
@@ -1039,7 +1039,7 @@ public final class Complex implements Serializable {
// ISO C99: Preserve the equality
// asinh(conj(z)) = conj(asinh(z))
final Complex z = negative(imaginary) ? conjugate() : this;
- final Complex result = z.square().add(ONE).sqrt().add(z).log();
+ final Complex result = z.square().add(1).sqrt().add(z).log();
return z == this ? result : result.conjugate();
}
if (Double.isInfinite(imaginary)) {
@@ -1142,7 +1142,7 @@ public final class Complex implements Serializable {
// ISO C99: Preserve the equality
// acosh(conj(z)) = conj(acosh(z))
final Complex z = negative(imaginary) ? conjugate() : this;
- final Complex result = z.square().subtract(ONE).sqrt().add(z).log();
+ final Complex result = z.square().subtract(1).sqrt().add(z).log();
return z == this ? result : result.conjugate();
}
if (Double.isInfinite(imaginary)) {
@@ -1561,13 +1561,10 @@ public final class Complex implements Serializable {
* square root</a> of <code>1 - this<sup>2</sup></code> for this complex
* number.
*
- * <p>Computes the result directly as
- * {@code sqrt(ONE.subtract(z.multiply(z)))}.</p>
- *
* @return the square root of <code>1 - this<sup>2</sup></code>.
*/
private Complex sqrt1z() {
- return ONE.subtract(square()).sqrt();
+ return square().subtractFromReal(1).sqrt();
}
/**
[commons-numbers] 01/06: Javadoc correction
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 13a3d64a0124ffa31aec50016556643cc6a57b46
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Wed Dec 4 19:18:38 2019 +0000
Javadoc correction
---
.../src/main/java/org/apache/commons/numbers/complex/Complex.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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 4ced624..fc80ecb 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
@@ -788,7 +788,7 @@ public final class Complex implements Serializable {
*
* @param real the real component
* @param imaginary the imaginary component
- * @return true if the complex is zero
+ * @return true if the complex is not zero
*/
private static boolean isNotZero(double real, double imaginary) {
// The use of equals is deliberate.
[commons-numbers] 05/06: [NUMBERS-78] Increase edge case coverage
of atanh.
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 d258522e2ec93b06f120fe66e3b8837afb8389b2
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Wed Dec 4 21:43:32 2019 +0000
[NUMBERS-78] Increase edge case coverage of atanh.
Requires implementation of subtractFromReal to negate the sign of the
imaginary zero when subtracting from 0 imaginary.
---
.../org/apache/commons/numbers/complex/Complex.java | 18 +++++++++++++++++-
.../apache/commons/numbers/complex/ComplexTest.java | 9 +++++++++
2 files changed, 26 insertions(+), 1 deletion(-)
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 fc80ecb..b14ff97 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
@@ -858,6 +858,22 @@ public final class Complex implements Serializable {
/**
* Returns a {@code Complex} whose value is
+ * {@code (minuend - this)}.
+ * Uses the definitional formula
+ * <p>
+ * {@code a - (c + di) = (a-c) -di}
+ * </p>
+ *
+ * @param minuend value that this {@code Complex} is to be subtracted from.
+ * @return {@code minuend - this}.
+ */
+ private Complex subtractFromReal(double minuend) {
+ return new Complex(minuend - real,
+ -imaginary);
+ }
+
+ /**
+ * Returns a {@code Complex} whose value is
* {@code (this - subtrahend)}.
*
* @param subtrahend value to be subtracted from this {@code Complex}.
@@ -1080,7 +1096,7 @@ public final class Complex implements Serializable {
// ISO C99: Preserve the equality
// atanh(conj(z)) = conj(atanh(z))
final Complex z = negative(imaginary) ? conjugate() : this;
- final Complex result = z.add(ONE).divide(ONE.subtract(z)).log().multiply(0.5);
+ final Complex result = z.add(1).divide(z.subtractFromReal(1)).log().multiply(0.5);
return z == this ? result : result.conjugate();
}
if (Double.isInfinite(imaginary)) {
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 78c61d7..977553b 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
@@ -1299,4 +1299,13 @@ public class ComplexTest {
TestUtils.assertEquals(Complex.ONE, Complex.ofCartesian(0, 25).tan(), 0);
TestUtils.assertEquals(Complex.ofCartesian(0, -1), Complex.ofCartesian(0, -25).tan(), 0);
}
+
+ @Test
+ public void testAtanhEdgeConditions() {
+ // Hits the edge case when imaginary == 0 but real != 0 or 1
+ final Complex c = Complex.ofCartesian(2, 0).atanh();
+ // Answer from g++
+ Assertions.assertEquals(0.54930614433405489, c.getReal());
+ Assertions.assertEquals(1.5707963267948966, c.getImaginary());
+ }
}
[commons-numbers] 04/06: [NUMBERS-78] Increase edge case coverage
of pow.
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 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);
[commons-numbers] 02/06: Use conjugate not conj
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 cbe47a6f4f595e9cb2c5758f3c7dc150aa3e327b
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Wed Dec 4 19:19:16 2019 +0000
Use conjugate not conj
---
.../test/java/org/apache/commons/numbers/complex/CStandardTest.java | 4 ++--
1 file changed, 2 insertions(+), 2 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 cddf068..18efe0f 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
@@ -172,8 +172,8 @@ public class CStandardTest {
private static void assertConjugateEquality(double re, double im,
UnaryOperator<Complex> operation) {
final Complex z = complex(re, im);
- final Complex c1 = operation.apply(z.conj());
- final Complex c2 = operation.apply(z).conj();
+ final Complex c1 = operation.apply(z.conjugate());
+ final Complex c2 = operation.apply(z).conjugate();
// Test for binary equality
if (!equals(c1.getReal(), c2.getReal()) ||
[commons-numbers] 03/06: [NUMBERS-78] Increase coverage of
reciprocal
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 75b94a2d28b59c8bc73c646f6020869043f8a167
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Wed Dec 4 19:38:26 2019 +0000
[NUMBERS-78] Increase coverage of reciprocal
---
.../java/org/apache/commons/numbers/complex/ComplexTest.java | 10 ++++++++++
1 file changed, 10 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 2711c61..005d7b3 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
@@ -372,6 +372,16 @@ public class ComplexTest {
}
@Test
+ public void testReciprocalMax() {
+ // This hits the edge case in reciprocal() for when q != 0 but scale == 0
+ final double smaller = Math.nextDown(Double.MAX_VALUE);
+ Complex z = Complex.ofCartesian(smaller, Double.MAX_VALUE);
+ Assertions.assertEquals(Complex.ofCartesian(0.0, -0.0), z.reciprocal());
+ z = Complex.ofCartesian(Double.MAX_VALUE, smaller);
+ Assertions.assertEquals(Complex.ofCartesian(0.0, -0.0), z.reciprocal());
+ }
+
+ @Test
public void testMultiply() {
final Complex x = Complex.ofCartesian(3.0, 4.0);
final Complex y = Complex.ofCartesian(5.0, 6.0);