Re: [1/2] commons-numbers git commit: NUMBERS-13: atanh() passes all tests

2017-07-28 Thread Gilles

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 -, ericbarnh...@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 
Authored: Fri Jul 28 13:24:12 2017 +0200
Committer: Eric Barnhill 
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)) {
+re

Re: commons-numbers git commit: NUMBERS-13: atanh() passes all tests

2017-07-11 Thread Gilles

Hi Eric.

On Tue, 11 Jul 2017 07:27:42 + (UTC), ericbarnh...@apache.org 
wrote:

Repository: commons-numbers
Updated Branches:
  refs/heads/complex-dev ade98aa18 -> 48464a3cf


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/48464a3c
Tree: 
http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/48464a3c
Diff: 
http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/48464a3c


Branch: refs/heads/complex-dev
Commit: 48464a3cf57e8a62d97e8c8741cadad23406e4ea
Parents: ade98aa
Author: Eric Barnhill 
Authored: Tue Jul 11 09:29:11 2017 +0200
Committer: Eric Barnhill 
Committed: Tue Jul 11 09:29:11 2017 +0200


--
 .../apache/commons/numbers/complex/Complex.java | 25 
++--

 1 file changed, 23 insertions(+), 2 deletions(-)

--



http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/48464a3c/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 d3d8aa8..e4c0a71 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
@@ -643,7 +643,7 @@ in the
 public Complex acos() {
 if (real == 0 && Double.isNaN(imaginary)) {
 return new Complex(Math.PI * 0.5, Double.NaN);
-} else if (!Double.isNaN(real) && !Double.isInfinite(real)
&& imaginary == Double.POSITIVE_INFINITY) {
+} else if (neitherInfiniteNorZeroNorNaN(real) && imaginary
== Double.POSITIVE_INFINITY) {
 return new Complex(Math.PI * 0.5, 
Double.NEGATIVE_INFINITY);
 } else if (real == Double.NEGATIVE_INFINITY && imaginary == 
1) {

 return new Complex(Math.PI, Double.NEGATIVE_INFINITY);
@@ -701,7 +701,7 @@ in the
  * @since 1.2
  */
 public Complex asinh(){
-if (!Double.isNaN(real) && !Double.isInfinite(real) &&
imaginary == Double.POSITIVE_INFINITY) {
+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);
@@ -729,6 +729,21 @@ in the
  * @since 1.2
  */
 public Complex atanh(){
+if (real == 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
== Double.POSITIVE_INFINITY) {
+return new Complex(0, Math.PI*0.5);
+} else if (real == Double.POSITIVE_INFINITY &&
neitherInfiniteNorZeroNorNaN(imaginary)) {
+return new Complex(0, Math.PI*0.5);
+} else if (real == Double.POSITIVE_INFINITY && imaginary ==
Double.POSITIVE_INFINITY) {
+return new Complex(0, Math.PI*0.5);
+} else if (real == Double.POSITIVE_INFINITY &&
Double.isNaN(imaginary)) {
+return new Complex(0, Double.NaN);
+} else if (Double.isNaN(real) && imaginary ==
Double.POSITIVE_INFINITY) {
+return new Complex(0, Math.PI*0.5);
+}
 return

this.add(Complex.ONE).divide(Complex.ONE.subtract(this)).log().divide(new
Complex(2));
 }


The amount of repeated
  Math.PI*0.5
asks for a named constant:
  private static double HALF_PI = Math.PI / 2;


/**
@@ -1225,4 +1240,10 @@ in the
 private static boolean equals(double x, double y) {
 return new Double(x).equals(new Double(y));
 }
+
+private static boolean neitherInfiniteNorZeroNorNaN(double d) {
+if (!Double.isNaN(d) && !Double.isInfinite(d) && d != 0) {
+return true;
+} else return false;
+}
 }


private static boolean neitherInfiniteNorZeroNorNaN(double d) {
return !Double.isNaN(d) &&
!Double.isInfinite(d) &&
d != 0;
}

Perhaps the "d != 0" should come first (?).

Regards,
Gilles


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