This is an automated email from the ASF dual-hosted git repository. erans pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-numbers.git
commit 1112388285df80a39dd2ee781da6c81428642df1 Author: Gilles Sadowski <[email protected]> AuthorDate: Sun Sep 29 03:31:27 2019 +0200 Named constants. --- .../apache/commons/numbers/complex/Complex.java | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 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 dc69104..df581a9 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 @@ -54,6 +54,10 @@ public final class Complex implements Serializable { public static final Complex ZERO = new Complex(0, 0); /** A complex number representing "NaN + NaN i" */ private static final Complex NAN = new Complex(Double.NaN, Double.NaN); + /** π/2. */ + private static final double PI_OVER_2 = 0.5 * Math.PI; + /** π/4. */ + private static final double PI_OVER_4 = 0.25 * Math.PI; /** Serializable version identifier. */ private static final long serialVersionUID = 20180201L; @@ -721,10 +725,10 @@ public final class Complex implements Serializable { public Complex acos() { if (real == 0 && Double.isNaN(imaginary)) { - return new Complex(Math.PI * 0.5, Double.NaN); + return new Complex(PI_OVER_2, Double.NaN); } else if (neitherInfiniteNorZeroNorNaN(real) && imaginary == Double.POSITIVE_INFINITY) { - return new Complex(Math.PI * 0.5, Double.NEGATIVE_INFINITY); + return new Complex(PI_OVER_2, Double.NEGATIVE_INFINITY); } else if (real == Double.NEGATIVE_INFINITY && imaginary == 1) { return new Complex(Math.PI, Double.NEGATIVE_INFINITY); @@ -736,7 +740,7 @@ public final class Complex implements Serializable { return new Complex(Math.PI * 0.75, Double.NEGATIVE_INFINITY); } else if (real == Double.POSITIVE_INFINITY && imaginary == Double.POSITIVE_INFINITY) { - return new Complex(Math.PI * 0.25, Double.NEGATIVE_INFINITY); + return new Complex(PI_OVER_4, Double.NEGATIVE_INFINITY); } else if (real == Double.POSITIVE_INFINITY && Double.isNaN(imaginary)) { return new Complex(Double.NaN , Double.POSITIVE_INFINITY); @@ -788,13 +792,13 @@ public final class Complex implements Serializable { public Complex asinh(){ if (neitherInfiniteNorZeroNorNaN(real) && imaginary == Double.POSITIVE_INFINITY) { - return new Complex(Double.POSITIVE_INFINITY, Math.PI * 0.5); + return new Complex(Double.POSITIVE_INFINITY, PI_OVER_2); } else if (real == Double.POSITIVE_INFINITY && !Double.isInfinite(imaginary) && !Double.isNaN(imaginary)) { return new Complex(Double.POSITIVE_INFINITY, 0); } else if (real == Double.POSITIVE_INFINITY && imaginary == Double.POSITIVE_INFINITY) { - return new Complex(Double.POSITIVE_INFINITY, Math.PI * 0.25); + return new Complex(Double.POSITIVE_INFINITY, PI_OVER_4); } else if (real == Double.POSITIVE_INFINITY && Double.isNaN(imaginary)) { return new Complex(Double.POSITIVE_INFINITY, Double.NaN); @@ -827,19 +831,19 @@ public final class Complex implements Serializable { return new Complex(Double.POSITIVE_INFINITY, 0); } else if (neitherInfiniteNorZeroNorNaN(real) && imaginary == Double.POSITIVE_INFINITY) { - return new Complex(0, Math.PI * 0.5); + return new Complex(0, PI_OVER_2); } else if (real == Double.POSITIVE_INFINITY && neitherInfiniteNorZeroNorNaN(imaginary)) { - return new Complex(0, Math.PI * 0.5); + return new Complex(0, PI_OVER_2); } else if (real == Double.POSITIVE_INFINITY && imaginary == Double.POSITIVE_INFINITY) { - return new Complex(0, Math.PI * 0.5); + return new Complex(0, PI_OVER_2); } 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 new Complex(0, PI_OVER_2); } return add(ONE).divide(ONE.subtract(this)).log().multiply(0.5); } @@ -989,7 +993,7 @@ public final class Complex implements Serializable { public Complex log() { if (real == Double.POSITIVE_INFINITY && imaginary == Double.POSITIVE_INFINITY) { - return new Complex(Double.POSITIVE_INFINITY, Math.PI * 0.25); + return new Complex(Double.POSITIVE_INFINITY, PI_OVER_4); } else if (real == Double.POSITIVE_INFINITY && Double.isNaN(imaginary)) { return new Complex(Double.POSITIVE_INFINITY, Double.NaN);
