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/master Commit: 48464a3cf57e8a62d97e8c8741cadad23406e4ea Parents: ade98aa Author: Eric Barnhill <ericbarnh...@apache.org> Authored: Tue Jul 11 09:29:11 2017 +0200 Committer: Eric Barnhill <ericbarnh...@apache.org> 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)); } /** @@ -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; + } }