Method "log(double base, double x)" moved from "MathUtils" to "FastMath".


git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1188949 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gilles Sadowski 2011-10-25 22:26:59 +00:00
parent 6ed1d06677
commit 3e6a882070
4 changed files with 31 additions and 31 deletions

View File

@ -1389,6 +1389,26 @@ public class FastMath {
return rln10b * lnb + rln10b * lna + rln10a * lnb + rln10a * lna;
}
/**
* 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.
*

View File

@ -165,26 +165,6 @@ public final class MathUtils {
return (x >= ZS) ? PS : NS;
}
/**
* <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>

View File

@ -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);
}
}

View File

@ -150,17 +150,6 @@ public final class MathUtilsTest {
Assert.assertEquals((short)(-1), MathUtils.indicator((short)(-2)));
}
@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) {