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/07 02:27:43 UTC
[commons-numbers] 01/04: Fix acosh() to preserve the conjugate
equality.
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 73743d3c7f69c0c31ee035ebf5bd57edea0a21fd
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Fri Dec 6 21:43:20 2019 +0000
Fix acosh() to preserve the conjugate equality.
The returned value is chosen to ensure the result is positive in the
real component.
---
.../java/org/apache/commons/numbers/complex/Complex.java | 16 +++++++++-------
1 file changed, 9 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 7111296..42a88e4 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
@@ -1278,15 +1278,17 @@ public final class Complex implements Serializable {
if (Double.isNaN(imaginary) && Double.isFinite(real)) {
return NAN;
}
- return acos(real, imaginary, (re, im) -> {
+ // ISO C99: Preserve the equality
+ // acos(conj(z)) = conj(acos(z))
+ // by always computing on a positive imaginary Complex number.
+ return acos(real, Math.abs(imaginary), (re, im) ->
// Set the sign appropriately for C99 equalities.
- // TODO: This function currently conflicts with the CReferenceTest
- return (negative(im)) ?
+ (im > 0) ?
+ // Multiply by -I and map back to the correct sign
+ new Complex(im, changeSign(-re, imaginary)) :
// Multiply by I
- new Complex(-im, re) :
- // Multiply by -I
- new Complex(im, -re);
- });
+ new Complex(-im, changeSign(re, imaginary))
+ );
}
/**