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/09 00:03:38 UTC
[commons-numbers] branch master updated (f621118 -> 9b1b887)
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 f621118 Remove unnecessary deltas from assertions.
new 8edcaec Remove getArgument and getAbsolute.
new 2753fa0 Document odd and even functions.
new 08465eb Removed mirrored cases for odd/even functions.
new c4648b9 Remove the edge cases for overflow.
new 0cfc94d Compute extreme values of sqrt() in polar coordinates.
new c897177 Use final
new f3c6b06 Avoid reassigning params
new 5db7d73 Remove unused private methods
new 9b1b887 Added TODO notes on special case for imaginary only numbers.
The 9 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 | 206 ++++++++-------
.../commons/numbers/complex/CReferenceTest.java | 287 ++-------------------
.../commons/numbers/complex/ComplexTest.java | 26 +-
3 files changed, 130 insertions(+), 389 deletions(-)
[commons-numbers] 07/09: Avoid reassigning params
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 f3c6b06cb53428a520ddd493b4709ca0946ab913
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sun Dec 8 23:42:27 2019 +0000
Avoid reassigning params
---
.../apache/commons/numbers/complex/Complex.java | 56 ++++++++++++++--------
1 file changed, 36 insertions(+), 20 deletions(-)
diff --git a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
index 3b48bdb..6530e00 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
@@ -410,14 +410,18 @@ public final class Complex implements Serializable {
* standard G.5.1. Method is fully in accordance with
* C++11 standards for complex numbers.</p>
*
- * @param a Real component of first number.
- * @param b Imaginary component of first number.
- * @param c Real component of second number.
- * @param d Imaginary component of second number.
+ * @param re1 Real component of first number.
+ * @param im1 Imaginary component of first number.
+ * @param re2 Real component of second number.
+ * @param im2 Imaginary component of second number.
* @return (a + b i) / (c + d i).
* @see <a href="http://mathworld.wolfram.com/ComplexDivision.html">Complex Division</a>
*/
- private static Complex divide(double a, double b, double c, double d) {
+ private static Complex divide(double re1, double im1, double re2, double im2) {
+ double a = re1;
+ double b = im1;
+ double c = re2;
+ double d = im2;
int ilogbw = 0;
final double logbw = Math.log(Math.max(Math.abs(c), Math.abs(d))) / Math.log(2);
if (Double.isFinite(logbw)) {
@@ -775,13 +779,17 @@ public final class Complex implements Serializable {
* standard G.5.1. Method is fully in accordance with
* C++11 standards for complex numbers.</p>
*
- * @param a Real component of first number.
- * @param b Imaginary component of first number.
- * @param c Real component of second number.
- * @param d Imaginary component of second number.
+ * @param re1 Real component of first number.
+ * @param im1 Imaginary component of first number.
+ * @param re2 Real component of second number.
+ * @param im2 Imaginary component of second number.
* @return (a + b i)(c + d i).
*/
- private static Complex multiply(double a, double b, double c, double d) {
+ private static Complex multiply(double re1, double im1, double re2, double im2) {
+ double a = re1;
+ double b = im1;
+ double c = re2;
+ double d = im2;
final double ac = a * c;
final double bd = b * d;
final double ad = a * d;
@@ -1373,15 +1381,20 @@ 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
+ // ISO C99: Preserve the even function by mapping to positive
// f(z) = f(-z)
+ double re;
+ double im;
if (negative(real)) {
- real = -real;
- imaginary = -imaginary;
+ re = -real;
+ im = -imaginary;
+ } else {
+ re = real;
+ im = imaginary;
}
// Special case for real == 0
- final double im = real == 0 ? Math.copySign(0, imaginary) : Double.NaN;
- return constructor.create(Double.NaN, im);
+ return constructor.create(Double.NaN,
+ re == 0 ? Math.copySign(0, im) : Double.NaN);
}
if (Double.isInfinite(real)) {
if (Double.isFinite(imaginary)) {
@@ -1393,13 +1406,16 @@ public final class Complex implements Serializable {
// inf * cis(y)
// ISO C99: Preserve the even function
// f(z) = f(-z)
+ double re;
+ double im;
if (real < 0) {
- real = -real;
- imaginary = -imaginary;
+ re = -real;
+ im = -imaginary;
+ } else {
+ re = real;
+ im = imaginary;
}
- final double re = real * Math.cos(imaginary);
- final double im = real * Math.sin(imaginary);
- return constructor.create(re, im);
+ return constructor.create(re * Math.cos(im), re * Math.sin(im));
}
// imaginary is infinite or NaN
return constructor.create(Double.POSITIVE_INFINITY, Double.NaN);
[commons-numbers] 05/09: Compute extreme values of sqrt() in polar
coordinates.
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 0cfc94de303b6cc56c3dbc6157db8d70bfa8c975
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sun Dec 8 23:18:40 2019 +0000
Compute extreme values of sqrt() in polar coordinates.
---
.../apache/commons/numbers/complex/Complex.java | 22 ++++++++++++++++------
.../commons/numbers/complex/CReferenceTest.java | 12 +++++++++++-
2 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
index 2d88c2f..9f9ac9e 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
@@ -1711,13 +1711,23 @@ public final class Complex implements Serializable {
if (real == 0 && imaginary == 0) {
return new Complex(0, imaginary);
}
- final double t = Math.sqrt(average(Math.abs(real), Math.hypot(real, imaginary)));
- // t is positive:
- // To prevent overflow dividing by (2 * t) divide by t then by 2.
+ final double abs = getAbsolute(real, imaginary);
+ final double av = average(Math.abs(real), abs);
+ if (av == Double.POSITIVE_INFINITY) {
+ // Compute in polar coords.
+ // This handles extreme values that fail in the cartesian representation.
+ final double sqrtAbs = Math.sqrt(abs);
+ final double halfArg = getArgument(real, imaginary) / 2;
+ final double re = sqrtAbs * Math.cos(halfArg);
+ final double im = sqrtAbs * Math.sin(halfArg);
+ return new Complex(re, im);
+ }
+
+ final double t = Math.sqrt(av);
if (real >= 0) {
- return new Complex(t, (imaginary / t) / 2);
+ return new Complex(t, imaginary / (2 * t));
}
- return new Complex((Math.abs(imaginary) / t) / 2,
+ return new Complex(Math.abs(imaginary) / (2 * t),
Math.copySign(1.0, imaginary) * t);
}
// Imaginary is nan
@@ -1744,7 +1754,7 @@ public final class Complex implements Serializable {
* @return the average
*/
private static double average(double a, double b) {
- return (b < a) ?
+ return (a < b) ?
a + (b - a) / 2 :
b + (a - b) / 2;
}
diff --git a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CReferenceTest.java b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CReferenceTest.java
index 2dbf394..22b8cf2 100644
--- a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CReferenceTest.java
+++ b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CReferenceTest.java
@@ -399,18 +399,28 @@ public class CReferenceTest {
@Test
public void testSqrt() {
+ // TODO: GNU g++ computes in polar coordinates.
+ // Test other reference implementations.
+ // This gives strange results for real negative and imaginary 0.
+
+ // Polar result
+ //assertComplex(-2, 0.0, Complex::sqrt, 8.6595605623549341e-17, 1.4142135623730951);
assertComplex(-2, 0.0, Complex::sqrt, 0, 1.4142135623730951);
assertComplex(-2, 0.5, Complex::sqrt, 0.17543205637629397, 1.425053124063947, 5);
assertComplex(-2, 1, Complex::sqrt, 0.3435607497225126, 1.4553466902253549, 3);
assertComplex(-2, 2, Complex::sqrt, 0.64359425290558281, 1.5537739740300374, 2);
+ // Polar result
+ //assertComplex(-1, 0.0, Complex::sqrt, 6.123233995736766e-17, 1);
assertComplex(-1, 0.0, Complex::sqrt, 0, 1);
assertComplex(-1, 0.5, Complex::sqrt, 0.24293413587832291, 1.0290855136357462, 3);
assertComplex(-1, 1, Complex::sqrt, 0.45508986056222739, 1.0986841134678098);
assertComplex(-1, 2, Complex::sqrt, 0.78615137775742339, 1.2720196495140688);
+ // Polar result
+ //assertComplex(-0.5, 0.0, Complex::sqrt, 4.329780281177467e-17, 0.70710678118654757);
assertComplex(-0.5, 0.0, Complex::sqrt, 0, 0.70710678118654757);
assertComplex(-0.5, 0.5, Complex::sqrt, 0.3217971264527914, 0.77688698701501868, 2);
assertComplex(-0.5, 1, Complex::sqrt, 0.55589297025142126, 0.89945371997393353);
- assertComplex(-0.5, 2, Complex::sqrt, 0.88361553087551337, 1.1317139242778693);
+ assertComplex(-0.5, 2, Complex::sqrt, 0.88361553087551337, 1.1317139242778693, 2);
assertComplex(-0.0, 0.0, Complex::sqrt, 0.0, 0.0);
assertComplex(-0.0, 0.5, Complex::sqrt, 0.50000000000000011, 0.5);
assertComplex(-0.0, 1, Complex::sqrt, 0.70710678118654757, 0.70710678118654746);
[commons-numbers] 04/09: Remove the edge cases for overflow.
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 c4648b9eaa314b453b0d95809626a32cedd8390d
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sun Dec 8 21:12:08 2019 +0000
Remove the edge cases for overflow.
These should be better constructed based on the formula that is
implemented in terms of overflow/underflow of parts of the computation.
---
.../commons/numbers/complex/CReferenceTest.java | 155 +--------------------
1 file changed, 5 insertions(+), 150 deletions(-)
diff --git a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CReferenceTest.java b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CReferenceTest.java
index a5f0454..2dbf394 100644
--- a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CReferenceTest.java
+++ b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CReferenceTest.java
@@ -148,434 +148,289 @@ public class CReferenceTest {
assertEquals(() -> c1 + " op " + c2 + ": imaginary", y, z.getImaginary(), maxUlps);
}
- // Fix:
- // acos
- // acosh
- // asinh
- // Q. Are these the function in boost?
-
@Test
public void testAcos() {
-// assertComplex(-1e+308, 0.0, Complex::acos, nan, -inf);
-// assertComplex(-1e+308, 0.5, Complex::acos, 0.78539816339744828, -inf);
-// assertComplex(-1e+308, 1, Complex::acos, 0.78539816339744828, -inf);
-// assertComplex(-1e+308, 2, Complex::acos, 0.78539816339744828, -inf);
- assertComplex(-1e+308, 1e+308, Complex::acos, 0.78539816339744828, -inf);
assertComplex(-2, 0.0, Complex::acos, 3.1415926535897931, -1.3169578969248164);
assertComplex(-2, 0.5, Complex::acos, 2.8638383970320791, -1.3618009008578467, 3);
assertComplex(-2, 1, Complex::acos, 2.6342363503726487, -1.4693517443681854);
assertComplex(-2, 2, Complex::acos, 2.3250454714929427, -1.7343245214879679);
- assertComplex(-2, 1e+308, Complex::acos, 0.78539816339744828, -inf);
assertComplex(-1, 0.0, Complex::acos, 3.1415926535897931, -0.0);
assertComplex(-1, 0.5, Complex::acos, 2.4667038080037869, -0.73285767597364526);
assertComplex(-1, 1, Complex::acos, 2.2370357592874122, -1.0612750619050364, 4);
assertComplex(-1, 2, Complex::acos, 1.997874913187373, -1.5285709194809995, 9);
- assertComplex(-1, 1e+308, Complex::acos, 0.78539816339744828, -inf);
assertComplex(-0.5, 0.0, Complex::acos, 2.0943951023931953, -1.1102230246251565e-16);
assertComplex(-0.5, 0.5, Complex::acos, 2.023074773946087, -0.53063753095251776);
assertComplex(-0.5, 1, Complex::acos, 1.9202353896521094, -0.92613303135018232, 2);
assertComplex(-0.5, 2, Complex::acos, 1.7918149624177808, -1.4657153519472903, 2);
- assertComplex(-0.5, 1e+308, Complex::acos, 1.5707963267948966, -inf);
assertComplex(-0.0, 0.0, Complex::acos, 1.5707963267948966, -0.0);
assertComplex(-0.0, 0.5, Complex::acos, 1.5707963267948966, -0.48121182505960336);
assertComplex(-0.0, 1, Complex::acos, 1.5707963267948963, -0.88137358701954283);
assertComplex(-0.0, 2, Complex::acos, 1.5707963267948959, -1.4436354751788099, 3);
- assertComplex(-0.0, 1e+308, Complex::acos, 1.5707963267948966, -inf);
assertComplex(0.0, 0.0, Complex::acos, 1.5707963267948966, -0.0);
assertComplex(0.0, 0.5, Complex::acos, 1.5707963267948966, -0.48121182505960347, 2);
assertComplex(0.0, 1, Complex::acos, 1.5707963267948966, -0.88137358701954294);
assertComplex(0.0, 2, Complex::acos, 1.5707963267948966, -1.4436354751788103, 2);
- assertComplex(0.0, 1e+308, Complex::acos, 1.5707963267948966, -inf);
assertComplex(0.5, 0.0, Complex::acos, 1.0471975511965976, -1.1102230246251565e-16);
assertComplex(0.5, 0.5, Complex::acos, 1.1185178796437059, -0.53063753095251787);
assertComplex(0.5, 1, Complex::acos, 1.2213572639376833, -0.92613303135018255, 2);
assertComplex(0.5, 2, Complex::acos, 1.3497776911720127, -1.4657153519472905);
- assertComplex(0.5, 1e+308, Complex::acos, 1.5707963267948966, -inf);
assertComplex(1, 0.0, Complex::acos, 0.0, -0.0);
assertComplex(1, 0.5, Complex::acos, 0.67488884558600637, -0.73285767597364526);
assertComplex(1, 1, Complex::acos, 0.90455689430238129, -1.0612750619050355);
assertComplex(1, 2, Complex::acos, 1.1437177404024204, -1.528570919480998, 2);
-// assertComplex(1, 1e+308, Complex::acos, 0.78539816339744828, -inf);
assertComplex(2, 0.0, Complex::acos, 0.0, -1.3169578969248166);
assertComplex(2, 0.5, Complex::acos, 0.27775425655771396, -1.3618009008578458);
assertComplex(2, 1, Complex::acos, 0.50735630321714453, -1.4693517443681852);
assertComplex(2, 2, Complex::acos, 0.8165471820968504, -1.7343245214879663, 7);
-// assertComplex(2, 1e+308, Complex::acos, 0.78539816339744828, -inf);
-// assertComplex(1e+308, 0.0, Complex::acos, nan, -inf);
-// assertComplex(1e+308, 0.5, Complex::acos, 0.78539816339744828, -inf);
-// assertComplex(1e+308, 1, Complex::acos, 0.78539816339744828, -inf);
-// assertComplex(1e+308, 2, Complex::acos, 0.78539816339744828, -inf);
-// assertComplex(1e+308, 1e+308, Complex::acos, 0.78539816339744828, -inf);
}
@Test
public void testAcosh() {
-// assertComplex(-1e+308, 0.0, Complex::acosh, inf, nan);
-// assertComplex(-1e+308, 0.5, Complex::acosh, inf, 0.78539816339744828);
-// assertComplex(-1e+308, 1, Complex::acosh, inf, 0.78539816339744828);
-// assertComplex(-1e+308, 2, Complex::acosh, inf, 0.78539816339744828);
- assertComplex(-1e+308, 1e+308, Complex::acosh, inf, 0.78539816339744828);
assertComplex(-2, 0.0, Complex::acosh, 1.3169578969248164, 3.1415926535897931);
assertComplex(-2, 0.5, Complex::acosh, 1.3618009008578467, 2.8638383970320791, 3);
assertComplex(-2, 1, Complex::acosh, 1.4693517443681854, 2.6342363503726487);
assertComplex(-2, 2, Complex::acosh, 1.7343245214879679, 2.3250454714929427);
- assertComplex(-2, 1e+308, Complex::acosh, inf, 0.78539816339744828);
assertComplex(-1, 0.0, Complex::acosh, 0.0, 3.1415926535897931);
assertComplex(-1, 0.5, Complex::acosh, 0.73285767597364526, 2.4667038080037869);
assertComplex(-1, 1, Complex::acosh, 1.0612750619050364, 2.2370357592874122, 4);
assertComplex(-1, 2, Complex::acosh, 1.5285709194809995, 1.997874913187373, 9);
- assertComplex(-1, 1e+308, Complex::acosh, inf, 0.78539816339744828);
assertComplex(-0.5, 0.0, Complex::acosh, 1.1102230246251565e-16, 2.0943951023931953);
assertComplex(-0.5, 0.5, Complex::acosh, 0.53063753095251776, 2.023074773946087);
assertComplex(-0.5, 1, Complex::acosh, 0.92613303135018232, 1.9202353896521094, 2);
assertComplex(-0.5, 2, Complex::acosh, 1.4657153519472903, 1.7918149624177808, 2);
- assertComplex(-0.5, 1e+308, Complex::acosh, inf, 1.5707963267948966);
assertComplex(-0.0, 0.0, Complex::acosh, 0.0, 1.5707963267948966);
assertComplex(-0.0, 0.5, Complex::acosh, 0.48121182505960336, 1.5707963267948966);
assertComplex(-0.0, 1, Complex::acosh, 0.88137358701954283, 1.5707963267948963);
assertComplex(-0.0, 2, Complex::acosh, 1.4436354751788099, 1.5707963267948959, 3);
- assertComplex(-0.0, 1e+308, Complex::acosh, inf, 1.5707963267948966);
assertComplex(0.0, 0.0, Complex::acosh, 0.0, 1.5707963267948966);
assertComplex(0.0, 0.5, Complex::acosh, 0.48121182505960347, 1.5707963267948966, 2);
assertComplex(0.0, 1, Complex::acosh, 0.88137358701954294, 1.5707963267948966);
assertComplex(0.0, 2, Complex::acosh, 1.4436354751788103, 1.5707963267948966, 2);
- assertComplex(0.0, 1e+308, Complex::acosh, inf, 1.5707963267948966);
assertComplex(0.5, 0.0, Complex::acosh, 1.1102230246251565e-16, 1.0471975511965976);
assertComplex(0.5, 0.5, Complex::acosh, 0.53063753095251787, 1.1185178796437059);
assertComplex(0.5, 1, Complex::acosh, 0.92613303135018255, 1.2213572639376833, 2);
assertComplex(0.5, 2, Complex::acosh, 1.4657153519472905, 1.3497776911720127);
- assertComplex(0.5, 1e+308, Complex::acosh, inf, 1.5707963267948966);
assertComplex(1, 0.0, Complex::acosh, 0.0, 0.0);
assertComplex(1, 0.5, Complex::acosh, 0.73285767597364526, 0.67488884558600637);
assertComplex(1, 1, Complex::acosh, 1.0612750619050355, 0.90455689430238129);
assertComplex(1, 2, Complex::acosh, 1.528570919480998, 1.1437177404024204, 2);
-// assertComplex(1, 1e+308, Complex::acosh, inf, 0.78539816339744828);
assertComplex(2, 0.0, Complex::acosh, 1.3169578969248166, 0.0);
assertComplex(2, 0.5, Complex::acosh, 1.3618009008578458, 0.27775425655771396);
assertComplex(2, 1, Complex::acosh, 1.4693517443681852, 0.50735630321714453, 7);
assertComplex(2, 2, Complex::acosh, 1.7343245214879663, 0.8165471820968504, 7);
-// assertComplex(1e+308, 0.0, Complex::acosh, inf, nan);
-// assertComplex(1e+308, 0.5, Complex::acosh, inf, 0.78539816339744828);
-// assertComplex(1e+308, 1, Complex::acosh, inf, 0.78539816339744828);
-// assertComplex(1e+308, 2, Complex::acosh, inf, 0.78539816339744828);
-// assertComplex(1e+308, 1e+308, Complex::acosh, inf, 0.78539816339744828);
}
@Test
public void testAsinh() {
- // Odd function: negative real cases defined by positive real cases
+ // Odd function: negative real cases defined by positive real cases
assertComplex(0.0, 0.0, Complex::asinh, 0.0, 0.0);
assertComplex(0.0, 0.5, Complex::asinh, 1.1102230246251565e-16, 0.52359877559829893);
assertComplex(0.0, 1, Complex::asinh, 0.0, 1.5707963267948966);
assertComplex(0.0, 2, Complex::asinh, 1.3169578969248166, 1.5707963267948966);
- assertComplex(0.0, 1e+308, Complex::asinh, inf, 1.5707963267948966);
assertComplex(0.5, 0.0, Complex::asinh, 0.48121182505960347, 0.0);
assertComplex(0.5, 0.5, Complex::asinh, 0.53063753095251787, 0.45227844715119064);
assertComplex(0.5, 1, Complex::asinh, 0.73285767597364526, 0.8959074812088903);
assertComplex(0.5, 2, Complex::asinh, 1.3618009008578458, 1.2930420702371828);
- assertComplex(0.5, 1e+308, Complex::asinh, inf, 1.5707963267948966);
assertComplex(1, 0.0, Complex::asinh, 0.88137358701954294, 0.0);
assertComplex(1, 0.5, Complex::asinh, 0.92613303135018255, 0.34943906285721327);
assertComplex(1, 1, Complex::asinh, 1.0612750619050357, 0.66623943249251527);
assertComplex(1, 2, Complex::asinh, 1.4693517443681852, 1.0634400235777519);
- assertComplex(1, 1e+308, Complex::asinh, inf, 0.78539816339744828);
assertComplex(2, 0.0, Complex::asinh, 1.4436354751788103, 0.0);
assertComplex(2, 0.5, Complex::asinh, 1.4657153519472905, 0.22101863562288387);
assertComplex(2, 1, Complex::asinh, 1.528570919480998, 0.42707858639247614);
assertComplex(2, 2, Complex::asinh, 1.7343245214879663, 0.75424914469804605);
- assertComplex(2, 1e+308, Complex::asinh, inf, 0.78539816339744828);
-// assertComplex(1e+308, 0.0, Complex::asinh, inf, nan);
-// assertComplex(1e+308, 0.5, Complex::asinh, inf, 0.78539816339744828);
-// assertComplex(1e+308, 1, Complex::asinh, inf, 0.78539816339744828);
-// assertComplex(1e+308, 2, Complex::asinh, inf, 0.78539816339744828);
- assertComplex(1e+308, 1e+308, Complex::asinh, inf, 0.78539816339744828);
}
@Test
public void testAtanh() {
- // Odd function: negative real cases defined by positive real cases
+ // Odd function: negative real cases defined by positive real cases
assertComplex(0.0, 0.0, Complex::atanh, 0.0, 0.0);
assertComplex(0.0, 0.5, Complex::atanh, 0.0, 0.46364760900080615);
assertComplex(0.0, 1, Complex::atanh, 0.0, 0.78539816339744828);
assertComplex(0.0, 2, Complex::atanh, 0.0, 1.1071487177940904);
- assertComplex(0.0, 1e+308, Complex::atanh, 0.0, 1.5707963267948966);
assertComplex(0.5, 0.0, Complex::atanh, 0.54930614433405489, 0.0);
assertComplex(0.5, 0.5, Complex::atanh, 0.40235947810852513, 0.5535743588970452);
assertComplex(0.5, 1, Complex::atanh, 0.23887786125685911, 0.84757566067082901);
assertComplex(0.5, 2, Complex::atanh, 0.096415620202996211, 1.1265564408348223, 7);
- assertComplex(0.5, 1e+308, Complex::atanh, 0.0, 1.5707963267948966);
assertComplex(1, 0.0, Complex::atanh, inf, 0.0);
assertComplex(1, 0.5, Complex::atanh, 0.70830333601405404, 0.90788749496088039);
assertComplex(1, 1, Complex::atanh, 0.40235947810852513, 1.0172219678978514);
assertComplex(1, 2, Complex::atanh, 0.17328679513998635, 1.1780972450961724);
- assertComplex(1, 1e+308, Complex::atanh, 0.0, 1.5707963267948966);
assertComplex(2, 0.0, Complex::atanh, 0.54930614433405489, 1.5707963267948966);
assertComplex(2, 0.5, Complex::atanh, 0.50037000005253096, 1.4215468610018069);
assertComplex(2, 1, Complex::atanh, 0.40235947810852513, 1.3389725222944935);
assertComplex(2, 2, Complex::atanh, 0.23887786125685906, 1.311223269671635);
- assertComplex(2, 1e+308, Complex::atanh, 0.0, 1.5707963267948966);
- assertComplex(1e+308, 0.0, Complex::atanh, 0.0, 1.5707963267948966);
- assertComplex(1e+308, 0.5, Complex::atanh, 0.0, 1.5707963267948966);
- assertComplex(1e+308, 1, Complex::atanh, 0.0, 1.5707963267948966);
- assertComplex(1e+308, 2, Complex::atanh, 0.0, 1.5707963267948966);
- assertComplex(1e+308, 1e+308, Complex::atanh, inf, 1.5707963267948966);
}
@Test
public void testCosh() {
- // Even function: negative real cases defined by positive real cases
+ // Even function: negative real cases defined by positive real cases
assertComplex(0.0, 0.0, Complex::cosh, 1, 0.0);
assertComplex(0.0, 0.5, Complex::cosh, 0.87758256189037276, 0.0);
assertComplex(0.0, 1, Complex::cosh, 0.54030230586813977, 0.0);
assertComplex(0.0, 2, Complex::cosh, -0.41614683654714241, 0.0);
- assertComplex(0.0, 1e+308, Complex::cosh, -0.89130893768703345, 0.0);
assertComplex(0.5, 0.0, Complex::cosh, 1.1276259652063807, 0.0);
assertComplex(0.5, 0.5, Complex::cosh, 0.9895848833999199, 0.24982639750046154);
assertComplex(0.5, 1, Complex::cosh, 0.60925890915779424, 0.43848657989259532);
assertComplex(0.5, 2, Complex::cosh, -0.46925797822905341, 0.473830620416407);
- assertComplex(0.5, 1e+308, Complex::cosh, -1.0050631011564148, 0.23626278272774978);
assertComplex(1, 0.0, Complex::cosh, 1.5430806348152437, 0.0);
assertComplex(1, 0.5, Complex::cosh, 1.3541806567045842, 0.5634214652309818);
assertComplex(1, 1, Complex::cosh, 0.83373002513114913, 0.98889770576286506);
assertComplex(1, 2, Complex::cosh, -0.64214812471551996, 1.0686074213827783);
- assertComplex(1, 1e+308, Complex::cosh, -1.375361561382608, 0.5328320968314485);
assertComplex(2, 0.0, Complex::cosh, 3.7621956910836314, 0.0);
assertComplex(2, 0.5, Complex::cosh, 3.3016373329140944, 1.7388095044743164);
assertComplex(2, 1, Complex::cosh, 2.0327230070196656, 3.0518977991517997);
assertComplex(2, 2, Complex::cosh, -1.5656258353157435, 3.2978948363112366);
- assertComplex(2, 1e+308, Complex::cosh, -3.3532786447904863, 1.6444057804572179);
- assertComplex(1e+308, 0.0, Complex::cosh, inf, nan);
- assertComplex(1e+308, 0.5, Complex::cosh, inf, inf);
- assertComplex(1e+308, 1, Complex::cosh, inf, inf);
- assertComplex(1e+308, 2, Complex::cosh, -inf, inf);
- assertComplex(1e+308, 1e+308, Complex::cosh, -inf, inf);
}
@Test
public void testSinh() {
- // Odd function: negative real cases defined by positive real cases
+ // Odd function: negative real cases defined by positive real cases
assertComplex(0.0, 0.0, Complex::sinh, 0.0, 0.0);
assertComplex(0.0, 0.5, Complex::sinh, 0.0, 0.47942553860420301);
assertComplex(0.0, 1, Complex::sinh, 0.0, 0.8414709848078965);
assertComplex(0.0, 2, Complex::sinh, -0.0, 0.90929742682568171);
- assertComplex(0.0, 1e+308, Complex::sinh, -0.0, 0.4533964905016491);
assertComplex(0.5, 0.0, Complex::sinh, 0.52109530549374738, 0.0);
assertComplex(0.5, 0.5, Complex::sinh, 0.45730415318424927, 0.54061268571315335);
assertComplex(0.5, 1, Complex::sinh, 0.28154899513533443, 0.94886453143716798);
assertComplex(0.5, 2, Complex::sinh, -0.21685216292078974, 1.0253473885839877);
- assertComplex(0.5, 1e+308, Complex::sinh, -0.46445690317333216, 0.51126165522310774);
assertComplex(1, 0.0, Complex::sinh, 1.1752011936438014, 0.0);
assertComplex(1, 0.5, Complex::sinh, 1.0313360742545512, 0.73979226445601376);
assertComplex(1, 1, Complex::sinh, 0.63496391478473613, 1.2984575814159773);
assertComplex(1, 2, Complex::sinh, -0.48905625904129368, 1.4031192506220405);
- assertComplex(1, 1e+308, Complex::sinh, -1.0474673274751902, 0.69962734438628826);
assertComplex(2, 0.0, Complex::sinh, 3.6268604078470186, 0.0);
assertComplex(2, 0.5, Complex::sinh, 3.1828694483371489, 1.8036926955321817);
assertComplex(2, 1, Complex::sinh, 1.9596010414216061, 3.1657785132161682);
assertComplex(2, 2, Complex::sinh, -1.5093064853236156, 3.4209548611170133);
- assertComplex(2, 1e+308, Complex::sinh, -3.2326530972572871, 1.7057663229177449);
- assertComplex(1e+308, 0.0, Complex::sinh, inf, nan);
- assertComplex(1e+308, 0.5, Complex::sinh, inf, inf);
- assertComplex(1e+308, 1, Complex::sinh, inf, inf);
- assertComplex(1e+308, 2, Complex::sinh, -inf, inf);
- assertComplex(1e+308, 1e+308, Complex::sinh, -inf, inf);
}
@Test
public void testTanh() {
- // Odd function: negative real cases defined by positive real cases
+ // Odd function: negative real cases defined by positive real cases
assertComplex(0.0, 0.0, Complex::tanh, 0.0, 0.0);
assertComplex(0.0, 0.5, Complex::tanh, 0.0, 0.54630248984379048);
assertComplex(0.0, 1, Complex::tanh, 0.0, 1.5574077246549021);
assertComplex(0.0, 2, Complex::tanh, 0.0, -2.1850398632615189);
- assertComplex(0.0, 1e+308, Complex::tanh, nan, nan);
assertComplex(0.5, 0.0, Complex::tanh, 0.46211715726000974, 0.0);
assertComplex(0.5, 0.5, Complex::tanh, 0.56408314126749848, 0.40389645531602575, 2);
assertComplex(0.5, 1, Complex::tanh, 1.042830728344361, 0.80687741216308495);
assertComplex(0.5, 2, Complex::tanh, 1.3212865837711918, -0.85087812114493777, 2);
- assertComplex(0.5, 1e+308, Complex::tanh, nan, nan);
assertComplex(1, 0.0, Complex::tanh, 0.76159415595576485, 0.0);
assertComplex(1, 0.5, Complex::tanh, 0.84296620484578311, 0.19557731006593398);
assertComplex(1, 1, Complex::tanh, 1.0839233273386946, 0.27175258531951174);
assertComplex(1, 2, Complex::tanh, 1.1667362572409199, -0.24345820118572523);
- assertComplex(1, 1e+308, Complex::tanh, nan, nan);
assertComplex(2, 0.0, Complex::tanh, 0.9640275800758169, 0.0);
assertComplex(2, 0.5, Complex::tanh, 0.97994084996173814, 0.030215987322877575);
assertComplex(2, 1, Complex::tanh, 1.0147936161466335, 0.033812826079896691);
assertComplex(2, 2, Complex::tanh, 1.0238355945704727, -0.028392952868232287);
- assertComplex(2, 1e+308, Complex::tanh, nan, nan);
- assertComplex(1e+308, 0.0, Complex::tanh, 1, -0.0);
- assertComplex(1e+308, 0.5, Complex::tanh, 1, 0.0);
- assertComplex(1e+308, 1, Complex::tanh, 1, 0.0);
- assertComplex(1e+308, 2, Complex::tanh, 1, 0.0);
- assertComplex(1e+308, 1e+308, Complex::tanh, nan, nan);
}
@Test
public void testExp() {
- assertComplex(-1e+308, 0.0, Complex::exp, 0.0, 0.0);
- assertComplex(-1e+308, 0.5, Complex::exp, 0.0, 0.0);
- assertComplex(-1e+308, 1, Complex::exp, 0.0, 0.0);
- assertComplex(-1e+308, 2, Complex::exp, -0.0, 0.0);
- assertComplex(-1e+308, 1e+308, Complex::exp, -0.0, 0.0);
assertComplex(-2, 0.0, Complex::exp, 0.1353352832366127, 0.0);
assertComplex(-2, 0.5, Complex::exp, 0.11876788457694579, 0.064883191057865414);
assertComplex(-2, 1, Complex::exp, 0.073121965598059641, 0.1138807140643681);
assertComplex(-2, 2, Complex::exp, -0.056319349992127891, 0.12306002480577674);
- assertComplex(-2, 1e+308, Complex::exp, -0.12062554753319905, 0.061360542460526864);
assertComplex(-1, 0.0, Complex::exp, 0.36787944117144233, 0.0);
assertComplex(-1, 0.5, Complex::exp, 0.32284458245003306, 0.17637079922503196);
assertComplex(-1, 1, Complex::exp, 0.19876611034641298, 0.30955987565311222);
assertComplex(-1, 2, Complex::exp, -0.15309186567422631, 0.33451182923926226);
- assertComplex(-1, 1e+308, Complex::exp, -0.32789423390741779, 0.16679524755483982);
assertComplex(-0.5, 0.0, Complex::exp, 0.60653065971263342, 0.0);
assertComplex(-0.5, 0.5, Complex::exp, 0.53228073021567079, 0.29078628821269187);
assertComplex(-0.5, 1, Complex::exp, 0.32770991402245986, 0.51037795154457277);
assertComplex(-0.5, 2, Complex::exp, -0.25240581530826373, 0.55151676816758077);
- assertComplex(-0.5, 1e+308, Complex::exp, -0.54060619798308285, 0.27499887249535798);
assertComplex(-0.0, 0.0, Complex::exp, 1, 0.0);
assertComplex(-0.0, 0.5, Complex::exp, 0.87758256189037276, 0.47942553860420301);
assertComplex(-0.0, 1, Complex::exp, 0.54030230586813977, 0.8414709848078965);
assertComplex(-0.0, 2, Complex::exp, -0.41614683654714241, 0.90929742682568171);
- assertComplex(-0.0, 1e+308, Complex::exp, -0.89130893768703345, 0.4533964905016491);
assertComplex(0.0, 0.0, Complex::exp, 1, 0.0);
assertComplex(0.0, 0.5, Complex::exp, 0.87758256189037276, 0.47942553860420301);
assertComplex(0.0, 1, Complex::exp, 0.54030230586813977, 0.8414709848078965);
assertComplex(0.0, 2, Complex::exp, -0.41614683654714241, 0.90929742682568171);
- assertComplex(0.0, 1e+308, Complex::exp, -0.89130893768703345, 0.4533964905016491);
assertComplex(0.5, 0.0, Complex::exp, 1.6487212707001282, 0.0);
assertComplex(0.5, 0.5, Complex::exp, 1.4468890365841693, 0.79043908321361489);
assertComplex(0.5, 1, Complex::exp, 0.89080790429312873, 1.3873511113297634);
assertComplex(0.5, 2, Complex::exp, -0.68611014114984314, 1.4991780090003948);
- assertComplex(0.5, 1e+308, Complex::exp, -1.4695200043297472, 0.74752443795085755);
assertComplex(1, 0.0, Complex::exp, 2.7182818284590451, 0.0);
assertComplex(1, 0.5, Complex::exp, 2.3855167309591354, 1.3032137296869954);
assertComplex(1, 1, Complex::exp, 1.4686939399158851, 2.2873552871788423);
assertComplex(1, 2, Complex::exp, -1.1312043837568135, 2.4717266720048188);
- assertComplex(1, 1e+308, Complex::exp, -2.4228288888577985, 1.2324594412177368);
assertComplex(2, 0.0, Complex::exp, 7.3890560989306504, 0.0);
assertComplex(2, 0.5, Complex::exp, 6.4845067812512438, 3.5425022000064983);
assertComplex(2, 1, Complex::exp, 3.9923240484412719, 6.2176763123679679);
assertComplex(2, 2, Complex::exp, -3.0749323206393591, 6.7188496974282499);
- assertComplex(2, 1e+308, Complex::exp, -6.5859317420477739, 3.350172103374963);
- assertComplex(1e+308, 0.0, Complex::exp, inf, 0);
- assertComplex(1e+308, 0.5, Complex::exp, inf, inf);
- assertComplex(1e+308, 1, Complex::exp, inf, inf);
- assertComplex(1e+308, 2, Complex::exp, -inf, inf);
- assertComplex(1e+308, 1e+308, Complex::exp, -inf, inf);
}
@Test
public void testLog() {
- assertComplex(-1e+308, 0.0, Complex::log, 709.19620864216608, 3.1415926535897931);
- assertComplex(-1e+308, 0.5, Complex::log, 709.19620864216608, 3.1415926535897931);
- assertComplex(-1e+308, 1, Complex::log, 709.19620864216608, 3.1415926535897931);
- assertComplex(-1e+308, 2, Complex::log, 709.19620864216608, 3.1415926535897931);
- assertComplex(-1e+308, 1e+308, Complex::log, 709.54278223244603, 2.3561944901923448);
assertComplex(-2, 0.0, Complex::log, 0.69314718055994529, 3.1415926535897931);
assertComplex(-2, 0.5, Complex::log, 0.72345949146816269, 2.8966139904629289);
assertComplex(-2, 1, Complex::log, 0.80471895621705025, 2.677945044588987);
assertComplex(-2, 2, Complex::log, 1.0397207708399181, 2.3561944901923448);
- assertComplex(-2, 1e+308, Complex::log, 709.19620864216608, 1.5707963267948966);
assertComplex(-1, 0.0, Complex::log, 0.0, 3.1415926535897931);
assertComplex(-1, 0.5, Complex::log, 0.11157177565710492, 2.677945044588987);
assertComplex(-1, 1, Complex::log, 0.3465735902799727, 2.3561944901923448);
assertComplex(-1, 2, Complex::log, 0.80471895621705025, 2.0344439357957027);
- assertComplex(-1, 1e+308, Complex::log, 709.19620864216608, 1.5707963267948966);
assertComplex(-0.5, 0.0, Complex::log, -0.69314718055994529, 3.1415926535897931);
assertComplex(-0.5, 0.5, Complex::log, -0.34657359027997259, 2.3561944901923448);
assertComplex(-0.5, 1, Complex::log, 0.11157177565710492, 2.0344439357957027);
assertComplex(-0.5, 2, Complex::log, 0.72345949146816269, 1.8157749899217608);
- assertComplex(-0.5, 1e+308, Complex::log, 709.19620864216608, 1.5707963267948966);
assertComplex(-0.0, 0.0, Complex::log, -inf, 3.1415926535897931);
assertComplex(-0.0, 0.5, Complex::log, -0.69314718055994529, 1.5707963267948966);
assertComplex(-0.0, 1, Complex::log, 0.0, 1.5707963267948966);
assertComplex(-0.0, 2, Complex::log, 0.69314718055994529, 1.5707963267948966);
- assertComplex(-0.0, 1e+308, Complex::log, 709.19620864216608, 1.5707963267948966);
assertComplex(0.0, 0.0, Complex::log, -inf, 0.0);
assertComplex(0.0, 0.5, Complex::log, -0.69314718055994529, 1.5707963267948966);
assertComplex(0.0, 1, Complex::log, 0.0, 1.5707963267948966);
assertComplex(0.0, 2, Complex::log, 0.69314718055994529, 1.5707963267948966);
- assertComplex(0.0, 1e+308, Complex::log, 709.19620864216608, 1.5707963267948966);
assertComplex(0.5, 0.0, Complex::log, -0.69314718055994529, 0.0);
assertComplex(0.5, 0.5, Complex::log, -0.34657359027997259, 0.78539816339744828);
assertComplex(0.5, 1, Complex::log, 0.11157177565710492, 1.1071487177940904);
assertComplex(0.5, 2, Complex::log, 0.72345949146816269, 1.3258176636680326);
- assertComplex(0.5, 1e+308, Complex::log, 709.19620864216608, 1.5707963267948966);
assertComplex(1, 0.0, Complex::log, 0.0, 0.0);
assertComplex(1, 0.5, Complex::log, 0.11157177565710492, 0.46364760900080609);
assertComplex(1, 1, Complex::log, 0.3465735902799727, 0.78539816339744828);
assertComplex(1, 2, Complex::log, 0.80471895621705025, 1.1071487177940904);
- assertComplex(1, 1e+308, Complex::log, 709.19620864216608, 1.5707963267948966);
assertComplex(2, 0.0, Complex::log, 0.69314718055994529, 0.0);
assertComplex(2, 0.5, Complex::log, 0.72345949146816269, 0.24497866312686414);
assertComplex(2, 1, Complex::log, 0.80471895621705025, 0.46364760900080609);
assertComplex(2, 2, Complex::log, 1.0397207708399181, 0.78539816339744828);
- assertComplex(2, 1e+308, Complex::log, 709.19620864216608, 1.5707963267948966);
- assertComplex(1e+308, 0.0, Complex::log, 709.19620864216608, 0.0);
- assertComplex(1e+308, 0.5, Complex::log, 709.19620864216608, 4.9999999999999995e-309);
- assertComplex(1e+308, 1, Complex::log, 709.19620864216608, 9.9999999999999991e-309);
- assertComplex(1e+308, 2, Complex::log, 709.19620864216608, 1.9999999999999998e-308);
- assertComplex(1e+308, 1e+308, Complex::log, 709.54278223244603, 0.78539816339744828);
}
@Test
public void testSqrt() {
- // ---
- // The following reference 'real' values have been copied from the (1e308, x) cases.
- // The C reference program used to compute these values does not compute
- // mirrored values.
- assertComplex(-1e+308, 0.0, Complex::sqrt, 0, 1e+154);
- assertComplex(-1e+308, 0.5, Complex::sqrt, 2.4999999999999974e-155, 1e+154, 6);
- assertComplex(-1e+308, 1, Complex::sqrt, 4.9999999999999999e-155, 1e+154);
- assertComplex(-1e+308, 2, Complex::sqrt, 9.9999999999999997e-155, 1e+154);
- assertComplex(-1e+308, 1e+308, Complex::sqrt, 4.5508986056222742e+153, 1.09868411346781e+154);
- // ---
assertComplex(-2, 0.0, Complex::sqrt, 0, 1.4142135623730951);
assertComplex(-2, 0.5, Complex::sqrt, 0.17543205637629397, 1.425053124063947, 5);
assertComplex(-2, 1, Complex::sqrt, 0.3435607497225126, 1.4553466902253549, 3);
assertComplex(-2, 2, Complex::sqrt, 0.64359425290558281, 1.5537739740300374, 2);
- assertComplex(-2, 1e+308, Complex::sqrt, 7.0710678118654767e+153, 7.0710678118654752e+153);
assertComplex(-1, 0.0, Complex::sqrt, 0, 1);
assertComplex(-1, 0.5, Complex::sqrt, 0.24293413587832291, 1.0290855136357462, 3);
assertComplex(-1, 1, Complex::sqrt, 0.45508986056222739, 1.0986841134678098);
assertComplex(-1, 2, Complex::sqrt, 0.78615137775742339, 1.2720196495140688);
- assertComplex(-1, 1e+308, Complex::sqrt, 7.0710678118654767e+153, 7.0710678118654752e+153);
assertComplex(-0.5, 0.0, Complex::sqrt, 0, 0.70710678118654757);
assertComplex(-0.5, 0.5, Complex::sqrt, 0.3217971264527914, 0.77688698701501868, 2);
assertComplex(-0.5, 1, Complex::sqrt, 0.55589297025142126, 0.89945371997393353);
assertComplex(-0.5, 2, Complex::sqrt, 0.88361553087551337, 1.1317139242778693);
- assertComplex(-0.5, 1e+308, Complex::sqrt, 7.0710678118654767e+153, 7.0710678118654752e+153);
assertComplex(-0.0, 0.0, Complex::sqrt, 0.0, 0.0);
assertComplex(-0.0, 0.5, Complex::sqrt, 0.50000000000000011, 0.5);
assertComplex(-0.0, 1, Complex::sqrt, 0.70710678118654757, 0.70710678118654746);
assertComplex(-0.0, 2, Complex::sqrt, 1.0000000000000002, 1);
- assertComplex(-0.0, 1e+308, Complex::sqrt, 7.0710678118654767e+153, 7.0710678118654752e+153);
assertComplex(0.0, 0.0, Complex::sqrt, 0.0, 0.0);
assertComplex(0.0, 0.5, Complex::sqrt, 0.50000000000000011, 0.5);
assertComplex(0.0, 1, Complex::sqrt, 0.70710678118654757, 0.70710678118654746);
assertComplex(0.0, 2, Complex::sqrt, 1.0000000000000002, 1);
- assertComplex(0.0, 1e+308, Complex::sqrt, 7.0710678118654767e+153, 7.0710678118654752e+153);
assertComplex(0.5, 0.0, Complex::sqrt, 0.70710678118654757, 0.0);
assertComplex(0.5, 0.5, Complex::sqrt, 0.77688698701501868, 0.32179712645279135);
assertComplex(0.5, 1, Complex::sqrt, 0.89945371997393364, 0.55589297025142115);
assertComplex(0.5, 2, Complex::sqrt, 1.1317139242778693, 0.88361553087551337);
- assertComplex(0.5, 1e+308, Complex::sqrt, 7.0710678118654767e+153, 7.0710678118654752e+153);
assertComplex(1, 0.0, Complex::sqrt, 1, 0.0);
assertComplex(1, 0.5, Complex::sqrt, 1.0290855136357462, 0.24293413587832283);
assertComplex(1, 1, Complex::sqrt, 1.0986841134678098, 0.45508986056222733);
assertComplex(1, 2, Complex::sqrt, 1.272019649514069, 0.78615137775742328);
- assertComplex(1, 1e+308, Complex::sqrt, 7.0710678118654767e+153, 7.0710678118654752e+153);
assertComplex(2, 0.0, Complex::sqrt, 1.4142135623730951, 0.0);
assertComplex(2, 0.5, Complex::sqrt, 1.425053124063947, 0.17543205637629383);
assertComplex(2, 1, Complex::sqrt, 1.4553466902253549, 0.34356074972251244);
assertComplex(2, 2, Complex::sqrt, 1.5537739740300374, 0.6435942529055827);
- assertComplex(2, 1e+308, Complex::sqrt, 7.0710678118654767e+153, 7.0710678118654752e+153);
- assertComplex(1e+308, 0.0, Complex::sqrt, 1e+154, 0.0);
- assertComplex(1e+308, 0.5, Complex::sqrt, 1e+154, 2.4999999999999974e-155, 6);
- assertComplex(1e+308, 1, Complex::sqrt, 1e+154, 4.9999999999999999e-155);
- assertComplex(1e+308, 2, Complex::sqrt, 1e+154, 9.9999999999999997e-155);
- assertComplex(1e+308, 1e+308, Complex::sqrt, 1.09868411346781e+154, 4.5508986056222734e+153);
}
@Test
[commons-numbers] 08/09: Remove unused private methods
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 5db7d736976477fe20e3f31cf81b582e40035515
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sun Dec 8 23:42:57 2019 +0000
Remove unused private methods
---
.../org/apache/commons/numbers/complex/Complex.java | 18 ------------------
1 file changed, 18 deletions(-)
diff --git a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
index 6530e00..ab28944 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
@@ -1082,24 +1082,6 @@ public final class Complex implements Serializable {
}
/**
- * Multiply the Complex by I.
- *
- * @return the result (iz)
- */
- private Complex multiplyByI() {
- return new Complex(-imaginary, real);
- }
-
- /**
- * Multiply the Complex by -I.
- *
- * @return the result (-iz)
- */
- private Complex multiplyByNegI() {
- return new Complex(imaginary, -real);
- }
-
- /**
* Compute the
* <a href="http://mathworld.wolfram.com/InverseHyperbolicSine.html">
* inverse hyperbolic sine</a> of this complex number.
[commons-numbers] 02/09: Document odd and even functions.
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 2753fa05fecfa6fe0c738248ed24737dfb5056f4
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sun Dec 8 17:58:10 2019 +0000
Document odd and even functions.
---
.../java/org/apache/commons/numbers/complex/Complex.java | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
index 19e00f4..2d88c2f 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
@@ -1102,6 +1102,8 @@ public final class Complex implements Serializable {
* </code>
* </pre>
*
+ * <p>This is an odd function: {@code f(z) = -f(-z)}.
+ *
* @return the inverse hyperbolic sine of this complex number
*/
public Complex asinh() {
@@ -1190,6 +1192,8 @@ public final class Complex implements Serializable {
* atanh(z) = (1/2) ln((1 + z) / (1 - z))
* </pre>
*
+ * <p>This is an odd function: {@code f(z) = -f(-z)}.
+ *
* @return the inverse hyperbolic tangent of this complex number
*/
public Complex atanh() {
@@ -1344,6 +1348,8 @@ public final class Complex implements Serializable {
* cosh(a + b i) = cosh(a)cos(b) + i sinh(a)sin(b)
* </pre>
*
+ * <p>This is an even function: {@code f(z) = f(-z)}.
+ *
* @return the hyperbolic cosine of this complex number.
*/
public Complex cosh() {
@@ -1594,9 +1600,8 @@ public final class Complex implements Serializable {
* <pre>
* sinh(a + b i) = sinh(a)cos(b)) + i cosh(a)sin(b)
* </pre>
- * where the (real) functions on the right-hand side are
- * {@link Math#sin}, {@link Math#cos},
- * {@link Math#cosh} and {@link Math#sinh}.
+ *
+ * <p>This is an odd function: {@code f(z) = -f(-z)}.
*
* @return the hyperbolic sine of {@code this}.
*/
@@ -1775,9 +1780,8 @@ public final class Complex implements Serializable {
* <pre>
* tan(a + b i) = sinh(2a)/(cosh(2a)+cos(2b)) + i [sin(2b)/(cosh(2a)+cos(2b))]
* </pre>
- * where the (real) functions on the right-hand side are
- * {@link Math#sin}, {@link Math#cos}, {@link Math#cosh} and
- * {@link Math#sinh}.
+ *
+ * <p>This is an odd function: {@code f(z) = -f(-z)}.
*
* @return the hyperbolic tangent of {@code this}.
*/
[commons-numbers] 06/09: Use final
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 c897177a3f4399e4feefeddff9fdb902f2c554bc
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sun Dec 8 23:23:24 2019 +0000
Use final
---
.../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 9f9ac9e..3b48bdb 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
@@ -1819,7 +1819,7 @@ public final class Complex implements Serializable {
if (Double.isFinite(real)) {
if (Double.isFinite(imaginary2)) {
- double real2 = 2 * real;
+ final double real2 = 2 * real;
// Math.cosh returns positive infinity for infinity.
// cosh -> inf
[commons-numbers] 03/09: Removed mirrored cases for odd/even
functions.
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 08465eb01b0bfc0dbf7e0e920a7cc20aba53cab6
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sun Dec 8 19:51:00 2019 +0000
Removed mirrored cases for odd/even functions.
The data for negative real is the same as that for the positive real for
odd/even functions.
---
.../commons/numbers/complex/CReferenceTest.java | 130 +--------------------
1 file changed, 5 insertions(+), 125 deletions(-)
diff --git a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CReferenceTest.java b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CReferenceTest.java
index 4bb9a31..a5f0454 100644
--- a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CReferenceTest.java
+++ b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CReferenceTest.java
@@ -263,31 +263,7 @@ public class CReferenceTest {
@Test
public void testAsinh() {
-// assertComplex(-1e+308, 0.0, Complex::asinh, -inf, nan);
-// assertComplex(-1e+308, 0.5, Complex::asinh, -inf, 0.78539816339744828);
-// assertComplex(-1e+308, 1, Complex::asinh, -inf, 0.78539816339744828);
-// assertComplex(-1e+308, 2, Complex::asinh, -inf, 0.78539816339744828);
- assertComplex(-1e+308, 1e+308, Complex::asinh, -inf, 0.78539816339744828);
- assertComplex(-2, 0.0, Complex::asinh, -1.4436354751788099, 0.0, 2);
- assertComplex(-2, 0.5, Complex::asinh, -1.4657153519472903, 0.22101863562288368, 6);
- assertComplex(-2, 1, Complex::asinh, -1.5285709194809995, 0.42707858639247681, 12);
- assertComplex(-2, 2, Complex::asinh, -1.7343245214879652, 0.75424914469804549, 6);
- assertComplex(-2, 1e+308, Complex::asinh, -inf, 0.78539816339744828);
- assertComplex(-1, 0.0, Complex::asinh, -0.88137358701954283, 0.0);
- assertComplex(-1, 0.5, Complex::asinh, -0.92613303135018232, 0.34943906285721327, 2);
- assertComplex(-1, 1, Complex::asinh, -1.0612750619050355, 0.66623943249251527);
- assertComplex(-1, 2, Complex::asinh, -1.4693517443681841, 1.0634400235777519, 5);
- assertComplex(-1, 1e+308, Complex::asinh, -inf, 0.78539816339744828);
- assertComplex(-0.5, 0.0, Complex::asinh, -0.48121182505960336, 0.0, 2);
- assertComplex(-0.5, 0.5, Complex::asinh, -0.53063753095251776, 0.4522784471511907);
- assertComplex(-0.5, 1, Complex::asinh, -0.73285767597364526, 0.89590748120889041, 2);
- assertComplex(-0.5, 2, Complex::asinh, -1.3618009008578469, 1.2930420702371832, 5);
- assertComplex(-0.5, 1e+308, Complex::asinh, -inf, 1.5707963267948966);
- assertComplex(-0.0, 0.0, Complex::asinh, -0.0, 0.0);
- assertComplex(-0.0, 0.5, Complex::asinh, -1.1102230246251565e-16, 0.52359877559829893);
- assertComplex(-0.0, 1, Complex::asinh, -0.0, 1.5707963267948966);
- assertComplex(-0.0, 2, Complex::asinh, -1.3169578969248164, 1.5707963267948961, 2);
- assertComplex(-0.0, 1e+308, Complex::asinh, -inf, 1.5707963267948966);
+ // Odd function: negative real cases defined by positive real cases
assertComplex(0.0, 0.0, Complex::asinh, 0.0, 0.0);
assertComplex(0.0, 0.5, Complex::asinh, 1.1102230246251565e-16, 0.52359877559829893);
assertComplex(0.0, 1, Complex::asinh, 0.0, 1.5707963267948966);
@@ -317,31 +293,7 @@ public class CReferenceTest {
@Test
public void testAtanh() {
- assertComplex(-1e+308, 0.0, Complex::atanh, -0.0, 1.5707963267948966);
- assertComplex(-1e+308, 0.5, Complex::atanh, -0.0, 1.5707963267948966);
- assertComplex(-1e+308, 1, Complex::atanh, -0.0, 1.5707963267948966);
- assertComplex(-1e+308, 2, Complex::atanh, -0.0, 1.5707963267948966);
- assertComplex(-1e+308, 1e+308, Complex::atanh, -inf, 1.5707963267948966);
- assertComplex(-2, 0.0, Complex::atanh, -0.54930614433405489, 1.5707963267948966);
- assertComplex(-2, 0.5, Complex::atanh, -0.50037000005253107, 1.4215468610018069);
- assertComplex(-2, 1, Complex::atanh, -0.40235947810852507, 1.3389725222944935);
- assertComplex(-2, 2, Complex::atanh, -0.23887786125685917, 1.311223269671635, 4);
- assertComplex(-2, 1e+308, Complex::atanh, -0.0, 1.5707963267948966);
- assertComplex(-1, 0.0, Complex::atanh, -inf, 0.0);
- assertComplex(-1, 0.5, Complex::atanh, -0.70830333601405404, 0.90788749496088039);
- assertComplex(-1, 1, Complex::atanh, -0.40235947810852507, 1.0172219678978514);
- assertComplex(-1, 2, Complex::atanh, -0.17328679513998629, 1.1780972450961724, 2);
- assertComplex(-1, 1e+308, Complex::atanh, -0.0, 1.5707963267948966);
- assertComplex(-0.5, 0.0, Complex::atanh, -0.54930614433405489, 0.0);
- assertComplex(-0.5, 0.5, Complex::atanh, -0.40235947810852507, 0.5535743588970452);
- assertComplex(-0.5, 1, Complex::atanh, -0.23887786125685906, 0.84757566067082901, 2);
- assertComplex(-0.5, 2, Complex::atanh, -0.096415620202996155, 1.1265564408348223, 3);
- assertComplex(-0.5, 1e+308, Complex::atanh, -0.0, 1.5707963267948966);
- assertComplex(-0.0, 0.0, Complex::atanh, -0.0, 0.0);
- assertComplex(-0.0, 0.5, Complex::atanh, -0.0, 0.46364760900080615);
- assertComplex(-0.0, 1, Complex::atanh, -0.0, 0.78539816339744828);
- assertComplex(-0.0, 2, Complex::atanh, -0.0, 1.1071487177940904);
- assertComplex(-0.0, 1e+308, Complex::atanh, -0.0, 1.5707963267948966);
+ // Odd function: negative real cases defined by positive real cases
assertComplex(0.0, 0.0, Complex::atanh, 0.0, 0.0);
assertComplex(0.0, 0.5, Complex::atanh, 0.0, 0.46364760900080615);
assertComplex(0.0, 1, Complex::atanh, 0.0, 0.78539816339744828);
@@ -371,31 +323,7 @@ public class CReferenceTest {
@Test
public void testCosh() {
- assertComplex(-1e+308, 0.0, Complex::cosh, inf, nan);
- assertComplex(-1e+308, 0.5, Complex::cosh, inf, -inf);
- assertComplex(-1e+308, 1, Complex::cosh, inf, -inf);
- assertComplex(-1e+308, 2, Complex::cosh, -inf, -inf);
- assertComplex(-1e+308, 1e+308, Complex::cosh, -inf, -inf);
- assertComplex(-2, 0.0, Complex::cosh, 3.7621956910836314, -0.0);
- assertComplex(-2, 0.5, Complex::cosh, 3.3016373329140944, -1.7388095044743164);
- assertComplex(-2, 1, Complex::cosh, 2.0327230070196656, -3.0518977991517997);
- assertComplex(-2, 2, Complex::cosh, -1.5656258353157435, -3.2978948363112366);
- assertComplex(-2, 1e+308, Complex::cosh, -3.3532786447904863, -1.6444057804572179);
- assertComplex(-1, 0.0, Complex::cosh, 1.5430806348152437, -0.0);
- assertComplex(-1, 0.5, Complex::cosh, 1.3541806567045842, -0.5634214652309818);
- assertComplex(-1, 1, Complex::cosh, 0.83373002513114913, -0.98889770576286506);
- assertComplex(-1, 2, Complex::cosh, -0.64214812471551996, -1.0686074213827783);
- assertComplex(-1, 1e+308, Complex::cosh, -1.375361561382608, -0.5328320968314485);
- assertComplex(-0.5, 0.0, Complex::cosh, 1.1276259652063807, -0.0);
- assertComplex(-0.5, 0.5, Complex::cosh, 0.9895848833999199, -0.24982639750046154);
- assertComplex(-0.5, 1, Complex::cosh, 0.60925890915779424, -0.43848657989259532);
- assertComplex(-0.5, 2, Complex::cosh, -0.46925797822905341, -0.473830620416407);
- assertComplex(-0.5, 1e+308, Complex::cosh, -1.0050631011564148, -0.23626278272774978);
- assertComplex(-0.0, 0.0, Complex::cosh, 1, 0.0);
- assertComplex(-0.0, 0.5, Complex::cosh, 0.87758256189037276, -0.0);
- assertComplex(-0.0, 1, Complex::cosh, 0.54030230586813977, -0.0);
- assertComplex(-0.0, 2, Complex::cosh, -0.41614683654714241, -0.0);
- assertComplex(-0.0, 1e+308, Complex::cosh, -0.89130893768703345, -0.0);
+ // Even function: negative real cases defined by positive real cases
assertComplex(0.0, 0.0, Complex::cosh, 1, 0.0);
assertComplex(0.0, 0.5, Complex::cosh, 0.87758256189037276, 0.0);
assertComplex(0.0, 1, Complex::cosh, 0.54030230586813977, 0.0);
@@ -425,31 +353,7 @@ public class CReferenceTest {
@Test
public void testSinh() {
- assertComplex(-1e+308, 0.0, Complex::sinh, -inf, nan);
- assertComplex(-1e+308, 0.5, Complex::sinh, -inf, inf);
- assertComplex(-1e+308, 1, Complex::sinh, -inf, inf);
- assertComplex(-1e+308, 2, Complex::sinh, inf, inf);
- assertComplex(-1e+308, 1e+308, Complex::sinh, inf, inf);
- assertComplex(-2, 0.0, Complex::sinh, -3.6268604078470186, 0.0);
- assertComplex(-2, 0.5, Complex::sinh, -3.1828694483371489, 1.8036926955321817);
- assertComplex(-2, 1, Complex::sinh, -1.9596010414216061, 3.1657785132161682);
- assertComplex(-2, 2, Complex::sinh, 1.5093064853236156, 3.4209548611170133);
- assertComplex(-2, 1e+308, Complex::sinh, 3.2326530972572871, 1.7057663229177449);
- assertComplex(-1, 0.0, Complex::sinh, -1.1752011936438014, 0.0);
- assertComplex(-1, 0.5, Complex::sinh, -1.0313360742545512, 0.73979226445601376);
- assertComplex(-1, 1, Complex::sinh, -0.63496391478473613, 1.2984575814159773);
- assertComplex(-1, 2, Complex::sinh, 0.48905625904129368, 1.4031192506220405);
- assertComplex(-1, 1e+308, Complex::sinh, 1.0474673274751902, 0.69962734438628826);
- assertComplex(-0.5, 0.0, Complex::sinh, -0.52109530549374738, 0.0);
- assertComplex(-0.5, 0.5, Complex::sinh, -0.45730415318424927, 0.54061268571315335);
- assertComplex(-0.5, 1, Complex::sinh, -0.28154899513533443, 0.94886453143716798);
- assertComplex(-0.5, 2, Complex::sinh, 0.21685216292078974, 1.0253473885839877);
- assertComplex(-0.5, 1e+308, Complex::sinh, 0.46445690317333216, 0.51126165522310774);
- assertComplex(-0.0, 0.0, Complex::sinh, -0.0, 0.0);
- assertComplex(-0.0, 0.5, Complex::sinh, -0.0, 0.47942553860420301);
- assertComplex(-0.0, 1, Complex::sinh, -0.0, 0.8414709848078965);
- assertComplex(-0.0, 2, Complex::sinh, 0.0, 0.90929742682568171);
- assertComplex(-0.0, 1e+308, Complex::sinh, 0.0, 0.4533964905016491);
+ // Odd function: negative real cases defined by positive real cases
assertComplex(0.0, 0.0, Complex::sinh, 0.0, 0.0);
assertComplex(0.0, 0.5, Complex::sinh, 0.0, 0.47942553860420301);
assertComplex(0.0, 1, Complex::sinh, 0.0, 0.8414709848078965);
@@ -479,31 +383,7 @@ public class CReferenceTest {
@Test
public void testTanh() {
- assertComplex(-1e+308, 0.0, Complex::tanh, -1, -0.0);
- assertComplex(-1e+308, 0.5, Complex::tanh, -1, 0.0);
- assertComplex(-1e+308, 1, Complex::tanh, -1, 0.0);
- assertComplex(-1e+308, 2, Complex::tanh, -1, 0.0);
- assertComplex(-1e+308, 1e+308, Complex::tanh, nan, nan);
- assertComplex(-2, 0.0, Complex::tanh, -0.9640275800758169, 0.0);
- assertComplex(-2, 0.5, Complex::tanh, -0.97994084996173814, 0.030215987322877575);
- assertComplex(-2, 1, Complex::tanh, -1.0147936161466335, 0.033812826079896691);
- assertComplex(-2, 2, Complex::tanh, -1.0238355945704727, -0.028392952868232287);
- assertComplex(-2, 1e+308, Complex::tanh, nan, nan);
- assertComplex(-1, 0.0, Complex::tanh, -0.76159415595576485, 0.0);
- assertComplex(-1, 0.5, Complex::tanh, -0.84296620484578311, 0.19557731006593398);
- assertComplex(-1, 1, Complex::tanh, -1.0839233273386946, 0.27175258531951174);
- assertComplex(-1, 2, Complex::tanh, -1.1667362572409199, -0.24345820118572523);
- assertComplex(-1, 1e+308, Complex::tanh, nan, nan);
- assertComplex(-0.5, 0.0, Complex::tanh, -0.46211715726000974, 0.0);
- assertComplex(-0.5, 0.5, Complex::tanh, -0.56408314126749848, 0.40389645531602575, 2);
- assertComplex(-0.5, 1, Complex::tanh, -1.042830728344361, 0.80687741216308495);
- assertComplex(-0.5, 2, Complex::tanh, -1.3212865837711918, -0.85087812114493777, 2);
- assertComplex(-0.5, 1e+308, Complex::tanh, nan, nan);
- assertComplex(-0.0, 0.0, Complex::tanh, -0.0, 0.0);
- assertComplex(-0.0, 0.5, Complex::tanh, -0.0, 0.54630248984379048);
- assertComplex(-0.0, 1, Complex::tanh, -0.0, 1.5574077246549021);
- assertComplex(-0.0, 2, Complex::tanh, -0.0, -2.1850398632615189);
- assertComplex(-0.0, 1e+308, Complex::tanh, nan, nan);
+ // Odd function: negative real cases defined by positive real cases
assertComplex(0.0, 0.0, Complex::tanh, 0.0, 0.0);
assertComplex(0.0, 0.5, Complex::tanh, 0.0, 0.54630248984379048);
assertComplex(0.0, 1, Complex::tanh, 0.0, 1.5574077246549021);
[commons-numbers] 09/09: Added TODO notes on special case for
imaginary only numbers.
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 9b1b88700a43a618c7a67590f0dbdba1302f956f
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sun Dec 8 23:52:45 2019 +0000
Added TODO notes on special case for imaginary only numbers.
asinh(iy) = i asin(y)
atanh(iy) = i atan(y)
do not work.
---
.../src/main/java/org/apache/commons/numbers/complex/Complex.java | 2 ++
1 file changed, 2 insertions(+)
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 ab28944..873db5f 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
@@ -1125,6 +1125,7 @@ public final class Complex implements Serializable {
if (imaginary == 0) {
return constructor.create(real, imaginary);
}
+ // TODO: Check why this does not work
// // asinh(iy) = i asin(y)
// final double re = -Math.asin(b);
// return constructor.create(changeSign(re, real),
@@ -1220,6 +1221,7 @@ public final class Complex implements Serializable {
if (imaginary == 0) {
return constructor.create(real, imaginary);
}
+ // TODO: Check why this does not work
// // atanh(iy) = i atan(y)
// final double re = -Math.atan(b);
// return constructor.create(changeSign(re, real),
[commons-numbers] 01/09: Remove getArgument and getAbsolute.
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 8edcaecda2262f229e214c26c3c0695eea508aa5
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sun Dec 8 17:54:12 2019 +0000
Remove getArgument and getAbsolute.
Document method names are chosen to match the names defined in ISO C99.
---
.../apache/commons/numbers/complex/Complex.java | 90 +++++++++-------------
.../commons/numbers/complex/ComplexTest.java | 26 +++----
2 files changed, 49 insertions(+), 67 deletions(-)
diff --git a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
index 92f4c2a..19e00f4 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
@@ -24,30 +24,24 @@ import java.util.List;
import org.apache.commons.numbers.core.Precision;
/**
- * Representation of a Complex number, i.e. a number which has both a
+ * Cartesian representation of a Complex number, i.e. a number which has both a
* real and imaginary part.
*
- * <p>Implementations of arithmetic operations handle {@code NaN} and
- * infinite values according to the rules for {@link java.lang.Double}, i.e.
- * {@link #equals} is an equivalence relation for all instances that have
- * a {@code NaN} in either real or imaginary part, e.g. the following are
- * considered equal:</p>
- * <ul>
- * <li>{@code 1 + NaNi}</li>
- * <li>{@code NaN + i}</li>
- * <li>{@code NaN + NaNi}</li>
- * </ul>
- *
- * <p>Note that this contradicts the IEEE-754 standard for floating
- * point numbers (according to which the test {@code x == x} must fail if
- * {@code x} is {@code NaN}). The method
- * {@link org.apache.commons.numbers.core.Precision#equals(double,double,int)
- * equals for primitive double} in class {@code Precision} conforms with
- * IEEE-754 while this class conforms with the standard behavior for Java
- * object types.</p>
+ * <p>This class is immutable. All arithmetic will create a new instance for the
+ * result.</p>
*
* <p>Arithmetic in this class conforms to the C.99 standard for complex numbers
- * defined in ISO/IEC 9899, Annex G.<p>
+ * defined in ISO/IEC 9899, Annex G. All methods have been named using the equivalent
+ * method in ISO C.99.</p>
+ *
+ * <p>Operations ({@code op}) with no arguments obey the conjuagte equality:</p>
+ * <pre>z.op().conjugate() == z.conjugate().op()</pre>
+ *
+ * <p>Operations that are odd or even obey the equality:</p>
+ * <pre>
+ * Odd: f(z) = -f(-z)
+ * Even: f(z) = f(-z)
+ * </pre>
*
* @see <a href="http://www.open-std.org/JTC1/SC22/WG14/www/standards">
* ISO/IEC 9899 - Programming languages - C</a>
@@ -294,36 +288,28 @@ public final class Complex implements Serializable {
*
* <p>This code follows the
* <a href="http://www.iso-9899.info/wiki/The_Standard">ISO C Standard</a>, Annex G,
- * in calculating the returned value using the {@code hypot(x,y)} method.
+ * in calculating the returned value using the {@code hypot(a, b)} method for complex
+ * {@code a + b i}.
*
* @return the absolute value.
* @see #isInfinite()
* @see #isNaN()
* @see Math#hypot(double, double)
*/
- public double getAbsolute() {
- return getAbsolute(real, imaginary);
- }
-
- /**
- * Compute the absolute of this complex number
- * (C++11 grammar).
- *
- * @return the absolute of {@code this}.
- * @see #getAbsolute()
- */
public double abs() {
- return getAbsolute(real, imaginary);
+ // Delegate
+ return Math.hypot(real, imaginary);
}
/**
- * Compute the argument of the complex number.
+ * Compute the absolute of the complex number.
*
* <p>This function exists for use in trigonomic functions.
*
* @param real Real part.
* @param imaginary Imaginary part.
- * @return the argument
+ * @return the absolute value.
+ * @see Math#hypot(double, double)
*/
private static double getAbsolute(double real, double imaginary) {
// Delegate
@@ -1250,7 +1236,7 @@ public final class Complex implements Serializable {
// Compute the rest inline to avoid Complex object creation.
// (re + im i) = (1/2) * ln((1 + z) / (1 - z))
final double re = 0.5 * Math.log(result.abs());
- final double im = 0.5 * result.getArgument();
+ final double im = 0.5 * result.arg();
// Map back to the correct sign
return constructor.create(changeSign(re, real),
changeSign(im, imaginary));
@@ -1493,7 +1479,7 @@ public final class Complex implements Serializable {
public Complex log() {
// All edge cases satisfied by the Math library
return new Complex(Math.log(abs()),
- getArgument());
+ arg());
}
/**
@@ -1513,7 +1499,7 @@ public final class Complex implements Serializable {
public Complex log10() {
// All edge cases satisfied by the Math library
return new Complex(Math.log10(abs()),
- getArgument());
+ arg());
}
/**
@@ -1870,30 +1856,28 @@ public final class Complex implements Serializable {
* infinite coordinate and returning a multiple of pi/4 depending on
* the signs of the infinite parts.
*
- * @return the argument of {@code this}.
- * @see Math#atan2(double, double)
- */
- public double getArgument() {
- return getArgument(real, imaginary);
- }
-
- /**
- * Compute the argument of this complex number
- * (C++11 grammar).
+ * <p>This code follows the
+ * <a href="http://www.iso-9899.info/wiki/The_Standard">ISO C Standard</a>, Annex G,
+ * in calculating the returned value using the {@code atan2(b, a)} method for complex
+ * {@code a + b i}.
*
* @return the argument of {@code this}.
- * @see #getArgument()
+ * @see Math#atan2(double, double)
*/
public double arg() {
- return getArgument(real, imaginary);
+ // Delegate
+ return Math.atan2(imaginary, real);
}
/**
* Compute the argument of the complex number.
*
+ * <p>This function exists for use in trigonomic functions.
+ *
* @param real Real part.
* @param imaginary Imaginary part.
- * @return the argument
+ * @return the argument.
+ * @see Math#atan2(double, double)
*/
private static double getArgument(double real, double imaginary) {
// Delegate
@@ -1910,7 +1894,7 @@ public final class Complex implements Serializable {
* </pre>
* for <i>{@code k=0, 1, ..., n-1}</i>, where {@code abs} and {@code phi}
* are respectively the {@link #abs() modulus} and
- * {@link #getArgument() argument} of this complex number.
+ * {@link #arg() argument} of this complex number.
*
* <p>If one or both parts of this complex number is NaN, a list with all
* all elements set to {@code NaN + NaN i} is returned.</p>
@@ -1930,7 +1914,7 @@ public final class Complex implements Serializable {
final double nthRootOfAbs = Math.pow(abs(), 1.0 / n);
// Compute nth roots of complex number with k = 0, 1, ... n-1
- final double nthPhi = getArgument() / n;
+ final double nthPhi = arg() / n;
final double slice = 2 * Math.PI / n;
double innerPart = nthPhi;
for (int k = 0; k < Math.abs(n); k++) {
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 8eaf503..13bd820 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
@@ -177,22 +177,22 @@ public class ComplexTest {
}
@Test
- public void testAbsolute() {
+ public void testAbs() {
final Complex z = Complex.ofCartesian(3.0, 4.0);
- Assertions.assertEquals(5.0, z.getAbsolute());
+ Assertions.assertEquals(5.0, z.abs());
}
@Test
- public void testAbsoluteNaN() {
+ public void testAbsNaN() {
// The result is NaN if either argument is NaN and the other is not infinite
- Assertions.assertEquals(nan, NAN.getAbsolute());
- Assertions.assertEquals(nan, Complex.ofCartesian(3.0, nan).getAbsolute());
- Assertions.assertEquals(nan, Complex.ofCartesian(nan, 3.0).getAbsolute());
+ Assertions.assertEquals(nan, NAN.abs());
+ Assertions.assertEquals(nan, Complex.ofCartesian(3.0, nan).abs());
+ Assertions.assertEquals(nan, Complex.ofCartesian(nan, 3.0).abs());
// The result is positive infinite if either argument is infinite
- Assertions.assertEquals(inf, Complex.ofCartesian(inf, nan).getAbsolute());
- Assertions.assertEquals(inf, Complex.ofCartesian(-inf, nan).getAbsolute());
- Assertions.assertEquals(inf, Complex.ofCartesian(nan, inf).getAbsolute());
- Assertions.assertEquals(inf, Complex.ofCartesian(nan, -inf).getAbsolute());
+ Assertions.assertEquals(inf, Complex.ofCartesian(inf, nan).abs());
+ Assertions.assertEquals(inf, Complex.ofCartesian(-inf, nan).abs());
+ Assertions.assertEquals(inf, Complex.ofCartesian(nan, inf).abs());
+ Assertions.assertEquals(inf, Complex.ofCartesian(nan, -inf).abs());
}
@Test
@@ -1206,7 +1206,7 @@ public class ComplexTest {
}
private static void assertGetArgument(double expected, Complex complex, double delta) {
- final double actual = complex.getArgument();
+ final double actual = complex.arg();
Assertions.assertEquals(expected, actual, delta);
Assertions.assertEquals(actual, complex.arg(), delta);
}
@@ -1286,8 +1286,6 @@ public class ComplexTest {
Assertions.assertEquals(z.getReal(), z.real(), "real");
Assertions.assertEquals(z.getImaginary(), z.imag(), "imag");
Assertions.assertEquals(z.conjugate(), z.conj(), "conj");
- Assertions.assertEquals(z.getArgument(), z.arg(), "arg");
- Assertions.assertEquals(z.getAbsolute(), z.abs(), "abs");
}
}
@@ -1302,7 +1300,7 @@ public class ComplexTest {
// This is prone to floating-point error so use a delta
Assertions.assertEquals(lnz.getReal() / ln10, log10z.getReal(), 1e-12, "real");
// This test should be exact
- final double abs = z.getAbsolute();
+ final double abs = z.abs();
Assertions.assertEquals(Math.log10(abs), log10z.getReal(), "real");
Assertions.assertEquals(lnz.getImaginary(), log10z.getImaginary(), "imag");
}