You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2018/03/01 13:12:23 UTC
[1/6] commons-numbers git commit: Fix unit tests: "Complex.NAN" was
made private in a previous commit.
Repository: commons-numbers
Updated Branches:
refs/heads/complex-constructors 3c184d14a -> b86702259
Fix unit tests: "Complex.NAN" was made private in a previous commit.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/d7f354f0
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/d7f354f0
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/d7f354f0
Branch: refs/heads/complex-constructors
Commit: d7f354f0dcb945ecef5e0b664031631ba63c6cb5
Parents: 58f8953
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Wed Feb 14 17:14:58 2018 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Wed Feb 14 17:16:08 2018 +0100
----------------------------------------------------------------------
.../apache/commons/numbers/complex/Complex.java | 2 +-
.../commons/numbers/complex/CStandardTest.java | 61 ++++++++++----------
.../commons/numbers/complex/ComplexTest.java | 24 ++++----
.../numbers/complex/ComplexUtilsTest.java | 33 ++++++-----
4 files changed, 61 insertions(+), 59 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/d7f354f0/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
----------------------------------------------------------------------
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 4490953..835c406 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
@@ -1211,7 +1211,7 @@ public class Complex implements Serializable {
* {@link #getArgument() argument} of this complex number.
* <p>
* If one or both parts of this complex number is NaN, a list with just
- * one element, {@link #NAN} is returned.
+ * one element, {@code NaN + NaN i} is returned.
* if neither part is NaN, but at least one part is infinite, the result
* is a one-element list containing {@link #INF}.
*
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/d7f354f0/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CStandardTest.java
----------------------------------------------------------------------
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 e79ce9f..861da5a 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
@@ -69,6 +69,7 @@ public class CStandardTest {
private static final Complex piTwoNegZero = new Complex(piOverTwo, -0.0);
private static final Complex threePiFourNegInf = new Complex(threePiOverFour,negInf);
private static final Complex piFourNegInf = new Complex(piOverFour, negInf);
+ private static final Complex NAN = new Complex(nan, nan);
public void assertComplex(Complex c1, Complex c2, double realTol, double imagTol) {
Assert.assertEquals(c1.getReal(), c2.getReal(), realTol);
@@ -115,16 +116,16 @@ public class CStandardTest {
assertComplex(negZeroZero.acos(), piTwoNegZero);
assertComplex(zeroNaN.acos(), piTwoNaN);
assertComplex(oneInf.acos(), piTwoNegInf);
- assertComplex(oneNaN.acos(), Complex.NAN);
+ assertComplex(oneNaN.acos(), NAN);
assertComplex(negInfOne.acos(), piNegInf);
assertComplex(infOne.acos(), zeroNegInf);
assertComplex(negInfPosInf.acos(), threePiFourNegInf);
assertComplex(infInf.acos(), piFourNegInf);
assertComplex(infNaN.acos(), nanInf);
assertComplex(negInfNaN.acos(), nanNegInf);
- assertComplex(nanOne.acos(), Complex.NAN);
+ assertComplex(nanOne.acos(), NAN);
assertComplex(nanInf.acos(), nanNegInf);
- assertComplex(Complex.NAN.acos(), Complex.NAN);
+ assertComplex(NAN.acos(), NAN);
}
/**
@@ -136,14 +137,14 @@ public class CStandardTest {
assertComplex(oneOne.conj().asinh(), oneOne.asinh().conj());
assertComplex(Complex.ZERO.asinh(), Complex.ZERO);
assertComplex(oneInf.asinh(), infPiTwo);
- assertComplex(oneNaN.asinh(), Complex.NAN);
+ assertComplex(oneNaN.asinh(), NAN);
assertComplex(infOne.asinh(), infZero);
assertComplex(infInf.asinh(), infPiFour);
assertComplex(infNaN.asinh(), infNaN);
assertComplex(nanZero.asinh(), nanZero);
- assertComplex(nanOne.asinh(), Complex.NAN);
+ assertComplex(nanOne.asinh(), NAN);
assertComplex(nanInf.asinh(), infNaN);
- assertComplex(Complex.NAN, Complex.NAN);
+ assertComplex(NAN, NAN);
}
/**
@@ -156,13 +157,13 @@ public class CStandardTest {
assertComplex(zeroNaN.atanh(), zeroNaN);
assertComplex(oneZero.atanh(), infZero);
assertComplex(oneInf.atanh(),zeroPiTwo);
- assertComplex(oneNaN.atanh(), Complex.NAN);
+ assertComplex(oneNaN.atanh(), NAN);
assertComplex(infOne.atanh(), zeroPiTwo);
assertComplex(infInf.atanh(), zeroPiTwo);
assertComplex(infNaN.atanh(), zeroNaN);
- assertComplex(nanOne.atanh(), Complex.NAN);
+ assertComplex(nanOne.atanh(), NAN);
assertComplex(nanInf.atanh(), zeroPiTwo);
- assertComplex(Complex.NAN.atanh(), Complex.NAN);
+ assertComplex(NAN.atanh(), NAN);
}
/**
@@ -174,8 +175,8 @@ public class CStandardTest {
assertComplex(Complex.ZERO.cosh(), Complex.ONE);
assertComplex(zeroInf.cosh(), nanZero);
assertComplex(zeroNaN.cosh(), nanZero);
- assertComplex(oneInf.cosh(), Complex.NAN);
- assertComplex(oneNaN.cosh(), Complex.NAN);
+ assertComplex(oneInf.cosh(), NAN);
+ assertComplex(oneNaN.cosh(), NAN);
assertComplex(infZero.cosh(), infZero);
// the next test does not appear to make sense:
// (inf + iy) = inf + cis(y)
@@ -183,8 +184,8 @@ public class CStandardTest {
assertComplex(infInf.cosh(), infNaN);
assertComplex(infNaN.cosh(), infNaN);
assertComplex(nanZero.cosh(), nanZero);
- assertComplex(nanOne.cosh(), Complex.NAN);
- assertComplex(Complex.NAN.cosh(), Complex.NAN);
+ assertComplex(nanOne.cosh(), NAN);
+ assertComplex(NAN.cosh(), NAN);
}
/**
@@ -196,15 +197,15 @@ public class CStandardTest {
assertComplex(Complex.ZERO.sinh(), Complex.ZERO);
assertComplex(zeroInf.sinh(), zeroNaN);
assertComplex(zeroNaN.sinh(), zeroNaN);
- assertComplex(oneInf.sinh(), Complex.NAN);
- assertComplex(oneNaN.sinh(), Complex.NAN);
+ assertComplex(oneInf.sinh(), NAN);
+ assertComplex(oneNaN.sinh(), NAN);
assertComplex(infZero.sinh(), infZero);
// skipped test similar to previous section
assertComplex(infInf.sinh(), infNaN);
assertComplex(infNaN.sinh(), infNaN);
assertComplex(nanZero.sinh(), nanZero);
- assertComplex(nanOne.sinh(), Complex.NAN);
- assertComplex(Complex.NAN.sinh(), Complex.NAN);
+ assertComplex(nanOne.sinh(), NAN);
+ assertComplex(NAN.sinh(), NAN);
}
/**
@@ -214,14 +215,14 @@ public class CStandardTest {
public void testTanh() {
assertComplex(oneOne.tanh().conj(), oneOne.conj().tanh()); // AND CSINH IS ODD
assertComplex(Complex.ZERO.tanh(), Complex.ZERO);
- assertComplex(oneInf.tanh(), Complex.NAN);
- assertComplex(oneNaN.tanh(), Complex.NAN);
+ assertComplex(oneInf.tanh(), NAN);
+ assertComplex(oneNaN.tanh(), NAN);
//Do Not Understand the Next Test
assertComplex(infInf.tanh(), oneZero);
assertComplex(infNaN.tanh(), oneZero);
assertComplex(nanZero.tanh(), nanZero);
- assertComplex(nanOne.tanh(), Complex.NAN);
- assertComplex(Complex.NAN.tanh(), Complex.NAN);
+ assertComplex(nanOne.tanh(), NAN);
+ assertComplex(NAN.tanh(), NAN);
}
/**
@@ -232,8 +233,8 @@ public class CStandardTest {
assertComplex(oneOne.conj().exp(), oneOne.exp().conj());
assertComplex(Complex.ZERO.exp(), oneZero);
assertComplex(negZeroZero.exp(), oneZero);
- assertComplex(oneInf.exp(), Complex.NAN);
- assertComplex(oneNaN.exp(), Complex.NAN);
+ assertComplex(oneInf.exp(), NAN);
+ assertComplex(oneNaN.exp(), NAN);
assertComplex(infZero.exp(), infZero);
// Do not understand next test
assertComplex(negInfInf.exp(), Complex.ZERO);
@@ -241,8 +242,8 @@ public class CStandardTest {
assertComplex(negInfNaN.exp(), Complex.ZERO);
assertComplex(infNaN.exp(), infNaN);
assertComplex(nanZero.exp(), nanZero);
- assertComplex(nanOne.exp(), Complex.NAN);
- assertComplex(Complex.NAN.exp(), Complex.NAN);
+ assertComplex(nanOne.exp(), NAN);
+ assertComplex(NAN.exp(), NAN);
}
/**
@@ -254,14 +255,14 @@ public class CStandardTest {
assertComplex(negZeroZero.log(), negInfPi);
assertComplex(Complex.ZERO.log(), negInfZero);
assertComplex(oneInf.log(), infPiTwo);
- assertComplex(oneNaN.log(), Complex.NAN);
+ assertComplex(oneNaN.log(), NAN);
assertComplex(negInfOne.log(), infPi);
assertComplex(infOne.log(), infZero);
assertComplex(infInf.log(), infPiFour);
assertComplex(infNaN.log(), infNaN);
- assertComplex(nanOne.log(), Complex.NAN);
+ assertComplex(nanOne.log(), NAN);
assertComplex(nanInf.log(), infNaN);
- assertComplex(Complex.NAN.log(), Complex.NAN);
+ assertComplex(NAN.log(), NAN);
}
/**
@@ -276,7 +277,7 @@ public class CStandardTest {
assertComplex(infOne.sqrt(), infZero);
assertComplex(negInfNaN.sqrt(), nanInf);
assertComplex(infNaN.sqrt(), infNaN);
- assertComplex(nanOne.sqrt(), Complex.NAN);
- assertComplex(Complex.NAN.sqrt(), Complex.NAN);
+ assertComplex(nanOne.sqrt(), NAN);
+ assertComplex(NAN.sqrt(), NAN);
}
}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/d7f354f0/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexTest.java
----------------------------------------------------------------------
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 3e87320..80b433d 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
@@ -30,7 +30,6 @@ import org.junit.Test;
*/
public class ComplexTest {
-
private static final double inf = Double.POSITIVE_INFINITY;
private static final double neginf = Double.NEGATIVE_INFINITY;
private static final double nan = Double.NaN;
@@ -53,6 +52,7 @@ public class ComplexTest {
private static final Complex nanInf = new Complex(nan, inf);
private static final Complex nanNegInf = new Complex(nan, neginf);
private static final Complex nanZero = new Complex(nan, 0);
+ private static final Complex NAN = new Complex(nan, nan);
@Test
public void testConstructor() {
@@ -81,7 +81,7 @@ public class ComplexTest {
@Test
public void testAbsNaN() {
- Assert.assertTrue(Double.isNaN(Complex.NAN.abs()));
+ Assert.assertTrue(Double.isNaN(NAN.abs()));
Complex z = new Complex(inf, nan);
Assert.assertTrue(Double.isNaN(z.abs()));
}
@@ -146,7 +146,7 @@ public class ComplexTest {
@Test
public void testConjugateNaN() {
- Complex z = Complex.NAN.conjugate();
+ Complex z = NAN.conjugate();
Assert.assertTrue(z.isNaN());
}
@@ -187,20 +187,20 @@ public class ComplexTest {
Complex x = new Complex(3.0, 4.0);
Complex z = x.divide(Complex.ZERO);
// Assert.assertEquals(z, Complex.INF); // See MATH-657
- Assert.assertEquals(z, Complex.NAN);
+ Assert.assertEquals(z, NAN);
}
@Test
public void testDivideZeroZero() {
Complex x = new Complex(0.0, 0.0);
Complex z = x.divide(Complex.ZERO);
- Assert.assertEquals(z, Complex.NAN);
+ Assert.assertEquals(z, NAN);
}
@Test
public void testDivideNaN() {
Complex x = new Complex(3.0, 4.0);
- Complex z = x.divide(Complex.NAN);
+ Complex z = x.divide(NAN);
Assert.assertTrue(z.isNaN());
}
@@ -274,7 +274,7 @@ public class ComplexTest {
@Test
public void testReciprocalNaN() {
- Assert.assertTrue(Complex.NAN.reciprocal().isNaN());
+ Assert.assertTrue(NAN.reciprocal().isNaN());
}
@Test
@@ -333,7 +333,7 @@ public class ComplexTest {
@Test
public void testNegateNaN() {
- Complex z = Complex.NAN.negate();
+ Complex z = NAN.negate();
Assert.assertTrue(z.isNaN());
}
@@ -521,7 +521,7 @@ public class ComplexTest {
Complex realNaN = new Complex(Double.NaN, 0.0);
Complex imaginaryNaN = new Complex(0.0, Double.NaN);
Assert.assertEquals(realNaN.hashCode(), imaginaryNaN.hashCode());
- Assert.assertEquals(imaginaryNaN.hashCode(), Complex.NAN.hashCode());
+ Assert.assertEquals(imaginaryNaN.hashCode(), NAN.hashCode());
// MATH-1118
// "equals" and "hashCode" must be compatible: if two objects have
@@ -578,7 +578,7 @@ public class ComplexTest {
@Test
public void testScalarPowNaNBase() {
- Complex x = Complex.NAN;
+ Complex x = NAN;
double yDouble = 5.0;
Complex yComplex = new Complex(yDouble);
Assert.assertEquals(x.pow(yComplex), x.pow(yDouble));
@@ -616,7 +616,7 @@ public class ComplexTest {
@Test
public void testSqrt1zNaN() {
- Assert.assertTrue(Complex.NAN.sqrt1z().isNaN());
+ Assert.assertTrue(NAN.sqrt1z().isNaN());
}
/**
@@ -799,7 +799,7 @@ public class ComplexTest {
public void testGetArgumentNaN() {
Assert.assertTrue(Double.isNaN(nanZero.getArgument()));
Assert.assertTrue(Double.isNaN(zeroNaN.getArgument()));
- Assert.assertTrue(Double.isNaN(Complex.NAN.getArgument()));
+ Assert.assertTrue(Double.isNaN(NAN.getArgument()));
}
/*
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/d7f354f0/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexUtilsTest.java
----------------------------------------------------------------------
diff --git a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexUtilsTest.java b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexUtilsTest.java
index 3989797..8ca143a 100644
--- a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexUtilsTest.java
+++ b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexUtilsTest.java
@@ -26,16 +26,17 @@ import org.junit.Test;
*/
public class ComplexUtilsTest {
- private final double inf = Double.POSITIVE_INFINITY;
- private final double negInf = Double.NEGATIVE_INFINITY;
- private final double nan = Double.NaN;
- private final double pi = Math.PI;
+ private static final double inf = Double.POSITIVE_INFINITY;
+ private static final double negInf = Double.NEGATIVE_INFINITY;
+ private static final double nan = Double.NaN;
+ private static final double pi = Math.PI;
- private final Complex negInfInf = new Complex(negInf, inf);
- private final Complex infNegInf = new Complex(inf, negInf);
- private final Complex infInf = new Complex(inf, inf);
- private final Complex negInfNegInf = new Complex(negInf, negInf);
- private final Complex infNaN = new Complex(inf, nan);
+ private static final Complex negInfInf = new Complex(negInf, inf);
+ private static final Complex infNegInf = new Complex(inf, negInf);
+ private static final Complex infInf = new Complex(inf, inf);
+ private static final Complex negInfNegInf = new Complex(negInf, negInf);
+ private static final Complex infNaN = new Complex(inf, nan);
+ private static final Complex NAN = new Complex(nan, nan);
private static Complex c[]; // complex array with real values even and imag
// values odd
@@ -209,17 +210,17 @@ public class ComplexUtilsTest {
@Test
public void testPolar2ComplexNaN() {
- TestUtils.assertSame(Complex.NAN, ComplexUtils.polar2Complex(nan, 1));
- TestUtils.assertSame(Complex.NAN, ComplexUtils.polar2Complex(1, nan));
- TestUtils.assertSame(Complex.NAN, ComplexUtils.polar2Complex(nan, nan));
+ TestUtils.assertSame(NAN, ComplexUtils.polar2Complex(nan, 1));
+ TestUtils.assertSame(NAN, ComplexUtils.polar2Complex(1, nan));
+ TestUtils.assertSame(NAN, ComplexUtils.polar2Complex(nan, nan));
}
@Test
public void testPolar2ComplexInf() {
- TestUtils.assertSame(Complex.NAN, ComplexUtils.polar2Complex(1, inf));
- TestUtils.assertSame(Complex.NAN, ComplexUtils.polar2Complex(1, negInf));
- TestUtils.assertSame(Complex.NAN, ComplexUtils.polar2Complex(inf, inf));
- TestUtils.assertSame(Complex.NAN, ComplexUtils.polar2Complex(inf, negInf));
+ TestUtils.assertSame(NAN, ComplexUtils.polar2Complex(1, inf));
+ TestUtils.assertSame(NAN, ComplexUtils.polar2Complex(1, negInf));
+ TestUtils.assertSame(NAN, ComplexUtils.polar2Complex(inf, inf));
+ TestUtils.assertSame(NAN, ComplexUtils.polar2Complex(inf, negInf));
TestUtils.assertSame(infInf, ComplexUtils.polar2Complex(inf, pi / 4));
TestUtils.assertSame(infNaN, ComplexUtils.polar2Complex(inf, 0));
TestUtils.assertSame(infNegInf, ComplexUtils.polar2Complex(inf, -pi / 4));
[2/6] commons-numbers git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/commons-numbers
Posted by er...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/commons-numbers
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/af7b1d21
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/af7b1d21
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/af7b1d21
Branch: refs/heads/complex-constructors
Commit: af7b1d214eae66c9d9228b42c2d6f8a5d5d9c3f4
Parents: d7f354f 118a2fd
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Wed Feb 14 17:17:09 2018 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Wed Feb 14 17:17:09 2018 +0100
----------------------------------------------------------------------
.../main/java/org/apache/commons/numbers/complex/Complex.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/af7b1d21/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
----------------------------------------------------------------------
[4/6] commons-numbers git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/commons-numbers
Posted by er...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/commons-numbers
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/abec5ad8
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/abec5ad8
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/abec5ad8
Branch: refs/heads/complex-constructors
Commit: abec5ad87eeb1c4b176305348d601aff41db7572
Parents: 3c184d1 e06534c
Author: Eric Barnhill <er...@apache.org>
Authored: Thu Mar 1 14:01:08 2018 +0100
Committer: Eric Barnhill <er...@apache.org>
Committed: Thu Mar 1 14:01:08 2018 +0100
----------------------------------------------------------------------
.../apache/commons/numbers/complex/Complex.java | 21 +++----
.../commons/numbers/complex/CStandardTest.java | 61 ++++++++++----------
.../commons/numbers/complex/ComplexTest.java | 24 ++++----
.../numbers/complex/ComplexUtilsTest.java | 33 ++++++-----
4 files changed, 69 insertions(+), 70 deletions(-)
----------------------------------------------------------------------
[5/6] commons-numbers git commit: merge of complex-constructor branch
Posted by er...@apache.org.
merge of complex-constructor branch
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/5166d4be
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/5166d4be
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/5166d4be
Branch: refs/heads/complex-constructors
Commit: 5166d4beb42c1a71314312197d247ede015c2050
Parents: abec5ad
Author: Eric Barnhill <er...@apache.org>
Authored: Thu Mar 1 14:01:48 2018 +0100
Committer: Eric Barnhill <er...@apache.org>
Committed: Thu Mar 1 14:01:48 2018 +0100
----------------------------------------------------------------------
.../apache/commons/numbers/complex/Complex.java | 77 ++++++--------------
.../commons/numbers/complex/ComplexUtils.java | 62 ++++++++--------
.../commons/numbers/complex/RootsOfUnity.java | 6 +-
3 files changed, 57 insertions(+), 88 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/5166d4be/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
----------------------------------------------------------------------
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 cfc9625..c36bea1 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
@@ -63,24 +63,28 @@ public class Complex implements Serializable {
/** The real part. */
private final double real;
+ private Complex(double real, double imaginary) {
+ this.real = real;
+ this.imaginary = imaginary;
+ }
+
/**
- * Create a complex number given only the real part.
- *
- * @param real Real part.
- */
- public Complex(double real) {
- this(real, 0);
+ * Create a complex number given the real and imaginary parts.
+ *
+ * @param real Real part.
+ * @param imaginary Imaginary part.
+ */
+ public static Complex ofCartesian(double real, double imaginary) {
+ return new Complex(real, imaginary);
}
- /**
- * Create a complex number given the real and imaginary parts.
- *
- * @param real Real part.
- * @param imaginary Imaginary part.
- */
- public Complex(double real, double imaginary) {
- this.real = real;
- this.imaginary = imaginary;
+ /**
+ * Create a complex number given the real part.
+ *
+ * @param real Real part.
+ */
+ public static Complex ofCartesian(double real) {
+ return new Complex(real, 0);
}
/**
@@ -103,7 +107,7 @@ public class Complex implements Serializable {
* @param theta the argument of the complex number to create
* @return {@code Complex}
*/
- public Complex polar(double r, double theta) {
+ public static Complex ofPolar(double r, double theta) {
checkNotNegative(r);
return new Complex(r * Math.cos(theta), r * Math.sin(theta));
}
@@ -115,7 +119,7 @@ public class Complex implements Serializable {
* @param x {@code double} to build the cis number
* @return {@code Complex}
*/
- public Complex cis(double x) {
+ public static Complex ofCis(double x) {
return new Complex(Math.cos(x), Math.sin(x));
}
@@ -163,7 +167,7 @@ public class Complex implements Serializable {
public Complex proj() {
if (Double.isInfinite(real) ||
Double.isInfinite(imaginary)) {
- return new Complex(Double.POSITIVE_INFINITY);
+ return new Complex(Double.POSITIVE_INFINITY, 0);
} else {
return this;
}
@@ -1233,7 +1237,7 @@ public class Complex implements Serializable {
// inner part
final double realPart = nthRootOfAbs * Math.cos(innerPart);
final double imaginaryPart = nthRootOfAbs * Math.sin(innerPart);
- result.add(createComplex(realPart, imaginaryPart));
+ result.add(new Complex(realPart, imaginaryPart));
innerPart += slice;
}
@@ -1241,41 +1245,6 @@ public class Complex implements Serializable {
}
/**
- * Create a complex number given the real and imaginary parts.
- *
- * @param realPart Real part.
- * @param imaginaryPart Imaginary part.
- * @return a new complex number instance.
- * @see #valueOf(double, double)
- */
- protected Complex createComplex(double realPart,
- double imaginaryPart) {
- return new Complex(realPart, imaginaryPart);
- }
-
- /**
- * Create a complex number given the real and imaginary parts.
- *
- * @param realPart Real part.
- * @param imaginaryPart Imaginary part.
- * @return a Complex instance.
- */
- public static Complex valueOf(double realPart,
- double imaginaryPart) {
- return new Complex(realPart, imaginaryPart);
- }
-
- /**
- * Create a complex number given only the real part.
- *
- * @param realPart Real part.
- * @return a Complex instance.
- */
- public static Complex valueOf(double realPart) {
- return new Complex(realPart);
- }
-
- /**
* Resolve the transient fields in a deserialized Complex Object.
* Subclasses will need to override {@link #createComplex} to
* deserialize properly.
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/5166d4be/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/ComplexUtils.java
----------------------------------------------------------------------
diff --git a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/ComplexUtils.java b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/ComplexUtils.java
index b9f758a..684d406 100644
--- a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/ComplexUtils.java
+++ b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/ComplexUtils.java
@@ -55,7 +55,7 @@ public class ComplexUtils {
if (r < 0) {
throw new NegativeModulusException(r);
}
- return new Complex(r * Math.cos(theta), r * Math.sin(theta));
+ return Complex.ofCartesian(r * Math.cos(theta), r * Math.sin(theta));
}
/**
@@ -74,7 +74,7 @@ public class ComplexUtils {
if (r[x] < 0) {
throw new NegativeModulusException(r[x]);
}
- c[x] = new Complex(r[x] * Math.cos(theta[x]), r[x] * Math.sin(theta[x]));
+ c[x] = Complex.ofCartesian(r[x] * Math.cos(theta[x]), r[x] * Math.sin(theta[x]));
}
return c;
}
@@ -126,7 +126,7 @@ public class ComplexUtils {
* @since 1.0
*/
public static Complex extractComplexFromRealArray(double[] real, int index) {
- return new Complex(real[index]);
+ return Complex.ofCartesian(real[index]);
}
/**
@@ -140,7 +140,7 @@ public class ComplexUtils {
* @since 1.0
*/
public static Complex extractComplexFromRealArray(float[] real, int index) {
- return new Complex(real[index]);
+ return Complex.ofCartesian(real[index]);
}
/**
@@ -154,7 +154,7 @@ public class ComplexUtils {
* @since 1.0
*/
public static Complex extractComplexFromImaginaryArray(double[] imaginary, int index) {
- return new Complex(0, imaginary[index]);
+ return Complex.ofCartesian(0, imaginary[index]);
}
/**
@@ -168,7 +168,7 @@ public class ComplexUtils {
* @since 1.0
*/
public static Complex extractComplexFromImaginaryArray(float[] imaginary, int index) {
- return new Complex(0, imaginary[index]);
+ return Complex.ofCartesian(0, imaginary[index]);
}
/**
@@ -232,13 +232,13 @@ public class ComplexUtils {
* {@code index}.
*
* @param d array of interleaved complex numbers alternating real and imaginary values
- * @param index location in the array This is the location by complex number, e.g. index number 5 in the array will return {@code new Complex(d[10], d[11])}
+ * @param index location in the array This is the location by complex number, e.g. index number 5 in the array will return {@code Complex.ofCartesian(d[10], d[11])}
* @return {@code Complex}.
*
* @since 1.0
*/
public static Complex extractComplexFromInterleavedArray(double[] d, int index) {
- return new Complex(d[index * 2], d[index * 2 + 1]);
+ return Complex.ofCartesian(d[index * 2], d[index * 2 + 1]);
}
/**
@@ -252,7 +252,7 @@ public class ComplexUtils {
* @since 1.0
*/
public static Complex extractComplexFromInterleavedArray(float[] f, int index) {
- return new Complex(f[index * 2], f[index * 2 + 1]);
+ return Complex.ofCartesian(f[index * 2], f[index * 2 + 1]);
}
/**
@@ -295,7 +295,7 @@ public class ComplexUtils {
int index = 0;
final Complex c[] = new Complex[real.length];
for (double d : real) {
- c[index] = new Complex(d);
+ c[index] = Complex.ofCartesian(d);
index++;
}
return c;
@@ -313,7 +313,7 @@ public class ComplexUtils {
int index = 0;
final Complex c[] = new Complex[real.length];
for (float d : real) {
- c[index] = new Complex(d);
+ c[index] = Complex.ofCartesian(d);
index++;
}
return c;
@@ -564,7 +564,7 @@ public class ComplexUtils {
int index = 0;
final Complex c[] = new Complex[imaginary.length];
for (double d : imaginary) {
- c[index] = new Complex(0, d);
+ c[index] = Complex.ofCartesian(0, d);
index++;
}
return c;
@@ -582,7 +582,7 @@ public class ComplexUtils {
int index = 0;
final Complex c[] = new Complex[imaginary.length];
for (float d : imaginary) {
- c[index] = new Complex(0, d);
+ c[index] = Complex.ofCartesian(0, d);
index++;
}
return c;
@@ -799,7 +799,7 @@ public class ComplexUtils {
final int length = interleaved.length / 2;
final Complex c[] = new Complex[length];
for (int n = 0; n < length; n++) {
- c[n] = new Complex(interleaved[n * 2], interleaved[n * 2 + 1]);
+ c[n] = Complex.ofCartesian(interleaved[n * 2], interleaved[n * 2 + 1]);
}
return c;
}
@@ -817,7 +817,7 @@ public class ComplexUtils {
final int length = interleaved.length / 2;
final Complex c[] = new Complex[length];
for (int n = 0; n < length; n++) {
- c[n] = new Complex(interleaved[n * 2], interleaved[n * 2 + 1]);
+ c[n] = Complex.ofCartesian(interleaved[n * 2], interleaved[n * 2 + 1]);
}
return c;
}
@@ -1220,14 +1220,14 @@ public class ComplexUtils {
c = new Complex[w / 2][h];
for (int x = 0; x < w / 2; x++) {
for (int y = 0; y < h; y++) {
- c[x][y] = new Complex(i[x * 2][y], i[x * 2 + 1][y]);
+ c[x][y] = Complex.ofCartesian(i[x * 2][y], i[x * 2 + 1][y]);
}
}
} else {
c = new Complex[w][h / 2];
for (int x = 0; x < w; x++) {
for (int y = 0; y < h / 2; y++) {
- c[x][y] = new Complex(i[x][y * 2], i[x][y * 2 + 1]);
+ c[x][y] = Complex.ofCartesian(i[x][y * 2], i[x][y * 2 + 1]);
}
}
}
@@ -1271,7 +1271,7 @@ public class ComplexUtils {
for (int x = 0; x < w / 2; x++) {
for (int y = 0; y < h; y++) {
for (int z = 0; z < d; z++) {
- c[x][y][z] = new Complex(i[x * 2][y][z], i[x * 2 + 1][y][z]);
+ c[x][y][z] = Complex.ofCartesian(i[x * 2][y][z], i[x * 2 + 1][y][z]);
}
}
}
@@ -1280,7 +1280,7 @@ public class ComplexUtils {
for (int x = 0; x < w; x++) {
for (int y = 0; y < h / 2; y++) {
for (int z = 0; z < d; z++) {
- c[x][y][z] = new Complex(i[x][y * 2][z], i[x][y * 2 + 1][z]);
+ c[x][y][z] = Complex.ofCartesian(i[x][y * 2][z], i[x][y * 2 + 1][z]);
}
}
}
@@ -1289,7 +1289,7 @@ public class ComplexUtils {
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
for (int z = 0; z < d / 2; z++) {
- c[x][y][z] = new Complex(i[x][y][z * 2], i[x][y][z * 2 + 1]);
+ c[x][y][z] = Complex.ofCartesian(i[x][y][z * 2], i[x][y][z * 2 + 1]);
}
}
}
@@ -1322,7 +1322,7 @@ public class ComplexUtils {
for (int y = 0; y < h; y++) {
for (int z = 0; z < d; z++) {
for (int t = 0; t < v; t++) {
- c[x][y][z][t] = new Complex(i[x * 2][y][z][t], i[x * 2 + 1][y][z][t]);
+ c[x][y][z][t] = Complex.ofCartesian(i[x * 2][y][z][t], i[x * 2 + 1][y][z][t]);
}
}
}
@@ -1333,7 +1333,7 @@ public class ComplexUtils {
for (int y = 0; y < h / 2; y++) {
for (int z = 0; z < d; z++) {
for (int t = 0; t < v; t++) {
- c[x][y][z][t] = new Complex(i[x][y * 2][z][t], i[x][y * 2 + 1][z][t]);
+ c[x][y][z][t] = Complex.ofCartesian(i[x][y * 2][z][t], i[x][y * 2 + 1][z][t]);
}
}
}
@@ -1344,7 +1344,7 @@ public class ComplexUtils {
for (int y = 0; y < h; y++) {
for (int z = 0; z < d / 2; z++) {
for (int t = 0; t < v; t++) {
- c[x][y][z][t] = new Complex(i[x][y][z * 2][t], i[x][y][z * 2 + 1][t]);
+ c[x][y][z][t] = Complex.ofCartesian(i[x][y][z * 2][t], i[x][y][z * 2 + 1][t]);
}
}
}
@@ -1355,7 +1355,7 @@ public class ComplexUtils {
for (int y = 0; y < h; y++) {
for (int z = 0; z < d; z++) {
for (int t = 0; t < v / 2; t++) {
- c[x][y][z][t] = new Complex(i[x][y][z][t * 2], i[x][y][z][t * 2 + 1]);
+ c[x][y][z][t] = Complex.ofCartesian(i[x][y][z][t * 2], i[x][y][z][t * 2 + 1]);
}
}
}
@@ -1399,14 +1399,14 @@ public class ComplexUtils {
c = new Complex[w / 2][h];
for (int x = 0; x < w / 2; x++) {
for (int y = 0; y < h; y++) {
- c[x][y] = new Complex(i[x * 2][y], i[x * 2 + 1][y]);
+ c[x][y] = Complex.ofCartesian(i[x * 2][y], i[x * 2 + 1][y]);
}
}
} else {
c = new Complex[w][h / 2];
for (int x = 0; x < w; x++) {
for (int y = 0; y < h / 2; y++) {
- c[x][y] = new Complex(i[x][y * 2], i[x][y * 2 + 1]);
+ c[x][y] = Complex.ofCartesian(i[x][y * 2], i[x][y * 2 + 1]);
}
}
}
@@ -1450,7 +1450,7 @@ public class ComplexUtils {
for (int x = 0; x < w/2; x ++) {
for (int y = 0; y < h; y++) {
for (int z = 0; z < d; z++) {
- c[x][y][z] = new Complex(i[x * 2][y][z], i[x * 2 + 1][y][z]);
+ c[x][y][z] = Complex.ofCartesian(i[x * 2][y][z], i[x * 2 + 1][y][z]);
}
}
}
@@ -1459,7 +1459,7 @@ public class ComplexUtils {
for (int x = 0; x < w; x++) {
for (int y = 0; y < h/2; y ++) {
for (int z = 0; z < d; z++) {
- c[x][y][z] = new Complex(i[x][y * 2][z], i[x][y * 2 + 1][z]);
+ c[x][y][z] = Complex.ofCartesian(i[x][y * 2][z], i[x][y * 2 + 1][z]);
}
}
}
@@ -1468,7 +1468,7 @@ public class ComplexUtils {
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
for (int z = 0; z < d/2; z++) {
- c[x][y][z] = new Complex(i[x][y][z * 2], i[x][y][z * 2 + 1]);
+ c[x][y][z] = Complex.ofCartesian(i[x][y][z * 2], i[x][y][z * 2 + 1]);
}
}
}
@@ -1506,7 +1506,7 @@ public class ComplexUtils {
final int length = real.length;
final Complex[] c = new Complex[length];
for (int n = 0; n < length; n++) {
- c[n] = new Complex(real[n], imag[n]);
+ c[n] = Complex.ofCartesian(real[n], imag[n]);
}
return c;
}
@@ -1582,7 +1582,7 @@ public class ComplexUtils {
final int length = real.length;
final Complex[] c = new Complex[length];
for (int n = 0; n < length; n++) {
- c[n] = new Complex(real[n], imag[n]);
+ c[n] = Complex.ofCartesian(real[n], imag[n]);
}
return c;
}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/5166d4be/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/RootsOfUnity.java
----------------------------------------------------------------------
diff --git a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/RootsOfUnity.java b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/RootsOfUnity.java
index 89bf8d3..c3035ce 100644
--- a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/RootsOfUnity.java
+++ b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/RootsOfUnity.java
@@ -65,14 +65,14 @@ public class RootsOfUnity {
double previousReal = 1;
double previousImag = 0;
- omega[0] = new Complex(previousReal, previousImag);
+ omega[0] = Complex.ofCartesian(previousReal, previousImag);
for (int i = 1; i < omegaCount; i++) {
final double real = previousReal * cosT - previousImag * sinT;
final double imag = previousReal * sinT + previousImag * cosT;
omega[i] = isCounterClockwise ?
- new Complex(real, imag) :
- new Complex(real, -imag);
+ Complex.ofCartesian(real, imag) :
+ Complex.ofCartesian(real, -imag);
previousReal = real;
previousImag = imag;
[3/6] commons-numbers git commit: Javadoc, declaration order.
Posted by er...@apache.org.
Javadoc, declaration order.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/e06534c8
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/e06534c8
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/e06534c8
Branch: refs/heads/complex-constructors
Commit: e06534c83e29d1ac47789860d2365ef3ff57e922
Parents: af7b1d2
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Wed Feb 14 18:30:29 2018 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Wed Feb 14 18:30:29 2018 +0100
----------------------------------------------------------------------
.../apache/commons/numbers/complex/Complex.java | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/e06534c8/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
----------------------------------------------------------------------
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 fe07621..cfc9625 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
@@ -45,22 +45,19 @@ import org.apache.commons.numbers.core.Precision;
*
*/
public class Complex implements Serializable {
- /** The square root of -1. A number representing "0.0 + 1.0i" */
- public static final Complex I = new Complex(0, 1);
- // CHECKSTYLE: stop ConstantName
- /** A complex number representing "NaN + NaNi" */
+ /** Serializable version identifier. */
+ private static final long serialVersionUID = 20180201L;
+ /** A complex number representing "NaN + NaN i" */
private static final Complex NAN = new Complex(Double.NaN, Double.NaN);
- // CHECKSTYLE: resume ConstantName
- /** A complex number representing "+INF + INFi" */
+ /** The square root of -1, a.k.a. "i". */
+ public static final Complex I = new Complex(0, 1);
+ /** A complex number representing "+INF + INF i" */
public static final Complex INF = new Complex(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
- /** A complex number representing "1.0 + 0.0i" */
+ /** A complex number representing one. */
public static final Complex ONE = new Complex(1, 0);
- /** A complex number representing "0.0 + 0.0i" */
+ /** A complex number representing zero. */
public static final Complex ZERO = new Complex(0, 0);
- /** Serializable version identifier */
- private static final long serialVersionUID = 20180201L;
-
/** The imaginary part. */
private final double imaginary;
/** The real part. */
[6/6] commons-numbers git commit: NUMBERS-53: Fixes to test classes.
Waiting on decision about TestComplex class.
Posted by er...@apache.org.
NUMBERS-53: Fixes to test classes. Waiting on decision about TestComplex
class.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/b8670225
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/b8670225
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/b8670225
Branch: refs/heads/complex-constructors
Commit: b867022591eb365476d0df3dce3e1d559369d011
Parents: 5166d4b
Author: Eric Barnhill <er...@apache.org>
Authored: Thu Mar 1 14:14:40 2018 +0100
Committer: Eric Barnhill <er...@apache.org>
Committed: Thu Mar 1 14:14:40 2018 +0100
----------------------------------------------------------------------
.../commons/numbers/complex/CStandardTest.java | 91 +++---
.../commons/numbers/complex/ComplexTest.java | 283 +++++++++----------
.../numbers/complex/ComplexUtilsTest.java | 58 ++--
3 files changed, 210 insertions(+), 222 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/b8670225/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CStandardTest.java
----------------------------------------------------------------------
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 861da5a..e7a595e 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
@@ -18,9 +18,7 @@
package org.apache.commons.numbers.complex;
import org.apache.commons.numbers.complex.Complex;
-import org.apache.commons.numbers.complex.ComplexUtils;
import org.junit.Assert;
-import org.junit.Ignore;
import org.junit.Test;
public class CStandardTest {
@@ -28,49 +26,44 @@ public class CStandardTest {
private static final double inf = Double.POSITIVE_INFINITY;
private static final double negInf = Double.NEGATIVE_INFINITY;
private static final double nan = Double.NaN;
- private static final double pi = Math.PI;
private static final double piOverFour = Math.PI / 4.0;
private static final double piOverTwo = Math.PI / 2.0;
private static final double threePiOverFour = 3.0*Math.PI/4.0;
- private static final Complex oneOne = new Complex(1, 1);
- private static final Complex oneZero = new Complex(1, 0);
- private static final Complex oneInf = new Complex(1, inf);
- private static final Complex oneNegInf = new Complex(1, negInf);
- private static final Complex oneNaN = new Complex(1, nan);
- private static final Complex zeroInf = new Complex(0, inf);
- private static final Complex zeroNegInf = new Complex(0,negInf);
- private static final Complex zeroNaN = new Complex(0, nan);
- private static final Complex zeroPiTwo = new Complex(0.0, piOverTwo);
- private static final Complex negZeroZero = new Complex(-0.0, 0);
- private static final Complex negZeroNan = new Complex(-0.0, nan);
- private static final Complex negI = new Complex(0.0, -1.0);
- private static final Complex infOne = new Complex(inf, 1);
- private static final Complex infZero = new Complex(inf, 0);
- private static final Complex infNaN = new Complex(inf, nan);
- private static final Complex infNegInf = new Complex(inf, negInf);
- private static final Complex infInf = new Complex(inf, inf);
- private static final Complex infPiTwo = new Complex(inf, piOverTwo);
- private static final Complex infPiFour = new Complex(inf, piOverFour);
- private static final Complex infPi = new Complex(inf, Math.PI);
- private static final Complex negInfInf = new Complex(negInf, inf);
- private static final Complex negInfZero = new Complex(negInf, 0);
- private static final Complex negInfOne = new Complex(negInf, 1);
- private static final Complex negInfNaN = new Complex(negInf, nan);
- private static final Complex negInfNegInf = new Complex(negInf, negInf);
- private static final Complex negInfPosInf = new Complex(negInf, inf);
- private static final Complex negInfPi = new Complex(negInf, Math.PI);
- private static final Complex nanInf = new Complex(nan, inf);
- private static final Complex nanNegInf = new Complex(nan, negInf);
- private static final Complex nanZero = new Complex(nan, 0);
- private static final Complex nanOne = new Complex(nan, 1);
- private static final Complex piTwoNaN = new Complex(piOverTwo, nan);
- private static final Complex piNegInf = new Complex(Math.PI, negInf);
- private static final Complex piTwoNegInf = new Complex(piOverTwo, negInf);
- private static final Complex piTwoNegZero = new Complex(piOverTwo, -0.0);
- private static final Complex threePiFourNegInf = new Complex(threePiOverFour,negInf);
- private static final Complex piFourNegInf = new Complex(piOverFour, negInf);
- private static final Complex NAN = new Complex(nan, nan);
-
+ private static final Complex oneOne = Complex.ofCartesian(1, 1);
+ private static final Complex oneZero = Complex.ofCartesian(1, 0);
+ private static final Complex oneInf = Complex.ofCartesian(1, inf);
+ private static final Complex oneNaN = Complex.ofCartesian(1, nan);
+ private static final Complex zeroInf = Complex.ofCartesian(0, inf);
+ private static final Complex zeroNegInf = Complex.ofCartesian(0,negInf);
+ private static final Complex zeroNaN = Complex.ofCartesian(0, nan);
+ private static final Complex zeroPiTwo = Complex.ofCartesian(0.0, piOverTwo);
+ private static final Complex negZeroZero = Complex.ofCartesian(-0.0, 0);
+ private static final Complex negI = Complex.ofCartesian(0.0, -1.0);
+ private static final Complex infOne = Complex.ofCartesian(inf, 1);
+ private static final Complex infZero = Complex.ofCartesian(inf, 0);
+ private static final Complex infNaN = Complex.ofCartesian(inf, nan);
+ private static final Complex infInf = Complex.ofCartesian(inf, inf);
+ private static final Complex infPiTwo = Complex.ofCartesian(inf, piOverTwo);
+ private static final Complex infPiFour = Complex.ofCartesian(inf, piOverFour);
+ private static final Complex infPi = Complex.ofCartesian(inf, Math.PI);
+ private static final Complex negInfInf = Complex.ofCartesian(negInf, inf);
+ private static final Complex negInfZero = Complex.ofCartesian(negInf, 0);
+ private static final Complex negInfOne = Complex.ofCartesian(negInf, 1);
+ private static final Complex negInfNaN = Complex.ofCartesian(negInf, nan);
+ private static final Complex negInfPosInf = Complex.ofCartesian(negInf, inf);
+ private static final Complex negInfPi = Complex.ofCartesian(negInf, Math.PI);
+ private static final Complex nanInf = Complex.ofCartesian(nan, inf);
+ private static final Complex nanNegInf = Complex.ofCartesian(nan, negInf);
+ private static final Complex nanZero = Complex.ofCartesian(nan, 0);
+ private static final Complex nanOne = Complex.ofCartesian(nan, 1);
+ private static final Complex piTwoNaN = Complex.ofCartesian(piOverTwo, nan);
+ private static final Complex piNegInf = Complex.ofCartesian(Math.PI, negInf);
+ private static final Complex piTwoNegInf = Complex.ofCartesian(piOverTwo, negInf);
+ private static final Complex piTwoNegZero = Complex.ofCartesian(piOverTwo, -0.0);
+ private static final Complex threePiFourNegInf = Complex.ofCartesian(threePiOverFour,negInf);
+ private static final Complex piFourNegInf = Complex.ofCartesian(piOverFour, negInf);
+ private static final Complex NAN = Complex.ofCartesian(nan, nan);
+
public void assertComplex(Complex c1, Complex c2, double realTol, double imagTol) {
Assert.assertEquals(c1.getReal(), c2.getReal(), realTol);
Assert.assertEquals(c1.getImaginary(), c2.getImaginary(), imagTol);
@@ -87,18 +80,18 @@ public class CStandardTest {
*/
@Test
public void testSqrt1() {
- Complex z1 = new Complex(-2.0, 0.0);
- Complex z2 = new Complex(0.0, Math.sqrt(2));
+ Complex z1 = Complex.ofCartesian(-2.0, 0.0);
+ Complex z2 = Complex.ofCartesian(0.0, Math.sqrt(2));
assertComplex(z1.sqrt(), z2);
- z1 = new Complex(-2.0, -0.0);
- z2 = new Complex(0.0, -Math.sqrt(2));
+ z1 = Complex.ofCartesian(-2.0, -0.0);
+ z2 = Complex.ofCartesian(0.0, -Math.sqrt(2));
assertComplex(z1.sqrt(), z2);
}
@Test
public void testImplicitTrig() {
- Complex z1 = new Complex(3.0);
- Complex z2 = new Complex(0.0, 3.0);
+ Complex z1 = Complex.ofCartesian(3.0);
+ Complex z2 = Complex.ofCartesian(0.0, 3.0);
assertComplex(z1.asin(), negI.multiply(z2.asinh()));
assertComplex(z1.atan(), negI.multiply(z2.atanh()), Math.ulp(1), Math.ulp(1));
assertComplex(z1.cos(), z2.cosh());
@@ -252,7 +245,7 @@ public class CStandardTest {
@Test
public void testLog() {
assertComplex(oneOne.log().conj(), oneOne.conj().log());
- assertComplex(negZeroZero.log(), negInfPi);
+ assertComplex(negZeroZero.log(), negInfPi);
assertComplex(Complex.ZERO.log(), negInfZero);
assertComplex(oneInf.log(), infPiTwo);
assertComplex(oneNaN.log(), NAN);
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/b8670225/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexTest.java
----------------------------------------------------------------------
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 80b433d..e147fe0 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
@@ -34,62 +34,62 @@ public class ComplexTest {
private static final double neginf = Double.NEGATIVE_INFINITY;
private static final double nan = Double.NaN;
private static final double pi = Math.PI;
- private static final Complex oneInf = new Complex(1, inf);
- private static final Complex oneNegInf = new Complex(1, neginf);
- private static final Complex infOne = new Complex(inf, 1);
- private static final Complex infZero = new Complex(inf, 0);
- private static final Complex infNaN = new Complex(inf, nan);
- private static final Complex infNegInf = new Complex(inf, neginf);
- private static final Complex infInf = new Complex(inf, inf);
- private static final Complex negInfInf = new Complex(neginf, inf);
- private static final Complex negInfZero = new Complex(neginf, 0);
- private static final Complex negInfOne = new Complex(neginf, 1);
- private static final Complex negInfNaN = new Complex(neginf, nan);
- private static final Complex negInfNegInf = new Complex(neginf, neginf);
- private static final Complex oneNaN = new Complex(1, nan);
- private static final Complex zeroInf = new Complex(0, inf);
- private static final Complex zeroNaN = new Complex(0, nan);
- private static final Complex nanInf = new Complex(nan, inf);
- private static final Complex nanNegInf = new Complex(nan, neginf);
- private static final Complex nanZero = new Complex(nan, 0);
- private static final Complex NAN = new Complex(nan, nan);
+ private static final Complex oneInf = Complex.ofCartesian(1, inf);
+ private static final Complex oneNegInf = Complex.ofCartesian(1, neginf);
+ private static final Complex infOne = Complex.ofCartesian(inf, 1);
+ private static final Complex infZero = Complex.ofCartesian(inf, 0);
+ private static final Complex infNaN = Complex.ofCartesian(inf, nan);
+ private static final Complex infNegInf = Complex.ofCartesian(inf, neginf);
+ private static final Complex infInf = Complex.ofCartesian(inf, inf);
+ private static final Complex negInfInf = Complex.ofCartesian(neginf, inf);
+ private static final Complex negInfZero = Complex.ofCartesian(neginf, 0);
+ private static final Complex negInfOne = Complex.ofCartesian(neginf, 1);
+ private static final Complex negInfNaN = Complex.ofCartesian(neginf, nan);
+ private static final Complex negInfNegInf = Complex.ofCartesian(neginf, neginf);
+ private static final Complex oneNaN = Complex.ofCartesian(1, nan);
+ private static final Complex zeroInf = Complex.ofCartesian(0, inf);
+ private static final Complex zeroNaN = Complex.ofCartesian(0, nan);
+ private static final Complex nanInf = Complex.ofCartesian(nan, inf);
+ private static final Complex nanNegInf = Complex.ofCartesian(nan, neginf);
+ private static final Complex nanZero = Complex.ofCartesian(nan, 0);
+ private static final Complex NAN = Complex.ofCartesian(nan, nan);
@Test
public void testConstructor() {
- Complex z = new Complex(3.0, 4.0);
+ Complex z = Complex.ofCartesian(3.0, 4.0);
Assert.assertEquals(3.0, z.getReal(), 1.0e-5);
Assert.assertEquals(4.0, z.getImaginary(), 1.0e-5);
}
@Test
public void testConstructorNaN() {
- Complex z = new Complex(3.0, Double.NaN);
+ Complex z = Complex.ofCartesian(3.0, Double.NaN);
Assert.assertTrue(z.isNaN());
- z = new Complex(nan, 4.0);
+ z = Complex.ofCartesian(nan, 4.0);
Assert.assertTrue(z.isNaN());
- z = new Complex(3.0, 4.0);
+ z = Complex.ofCartesian(3.0, 4.0);
Assert.assertFalse(z.isNaN());
}
@Test
public void testAbs() {
- Complex z = new Complex(3.0, 4.0);
+ Complex z = Complex.ofCartesian(3.0, 4.0);
Assert.assertEquals(5.0, z.abs(), 1.0e-5);
}
@Test
public void testAbsNaN() {
Assert.assertTrue(Double.isNaN(NAN.abs()));
- Complex z = new Complex(inf, nan);
+ Complex z = Complex.ofCartesian(inf, nan);
Assert.assertTrue(Double.isNaN(z.abs()));
}
@Test
public void testAdd() {
- Complex x = new Complex(3.0, 4.0);
- Complex y = new Complex(5.0, 6.0);
+ Complex x = Complex.ofCartesian(3.0, 4.0);
+ Complex y = Complex.ofCartesian(5.0, 6.0);
Complex z = x.add(y);
Assert.assertEquals(8.0, z.getReal(), 1.0e-5);
Assert.assertEquals(10.0, z.getImaginary(), 1.0e-5);
@@ -97,48 +97,48 @@ public class ComplexTest {
@Test
public void testAddInf() {
- Complex x = new Complex(1, 1);
- Complex z = new Complex(inf, 0);
+ Complex x = Complex.ofCartesian(1, 1);
+ Complex z = Complex.ofCartesian(inf, 0);
Complex w = x.add(z);
Assert.assertEquals(w.getImaginary(), 1, 0);
Assert.assertEquals(inf, w.getReal(), 0);
- x = new Complex(neginf, 0);
+ x = Complex.ofCartesian(neginf, 0);
Assert.assertTrue(Double.isNaN(x.add(z).getReal()));
}
@Test
public void testScalarAdd() {
- Complex x = new Complex(3.0, 4.0);
+ Complex x = Complex.ofCartesian(3.0, 4.0);
double yDouble = 2.0;
- Complex yComplex = new Complex(yDouble);
+ Complex yComplex = Complex.ofCartesian(yDouble);
Assert.assertEquals(x.add(yComplex), x.add(yDouble));
}
@Test
public void testScalarAddNaN() {
- Complex x = new Complex(3.0, 4.0);
+ Complex x = Complex.ofCartesian(3.0, 4.0);
double yDouble = Double.NaN;
- Complex yComplex = new Complex(yDouble);
+ Complex yComplex = Complex.ofCartesian(yDouble);
Assert.assertEquals(x.add(yComplex), x.add(yDouble));
}
@Test
public void testScalarAddInf() {
- Complex x = new Complex(1, 1);
+ Complex x = Complex.ofCartesian(1, 1);
double yDouble = Double.POSITIVE_INFINITY;
- Complex yComplex = new Complex(yDouble);
+ Complex yComplex = Complex.ofCartesian(yDouble);
Assert.assertEquals(x.add(yComplex), x.add(yDouble));
- x = new Complex(neginf, 0);
+ x = Complex.ofCartesian(neginf, 0);
Assert.assertEquals(x.add(yComplex), x.add(yDouble));
}
@Test
public void testConjugate() {
- Complex x = new Complex(3.0, 4.0);
+ Complex x = Complex.ofCartesian(3.0, 4.0);
Complex z = x.conjugate();
Assert.assertEquals(3.0, z.getReal(), 1.0e-5);
Assert.assertEquals(-4.0, z.getImaginary(), 1.0e-5);
@@ -152,16 +152,16 @@ public class ComplexTest {
@Test
public void testConjugateInfiinite() {
- Complex z = new Complex(0, inf);
+ Complex z = Complex.ofCartesian(0, inf);
Assert.assertEquals(neginf, z.conjugate().getImaginary(), 0);
- z = new Complex(0, neginf);
+ z = Complex.ofCartesian(0, neginf);
Assert.assertEquals(inf, z.conjugate().getImaginary(), 0);
}
@Test
public void testDivide() {
- Complex x = new Complex(3.0, 4.0);
- Complex y = new Complex(5.0, 6.0);
+ Complex x = Complex.ofCartesian(3.0, 4.0);
+ Complex y = Complex.ofCartesian(5.0, 6.0);
Complex z = x.divide(y);
Assert.assertEquals(39.0 / 61.0, z.getReal(), 1.0e-5);
Assert.assertEquals(2.0 / 61.0, z.getImaginary(), 1.0e-5);
@@ -169,22 +169,22 @@ public class ComplexTest {
@Test
public void testDivideReal() {
- Complex x = new Complex(2d, 3d);
- Complex y = new Complex(2d, 0d);
- Assert.assertEquals(new Complex(1d, 1.5), x.divide(y));
+ Complex x = Complex.ofCartesian(2d, 3d);
+ Complex y = Complex.ofCartesian(2d, 0d);
+ Assert.assertEquals(Complex.ofCartesian(1d, 1.5), x.divide(y));
}
@Test
public void testDivideImaginary() {
- Complex x = new Complex(2d, 3d);
- Complex y = new Complex(0d, 2d);
- Assert.assertEquals(new Complex(1.5d, -1d), x.divide(y));
+ Complex x = Complex.ofCartesian(2d, 3d);
+ Complex y = Complex.ofCartesian(0d, 2d);
+ Assert.assertEquals(Complex.ofCartesian(1.5d, -1d), x.divide(y));
}
@Test
public void testDivideZero() {
- Complex x = new Complex(3.0, 4.0);
+ Complex x = Complex.ofCartesian(3.0, 4.0);
Complex z = x.divide(Complex.ZERO);
// Assert.assertEquals(z, Complex.INF); // See MATH-657
Assert.assertEquals(z, NAN);
@@ -192,14 +192,14 @@ public class ComplexTest {
@Test
public void testDivideZeroZero() {
- Complex x = new Complex(0.0, 0.0);
+ Complex x = Complex.ofCartesian(0.0, 0.0);
Complex z = x.divide(Complex.ZERO);
Assert.assertEquals(z, NAN);
}
@Test
public void testDivideNaN() {
- Complex x = new Complex(3.0, 4.0);
+ Complex x = Complex.ofCartesian(3.0, 4.0);
Complex z = x.divide(NAN);
Assert.assertTrue(z.isNaN());
}
@@ -221,29 +221,29 @@ public class ComplexTest {
@Test
public void testScalarDivide() {
- Complex x = new Complex(3.0, 4.0);
+ Complex x = Complex.ofCartesian(3.0, 4.0);
double yDouble = 2.0;
- Complex yComplex = new Complex(yDouble);
+ Complex yComplex = Complex.ofCartesian(yDouble);
Assert.assertEquals(x.divide(yComplex), x.divide(yDouble));
}
@Test
public void testScalarDivideNaN() {
- Complex x = new Complex(3.0, 4.0);
+ Complex x = Complex.ofCartesian(3.0, 4.0);
double yDouble = Double.NaN;
- Complex yComplex = new Complex(yDouble);
+ Complex yComplex = Complex.ofCartesian(yDouble);
Assert.assertEquals(x.divide(yComplex), x.divide(yDouble));
}
@Test
public void testScalarDivideZero() {
- Complex x = new Complex(1,1);
+ Complex x = Complex.ofCartesian(1,1);
TestUtils.assertEquals(x.divide(Complex.ZERO), x.divide(0), 0);
}
@Test
public void testReciprocal() {
- Complex z = new Complex(5.0, 6.0);
+ Complex z = Complex.ofCartesian(5.0, 6.0);
Complex act = z.reciprocal();
double expRe = 5.0 / 61.0;
double expIm = -6.0 / 61.0;
@@ -253,7 +253,7 @@ public class ComplexTest {
@Test
public void testReciprocalReciprocal() {
- Complex z = new Complex(5.0, 6.0);
+ Complex z = Complex.ofCartesian(5.0, 6.0);
Complex zRR = z.reciprocal().reciprocal();
final double tol = 1e-14;
Assert.assertEquals(zRR.getReal(), z.getReal(), tol);
@@ -262,14 +262,14 @@ public class ComplexTest {
@Test
public void testReciprocalReal() {
- Complex z = new Complex(-2.0, 0.0);
- Assert.assertTrue(Complex.equals(new Complex(-0.5, 0.0), z.reciprocal()));
+ Complex z = Complex.ofCartesian(-2.0, 0.0);
+ Assert.assertTrue(Complex.equals(Complex.ofCartesian(-0.5, 0.0), z.reciprocal()));
}
@Test
public void testReciprocalImaginary() {
- Complex z = new Complex(0.0, -2.0);
- Assert.assertEquals(new Complex(0.0, 0.5), z.reciprocal());
+ Complex z = Complex.ofCartesian(0.0, -2.0);
+ Assert.assertEquals(Complex.ofCartesian(0.0, 0.5), z.reciprocal());
}
@Test
@@ -279,8 +279,8 @@ public class ComplexTest {
@Test
public void testMultiply() {
- Complex x = new Complex(3.0, 4.0);
- Complex y = new Complex(5.0, 6.0);
+ Complex x = Complex.ofCartesian(3.0, 4.0);
+ Complex y = Complex.ofCartesian(5.0, 6.0);
Complex z = x.multiply(y);
Assert.assertEquals(-9.0, z.getReal(), 1.0e-5);
Assert.assertEquals(38.0, z.getImaginary(), 1.0e-5);
@@ -294,38 +294,38 @@ public class ComplexTest {
@Test
public void testScalarMultiply() {
- Complex x = new Complex(3.0, 4.0);
+ Complex x = Complex.ofCartesian(3.0, 4.0);
double yDouble = 2.0;
- Complex yComplex = new Complex(yDouble);
+ Complex yComplex = Complex.ofCartesian(yDouble);
Assert.assertEquals(x.multiply(yComplex), x.multiply(yDouble));
int zInt = -5;
- Complex zComplex = new Complex(zInt);
+ Complex zComplex = Complex.ofCartesian(zInt);
Assert.assertEquals(x.multiply(zComplex), x.multiply(zInt));
}
@Test
public void testScalarMultiplyNaN() {
- Complex x = new Complex(3.0, 4.0);
+ Complex x = Complex.ofCartesian(3.0, 4.0);
double yDouble = Double.NaN;
- Complex yComplex = new Complex(yDouble);
+ Complex yComplex = Complex.ofCartesian(yDouble);
Assert.assertEquals(x.multiply(yComplex), x.multiply(yDouble));
}
@Test
public void testScalarMultiplyInf() {
- Complex x = new Complex(1, 1);
+ Complex x = Complex.ofCartesian(1, 1);
double yDouble = Double.POSITIVE_INFINITY;
- Complex yComplex = new Complex(yDouble);
+ Complex yComplex = Complex.ofCartesian(yDouble);
Assert.assertEquals(x.multiply(yComplex), x.multiply(yDouble));
yDouble = Double.NEGATIVE_INFINITY;
- yComplex = new Complex(yDouble);
+ yComplex = Complex.ofCartesian(yDouble);
Assert.assertEquals(x.multiply(yComplex), x.multiply(yDouble));
}
@Test
public void testNegate() {
- Complex x = new Complex(3.0, 4.0);
+ Complex x = Complex.ofCartesian(3.0, 4.0);
Complex z = x.negate();
Assert.assertEquals(-3.0, z.getReal(), 1.0e-5);
Assert.assertEquals(-4.0, z.getImaginary(), 1.0e-5);
@@ -339,8 +339,8 @@ public class ComplexTest {
@Test
public void testSubtract() {
- Complex x = new Complex(3.0, 4.0);
- Complex y = new Complex(5.0, 6.0);
+ Complex x = Complex.ofCartesian(3.0, 4.0);
+ Complex y = Complex.ofCartesian(5.0, 6.0);
Complex z = x.subtract(y);
Assert.assertEquals(-2.0, z.getReal(), 1.0e-5);
Assert.assertEquals(-2.0, z.getImaginary(), 1.0e-5);
@@ -348,68 +348,68 @@ public class ComplexTest {
@Test
public void testSubtractInf() {
- Complex x = new Complex(1, 1);
- Complex z = new Complex(neginf, 0);
+ Complex x = Complex.ofCartesian(1, 1);
+ Complex z = Complex.ofCartesian(neginf, 0);
Complex w = x.subtract(z);
Assert.assertEquals(w.getImaginary(), 1, 0);
Assert.assertEquals(inf, w.getReal(), 0);
- x = new Complex(neginf, 0);
+ x = Complex.ofCartesian(neginf, 0);
Assert.assertTrue(Double.isNaN(x.subtract(z).getReal()));
}
@Test
public void testScalarSubtract() {
- Complex x = new Complex(3.0, 4.0);
+ Complex x = Complex.ofCartesian(3.0, 4.0);
double yDouble = 2.0;
- Complex yComplex = new Complex(yDouble);
+ Complex yComplex = Complex.ofCartesian(yDouble);
Assert.assertEquals(x.subtract(yComplex), x.subtract(yDouble));
}
@Test
public void testScalarSubtractNaN() {
- Complex x = new Complex(3.0, 4.0);
+ Complex x = Complex.ofCartesian(3.0, 4.0);
double yDouble = Double.NaN;
- Complex yComplex = new Complex(yDouble);
+ Complex yComplex = Complex.ofCartesian(yDouble);
Assert.assertEquals(x.subtract(yComplex), x.subtract(yDouble));
}
@Test
public void testScalarSubtractInf() {
- Complex x = new Complex(1, 1);
+ Complex x = Complex.ofCartesian(1, 1);
double yDouble = Double.POSITIVE_INFINITY;
- Complex yComplex = new Complex(yDouble);
+ Complex yComplex = Complex.ofCartesian(yDouble);
Assert.assertEquals(x.subtract(yComplex), x.subtract(yDouble));
- x = new Complex(neginf, 0);
+ x = Complex.ofCartesian(neginf, 0);
Assert.assertEquals(x.subtract(yComplex), x.subtract(yDouble));
}
@Test
public void testEqualsNull() {
- Complex x = new Complex(3.0, 4.0);
+ Complex x = Complex.ofCartesian(3.0, 4.0);
Assert.assertFalse(x.equals(null));
}
@Test(expected=NullPointerException.class)
public void testFloatingPointEqualsPrecondition1() {
- Complex.equals(new Complex(3.0, 4.0), null, 3);
+ Complex.equals(Complex.ofCartesian(3.0, 4.0), null, 3);
}
@Test(expected=NullPointerException.class)
public void testFloatingPointEqualsPrecondition2() {
- Complex.equals(null, new Complex(3.0, 4.0), 3);
+ Complex.equals(null, Complex.ofCartesian(3.0, 4.0), 3);
}
@Test
public void testEqualsClass() {
- Complex x = new Complex(3.0, 4.0);
+ Complex x = Complex.ofCartesian(3.0, 4.0);
Assert.assertFalse(x.equals(this));
}
@Test
public void testEqualsSame() {
- Complex x = new Complex(3.0, 4.0);
+ Complex x = Complex.ofCartesian(3.0, 4.0);
Assert.assertTrue(x.equals(x));
}
@@ -418,8 +418,8 @@ public class ComplexTest {
double re = -3.21;
double im = 456789e10;
- final Complex x = new Complex(re, im);
- Complex y = new Complex(re, im);
+ final Complex x = Complex.ofCartesian(re, im);
+ Complex y = Complex.ofCartesian(re, im);
Assert.assertTrue(x.equals(y));
Assert.assertTrue(Complex.equals(x, y));
@@ -429,21 +429,21 @@ public class ComplexTest {
re = Math.nextUp(re);
im = Math.nextUp(im);
}
- y = new Complex(re, im);
+ y = Complex.ofCartesian(re, im);
Assert.assertTrue(Complex.equals(x, y, maxUlps));
re = Math.nextUp(re);
im = Math.nextUp(im);
- y = new Complex(re, im);
+ y = Complex.ofCartesian(re, im);
Assert.assertFalse(Complex.equals(x, y, maxUlps));
}
@Test
public void testFloatingPointEqualsNaN() {
- Complex c = new Complex(Double.NaN, 1);
+ Complex c = Complex.ofCartesian(Double.NaN, 1);
Assert.assertFalse(Complex.equals(c, c));
- c = new Complex(1, Double.NaN);
+ c = Complex.ofCartesian(1, Double.NaN);
Assert.assertFalse(Complex.equals(c, c));
}
@@ -452,8 +452,8 @@ public class ComplexTest {
final double re = 153.0000;
final double im = 152.9375;
final double tol1 = 0.0625;
- final Complex x = new Complex(re, im);
- final Complex y = new Complex(re + tol1, im + tol1);
+ final Complex x = Complex.ofCartesian(re, im);
+ final Complex y = Complex.ofCartesian(re + tol1, im + tol1);
Assert.assertTrue(Complex.equals(x, y, tol1));
final double tol2 = 0.0624;
@@ -462,8 +462,8 @@ public class ComplexTest {
@Test
public void testFloatingPointEqualsWithAllowedDeltaNaN() {
- final Complex x = new Complex(0, Double.NaN);
- final Complex y = new Complex(Double.NaN, 0);
+ final Complex x = Complex.ofCartesian(0, Double.NaN);
+ final Complex y = Complex.ofCartesian(Double.NaN, 0);
Assert.assertFalse(Complex.equals(x, Complex.ZERO, 0.1));
Assert.assertFalse(Complex.equals(x, x, 0.1));
Assert.assertFalse(Complex.equals(x, y, 0.1));
@@ -476,15 +476,15 @@ public class ComplexTest {
final double im = 1e10;
final double f = 1 + tol;
- final Complex x = new Complex(re, im);
- final Complex y = new Complex(re * f, im * f);
+ final Complex x = Complex.ofCartesian(re, im);
+ final Complex y = Complex.ofCartesian(re * f, im * f);
Assert.assertTrue(Complex.equalsWithRelativeTolerance(x, y, tol));
}
@Test
public void testFloatingPointEqualsWithRelativeToleranceNaN() {
- final Complex x = new Complex(0, Double.NaN);
- final Complex y = new Complex(Double.NaN, 0);
+ final Complex x = Complex.ofCartesian(0, Double.NaN);
+ final Complex y = Complex.ofCartesian(Double.NaN, 0);
Assert.assertFalse(Complex.equalsWithRelativeTolerance(x, Complex.ZERO, 0.1));
Assert.assertFalse(Complex.equalsWithRelativeTolerance(x, x, 0.1));
Assert.assertFalse(Complex.equalsWithRelativeTolerance(x, y, 0.1));
@@ -492,34 +492,34 @@ public class ComplexTest {
@Test
public void testEqualsTrue() {
- Complex x = new Complex(3.0, 4.0);
- Complex y = new Complex(3.0, 4.0);
+ Complex x = Complex.ofCartesian(3.0, 4.0);
+ Complex y = Complex.ofCartesian(3.0, 4.0);
Assert.assertTrue(x.equals(y));
}
@Test
public void testEqualsRealDifference() {
- Complex x = new Complex(0.0, 0.0);
- Complex y = new Complex(0.0 + Double.MIN_VALUE, 0.0);
+ Complex x = Complex.ofCartesian(0.0, 0.0);
+ Complex y = Complex.ofCartesian(0.0 + Double.MIN_VALUE, 0.0);
Assert.assertFalse(x.equals(y));
}
@Test
public void testEqualsImaginaryDifference() {
- Complex x = new Complex(0.0, 0.0);
- Complex y = new Complex(0.0, 0.0 + Double.MIN_VALUE);
+ Complex x = Complex.ofCartesian(0.0, 0.0);
+ Complex y = Complex.ofCartesian(0.0, 0.0 + Double.MIN_VALUE);
Assert.assertFalse(x.equals(y));
}
@Test
public void testHashCode() {
- Complex x = new Complex(0.0, 0.0);
- Complex y = new Complex(0.0, 0.0 + Double.MIN_VALUE);
+ Complex x = Complex.ofCartesian(0.0, 0.0);
+ Complex y = Complex.ofCartesian(0.0, 0.0 + Double.MIN_VALUE);
Assert.assertFalse(x.hashCode()==y.hashCode());
- y = new Complex(0.0 + Double.MIN_VALUE, 0.0);
+ y = Complex.ofCartesian(0.0 + Double.MIN_VALUE, 0.0);
Assert.assertFalse(x.hashCode()==y.hashCode());
- Complex realNaN = new Complex(Double.NaN, 0.0);
- Complex imaginaryNaN = new Complex(0.0, Double.NaN);
+ Complex realNaN = Complex.ofCartesian(Double.NaN, 0.0);
+ Complex imaginaryNaN = Complex.ofCartesian(0.0, Double.NaN);
Assert.assertEquals(realNaN.hashCode(), imaginaryNaN.hashCode());
Assert.assertEquals(imaginaryNaN.hashCode(), NAN.hashCode());
@@ -528,13 +528,13 @@ public class ComplexTest {
// different hash codes, "equals" must return false.
final String msg = "'equals' not compatible with 'hashCode'";
- x = new Complex(0.0, 0.0);
- y = new Complex(0.0, -0.0);
+ x = Complex.ofCartesian(0.0, 0.0);
+ y = Complex.ofCartesian(0.0, -0.0);
Assert.assertTrue(x.hashCode() != y.hashCode());
Assert.assertFalse(msg, x.equals(y));
- x = new Complex(0.0, 0.0);
- y = new Complex(-0.0, 0.0);
+ x = Complex.ofCartesian(0.0, 0.0);
+ y = Complex.ofCartesian(-0.0, 0.0);
Assert.assertTrue(x.hashCode() != y.hashCode());
Assert.assertFalse(msg, x.equals(y));
}
@@ -570,9 +570,9 @@ public class ComplexTest {
@Test
public void testScalarPow() {
- Complex x = new Complex(3, 4);
+ Complex x = Complex.ofCartesian(3, 4);
double yDouble = 5.0;
- Complex yComplex = new Complex(yDouble);
+ Complex yComplex = Complex.ofCartesian(yDouble);
Assert.assertEquals(x.pow(yComplex), x.pow(yDouble));
}
@@ -580,15 +580,15 @@ public class ComplexTest {
public void testScalarPowNaNBase() {
Complex x = NAN;
double yDouble = 5.0;
- Complex yComplex = new Complex(yDouble);
+ Complex yComplex = Complex.ofCartesian(yDouble);
Assert.assertEquals(x.pow(yComplex), x.pow(yDouble));
}
@Test
public void testScalarPowNaNExponent() {
- Complex x = new Complex(3, 4);
+ Complex x = Complex.ofCartesian(3, 4);
double yDouble = Double.NaN;
- Complex yComplex = new Complex(yDouble);
+ Complex yComplex = Complex.ofCartesian(yDouble);
Assert.assertEquals(x.pow(yComplex), x.pow(yDouble));
}
@Test
@@ -609,8 +609,8 @@ public class ComplexTest {
@Test
public void testSqrt1z() {
- Complex z = new Complex(3, 4);
- Complex expected = new Complex(4.08033, -2.94094);
+ Complex z = Complex.ofCartesian(3, 4);
+ Complex expected = Complex.ofCartesian(4.08033, -2.94094);
TestUtils.assertEquals(expected, z.sqrt1z(), 1.0e-5);
}
@@ -633,7 +633,7 @@ public class ComplexTest {
@Test
public void testNthRoot_normal_thirdRoot() {
// The complex number we want to compute all third-roots for.
- Complex z = new Complex(-2,2);
+ Complex z = Complex.ofCartesian(-2,2);
// The List holding all third roots
Complex[] thirdRootsOfZ = z.nthRoot(3).toArray(new Complex[0]);
// Returned Collection must not be empty!
@@ -665,7 +665,7 @@ public class ComplexTest {
@Test
public void testNthRoot_normal_fourthRoot() {
// The complex number we want to compute all third-roots for.
- Complex z = new Complex(5,-2);
+ Complex z = Complex.ofCartesian(5,-2);
// The List holding all fourth roots
Complex[] fourthRootsOfZ = z.nthRoot(4).toArray(new Complex[0]);
// Returned Collection must not be empty!
@@ -699,7 +699,7 @@ public class ComplexTest {
public void testNthRoot_cornercase_thirdRoot_imaginaryPartEmpty() {
// The number 8 has three third roots. One we all already know is the number 2.
// But there are two more complex roots.
- Complex z = new Complex(8,0);
+ Complex z = Complex.ofCartesian(8,0);
// The List holding all third roots
Complex[] thirdRootsOfZ = z.nthRoot(3).toArray(new Complex[0]);
// Returned Collection must not be empty!
@@ -730,7 +730,7 @@ public class ComplexTest {
@Test
public void testNthRoot_cornercase_thirdRoot_realPartZero() {
// complex number with only imaginary part
- Complex z = new Complex(0,2);
+ Complex z = Complex.ofCartesian(0,2);
// The List holding all third roots
Complex[] thirdRootsOfZ = z.nthRoot(3).toArray(new Complex[0]);
// Returned Collection must not be empty!
@@ -751,28 +751,28 @@ public class ComplexTest {
*/
@Test
public void testGetArgument() {
- Complex z = new Complex(1, 0);
+ Complex z = Complex.ofCartesian(1, 0);
Assert.assertEquals(0.0, z.getArgument(), 1.0e-12);
- z = new Complex(1, 1);
+ z = Complex.ofCartesian(1, 1);
Assert.assertEquals(Math.PI/4, z.getArgument(), 1.0e-12);
- z = new Complex(0, 1);
+ z = Complex.ofCartesian(0, 1);
Assert.assertEquals(Math.PI/2, z.getArgument(), 1.0e-12);
- z = new Complex(-1, 1);
+ z = Complex.ofCartesian(-1, 1);
Assert.assertEquals(3 * Math.PI/4, z.getArgument(), 1.0e-12);
- z = new Complex(-1, 0);
+ z = Complex.ofCartesian(-1, 0);
Assert.assertEquals(Math.PI, z.getArgument(), 1.0e-12);
- z = new Complex(-1, -1);
+ z = Complex.ofCartesian(-1, -1);
Assert.assertEquals(-3 * Math.PI/4, z.getArgument(), 1.0e-12);
- z = new Complex(0, -1);
+ z = Complex.ofCartesian(0, -1);
Assert.assertEquals(-Math.PI/2, z.getArgument(), 1.0e-12);
- z = new Complex(1, -1);
+ z = Complex.ofCartesian(1, -1);
Assert.assertEquals(-Math.PI/4, z.getArgument(), 1.0e-12);
}
@@ -805,7 +805,7 @@ public class ComplexTest {
/*
@Test
public void testSerial() {
- Complex z = new Complex(3.0, 4.0);
+ Complex z = Complex.ofCartesian(3.0, 4.0);
Assert.assertEquals(z, TestUtils.serializeAndRecover(z));
Complex ncmplx = (Complex)TestUtils.serializeAndRecover(oneNaN); Assert.assertEquals(nanZero, ncmplx); Assert.assertTrue(ncmplx.isNaN());
Complex infcmplx = (Complex)TestUtils.serializeAndRecover(infInf);
@@ -840,10 +840,5 @@ public class ComplexTest {
this(other.getReal(), other.getImaginary());
}
- @Override
- protected TestComplex createComplex(double real, double imaginary){
- return new TestComplex(real, imaginary);
- }
-
}
}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/b8670225/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexUtilsTest.java
----------------------------------------------------------------------
diff --git a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexUtilsTest.java b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexUtilsTest.java
index 8ca143a..b57a6b1 100644
--- a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexUtilsTest.java
+++ b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexUtilsTest.java
@@ -31,12 +31,12 @@ public class ComplexUtilsTest {
private static final double nan = Double.NaN;
private static final double pi = Math.PI;
- private static final Complex negInfInf = new Complex(negInf, inf);
- private static final Complex infNegInf = new Complex(inf, negInf);
- private static final Complex infInf = new Complex(inf, inf);
- private static final Complex negInfNegInf = new Complex(negInf, negInf);
- private static final Complex infNaN = new Complex(inf, nan);
- private static final Complex NAN = new Complex(nan, nan);
+ private static final Complex negInfInf = Complex.ofCartesian(negInf, inf);
+ private static final Complex infNegInf = Complex.ofCartesian(inf, negInf);
+ private static final Complex infInf = Complex.ofCartesian(inf, inf);
+ private static final Complex negInfNegInf = Complex.ofCartesian(negInf, negInf);
+ private static final Complex infNaN = Complex.ofCartesian(inf, nan);
+ private static final Complex NAN = Complex.ofCartesian(nan, nan);
private static Complex c[]; // complex array with real values even and imag
// values odd
@@ -109,9 +109,9 @@ public class ComplexUtilsTest {
di[i + 1] = i + 1;
fi[i] = i;
fi[i + 1] = i + 1;
- c[i / 2] = new Complex(i, i + 1);
- cr[i / 2] = new Complex(i / 2);
- ci[i / 2] = new Complex(0, i / 2);
+ c[i / 2] = Complex.ofCartesian(i, i + 1);
+ cr[i / 2] = Complex.ofCartesian(i / 2);
+ ci[i / 2] = Complex.ofCartesian(0, i / 2);
sr[i / 2] = i;
si[i / 2] = i + 1;
sfr[i / 2] = i;
@@ -129,9 +129,9 @@ public class ComplexUtilsTest {
di2d[i][j + 1] = 10 * i + j + 1;
fi2d[i][j] = 10 * i + j;
fi2d[i][j + 1] = 10 * i + j + 1;
- c2d[i][j / 2] = new Complex(10 * i + j, 10 * i + j + 1);
- cr2d[i][j / 2] = new Complex(10 * i + j / 2);
- ci2d[i][j / 2] = new Complex(0, 10 * i + j / 2);
+ c2d[i][j / 2] = Complex.ofCartesian(10 * i + j, 10 * i + j + 1);
+ cr2d[i][j / 2] = Complex.ofCartesian(10 * i + j / 2);
+ ci2d[i][j / 2] = Complex.ofCartesian(0, 10 * i + j / 2);
}
}
for (int i = 0; i < 10; i++) {
@@ -147,20 +147,20 @@ public class ComplexUtilsTest {
di3d[i][j][k + 1] = 100 * i + 10 * j + k + 1;
fi3d[i][j][k] = 100 * i + 10 * j + k;
fi3d[i][j][k + 1] = 100 * i + 10 * j + k + 1;
- c3d[i][j][k / 2] = new Complex(100 * i + 10 * j + k, 100 * i + 10 * j + k + 1);
- cr3d[i][j][k / 2] = new Complex(100 * i + 10 * j + k / 2);
- ci3d[i][j][k / 2] = new Complex(0, 100 * i + 10 * j + k / 2);
+ c3d[i][j][k / 2] = Complex.ofCartesian(100 * i + 10 * j + k, 100 * i + 10 * j + k + 1);
+ cr3d[i][j][k / 2] = Complex.ofCartesian(100 * i + 10 * j + k / 2);
+ ci3d[i][j][k / 2] = Complex.ofCartesian(0, 100 * i + 10 * j + k / 2);
}
}
}
- ansArrayc1r = new Complex[] { new Complex(3), new Complex(4), new Complex(5), new Complex(6), new Complex(7) };
- ansArrayc2r = new Complex[] { new Complex(3), new Complex(5), new Complex(7) };
- ansArrayc1i = new Complex[] { new Complex(0, 3), new Complex(0, 4), new Complex(0, 5), new Complex(0, 6),
- new Complex(0, 7) };
- ansArrayc2i = new Complex[] { new Complex(0, 3), new Complex(0, 5), new Complex(0, 7) };
- ansArrayc3 = new Complex[] { new Complex(6, 7), new Complex(8, 9), new Complex(10, 11), new Complex(12, 13),
- new Complex(14, 15) };
- ansArrayc4 = new Complex[] { new Complex(6, 7), new Complex(10, 11), new Complex(14, 15) };
+ ansArrayc1r = new Complex[] { Complex.ofCartesian(3), Complex.ofCartesian(4), Complex.ofCartesian(5), Complex.ofCartesian(6), Complex.ofCartesian(7) };
+ ansArrayc2r = new Complex[] { Complex.ofCartesian(3), Complex.ofCartesian(5), Complex.ofCartesian(7) };
+ ansArrayc1i = new Complex[] { Complex.ofCartesian(0, 3), Complex.ofCartesian(0, 4), Complex.ofCartesian(0, 5), Complex.ofCartesian(0, 6),
+ Complex.ofCartesian(0, 7) };
+ ansArrayc2i = new Complex[] { Complex.ofCartesian(0, 3), Complex.ofCartesian(0, 5), Complex.ofCartesian(0, 7) };
+ ansArrayc3 = new Complex[] { Complex.ofCartesian(6, 7), Complex.ofCartesian(8, 9), Complex.ofCartesian(10, 11), Complex.ofCartesian(12, 13),
+ Complex.ofCartesian(14, 15) };
+ ansArrayc4 = new Complex[] { Complex.ofCartesian(6, 7), Complex.ofCartesian(10, 11), Complex.ofCartesian(14, 15) };
ansArrayd1r = new double[] { 6, 8, 10, 12, 14 };
ansArrayd1i = new double[] { 7, 9, 11, 13, 15 };
ansArrayd2r = new double[] { 6, 10, 14 };
@@ -200,7 +200,7 @@ public class ComplexUtilsTest {
}
protected Complex altPolar(double r, double theta) {
- return Complex.I.multiply(new Complex(theta, 0)).exp().multiply(new Complex(r, 0));
+ return Complex.I.multiply(Complex.ofCartesian(theta, 0)).exp().multiply(Complex.ofCartesian(r, 0));
}
@Test(expected = IllegalArgumentException.class)
@@ -244,17 +244,17 @@ public class ComplexUtilsTest {
public void testExtractionMethods() {
setArrays();
// Extract complex from real double array, index 3
- TestUtils.assertSame(new Complex(3), ComplexUtils.extractComplexFromRealArray(d, 3));
+ TestUtils.assertSame(Complex.ofCartesian(3), ComplexUtils.extractComplexFromRealArray(d, 3));
// Extract complex from real float array, index 3
- TestUtils.assertSame(new Complex(3), ComplexUtils.extractComplexFromRealArray(f, 3));
+ TestUtils.assertSame(Complex.ofCartesian(3), ComplexUtils.extractComplexFromRealArray(f, 3));
// Extract real double from complex array, index 3
TestUtils.assertSame(6, ComplexUtils.extractRealFromComplexArray(c, 3));
// Extract real float from complex array, index 3
TestUtils.assertSame(6, ComplexUtils.extractRealFloatFromComplexArray(c, 3));
// Extract complex from interleaved double array, index 3
- TestUtils.assertSame(new Complex(6, 7), ComplexUtils.extractComplexFromInterleavedArray(d, 3));
+ TestUtils.assertSame(Complex.ofCartesian(6, 7), ComplexUtils.extractComplexFromInterleavedArray(d, 3));
// Extract complex from interleaved float array, index 3
- TestUtils.assertSame(new Complex(6, 7), ComplexUtils.extractComplexFromInterleavedArray(f, 3));
+ TestUtils.assertSame(Complex.ofCartesian(6, 7), ComplexUtils.extractComplexFromInterleavedArray(f, 3));
// Extract interleaved double from complex array, index 3
TestUtils.assertEquals(msg, new double[] { 6, 7 }, ComplexUtils.extractInterleavedFromComplexArray(c, 3),
Math.ulp(1));
@@ -470,7 +470,7 @@ public class ComplexUtilsTest {
Complex[] c = new Complex[10];
ComplexUtils.initialize(c);
for (Complex cc : c) {
- TestUtils.assertEquals(new Complex(0, 0), cc, Math.ulp(0));
+ TestUtils.assertEquals(Complex.ofCartesian(0, 0), cc, Math.ulp(0));
}
}
}