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


The following commit(s) were added to refs/heads/master by this push:
     new 32dbe34  Remove overflow protection to compute average.
32dbe34 is described below

commit 32dbe346e717ffafa188b0b1d9cf51006b852c17
Author: Alex Herbert <[email protected]>
AuthorDate: Mon Dec 9 00:37:13 2019 +0000

    Remove overflow protection to compute average.
    
    The sqrt() switches to using polar coordinates to compute the result.
---
 .../apache/commons/numbers/complex/Complex.java    | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 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 873db5f..4a4ee76 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
@@ -1701,6 +1701,13 @@ public final class Complex implements Serializable  {
      * @return the square root of the complex number.
      */
     private static Complex sqrt(double real, double imaginary) {
+//        final double abs = getAbsolute(real, imaginary);
+//        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);
+
         // Special case for infinite imaginary for all real including nan
         if (Double.isInfinite(imaginary)) {
             return new Complex(Double.POSITIVE_INFINITY, imaginary);
@@ -1712,7 +1719,7 @@ public final class Complex implements Serializable  {
                     return new Complex(0, imaginary);
                 }
                 final double abs = getAbsolute(real, imaginary);
-                final double av = average(Math.abs(real), abs);
+                final double av = (Math.abs(real) + abs) / 2;
                 if (av == Double.POSITIVE_INFINITY) {
                     // Compute in polar coords.
                     // This handles extreme values that fail in the cartesian 
representation.
@@ -1747,19 +1754,6 @@ public final class Complex implements Serializable  {
     }
 
     /**
-     * Compute {@code (a + b) / 2} without overflow.
-     *
-     * @param a the a
-     * @param b the b
-     * @return the average
-     */
-    private static double average(double a, double b) {
-        return (a < b) ?
-                a + (b - a) / 2 :
-                b + (a - b) / 2;
-    }
-
-    /**
      * Compute the
      * <a href="http://mathworld.wolfram.com/Tangent.html";>
      * tangent</a> of this complex number.

Reply via email to