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 2011/10/26 00:27:00 UTC

svn commit: r1188949 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/util/ test/java/org/apache/commons/math/util/

Author: erans
Date: Tue Oct 25 22:26:59 2011
New Revision: 1188949

URL: http://svn.apache.org/viewvc?rev=1188949&view=rev
Log:
MATH-689
Method "log(double base, double x)" moved from "MathUtils" to "FastMath".

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java?rev=1188949&r1=1188948&r2=1188949&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java Tue Oct 25 22:26:59 2011
@@ -1390,6 +1390,26 @@ public class FastMath {
     }
 
     /**
+     * Computes the <a href="http://mathworld.wolfram.com/Logarithm.html">
+     * logarithm</a> in a given base.
+     *
+     * Returns {@code NaN} if either argument is negative.
+     * If {@code base} is 0 and {@code x} is positive, 0 is returned.
+     * If {@code base} is positive and {@code x} is 0,
+     * {@code Double.NEGATIVE_INFINITY} is returned.
+     * If both arguments are 0, the result is {@code NaN}.
+     *
+     * @param base Base of the logarithm, must be greater than 0.
+     * @param x Argument, must be greater than 0.
+     * @return the value of the logarithm, i.e. the number {@code y} such that
+     * <code>base<sup>y</sup> = x</code>.
+     * @since 1.2 (previously in {@code MathUtils}, moved as of version 3.0)
+     */
+    public static double log(double base, double x) {
+        return log(x) / log(base);
+    }
+
+    /**
      * Power function.  Compute x^y.
      *
      * @param x   a double

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java?rev=1188949&r1=1188948&r2=1188949&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java Tue Oct 25 22:26:59 2011
@@ -166,26 +166,6 @@ public final class MathUtils {
     }
 
     /**
-     * <p>Returns the
-     * <a href="http://mathworld.wolfram.com/Logarithm.html">logarithm</a>
-     * for base {@code b} of {@code x}.
-     * </p>
-     * <p>Returns {@code NaN} if either argument is negative. If
-     * {@code base} is 0 and {@code x} is positive, 0 is returned.
-     * If {@code base} is positive and {@code x} is 0,
-     * {@code Double.NEGATIVE_INFINITY} is returned.  If both arguments
-     * are 0, the result is {@code NaN}.</p>
-     *
-     * @param base the base of the logarithm, must be greater than 0
-     * @param x argument, must be greater than 0
-     * @return the value of the logarithm - the number y such that base^y = x.
-     * @since 1.2
-     */
-    public static double log(double base, double x) {
-        return FastMath.log(x)/FastMath.log(base);
-    }
-
-    /**
      * Normalize an angle in a 2&pi wide interval around a center value.
      * <p>This method has three main uses:</p>
      * <ul>

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTest.java?rev=1188949&r1=1188948&r2=1188949&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTest.java Tue Oct 25 22:26:59 2011
@@ -1078,4 +1078,15 @@ public class FastMathTest {
         Assert.assertEquals(-1.0F, FastMath.signum(-2.0F), delta);
         TestUtils.assertSame(Float.NaN, FastMath.signum(Float.NaN));
     }
+
+    @Test
+    public void testLogWithBase() {
+        Assert.assertEquals(2.0, FastMath.log(2, 4), 0);
+        Assert.assertEquals(3.0, FastMath.log(2, 8), 0);
+        Assert.assertTrue(Double.isNaN(FastMath.log(-1, 1)));
+        Assert.assertTrue(Double.isNaN(FastMath.log(1, -1)));
+        Assert.assertTrue(Double.isNaN(FastMath.log(0, 0)));
+        Assert.assertEquals(0, FastMath.log(0, 10), 0);
+        Assert.assertEquals(Double.NEGATIVE_INFINITY, FastMath.log(10, 0), 0);
+    }
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java?rev=1188949&r1=1188948&r2=1188949&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java Tue Oct 25 22:26:59 2011
@@ -151,17 +151,6 @@ public final class MathUtilsTest {
     }
 
     @Test
-    public void testLog() {
-        Assert.assertEquals(2.0, MathUtils.log(2, 4), 0);
-        Assert.assertEquals(3.0, MathUtils.log(2, 8), 0);
-        Assert.assertTrue(Double.isNaN(MathUtils.log(-1, 1)));
-        Assert.assertTrue(Double.isNaN(MathUtils.log(1, -1)));
-        Assert.assertTrue(Double.isNaN(MathUtils.log(0, 0)));
-        Assert.assertEquals(0, MathUtils.log(0, 10), 0);
-        Assert.assertEquals(Double.NEGATIVE_INFINITY, MathUtils.log(10, 0), 0);
-    }
-
-    @Test
     public void testNormalizeAngle() {
         for (double a = -15.0; a <= 15.0; a += 0.1) {
             for (double b = -15.0; b <= 15.0; b += 0.2) {