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/04 21:53:56 UTC

[commons-numbers] 06/06: Use add(double), subtract and subtractFromReal(double).

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 2026f96c3d8465eda9e494756d29427e1bb9840f
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Wed Dec 4 21:52:56 2019 +0000

    Use add(double), subtract and subtractFromReal(double).
    
    Use this in preference to add(ONE), subtract(ONE) and ONE.subtract(z).
    
    The add is faster.
    
    The subtract preserves the sign of an imaginary zero.
    
    The subtractFromReal negates the sign of the imaginary if it is zero.
---
 .../main/java/org/apache/commons/numbers/complex/Complex.java    | 9 +++------
 1 file changed, 3 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 b14ff97..1a7abfe 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
@@ -1039,7 +1039,7 @@ public final class Complex implements Serializable  {
                 // ISO C99: Preserve the equality
                 // asinh(conj(z)) = conj(asinh(z))
                 final Complex z = negative(imaginary) ? conjugate() : this;
-                final Complex result = z.square().add(ONE).sqrt().add(z).log();
+                final Complex result = z.square().add(1).sqrt().add(z).log();
                 return z == this ? result : result.conjugate();
             }
             if (Double.isInfinite(imaginary)) {
@@ -1142,7 +1142,7 @@ public final class Complex implements Serializable  {
                 // ISO C99: Preserve the equality
                 // acosh(conj(z)) = conj(acosh(z))
                 final Complex z = negative(imaginary) ? conjugate() : this;
-                final Complex result = z.square().subtract(ONE).sqrt().add(z).log();
+                final Complex result = z.square().subtract(1).sqrt().add(z).log();
                 return z == this ? result : result.conjugate();
             }
             if (Double.isInfinite(imaginary)) {
@@ -1561,13 +1561,10 @@ public final class Complex implements Serializable  {
      * square root</a> of <code>1 - this<sup>2</sup></code> for this complex
      * number.
      *
-     * <p>Computes the result directly as
-     * {@code sqrt(ONE.subtract(z.multiply(z)))}.</p>
-     *
      * @return the square root of <code>1 - this<sup>2</sup></code>.
      */
     private Complex sqrt1z() {
-        return ONE.subtract(square()).sqrt();
+        return square().subtractFromReal(1).sqrt();
     }
 
     /**