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 2017/04/23 17:44:35 UTC

[01/12] commons-numbers git commit: Revert large commit with many changes that should have been reviewed in a separate branch.

Repository: commons-numbers
Updated Branches:
  refs/heads/complex-dev e2668df11 -> 410abd7fa


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/complex-dev
Commit: c15e3b901f5cdc4d3d5ea8d54e29e852e9bdaf15
Parents: 8570337
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Sun Mar 19 18:21:14 2017 +0100
Committer: Gilles Sadowski <gi...@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 &nbsp; 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 &#8805; 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


[10/12] commons-numbers git commit: Merge branch 'master' into eb-test

Posted by er...@apache.org.
Merge branch 'master' into eb-test


Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/608307bc
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/608307bc
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/608307bc

Branch: refs/heads/complex-dev
Commit: 608307bc5ae1201ba28802e39db157e8aab67ff4
Parents: 8c4026a 1e4947b
Author: Eric Barnhill <er...@apache.org>
Authored: Sat Apr 22 05:29:26 2017 +0200
Committer: Eric Barnhill <er...@apache.org>
Committed: Sat Apr 22 05:29:26 2017 +0200

----------------------------------------------------------------------
 .../numbers/fraction/ContinuedFraction.java     | 166 +++++++++++++++++++
 .../numbers/fraction/ContinuedFractionTest.java |  45 +++++
 pom.xml                                         |   2 +-
 src/changes/changes.xml                         |   3 +
 src/site/site.xml                               |   2 +-
 5 files changed, 216 insertions(+), 2 deletions(-)
----------------------------------------------------------------------



[07/12] commons-numbers git commit: NUMBERS-12: Merge branch 'feature-NUMBERS-12'

Posted by er...@apache.org.
NUMBERS-12: Merge branch 'feature-NUMBERS-12'


Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/48c9522d
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/48c9522d
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/48c9522d

Branch: refs/heads/complex-dev
Commit: 48c9522d8c835a4f6647c4bb044bb2bffc7986c3
Parents: b37c9f1 e3399d1
Author: Ray DeCampo <ra...@decampo.org>
Authored: Thu Apr 20 06:40:29 2017 -0400
Committer: Ray DeCampo <ra...@decampo.org>
Committed: Thu Apr 20 06:40:29 2017 -0400

----------------------------------------------------------------------
 .../numbers/fraction/ContinuedFraction.java     | 169 +++++++++++++++++++
 .../numbers/fraction/ContinuedFractionTest.java |  45 +++++
 2 files changed, 214 insertions(+)
----------------------------------------------------------------------



[05/12] commons-numbers git commit: Port ContinuedFraction from commons math. Converted exceptions to ArithmeticException.

Posted by er...@apache.org.
Port ContinuedFraction from commons math.
Converted exceptions to ArithmeticException.


Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/9602e36b
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/9602e36b
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/9602e36b

Branch: refs/heads/complex-dev
Commit: 9602e36b262f41036c3204b55f1addb91769573f
Parents: 4e1339e
Author: Ray DeCampo <ra...@decampo.org>
Authored: Thu Apr 20 06:34:15 2017 -0400
Committer: Ray DeCampo <ra...@decampo.org>
Committed: Thu Apr 20 06:34:15 2017 -0400

----------------------------------------------------------------------
 .../numbers/fraction/ContinuedFraction.java     | 37 +++++++++-----------
 .../numbers/fraction/ContinuedFractionTest.java |  3 +-
 2 files changed, 17 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/9602e36b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java
index 56b7267..7608c2a 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java
@@ -14,11 +14,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.commons.math4.util;
+package org.apache.commons.numbers.fraction;
 
-import org.apache.commons.math4.exception.ConvergenceException;
-import org.apache.commons.math4.exception.MaxCountExceededException;
-import org.apache.commons.math4.exception.util.LocalizedFormats;
+import org.apache.commons.numbers.core.Precision;
 
 /**
  * Provides a generic means to evaluate continued fractions.  Subclasses simply
@@ -66,9 +64,9 @@ public abstract class ContinuedFraction {
      * Evaluates the continued fraction at the value x.
      * @param x the evaluation point.
      * @return the value of the continued fraction evaluated at x.
-     * @throws ConvergenceException if the algorithm fails to converge.
+     * @throws ArithmeticException if the algorithm fails to converge.
      */
