You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2018/02/01 14:08:53 UTC
[01/14] commons-numbers git commit: Use more specific exception type.
Repository: commons-numbers
Updated Branches:
refs/heads/master 2d1f76767 -> 1b2eb2220
Use more specific exception type.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/393cf663
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/393cf663
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/393cf663
Branch: refs/heads/master
Commit: 393cf6636de3bac72d09c60b900b2b124fa40e18
Parents: 2d1f767
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Thu Feb 1 12:19:49 2018 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Thu Feb 1 12:19:49 2018 +0100
----------------------------------------------------------------------
.../main/java/org/apache/commons/numbers/complex/Complex.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/393cf663/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 99888f2..be58584 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
@@ -1175,7 +1175,7 @@ public class Complex implements Serializable {
public List<Complex> nthRoot(int n) {
if (n <= 0) {
- throw new RuntimeException("cannot compute nth root for null or negative n: {0}");
+ throw new IllegalArgumentException("cannot compute nth root for null or negative n: {0}");
}
final List<Complex> result = new ArrayList<Complex>();
@@ -1257,7 +1257,7 @@ public class Complex implements Serializable {
*/
private static void checkNotNull(Object o) {
if (o == null) {
- throw new RuntimeException("Null Argument to Complex Method");
+ throw new IllegalArgumentException("Null Argument to Complex Method");
}
}
@@ -1268,7 +1268,7 @@ public class Complex implements Serializable {
*/
private static void checkNotNegative(double arg) {
if (arg <= 0) {
- throw new RuntimeException("Complex: Non-positive argument");
+ throw new IllegalArgumentException("Complex: Non-positive argument");
}
}
[02/14] commons-numbers git commit: Alignment (nit-picks).
Posted by er...@apache.org.
Alignment (nit-picks).
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/e42ec505
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/e42ec505
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/e42ec505
Branch: refs/heads/master
Commit: e42ec505d2899d3fd239c01dc01a0c3d71302b4b
Parents: 393cf66
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Thu Feb 1 12:43:34 2018 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Thu Feb 1 12:43:34 2018 +0100
----------------------------------------------------------------------
.../apache/commons/numbers/complex/Complex.java | 213 ++++++++++++-------
1 file changed, 137 insertions(+), 76 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/e42ec505/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 be58584..9b4508a 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
@@ -133,7 +133,8 @@ public class Complex implements Serializable {
* @return {@code boolean}
*/
public boolean isNaN() {
- if (Double.isNaN(real) || Double.isNaN(imaginary)) {
+ if (Double.isNaN(real) ||
+ Double.isNaN(imaginary)) {
return true;
} else {
return false;
@@ -166,7 +167,8 @@ public class Complex implements Serializable {
* @return {@code Complex} projected onto the Riemann sphere.
*/
public Complex proj() {
- if (Double.isInfinite(real) || Double.isInfinite(imaginary)) {
+ if (Double.isInfinite(real) ||
+ Double.isInfinite(imaginary)) {
return new Complex(Double.POSITIVE_INFINITY);
} else {
return this;
@@ -299,11 +301,15 @@ public class Complex implements Serializable {
final double c = divisor.getReal();
final double d = divisor.getImaginary();
- if (c == 0.0 && d == 0.0) {
+ if (c == 0.0 &&
+ d == 0.0) {
return NaN;
}
- if ( (Double.isInfinite(c) || Double.isInfinite(d))&& (Double.isInfinite(real) || Double.isInfinite(imaginary))) {
+ if ((Double.isInfinite(c) ||
+ Double.isInfinite(d)) &&
+ (Double.isInfinite(real) ||
+ Double.isInfinite(imaginary))) {
return ZERO;
}
@@ -311,12 +317,12 @@ public class Complex implements Serializable {
final double q = c / d;
final double denominator = c * q + d;
return new Complex((real * q + imaginary) / denominator,
- (imaginary * q - real) / denominator);
+ (imaginary * q - real) / denominator);
} else {
final double q = d / c;
final double denominator = d * q + c;
return new Complex((imaginary * q + real) / denominator,
- (imaginary - real * q) / denominator);
+ (imaginary - real * q) / denominator);
}
}
@@ -333,10 +339,11 @@ public class Complex implements Serializable {
return NaN;
}
if (Double.isInfinite(divisor)) {
- return !(Double.isInfinite(real) || Double.isInfinite(imaginary)) ? ZERO : NaN;
+ return !(Double.isInfinite(real) ||
+ Double.isInfinite(imaginary)) ? ZERO : NaN;
}
return new Complex(real / divisor,
- imaginary / divisor);
+ imaginary / divisor);
}
/**
@@ -350,7 +357,8 @@ public class Complex implements Serializable {
final double q = real / imaginary;
final double scale = 1. / (real * q + imaginary);
double scaleQ = 0;
- if (q != 0 && scale != 0) {
+ if (q != 0 &&
+ scale != 0) {
scaleQ = scale * q;
}
return new Complex(scaleQ, -scale);
@@ -358,7 +366,8 @@ public class Complex implements Serializable {
final double q = imaginary / real;
final double scale = 1. / (imaginary * q + real);
double scaleQ = 0;
- if (q != 0 && scale != 0) {
+ if (q != 0 &&
+ scale != 0) {
scaleQ = scale * q;
}
return new Complex(scale, -scaleQ);
@@ -397,7 +406,7 @@ public class Complex implements Serializable {
if (other instanceof Complex){
Complex c = (Complex) other;
return equals(real, c.real) &&
- equals(imaginary, c.imaginary);
+ equals(imaginary, c.imaginary);
}
return false;
}
@@ -418,7 +427,9 @@ public class Complex implements Serializable {
*
* @see Precision#equals(double,double,int)
*/
- public static boolean equals(Complex x, Complex y, int maxUlps) {
+ public static boolean equals(Complex x,
+ Complex y,
+ int maxUlps) {
return Precision.equals(x.real, y.real, maxUlps) &&
Precision.equals(x.imaginary, y.imaginary, maxUlps);
}
@@ -431,7 +442,8 @@ public class Complex implements Serializable {
* @param y Second value (cannot be {@code null}).
* @return {@code true} if the values are equal.
*/
- public static boolean equals(Complex x, Complex y) {
+ public static boolean equals(Complex x,
+ Complex y) {
return equals(x, y, 1);
}
@@ -449,7 +461,9 @@ public class Complex implements Serializable {
*
* @see Precision#equals(double,double,double)
*/
- public static boolean equals(Complex x, Complex y, double eps) {
+ public static boolean equals(Complex x,
+ Complex y,
+ double eps) {
return Precision.equals(x.real, y.real, eps) &&
Precision.equals(x.imaginary, y.imaginary, eps);
}
@@ -483,7 +497,8 @@ public class Complex implements Serializable {
*/
@Override
public int hashCode() {
- if (Double.isNaN(real) || Double.isNaN(imaginary)) {
+ if (Double.isNaN(real) ||
+ Double.isNaN(imaginary)) {
return 7;
}
return 37 * (17 * hash(imaginary) + hash(real));
@@ -495,7 +510,7 @@ public class Complex implements Serializable {
*/
private int hash(double d) {
final long v = Double.doubleToLongBits(d);
- return (int)(v^(v>>>32));
+ return (int) (v ^ (v >>> 32));
//return new Double(d).hashCode();
}
@@ -610,7 +625,7 @@ public class Complex implements Serializable {
public Complex subtract(Complex subtrahend) {
checkNotNull(subtrahend);
return new Complex(real - subtrahend.getReal(),
- imaginary - subtrahend.getImaginary());
+ imaginary - subtrahend.getImaginary());
}
/**
@@ -639,21 +654,29 @@ public class Complex implements Serializable {
public Complex acos() {
if (real == 0.0&& Double.isNaN(imaginary)) {
return new Complex(Math.PI * 0.5, Double.NaN);
- } else if (neitherInfiniteNorZeroNorNaN(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) {
+ } else if (real == Double.NEGATIVE_INFINITY &&
+ imaginary == 1) {
return new Complex(Math.PI, Double.NEGATIVE_INFINITY);
- } else if (real == Double.POSITIVE_INFINITY && imaginary == 1) {
+ } else if (real == Double.POSITIVE_INFINITY &&
+ imaginary == 1) {
return new Complex(0, Double.NEGATIVE_INFINITY);
- } else if (real == Double.NEGATIVE_INFINITY && imaginary == Double.POSITIVE_INFINITY) {
+ } else if (real == Double.NEGATIVE_INFINITY &&
+ imaginary == Double.POSITIVE_INFINITY) {
return new Complex(Math.PI * 0.75, Double.NEGATIVE_INFINITY);
- } else if (real == Double.POSITIVE_INFINITY && imaginary == Double.POSITIVE_INFINITY) {
+ } else if (real == Double.POSITIVE_INFINITY &&
+ imaginary == Double.POSITIVE_INFINITY) {
return new Complex(Math.PI * 0.25, Double.NEGATIVE_INFINITY);
- } else if (real == Double.POSITIVE_INFINITY && Double.isNaN(imaginary)) {
+ } else if (real == Double.POSITIVE_INFINITY &&
+ Double.isNaN(imaginary)) {
return new Complex(Double.NaN , Double.POSITIVE_INFINITY);
- } else if (real == Double.NEGATIVE_INFINITY && Double.isNaN(imaginary)) {
+ } else if (real == Double.NEGATIVE_INFINITY &&
+ Double.isNaN(imaginary)) {
return new Complex(Double.NaN, Double.NEGATIVE_INFINITY);
- } else if (Double.isNaN(real) && imaginary == Double.POSITIVE_INFINITY) {
+ } else if (Double.isNaN(real) &&
+ imaginary == Double.POSITIVE_INFINITY) {
return new Complex(Double.NaN, Double.NEGATIVE_INFINITY);
}
return this.add(this.sqrt1z().multiply(I)).log().multiply(I.negate());
@@ -682,7 +705,7 @@ public class Complex implements Serializable {
*/
public Complex atan() {
return this.add(I).divide(I.subtract(this)).log()
- .multiply(I.divide(createComplex(2.0, 0.0)));
+ .multiply(I.divide(createComplex(2.0, 0.0)));
}
/**
@@ -697,17 +720,23 @@ public class Complex implements Serializable {
* @since 1.2
*/
public Complex asinh(){
- if (neitherInfiniteNorZeroNorNaN(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)) {
+ } else if (real == Double.POSITIVE_INFINITY &&
+ !Double.isInfinite(imaginary) && !Double.isNaN(imaginary)) {
return new Complex(Double.POSITIVE_INFINITY, 0.0);
- } else if (real == Double.POSITIVE_INFINITY && imaginary == Double.POSITIVE_INFINITY) {
+ } 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)) {
+ } else if (real == Double.POSITIVE_INFINITY &&
+ Double.isNaN(imaginary)) {
return new Complex(Double.POSITIVE_INFINITY, Double.NaN);
- } else if (Double.isNaN(real) && imaginary == 0.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) {
+ } else if (Double.isNaN(real) &&
+ imaginary == Double.POSITIVE_INFINITY) {
return new Complex(Double.POSITIVE_INFINITY, Double.NaN);
}
return square().add(Complex.ONE).sqrt().add(this).log();
@@ -783,7 +812,7 @@ public class Complex implements Serializable {
*/
public Complex cos() {
return new Complex(Math.cos(real) * Math.cosh(imaginary),
- -Math.sin(real) * Math.sinh(imaginary));
+ -Math.sin(real) * Math.sinh(imaginary));
}
/**
@@ -804,22 +833,28 @@ public class Complex implements Serializable {
* @return the hyperbolic cosine of this complex number.
*/
public Complex cosh() {
- if (real == 0.0&& imaginary == Double.POSITIVE_INFINITY) {
+ if (real == 0.0 &&
+ imaginary == Double.POSITIVE_INFINITY) {
return new Complex(Double.NaN, 0.0);
- } else if (real == 0.0&& Double.isNaN(imaginary)) {
+ } else if (real == 0.0 &&
+ Double.isNaN(imaginary)) {
return new Complex(Double.NaN, 0.0);
- } else if (real == Double.POSITIVE_INFINITY && imaginary == 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) {
+ } 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)) {
+ } else if (real == Double.POSITIVE_INFINITY &&
+ Double.isNaN(imaginary)) {
return new Complex(Double.POSITIVE_INFINITY, Double.NaN);
- } else if (Double.isNaN(real) && imaginary == 0.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),
- Math.sinh(real) * Math.sin(imaginary));
+ Math.sinh(real) * Math.sin(imaginary));
}
/**
@@ -839,22 +874,28 @@ public class Complex implements Serializable {
* @return <code><i>e</i><sup>this</sup></code>.
*/
public Complex exp() {
- if (real == Double.POSITIVE_INFINITY && imaginary == 0.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) {
+ } else if (real == Double.NEGATIVE_INFINITY &&
+ imaginary == Double.POSITIVE_INFINITY) {
return Complex.ZERO;
- } else if (real == Double.POSITIVE_INFINITY && imaginary == Double.POSITIVE_INFINITY) {
+ } else if (real == Double.POSITIVE_INFINITY &&
+ imaginary == Double.POSITIVE_INFINITY) {
return new Complex(Double.POSITIVE_INFINITY, Double.NaN);
- } else if (real == Double.NEGATIVE_INFINITY && Double.isNaN(imaginary)) {
+ } else if (real == Double.NEGATIVE_INFINITY &&
+ Double.isNaN(imaginary)) {
return Complex.ZERO;
- } else if (real == Double.POSITIVE_INFINITY && Double.isNaN(imaginary)) {
+ } else if (real == Double.POSITIVE_INFINITY &&
+ Double.isNaN(imaginary)) {
return new Complex(Double.POSITIVE_INFINITY, Double.NaN);
- } else if (Double.isNaN(real) && imaginary == 0.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),
- expReal * Math.sin(imaginary));
+ expReal * Math.sin(imaginary));
}
/**
@@ -875,15 +916,18 @@ public class Complex implements Serializable {
* of {@code this}.
*/
public Complex log() {
- if (real == Double.POSITIVE_INFINITY && imaginary == Double.POSITIVE_INFINITY) {
+ 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)) {
+ } else if (real == Double.POSITIVE_INFINITY &&
+ Double.isNaN(imaginary)) {
return new Complex(Double.POSITIVE_INFINITY, Double.NaN);
- } else if (Double.isNaN(real) && imaginary == Double.POSITIVE_INFINITY) {
+ } else if (Double.isNaN(real) &&
+ imaginary == Double.POSITIVE_INFINITY) {
return new Complex(Double.POSITIVE_INFINITY, Double.NaN);
}
return new Complex(Math.log(abs()),
- Math.atan2(imaginary, real));
+ Math.atan2(imaginary, real));
}
/**
@@ -895,7 +939,7 @@ public class Complex implements Serializable {
*/
public Complex log10() {
return new Complex(Math.log(abs())/Math.log(10),
- Math.atan2(imaginary, real));
+ Math.atan2(imaginary, real));
}
/**
@@ -914,8 +958,10 @@ public class Complex implements Serializable {
*/
public Complex pow(Complex x) {
checkNotNull(x);
- if (real == 0.0&& imaginary == 0.0) {
- if (x.real > 0 && x.imaginary == 0.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 {
@@ -934,7 +980,8 @@ public class Complex implements Serializable {
* @see #pow(Complex)
*/
public Complex pow(double x) {
- if (real == 0.0&& imaginary == 0.0) {
+ if (real == 0.0 &&
+ imaginary == 0.0) {
if (x > 0) {
// 0 raised to positive number is 0
return ZERO;
@@ -965,7 +1012,7 @@ public class Complex implements Serializable {
*/
public Complex sin() {
return new Complex(Math.sin(real) * Math.cosh(imaginary),
- Math.cos(real) * Math.sinh(imaginary));
+ Math.cos(real) * Math.sinh(imaginary));
}
/**
@@ -985,23 +1032,30 @@ public class Complex implements Serializable {
* @return the hyperbolic sine of {@code this}.
*/
public Complex sinh() {
- if (real == 0.0&& imaginary == 0.0) {
+ if (real == 0.0 &&
+ imaginary == 0.0) {
return Complex.ZERO;
- } else if (real == 0.0&& imaginary == Double.POSITIVE_INFINITY) {
+ } else if (real == 0.0 &&
+ imaginary == Double.POSITIVE_INFINITY) {
return new Complex(0, Double.NaN);
- } else if (real == 0.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.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) {
+ } 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)) {
+ } else if (real == Double.POSITIVE_INFINITY &&
+ Double.isNaN(imaginary)) {
return new Complex(Double.POSITIVE_INFINITY, Double.NaN);
- } else if (Double.isNaN(real) && imaginary == 0.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));
+ Math.cosh(real) * Math.sin(imaginary));
}
/**
@@ -1022,15 +1076,20 @@ public class Complex implements Serializable {
* @return the square root of {@code this}.
*/
public Complex sqrt() {
- if (real == 0.0 && imaginary == 0.0) {
+ if (real == 0.0 &&
+ imaginary == 0.0) {
return new Complex(0.0, 0.0);
- } else if (neitherInfiniteNorZeroNorNaN(real) && imaginary == Double.POSITIVE_INFINITY) {
+ } 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)) {
+ } else if (real == Double.NEGATIVE_INFINITY &&
+ neitherInfiniteNorZeroNorNaN(imaginary)) {
return new Complex(0.0, Double.NaN);
- } else if (real == Double.NEGATIVE_INFINITY && Double.isNaN(imaginary)) {
+ } 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)) {
+ } else if (real == Double.POSITIVE_INFINITY &&
+ Double.isNaN(imaginary)) {
return new Complex(Double.POSITIVE_INFINITY, Double.NaN);
}
@@ -1039,7 +1098,7 @@ public class Complex implements Serializable {
return new Complex(t, imaginary / (2.0 * t));
} else {
return new Complex(Math.abs(imaginary) / (2.0 * t),
- Math.copySign(1d, imaginary) * t);
+ Math.copySign(1d, imaginary) * t);
}
}
@@ -1086,7 +1145,7 @@ public class Complex implements Serializable {
final double d = Math.cos(real2) + Math.cosh(imaginary2);
return new Complex(Math.sin(real2) / d,
- Math.sinh(imaginary2) / d);
+ Math.sinh(imaginary2) / d);
}
/**
@@ -1106,11 +1165,14 @@ public class Complex implements Serializable {
* @return the hyperbolic tangent of {@code this}.
*/
public Complex tanh() {
- if (real == Double.POSITIVE_INFINITY && imaginary == Double.POSITIVE_INFINITY) {
+ if (real == Double.POSITIVE_INFINITY &&
+ imaginary == Double.POSITIVE_INFINITY) {
return new Complex(1.0, 0.0);
- } else if (real == Double.POSITIVE_INFINITY && Double.isNaN(imaginary)) {
+ } else if (real == Double.POSITIVE_INFINITY &&
+ Double.isNaN(imaginary)) {
return new Complex(1.0, 0.0);
- } else if (Double.isNaN(real) && imaginary == 0) {
+ } else if (Double.isNaN(real) &&
+ imaginary == 0) {
return new Complex(Double.NaN, 0);
}
final double real2 = 2.0 * real;
@@ -1118,7 +1180,7 @@ public class Complex implements Serializable {
final double d = Math.cosh(real2) + Math.cos(imaginary2);
return new Complex(Math.sinh(real2) / d,
- Math.sin(imaginary2) / d);
+ Math.sin(imaginary2) / d);
}
/**
@@ -1173,7 +1235,6 @@ public class Complex implements Serializable {
* @return a List of all {@code n}-th roots of {@code this}.
*/
public List<Complex> nthRoot(int n) {
-
if (n <= 0) {
throw new IllegalArgumentException("cannot compute nth root for null or negative n: {0}");
}
[09/14] commons-numbers git commit: Unnecessary instantiation.
Posted by er...@apache.org.
Unnecessary instantiation.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/49ed2b81
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/49ed2b81
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/49ed2b81
Branch: refs/heads/master
Commit: 49ed2b81e8a086fd0a801ba2fa54a4f16827512f
Parents: 5dbfebe
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Thu Feb 1 13:09:33 2018 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Thu Feb 1 13:09:33 2018 +0100
----------------------------------------------------------------------
.../src/main/java/org/apache/commons/numbers/complex/Complex.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/49ed2b81/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 a56c641..d474c31 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
@@ -706,7 +706,7 @@ public class Complex implements Serializable {
*/
public Complex atan() {
return this.add(I).divide(I.subtract(this)).log()
- .multiply(I.divide(createComplex(2, 0)));
+ .multiply(I.multiply(0.5));
}
/**
[04/14] commons-numbers git commit: More nit-picks.
Posted by er...@apache.org.
More nit-picks.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/7da7fa97
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/7da7fa97
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/7da7fa97
Branch: refs/heads/master
Commit: 7da7fa9711ec6cf25903c045fb0eeb5267971f8d
Parents: 21d5060
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Thu Feb 1 12:52:50 2018 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Thu Feb 1 12:52:50 2018 +0100
----------------------------------------------------------------------
.../java/org/apache/commons/numbers/complex/Complex.java | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/7da7fa97/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 c0561ad..b45093d 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
@@ -573,7 +573,7 @@ public class Complex implements Serializable {
public Complex multiply(Complex factor) {
checkNotNull(factor);
return new Complex(real * factor.real - imaginary * factor.imaginary,
- real * factor.imaginary + imaginary * factor.real);
+ real * factor.imaginary + imaginary * factor.real);
}
/**
@@ -759,15 +759,15 @@ public class Complex implements Serializable {
} 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);
+ return new Complex(0, Math.PI * 0.5);
} else if (real == Double.POSITIVE_INFINITY && neitherInfiniteNorZeroNorNaN(imaginary)) {
- return new Complex(0, Math.PI*0.5);
+ 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);
+ 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 new Complex(0, Math.PI * 0.5);
}
return this.add(Complex.ONE).divide(Complex.ONE.subtract(this)).log().divide(new Complex(2));
}
[10/14] commons-numbers git commit: Unnecessary instantiation.
Posted by er...@apache.org.
Unnecessary instantiation.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/2af72846
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/2af72846
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/2af72846
Branch: refs/heads/master
Commit: 2af72846f1b96315804a320f6fd95bcd5458a547
Parents: 49ed2b8
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Thu Feb 1 13:11:37 2018 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Thu Feb 1 13:11:37 2018 +0100
----------------------------------------------------------------------
.../src/main/java/org/apache/commons/numbers/complex/Complex.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/2af72846/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 d474c31..ca0eea8 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
@@ -1086,7 +1086,7 @@ public class Complex implements Serializable {
public Complex sqrt() {
if (real == 0 &&
imaginary == 0) {
- return new Complex(0, 0);
+ return ZERO;
} else if (neitherInfiniteNorZeroNorNaN(real) &&
imaginary == Double.POSITIVE_INFINITY) {
return new Complex(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
[05/14] commons-numbers git commit: Unnecessary instantiations.
Posted by er...@apache.org.
Unnecessary instantiations.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/2daea445
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/2daea445
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/2daea445
Branch: refs/heads/master
Commit: 2daea445e878c98fc0f0a5a90deb413813fdc8cf
Parents: 7da7fa9
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Thu Feb 1 12:56:06 2018 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Thu Feb 1 12:56:06 2018 +0100
----------------------------------------------------------------------
.../java/org/apache/commons/numbers/complex/Complex.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/2daea445/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 b45093d..7034f94 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
@@ -1113,7 +1113,7 @@ public class Complex implements Serializable {
* @return the square root of <code>1 - this<sup>2</sup></code>.
*/
public Complex sqrt1z() {
- return new Complex(1, 0).subtract(this.multiply(this)).sqrt();
+ return Complex.ONE.subtract(this.multiply(this)).sqrt();
}
/**
@@ -1134,7 +1134,7 @@ public class Complex implements Serializable {
*/
public Complex tan() {
if (imaginary > 20) {
- return new Complex(0, 1);
+ return Complex.ONE;
}
if (imaginary < -20) {
return new Complex(0, -1);
@@ -1167,10 +1167,10 @@ public class Complex implements Serializable {
public Complex tanh() {
if (real == Double.POSITIVE_INFINITY &&
imaginary == Double.POSITIVE_INFINITY) {
- return new Complex(1, 0);
+ return Complex.ONE;
} else if (real == Double.POSITIVE_INFINITY &&
Double.isNaN(imaginary)) {
- return new Complex(1, 0);
+ return Complex.ONE;
} else if (Double.isNaN(real) &&
imaginary == 0) {
return new Complex(Double.NaN, 0);
[13/14] commons-numbers git commit: Unnecessary use of accessors.
Posted by er...@apache.org.
Unnecessary use of accessors.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/a4bee700
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/a4bee700
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/a4bee700
Branch: refs/heads/master
Commit: a4bee7004200d68afe8c6831b3eced555d98d8da
Parents: 5de033d
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Thu Feb 1 13:24:34 2018 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Thu Feb 1 13:24:34 2018 +0100
----------------------------------------------------------------------
.../org/apache/commons/numbers/complex/Complex.java | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a4bee700/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 6e52674..53e3ff1 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
@@ -222,8 +222,8 @@ public class Complex implements Serializable {
*/
public Complex add(Complex addend) {
checkNotNull(addend);
- return new Complex(real + addend.getReal(),
- imaginary + addend.getImaginary());
+ return new Complex(real + addend.real,
+ imaginary + addend.imaginary);
}
/**
@@ -299,8 +299,8 @@ public class Complex implements Serializable {
public Complex divide(Complex divisor) {
checkNotNull(divisor);
- final double c = divisor.getReal();
- final double d = divisor.getImaginary();
+ final double c = divisor.real;
+ final double d = divisor.imaginary;
if (c == 0 &&
d == 0) {
return NaN;
@@ -624,8 +624,8 @@ public class Complex implements Serializable {
*/
public Complex subtract(Complex subtrahend) {
checkNotNull(subtrahend);
- return new Complex(real - subtrahend.getReal(),
- imaginary - subtrahend.getImaginary());
+ return new Complex(real - subtrahend.real,
+ imaginary - subtrahend.imaginary);
}
/**
@@ -1209,7 +1209,7 @@ public class Complex implements Serializable {
* @return the argument of {@code this}.
*/
public double getArgument() {
- return Math.atan2(getImaginary(), getReal());
+ return Math.atan2(imaginary, real);
}
/**
[06/14] commons-numbers git commit: Alignment (nit-picks).
Posted by er...@apache.org.
Alignment (nit-picks).
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/a88c7677
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/a88c7677
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/a88c7677
Branch: refs/heads/master
Commit: a88c7677c6f4dfcea2d8ef29f353afe3045df06a
Parents: 2daea44
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Thu Feb 1 12:56:56 2018 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Thu Feb 1 12:56:56 2018 +0100
----------------------------------------------------------------------
.../apache/commons/numbers/complex/Complex.java | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a88c7677/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 7034f94..31d1cf5 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
@@ -756,17 +756,23 @@ public class Complex implements Serializable {
public Complex atanh(){
if (real == 0 && Double.isNaN(imaginary)) {
return new Complex(0, Double.NaN);
- } else if (neitherInfiniteNorZeroNorNaN(real) && imaginary == 0) {
+ } else if (neitherInfiniteNorZeroNorNaN(real) &&
+ imaginary == 0) {
return new Complex(Double.POSITIVE_INFINITY, 0);
- } else if (neitherInfiniteNorZeroNorNaN(real) && imaginary == Double.POSITIVE_INFINITY) {
+ } else if (neitherInfiniteNorZeroNorNaN(real) &&
+ imaginary == Double.POSITIVE_INFINITY) {
return new Complex(0, Math.PI * 0.5);
- } else if (real == Double.POSITIVE_INFINITY && neitherInfiniteNorZeroNorNaN(imaginary)) {
+ } 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) {
+ } 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)) {
+ } else if (real == Double.POSITIVE_INFINITY &&
+ Double.isNaN(imaginary)) {
return new Complex(0, Double.NaN);
- } else if (Double.isNaN(real) && imaginary == Double.POSITIVE_INFINITY) {
+ } 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));
[03/14] commons-numbers git commit: Visual clean-up (nit-picks).
Posted by er...@apache.org.
Visual clean-up (nit-picks).
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/21d5060f
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/21d5060f
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/21d5060f
Branch: refs/heads/master
Commit: 21d5060f71811799cf5ef64cd872a4f1dee74997
Parents: e42ec50
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Thu Feb 1 12:48:28 2018 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Thu Feb 1 12:48:28 2018 +0100
----------------------------------------------------------------------
.../apache/commons/numbers/complex/Complex.java | 120 +++++++++----------
1 file changed, 60 insertions(+), 60 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/21d5060f/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 9b4508a..c0561ad 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
@@ -46,7 +46,7 @@ import org.apache.commons.numbers.core.Precision;
*/
public class Complex implements Serializable {
/** The square root of -1. A number representing "0.0 + 1.0i" */
- public static final Complex I = new Complex(0.0, 1.0);
+ public static final Complex I = new Complex(0, 1);
// CHECKSTYLE: stop ConstantName
/** A complex number representing "NaN + NaNi" */
public static final Complex NaN = new Complex(Double.NaN, Double.NaN);
@@ -54,9 +54,9 @@ public class Complex implements Serializable {
/** A complex number representing "+INF + INFi" */
public static final Complex INF = new Complex(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
/** A complex number representing "1.0 + 0.0i" */
- public static final Complex ONE = new Complex(1.0, 0.0);
+ public static final Complex ONE = new Complex(1, 0);
/** A complex number representing "0.0 + 0.0i" */
- public static final Complex ZERO = new Complex(0.0, 0.0);
+ public static final Complex ZERO = new Complex(0, 0);
/** Serializable version identifier */
private static final long serialVersionUID = -6195664516687396620L;
@@ -72,7 +72,7 @@ public class Complex implements Serializable {
* @param real Real part.
*/
public Complex(double real) {
- this(real, 0.0);
+ this(real, 0);
}
/**
@@ -189,7 +189,7 @@ public class Complex implements Serializable {
final double q = real / imaginary;
return Math.abs(imaginary) * Math.sqrt(1 + q * q);
} else {
- if (real == 0.0) {
+ if (real == 0) {
return Math.abs(imaginary);
}
final double q = imaginary / real;
@@ -301,8 +301,8 @@ public class Complex implements Serializable {
final double c = divisor.getReal();
final double d = divisor.getImaginary();
- if (c == 0.0 &&
- d == 0.0) {
+ if (c == 0 &&
+ d == 0) {
return NaN;
}
@@ -652,7 +652,7 @@ public class Complex implements Serializable {
* @return the inverse cosine of this complex number.
*/
public Complex acos() {
- if (real == 0.0&& Double.isNaN(imaginary)) {
+ if (real == 0 && Double.isNaN(imaginary)) {
return new Complex(Math.PI * 0.5, Double.NaN);
} else if (neitherInfiniteNorZeroNorNaN(real) &&
imaginary == Double.POSITIVE_INFINITY) {
@@ -705,7 +705,7 @@ public class Complex implements Serializable {
*/
public Complex atan() {
return this.add(I).divide(I.subtract(this)).log()
- .multiply(I.divide(createComplex(2.0, 0.0)));
+ .multiply(I.divide(createComplex(2, 0)));
}
/**
@@ -725,7 +725,7 @@ public class Complex implements Serializable {
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.0);
+ 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);
@@ -733,8 +733,8 @@ public class Complex implements Serializable {
Double.isNaN(imaginary)) {
return new Complex(Double.POSITIVE_INFINITY, Double.NaN);
} else if (Double.isNaN(real) &&
- imaginary == 0.0) {
- return new Complex(Double.NaN, 0.0);
+ imaginary == 0) {
+ return new Complex(Double.NaN, 0);
} else if (Double.isNaN(real) &&
imaginary == Double.POSITIVE_INFINITY) {
return new Complex(Double.POSITIVE_INFINITY, Double.NaN);
@@ -754,10 +754,10 @@ public class Complex implements Serializable {
* @since 1.2
*/
public Complex atanh(){
- if (real == 0.0 && Double.isNaN(imaginary)) {
+ if (real == 0 && Double.isNaN(imaginary)) {
return new Complex(0, Double.NaN);
- } else if (neitherInfiniteNorZeroNorNaN(real) && imaginary == 0.0) {
- return new Complex(Double.POSITIVE_INFINITY, 0.0);
+ } 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)) {
@@ -833,15 +833,15 @@ public class Complex implements Serializable {
* @return the hyperbolic cosine of this complex number.
*/
public Complex cosh() {
- if (real == 0.0 &&
+ if (real == 0 &&
imaginary == Double.POSITIVE_INFINITY) {
- return new Complex(Double.NaN, 0.0);
- } else if (real == 0.0 &&
+ return new Complex(Double.NaN, 0);
+ } else if (real == 0 &&
Double.isNaN(imaginary)) {
- return new Complex(Double.NaN, 0.0);
+ return new Complex(Double.NaN, 0);
} else if (real == Double.POSITIVE_INFINITY &&
- imaginary == 0.0) {
- return new Complex(Double.POSITIVE_INFINITY, 0.0);
+ imaginary == 0) {
+ return new Complex(Double.POSITIVE_INFINITY, 0);
} else if (real == Double.POSITIVE_INFINITY &&
imaginary == Double.POSITIVE_INFINITY) {
return new Complex(Double.POSITIVE_INFINITY, Double.NaN);
@@ -849,8 +849,8 @@ public class Complex implements Serializable {
Double.isNaN(imaginary)) {
return new Complex(Double.POSITIVE_INFINITY, Double.NaN);
} else if (Double.isNaN(real) &&
- imaginary == 0.0) {
- return new Complex(Double.NaN, 0.0);
+ imaginary == 0) {
+ return new Complex(Double.NaN, 0);
}
return new Complex(Math.cosh(real) * Math.cos(imaginary),
@@ -875,8 +875,8 @@ public class Complex implements Serializable {
*/
public Complex exp() {
if (real == Double.POSITIVE_INFINITY &&
- imaginary == 0.0) {
- return new Complex(Double.POSITIVE_INFINITY, 0.0);
+ imaginary == 0) {
+ return new Complex(Double.POSITIVE_INFINITY, 0);
} else if (real == Double.NEGATIVE_INFINITY &&
imaginary == Double.POSITIVE_INFINITY) {
return Complex.ZERO;
@@ -890,8 +890,8 @@ public class Complex implements Serializable {
Double.isNaN(imaginary)) {
return new Complex(Double.POSITIVE_INFINITY, Double.NaN);
} else if (Double.isNaN(real) &&
- imaginary == 0.0) {
- return new Complex(Double.NaN, 0.0);
+ imaginary == 0) {
+ return new Complex(Double.NaN, 0);
}
double expReal = Math.exp(real);
return new Complex(expReal * Math.cos(imaginary),
@@ -958,10 +958,10 @@ public class Complex implements Serializable {
*/
public Complex pow(Complex x) {
checkNotNull(x);
- if (real == 0.0 &&
- imaginary == 0.0) {
+ if (real == 0 &&
+ imaginary == 0) {
if (x.real > 0 &&
- x.imaginary == 0.0) {
+ x.imaginary == 0) {
// 0 raised to positive number is 0
return ZERO;
} else {
@@ -980,8 +980,8 @@ public class Complex implements Serializable {
* @see #pow(Complex)
*/
public Complex pow(double x) {
- if (real == 0.0 &&
- imaginary == 0.0) {
+ if (real == 0 &&
+ imaginary == 0) {
if (x > 0) {
// 0 raised to positive number is 0
return ZERO;
@@ -1032,18 +1032,18 @@ public class Complex implements Serializable {
* @return the hyperbolic sine of {@code this}.
*/
public Complex sinh() {
- if (real == 0.0 &&
- imaginary == 0.0) {
+ if (real == 0 &&
+ imaginary == 0) {
return Complex.ZERO;
- } else if (real == 0.0 &&
+ } else if (real == 0 &&
imaginary == Double.POSITIVE_INFINITY) {
return new Complex(0, Double.NaN);
- } else if (real == 0.0 &&
+ } else if (real == 0 &&
Double.isNaN(imaginary)) {
return new Complex(0, Double.NaN);
} else if (real == Double.POSITIVE_INFINITY &&
- imaginary == 0.0) {
- return new Complex(Double.POSITIVE_INFINITY, 0.0);
+ imaginary == 0) {
+ return new Complex(Double.POSITIVE_INFINITY, 0);
} else if (real == Double.POSITIVE_INFINITY &&
imaginary == Double.POSITIVE_INFINITY) {
return new Complex(Double.POSITIVE_INFINITY, Double.NaN);
@@ -1051,8 +1051,8 @@ public class Complex implements Serializable {
Double.isNaN(imaginary)) {
return new Complex(Double.POSITIVE_INFINITY, Double.NaN);
} else if (Double.isNaN(real) &&
- imaginary == 0.0) {
- return new Complex(Double.NaN, 0.0);
+ imaginary == 0) {
+ return new Complex(Double.NaN, 0);
}
return new Complex(Math.sinh(real) * Math.cos(imaginary),
Math.cosh(real) * Math.sin(imaginary));
@@ -1076,15 +1076,15 @@ public class Complex implements Serializable {
* @return the square root of {@code this}.
*/
public Complex sqrt() {
- if (real == 0.0 &&
- imaginary == 0.0) {
- return new Complex(0.0, 0.0);
+ if (real == 0 &&
+ imaginary == 0) {
+ return new Complex(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);
+ return new Complex(0, Double.NaN);
} else if (real == Double.NEGATIVE_INFINITY &&
Double.isNaN(imaginary)) {
return new Complex(Double.NaN, Double.POSITIVE_INFINITY);
@@ -1093,11 +1093,11 @@ public class Complex implements Serializable {
return new Complex(Double.POSITIVE_INFINITY, Double.NaN);
}
- final double t = Math.sqrt((Math.abs(real) + abs()) / 2.0);
- if (real >= 0.0) {
- return new Complex(t, imaginary / (2.0 * t));
+ final double t = Math.sqrt((Math.abs(real) + abs()) / 2);
+ if (real >= 0) {
+ return new Complex(t, imaginary / (2 * t));
} else {
- return new Complex(Math.abs(imaginary) / (2.0 * t),
+ return new Complex(Math.abs(imaginary) / (2 * t),
Math.copySign(1d, imaginary) * t);
}
}
@@ -1113,7 +1113,7 @@ public class Complex implements Serializable {
* @return the square root of <code>1 - this<sup>2</sup></code>.
*/
public Complex sqrt1z() {
- return new Complex(1.0, 0.0).subtract(this.multiply(this)).sqrt();
+ return new Complex(1, 0).subtract(this.multiply(this)).sqrt();
}
/**
@@ -1133,15 +1133,15 @@ public class Complex implements Serializable {
* @return the tangent of {@code this}.
*/
public Complex tan() {
- if (imaginary > 20.0) {
- return new Complex(0.0, 1.0);
+ if (imaginary > 20) {
+ return new Complex(0, 1);
}
- if (imaginary < -20.0) {
- return new Complex(0.0, -1.0);
+ if (imaginary < -20) {
+ return new Complex(0, -1);
}
- final double real2 = 2.0 * real;
- final double imaginary2 = 2.0 * imaginary;
+ final double real2 = 2 * real;
+ final double imaginary2 = 2 * imaginary;
final double d = Math.cos(real2) + Math.cosh(imaginary2);
return new Complex(Math.sin(real2) / d,
@@ -1167,16 +1167,16 @@ public class Complex implements Serializable {
public Complex tanh() {
if (real == Double.POSITIVE_INFINITY &&
imaginary == Double.POSITIVE_INFINITY) {
- return new Complex(1.0, 0.0);
+ return new Complex(1, 0);
} else if (real == Double.POSITIVE_INFINITY &&
Double.isNaN(imaginary)) {
- return new Complex(1.0, 0.0);
+ return new Complex(1, 0);
} else if (Double.isNaN(real) &&
imaginary == 0) {
return new Complex(Double.NaN, 0);
}
- final double real2 = 2.0 * real;
- final double imaginary2 = 2.0 * imaginary;
+ final double real2 = 2 * real;
+ final double imaginary2 = 2 * imaginary;
final double d = Math.cosh(real2) + Math.cos(imaginary2);
return new Complex(Math.sinh(real2) / d,
@@ -1242,7 +1242,7 @@ public class Complex implements Serializable {
final List<Complex> result = new ArrayList<Complex>();
// nth root of abs -- faster / more accurate to use a solver here?
- final double nthRootOfAbs = Math.pow(abs(), 1.0 / n);
+ final double nthRootOfAbs = Math.pow(abs(), 1d / n);
// Compute nth roots of complex number with k = 0, 1, ... n-1
final double nthPhi = getArgument() / n;
[11/14] commons-numbers git commit: Use custom serial version
identifier.
Posted by er...@apache.org.
Use custom serial version identifier.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/f50fbcf4
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/f50fbcf4
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/f50fbcf4
Branch: refs/heads/master
Commit: f50fbcf42c2693055127bda1060a636697427bbb
Parents: 2af7284
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Thu Feb 1 13:17:24 2018 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Thu Feb 1 13:17:24 2018 +0100
----------------------------------------------------------------------
.../src/main/java/org/apache/commons/numbers/complex/Complex.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/f50fbcf4/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 ca0eea8..bdb6c7e 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
@@ -59,7 +59,7 @@ public class Complex implements Serializable {
public static final Complex ZERO = new Complex(0, 0);
/** Serializable version identifier */
- private static final long serialVersionUID = -6195664516687396620L;
+ private static final long serialVersionUID = 20180201L;
/** The imaginary part. */
private final double imaginary;
[14/14] commons-numbers git commit: Space around operator (nit-picks).
Posted by er...@apache.org.
Space around operator (nit-picks).
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/1b2eb222
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/1b2eb222
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/1b2eb222
Branch: refs/heads/master
Commit: 1b2eb2220f873f2ba7e45e749c49bc2930af6666
Parents: a4bee70
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Thu Feb 1 14:00:31 2018 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Thu Feb 1 14:00:31 2018 +0100
----------------------------------------------------------------------
.../src/main/java/org/apache/commons/numbers/complex/Complex.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/1b2eb222/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 53e3ff1..93e0614 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
@@ -946,7 +946,7 @@ public class Complex implements Serializable {
* @return the base 10 logarithm of <code>this</code>.
*/
public Complex log10() {
- return new Complex(Math.log(abs())/Math.log(10),
+ return new Complex(Math.log(abs()) / Math.log(10),
Math.atan2(imaginary, real));
}
[12/14] commons-numbers git commit: Visual clean-up (nit-picks).
Posted by er...@apache.org.
Visual clean-up (nit-picks).
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/5de033d1
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/5de033d1
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/5de033d1
Branch: refs/heads/master
Commit: 5de033d1b793e6260767609e735105013be6c0d7
Parents: f50fbcf
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Thu Feb 1 13:22:45 2018 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Thu Feb 1 13:22:45 2018 +0100
----------------------------------------------------------------------
.../org/apache/commons/numbers/complex/Complex.java | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/5de033d1/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 bdb6c7e..6e52674 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
@@ -740,7 +740,7 @@ public class Complex implements Serializable {
imaginary == Double.POSITIVE_INFINITY) {
return new Complex(Double.POSITIVE_INFINITY, Double.NaN);
}
- return square().add(Complex.ONE).sqrt().add(this).log();
+ return square().add(ONE).sqrt().add(this).log();
}
/**
@@ -777,7 +777,7 @@ public class Complex implements Serializable {
imaginary == Double.POSITIVE_INFINITY) {
return new Complex(0, Math.PI * 0.5);
}
- return this.add(Complex.ONE).divide(Complex.ONE.subtract(this)).log().multiply(0.5);
+ return this.add(ONE).divide(ONE.subtract(this)).log().multiply(0.5);
}
/**
* Compute the
@@ -791,7 +791,7 @@ public class Complex implements Serializable {
* @since 1.2
*/
public Complex acosh() {
- return square().subtract(Complex.ONE).sqrt().add(this).log();
+ return square().subtract(ONE).sqrt().add(this).log();
}
/**
@@ -1121,7 +1121,7 @@ public class Complex implements Serializable {
* @return the square root of <code>1 - this<sup>2</sup></code>.
*/
public Complex sqrt1z() {
- return Complex.ONE.subtract(this.multiply(this)).sqrt();
+ return ONE.subtract(this.multiply(this)).sqrt();
}
/**
@@ -1142,7 +1142,7 @@ public class Complex implements Serializable {
*/
public Complex tan() {
if (imaginary > 20) {
- return Complex.ONE;
+ return ONE;
}
if (imaginary < -20) {
return new Complex(0, -1);
@@ -1175,10 +1175,10 @@ public class Complex implements Serializable {
public Complex tanh() {
if (real == Double.POSITIVE_INFINITY &&
imaginary == Double.POSITIVE_INFINITY) {
- return Complex.ONE;
+ return ONE;
} else if (real == Double.POSITIVE_INFINITY &&
Double.isNaN(imaginary)) {
- return Complex.ONE;
+ return ONE;
} else if (Double.isNaN(real) &&
imaginary == 0) {
return new Complex(Double.NaN, 0);
[07/14] commons-numbers git commit: Alignment (nit-picks).
Posted by er...@apache.org.
Alignment (nit-picks).
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/818603c2
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/818603c2
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/818603c2
Branch: refs/heads/master
Commit: 818603c2895c10ec24c687105dc53cb64843a632
Parents: a88c767
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Thu Feb 1 12:59:23 2018 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Thu Feb 1 12:59:23 2018 +0100
----------------------------------------------------------------------
.../main/java/org/apache/commons/numbers/complex/Complex.java | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/818603c2/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 31d1cf5..e544e28 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
@@ -652,7 +652,8 @@ public class Complex implements Serializable {
* @return the inverse cosine of this complex number.
*/
public Complex acos() {
- if (real == 0 && Double.isNaN(imaginary)) {
+ if (real == 0 &&
+ Double.isNaN(imaginary)) {
return new Complex(Math.PI * 0.5, Double.NaN);
} else if (neitherInfiniteNorZeroNorNaN(real) &&
imaginary == Double.POSITIVE_INFINITY) {
@@ -754,7 +755,8 @@ public class Complex implements Serializable {
* @since 1.2
*/
public Complex atanh(){
- if (real == 0 && Double.isNaN(imaginary)) {
+ if (real == 0 &&
+ Double.isNaN(imaginary)) {
return new Complex(0, Double.NaN);
} else if (neitherInfiniteNorZeroNorNaN(real) &&
imaginary == 0) {
[08/14] commons-numbers git commit: Unnecessary instantiation.
Posted by er...@apache.org.
Unnecessary instantiation.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/5dbfebeb
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/5dbfebeb
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/5dbfebeb
Branch: refs/heads/master
Commit: 5dbfebebe6a85d844abe0587404d7b3e70299229
Parents: 818603c
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Thu Feb 1 13:05:56 2018 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Thu Feb 1 13:05:56 2018 +0100
----------------------------------------------------------------------
.../src/main/java/org/apache/commons/numbers/complex/Complex.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/5dbfebeb/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 e544e28..a56c641 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
@@ -777,7 +777,7 @@ public class Complex implements Serializable {
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));
+ return this.add(Complex.ONE).divide(Complex.ONE.subtract(this)).log().multiply(0.5);
}
/**
* Compute the