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/10 14:59:31 UTC
[commons-numbers] 01/05: Added special cases of trigonomic
functions:
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 2ed318c04e6f9afdf6269c6230587ea52378acfc
Author: aherbert <ah...@apache.org>
AuthorDate: Tue Dec 10 12:13:10 2019 +0000
Added special cases of trigonomic functions:
acos(a + 0 i) when |a| <= 1
asinh(0 + b i) = i asin(b) when |b| <= 1
atanh(0 + b i) = i atan(b)
---
.../apache/commons/numbers/complex/Complex.java | 23 ++++++++++------------
1 file changed, 10 insertions(+), 13 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 8e57ac0..f6f4681 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
@@ -974,9 +974,10 @@ public final class Complex implements Serializable {
private static Complex acos(double real, double imaginary, ComplexConstructor constructor) {
if (Double.isFinite(real)) {
if (Double.isFinite(imaginary)) {
- // Special case for zero
- if (real == 0 && imaginary == 0) {
- return constructor.create(PI_OVER_2, Math.copySign(0, -imaginary));
+ // Special case for real numbers
+ if (imaginary == 0 && Math.abs(real) <= 1) {
+ return constructor.create(real == 0.0 ? PI_OVER_2 : Math.acos(real),
+ Math.copySign(0, -imaginary));
}
// ISO C99: Preserve the equality
// acos(conj(z)) = conj(acos(z))
@@ -1114,11 +1115,9 @@ 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),
-// imaginary);
+ // asinh(iy) = i asin(y)
+ final double im = Math.asin(imaginary);
+ return constructor.create(real, im);
}
// square() is implemented using multiply
final Complex z2 = multiply(a, b, a, b);
@@ -1210,11 +1209,9 @@ 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),
-// imaginary);
+ // atanh(iy) = i atan(y)
+ final double im = Math.atan(imaginary);
+ return constructor.create(real, im);
}
// (1 + (a + b i)) / (1 - (a + b i))
final Complex result = divide(1 + a, b, 1 - a, -b);