-    public double evaluate(double x) throws ConvergenceException {
+    public double evaluate(double x) {
         return evaluate(x, DEFAULT_EPSILON, Integer.MAX_VALUE);
     }
 
@@ -77,9 +75,9 @@ public abstract class ContinuedFraction {
      * @param x the evaluation point.
      * @param epsilon maximum error allowed.
      * @return the value of the continued fraction evaluated at x.
-     * @throws ConvergenceException if the algorithm fails to converge.
+     * @throws ArithmeticException if the algorithm fails to converge.
      */
-    public double evaluate(double x, double epsilon) throws ConvergenceException {
+    public double evaluate(double x, double epsilon) {
         return evaluate(x, epsilon, Integer.MAX_VALUE);
     }
 
@@ -88,11 +86,10 @@ public abstract class ContinuedFraction {
      * @param x the evaluation point.
      * @param maxIterations maximum number of convergents
      * @return the value of the continued fraction evaluated at x.
-     * @throws ConvergenceException if the algorithm fails to converge.
-     * @throws MaxCountExceededException if maximal number of iterations is reached
+     * @throws ArithmeticException if the algorithm fails to converge.
+     * @throws ArithmeticException if maximal number of iterations is reached
      */
-    public double evaluate(double x, int maxIterations)
-        throws ConvergenceException, MaxCountExceededException {
+    public double evaluate(double x, int maxIterations) {
         return evaluate(x, DEFAULT_EPSILON, maxIterations);
     }
 
@@ -116,11 +113,10 @@ public abstract class ContinuedFraction {
      * @param epsilon maximum error allowed.
      * @param maxIterations maximum number of convergents
      * @return the value of the continued fraction evaluated at x.
-     * @throws ConvergenceException if the algorithm fails to converge.
-     * @throws MaxCountExceededException if maximal number of iterations is reached
+     * @throws ArithmeticException if the algorithm fails to converge.
+     * @throws ArithmeticException if maximal number of iterations is reached
      */
-    public double evaluate(double x, double epsilon, int maxIterations)
-        throws ConvergenceException, MaxCountExceededException {
+    public double evaluate(double x, double epsilon, int maxIterations) {
         final double small = 1e-50;
         double hPrev = getA(0, x);
 
@@ -152,15 +148,15 @@ public abstract class ContinuedFraction {
             hN = hPrev * deltaN;
 
             if (Double.isInfinite(hN)) {
-                throw new ConvergenceException(LocalizedFormats.CONTINUED_FRACTION_INFINITY_DIVERGENCE,
+                throw new FractionException("Continued fraction convergents diverged to +/- infinity for value {0}",
                                                x);
             }
             if (Double.isNaN(hN)) {
-                throw new ConvergenceException(LocalizedFormats.CONTINUED_FRACTION_NAN_DIVERGENCE,
+                throw new FractionException("Continued fraction diverged to NaN for value {0}",
                                                x);
             }
 
-            if (FastMath.abs(deltaN - 1.0) < epsilon) {
+            if (Math.abs(deltaN - 1.0) < epsilon) {
                 break;
             }
 
@@ -171,8 +167,7 @@ public abstract class ContinuedFraction {
         }
 
         if (n >= maxIterations) {
-            throw new MaxCountExceededException(LocalizedFormats.NON_CONVERGENT_CONTINUED_FRACTION,
-                                                maxIterations, x);
+            throw new FractionException("maximal count ({0}) exceeded", maxIterations);
         }
 
         return hN;

http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/9602e36b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/ContinuedFractionTest.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/ContinuedFractionTest.java b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/ContinuedFractionTest.java
index 686fb51..f548fb1 100644
--- a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/ContinuedFractionTest.java
+++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/ContinuedFractionTest.java
@@ -14,9 +14,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.commons.math4.util;
+package org.apache.commons.numbers.fraction;
 
-import org.apache.commons.math4.util.ContinuedFraction;
 import org.junit.Assert;
 import org.junit.Test;
 


[12/12] commons-numbers git commit: merge master and eb-test branches into commons-dev branch. I was mistakenly still making edits to eb-test branch.

Posted by er...@apache.org.
merge master and eb-test branches into commons-dev branch. I was mistakenly still making edits to eb-test branch.


Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/410abd7f
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/410abd7f
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/410abd7f

Branch: refs/heads/complex-dev
Commit: 410abd7fa4f63d8c2d297b62181ddfeeb44da869
Parents: e2668df ec66bce
Author: Eric Barnhill <er...@apache.org>
Authored: Sun Apr 23 19:42:53 2017 +0200
Committer: Eric Barnhill <er...@apache.org>
Committed: Sun Apr 23 19:42:53 2017 +0200

----------------------------------------------------------------------
 .../apache/commons/numbers/complex/Complex.java | 244 +++++++++----------
 .../commons/numbers/fraction/BigFraction.java   |  16 +-
 .../numbers/fraction/ContinuedFraction.java     | 166 +++++++++++++
 .../numbers/fraction/BigFractionTest.java       |  22 ++
 .../numbers/fraction/ContinuedFractionTest.java |  45 ++++
 pom.xml                                         |   2 +-
 src/changes/changes.xml                         |   8 +-
 src/site/site.xml                               |   2 +-
 8 files changed, 366 insertions(+), 139 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/410abd7f/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
----------------------------------------------------------------------
diff --cc commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
index 42cd0cc,ccd25d1..1189451
--- 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,11 -20,9 +20,9 @@@ package org.apache.commons.numbers.comp
  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
 + * Representation of a Complex number, i.e. a number which has both a
   * real and imaginary part.
   * <p>
   * Implementations of arithmetic operations handle {@code NaN} and
@@@ -96,56 -94,8 +94,56 @@@ public class Complex implements Seriali
              (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,
++     * 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 -125,6 +173,19 @@@
          }
      }
  
 +     /**
-      * Return the norm of this Complex number, defined as the square of the magnitude
++     * 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)}.
@@@ -234,14 -171,14 +233,14 @@@
       * The conjugate of {@code a + bi} is {@code a - bi}.
       * <p>
       * {@link #NaN} is returned if either the real or imaginary
--     * part of this Complex number equals {@code Double.NaN}.
++     * part of this complex number equals {@code Double.NaN}.
       * </p><p>
       * If the imaginary part is infinite, and the real part is not
       * {@code NaN}, the returned value has infinite imaginary part
       * of the opposite sign, e.g. the conjugate of
       * {@code 1 + POSITIVE_INFINITY i} is {@code 1 - NEGATIVE_INFINITY i}.
       * </p>
--     * @return the conjugate of this Complex object.
++     * @return the conjugate of this complex object.
       */
      public Complex conjugate() {
          if (isNaN) {
@@@ -251,17 -188,6 +250,17 @@@
          return createComplex(real, -imaginary);
      }
  
 +     /**
-      * Returns the conjugate of this Complex number.
++     * Returns the conjugate of this complex number.
 +     * C++11 grammar.
 +     * </p>
-      * @return the conjugate of this Complex object.
++     * @return the conjugate of this complex object.
 +     */
 +    public Complex conj() {
 +        return conjugate();
 +    }
 +
 +
      /**
       * Returns a {@code Complex} whose value is
       * {@code (this / divisor)}.
@@@ -302,10 -228,8 +301,9 @@@
       *
       * @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;
@@@ -547,20 -457,11 +545,20 @@@
          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() {
@@@ -600,10 -501,8 +598,9 @@@
       *
       * @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;
@@@ -662,7 -561,7 +659,7 @@@
      /**
       * Returns a {@code Complex} whose value is {@code (-this)}.
       * Returns {@code NaN} if either real or imaginary
--     * part of this Complex number is {@code Double.NaN}.
++     * part of this complex number is {@code Double.NaN}.
       *
       * @return {@code -this}.
       */
@@@ -785,86 -679,8 +777,86 @@@
  
      /**
       * Compute the
 +     * <a href="http://mathworld.wolfram.com/InverseHyperbolicSine.html" TARGET="_top">
-      * inverse hyperbolic sine</a> of this Complex number.
++     * 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
++     * @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.
++     * 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
++     * @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.
++     * 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
++     * @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.
++     * Compute the square of this complex number.
 +     *
-      * @return 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}
@@@ -1025,19 -838,7 +1014,19 @@@
      }
  
      /**
 +     * Compute the base 10 or
 +     * <a href="http://mathworld.wolfram.com/CommonLogarithm.html" TARGET="_top">
-      * common logarithm</a> of this Complex number.
++     * 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>
@@@ -1328,8 -1138,10 +1326,8 @@@
                               Math.sin(imaginary2) / d);
      }
  
 -
 -
--    /**
-      * 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)
@@@ -1350,28 -1162,7 +1348,17 @@@
      }
  
      /**
-      * 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.
++     * Compute the argument of this complex number.
++     * C++11 syntax
 +     *
 +     * @return the argument of {@code this}.
 +     */
 +    public double arg() {
 +        return getArgument();
 +    }
 +
 +    /**
-      * 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>
@@@ -1497,27 -1286,16 +1482,28 @@@
          }
      }
  
 +
 +     /**
 +     * 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));
      }
  
      /**


[02/12] commons-numbers git commit: NUMBERS-15: Fix overflow in "BigFraction".

Posted by er...@apache.org.
NUMBERS-15: Fix overflow in "BigFraction".

Thanks to Sergey Ushakov.


Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/b37c9f19
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/b37c9f19
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/b37c9f19

Branch: refs/heads/complex-dev
Commit: b37c9f195f28f897eadadaf1f2df86bca0b8ce7c
Parents: c15e3b9
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Sun Mar 19 18:43:49 2017 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Sun Mar 19 18:43:49 2017 +0100

----------------------------------------------------------------------
 .../commons/numbers/fraction/BigFraction.java   | 16 ++++++++++----
 .../numbers/fraction/BigFractionTest.java       | 22 ++++++++++++++++++++
 src/changes/changes.xml                         |  5 +++--
 3 files changed, 37 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/b37c9f19/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
index eab9b7f..a76eb45 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
@@ -695,8 +695,12 @@ public class BigFraction
      */
     @Override
     public double doubleValue() {
-        double result = numerator.doubleValue() / denominator.doubleValue();
-        if (Double.isNaN(result)) {
+        double doubleNum = numerator.doubleValue();
+        double doubleDen = denominator.doubleValue();
+        double result = doubleNum / doubleDen;
+        if (Double.isInfinite(doubleNum) ||
+            Double.isInfinite(doubleDen) ||
+            Double.isNaN(result)) {
             // Numerator and/or denominator must be out of range:
             // Calculate how far to shift them to put them in range.
             int shift = Math.max(numerator.bitLength(),
@@ -748,8 +752,12 @@ public class BigFraction
      */
     @Override
     public float floatValue() {
-        float result = numerator.floatValue() / denominator.floatValue();
-        if (Double.isNaN(result)) {
+        float floatNum = numerator.floatValue();
+        float floatDen = denominator.floatValue();
+        float result = floatNum / floatDen;
+        if (Float.isInfinite(floatNum) ||
+            Float.isInfinite(floatDen) ||
+            Float.isNaN(result)) {
             // Numerator and/or denominator must be out of range:
             // Calculate how far to shift them to put them in range.
             int shift = Math.max(numerator.bitLength(),

http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/b37c9f19/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
index 55982ea..e17eb2a 100644
--- a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
+++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
@@ -233,6 +233,28 @@ public class BigFractionTest {
         Assert.assertEquals(5, large.floatValue(), 1e-15);
     }
 
+    // NUMBERS-15
+    @Test
+    public void testDoubleValueForLargeNumeratorAndSmallDenominator() {
+        final BigInteger pow300 = BigInteger.TEN.pow(300);
+        final BigInteger pow330 = BigInteger.TEN.pow(330);
+        final BigFraction large = new BigFraction(pow330.add(BigInteger.ONE),
+                                                  pow300);
+
+        Assert.assertEquals(1e30, large.doubleValue(), 1e-15);
+    }
+
+    // NUMBERS-15
+    @Test
+    public void testFloatValueForLargeNumeratorAndSmallDenominator() {
+        final BigInteger pow30 = BigInteger.TEN.pow(30);
+        final BigInteger pow40 = BigInteger.TEN.pow(40);
+        final BigFraction large = new BigFraction(pow40.add(BigInteger.ONE),
+                pow30);
+
+        Assert.assertEquals(1e10f, large.floatValue(), 1e-15);
+    }
+
     @Test
     public void testFloatValue() {
         BigFraction first = new BigFraction(1, 2);

http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/b37c9f19/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 941d628..06fdc65 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -56,8 +56,9 @@ This is the first release of Apache Commons Numbers.
 Apache Commons Numbers 1.0 contains the following modules:
 TBD
 ">
-      <!-- <action dev="erans" type="fix" issue="NUMBERS-xxx"> -->
-      <!-- </action> -->
+      <action dev="sushakov" type="fix" issue="NUMBERS-15">
+        "BigFraction": Fixed overflow "doubleValue()" and "floatValue()".
+      </action>
     </release>
 
   </body>


[06/12] commons-numbers git commit: Remove unnecessary default constructor

Posted by er...@apache.org.
Remove unnecessary default constructor


Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/e3399d1b
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/e3399d1b
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/e3399d1b

Branch: refs/heads/complex-dev
Commit: e3399d1bab7065bdad7ebac80db184b5ef758808
Parents: 9602e36
Author: Ray DeCampo <ra...@decampo.org>
Authored: Thu Apr 20 06:36:51 2017 -0400
Committer: Ray DeCampo <ra...@decampo.org>
Committed: Thu Apr 20 06:36:51 2017 -0400

----------------------------------------------------------------------
 .../apache/commons/numbers/fraction/ContinuedFraction.java    | 7 -------
 1 file changed, 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/e3399d1b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java
index 7608c2a..a2e38a7 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java
@@ -36,13 +36,6 @@ public abstract class ContinuedFraction {
     private static final double DEFAULT_EPSILON = 10e-9;
 
     /**
-     * Default constructor.
-     */
-    protected ContinuedFraction() {
-        super();
-    }
-
-    /**
      * Access the n-th a coefficient of the continued fraction.  Since a can be
      * a function of the evaluation point, x, that is passed in as well.
      * @param n the coefficient index to retrieve.


[09/12] commons-numbers git commit: Javadoc.

Posted by er...@apache.org.
Javadoc.


Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/1e4947b7
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/1e4947b7
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/1e4947b7

Branch: refs/heads/complex-dev
Commit: 1e4947b722811f01ea72a218eb6d84af0ad53ba1
Parents: 193b4f9
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Sat Apr 22 02:10:06 2017 +0200
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Sat Apr 22 02:10:06 2017 +0200

----------------------------------------------------------------------
 .../commons/numbers/fraction/ContinuedFraction.java | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/1e4947b7/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java
index ebf447b..47bd9b9 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java
@@ -19,18 +19,10 @@ package org.apache.commons.numbers.fraction;
 import org.apache.commons.numbers.core.Precision;
 
 /**
- * Provides a generic means to evaluate continued fractions.  Subclasses simply
- * provided the a and b coefficients to evaluate the continued fraction.
- *
- * <p>
- * References:
- * </p>
- *
- * <ul>
- * <li><a href="http://mathworld.wolfram.com/ContinuedFraction.html">
- * Continued Fraction</a></li>
- * </ul>
- *
+ * Provides a generic means to evaluate
+ * <a href="http://mathworld.wolfram.com/ContinuedFraction.html">continued fractions</a>.
+ * Subclasses must provide the {@link #getA(int,double) a} and {@link #getB(int,double) b}
+ * coefficients to evaluate the continued fraction.
  */
 public abstract class ContinuedFraction {
     /** Maximum allowed numerical error. */


[03/12] commons-numbers git commit: added a comma to Complex.java . this is a test to see if I have sorted out pushing to a branch.

Posted by er...@apache.org.
added a comma to Complex.java . this is a test to see if I have sorted out pushing to a branch.


Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/8c4026ad
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/8c4026ad
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/8c4026ad

Branch: refs/heads/complex-dev
Commit: 8c4026adce30725f9011283951e3f9e363e0d119
Parents: b37c9f1
Author: Eric Barnhill <er...@apache.org>
Authored: Thu Mar 30 20:41:32 2017 +0200
Committer: Eric Barnhill <er...@apache.org>
Committed: Thu Mar 30 20:41:32 2017 +0200

----------------------------------------------------------------------
 .../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/8c4026ad/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 4e9022e..35f3a26 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
@@ -22,7 +22,7 @@ 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
+ * Representation of a Complex number, i.e., a number which has both a
  * real and imaginary part.
  * <p>
  * Implementations of arithmetic operations handle {@code NaN} and


[11/12] commons-numbers git commit: partial work on ISO C test class

Posted by er...@apache.org.
partial work on ISO C test class


Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/ec66bced
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/ec66bced
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/ec66bced

Branch: refs/heads/complex-dev
Commit: ec66bced51bc44a50575584a0b98938730aef417
Parents: 608307b
Author: Eric Barnhill <er...@apache.org>
Authored: Sun Apr 23 19:19:57 2017 +0200
Committer: Eric Barnhill <er...@apache.org>
Committed: Sun Apr 23 19:19:57 2017 +0200

----------------------------------------------------------------------
 .../src/main/java/org/apache/commons/numbers/complex/Complex.java   | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ec66bced/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 35f3a26..ccd25d1 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
@@ -99,6 +99,7 @@ public class Complex implements Serializable  {
      * 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.
+     * This code follows the <a href="http://www.iso-9899.info/wiki/The_Standard">ISO C Standard</a>, Annex G, in calculating the returned value (i.e. the hypot(x,y) method)
      *
      * @return the absolute value.
      */


[04/12] commons-numbers git commit: Establish baseline of files copied from commons-math. (Will not build.)

Posted by er...@apache.org.
Establish baseline of files copied from commons-math.  (Will not build.)


Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/4e1339ee
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/4e1339ee
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/4e1339ee

Branch: refs/heads/complex-dev
Commit: 4e1339eec8f100236f7aac310f797f87c986b47e
Parents: b37c9f1
Author: Ray DeCampo <ra...@decampo.org>
Authored: Thu Apr 20 06:30:11 2017 -0400
Committer: Ray DeCampo <ra...@decampo.org>
Committed: Thu Apr 20 06:30:11 2017 -0400

----------------------------------------------------------------------
 .../numbers/fraction/ContinuedFraction.java     | 181 +++++++++++++++++++
 .../numbers/fraction/ContinuedFractionTest.java |  46 +++++
 2 files changed, 227 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/4e1339ee/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java
new file mode 100644
index 0000000..56b7267
--- /dev/null
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java
@@ -0,0 +1,181 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math4.util;
+
+import org.apache.commons.math4.exception.ConvergenceException;
+import org.apache.commons.math4.exception.MaxCountExceededException;
+import org.apache.commons.math4.exception.util.LocalizedFormats;
+
+/**
+ * Provides a generic means to evaluate continued fractions.  Subclasses simply
+ * provided the a and b coefficients to evaluate the continued fraction.
+ *
+ * <p>
+ * References:
+ * <ul>
+ * <li><a href="http://mathworld.wolfram.com/ContinuedFraction.html">
+ * Continued Fraction</a></li>
+ * </ul>
+ * </p>
+ *
+ */
+public abstract class ContinuedFraction {
+    /** Maximum allowed numerical error. */
+    private static final double DEFAULT_EPSILON = 10e-9;
+
+    /**
+     * Default constructor.
+     */
+    protected ContinuedFraction() {
+        super();
+    }
+
+    /**
+     * Access the n-th a coefficient of the continued fraction.  Since a can be
+     * a function of the evaluation point, x, that is passed in as well.
+     * @param n the coefficient index to retrieve.
+     * @param x the evaluation point.
+     * @return the n-th a coefficient.
+     */
+    protected abstract double getA(int n, double x);
+
+    /**
+     * Access the n-th b coefficient of the continued fraction.  Since b can be
+     * a function of the evaluation point, x, that is passed in as well.
+     * @param n the coefficient index to retrieve.
+     * @param x the evaluation point.
+     * @return the n-th b coefficient.
+     */
+    protected abstract double getB(int n, double x);
+
+    /**
+     * Evaluates the continued fraction at the value x.
+     * @param x the evaluation point.
+     * @return the value of the continued fraction evaluated at x.
+     * @throws ConvergenceException if the algorithm fails to converge.
+     */
+    public double evaluate(double x) throws ConvergenceException {
+        return evaluate(x, DEFAULT_EPSILON, Integer.MAX_VALUE);
+    }
+
+    /**
+     * Evaluates the continued fraction at the value x.
+     * @param x the evaluation point.
+     * @param epsilon maximum error allowed.
+     * @return the value of the continued fraction evaluated at x.
+     * @throws ConvergenceException if the algorithm fails to converge.
+     */
+    public double evaluate(double x, double epsilon) throws ConvergenceException {
+        return evaluate(x, epsilon, Integer.MAX_VALUE);
+    }
+
+    /**
+     * Evaluates the continued fraction at the value x.
+     * @param x the evaluation point.
+     * @param maxIterations maximum number of convergents
+     * @return the value of the continued fraction evaluated at x.
+     * @throws ConvergenceException if the algorithm fails to converge.
+     * @throws MaxCountExceededException if maximal number of iterations is reached
+     */
+    public double evaluate(double x, int maxIterations)
+        throws ConvergenceException, MaxCountExceededException {
+        return evaluate(x, DEFAULT_EPSILON, maxIterations);
+    }
+
+    /**
+     * Evaluates the continued fraction at the value x.
+     * <p>
+     * The implementation of this method is based on the modified Lentz algorithm as described
+     * on page 18 ff. in:
+     * <ul>
+     *   <li>
+     *   I. J. Thompson,  A. R. Barnett. "Coulomb and Bessel Functions of Complex Arguments and Order."
+     *   <a target="_blank" href="http://www.fresco.org.uk/papers/Thompson-JCP64p490.pdf">
+     *   http://www.fresco.org.uk/papers/Thompson-JCP64p490.pdf</a>
+     *   </li>
+     * </ul>
+     * <b>Note:</b> the implementation uses the terms a<sub>i</sub> and b<sub>i</sub> as defined in
+     * <a href="http://mathworld.wolfram.com/ContinuedFraction.html">Continued Fraction @ MathWorld</a>.
+     * </p>
+     *
+     * @param x the evaluation point.
+     * @param epsilon maximum error allowed.
+     * @param maxIterations maximum number of convergents
+     * @return the value of the continued fraction evaluated at x.
+     * @throws ConvergenceException if the algorithm fails to converge.
+     * @throws MaxCountExceededException if maximal number of iterations is reached
+     */
+    public double evaluate(double x, double epsilon, int maxIterations)
+        throws ConvergenceException, MaxCountExceededException {
+        final double small = 1e-50;
+        double hPrev = getA(0, x);
+
+        // use the value of small as epsilon criteria for zero checks
+        if (Precision.equals(hPrev, 0.0, small)) {
+            hPrev = small;
+        }
+
+        int n = 1;
+        double dPrev = 0.0;
+        double cPrev = hPrev;
+        double hN = hPrev;
+
+        while (n < maxIterations) {
+            final double a = getA(n, x);
+            final double b = getB(n, x);
+
+            double dN = a + b * dPrev;
+            if (Precision.equals(dN, 0.0, small)) {
+                dN = small;
+            }
+            double cN = a + b / cPrev;
+            if (Precision.equals(cN, 0.0, small)) {
+                cN = small;
+            }
+
+            dN = 1 / dN;
+            final double deltaN = cN * dN;
+            hN = hPrev * deltaN;
+
+            if (Double.isInfinite(hN)) {
+                throw new ConvergenceException(LocalizedFormats.CONTINUED_FRACTION_INFINITY_DIVERGENCE,
+                                               x);
+            }
+            if (Double.isNaN(hN)) {
+                throw new ConvergenceException(LocalizedFormats.CONTINUED_FRACTION_NAN_DIVERGENCE,
+                                               x);
+            }
+
+            if (FastMath.abs(deltaN - 1.0) < epsilon) {
+                break;
+            }
+
+            dPrev = dN;
+            cPrev = cN;
+            hPrev = hN;
+            n++;
+        }
+
+        if (n >= maxIterations) {
+            throw new MaxCountExceededException(LocalizedFormats.NON_CONVERGENT_CONTINUED_FRACTION,
+                                                maxIterations, x);
+        }
+
+        return hN;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/4e1339ee/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/ContinuedFractionTest.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/ContinuedFractionTest.java b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/ContinuedFractionTest.java
new file mode 100644
index 0000000..686fb51
--- /dev/null
+++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/ContinuedFractionTest.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math4.util;
+
+import org.apache.commons.math4.util.ContinuedFraction;
+import org.junit.Assert;
+import org.junit.Test;
+
+
+/**
+ */
+public class ContinuedFractionTest {
+
+    @Test
+    public void testGoldenRatio() throws Exception {
+        ContinuedFraction cf = new ContinuedFraction() {
+
+            @Override
+            public double getA(int n, double x) {
+                return 1.0;
+            }
+
+            @Override
+            public double getB(int n, double x) {
+                return 1.0;
+            }
+        };
+
+        double gr = cf.evaluate(0.0, 10e-9);
+        Assert.assertEquals(1.61803399, gr, 10e-9);
+    }
+}


[08/12] commons-numbers git commit: NUMBERS-23: add --allow-script-in-comments and fix logo URL

Posted by er...@apache.org.
NUMBERS-23: add --allow-script-in-comments and fix logo URL


Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/193b4f93
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/193b4f93
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/193b4f93

Branch: refs/heads/complex-dev
Commit: 193b4f93df0e11dc2602ebc5ea3bc2c4427df5e0
Parents: 48c9522
Author: Bruno P. Kinoshita <br...@yahoo.com.br>
Authored: Sat Apr 22 11:41:49 2017 +1200
Committer: Bruno P. Kinoshita <br...@yahoo.com.br>
Committed: Sat Apr 22 11:41:49 2017 +1200

----------------------------------------------------------------------
 .../apache/commons/numbers/fraction/ContinuedFraction.java    | 7 ++++++-
 pom.xml                                                       | 2 +-
 src/changes/changes.xml                                       | 3 +++
 src/site/site.xml                                             | 2 +-
 4 files changed, 11 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/193b4f93/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java
index a2e38a7..ebf447b 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java
@@ -24,11 +24,12 @@ import org.apache.commons.numbers.core.Precision;
  *
  * <p>
  * References:
+ * </p>
+ *
  * <ul>
  * <li><a href="http://mathworld.wolfram.com/ContinuedFraction.html">
  * Continued Fraction</a></li>
  * </ul>
- * </p>
  *
  */
 public abstract class ContinuedFraction {
@@ -91,6 +92,8 @@ public abstract class ContinuedFraction {
      * <p>
      * The implementation of this method is based on the modified Lentz algorithm as described
      * on page 18 ff. in:
+     * </p>
+     *
      * <ul>
      *   <li>
      *   I. J. Thompson,  A. R. Barnett. "Coulomb and Bessel Functions of Complex Arguments and Order."
@@ -98,6 +101,8 @@ public abstract class ContinuedFraction {
      *   http://www.fresco.org.uk/papers/Thompson-JCP64p490.pdf</a>
      *   </li>
      * </ul>
+     *
+     * <p>
      * <b>Note:</b> the implementation uses the terms a<sub>i</sub> and b<sub>i</sub> as defined in
      * <a href="http://mathworld.wolfram.com/ContinuedFraction.html">Continued Fraction @ MathWorld</a>.
      * </p>

http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/193b4f93/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 4485994..2758db7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -366,7 +366,7 @@
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-javadoc-plugin</artifactId>
         <configuration>
-          <additionalparam>-Xdoclint:all -header '&lt;script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"&gt;&lt;/script&gt;'</additionalparam>
+          <additionalparam>-Xdoclint:all --allow-script-in-comments -header '&lt;script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"&gt;&lt;/script&gt;'</additionalparam>
           <!-- <aggregate>true</aggregate> -->
         </configuration>
       </plugin>

http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/193b4f93/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 06fdc65..fa158bb 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -56,6 +56,9 @@ This is the first release of Apache Commons Numbers.
 Apache Commons Numbers 1.0 contains the following modules:
 TBD
 ">
+      <action dev="kinow" type="fix" issue="NUMBERS-23">
+        mvn site won't compile due to javascript error
+      </action>
       <action dev="sushakov" type="fix" issue="NUMBERS-15">
         "BigFraction": Fixed overflow "doubleValue()" and "floatValue()".
       </action>

http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/193b4f93/src/site/site.xml
----------------------------------------------------------------------
diff --git a/src/site/site.xml b/src/site/site.xml
index c939d2c..52696ba 100644
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -18,7 +18,7 @@
 <project name="Numbers">
   <bannerRight>
     <name>Apache Commons Numbers</name>
-    <src>/images/commons_numbers.small.png</src>
+    <src>/images/math.gif</src>
     <href>/index.html</href>
   </bannerRight>