Author: psteitz
Date: Wed Jun 20 16:39:50 2007
New Revision: 549299

URL: http://svn.apache.org/viewvc?view=rev&rev=549299
Log:
Added log function.
JIRA: MATH-158


Modified:
    
jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java
    
jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java
    jakarta/commons/proper/math/trunk/xdocs/changes.xml

Modified: 
jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java?view=diff&rev=549299&r1=549298&r2=549299
==============================================================================
--- 
jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java
 (original)
+++ 
jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java
 Wed Jun 20 16:39:50 2007
@@ -117,7 +117,26 @@
         }
         return result;
     }
-
+    
+    /** 
+     * <p>Returns the 
+     * <a href="http://mathworld.wolfram.com/Logarithm.html";>logarithm</a>
+     * for base <code>b</code> of <code>x</code>.
+     * </p>
+     * <p>Returns <code>NaN<code> if either argument is negative.  If 
+     * <code>base</code> is 0 and <code>x</code> is positive, 0 is returned.
+     * If <code>base</code> is positive and <code>x</code> is 0, 
+     * <code>Double.NEGATIVE_INFINITY</code> is returned.  If both arguments
+     * are 0, the result is <code>NaN</code>.</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.
+     */ 
+    public static double log(double base, double x) {
+       return Math.log(x)/Math.log(base);
+    }
+    
     /**
      * Returns a <code>double</code> representation of the <a
      * href="http://mathworld.wolfram.com/BinomialCoefficient.html";> Binomial

Modified: 
jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java?view=diff&rev=549299&r1=549298&r2=549299
==============================================================================
--- 
jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java
 (original)
+++ 
jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java
 Wed Jun 20 16:39:50 2007
@@ -444,6 +444,16 @@
         } 
     }
     
+    public void testLog() {
+       assertEquals(2.0, MathUtils.log(2,4), 0);
+       assertEquals(3.0, MathUtils.log(2,8), 0);
+        assertTrue(Double.isNaN(MathUtils.log(-1, 1)));
+        assertTrue(Double.isNaN(MathUtils.log(1, -1)));
+        assertTrue(Double.isNaN(MathUtils.log(0, 0)));
+        assertEquals(0, MathUtils.log(0, 10), 0);
+        assertEquals(Double.NEGATIVE_INFINITY, MathUtils.log(10, 0), 0);
+    }
+    
     public void testGcd() {
         int a = 30;
         int b = 50;

Modified: jakarta/commons/proper/math/trunk/xdocs/changes.xml
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/xdocs/changes.xml?view=diff&rev=549299&r1=549298&r2=549299
==============================================================================
--- jakarta/commons/proper/math/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/math/trunk/xdocs/changes.xml Wed Jun 20 16:39:50 2007
@@ -81,6 +81,9 @@
       <action dev="psteitz" type="fix" issue="MATH-166" due-to="Lukas Theussl">
         Increased default precision of Gamma and Beta functions.
       </action>
+      <action dev="psteitz" type="update" issue="MATH-158" due-to "Hasan 
Diwan">
+        Added log function to MathUtils.
+      </action>
     </release>
     <release version="1.1" date="2005-12-17"  
  description="This is a maintenance release containing bug fixes and 
enhancements.



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to