Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 89127 invoked from network); 29 Aug 2010 22:06:31 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 29 Aug 2010 22:06:31 -0000 Received: (qmail 63084 invoked by uid 500); 29 Aug 2010 22:06:30 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 63018 invoked by uid 500); 29 Aug 2010 22:06:30 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 63011 invoked by uid 99); 29 Aug 2010 22:06:30 -0000 Received: from Unknown (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 29 Aug 2010 22:06:30 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 29 Aug 2010 22:06:03 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 474272388B71; Sun, 29 Aug 2010 22:04:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r990658 [10/10] - in /commons/proper/math/trunk: ./ src/main/java/org/apache/commons/math/analysis/ src/main/java/org/apache/commons/math/analysis/integration/ src/main/java/org/apache/commons/math/analysis/interpolation/ src/main/java/org/... Date: Sun, 29 Aug 2010 22:04:15 -0000 To: commits@commons.apache.org From: luc@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100829220420.474272388B71@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/MinpackTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/MinpackTest.java?rev=990658&r1=990657&r2=990658&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/MinpackTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/MinpackTest.java Sun Aug 29 22:04:09 2010 @@ -27,6 +27,7 @@ import org.apache.commons.math.analysis. import org.apache.commons.math.analysis.MultivariateMatrixFunction; import org.apache.commons.math.optimization.OptimizationException; import org.apache.commons.math.optimization.VectorialPointValuePair; +import org.apache.commons.math.util.FastMath; /** *

Some of the unit tests are re-implementations of the MINPACK = 0) ? 0.25 : -0.25; } else { - tmp1 = Math.atan(x2 / x1) / twoPi; + tmp1 = FastMath.atan(x2 / x1) / twoPi; if (x1 < 0) { tmp1 += 0.5; } } - double tmp2 = Math.sqrt(x1 * x1 + x2 * x2); + double tmp2 = FastMath.sqrt(x1 * x1 + x2 * x2); return new double[] { 10.0 * (x3 - 10 * tmp1), 10.0 * (tmp2 - 1), @@ -785,7 +786,7 @@ public class MinpackTest extends TestCas }; } - private static final double twoPi = 2.0 * Math.PI; + private static final double twoPi = 2.0 * FastMath.PI; } @@ -826,8 +827,8 @@ public class MinpackTest extends TestCas }; } - private static final double sqrt5 = Math.sqrt( 5.0); - private static final double sqrt10 = Math.sqrt(10.0); + private static final double sqrt5 = FastMath.sqrt( 5.0); + private static final double sqrt10 = FastMath.sqrt(10.0); } @@ -998,7 +999,7 @@ public class MinpackTest extends TestCas for (int i = 0; i < m; ++i) { double temp = 5.0 * (i + 1) + 45.0 + x3; double tmp1 = x2 / temp; - double tmp2 = Math.exp(tmp1); + double tmp2 = FastMath.exp(tmp1); double tmp3 = x1 * tmp2 / temp; jacobian[i] = new double[] { tmp2, tmp3, -tmp1 * tmp3 }; } @@ -1012,7 +1013,7 @@ public class MinpackTest extends TestCas double x3 = variables[2]; double[] f = new double[m]; for (int i = 0; i < m; ++i) { - f[i] = x1 * Math.exp(x2 / (5.0 * (i + 1) + 45.0 + x3)) - y[i]; + f[i] = x1 * FastMath.exp(x2 / (5.0 * (i + 1) + 45.0 + x3)) - y[i]; } return f; } @@ -1120,9 +1121,9 @@ public class MinpackTest extends TestCas for (int i = 0; i < m; ++i) { double tmp = (i + 1) / 10.0; jacobian[i] = new double[] { - -tmp * Math.exp(-tmp * x1), - tmp * Math.exp(-tmp * x2), - Math.exp(-i - 1) - Math.exp(-tmp) + -tmp * FastMath.exp(-tmp * x1), + tmp * FastMath.exp(-tmp * x2), + FastMath.exp(-i - 1) - FastMath.exp(-tmp) }; } return jacobian; @@ -1136,8 +1137,8 @@ public class MinpackTest extends TestCas double[] f = new double[m]; for (int i = 0; i < m; ++i) { double tmp = (i + 1) / 10.0; - f[i] = Math.exp(-tmp * x1) - Math.exp(-tmp * x2) - + (Math.exp(-i - 1) - Math.exp(-tmp)) * x3; + f[i] = FastMath.exp(-tmp * x1) - FastMath.exp(-tmp * x2) + + (FastMath.exp(-i - 1) - FastMath.exp(-tmp)) * x3; } return f; } @@ -1163,7 +1164,7 @@ public class MinpackTest extends TestCas double[][] jacobian = new double[m][]; for (int i = 0; i < m; ++i) { double t = i + 1; - jacobian[i] = new double[] { -t * Math.exp(t * x1), -t * Math.exp(t * x2) }; + jacobian[i] = new double[] { -t * FastMath.exp(t * x1), -t * FastMath.exp(t * x2) }; } return jacobian; } @@ -1175,7 +1176,7 @@ public class MinpackTest extends TestCas double[] f = new double[m]; for (int i = 0; i < m; ++i) { double temp = i + 1; - f[i] = 2 + 2 * temp - Math.exp(temp * x1) - Math.exp(temp * x2); + f[i] = 2 + 2 * temp - FastMath.exp(temp * x1) - FastMath.exp(temp * x2); } return f; } @@ -1204,9 +1205,9 @@ public class MinpackTest extends TestCas double[][] jacobian = new double[m][]; for (int i = 0; i < m; ++i) { double temp = (i + 1) / 5.0; - double ti = Math.sin(temp); - double tmp1 = x1 + temp * x2 - Math.exp(temp); - double tmp2 = x3 + ti * x4 - Math.cos(temp); + double ti = FastMath.sin(temp); + double tmp1 = x1 + temp * x2 - FastMath.exp(temp); + double tmp2 = x3 + ti * x4 - FastMath.cos(temp); jacobian[i] = new double[] { 2 * tmp1, 2 * temp * tmp1, 2 * tmp2, 2 * ti * tmp2 }; @@ -1223,8 +1224,8 @@ public class MinpackTest extends TestCas double[] f = new double[m]; for (int i = 0; i < m; ++i) { double temp = (i + 1) / 5.0; - double tmp1 = x1 + temp * x2 - Math.exp(temp); - double tmp2 = x3 + Math.sin(temp) * x4 - Math.cos(temp); + double tmp1 = x1 + temp * x2 - FastMath.exp(temp); + double tmp2 = x3 + FastMath.sin(temp) * x4 - FastMath.cos(temp); f[i] = tmp1 * tmp1 + tmp2 * tmp2; } return f; @@ -1401,8 +1402,8 @@ public class MinpackTest extends TestCas double[][] jacobian = new double[m][]; for (int i = 0; i < m; ++i) { double temp = 10.0 * i; - double tmp1 = Math.exp(-temp * x4); - double tmp2 = Math.exp(-temp * x5); + double tmp1 = FastMath.exp(-temp * x4); + double tmp2 = FastMath.exp(-temp * x5); jacobian[i] = new double[] { -1, -tmp1, -tmp2, temp * x2 * tmp1, temp * x3 * tmp2 }; @@ -1420,8 +1421,8 @@ public class MinpackTest extends TestCas double[] f = new double[m]; for (int i = 0; i < m; ++i) { double temp = 10.0 * i; - double tmp1 = Math.exp(-temp * x4); - double tmp2 = Math.exp(-temp * x5); + double tmp1 = FastMath.exp(-temp * x4); + double tmp2 = FastMath.exp(-temp * x5); f[i] = y[i] - (x1 + x2 * tmp1 + x3 * tmp2); } return f; @@ -1463,10 +1464,10 @@ public class MinpackTest extends TestCas double[][] jacobian = new double[m][]; for (int i = 0; i < m; ++i) { double temp = i / 10.0; - double tmp1 = Math.exp(-x05 * temp); - double tmp2 = Math.exp(-x06 * (temp - x09) * (temp - x09)); - double tmp3 = Math.exp(-x07 * (temp - x10) * (temp - x10)); - double tmp4 = Math.exp(-x08 * (temp - x11) * (temp - x11)); + double tmp1 = FastMath.exp(-x05 * temp); + double tmp2 = FastMath.exp(-x06 * (temp - x09) * (temp - x09)); + double tmp3 = FastMath.exp(-x07 * (temp - x10) * (temp - x10)); + double tmp4 = FastMath.exp(-x08 * (temp - x11) * (temp - x11)); jacobian[i] = new double[] { -tmp1, -tmp2, @@ -1500,10 +1501,10 @@ public class MinpackTest extends TestCas double[] f = new double[m]; for (int i = 0; i < m; ++i) { double temp = i / 10.0; - double tmp1 = Math.exp(-x05 * temp); - double tmp2 = Math.exp(-x06 * (temp - x09) * (temp - x09)); - double tmp3 = Math.exp(-x07 * (temp - x10) * (temp - x10)); - double tmp4 = Math.exp(-x08 * (temp - x11) * (temp - x11)); + double tmp1 = FastMath.exp(-x05 * temp); + double tmp2 = FastMath.exp(-x06 * (temp - x09) * (temp - x09)); + double tmp3 = FastMath.exp(-x07 * (temp - x10) * (temp - x10)); + double tmp4 = FastMath.exp(-x08 * (temp - x11) * (temp - x11)); f[i] = y[i] - (x01 * tmp1 + x02 * tmp2 + x03 * tmp3 + x04 * tmp4); } return f; Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/univariate/BrentOptimizerTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/univariate/BrentOptimizerTest.java?rev=990658&r1=990657&r2=990658&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/univariate/BrentOptimizerTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/univariate/BrentOptimizerTest.java Sun Aug 29 22:04:09 2010 @@ -30,6 +30,7 @@ import org.apache.commons.math.analysis. import org.apache.commons.math.optimization.GoalType; import org.apache.commons.math.optimization.UnivariateRealOptimizer; import org.apache.commons.math.stat.descriptive.DescriptiveStatistics; +import org.apache.commons.math.util.FastMath; import org.junit.Test; /** @@ -51,9 +52,9 @@ public final class BrentOptimizerTest { } catch (Exception e) { fail("wrong exception caught"); } - assertEquals(3 * Math.PI / 2, minimizer.optimize(f, GoalType.MINIMIZE, 4, 5), 10 * minimizer.getRelativeAccuracy()); + assertEquals(3 * FastMath.PI / 2, minimizer.optimize(f, GoalType.MINIMIZE, 4, 5), 10 * minimizer.getRelativeAccuracy()); assertTrue(minimizer.getIterationCount() <= 50); - assertEquals(3 * Math.PI / 2, minimizer.optimize(f, GoalType.MINIMIZE, 1, 5), 10 * minimizer.getRelativeAccuracy()); + assertEquals(3 * FastMath.PI / 2, minimizer.optimize(f, GoalType.MINIMIZE, 1, 5), 10 * minimizer.getRelativeAccuracy()); assertTrue(minimizer.getIterationCount() <= 50); assertTrue(minimizer.getEvaluations() <= 100); assertTrue(minimizer.getEvaluations() >= 15); @@ -110,8 +111,8 @@ public final class BrentOptimizerTest { final double medianIter = stat[1].getPercentile(50); final double medianEval = stat[2].getPercentile(50); assertTrue(meanOptValue > -0.27195612812 && meanOptValue < -0.27195612811); - assertEquals(medianIter, 17, Math.ulp(1d)); - assertEquals(medianEval, 18, Math.ulp(1d)); + assertEquals(medianIter, 17, FastMath.ulp(1d)); + assertEquals(medianEval, 18, FastMath.ulp(1d)); } @Test @@ -140,10 +141,10 @@ public final class BrentOptimizerTest { solver.setRelativeAccuracy(1e-8); // endpoint is minimum - double result = solver.optimize(f, GoalType.MINIMIZE, 3 * Math.PI / 2, 5); - assertEquals(3 * Math.PI / 2, result, 10 * solver.getRelativeAccuracy()); + double result = solver.optimize(f, GoalType.MINIMIZE, 3 * FastMath.PI / 2, 5); + assertEquals(3 * FastMath.PI / 2, result, 10 * solver.getRelativeAccuracy()); - result = solver.optimize(f, GoalType.MINIMIZE, 4, 3 * Math.PI / 2); - assertEquals(3 * Math.PI / 2, result, 10 * solver.getRelativeAccuracy()); + result = solver.optimize(f, GoalType.MINIMIZE, 4, 3 * FastMath.PI / 2); + assertEquals(3 * FastMath.PI / 2, result, 10 * solver.getRelativeAccuracy()); } } Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/CorrelatedRandomVectorGeneratorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/CorrelatedRandomVectorGeneratorTest.java?rev=990658&r1=990657&r2=990658&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/CorrelatedRandomVectorGeneratorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/CorrelatedRandomVectorGeneratorTest.java Sun Aug 29 22:04:09 2010 @@ -25,6 +25,7 @@ import org.apache.commons.math.linear.No import org.apache.commons.math.linear.RealMatrix; import org.apache.commons.math.stat.descriptive.moment.VectorialCovariance; import org.apache.commons.math.stat.descriptive.moment.VectorialMean; +import org.apache.commons.math.util.FastMath; public class CorrelatedRandomVectorGeneratorTest extends TestCase { @@ -58,7 +59,7 @@ extends TestCase { for (int i = 0; i < 10; i++) { double[] generated = sg.nextVector(); - assertTrue(Math.abs(generated[0] - 1) > 0.1); + assertTrue(FastMath.abs(generated[0] - 1) > 0.1); } } @@ -90,7 +91,7 @@ extends TestCase { for (int j = 0; j <= i; ++j) { assertEquals(covariance.getEntry(i, j), estimatedCovariance.getEntry(i, j), - 0.1 * (1.0 + Math.abs(mean[i])) * (1.0 + Math.abs(mean[j]))); + 0.1 * (1.0 + FastMath.abs(mean[i])) * (1.0 + FastMath.abs(mean[j]))); } } Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/MersenneTwisterTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/MersenneTwisterTest.java?rev=990658&r1=990657&r2=990658&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/MersenneTwisterTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/MersenneTwisterTest.java Sun Aug 29 22:04:09 2010 @@ -20,6 +20,7 @@ import static org.junit.Assert.assertEqu import static org.junit.Assert.assertTrue; import org.apache.commons.math.stat.descriptive.SummaryStatistics; +import org.apache.commons.math.util.FastMath; import org.junit.Test; public class MersenneTwisterTest { @@ -43,7 +44,7 @@ public class MersenneTwisterTest { sample.addValue(mt.nextDouble()); } assertEquals(0.5, sample.getMean(), 0.02); - assertEquals(1.0 / (2.0 * Math.sqrt(3.0)), + assertEquals(1.0 / (2.0 * FastMath.sqrt(3.0)), sample.getStandardDeviation(), 0.002); } @@ -56,7 +57,7 @@ public class MersenneTwisterTest { sample.addValue(mt.nextFloat()); } assertEquals(0.5, sample.getMean(), 0.01); - assertEquals(1.0 / (2.0 * Math.sqrt(3.0)), + assertEquals(1.0 / (2.0 * FastMath.sqrt(3.0)), sample.getStandardDeviation(), 0.006); } @@ -95,7 +96,7 @@ public class MersenneTwisterTest { --walk; } } - assertTrue(Math.abs(walk) < 120); + assertTrue(FastMath.abs(walk) < 120); } @Test @@ -109,7 +110,7 @@ public class MersenneTwisterTest { --walk; } } - assertTrue(Math.abs(walk) < 50); + assertTrue(FastMath.abs(walk) < 50); } @Test @@ -123,7 +124,7 @@ public class MersenneTwisterTest { --walk; } } - assertTrue(Math.abs(walk) < 250); + assertTrue(FastMath.abs(walk) < 250); } @Test @@ -140,8 +141,8 @@ public class MersenneTwisterTest { int min = Integer.MAX_VALUE; int max = Integer.MIN_VALUE; for (int c : count) { - min = Math.min(min, c); - max = Math.max(max, c); + min = FastMath.min(min, c); + max = FastMath.max(max, c); } int expected = (100000 * bytes.length) / count.length; assertTrue((expected - 200) < min); Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/RandomDataTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/RandomDataTest.java?rev=990658&r1=990657&r2=990658&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/RandomDataTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/RandomDataTest.java Sun Aug 29 22:04:09 2010 @@ -46,6 +46,7 @@ import org.apache.commons.math.stat.Freq import org.apache.commons.math.stat.descriptive.SummaryStatistics; import org.apache.commons.math.stat.inference.ChiSquareTest; import org.apache.commons.math.stat.inference.ChiSquareTestImpl; +import org.apache.commons.math.util.FastMath; /** * Test cases for the RandomData class. @@ -303,7 +304,7 @@ public class RandomDataTest extends Retr while (!widthSufficient) { lowerBinMass = poissonDistribution.cumulativeProbability(lower, lower + binWidth - 1); upperBinMass = poissonDistribution.cumulativeProbability(upper - binWidth + 1, upper); - widthSufficient = Math.min(lowerBinMass, upperBinMass) * sampleSize >= minExpectedCount; + widthSufficient = FastMath.min(lowerBinMass, upperBinMass) * sampleSize >= minExpectedCount; binWidth++; } @@ -563,7 +564,7 @@ public class RandomDataTest extends Retr * t-test at .001-level TODO: replace with externalized t-test, with * test statistic defined in TestStatistic */ - assertTrue(Math.abs(xbar) / (s / Math.sqrt(n)) < 3.29); + assertTrue(FastMath.abs(xbar) / (s / FastMath.sqrt(n)) < 3.29); } /** test failure modes and distribution of nextExponential() */ Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/special/ErfTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/special/ErfTest.java?rev=990658&r1=990657&r2=990658&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/special/ErfTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/special/ErfTest.java Sun Aug 29 22:04:09 2010 @@ -18,6 +18,7 @@ package org.apache.commons.math.special; import org.apache.commons.math.MathException; +import org.apache.commons.math.util.FastMath; import junit.framework.TestCase; @@ -33,7 +34,7 @@ public class ErfTest extends TestCase { } public void testErf1960() throws MathException { - double x = 1.960 / Math.sqrt(2.0); + double x = 1.960 / FastMath.sqrt(2.0); double actual = Erf.erf(x); double expected = 0.95; assertEquals(expected, actual, 1.0e-5); @@ -44,7 +45,7 @@ public class ErfTest extends TestCase { } public void testErf2576() throws MathException { - double x = 2.576 / Math.sqrt(2.0); + double x = 2.576 / FastMath.sqrt(2.0); double actual = Erf.erf(x); double expected = 0.99; assertEquals(expected, actual, 1.0e-5); @@ -55,7 +56,7 @@ public class ErfTest extends TestCase { } public void testErf2807() throws MathException { - double x = 2.807 / Math.sqrt(2.0); + double x = 2.807 / FastMath.sqrt(2.0); double actual = Erf.erf(x); double expected = 0.995; assertEquals(expected, actual, 1.0e-5); @@ -66,7 +67,7 @@ public class ErfTest extends TestCase { } public void testErf3291() throws MathException { - double x = 3.291 / Math.sqrt(2.0); + double x = 3.291 / FastMath.sqrt(2.0); double actual = Erf.erf(x); double expected = 0.999; assertEquals(expected, actual, 1.0e-5); Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/special/GammaTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/special/GammaTest.java?rev=990658&r1=990657&r2=990658&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/special/GammaTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/special/GammaTest.java Sun Aug 29 22:04:09 2010 @@ -18,6 +18,7 @@ package org.apache.commons.math.special; import org.apache.commons.math.MathException; import org.apache.commons.math.TestUtils; +import org.apache.commons.math.util.FastMath; import junit.framework.TestCase; @@ -115,7 +116,7 @@ public class GammaTest extends TestCase -1e+17, -1e+18, -1e+19, -1e+20, -1e+21, -1e+22, -1e+23, -1e+24, -1e+25, -1e+26, -1e+27, -1e+28, -1e+29, -1e+30}; for (double n = 1; n < 30; n++) { - checkRelativeError(String.format("Test %.0f: ", n), expected[(int) (n - 1)], Gamma.digamma(Math.pow(10.0, -n)), 1e-8); + checkRelativeError(String.format("Test %.0f: ", n), expected[(int) (n - 1)], Gamma.digamma(FastMath.pow(10.0, -n)), 1e-8); } } @@ -145,6 +146,6 @@ public class GammaTest extends TestCase } private void checkRelativeError(String msg, double expected, double actual, double tolerance) { - assertEquals(msg, expected, actual, Math.abs(tolerance * actual)); + assertEquals(msg, expected, actual, FastMath.abs(tolerance * actual)); } } Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/StatUtilsTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/StatUtilsTest.java?rev=990658&r1=990657&r2=990658&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/StatUtilsTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/StatUtilsTest.java Sun Aug 29 22:04:09 2010 @@ -19,6 +19,7 @@ package org.apache.commons.math.stat; import junit.framework.TestCase; import org.apache.commons.math.TestUtils; +import org.apache.commons.math.util.FastMath; /** * Test cases for the {@link StatUtils} class. @@ -203,13 +204,13 @@ public final class StatUtilsTest extends // test one x = new double[] {two}; - TestUtils.assertEquals(Math.log(two), StatUtils.sumLog(x), tolerance); - TestUtils.assertEquals(Math.log(two), StatUtils.sumLog(x, 0, 1), tolerance); + TestUtils.assertEquals(FastMath.log(two), StatUtils.sumLog(x), tolerance); + TestUtils.assertEquals(FastMath.log(two), StatUtils.sumLog(x, 0, 1), tolerance); // test many x = new double[] {one, two, two, three}; - TestUtils.assertEquals(Math.log(one) + 2.0 * Math.log(two) + Math.log(three), StatUtils.sumLog(x), tolerance); - TestUtils.assertEquals(2.0 * Math.log(two), StatUtils.sumLog(x, 1, 2), tolerance); + TestUtils.assertEquals(FastMath.log(one) + 2.0 * FastMath.log(two) + FastMath.log(three), StatUtils.sumLog(x), tolerance); + TestUtils.assertEquals(2.0 * FastMath.log(two), StatUtils.sumLog(x, 1, 2), tolerance); } public void testMean() { @@ -414,9 +415,9 @@ public final class StatUtilsTest extends // expected } test = new double[] {2, 4, 6, 8}; - assertEquals(Math.exp(0.25d * StatUtils.sumLog(test)), + assertEquals(FastMath.exp(0.25d * StatUtils.sumLog(test)), StatUtils.geometricMean(test), Double.MIN_VALUE); - assertEquals(Math.exp(0.5 * StatUtils.sumLog(test, 0, 2)), + assertEquals(FastMath.exp(0.5 * StatUtils.sumLog(test, 0, 2)), StatUtils.geometricMean(test, 0, 2), Double.MIN_VALUE); } } Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/clustering/EuclideanIntegerPointTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/clustering/EuclideanIntegerPointTest.java?rev=990658&r1=990657&r2=990658&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/clustering/EuclideanIntegerPointTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/clustering/EuclideanIntegerPointTest.java Sun Aug 29 22:04:09 2010 @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.List; import org.apache.commons.math.TestUtils; +import org.apache.commons.math.util.FastMath; import org.junit.Test; public class EuclideanIntegerPointTest { @@ -38,7 +39,7 @@ public class EuclideanIntegerPointTest { public void testDistance() { EuclideanIntegerPoint e1 = new EuclideanIntegerPoint(new int[] { -3, -2, -1, 0, 1 }); EuclideanIntegerPoint e2 = new EuclideanIntegerPoint(new int[] { 1, 0, -1, 1, 1 }); - assertEquals(Math.sqrt(21.0), e1.distanceFrom(e2), 1.0e-15); + assertEquals(FastMath.sqrt(21.0), e1.distanceFrom(e2), 1.0e-15); assertEquals(0.0, e1.distanceFrom(e1), 1.0e-15); assertEquals(0.0, e2.distanceFrom(e2), 1.0e-15); } Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/correlation/PearsonsCorrelationTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/correlation/PearsonsCorrelationTest.java?rev=990658&r1=990657&r2=990658&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/correlation/PearsonsCorrelationTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/correlation/PearsonsCorrelationTest.java Sun Aug 29 22:04:09 2010 @@ -21,6 +21,7 @@ import org.apache.commons.math.distribut import org.apache.commons.math.distribution.TDistributionImpl; import org.apache.commons.math.linear.RealMatrix; import org.apache.commons.math.linear.BlockRealMatrix; +import org.apache.commons.math.util.FastMath; import junit.framework.TestCase; @@ -227,7 +228,7 @@ public class PearsonsCorrelationTest ext RealMatrix stdErrors = corrInstance.getCorrelationStandardErrors(); for (int i = 0; i < 5; i++) { for (int j = 0; j < i; j++) { - double t = Math.abs(rValues.getEntry(i, j)) / stdErrors.getEntry(i, j); + double t = FastMath.abs(rValues.getEntry(i, j)) / stdErrors.getEntry(i, j); double p = 2 * (1 - tDistribution.cumulativeProbability(t)); assertEquals(p, pValues.getEntry(i, j), 10E-15); } Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/ListUnivariateImpl.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/ListUnivariateImpl.java?rev=990658&r1=990657&r2=990658&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/ListUnivariateImpl.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/ListUnivariateImpl.java Sun Aug 29 22:04:09 2010 @@ -24,6 +24,7 @@ import org.apache.commons.math.MathExcep import org.apache.commons.math.stat.descriptive.UnivariateStatistic; import org.apache.commons.math.stat.descriptive.DescriptiveStatistics; import org.apache.commons.math.util.DefaultTransformer; +import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.NumberTransformer; /** @@ -83,7 +84,7 @@ public class ListUnivariateImpl extends if (windowSize != DescriptiveStatistics.INFINITE_WINDOW && windowSize < list.size()) { - length = list.size() - Math.max(0, list.size() - windowSize); + length = list.size() - FastMath.max(0, list.size() - windowSize); } // Create an array to hold all values Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/ListUnivariateImplTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/ListUnivariateImplTest.java?rev=990658&r1=990657&r2=990658&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/ListUnivariateImplTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/ListUnivariateImplTest.java Sun Aug 29 22:04:09 2010 @@ -22,6 +22,7 @@ import java.util.List; import junit.framework.TestCase; import org.apache.commons.math.TestUtils; +import org.apache.commons.math.util.FastMath; /** * Test cases for the {@link ListUnivariateImpl} class. @@ -39,7 +40,7 @@ public final class ListUnivariateImplTes private double sumSq = 18; private double sum = 8; private double var = 0.666666666666666666667; - private double std = Math.sqrt(var); + private double std = FastMath.sqrt(var); private double n = 4; private double min = 1; private double max = 3; Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/MixedListUnivariateImplTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/MixedListUnivariateImplTest.java?rev=990658&r1=990657&r2=990658&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/MixedListUnivariateImplTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/MixedListUnivariateImplTest.java Sun Aug 29 22:04:09 2010 @@ -22,6 +22,7 @@ import java.util.List; import junit.framework.TestCase; +import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.NumberTransformer; import org.apache.commons.math.util.TransformerMap; @@ -40,7 +41,7 @@ public final class MixedListUnivariateIm private double sumSq = 18; private double sum = 8; private double var = 0.666666666666666666667; - private double std = Math.sqrt(var); + private double std = FastMath.sqrt(var); private double n = 4; private double min = 1; private double max = 3; Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatisticsTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatisticsTest.java?rev=990658&r1=990657&r2=990658&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatisticsTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatisticsTest.java Sun Aug 29 22:04:09 2010 @@ -24,6 +24,7 @@ import junit.framework.TestCase; import org.apache.commons.math.DimensionMismatchException; import org.apache.commons.math.TestUtils; import org.apache.commons.math.stat.descriptive.moment.Mean; +import org.apache.commons.math.util.FastMath; /** * Test cases for the {@link MultivariateSummaryStatistics} class. @@ -202,8 +203,8 @@ public class MultivariateSummaryStatisti assertEquals( 2.9129506302439405217, u.getGeometricMean()[1], 1.0e-10); assertEquals( 2, u.getMean()[0], 1.0e-10); assertEquals( 3, u.getMean()[1], 1.0e-10); - assertEquals(Math.sqrt(2.0 / 3.0), u.getStandardDeviation()[0], 1.0e-10); - assertEquals(Math.sqrt(2.0 / 3.0), u.getStandardDeviation()[1], 1.0e-10); + assertEquals(FastMath.sqrt(2.0 / 3.0), u.getStandardDeviation()[0], 1.0e-10); + assertEquals(FastMath.sqrt(2.0 / 3.0), u.getStandardDeviation()[1], 1.0e-10); assertEquals(2.0 / 3.0, u.getCovariance().getEntry(0, 0), 1.0e-10); assertEquals(2.0 / 3.0, u.getCovariance().getEntry(0, 1), 1.0e-10); assertEquals(2.0 / 3.0, u.getCovariance().getEntry(1, 0), 1.0e-10); Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/StorelessUnivariateStatisticAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/StorelessUnivariateStatisticAbstractTest.java?rev=990658&r1=990657&r2=990658&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/StorelessUnivariateStatisticAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/StorelessUnivariateStatisticAbstractTest.java Sun Aug 29 22:04:09 2010 @@ -18,6 +18,7 @@ package org.apache.commons.math.stat.des import org.apache.commons.math.TestUtils; import org.apache.commons.math.stat.descriptive.moment.SecondMoment; +import org.apache.commons.math.util.FastMath; /** * Test cases for {@link StorelessUnivariateStatistic} classes. @@ -183,7 +184,7 @@ public abstract class StorelessUnivariat StorelessUnivariateStatistic replica = null; // Randomly select a portion of testArray to load first - long index = Math.round((Math.random()) * testArray.length); + long index = FastMath.round((FastMath.random()) * testArray.length); // Put first half in master and copy master to replica master.incrementAll(testArray, 0, (int) index); Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/SummaryStatisticsTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/SummaryStatisticsTest.java?rev=990658&r1=990657&r2=990658&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/SummaryStatisticsTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/SummaryStatisticsTest.java Sun Aug 29 22:04:09 2010 @@ -21,6 +21,7 @@ import junit.framework.TestCase; import org.apache.commons.math.TestUtils; import org.apache.commons.math.stat.descriptive.moment.Mean; import org.apache.commons.math.stat.descriptive.summary.Sum; +import org.apache.commons.math.util.FastMath; /** * Test cases for the {@link SummaryStatistics} class. * @@ -37,7 +38,7 @@ public class SummaryStatisticsTest exten private double sumSq = 18; private double sum = 8; private double var = 0.666666666666666666667; - private double std = Math.sqrt(var); + private double std = FastMath.sqrt(var); private double n = 4; private double min = 1; private double max = 3; @@ -275,7 +276,7 @@ public class SummaryStatisticsTest exten u.addValue(3); assertEquals(4, u.getMean(), 1E-14); assertEquals(4, u.getSumOfLogs(), 1E-14); - assertEquals(Math.exp(2), u.getGeometricMean(), 1E-14); + assertEquals(FastMath.exp(2), u.getGeometricMean(), 1E-14); u.clear(); u.addValue(1); u.addValue(2); Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/UnivariateStatisticAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/UnivariateStatisticAbstractTest.java?rev=990658&r1=990657&r2=990658&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/UnivariateStatisticAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/UnivariateStatisticAbstractTest.java Sun Aug 29 22:04:09 2010 @@ -24,6 +24,7 @@ import junit.framework.TestCase; import org.apache.commons.math.TestUtils; import org.apache.commons.math.random.RandomData; import org.apache.commons.math.random.RandomDataImpl; +import org.apache.commons.math.util.FastMath; /** * Test cases for the {@link UnivariateStatistic} class. @@ -35,7 +36,7 @@ public abstract class UnivariateStatisti protected double geoMean = 12.070589161633011d; protected double var = 10.00235930735931d; - protected double std = Math.sqrt(var); + protected double std = FastMath.sqrt(var); protected double skew = 1.437423729196190d; protected double kurt = 2.377191264804700d; @@ -56,7 +57,7 @@ public abstract class UnivariateStatisti protected double weightedMean = 12.366995073891626d; protected double weightedVar = 9.974760968886391d; - protected double weightedStd = Math.sqrt(weightedVar); + protected double weightedStd = FastMath.sqrt(weightedVar); protected double weightedProduct = 8517647448765288000000d; protected double weightedSum = 251.05d; Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/StandardDeviationTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/StandardDeviationTest.java?rev=990658&r1=990657&r2=990658&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/StandardDeviationTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/moment/StandardDeviationTest.java Sun Aug 29 22:04:09 2010 @@ -18,6 +18,7 @@ package org.apache.commons.math.stat.des import org.apache.commons.math.stat.descriptive.StorelessUnivariateStatisticAbstractTest; import org.apache.commons.math.stat.descriptive.UnivariateStatistic; +import org.apache.commons.math.util.FastMath; /** * Test cases for the {@link UnivariateStatistic} class. @@ -92,7 +93,7 @@ public class StandardDeviationTest exten for (int i = 0; i < v.length; i++) { sum += (v[i] - mean) * (v[i] - mean); } - return Math.sqrt(sum / v.length); + return FastMath.sqrt(sum / v.length); } } Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastCosineTransformerTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastCosineTransformerTest.java?rev=990658&r1=990657&r2=990658&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastCosineTransformerTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastCosineTransformerTest.java Sun Aug 29 22:04:09 2010 @@ -17,6 +17,7 @@ package org.apache.commons.math.transform; import org.apache.commons.math.analysis.*; +import org.apache.commons.math.util.FastMath; import org.apache.commons.math.MathException; import junit.framework.TestCase; @@ -52,7 +53,7 @@ public final class FastCosineTransformer assertEquals(x[i], result[i], tolerance); } - FastFourierTransformer.scaleArray(x, Math.sqrt(0.5 * (x.length-1))); + FastFourierTransformer.scaleArray(x, FastMath.sqrt(0.5 * (x.length-1))); result = transformer.transform2(y); for (int i = 0; i < result.length; i++) { @@ -76,13 +77,13 @@ public final class FastCosineTransformer double expected[] = { 0.0, 3.26197262739567, 0.0, -2.17958042710327, 0.0, -0.648846697642915, 0.0, -0.433545502649478, 0.0 }; - min = 0.0; max = 2.0 * Math.PI * N / (N-1); + min = 0.0; max = 2.0 * FastMath.PI * N / (N-1); result = transformer.transform(f, min, max, N); for (int i = 0; i < N; i++) { assertEquals(expected[i], result[i], tolerance); } - min = -Math.PI; max = Math.PI * (N+1) / (N-1); + min = -FastMath.PI; max = FastMath.PI * (N+1) / (N-1); result = transformer.transform(f, min, max, N); for (int i = 0; i < N; i++) { assertEquals(-expected[i], result[i], tolerance); Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastFourierTransformerTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastFourierTransformerTest.java?rev=990658&r1=990657&r2=990658&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastFourierTransformerTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastFourierTransformerTest.java Sun Aug 29 22:04:09 2010 @@ -18,6 +18,7 @@ package org.apache.commons.math.transfor import org.apache.commons.math.analysis.*; import org.apache.commons.math.complex.*; +import org.apache.commons.math.util.FastMath; import org.apache.commons.math.MathException; import junit.framework.TestCase; @@ -62,7 +63,7 @@ public final class FastFourierTransforme } double x2[] = {10.4, 21.6, 40.8, 13.6, 23.2, 32.8, 13.6, 19.2}; - FastFourierTransformer.scaleArray(x2, 1.0 / Math.sqrt(x2.length)); + FastFourierTransformer.scaleArray(x2, 1.0 / FastMath.sqrt(x2.length)); Complex y2[] = y; result = transformer.transform2(y2); @@ -119,7 +120,7 @@ public final class FastFourierTransforme Complex result[]; int N = 1 << 8; double min, max, tolerance = 1E-12; - min = 0.0; max = 2.0 * Math.PI; + min = 0.0; max = 2.0 * FastMath.PI; result = transformer.transform(f, min, max, N); assertEquals(0.0, result[1].getReal(), tolerance); assertEquals(-(N >> 1), result[1].getImaginary(), tolerance); @@ -130,7 +131,7 @@ public final class FastFourierTransforme assertEquals(0.0, result[i].getImaginary(), tolerance); } - min = -Math.PI; max = Math.PI; + min = -FastMath.PI; max = FastMath.PI; result = transformer.inversetransform(f, min, max, N); assertEquals(0.0, result[1].getReal(), tolerance); assertEquals(-0.5, result[1].getImaginary(), tolerance); Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastSineTransformerTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastSineTransformerTest.java?rev=990658&r1=990657&r2=990658&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastSineTransformerTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/transform/FastSineTransformerTest.java Sun Aug 29 22:04:09 2010 @@ -17,6 +17,7 @@ package org.apache.commons.math.transform; import org.apache.commons.math.analysis.*; +import org.apache.commons.math.util.FastMath; import org.apache.commons.math.MathException; import junit.framework.TestCase; @@ -52,7 +53,7 @@ public final class FastSineTransformerTe assertEquals(x[i], result[i], tolerance); } - FastFourierTransformer.scaleArray(x, Math.sqrt(x.length / 2.0)); + FastFourierTransformer.scaleArray(x, FastMath.sqrt(x.length / 2.0)); result = transformer.transform2(y); for (int i = 0; i < result.length; i++) { @@ -73,14 +74,14 @@ public final class FastSineTransformerTe FastSineTransformer transformer = new FastSineTransformer(); double min, max, result[], tolerance = 1E-12; int N = 1 << 8; - min = 0.0; max = 2.0 * Math.PI; + min = 0.0; max = 2.0 * FastMath.PI; result = transformer.transform(f, min, max, N); assertEquals(N >> 1, result[2], tolerance); for (int i = 0; i < N; i += (i == 1 ? 2 : 1)) { assertEquals(0.0, result[i], tolerance); } - min = -Math.PI; max = Math.PI; + min = -FastMath.PI; max = FastMath.PI; result = transformer.transform(f, min, max, N); assertEquals(-(N >> 1), result[2], tolerance); for (int i = 0; i < N; i += (i == 1 ? 2 : 1)) { Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/BigRealTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/BigRealTest.java?rev=990658&r1=990657&r2=990658&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/BigRealTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/BigRealTest.java Sun Aug 29 22:04:09 2010 @@ -117,7 +117,7 @@ public class BigRealTest { public void testSerial() { BigReal[] Reals = { new BigReal(3.0), BigReal.ONE, BigReal.ZERO, - new BigReal(17), new BigReal(Math.PI), + new BigReal(17), new BigReal(FastMath.PI), new BigReal(-2.5) }; for (BigReal Real : Reals) { 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=990658&r1=990657&r2=990658&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 Sun Aug 29 22:04:09 2010 @@ -164,7 +164,7 @@ public final class MathUtilsTest extends for (int k = 0; k <= n; k++) { assertEquals(n + " choose " + k, binomialCoefficient(n, k), MathUtils.binomialCoefficient(n, k)); assertEquals(n + " choose " + k, binomialCoefficient(n, k), MathUtils.binomialCoefficientDouble(n, k), Double.MIN_VALUE); - assertEquals(n + " choose " + k, Math.log(binomialCoefficient(n, k)), MathUtils.binomialCoefficientLog(n, k), 10E-12); + assertEquals(n + " choose " + k, FastMath.log(binomialCoefficient(n, k)), MathUtils.binomialCoefficientLog(n, k), 10E-12); } } @@ -176,7 +176,7 @@ public final class MathUtilsTest extends MathUtils.binomialCoefficient(n[i], k[i])); assertEquals(n[i] + " choose " + k[i], expected, MathUtils.binomialCoefficientDouble(n[i], k[i]), 0.0); - assertEquals("log(" + n[i] + " choose " + k[i] + ")", Math.log(expected), + assertEquals("log(" + n[i] + " choose " + k[i] + ")", FastMath.log(expected), MathUtils.binomialCoefficientLog(n[i], k[i]), 0.0); } } @@ -211,7 +211,7 @@ public final class MathUtilsTest extends assertEquals(n + " choose " + k, 1., MathUtils.binomialCoefficientDouble(n, k) / exactResult, 1e-10); assertEquals(n + " choose " + k, 1, - MathUtils.binomialCoefficientLog(n, k) / Math.log(exactResult), 1e-10); + MathUtils.binomialCoefficientLog(n, k) / FastMath.log(exactResult), 1e-10); } } } @@ -237,7 +237,7 @@ public final class MathUtilsTest extends exactResult = binomialCoefficient(n, 3); assertEquals(exactResult, ourResult); assertEquals(1, MathUtils.binomialCoefficientDouble(n, 3) / exactResult, 1e-10); - assertEquals(1, MathUtils.binomialCoefficientLog(n, 3) / Math.log(exactResult), 1e-10); + assertEquals(1, MathUtils.binomialCoefficientLog(n, 3) / FastMath.log(exactResult), 1e-10); } @@ -362,17 +362,17 @@ public final class MathUtilsTest extends public void testEqualsWithAllowedUlps() { assertTrue(MathUtils.equals(0.0, -0.0, 1)); - assertTrue(MathUtils.equals(1.0, 1 + Math.ulp(1d), 1)); - assertFalse(MathUtils.equals(1.0, 1 + 2 * Math.ulp(1d), 1)); + assertTrue(MathUtils.equals(1.0, 1 + FastMath.ulp(1d), 1)); + assertFalse(MathUtils.equals(1.0, 1 + 2 * FastMath.ulp(1d), 1)); - final double nUp1 = MathUtils.nextAfter(1d, Double.POSITIVE_INFINITY); - final double nnUp1 = MathUtils.nextAfter(nUp1, Double.POSITIVE_INFINITY); + final double nUp1 = FastMath.nextAfter(1d, Double.POSITIVE_INFINITY); + final double nnUp1 = FastMath.nextAfter(nUp1, Double.POSITIVE_INFINITY); assertTrue(MathUtils.equals(1.0, nUp1, 1)); assertTrue(MathUtils.equals(nUp1, nnUp1, 1)); assertFalse(MathUtils.equals(1.0, nnUp1, 1)); - assertTrue(MathUtils.equals(0.0, Math.ulp(0d), 1)); - assertTrue(MathUtils.equals(0.0, -Math.ulp(0d), 1)); + assertTrue(MathUtils.equals(0.0, FastMath.ulp(0d), 1)); + assertTrue(MathUtils.equals(0.0, -FastMath.ulp(0d), 1)); assertTrue(MathUtils.equals(153.0, 153.0, 1)); @@ -400,17 +400,17 @@ public final class MathUtilsTest extends public void testEqualsIncludingNaNWithAllowedUlps() { assertTrue(MathUtils.equalsIncludingNaN(0.0, -0.0, 1)); - assertTrue(MathUtils.equalsIncludingNaN(1.0, 1 + Math.ulp(1d), 1)); - assertFalse(MathUtils.equalsIncludingNaN(1.0, 1 + 2 * Math.ulp(1d), 1)); + assertTrue(MathUtils.equalsIncludingNaN(1.0, 1 + FastMath.ulp(1d), 1)); + assertFalse(MathUtils.equalsIncludingNaN(1.0, 1 + 2 * FastMath.ulp(1d), 1)); - final double nUp1 = MathUtils.nextAfter(1d, Double.POSITIVE_INFINITY); - final double nnUp1 = Math.nextAfter(nUp1, Double.POSITIVE_INFINITY); + final double nUp1 = FastMath.nextAfter(1d, Double.POSITIVE_INFINITY); + final double nnUp1 = FastMath.nextAfter(nUp1, Double.POSITIVE_INFINITY); assertTrue(MathUtils.equalsIncludingNaN(1.0, nUp1, 1)); assertTrue(MathUtils.equalsIncludingNaN(nUp1, nnUp1, 1)); assertFalse(MathUtils.equalsIncludingNaN(1.0, nnUp1, 1)); - assertTrue(MathUtils.equalsIncludingNaN(0.0, Math.ulp(0d), 1)); - assertTrue(MathUtils.equalsIncludingNaN(0.0, -Math.ulp(0d), 1)); + assertTrue(MathUtils.equalsIncludingNaN(0.0, FastMath.ulp(0d), 1)); + assertTrue(MathUtils.equalsIncludingNaN(0.0, -FastMath.ulp(0d), 1)); assertTrue(MathUtils.equalsIncludingNaN(153.0, 153.0, 1)); @@ -456,7 +456,7 @@ public final class MathUtilsTest extends assertFalse(MathUtils.equals(new double[] { Double.POSITIVE_INFINITY }, new double[] { Double.NEGATIVE_INFINITY })); assertFalse(MathUtils.equals(new double[] { 1d }, - new double[] { MathUtils.nextAfter(1d, 2d) })); + new double[] { FastMath.nextAfter(1d, 2d) })); } @@ -477,14 +477,14 @@ public final class MathUtilsTest extends assertFalse(MathUtils.equalsIncludingNaN(new double[] { Double.POSITIVE_INFINITY }, new double[] { Double.NEGATIVE_INFINITY })); assertFalse(MathUtils.equalsIncludingNaN(new double[] { 1d }, - new double[] { MathUtils.nextAfter(MathUtils.nextAfter(1d, 2d), 2d) })); + new double[] { FastMath.nextAfter(FastMath.nextAfter(1d, 2d), 2d) })); } public void testFactorial() { for (int i = 1; i < 21; i++) { assertEquals(i + "! ", factorial(i), MathUtils.factorial(i)); assertEquals(i + "! ", factorial(i), MathUtils.factorialDouble(i), Double.MIN_VALUE); - assertEquals(i + "! ", Math.log(factorial(i)), MathUtils.factorialLog(i), 10E-12); + assertEquals(i + "! ", FastMath.log(factorial(i)), MathUtils.factorialLog(i), 10E-12); } assertEquals("0", 1, MathUtils.factorial(0)); @@ -680,7 +680,7 @@ public final class MathUtilsTest extends Double.NEGATIVE_INFINITY, 1d, 0d })); assertFalse(MathUtils.hash(new double[] { 1d }) == - MathUtils.hash(new double[] { MathUtils.nextAfter(1d, 2d) })); + MathUtils.hash(new double[] { FastMath.nextAfter(1d, 2d) })); assertFalse(MathUtils.hash(new double[] { 1d }) == MathUtils.hash(new double[] { 1d, 1d })); } @@ -907,84 +907,84 @@ public final class MathUtilsTest extends public void testNextAfter() { // 0x402fffffffffffff 0x404123456789abcd -> 4030000000000000 - assertEquals(16.0, MathUtils.nextAfter(15.999999999999998, 34.27555555555555), 0.0); + assertEquals(16.0, FastMath.nextAfter(15.999999999999998, 34.27555555555555), 0.0); // 0xc02fffffffffffff 0x404123456789abcd -> c02ffffffffffffe - assertEquals(-15.999999999999996, MathUtils.nextAfter(-15.999999999999998, 34.27555555555555), 0.0); + assertEquals(-15.999999999999996, FastMath.nextAfter(-15.999999999999998, 34.27555555555555), 0.0); // 0x402fffffffffffff 0x400123456789abcd -> 402ffffffffffffe - assertEquals(15.999999999999996, MathUtils.nextAfter(15.999999999999998, 2.142222222222222), 0.0); + assertEquals(15.999999999999996, FastMath.nextAfter(15.999999999999998, 2.142222222222222), 0.0); // 0xc02fffffffffffff 0x400123456789abcd -> c02ffffffffffffe - assertEquals(-15.999999999999996, MathUtils.nextAfter(-15.999999999999998, 2.142222222222222), 0.0); + assertEquals(-15.999999999999996, FastMath.nextAfter(-15.999999999999998, 2.142222222222222), 0.0); // 0x4020000000000000 0x404123456789abcd -> 4020000000000001 - assertEquals(8.000000000000002, MathUtils.nextAfter(8.0, 34.27555555555555), 0.0); + assertEquals(8.000000000000002, FastMath.nextAfter(8.0, 34.27555555555555), 0.0); // 0xc020000000000000 0x404123456789abcd -> c01fffffffffffff - assertEquals(-7.999999999999999, MathUtils.nextAfter(-8.0, 34.27555555555555), 0.0); + assertEquals(-7.999999999999999, FastMath.nextAfter(-8.0, 34.27555555555555), 0.0); // 0x4020000000000000 0x400123456789abcd -> 401fffffffffffff - assertEquals(7.999999999999999, MathUtils.nextAfter(8.0, 2.142222222222222), 0.0); + assertEquals(7.999999999999999, FastMath.nextAfter(8.0, 2.142222222222222), 0.0); // 0xc020000000000000 0x400123456789abcd -> c01fffffffffffff - assertEquals(-7.999999999999999, MathUtils.nextAfter(-8.0, 2.142222222222222), 0.0); + assertEquals(-7.999999999999999, FastMath.nextAfter(-8.0, 2.142222222222222), 0.0); // 0x3f2e43753d36a223 0x3f2e43753d36a224 -> 3f2e43753d36a224 - assertEquals(2.308922399667661E-4, MathUtils.nextAfter(2.3089223996676606E-4, 2.308922399667661E-4), 0.0); + assertEquals(2.308922399667661E-4, FastMath.nextAfter(2.3089223996676606E-4, 2.308922399667661E-4), 0.0); // 0x3f2e43753d36a223 0x3f2e43753d36a223 -> 3f2e43753d36a224 - assertEquals(2.308922399667661E-4, MathUtils.nextAfter(2.3089223996676606E-4, 2.3089223996676606E-4), 0.0); + assertEquals(2.308922399667661E-4, FastMath.nextAfter(2.3089223996676606E-4, 2.3089223996676606E-4), 0.0); // 0x3f2e43753d36a223 0x3f2e43753d36a222 -> 3f2e43753d36a222 - assertEquals(2.3089223996676603E-4, MathUtils.nextAfter(2.3089223996676606E-4, 2.3089223996676603E-4), 0.0); + assertEquals(2.3089223996676603E-4, FastMath.nextAfter(2.3089223996676606E-4, 2.3089223996676603E-4), 0.0); // 0x3f2e43753d36a223 0xbf2e43753d36a224 -> 3f2e43753d36a222 - assertEquals(2.3089223996676603E-4, MathUtils.nextAfter(2.3089223996676606E-4, -2.308922399667661E-4), 0.0); + assertEquals(2.3089223996676603E-4, FastMath.nextAfter(2.3089223996676606E-4, -2.308922399667661E-4), 0.0); // 0x3f2e43753d36a223 0xbf2e43753d36a223 -> 3f2e43753d36a222 - assertEquals(2.3089223996676603E-4, MathUtils.nextAfter(2.3089223996676606E-4, -2.3089223996676606E-4), 0.0); + assertEquals(2.3089223996676603E-4, FastMath.nextAfter(2.3089223996676606E-4, -2.3089223996676606E-4), 0.0); // 0x3f2e43753d36a223 0xbf2e43753d36a222 -> 3f2e43753d36a222 - assertEquals(2.3089223996676603E-4, MathUtils.nextAfter(2.3089223996676606E-4, -2.3089223996676603E-4), 0.0); + assertEquals(2.3089223996676603E-4, FastMath.nextAfter(2.3089223996676606E-4, -2.3089223996676603E-4), 0.0); // 0xbf2e43753d36a223 0x3f2e43753d36a224 -> bf2e43753d36a222 - assertEquals(-2.3089223996676603E-4, MathUtils.nextAfter(-2.3089223996676606E-4, 2.308922399667661E-4), 0.0); + assertEquals(-2.3089223996676603E-4, FastMath.nextAfter(-2.3089223996676606E-4, 2.308922399667661E-4), 0.0); // 0xbf2e43753d36a223 0x3f2e43753d36a223 -> bf2e43753d36a222 - assertEquals(-2.3089223996676603E-4, MathUtils.nextAfter(-2.3089223996676606E-4, 2.3089223996676606E-4), 0.0); + assertEquals(-2.3089223996676603E-4, FastMath.nextAfter(-2.3089223996676606E-4, 2.3089223996676606E-4), 0.0); // 0xbf2e43753d36a223 0x3f2e43753d36a222 -> bf2e43753d36a222 - assertEquals(-2.3089223996676603E-4, MathUtils.nextAfter(-2.3089223996676606E-4, 2.3089223996676603E-4), 0.0); + assertEquals(-2.3089223996676603E-4, FastMath.nextAfter(-2.3089223996676606E-4, 2.3089223996676603E-4), 0.0); // 0xbf2e43753d36a223 0xbf2e43753d36a224 -> bf2e43753d36a224 - assertEquals(-2.308922399667661E-4, MathUtils.nextAfter(-2.3089223996676606E-4, -2.308922399667661E-4), 0.0); + assertEquals(-2.308922399667661E-4, FastMath.nextAfter(-2.3089223996676606E-4, -2.308922399667661E-4), 0.0); // 0xbf2e43753d36a223 0xbf2e43753d36a223 -> bf2e43753d36a224 - assertEquals(-2.308922399667661E-4, MathUtils.nextAfter(-2.3089223996676606E-4, -2.3089223996676606E-4), 0.0); + assertEquals(-2.308922399667661E-4, FastMath.nextAfter(-2.3089223996676606E-4, -2.3089223996676606E-4), 0.0); // 0xbf2e43753d36a223 0xbf2e43753d36a222 -> bf2e43753d36a222 - assertEquals(-2.3089223996676603E-4, MathUtils.nextAfter(-2.3089223996676606E-4, -2.3089223996676603E-4), 0.0); + assertEquals(-2.3089223996676603E-4, FastMath.nextAfter(-2.3089223996676606E-4, -2.3089223996676603E-4), 0.0); } public void testNextAfterSpecialCases() { - assertTrue(Double.isInfinite(MathUtils.nextAfter(Double.NEGATIVE_INFINITY, 0))); - assertTrue(Double.isInfinite(MathUtils.nextAfter(Double.POSITIVE_INFINITY, 0))); - assertTrue(Double.isNaN(MathUtils.nextAfter(Double.NaN, 0))); - assertTrue(Double.isInfinite(MathUtils.nextAfter(Double.MAX_VALUE, Double.POSITIVE_INFINITY))); - assertTrue(Double.isInfinite(MathUtils.nextAfter(-Double.MAX_VALUE, Double.NEGATIVE_INFINITY))); - assertEquals(Double.MIN_VALUE, MathUtils.nextAfter(0, 1), 0); - assertEquals(-Double.MIN_VALUE, MathUtils.nextAfter(0, -1), 0); - assertEquals(0, MathUtils.nextAfter(Double.MIN_VALUE, -1), 0); - assertEquals(0, MathUtils.nextAfter(-Double.MIN_VALUE, 1), 0); + assertTrue(Double.isInfinite(FastMath.nextAfter(Double.NEGATIVE_INFINITY, 0))); + assertTrue(Double.isInfinite(FastMath.nextAfter(Double.POSITIVE_INFINITY, 0))); + assertTrue(Double.isNaN(FastMath.nextAfter(Double.NaN, 0))); + assertTrue(Double.isInfinite(FastMath.nextAfter(Double.MAX_VALUE, Double.POSITIVE_INFINITY))); + assertTrue(Double.isInfinite(FastMath.nextAfter(-Double.MAX_VALUE, Double.NEGATIVE_INFINITY))); + assertEquals(Double.MIN_VALUE, FastMath.nextAfter(0, 1), 0); + assertEquals(-Double.MIN_VALUE, FastMath.nextAfter(0, -1), 0); + assertEquals(0, FastMath.nextAfter(Double.MIN_VALUE, -1), 0); + assertEquals(0, FastMath.nextAfter(-Double.MIN_VALUE, 1), 0); } public void testScalb() { assertEquals( 0.0, MathUtils.scalb(0.0, 5), 1.0e-15); assertEquals(32.0, MathUtils.scalb(1.0, 5), 1.0e-15); assertEquals(1.0 / 32.0, MathUtils.scalb(1.0, -5), 1.0e-15); - assertEquals(Math.PI, MathUtils.scalb(Math.PI, 0), 1.0e-15); + assertEquals(FastMath.PI, MathUtils.scalb(FastMath.PI, 0), 1.0e-15); assertTrue(Double.isInfinite(MathUtils.scalb(Double.POSITIVE_INFINITY, 1))); assertTrue(Double.isInfinite(MathUtils.scalb(Double.NEGATIVE_INFINITY, 1))); assertTrue(Double.isNaN(MathUtils.scalb(Double.NaN, 1))); @@ -994,10 +994,10 @@ public final class MathUtilsTest extends for (double a = -15.0; a <= 15.0; a += 0.1) { for (double b = -15.0; b <= 15.0; b += 0.2) { double c = MathUtils.normalizeAngle(a, b); - assertTrue((b - Math.PI) <= c); - assertTrue(c <= (b + Math.PI)); - double twoK = Math.rint((a - c) / Math.PI); - assertEquals(c, a - twoK * Math.PI, 1.0e-14); + assertTrue((b - FastMath.PI) <= c); + assertTrue(c <= (b + FastMath.PI)); + double twoK = FastMath.rint((a - c) / FastMath.PI); + assertEquals(c, a - twoK * FastMath.PI, 1.0e-14); } } }