commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilles <gil...@harfang.homelinux.org>
Subject Re: [1/2] commons-numbers git commit: NUMBERS-13: atanh() passes all tests
Date Fri, 28 Jul 2017 12:46:48 GMT
Hi Eric.

Changing
   0 -> 0.0
is not necessary, and since the latter is less esthetically pleasing,
why bother?
And, as usual, we should avoid mixing different types of changes in
the same commit.

Regards,
Gilles

On Fri, 28 Jul 2017 11:34:47 -0000, ericbarnhill@apache.org wrote:
> Repository: commons-numbers
> Updated Branches:
>   refs/heads/complex-dev af5fc05bb -> 387f4e09b
>
>
> NUMBERS-13: atanh() passes all tests
>
>
> Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
> Commit:
> 
> http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/a9437c90
> Tree: 
> http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/a9437c90
> Diff: 
> http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/a9437c90
>
> Branch: refs/heads/complex-dev
> Commit: a9437c90666ca8c3045f1d59de1b77e536addba6
> Parents: af5fc05
> Author: Eric Barnhill <ericbarnhill@apache.org>
> Authored: Fri Jul 28 13:24:12 2017 +0200
> Committer: Eric Barnhill <ericbarnhill@apache.org>
> Committed: Fri Jul 28 13:24:12 2017 +0200
>
> 
> ----------------------------------------------------------------------
>  .../apache/commons/numbers/complex/Complex.java | 75 
> +++++++++++---------
>  .../commons/numbers/complex/CStandardTest.java  |  4 +-
>  2 files changed, 44 insertions(+), 35 deletions(-)
> 
> ----------------------------------------------------------------------
>
>
> 
> http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a9437c90/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
> 
> ----------------------------------------------------------------------
> 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 fc3ff93..5a77a9f 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
> @@ -641,7 +641,7 @@ in the
>       * @return the inverse cosine of this complex number.
>       */
>      public Complex acos() {
> -        if (real == 0 && Double.isNaN(imaginary)) {
> +        if (real == 0.0&& Double.isNaN(imaginary)) {
>              return new Complex(Math.PI * 0.5, Double.NaN);
>          } else if (neitherInfiniteNorZeroNorNaN(real) && imaginary
> == Double.POSITIVE_INFINITY) {
>              return new Complex(Math.PI * 0.5, 
> Double.NEGATIVE_INFINITY);
> @@ -704,13 +704,13 @@ in the
>          if (neitherInfiniteNorZeroNorNaN(real) && imaginary ==
> Double.POSITIVE_INFINITY) {
>              return new Complex(Double.POSITIVE_INFINITY, Math.PI * 
> 0.5);
>          } else if (real == Double.POSITIVE_INFINITY &&
> !Double.isInfinite(imaginary) && !Double.isNaN(imaginary)) {
> -            return new Complex(Double.POSITIVE_INFINITY, 0);
> +            return new Complex(Double.POSITIVE_INFINITY, 0.0);
>          } else if (real == Double.POSITIVE_INFINITY && imaginary ==
> Double.POSITIVE_INFINITY) {
>              return new Complex(Double.POSITIVE_INFINITY, Math.PI * 
> 0.25);
>          } else if (real == Double.POSITIVE_INFINITY &&
> Double.isNaN(imaginary)) {
>              return new Complex(Double.POSITIVE_INFINITY,  
> Double.NaN);
> -        } else if (Double.isNaN(real) && imaginary == 0) {
> -            return new Complex(Double.NaN, 0);
> +        } else if (Double.isNaN(real) && imaginary == 0.0) {
> +            return new Complex(Double.NaN, 0.0);
>          } else if (Double.isNaN(real) && imaginary ==
> Double.POSITIVE_INFINITY) {
>              return new Complex(Double.POSITIVE_INFINITY, 
> Double.NaN);
>          }
> @@ -729,10 +729,10 @@ in the
>       * @since 1.2
>       */
>      public Complex atanh(){
> -        if (real == 0  && Double.isNaN(imaginary)) {
> +        if (real == 0.0 && Double.isNaN(imaginary)) {
>              return new Complex(0, Double.NaN);
> -        } else if (neitherInfiniteNorZeroNorNaN(real) && imaginary 
> == 0) {
> -            return new Complex(Double.POSITIVE_INFINITY, 0);
> +        } else if (neitherInfiniteNorZeroNorNaN(real) && imaginary 
> == 0.0) {
> +            return new Complex(Double.POSITIVE_INFINITY, 0.0);
>          } else if (neitherInfiniteNorZeroNorNaN(real) && imaginary
> == Double.POSITIVE_INFINITY) {
>              return new Complex(0, Math.PI*0.5);
>          } else if (real == Double.POSITIVE_INFINITY &&
> neitherInfiniteNorZeroNorNaN(imaginary)) {
> @@ -808,18 +808,18 @@ in the
>       * @return the hyperbolic cosine of this complex number.
>       */
>      public Complex cosh() {
> -        if (real == 0 && imaginary == Double.POSITIVE_INFINITY) {
> -            return new Complex(Double.NaN, 0);
> -        } else if (real == 0 && Double.isNaN(imaginary)) {
> -            return new Complex(Double.NaN, 0);
> -        } else if (real == Double.POSITIVE_INFINITY && imaginary == 
> 0) {
> -            return new Complex(Double.POSITIVE_INFINITY, 0);
> +        if (real == 0.0&& imaginary == Double.POSITIVE_INFINITY) {
> +            return new Complex(Double.NaN, 0.0);
> +        } else if (real == 0.0&& Double.isNaN(imaginary)) {
> +            return new Complex(Double.NaN, 0.0);
> +        } else if (real == Double.POSITIVE_INFINITY && imaginary == 
> 0.0) {
> +            return new Complex(Double.POSITIVE_INFINITY, 0.0);
>          } else if (real == Double.POSITIVE_INFINITY && imaginary ==
> Double.POSITIVE_INFINITY) {
>              return new Complex(Double.POSITIVE_INFINITY, 
> Double.NaN);
>          } else if (real == Double.POSITIVE_INFINITY &&
> Double.isNaN(imaginary)) {
>              return new Complex(Double.POSITIVE_INFINITY, 
> Double.NaN);
> -        } else if (Double.isNaN(real) && imaginary == 0) {
> -            return new Complex(Double.NaN, 0);
> +        } else if (Double.isNaN(real) && imaginary == 0.0) {
> +            return new Complex(Double.NaN, 0.0);
>          }
>
>          return new Complex(Math.cosh(real) * Math.cos(imaginary),
> @@ -843,8 +843,8 @@ in the
>       * @return <code><i>e</i><sup>this</sup></code>.
>       */
>      public Complex exp() {
> -        if (real == Double.POSITIVE_INFINITY && imaginary == 0) {
> -            return new Complex(Double.POSITIVE_INFINITY, 0);
> +        if (real == Double.POSITIVE_INFINITY && imaginary == 0.0) {
> +            return new Complex(Double.POSITIVE_INFINITY, 0.0);
>          } else if (real == Double.NEGATIVE_INFINITY && imaginary ==
> Double.POSITIVE_INFINITY) {
>              return Complex.ZERO;
>          } else if (real == Double.POSITIVE_INFINITY && imaginary ==
> Double.POSITIVE_INFINITY) {
> @@ -853,8 +853,8 @@ in the
>              return Complex.ZERO;
>          } else if (real == Double.POSITIVE_INFINITY &&
> Double.isNaN(imaginary)) {
>              return new Complex(Double.POSITIVE_INFINITY, 
> Double.NaN);
> -        } else if (Double.isNaN(real) && imaginary == 0) {
> -            return new Complex(Double.NaN, 0);
> +        } else if (Double.isNaN(real) && imaginary == 0.0) {
> +            return new Complex(Double.NaN, 0.0);
>          }
>          double expReal = Math.exp(real);
>          return new Complex(expReal *  Math.cos(imaginary),
> @@ -918,8 +918,8 @@ in the
>       */
>      public Complex pow(Complex x) {
>          checkNotNull(x);
> -        if (real == 0 && imaginary == 0) {
> -            if (x.real > 0 && x.imaginary == 0) {
> +        if (real == 0.0&& imaginary == 0.0) {
> +            if (x.real > 0 && x.imaginary == 0.0) {
>                  // 0 raised to positive number is 0
>                  return ZERO;
>              } else {
> @@ -938,7 +938,7 @@ in the
>       * @see #pow(Complex)
>       */
>       public Complex pow(double x) {
> -        if (real == 0 && imaginary == 0) {
> +        if (real == 0.0&& imaginary == 0.0) {
>              if (x > 0) {
>                  // 0 raised to positive number is 0
>                  return ZERO;
> @@ -989,20 +989,20 @@ in the
>       * @return the hyperbolic sine of {@code this}.
>       */
>      public Complex sinh() {
> -        if (real == 0 && imaginary == 0) {
> +        if (real == 0.0&& imaginary == 0.0) {
>              return Complex.ZERO;
> -        } else if (real == 0 && imaginary == 
> Double.POSITIVE_INFINITY) {
> +        } else if (real == 0.0&& imaginary == 
> Double.POSITIVE_INFINITY) {
>              return new Complex(0, Double.NaN);
> -        } else if (real == 0 && Double.isNaN(imaginary)) {
> +        } else if (real == 0.0&& Double.isNaN(imaginary)) {
>              return new Complex(0, Double.NaN);
> -        } else if (real == Double.POSITIVE_INFINITY && imaginary == 
> 0) {
> -            return new Complex(Double.POSITIVE_INFINITY, 0);
> +        } else if (real == Double.POSITIVE_INFINITY && imaginary == 
> 0.0) {
> +            return new Complex(Double.POSITIVE_INFINITY, 0.0);
>          } else if (real == Double.POSITIVE_INFINITY && imaginary ==
> Double.POSITIVE_INFINITY) {
>              return new Complex(Double.POSITIVE_INFINITY, 
> Double.NaN);
>          } else if (real == Double.POSITIVE_INFINITY &&
> Double.isNaN(imaginary)) {
>              return new Complex(Double.POSITIVE_INFINITY, 
> Double.NaN);
> -        } else if (Double.isNaN(real) && imaginary == 0) {
> -            return new Complex(Double.NaN, 0);
> +        } else if (Double.isNaN(real) && imaginary == 0.0) {
> +            return new Complex(Double.NaN, 0.0);
>          }
>          return new Complex(Math.sinh(real) * Math.cos(imaginary),
>              Math.cosh(real) * Math.sin(imaginary));
> @@ -1028,6 +1028,14 @@ in the
>      public Complex sqrt() {
>          if (real == 0.0 && imaginary == 0.0) {
>              return new Complex(0.0, 0.0);
> +        } else if (neitherInfiniteNorZeroNorNaN(real) && imaginary
> == Double.POSITIVE_INFINITY) {
> +            return new Complex(Double.POSITIVE_INFINITY,
> Double.POSITIVE_INFINITY);
> +        } else if (real == Double.NEGATIVE_INFINITY &&
> neitherInfiniteNorZeroNorNaN(imaginary)) {
> +            return new Complex(0.0, Double.NaN);
> +        } else if (real == Double.NEGATIVE_INFINITY &&
> Double.isNaN(imaginary)) {
> +            return new Complex(Double.NaN, 
> Double.POSITIVE_INFINITY);
> +        } else if (real == Double.POSITIVE_INFINITY &&
> Double.isNaN(imaginary)) {
> +            return new Complex(Double.POSITIVE_INFINITY, 
> Double.NaN);
>          }
>
>          double t = Math.sqrt((Math.abs(real) + abs()) / 2.0);
> @@ -1102,11 +1110,12 @@ in the
>       * @return the hyperbolic tangent of {@code this}.
>       */
>      public Complex tanh() {
> -        if (real > 20.0) {
> +        if (real == Double.POSITIVE_INFINITY && imaginary ==
> Double.POSITIVE_INFINITY) {
>              return new Complex(1.0, 0.0);
> -        }
> -        if (real < -20.0) {
> -            return new Complex(-1.0, 0.0);
> +        } else if (real == Double.POSITIVE_INFINITY &&
> Double.isNaN(imaginary)) {
> +            return new Complex(1.0, 0.0);
> +        } else if (Double.isNaN(real) && imaginary == 0) {
> +            return new Complex(Double.NaN, 0);
>          }
>          double real2 = 2.0 * real;
>          double imaginary2 = 2.0 * imaginary;
>
> 
> http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a9437c90/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CStandardTest.java
> 
> ----------------------------------------------------------------------
> diff --git
> 
> a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CStandardTest.java
> 
> b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CStandardTest.java
> index 1ca0106..6ec5460 100644
> ---
> 
> a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CStandardTest.java
> +++
> 
> b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/CStandardTest.java
> @@ -96,14 +96,14 @@ public class CStandardTest {
>
>      @Test
>      public void testImplicitTrig() {
> -        Complex z1 = new Complex(3.0);
> +        Complex z1 = new Complex(1.0);
>          Complex z2 = new Complex(0.0, 3.0);
>          assertComplex(z1.asin(), negI.multiply(z2.asinh()));
>          assertComplex(z1.atan(), negI.multiply(z2.atanh()),
> Math.ulp(1), Math.ulp(1));
>          assertComplex(z1.cos(), z2.cosh());
>          assertComplex(z1.sin(), negI.multiply(z2.sinh()));
>          // CURRENTLY FAILS BELOW TEST
> -        // assertComplex(z1.tan(), negI.multiply(z1.tanh()));
> +        assertComplex(z1.tan(), negI.multiply(z1.tanh()));
>      }
>
>      /**


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message