Added log function.
JIRA: MATH-158 git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@549299 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
35414bc4f4
commit
9104ab39e9
|
@ -117,7 +117,26 @@ public final class MathUtils {
|
|||
}
|
||||
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
|
||||
|
|
|
@ -444,6 +444,16 @@ public final class MathUtilsTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
@ -81,6 +81,9 @@ Commons Math Release Notes</title>
|
|||
<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.
|
||||
|
|
Loading…
Reference in New Issue