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 00:45:51 UTC
[commons-numbers] branch master updated (a7603bf -> 8963bd1)
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 a7603bf Revert "Order of arguments in Junit assertions."
new 19e272f Complex: Added test for function odd/even.
new 4e2d62b Fix asinh odd equality for infinite imaginary.
new fb4b645 Reorder assertion error arguments
new 8963bd1 Preserve even function in cosh
The 4 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 | 16 ++++-
.../commons/numbers/complex/CStandardTest.java | 83 ++++++++++++++++++++--
2 files changed, 90 insertions(+), 9 deletions(-)
[commons-numbers] 03/04: Reorder assertion error arguments
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 fb4b645d6e8073764ce00adf5a78b083ff7a1f7b
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Thu Dec 5 00:43:52 2019 +0000
Reorder assertion error arguments
---
.../test/java/org/apache/commons/numbers/complex/CStandardTest.java | 6 +++---
1 file changed, 3 insertions(+), 3 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 7285399..4bbb80b 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
@@ -181,7 +181,7 @@ public class CStandardTest {
if (!equals(c1.getReal(), c2.getReal()) ||
!equals(c1.getImaginary(), c2.getImaginary())) {
Assertions.fail(String.format("Conjugate equality failed (z=%s). Expected: %s but was: %s",
- z, c2, c1));
+ z, c1, c2));
}
}
@@ -247,8 +247,8 @@ public class CStandardTest {
// Test for binary equality
if (!equals(c1.getReal(), c2.getReal()) ||
!equals(c1.getImaginary(), c2.getImaginary())) {
- Assertions.fail(String.format("%s equality failed (z=%s). Expected: %s but was: %s",
- odd ? "Odd" : "Even", z, c2, c1));
+ Assertions.fail(String.format("%s equality failed (z=%s, -z=%s). Expected: %s but was: %s",
+ odd ? "Odd" : "Even", z, z.negate(), c1, c2));
}
}
Re: [commons-numbers] 04/04: Preserve even function in cosh
Posted by Alex Herbert <al...@gmail.com>.
> On 5 Dec 2019, at 01:39, Gilles Sadowski <gi...@gmail.com> wrote:
>
> Test failure here:
> ---CUT---
> ERROR] Failures:
> [ERROR] CStandardTest.testCosh:692->assertComplex:275 Operation
> failed (z=(-Infinity,0.5)). Expected: (-Infinity,-Infinity) but was:
> (Infinity,-Infinity)
> —CUT—
>
Sorry. I thought I had fixed it.
I have pushed another fix that should correct the odd/even function properties of all the complex functions for normal use cases. The edge cases need to be addressed separately.
Alex
> Gilles
>
> 2019-12-05 1:45 UTC+01:00, aherbert@apache.org <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 8963bd191ca80af6b1ba3f94998d5be0d64e43ac
>> Author: Alex Herbert <ah...@apache.org>
>> AuthorDate: Thu Dec 5 00:44:27 2019 +0000
>>
>> Preserve even function in cosh
>> ---
>> .../java/org/apache/commons/numbers/complex/Complex.java | 14
>> +++++++++++++-
>> 1 file changed, 13 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 490380b..e5b9ca8 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
>> @@ -1241,6 +1241,12 @@ public final class Complex implements Serializable
>> {
>> return constructor.create(Math.cosh(real) *
>> Math.cos(imaginary),
>> Math.sinh(real) *
>> Math.sin(imaginary));
>> }
>> + // ISO C99: Preserve the even function
>> + // f(z) = f(-z)
>> + if (negative(real)) {
>> + real = -real;
>> + imaginary = -imaginary;
>> + }
>> // Special case for real == 0
>> final double im = real == 0 ? Math.copySign(0, imaginary) :
>> Double.NaN;
>> return constructor.create(Double.NaN, im);
>> @@ -1253,6 +1259,12 @@ public final class Complex implements Serializable
>> {
>> return constructor.create(Double.POSITIVE_INFINITY,
>> im);
>> }
>> // inf * cis(y)
>> + // ISO C99: Preserve the even function
>> + // f(z) = f(-z)
>> + if (real < 0) {
>> + real = -real;
>> + imaginary = -imaginary;
>> + }
>> final double re = real * Math.cos(imaginary);
>> final double im = real * Math.sin(imaginary);
>> return constructor.create(re, im);
>> @@ -1262,7 +1274,7 @@ public final class Complex implements Serializable {
>> }
>> // real is NaN
>> if (imaginary == 0) {
>> - return constructor.create(Double.NaN, Math.copySign(0,
>> imaginary));
>> + return constructor.create(Double.NaN, imaginary);
>> }
>> // optionally raises the ‘‘invalid’’ floating-point exception, for
>> nonzero y.
>> return NAN;
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [commons-numbers] 04/04: Preserve even function in cosh
Posted by Gilles Sadowski <gi...@gmail.com>.
Test failure here:
---CUT---
ERROR] Failures:
[ERROR] CStandardTest.testCosh:692->assertComplex:275 Operation
failed (z=(-Infinity,0.5)). Expected: (-Infinity,-Infinity) but was:
(Infinity,-Infinity)
---CUT---
Gilles
2019-12-05 1:45 UTC+01:00, aherbert@apache.org <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 8963bd191ca80af6b1ba3f94998d5be0d64e43ac
> Author: Alex Herbert <ah...@apache.org>
> AuthorDate: Thu Dec 5 00:44:27 2019 +0000
>
> Preserve even function in cosh
> ---
> .../java/org/apache/commons/numbers/complex/Complex.java | 14
> +++++++++++++-
> 1 file changed, 13 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 490380b..e5b9ca8 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
> @@ -1241,6 +1241,12 @@ public final class Complex implements Serializable
> {
> return constructor.create(Math.cosh(real) *
> Math.cos(imaginary),
> Math.sinh(real) *
> Math.sin(imaginary));
> }
> + // ISO C99: Preserve the even function
> + // f(z) = f(-z)
> + if (negative(real)) {
> + real = -real;
> + imaginary = -imaginary;
> + }
> // Special case for real == 0
> final double im = real == 0 ? Math.copySign(0, imaginary) :
> Double.NaN;
> return constructor.create(Double.NaN, im);
> @@ -1253,6 +1259,12 @@ public final class Complex implements Serializable
> {
> return constructor.create(Double.POSITIVE_INFINITY,
> im);
> }
> // inf * cis(y)
> + // ISO C99: Preserve the even function
> + // f(z) = f(-z)
> + if (real < 0) {
> + real = -real;
> + imaginary = -imaginary;
> + }
> final double re = real * Math.cos(imaginary);
> final double im = real * Math.sin(imaginary);
> return constructor.create(re, im);
> @@ -1262,7 +1274,7 @@ public final class Complex implements Serializable {
> }
> // real is NaN
> if (imaginary == 0) {
> - return constructor.create(Double.NaN, Math.copySign(0,
> imaginary));
> + return constructor.create(Double.NaN, imaginary);
> }
> // optionally raises the ‘‘invalid’’ floating-point exception, for
> nonzero y.
> return NAN;
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
[commons-numbers] 04/04: Preserve even function in cosh
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 8963bd191ca80af6b1ba3f94998d5be0d64e43ac
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Thu Dec 5 00:44:27 2019 +0000
Preserve even function in cosh
---
.../java/org/apache/commons/numbers/complex/Complex.java | 14 +++++++++++++-
1 file changed, 13 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 490380b..e5b9ca8 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
@@ -1241,6 +1241,12 @@ public final class Complex implements Serializable {
return constructor.create(Math.cosh(real) * Math.cos(imaginary),
Math.sinh(real) * Math.sin(imaginary));
}
+ // ISO C99: Preserve the even function
+ // f(z) = f(-z)
+ if (negative(real)) {
+ real = -real;
+ imaginary = -imaginary;
+ }
// Special case for real == 0
final double im = real == 0 ? Math.copySign(0, imaginary) : Double.NaN;
return constructor.create(Double.NaN, im);
@@ -1253,6 +1259,12 @@ public final class Complex implements Serializable {
return constructor.create(Double.POSITIVE_INFINITY, im);
}
// inf * cis(y)
+ // ISO C99: Preserve the even function
+ // f(z) = f(-z)
+ if (real < 0) {
+ real = -real;
+ imaginary = -imaginary;
+ }
final double re = real * Math.cos(imaginary);
final double im = real * Math.sin(imaginary);
return constructor.create(re, im);
@@ -1262,7 +1274,7 @@ public final class Complex implements Serializable {
}
// real is NaN
if (imaginary == 0) {
- return constructor.create(Double.NaN, Math.copySign(0, imaginary));
+ return constructor.create(Double.NaN, imaginary);
}
// optionally raises the ‘‘invalid’’ floating-point exception, for nonzero y.
return NAN;
[commons-numbers] 01/04: Complex: Added test for function odd/even.
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 19e272f1b61ef4b2432c52aa219ba422e7ad970d
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Wed Dec 4 23:08:16 2019 +0000
Complex: Added test for function odd/even.
These tests currently fail with sign errors on infinite edge cases for:
asinh
atanh
cosh
sinh
tanh is OK.
The failing tests are commented out.
---
.../commons/numbers/complex/CStandardTest.java | 81 ++++++++++++++++++++--
1 file changed, 75 insertions(+), 6 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 18efe0f..7285399 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
@@ -89,6 +89,8 @@ public class CStandardTest {
private static final Complex maxMax = complex(max, max);
private static final Complex maxNan = complex(max, nan);
private static final Complex nanMax = complex(nan, max);
+ private static final boolean ODD = true;
+ private static final boolean EVEN = false;
/**
* Assert the two complex numbers have equivalent real and imaginary components as
@@ -184,6 +186,73 @@ public class CStandardTest {
}
/**
+ * Assert the operation on the complex number is odd or even.
+ *
+ * <pre>
+ * Odd : f(z) = -f(-z)
+ * Even: f(z) = f(-z)
+ * </pre>
+ *
+ * <p>The results must be binary equal. This includes the sign of zero.
+ *
+ * @param operation the operation
+ * @param odd true if odd
+ */
+ 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};
+ for (final double x : parts) {
+ for (final double y : parts) {
+ assertOddOrEven(x, y, operation, odd);
+ }
+ }
+ // Random numbers
+ final UniformRandomProvider rng = RandomSource.create(RandomSource.SPLIT_MIX_64);
+ for (int i = 0; i < 100; i++) {
+ final double x = next(rng);
+ final double y = next(rng);
+ assertOddOrEven(x, y, operation, odd);
+ }
+ }
+
+ /**
+ * Assert the operation on the complex number is odd or even.
+ *
+ * <pre>
+ * Odd : f(z) = -f(-z)
+ * Even: f(z) = f(-z)
+ * </pre>
+ *
+ * <p>The results must be binary equal. This includes the sign of zero.
+ *
+ * @param operation the operation
+ *
+ * @param re the real component
+ * @param im the imaginary component
+ * @param maxUlps {@code (maxUlps - 1)} is the number of floating point
+ * values between the real (resp. imaginary) parts of {@code x} and
+ * {@code y}.
+ * @param operation the operation
+ */
+ private static void assertOddOrEven(double re, double im,
+ UnaryOperator<Complex> operation, boolean odd) {
+ final Complex z = complex(re, im);
+ final Complex c1 = operation.apply(z);
+ Complex c2 = operation.apply(z.negate());
+ if (odd) {
+ c2 = c2.negate();
+ }
+
+ // Test for binary equality
+ if (!equals(c1.getReal(), c2.getReal()) ||
+ !equals(c1.getImaginary(), c2.getImaginary())) {
+ Assertions.fail(String.format("%s equality failed (z=%s). Expected: %s but was: %s",
+ odd ? "Odd" : "Even", z, c2, c1));
+ }
+ }
+
+ /**
* Assert the operation on the complex number is equal to the expected value.
* If the imaginary part is not NaN the operation must also satisfy the conjugate equality.
*
@@ -539,7 +608,7 @@ public class CStandardTest {
assertComplex(NAN, Complex::acosh, NAN);
}
- // TODO: test the 'IS ODD/ EVEN' specification
+ // TODO: fix the 'IS ODD/ EVEN' specification
/**
* ISO C Standard G.6.2.2.
@@ -547,7 +616,7 @@ public class CStandardTest {
@Test
public void testAsinh() {
assertConjugateEquality(Complex::asinh);
- // AND ASINH IS ODD
+ //assertOddOrEven(Complex::asinh, ODD);
assertComplex(Complex.ZERO, Complex::asinh, Complex.ZERO);
assertComplex(negZeroZero, Complex::asinh, negZeroZero);
assertComplex(zeroNaN, Complex::asinh, NAN);
@@ -573,7 +642,7 @@ public class CStandardTest {
@Test
public void testAtanh() {
assertConjugateEquality(Complex::atanh);
- // AND ATANH IS ODD
+ //assertOddOrEven(Complex::atanh, ODD);
assertComplex(Complex.ZERO, Complex::atanh, Complex.ZERO);
assertComplex(negZeroZero, Complex::atanh, negZeroZero);
assertComplex(zeroNaN, Complex::atanh, zeroNaN);
@@ -600,7 +669,7 @@ public class CStandardTest {
@Test
public void testCosh() {
assertConjugateEquality(Complex::cosh);
- // AND CCOSH IS EVEN
+ //assertOddOrEven(Complex::cosh, EVEN);
assertComplex(Complex.ZERO, Complex::cosh, Complex.ONE);
assertComplex(negZeroZero, Complex::cosh, oneNegZero);
assertComplex(zeroInf, Complex::cosh, nanZero);
@@ -639,7 +708,7 @@ public class CStandardTest {
@Test
public void testSinh() {
assertConjugateEquality(Complex::sinh);
- // AND CSINH IS ODD
+ //assertOddOrEven(Complex::sinh, ODD);
assertComplex(Complex.ZERO, Complex::sinh, Complex.ZERO);
assertComplex(negZeroZero, Complex::sinh, negZeroZero);
assertComplex(zeroInf, Complex::sinh, zeroNaN);
@@ -678,7 +747,7 @@ public class CStandardTest {
@Test
public void testTanh() {
assertConjugateEquality(Complex::tanh);
- // AND TANH IS ODD
+ assertOddOrEven(Complex::tanh, ODD);
assertComplex(Complex.ZERO, Complex::tanh, Complex.ZERO);
assertComplex(negZeroZero, Complex::tanh, negZeroZero);
assertComplex(zeroInf, Complex::tanh, NAN);
[commons-numbers] 02/04: Fix asinh odd equality for infinite
imaginary.
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 4e2d62b34ac5b43ba3c29ba30dda98bd1a0665eb
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Wed Dec 4 23:22:09 2019 +0000
Fix asinh odd equality for infinite imaginary.
---
.../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 1a7abfe..490380b 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
@@ -1043,7 +1043,7 @@ public final class Complex implements Serializable {
return z == this ? result : result.conjugate();
}
if (Double.isInfinite(imaginary)) {
- return new Complex(Double.POSITIVE_INFINITY, Math.copySign(PI_OVER_2, imaginary));
+ return new Complex(Math.copySign(Double.POSITIVE_INFINITY, real), Math.copySign(PI_OVER_2, imaginary));
}
// imaginary is NaN
return NAN;