Repository: commons-numbers Updated Branches: refs/heads/master 857033738 -> b37c9f195
Revert large commit with many changes that should have been reviewed in a separate branch. This reverts commit 857033738c5f470289f3ff4ea325e5b7f6adae52. Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/c15e3b90 Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/c15e3b90 Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/c15e3b90 Branch: refs/heads/master Commit: c15e3b901f5cdc4d3d5ea8d54e29e852e9bdaf15 Parents: 8570337 Author: Gilles Sadowski <gil...@harfang.homelinux.org> Authored: Sun Mar 19 18:21:14 2017 +0100 Committer: Gilles Sadowski <gil...@harfang.homelinux.org> Committed: Sun Mar 19 18:21:14 2017 +0100 ---------------------------------------------------------------------- .swp | Bin 16384 -> 0 bytes .../apache/commons/numbers/complex/Complex.java | 420 +++++-------------- .../numbers/core/.ArithmeticUtils.java.swp | Bin 16384 -> 0 bytes .../numbers/fraction/.BigFraction.java.swp | Bin 16384 -> 0 bytes 4 files changed, 99 insertions(+), 321 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c15e3b90/.swp ---------------------------------------------------------------------- diff --git a/.swp b/.swp deleted file mode 100644 index e5f142d..0000000 Binary files a/.swp and /dev/null differ http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c15e3b90/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 6e4639b..4e9022e 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 @@ -20,9 +20,7 @@ package org.apache.commons.numbers.complex; import java.io.Serializable; import java.util.ArrayList; import java.util.List; - import org.apache.commons.numbers.core.Precision; - /** * Representation of a Complex number, i.e. a number which has both a * real and imaginary part. @@ -40,10 +38,10 @@ import org.apache.commons.numbers.core.Precision; * Note that this contradicts the IEEE-754 standard for floating * point numbers (according to which the test {@code x == x} must fail if * {@code x} is {@code NaN}). The method - * {@link org.apache.commons.math4.util.Precision#equals(double,double,int) - * equals for primitive double} in {@link org.apache.commons.math4.util.Precision} - * conforms with IEEE-754 while this class conforms with the standard behavior - * for Java object types.</p> + * {@link org.apache.commons.numbers.core.Precision#equals(double,double,int) + * equals for primitive double} in class {@code Precision} conforms with + * IEEE-754 while this class conforms with the standard behavior for Java + * object types.</p> * */ public class Complex implements Serializable { @@ -61,15 +59,15 @@ public class Complex implements Serializable { public static final Complex ZERO = new Complex(0.0, 0.0); /** Serializable version identifier */ - private static final long serialVersionUID = -6195664516687396620L; + private static final long serialVersionUID = 201701120L; /** The imaginary part. */ private final double imaginary; /** The real part. */ private final double real; - /** Record whether this Complex number is equal to NaN. */ + /** Record whether this complex number is equal to NaN. */ private final transient boolean isNaN; - /** Record whether this Complex number is infinite. */ + /** Record whether this complex number is infinite. */ private final transient boolean isInfinite; /** @@ -81,7 +79,7 @@ public class Complex implements Serializable { this(real, 0.0); } - /** + /** * Create a complex number given the real and imaginary parts. * * @param real Real part. @@ -96,56 +94,8 @@ public class Complex implements Serializable { (Double.isInfinite(real) || Double.isInfinite(imaginary)); } - /** - * Creates a Complex from its polar representation. - * <p> - * If either {@code r} or {@code theta} is NaN, or {@code theta} is - * infinite, {@link Complex#NaN} is returned. - * <p> - * If {@code r} is infinite and {@code theta} is finite, infinite or NaN - * values may be returned in parts of the result, following the rules for - * double arithmetic. - * - * <pre> - * Examples: - * {@code - * polar2Complex(INFINITY, \(\pi\)) = INFINITY + INFINITY i - * polar2Complex(INFINITY, 0) = INFINITY + NaN i - * polar2Complex(INFINITY, \(-\frac{\pi}{4}\)) = INFINITY - INFINITY i - * polar2Complex(INFINITY, \(5\frac{\pi}{4}\)) = -INFINITY - INFINITY i } - * </pre> - * - * @param r the modulus of the complex number to create - * @param theta the argument of the complex number to create - * @return {@code Complex} - * @since 1.1 - */ - public Complex polar(double r, double theta) { - checkNotNegative(r); - return new Complex(r * Math.cos(theta), r * Math.sin(theta)); - } - /** - * Returns projection of this Complex number onto the Riemann sphere, - * i.e. all infinities (including those with an NaN component) - * project onto real infinity, as described in the - * <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/cproj.html"> - * IEEE and ISO C standards</a>. - * <p> - * - * - * @return {@code Complex} projected onto the Riemann sphere. - */ - public Complex proj() { - if (isInfinite) { - return new Complex(Double.POSITIVE_INFINITY); - } else { - return this; - } - } - - /** - * Return the absolute value of this Complex number. + * Return the absolute value of this complex number. * Returns {@code NaN} if either real or imaginary part is {@code NaN} * and {@code Double.POSITIVE_INFINITY} if neither part is {@code NaN}, * but at least one part is infinite. @@ -174,19 +124,6 @@ public class Complex implements Serializable { } } - /** - * Return the norm of this Complex number, defined as the square of the magnitude - * (Matches C++ 11 standards.) - * Returns {@code NaN} if either real or imaginary part is {@code NaN} - * and {@code Double.POSITIVE_INFINITY} if neither part is {@code NaN}, - * but at least one part is infinite. - * - * @return the absolute value. - */ - public double norm() { - return abs()*abs(); - } - /** * Returns a {@code Complex} whose value is * {@code (this + addend)}. @@ -201,7 +138,6 @@ public class Complex implements Serializable { * * @param addend Value to be added to this {@code Complex}. * @return {@code this + addend}. - * @if {@code addend} is {@code null}. */ public Complex add(Complex addend) { checkNotNull(addend); @@ -230,7 +166,7 @@ public class Complex implements Serializable { } /** - * Returns the conjugate of this Complex number. + * Returns the conjugate of this complex number. * The conjugate of {@code a + bi} is {@code a - bi}. * <p> * {@link #NaN} is returned if either the real or imaginary @@ -251,17 +187,6 @@ public class Complex implements Serializable { return createComplex(real, -imaginary); } - /** - * Returns the conjugate of this Complex number. - * C++11 grammar. - * </p> - * @return the conjugate of this Complex object. - */ - public Complex conj() { - return conjugate(); - } - - /** * Returns a {@code Complex} whose value is * {@code (this / divisor)}. @@ -302,10 +227,8 @@ public class Complex implements Serializable { * * @param divisor Value by which this {@code Complex} is to be divided. * @return {@code this / divisor}. - * @if {@code divisor} is {@code null}. */ - public Complex divide(Complex divisor) - { + public Complex divide(Complex divisor) { checkNotNull(divisor); if (isNaN || divisor.isNaN) { return NaN; @@ -356,7 +279,12 @@ public class Complex implements Serializable { imaginary / divisor); } - /** {@inheritDoc} */ + /** + * Returns the multiplicative inverse this instance. + * + * @return {@code 1 / this}. + * @see #divide(Complex) + */ public Complex reciprocal() { if (isNaN) { return NaN; @@ -415,8 +343,8 @@ public class Complex implements Serializable { if (c.isNaN) { return isNaN; } else { - return Precision.equals(real, c.real) && - Precision.equals(imaginary, c.imaginary); + return equals(real, c.real) && + equals(imaginary, c.imaginary); } } return false; @@ -437,7 +365,6 @@ public class Complex implements Serializable { * and {@code y}. * * @see Precision#equals(double,double,int) - * @since 3.3 */ public static boolean equals(Complex x, Complex y, int maxUlps) { return Precision.equals(x.real, y.real, maxUlps) && @@ -451,8 +378,6 @@ public class Complex implements Serializable { * @param x First value (cannot be {@code null}). * @param y Second value (cannot be {@code null}). * @return {@code true} if the values are equal. - * - * @since 3.3 */ public static boolean equals(Complex x, Complex y) { return equals(x, y, 1); @@ -471,7 +396,6 @@ public class Complex implements Serializable { * numbers or they are within range of each other. * * @see Precision#equals(double,double,double) - * @since 3.3 */ public static boolean equals(Complex x, Complex y, double eps) { return Precision.equals(x.real, y.real, eps) && @@ -491,7 +415,6 @@ public class Complex implements Serializable { * numbers or they are within range of each other. * * @see Precision#equalsWithRelativeTolerance(double,double,double) - * @since 3.3 */ public static boolean equalsWithRelativeTolerance(Complex x, Complex y, double eps) { @@ -511,8 +434,8 @@ public class Complex implements Serializable { if (isNaN) { return 7; } - return 37 * (17 * Precision.hash(imaginary) + - Precision.hash(real)); + return 37 * (17 * hash(imaginary) + + hash(real)); } /** @@ -523,14 +446,6 @@ public class Complex implements Serializable { public double getImaginary() { return imaginary; } - /** - * Access the imaginary part (C++ grammar) - * - * @return the imaginary part. - */ - public double imag() { - return imaginary; - } /** * Access the real part. @@ -541,20 +456,11 @@ public class Complex implements Serializable { return real; } - /** - * Access the real part (C++ grammar) - * - * @return the real part. - */ - public double real() { - return real; - } - - /** - * Checks whether either or both parts of this Complex number is + /** + * Checks whether either or both parts of this complex number is * {@code NaN}. * - * @return true if either or both parts of this Complex number is + * @return true if either or both parts of this complex number is * {@code NaN}; false otherwise. */ public boolean isNaN() { @@ -562,12 +468,12 @@ public class Complex implements Serializable { } /** - * Checks whether either the real or imaginary part of this Complex number + * Checks whether either the real or imaginary part of this complex number * takes an infinite value (either {@code Double.POSITIVE_INFINITY} or * {@code Double.NEGATIVE_INFINITY}) and neither part * is {@code NaN}. * - * @return true if one or both parts of this Complex number are infinite + * @return true if one or both parts of this complex number are infinite * and neither part is {@code NaN}. */ public boolean isInfinite() { @@ -594,10 +500,8 @@ public class Complex implements Serializable { * * @param factor value to be multiplied by this {@code Complex}. * @return {@code this * factor}. - * @if {@code factor} is {@code null}. */ - public Complex multiply(Complex factor) - { + public Complex multiply(Complex factor) { checkNotNull(factor); if (isNaN || factor.isNaN) { return NaN; @@ -682,10 +586,8 @@ public class Complex implements Serializable { * * @param subtrahend value to be subtracted from this {@code Complex}. * @return {@code this - subtrahend}. - * @if {@code subtrahend} is {@code null}. */ - public Complex subtract(Complex subtrahend) - { + public Complex subtract(Complex subtrahend) { checkNotNull(subtrahend); if (isNaN || subtrahend.isNaN) { return NaN; @@ -713,7 +615,7 @@ public class Complex implements Serializable { /** * Compute the * <a href="http://mathworld.wolfram.com/InverseCosine.html" TARGET="_top"> - * inverse cosine</a> of this Complex number. + * inverse cosine</a> of this complex number. * Implements the formula: * <p> * {@code acos(z) = -i (log(z + i (sqrt(1 - z<sup>2</sup>))))} @@ -721,8 +623,7 @@ public class Complex implements Serializable { * Returns {@link Complex#NaN} if either real or imaginary part of the * input argument is {@code NaN} or infinite. * - * @return the inverse cosine of this Complex number. - * @since 1.2 + * @return the inverse cosine of this complex number. */ public Complex acos() { if (isNaN) { @@ -735,7 +636,7 @@ public class Complex implements Serializable { /** * Compute the * <a href="http://mathworld.wolfram.com/InverseSine.html" TARGET="_top"> - * inverse sine</a> of this Complex number. + * inverse sine</a> of this complex number. * Implements the formula: * <p> * {@code asin(z) = -i (log(sqrt(1 - z<sup>2</sup>) + iz))} @@ -743,8 +644,7 @@ public class Complex implements Serializable { * Returns {@link Complex#NaN} if either real or imaginary part of the * input argument is {@code NaN} or infinite.</p> * - * @return the inverse sine of this Complex number. - * @since 1.2 + * @return the inverse sine of this complex number. */ public Complex asin() { if (isNaN) { @@ -757,7 +657,7 @@ public class Complex implements Serializable { /** * Compute the * <a href="http://mathworld.wolfram.com/InverseTangent.html" TARGET="_top"> - * inverse tangent</a> of this Complex number. + * inverse tangent</a> of this complex number. * Implements the formula: * <p> * {@code atan(z) = (i/2) log((i + z)/(i - z))} @@ -765,8 +665,7 @@ public class Complex implements Serializable { * Returns {@link Complex#NaN} if either real or imaginary part of the * input argument is {@code NaN} or infinite.</p> * - * @return the inverse tangent of this Complex number - * @since 1.2 + * @return the inverse tangent of this complex number */ public Complex atan() { if (isNaN) { @@ -779,86 +678,8 @@ public class Complex implements Serializable { /** * Compute the - * <a href="http://mathworld.wolfram.com/InverseHyperbolicSine.html" TARGET="_top"> - * inverse hyperbolic sine</a> of this Complex number. - * Implements the formula: - * <p> - * {@code asinh(z) = log(z+sqrt(z^2+1))} - * </p><p> - * Returns {@link Complex#NaN} if either real or imaginary part of the - * input argument is {@code NaN} or infinite.</p> - * - * @return the inverse hyperbolic cosine of this Complex number - * @since 1.2 - */ - public Complex asinh(){ - if (isNaN) { - return NaN; - } - - return square().add(Complex.ONE).sqrt().add(this).log(); - } - - /** - * Compute the - * <a href="http://mathworld.wolfram.com/InverseHyperbolicTangent.html" TARGET="_top"> - * inverse hyperbolic tangent</a> of this Complex number. - * Implements the formula: - * <p> - * {@code atanh(z) = log((1+z)/(1-z))/2} - * </p><p> - * Returns {@link Complex#NaN} if either real or imaginary part of the - * input argument is {@code NaN} or infinite.</p> - * - * @return the inverse hyperbolic cosine of this Complex number - * @since 1.2 - */ - public Complex atanh(){ - if (isNaN) { - return NaN; - } - - return this.add(Complex.ONE).divide(Complex.ONE.subtract(this)).log().divide(new Complex(2)); - } - /** - * Compute the - * <a href="http://mathworld.wolfram.com/InverseHyperbolicCosine.html" TARGET="_top"> - * inverse hyperbolic cosine</a> of this Complex number. - * Implements the formula: - * <p> - * {@code acosh(z) = log(z+sqrt(z^2-1))} - * </p><p> - * Returns {@link Complex#NaN} if either real or imaginary part of the - * input argument is {@code NaN} or infinite.</p> - * - * @return the inverse hyperbolic cosine of this Complex number - * @since 1.2 - */ - public Complex acosh() { - if (isNaN) { - return NaN; - } - - return square().subtract(Complex.ONE).sqrt().add(this).log(); - } - - /** - * Compute the square of this Complex number. - * - * @return square of this Complex number - */ - public Complex square(){ - if (isNaN) { - return NaN; - } - - return this.multiply(this); - } - - /** - * Compute the * <a href="http://mathworld.wolfram.com/Cosine.html" TARGET="_top"> - * cosine</a> of this Complex number. + * cosine</a> of this complex number. * Implements the formula: * <p> * {@code cos(a + bi) = cos(a)cosh(b) - sin(a)sinh(b)i} @@ -881,8 +702,7 @@ public class Complex implements Serializable { * </code> * </pre> * - * @return the cosine of this Complex number. - * @since 1.2 + * @return the cosine of this complex number. */ public Complex cos() { if (isNaN) { @@ -896,7 +716,7 @@ public class Complex implements Serializable { /** * Compute the * <a href="http://mathworld.wolfram.com/HyperbolicCosine.html" TARGET="_top"> - * hyperbolic cosine</a> of this Complex number. + * hyperbolic cosine</a> of this complex number. * Implements the formula: * <pre> * <code> @@ -921,8 +741,7 @@ public class Complex implements Serializable { * </code> * </pre> * - * @return the hyperbolic cosine of this Complex number. - * @since 1.2 + * @return the hyperbolic cosine of this complex number. */ public Complex cosh() { if (isNaN) { @@ -936,7 +755,7 @@ public class Complex implements Serializable { /** * Compute the * <a href="http://mathworld.wolfram.com/ExponentialFunction.html" TARGET="_top"> - * exponential function</a> of this Complex number. + * exponential function</a> of this complex number. * Implements the formula: * <pre> * <code> @@ -963,7 +782,6 @@ public class Complex implements Serializable { * </pre> * * @return <code><i>e</i><sup>this</sup></code>. - * @since 1.2 */ public Complex exp() { if (isNaN) { @@ -978,7 +796,7 @@ public class Complex implements Serializable { /** * Compute the * <a href="http://mathworld.wolfram.com/NaturalLogarithm.html" TARGET="_top"> - * natural logarithm</a> of this Complex number. + * natural logarithm</a> of this complex number. * Implements the formula: * <pre> * <code> @@ -1008,7 +826,6 @@ public class Complex implements Serializable { * * @return the value <code>ln this</code>, the natural logarithm * of {@code this}. - * @since 1.2 */ public Complex log() { if (isNaN) { @@ -1020,19 +837,7 @@ public class Complex implements Serializable { } /** - * Compute the base 10 or - * <a href="http://mathworld.wolfram.com/CommonLogarithm.html" TARGET="_top"> - * common logarithm</a> of this Complex number. - * - * @return the base 10 logarithm of <code>this</code>. - */ - public Complex log10() { - return createComplex(Math.log(abs())/Math.log(10), - Math.atan2(imaginary, real)); - } - - /** - * Returns of value of this Complex number raised to the power of {@code x}. + * Returns of value of this complex number raised to the power of {@code x}. * Implements the formula: * <pre> * <code> @@ -1048,23 +853,38 @@ public class Complex implements Serializable { * * @param x exponent to which this {@code Complex} is to be raised. * @return <code> this<sup>x</sup></code>. - * @if x is {@code null}. - * @since 1.2 */ - public Complex pow(Complex x) - { + public Complex pow(Complex x) { checkNotNull(x); + if (real == 0 && imaginary == 0) { + if (x.real > 0 && x.imaginary == 0) { + // 0 raised to positive number is 0 + return ZERO; + } else { + // 0 raised to anything else is NaN + return NaN; + } + } return this.log().multiply(x).exp(); } /** - * Returns of value of this Complex number raised to the power of {@code x}. + * Returns of value of this complex number raised to the power of {@code x}. * * @param x exponent to which this {@code Complex} is to be raised. * @return <code>this<sup>x</sup></code>. * @see #pow(Complex) */ public Complex pow(double x) { + if (real == 0 && imaginary == 0) { + if (x > 0) { + // 0 raised to positive number is 0 + return ZERO; + } else { + // 0 raised to anything else is NaN + return NaN; + } + } return this.log().multiply(x).exp(); } @@ -1072,7 +892,7 @@ public class Complex implements Serializable { * Compute the * <a href="http://mathworld.wolfram.com/Sine.html" TARGET="_top"> * sine</a> - * of this Complex number. + * of this complex number. * Implements the formula: * <pre> * <code> @@ -1097,8 +917,7 @@ public class Complex implements Serializable { * </code> * </pre> * - * @return the sine of this Complex number. - * @since 1.2 + * @return the sine of this complex number. */ public Complex sin() { if (isNaN) { @@ -1112,7 +931,7 @@ public class Complex implements Serializable { /** * Compute the * <a href="http://mathworld.wolfram.com/HyperbolicSine.html" TARGET="_top"> - * hyperbolic sine</a> of this Complex number. + * hyperbolic sine</a> of this complex number. * Implements the formula: * <pre> * <code> @@ -1138,7 +957,6 @@ public class Complex implements Serializable { * </pre> * * @return the hyperbolic sine of {@code this}. - * @since 1.2 */ public Complex sinh() { if (isNaN) { @@ -1152,7 +970,7 @@ public class Complex implements Serializable { /** * Compute the * <a href="http://mathworld.wolfram.com/SquareRoot.html" TARGET="_top"> - * square root</a> of this Complex number. + * square root</a> of this complex number. * Implements the following algorithm to compute {@code sqrt(a + bi)}: * <ol><li>Let {@code t = sqrt((|a| + |a + bi|) / 2)}</li> * <li><pre>if {@code a ≥ 0} return {@code t + (b/2t)i} @@ -1181,7 +999,6 @@ public class Complex implements Serializable { * </pre> * * @return the square root of {@code this}. - * @since 1.2 */ public Complex sqrt() { if (isNaN) { @@ -1216,7 +1033,6 @@ public class Complex implements Serializable { * infinite or NaN values returned in parts of the result. * * @return the square root of <code>1 - this<sup>2</sup></code>. - * @since 1.2 */ public Complex sqrt1z() { return createComplex(1.0, 0.0).subtract(this.multiply(this)).sqrt(); @@ -1225,7 +1041,7 @@ public class Complex implements Serializable { /** * Compute the * <a href="http://mathworld.wolfram.com/Tangent.html" TARGET="_top"> - * tangent</a> of this Complex number. + * tangent</a> of this complex number. * Implements the formula: * <pre> * <code> @@ -1252,7 +1068,6 @@ public class Complex implements Serializable { * </pre> * * @return the tangent of {@code this}. - * @since 1.2 */ public Complex tan() { if (isNaN || Double.isInfinite(real)) { @@ -1276,7 +1091,7 @@ public class Complex implements Serializable { /** * Compute the * <a href="http://mathworld.wolfram.com/HyperbolicTangent.html" TARGET="_top"> - * hyperbolic tangent</a> of this Complex number. + * hyperbolic tangent</a> of this complex number. * Implements the formula: * <pre> * <code> @@ -1303,7 +1118,6 @@ public class Complex implements Serializable { * </pre> * * @return the hyperbolic tangent of {@code this}. - * @since 1.2 */ public Complex tanh() { if (isNaN || Double.isInfinite(imaginary)) { @@ -1323,29 +1137,10 @@ public class Complex implements Serializable { Math.sin(imaginary2) / d); } - /** - * Compute the argument of this Complex number. - * The argument is the angle phi between the positive real axis and - * the point representing this number in the complex plane. - * The value returned is between -PI (not inclusive) - * and PI (inclusive), with negative values returned for numbers with - * negative imaginary parts. - * <p> - * If either real or imaginary part (or both) is NaN, NaN is returned. - * Infinite parts are handled as {@code Math.atan2} handles them, - * essentially treating finite parts as zero in the presence of an - * infinite coordinate and returning a multiple of pi/4 depending on - * the signs of the infinite parts. - * See the javadoc for {@code Math.atan2} for full details. - * - * @return the argument of {@code this}. - */ - public double getArgument() { - return Math.atan2(imaginary, real); - } + /** - * Compute the argument of this Complex number. + * Compute the argument of this complex number. * The argument is the angle phi between the positive real axis and * the point representing this number in the complex plane. * The value returned is between -PI (not inclusive) @@ -1361,12 +1156,12 @@ public class Complex implements Serializable { * * @return the argument of {@code this}. */ - public double arg() { - return getArgument(); + public double getArgument() { + return Math.atan2(getImaginary(), getReal()); } /** - * Computes the n-th roots of this Complex number. + * Computes the n-th roots of this complex number. * The nth roots are defined by the formula: * <pre> * <code> @@ -1375,21 +1170,21 @@ public class Complex implements Serializable { * </pre> * for <i>{@code k=0, 1, ..., n-1}</i>, where {@code abs} and {@code phi} * are respectively the {@link #abs() modulus} and - * {@link #getArgument() argument} of this Complex number. + * {@link #getArgument() argument} of this complex number. * <p> - * If one or both parts of this Complex number is NaN, a list with just + * If one or both parts of this complex number is NaN, a list with just * one element, {@link #NaN} is returned. * if neither part is NaN, but at least one part is infinite, the result * is a one-element list containing {@link #INF}. * * @param n Degree of root. * @return a List of all {@code n}-th roots of {@code this}. - * @throws NotPositiveException if {@code n <= 0}. - * @since 2.0 */ public List<Complex> nthRoot(int n) { - checkNotNegative(n); + if (n <= 0) { + throw new RuntimeException("cannot compute nth root for null or negative n: {0}"); + } final List<Complex> result = new ArrayList<Complex>(); @@ -1426,7 +1221,6 @@ public class Complex implements Serializable { * @param realPart Real part. * @param imaginaryPart Imaginary part. * @return a new complex number instance. - * @since 1.2 * @see #valueOf(double, double) */ protected Complex createComplex(double realPart, @@ -1469,7 +1263,6 @@ public class Complex implements Serializable { * deserialize properly. * * @return A Complex instance with all fields resolved. - * @since 2.0 */ protected final Object readResolve() { return createComplex(real, imaginary); @@ -1481,51 +1274,36 @@ public class Complex implements Serializable { return "(" + real + ", " + imaginary + ")"; } - /** - * Check that the argument is positive and throw a RuntimeException - * if it is not. - * @param arg {@code double} to check + /** + * Checks that an object is not null. + * + * @param o Object to be checked. */ - private static void checkNotNegative(double arg) { - if (arg <= 0) { - throw new RuntimeException("Complex: Non-positive argument"); + private static void checkNotNull(Object o) { + if (o == null) { + throw new RuntimeException("Null Argument to Complex Method"); } } - - /** - * Check that the argument is positive and throw a RuntimeException - * if it is not. - * @param arg {@code int} to check - */ - private static void checkNotNegative(int arg) { - if (arg <= 0) { - throw new RuntimeException("Complex: Non-positive argument"); - } - } - /** - * Check that the Complex is not null and throw a RuntimeException - * if it is. - * @param arg the Complex to check + * Returns {@code true} if the values are equal according to semantics of + * {@link Double#equals(Object)}. + * + * @param x Value + * @param y Value + * @return {@code new Double(x).equals(new Double(y))} */ - private static void checkNotNull(Complex arg) { - if (arg == null) { - throw new RuntimeException("Complex: Null argument"); - } + private static boolean equals(double x, double y) { + return new Double(x).equals(new Double(y)); } /** - * Check that the argument is not null and throw a RuntimeException - * if it is. - * @param arg the argument to check - * @param argName the name of the argument + * Returns an integer hash code representing the given double value. + * + * @param value the value to be hashed + * @return the hash code */ - private static void checkNotNull(Object arg, String argName) { - if (arg == null) { - throw new RuntimeException("Complex: Null argument"); - } + private static int hash(double value) { + return new Double(value).hashCode(); } -} - - +} http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c15e3b90/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/.ArithmeticUtils.java.swp ---------------------------------------------------------------------- diff --git a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/.ArithmeticUtils.java.swp b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/.ArithmeticUtils.java.swp deleted file mode 100644 index cb08acb..0000000 Binary files a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/.ArithmeticUtils.java.swp and /dev/null differ http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c15e3b90/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/.BigFraction.java.swp ---------------------------------------------------------------------- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/.BigFraction.java.swp b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/.BigFraction.java.swp deleted file mode 100644 index 0321309..0000000 Binary files a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/.BigFraction.java.swp and /dev/null differ