You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2010/08/29 23:49:53 UTC
svn commit: r990655 [7/10] - in /commons/proper/math/branches/MATH_2_X: ./
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/mai...
Propchange: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/MathUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/MathUtils.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/MathUtils.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/MathUtils.java Sun Aug 29 21:49:40 2010
@@ -45,7 +45,7 @@ public final class MathUtils {
* 2 π.
* @since 2.1
*/
- public static final double TWO_PI = 2 * Math.PI;
+ public static final double TWO_PI = 2 * FastMath.PI;
/** -1.0 cast as a byte. */
private static final byte NB = (byte)-1;
@@ -287,7 +287,7 @@ public final class MathUtils {
result *= (double)(n - k + i) / (double)i;
}
- return Math.floor(result + 0.5);
+ return FastMath.floor(result + 0.5);
}
/**
@@ -314,7 +314,7 @@ public final class MathUtils {
return 0;
}
if ((k == 1) || (k == n - 1)) {
- return Math.log(n);
+ return FastMath.log(n);
}
/*
@@ -322,7 +322,7 @@ public final class MathUtils {
* return the log of the exact value
*/
if (n < 67) {
- return Math.log(binomialCoefficient(n,k));
+ return FastMath.log(binomialCoefficient(n,k));
}
/*
@@ -330,7 +330,7 @@ public final class MathUtils {
* overflow binomialCoefficientDouble
*/
if (n < 1030) {
- return Math.log(binomialCoefficientDouble(n, k));
+ return FastMath.log(binomialCoefficientDouble(n, k));
}
if (k > n / 2) {
@@ -344,12 +344,12 @@ public final class MathUtils {
// n!/(n-k)!
for (int i = n - k + 1; i <= n; i++) {
- logSum += Math.log(i);
+ logSum += FastMath.log(i);
}
// divide by k!
for (int i = 2; i <= k; i++) {
- logSum -= Math.log(i);
+ logSum -= FastMath.log(i);
}
return logSum;
@@ -402,7 +402,7 @@ public final class MathUtils {
* @return hyperbolic cosine of x
*/
public static double cosh(double x) {
- return (Math.exp(x) + Math.exp(-x)) / 2.0;
+ return (FastMath.exp(x) + FastMath.exp(-x)) / 2.0;
}
/**
@@ -445,7 +445,7 @@ public final class MathUtils {
* @return {@code true} if the values are equal or within range of each other.
*/
public static boolean equals(double x, double y, double eps) {
- return equals(x, y, 1) || Math.abs(y - x) <= eps;
+ return equals(x, y, 1) || FastMath.abs(y - x) <= eps;
}
/**
@@ -459,7 +459,7 @@ public final class MathUtils {
* or both are NaN.
*/
public static boolean equalsIncludingNaN(double x, double y, double eps) {
- return equalsIncludingNaN(x, y) || (Math.abs(y - x) <= eps);
+ return equalsIncludingNaN(x, y) || (FastMath.abs(y - x) <= eps);
}
/**
@@ -495,7 +495,7 @@ public final class MathUtils {
yInt = SGN_MASK - yInt;
}
- final boolean isEqual = Math.abs(xInt - yInt) <= maxUlps;
+ final boolean isEqual = FastMath.abs(xInt - yInt) <= maxUlps;
return isEqual && !Double.isNaN(x) && !Double.isNaN(y);
}
@@ -635,7 +635,7 @@ public final class MathUtils {
if (n < 21) {
return factorial(n);
}
- return Math.floor(Math.exp(factorialLog(n)) + 0.5);
+ return FastMath.floor(FastMath.exp(factorialLog(n)) + 0.5);
}
/**
@@ -658,11 +658,11 @@ public final class MathUtils {
n);
}
if (n < 21) {
- return Math.log(factorial(n));
+ return FastMath.log(factorial(n));
}
double logSum = 0;
for (int i = 2; i <= n; i++) {
- logSum += Math.log(i);
+ logSum += FastMath.log(i);
}
return logSum;
}
@@ -705,7 +705,7 @@ public final class MathUtils {
LocalizedFormats.GCD_OVERFLOW_32_BITS,
p, q);
}
- return Math.abs(u) + Math.abs(v);
+ return FastMath.abs(u) + FastMath.abs(v);
}
// keep u and v negative, as negative integers range down to
// -2^31, while positive numbers can only be as large as 2^31-1
@@ -794,7 +794,7 @@ public final class MathUtils {
LocalizedFormats.GCD_OVERFLOW_64_BITS,
p, q);
}
- return Math.abs(u) + Math.abs(v);
+ return FastMath.abs(u) + FastMath.abs(v);
}
// keep u and v negative, as negative integers range down to
// -2^63, while positive numbers can only be as large as 2^63-1
@@ -964,7 +964,7 @@ public final class MathUtils {
if (a==0 || b==0){
return 0;
}
- int lcm = Math.abs(mulAndCheck(a / gcd(a, b), b));
+ int lcm = FastMath.abs(mulAndCheck(a / gcd(a, b), b));
if (lcm == Integer.MIN_VALUE) {
throw MathRuntimeException.createArithmeticException(
LocalizedFormats.LCM_OVERFLOW_32_BITS,
@@ -999,7 +999,7 @@ public final class MathUtils {
if (a==0 || b==0){
return 0;
}
- long lcm = Math.abs(mulAndCheck(a / gcd(a, b), b));
+ long lcm = FastMath.abs(mulAndCheck(a / gcd(a, b), b));
if (lcm == Long.MIN_VALUE){
throw MathRuntimeException.createArithmeticException(
LocalizedFormats.LCM_OVERFLOW_64_BITS,
@@ -1025,7 +1025,7 @@ public final class MathUtils {
* @since 1.2
*/
public static double log(double base, double x) {
- return Math.log(x)/Math.log(base);
+ return FastMath.log(x)/FastMath.log(base);
}
/**
@@ -1117,45 +1117,11 @@ public final class MathUtils {
* direction is greater or smaller than d)
* @return the next machine representable number in the specified direction
* @since 1.2
+ * @deprecated as of 2.2, replaced by {@link FastMath#nextAfter(double, double)}
*/
+ @Deprecated
public static double nextAfter(double d, double direction) {
-
- // handling of some important special cases
- if (Double.isNaN(d) || Double.isInfinite(d)) {
- return d;
- } else if (d == 0) {
- return (direction < 0) ? -Double.MIN_VALUE : Double.MIN_VALUE;
- }
- // special cases MAX_VALUE to infinity and MIN_VALUE to 0
- // are handled just as normal numbers
-
- // split the double in raw components
- long bits = Double.doubleToLongBits(d);
- long sign = bits & 0x8000000000000000L;
- long exponent = bits & 0x7ff0000000000000L;
- long mantissa = bits & 0x000fffffffffffffL;
-
- if (d * (direction - d) >= 0) {
- // we should increase the mantissa
- if (mantissa == 0x000fffffffffffffL) {
- return Double.longBitsToDouble(sign |
- (exponent + 0x0010000000000000L));
- } else {
- return Double.longBitsToDouble(sign |
- exponent | (mantissa + 1));
- }
- } else {
- // we should decrease the mantissa
- if (mantissa == 0L) {
- return Double.longBitsToDouble(sign |
- (exponent - 0x0010000000000000L) |
- 0x000fffffffffffffL);
- } else {
- return Double.longBitsToDouble(sign |
- exponent | (mantissa - 1));
- }
- }
-
+ return FastMath.nextAfter(d, direction);
}
/**
@@ -1190,7 +1156,7 @@ public final class MathUtils {
* <p>This method has three main uses:</p>
* <ul>
* <li>normalize an angle between 0 and 2π:<br/>
- * <code>a = MathUtils.normalizeAngle(a, Math.PI);</code></li>
+ * <code>a = MathUtils.normalizeAngle(a, FastMath.PI);</code></li>
* <li>normalize an angle between -π and +π<br/>
* <code>a = MathUtils.normalizeAngle(a, 0.0);</code></li>
* <li>compute the angle between two defining angular positions:<br>
@@ -1205,7 +1171,7 @@ public final class MathUtils {
* @since 1.2
*/
public static double normalizeAngle(double a, double center) {
- return a - TWO_PI * Math.floor((a + Math.PI - center) / TWO_PI);
+ return a - TWO_PI * FastMath.floor((a + FastMath.PI - center) / TWO_PI);
}
/**
@@ -1331,7 +1297,7 @@ public final class MathUtils {
*/
public static float round(float x, int scale, int roundingMethod) {
float sign = indicator(x);
- float factor = (float)Math.pow(10.0f, scale) * sign;
+ float factor = (float)FastMath.pow(10.0f, scale) * sign;
return (float)roundUnscaled(x * factor, sign, roundingMethod) / factor;
}
@@ -1352,65 +1318,65 @@ public final class MathUtils {
switch (roundingMethod) {
case BigDecimal.ROUND_CEILING :
if (sign == -1) {
- unscaled = Math.floor(nextAfter(unscaled, Double.NEGATIVE_INFINITY));
+ unscaled = FastMath.floor(nextAfter(unscaled, Double.NEGATIVE_INFINITY));
} else {
- unscaled = Math.ceil(nextAfter(unscaled, Double.POSITIVE_INFINITY));
+ unscaled = FastMath.ceil(nextAfter(unscaled, Double.POSITIVE_INFINITY));
}
break;
case BigDecimal.ROUND_DOWN :
- unscaled = Math.floor(nextAfter(unscaled, Double.NEGATIVE_INFINITY));
+ unscaled = FastMath.floor(nextAfter(unscaled, Double.NEGATIVE_INFINITY));
break;
case BigDecimal.ROUND_FLOOR :
if (sign == -1) {
- unscaled = Math.ceil(nextAfter(unscaled, Double.POSITIVE_INFINITY));
+ unscaled = FastMath.ceil(nextAfter(unscaled, Double.POSITIVE_INFINITY));
} else {
- unscaled = Math.floor(nextAfter(unscaled, Double.NEGATIVE_INFINITY));
+ unscaled = FastMath.floor(nextAfter(unscaled, Double.NEGATIVE_INFINITY));
}
break;
case BigDecimal.ROUND_HALF_DOWN : {
unscaled = nextAfter(unscaled, Double.NEGATIVE_INFINITY);
- double fraction = unscaled - Math.floor(unscaled);
+ double fraction = unscaled - FastMath.floor(unscaled);
if (fraction > 0.5) {
- unscaled = Math.ceil(unscaled);
+ unscaled = FastMath.ceil(unscaled);
} else {
- unscaled = Math.floor(unscaled);
+ unscaled = FastMath.floor(unscaled);
}
break;
}
case BigDecimal.ROUND_HALF_EVEN : {
- double fraction = unscaled - Math.floor(unscaled);
+ double fraction = unscaled - FastMath.floor(unscaled);
if (fraction > 0.5) {
- unscaled = Math.ceil(unscaled);
+ unscaled = FastMath.ceil(unscaled);
} else if (fraction < 0.5) {
- unscaled = Math.floor(unscaled);
+ unscaled = FastMath.floor(unscaled);
} else {
// The following equality test is intentional and needed for rounding purposes
- if (Math.floor(unscaled) / 2.0 == Math.floor(Math
+ if (FastMath.floor(unscaled) / 2.0 == FastMath.floor(Math
.floor(unscaled) / 2.0)) { // even
- unscaled = Math.floor(unscaled);
+ unscaled = FastMath.floor(unscaled);
} else { // odd
- unscaled = Math.ceil(unscaled);
+ unscaled = FastMath.ceil(unscaled);
}
}
break;
}
case BigDecimal.ROUND_HALF_UP : {
unscaled = nextAfter(unscaled, Double.POSITIVE_INFINITY);
- double fraction = unscaled - Math.floor(unscaled);
+ double fraction = unscaled - FastMath.floor(unscaled);
if (fraction >= 0.5) {
- unscaled = Math.ceil(unscaled);
+ unscaled = FastMath.ceil(unscaled);
} else {
- unscaled = Math.floor(unscaled);
+ unscaled = FastMath.floor(unscaled);
}
break;
}
case BigDecimal.ROUND_UNNECESSARY :
- if (unscaled != Math.floor(unscaled)) {
+ if (unscaled != FastMath.floor(unscaled)) {
throw new ArithmeticException("Inexact result from rounding");
}
break;
case BigDecimal.ROUND_UP :
- unscaled = Math.ceil(nextAfter(unscaled, Double.POSITIVE_INFINITY));
+ unscaled = FastMath.ceil(nextAfter(unscaled, Double.POSITIVE_INFINITY));
break;
default :
throw MathRuntimeException.createIllegalArgumentException(
@@ -1530,7 +1496,7 @@ public final class MathUtils {
* @return hyperbolic sine of x
*/
public static double sinh(double x) {
- return (Math.exp(x) - Math.exp(-x)) / 2.0;
+ return (FastMath.exp(x) - FastMath.exp(-x)) / 2.0;
}
/**
@@ -1787,7 +1753,7 @@ public final class MathUtils {
public static double distance1(double[] p1, double[] p2) {
double sum = 0;
for (int i = 0; i < p1.length; i++) {
- sum += Math.abs(p1[i] - p2[i]);
+ sum += FastMath.abs(p1[i] - p2[i]);
}
return sum;
}
@@ -1802,7 +1768,7 @@ public final class MathUtils {
public static int distance1(int[] p1, int[] p2) {
int sum = 0;
for (int i = 0; i < p1.length; i++) {
- sum += Math.abs(p1[i] - p2[i]);
+ sum += FastMath.abs(p1[i] - p2[i]);
}
return sum;
}
@@ -1820,7 +1786,7 @@ public final class MathUtils {
final double dp = p1[i] - p2[i];
sum += dp * dp;
}
- return Math.sqrt(sum);
+ return FastMath.sqrt(sum);
}
/**
@@ -1836,7 +1802,7 @@ public final class MathUtils {
final double dp = p1[i] - p2[i];
sum += dp * dp;
}
- return Math.sqrt(sum);
+ return FastMath.sqrt(sum);
}
/**
@@ -1849,7 +1815,7 @@ public final class MathUtils {
public static double distanceInf(double[] p1, double[] p2) {
double max = 0;
for (int i = 0; i < p1.length; i++) {
- max = Math.max(max, Math.abs(p1[i] - p2[i]));
+ max = FastMath.max(max, FastMath.abs(p1[i] - p2[i]));
}
return max;
}
@@ -1864,7 +1830,7 @@ public final class MathUtils {
public static int distanceInf(int[] p1, int[] p2) {
int max = 0;
for (int i = 0; i < p1.length; i++) {
- max = Math.max(max, Math.abs(p1[i] - p2[i]));
+ max = FastMath.max(max, FastMath.abs(p1[i] - p2[i]));
}
return max;
}
@@ -2069,5 +2035,5 @@ public final class MathUtils {
}
return norm;
}
-
+
}
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/OpenIntToDoubleHashMap.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/OpenIntToDoubleHashMap.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/OpenIntToDoubleHashMap.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/OpenIntToDoubleHashMap.java Sun Aug 29 21:49:40 2010
@@ -153,7 +153,7 @@ public class OpenIntToDoubleHashMap impl
if (expectedSize == 0) {
return 1;
}
- final int capacity = (int) Math.ceil(expectedSize / LOAD_FACTOR);
+ final int capacity = (int) FastMath.ceil(expectedSize / LOAD_FACTOR);
final int powerOfTwo = Integer.highestOneBit(capacity);
if (powerOfTwo == capacity) {
return capacity;
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/OpenIntToFieldHashMap.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/OpenIntToFieldHashMap.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/OpenIntToFieldHashMap.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/OpenIntToFieldHashMap.java Sun Aug 29 21:49:40 2010
@@ -165,7 +165,7 @@ public class OpenIntToFieldHashMap<T ext
if (expectedSize == 0) {
return 1;
}
- final int capacity = (int) Math.ceil(expectedSize / LOAD_FACTOR);
+ final int capacity = (int) FastMath.ceil(expectedSize / LOAD_FACTOR);
final int powerOfTwo = Integer.highestOneBit(capacity);
if (powerOfTwo == capacity) {
return capacity;
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/ResizableDoubleArray.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/ResizableDoubleArray.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/ResizableDoubleArray.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/ResizableDoubleArray.java Sun Aug 29 21:49:40 2010
@@ -473,16 +473,16 @@ public class ResizableDoubleArray implem
*/
protected synchronized void expand() {
- // notice the use of Math.ceil(), this guarantees that we will always
+ // notice the use of FastMath.ceil(), this guarantees that we will always
// have an array of at least currentSize + 1. Assume that the
// current initial capacity is 1 and the expansion factor
// is 1.000000000000000001. The newly calculated size will be
// rounded up to 2 after the multiplication is performed.
int newSize = 0;
if (expansionMode == MULTIPLICATIVE_MODE) {
- newSize = (int) Math.ceil(internalArray.length * expansionFactor);
+ newSize = (int) FastMath.ceil(internalArray.length * expansionFactor);
} else {
- newSize = internalArray.length + Math.round(expansionFactor);
+ newSize = internalArray.length + FastMath.round(expansionFactor);
}
double[] tempArray = new double[newSize];
Modified: commons/proper/math/branches/MATH_2_X/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/site/xdoc/changes.xml?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/branches/MATH_2_X/src/site/xdoc/changes.xml Sun Aug 29 21:49:40 2010
@@ -52,6 +52,13 @@ The <action> type attribute can be add,u
If the output is not quite correct, check for invisible trailing spaces!
-->
<release version="2.2" date="TBD" description="TBD">
+ <action dev="luc" type="fix" issue="MATH-375" due-to="Bill Rossi">
+ Added faster and more accurate version of traditional mathematical functions in a FastMath
+ class intended to be a drop-in replacement for java.util.Math at source-level. Some functions
+ still directly delegates to Math but this will improve with time. Some functions like exp
+ may be twice as fast (even 3 times faster on some processors). Sine, cosine or power functions
+ show typical speedups of 1.5 times faster or more.
+ </action>
<action dev="psteitz" type="fix" issue="MATH-386">
Added R-squared and adjusted R-squared statistics to OLSMultipleLinearRegression.
</action>
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/ArgumentOutsideDomainExceptionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/ArgumentOutsideDomainExceptionTest.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/ArgumentOutsideDomainExceptionTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/ArgumentOutsideDomainExceptionTest.java Sun Aug 29 21:49:40 2010
@@ -19,6 +19,8 @@ package org.apache.commons.math;
import java.util.Locale;
+import org.apache.commons.math.util.FastMath;
+
import junit.framework.TestCase;
/**
@@ -27,11 +29,11 @@ import junit.framework.TestCase;
public class ArgumentOutsideDomainExceptionTest extends TestCase {
public void testConstructor(){
- ArgumentOutsideDomainException ex = new ArgumentOutsideDomainException(Math.PI, 10.0, 20.0);
+ ArgumentOutsideDomainException ex = new ArgumentOutsideDomainException(FastMath.PI, 10.0, 20.0);
assertNull(ex.getCause());
assertNotNull(ex.getMessage());
assertTrue(ex.getMessage().indexOf("3.14") > 0);
- assertEquals(Math.PI, ex.getArgument()[0], 0);
+ assertEquals(FastMath.PI, ex.getArgument()[0], 0);
assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
}
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/TestUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/TestUtils.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/TestUtils.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/TestUtils.java Sun Aug 29 21:49:40 2010
@@ -34,6 +34,7 @@ import org.apache.commons.math.linear.Fi
import org.apache.commons.math.linear.RealMatrix;
import org.apache.commons.math.stat.inference.ChiSquareTest;
import org.apache.commons.math.stat.inference.ChiSquareTestImpl;
+import org.apache.commons.math.util.FastMath;
/**
* @version $Revision$ $Date$
@@ -173,7 +174,7 @@ public class TestUtils {
} else if (expected == 0.0) {
Assert.assertEquals(msg, actual, expected, relativeError);
} else {
- double absError = Math.abs(expected) * relativeError;
+ double absError = FastMath.abs(expected) * relativeError;
Assert.assertEquals(msg, expected, actual, absError);
}
}
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/BinaryFunctionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/BinaryFunctionTest.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/BinaryFunctionTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/BinaryFunctionTest.java Sun Aug 29 21:49:40 2010
@@ -17,6 +17,7 @@
package org.apache.commons.math.analysis;
import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.util.FastMath;
import org.junit.Assert;
import org.junit.Test;
@@ -54,15 +55,15 @@ public class BinaryFunctionTest {
@Test
public void testAtan2() throws FunctionEvaluationException {
- Assert.assertEquals(Math.PI / 4, BinaryFunction.ATAN2.value(1, 1), 1.0e-15);
- Assert.assertEquals(-Math.PI / 4, BinaryFunction.ATAN2.value(-1, 1), 1.0e-15);
+ Assert.assertEquals(FastMath.PI / 4, BinaryFunction.ATAN2.value(1, 1), 1.0e-15);
+ Assert.assertEquals(-FastMath.PI / 4, BinaryFunction.ATAN2.value(-1, 1), 1.0e-15);
}
@Test
public void testFix1st() throws FunctionEvaluationException {
ComposableFunction f = BinaryFunction.POW.fix1stArgument(2);
for (double x = 0.0; x < 1.0; x += 0.01) {
- Assert.assertEquals(Math.pow(2.0, x), f.value(x), 1.0e-15);
+ Assert.assertEquals(FastMath.pow(2.0, x), f.value(x), 1.0e-15);
}
}
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/ComposableFunctionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/ComposableFunctionTest.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/ComposableFunctionTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/ComposableFunctionTest.java Sun Aug 29 21:49:40 2010
@@ -17,6 +17,7 @@
package org.apache.commons.math.analysis;
import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.util.FastMath;
import org.junit.Assert;
import org.junit.Test;
@@ -78,25 +79,25 @@ public class ComposableFunctionTest {
ComposableFunction f1 = sqrt.of(abs.of(expm1.of(cbrt.of(tanh).of(id))));
for (double x = 0.1; x < 0.9; x += 0.01) {
- Assert.assertEquals(Math.sqrt(Math.abs(Math.expm1(Math.cbrt(Math.tanh(x))))),
+ Assert.assertEquals(FastMath.sqrt(FastMath.abs(FastMath.expm1(FastMath.cbrt(FastMath.tanh(x))))),
f1.value(x), 1.0e-15);
}
ComposableFunction f2 = cosh.of(sinh.of(tanh.of(ceil.postCompose(log.postCompose(cosh)))));
for (double x = 0.1; x < 12.9; x += 1.0) {
- Assert.assertEquals(Math.cosh(Math.sinh(Math.tanh(Math.cosh(Math.log(Math.ceil(x)))))),
+ Assert.assertEquals(FastMath.cosh(FastMath.sinh(FastMath.tanh(FastMath.cosh(FastMath.log(FastMath.ceil(x)))))),
f2.value(x), 1.0e-15);
}
ComposableFunction f3 = cos.of(sin.of(tan.of(acos.of(asin.of(log10.of(log.of(ulp)))))));
for (double x = 1.0e16; x < 1.0e17; x += 1.0e16) {
- Assert.assertEquals(Math.cos(Math.sin(Math.tan(Math.acos(Math.asin(Math.log10(Math.log(Math.ulp(x)))))))),
+ Assert.assertEquals(FastMath.cos(FastMath.sin(FastMath.tan(FastMath.acos(FastMath.asin(FastMath.log10(FastMath.log(FastMath.ulp(x)))))))),
f3.value(x), 1.0e-15);
}
ComposableFunction f4 = atan.of(exp.of(negate.of(floor)));
for (double x = 1.1; x < 10.2; x += 1.0) {
- Assert.assertEquals(Math.atan(Math.exp(-Math.floor(x))),
+ Assert.assertEquals(FastMath.atan(FastMath.exp(-FastMath.floor(x))),
f4.value(x), 1.0e-15);
}
@@ -108,7 +109,7 @@ public class ComposableFunctionTest {
ComposableFunction f =
ComposableFunction.COS.combine(ComposableFunction.ASIN, BinaryFunction.POW);
for (double x = 0.1; x < 0.9; x += 0.01) {
- Assert.assertEquals(Math.pow(Math.cos(x), Math.asin(x)), f.value(x), 1.0e-15);
+ Assert.assertEquals(FastMath.pow(FastMath.cos(x), FastMath.asin(x)), f.value(x), 1.0e-15);
}
}
@@ -123,12 +124,12 @@ public class ComposableFunctionTest {
ComposableFunction f5 = ComposableFunction.COS.multiply(5);
ComposableFunction f6 = ComposableFunction.COS.divide(ComposableFunction.SIN);
for (double x = 0.1; x < 0.9; x += 0.01) {
- Assert.assertEquals(Math.cos(x) + 3, f1.value(x), 1.0e-15);
- Assert.assertEquals(Math.cos(x) + Math.sin(x), f2.value(x), 1.0e-15);
- Assert.assertEquals(Math.cos(x) - Math.sin(x), f3.value(x), 1.0e-15);
- Assert.assertEquals(Math.cos(x) * Math.sin(x), f4.value(x), 1.0e-15);
- Assert.assertEquals(Math.cos(x) * 5, f5.value(x), 1.0e-15);
- Assert.assertEquals(Math.cos(x) / Math.sin(x), f6.value(x), 1.0e-15);
+ Assert.assertEquals(FastMath.cos(x) + 3, f1.value(x), 1.0e-15);
+ Assert.assertEquals(FastMath.cos(x) + FastMath.sin(x), f2.value(x), 1.0e-15);
+ Assert.assertEquals(FastMath.cos(x) - FastMath.sin(x), f3.value(x), 1.0e-15);
+ Assert.assertEquals(FastMath.cos(x) * FastMath.sin(x), f4.value(x), 1.0e-15);
+ Assert.assertEquals(FastMath.cos(x) * 5, f5.value(x), 1.0e-15);
+ Assert.assertEquals(FastMath.cos(x) / FastMath.sin(x), f6.value(x), 1.0e-15);
}
}
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/Expm1Function.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/Expm1Function.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/Expm1Function.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/Expm1Function.java Sun Aug 29 21:49:40 2010
@@ -17,6 +17,7 @@
package org.apache.commons.math.analysis;
import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.util.FastMath;
/**
* Auxillary class for testing purposes.
@@ -26,14 +27,14 @@ import org.apache.commons.math.FunctionE
public class Expm1Function implements DifferentiableUnivariateRealFunction {
public double value(double x) throws FunctionEvaluationException {
- // Math.expm1() is available in jdk 1.5 but not in jdk 1.4.2.
- return Math.exp(x) - 1.0;
+ // FastMath.expm1() is available in jdk 1.5 but not in jdk 1.4.2.
+ return FastMath.exp(x) - 1.0;
}
public UnivariateRealFunction derivative() {
return new UnivariateRealFunction() {
public double value(double x) throws FunctionEvaluationException {
- return Math.exp(x);
+ return FastMath.exp(x);
}
};
}
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/SinFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/SinFunction.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/SinFunction.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/SinFunction.java Sun Aug 29 21:49:40 2010
@@ -17,6 +17,7 @@
package org.apache.commons.math.analysis;
import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.util.FastMath;
/**
* Auxillary class for testing solvers.
@@ -34,7 +35,7 @@ public class SinFunction implements Diff
* @see org.apache.commons.math.UnivariateRealFunction#value(double)
*/
public double value(double x) throws FunctionEvaluationException {
- return Math.sin(x);
+ return FastMath.sin(x);
}
/* First derivative of sinus function
@@ -42,7 +43,7 @@ public class SinFunction implements Diff
public UnivariateRealFunction derivative() {
return new UnivariateRealFunction() {
public double value(double x) throws FunctionEvaluationException {
- return Math.cos(x);
+ return FastMath.cos(x);
}
};
}
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/integration/LegendreGaussIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/integration/LegendreGaussIntegratorTest.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/integration/LegendreGaussIntegratorTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/integration/LegendreGaussIntegratorTest.java Sun Aug 29 21:49:40 2010
@@ -25,6 +25,7 @@ import org.apache.commons.math.analysis.
import org.apache.commons.math.analysis.SinFunction;
import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.polynomials.PolynomialFunction;
+import org.apache.commons.math.util.FastMath;
import junit.framework.*;
@@ -44,15 +45,15 @@ extends TestCase {
integrator.setMaximalIterationCount(15);
double min, max, expected, result, tolerance;
- min = 0; max = Math.PI; expected = 2;
- tolerance = Math.max(integrator.getAbsoluteAccuracy(),
- Math.abs(expected * integrator.getRelativeAccuracy()));
+ min = 0; max = FastMath.PI; expected = 2;
+ tolerance = FastMath.max(integrator.getAbsoluteAccuracy(),
+ FastMath.abs(expected * integrator.getRelativeAccuracy()));
result = integrator.integrate(f, min, max);
assertEquals(expected, result, tolerance);
- min = -Math.PI/3; max = 0; expected = -0.5;
- tolerance = Math.max(integrator.getAbsoluteAccuracy(),
- Math.abs(expected * integrator.getRelativeAccuracy()));
+ min = -FastMath.PI/3; max = 0; expected = -0.5;
+ tolerance = FastMath.max(integrator.getAbsoluteAccuracy(),
+ FastMath.abs(expected * integrator.getRelativeAccuracy()));
result = integrator.integrate(f, min, max);
assertEquals(expected, result, tolerance);
}
@@ -92,7 +93,7 @@ extends TestCase {
PolynomialFunction p = new PolynomialFunction(coeff);
double result = integrator.integrate(p, -5.0, 15.0);
double reference = exactIntegration(p, -5.0, 15.0);
- assertEquals(n + " " + degree + " " + i, reference, result, 1.0e-12 * (1.0 + Math.abs(reference)));
+ assertEquals(n + " " + degree + " " + i, reference, result, 1.0e-12 * (1.0 + FastMath.abs(reference)));
}
}
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/integration/RombergIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/integration/RombergIntegratorTest.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/integration/RombergIntegratorTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/integration/RombergIntegratorTest.java Sun Aug 29 21:49:40 2010
@@ -20,6 +20,7 @@ import org.apache.commons.math.MathExcep
import org.apache.commons.math.analysis.QuinticFunction;
import org.apache.commons.math.analysis.SinFunction;
import org.apache.commons.math.analysis.UnivariateRealFunction;
+import org.apache.commons.math.util.FastMath;
import junit.framework.TestCase;
@@ -42,13 +43,13 @@ public final class RombergIntegratorTest
UnivariateRealIntegrator integrator = new RombergIntegrator();
double min, max, expected, result, tolerance;
- min = 0; max = Math.PI; expected = 2;
- tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
+ min = 0; max = FastMath.PI; expected = 2;
+ tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
result = integrator.integrate(f, min, max);
assertEquals(expected, result, tolerance);
- min = -Math.PI/3; max = 0; expected = -0.5;
- tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
+ min = -FastMath.PI/3; max = 0; expected = -0.5;
+ tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
result = integrator.integrate(f, min, max);
assertEquals(expected, result, tolerance);
}
@@ -62,17 +63,17 @@ public final class RombergIntegratorTest
double min, max, expected, result, tolerance;
min = 0; max = 1; expected = -1.0/48;
- tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
+ tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
result = integrator.integrate(f, min, max);
assertEquals(expected, result, tolerance);
min = 0; max = 0.5; expected = 11.0/768;
- tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
+ tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
result = integrator.integrate(f, min, max);
assertEquals(expected, result, tolerance);
min = -1; max = 4; expected = 2048/3.0 - 78 + 1.0/48;
- tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
+ tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
result = integrator.integrate(f, min, max);
assertEquals(expected, result, tolerance);
}
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/integration/SimpsonIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/integration/SimpsonIntegratorTest.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/integration/SimpsonIntegratorTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/integration/SimpsonIntegratorTest.java Sun Aug 29 21:49:40 2010
@@ -20,6 +20,7 @@ import org.apache.commons.math.MathExcep
import org.apache.commons.math.analysis.QuinticFunction;
import org.apache.commons.math.analysis.SinFunction;
import org.apache.commons.math.analysis.UnivariateRealFunction;
+import org.apache.commons.math.util.FastMath;
import junit.framework.TestCase;
@@ -41,13 +42,13 @@ public final class SimpsonIntegratorTest
UnivariateRealIntegrator integrator = new SimpsonIntegrator();
double min, max, expected, result, tolerance;
- min = 0; max = Math.PI; expected = 2;
- tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
+ min = 0; max = FastMath.PI; expected = 2;
+ tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
result = integrator.integrate(f, min, max);
assertEquals(expected, result, tolerance);
- min = -Math.PI/3; max = 0; expected = -0.5;
- tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
+ min = -FastMath.PI/3; max = 0; expected = -0.5;
+ tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
result = integrator.integrate(f, min, max);
assertEquals(expected, result, tolerance);
}
@@ -61,17 +62,17 @@ public final class SimpsonIntegratorTest
double min, max, expected, result, tolerance;
min = 0; max = 1; expected = -1.0/48;
- tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
+ tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
result = integrator.integrate(f, min, max);
assertEquals(expected, result, tolerance);
min = 0; max = 0.5; expected = 11.0/768;
- tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
+ tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
result = integrator.integrate(f, min, max);
assertEquals(expected, result, tolerance);
min = -1; max = 4; expected = 2048/3.0 - 78 + 1.0/48;
- tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
+ tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
result = integrator.integrate(f, min, max);
assertEquals(expected, result, tolerance);
}
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/integration/TrapezoidIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/integration/TrapezoidIntegratorTest.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/integration/TrapezoidIntegratorTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/integration/TrapezoidIntegratorTest.java Sun Aug 29 21:49:40 2010
@@ -20,6 +20,7 @@ import org.apache.commons.math.MathExcep
import org.apache.commons.math.analysis.QuinticFunction;
import org.apache.commons.math.analysis.SinFunction;
import org.apache.commons.math.analysis.UnivariateRealFunction;
+import org.apache.commons.math.util.FastMath;
import junit.framework.TestCase;
@@ -41,13 +42,13 @@ public final class TrapezoidIntegratorTe
UnivariateRealIntegrator integrator = new TrapezoidIntegrator();
double min, max, expected, result, tolerance;
- min = 0; max = Math.PI; expected = 2;
- tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
+ min = 0; max = FastMath.PI; expected = 2;
+ tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
result = integrator.integrate(f, min, max);
assertEquals(expected, result, tolerance);
- min = -Math.PI/3; max = 0; expected = -0.5;
- tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
+ min = -FastMath.PI/3; max = 0; expected = -0.5;
+ tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
result = integrator.integrate(f, min, max);
assertEquals(expected, result, tolerance);
}
@@ -61,17 +62,17 @@ public final class TrapezoidIntegratorTe
double min, max, expected, result, tolerance;
min = 0; max = 1; expected = -1.0/48;
- tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
+ tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
result = integrator.integrate(f, min, max);
assertEquals(expected, result, tolerance);
min = 0; max = 0.5; expected = 11.0/768;
- tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
+ tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
result = integrator.integrate(f, min, max);
assertEquals(expected, result, tolerance);
min = -1; max = 4; expected = 2048/3.0 - 78 + 1.0/48;
- tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
+ tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
result = integrator.integrate(f, min, max);
assertEquals(expected, result, tolerance);
}
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/DividedDifferenceInterpolatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/DividedDifferenceInterpolatorTest.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/DividedDifferenceInterpolatorTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/DividedDifferenceInterpolatorTest.java Sun Aug 29 21:49:40 2010
@@ -20,6 +20,7 @@ import org.apache.commons.math.MathExcep
import org.apache.commons.math.analysis.Expm1Function;
import org.apache.commons.math.analysis.SinFunction;
import org.apache.commons.math.analysis.UnivariateRealFunction;
+import org.apache.commons.math.util.FastMath;
import junit.framework.TestCase;
@@ -51,7 +52,7 @@ public final class DividedDifferenceInte
// 6 interpolating points on interval [0, 2*PI]
int n = 6;
- double min = 0.0, max = 2 * Math.PI;
+ double min = 0.0, max = 2 * FastMath.PI;
x = new double[n];
y = new double[n];
for (int i = 0; i < n; i++) {
@@ -61,12 +62,12 @@ public final class DividedDifferenceInte
double derivativebound = 1.0;
UnivariateRealFunction p = interpolator.interpolate(x, y);
- z = Math.PI / 4; expected = f.value(z); result = p.value(z);
- tolerance = Math.abs(derivativebound * partialerror(x, z));
+ z = FastMath.PI / 4; expected = f.value(z); result = p.value(z);
+ tolerance = FastMath.abs(derivativebound * partialerror(x, z));
assertEquals(expected, result, tolerance);
- z = Math.PI * 1.5; expected = f.value(z); result = p.value(z);
- tolerance = Math.abs(derivativebound * partialerror(x, z));
+ z = FastMath.PI * 1.5; expected = f.value(z); result = p.value(z);
+ tolerance = FastMath.abs(derivativebound * partialerror(x, z));
assertEquals(expected, result, tolerance);
}
@@ -89,19 +90,19 @@ public final class DividedDifferenceInte
x[i] = min + i * (max - min) / n;
y[i] = f.value(x[i]);
}
- double derivativebound = Math.E;
+ double derivativebound = FastMath.E;
UnivariateRealFunction p = interpolator.interpolate(x, y);
z = 0.0; expected = f.value(z); result = p.value(z);
- tolerance = Math.abs(derivativebound * partialerror(x, z));
+ tolerance = FastMath.abs(derivativebound * partialerror(x, z));
assertEquals(expected, result, tolerance);
z = 0.5; expected = f.value(z); result = p.value(z);
- tolerance = Math.abs(derivativebound * partialerror(x, z));
+ tolerance = FastMath.abs(derivativebound * partialerror(x, z));
assertEquals(expected, result, tolerance);
z = -0.5; expected = f.value(z); result = p.value(z);
- tolerance = Math.abs(derivativebound * partialerror(x, z));
+ tolerance = FastMath.abs(derivativebound * partialerror(x, z));
assertEquals(expected, result, tolerance);
}
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/LoessInterpolatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/LoessInterpolatorTest.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/LoessInterpolatorTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/LoessInterpolatorTest.java Sun Aug 29 21:49:40 2010
@@ -17,6 +17,7 @@
package org.apache.commons.math.analysis.interpolation;
import org.apache.commons.math.MathException;
+import org.apache.commons.math.util.FastMath;
import org.junit.Assert;
import org.junit.Test;
@@ -77,12 +78,12 @@ public class LoessInterpolatorTest {
double fitResidualSum = 0;
for(int i = 0; i < numPoints; ++i) {
- double expected = Math.sin(xval[i]);
+ double expected = FastMath.sin(xval[i]);
double noisy = yval[i];
double fit = res[i];
- noisyResidualSum += Math.pow(noisy - expected, 2);
- fitResidualSum += Math.pow(fit - expected, 2);
+ noisyResidualSum += FastMath.pow(noisy - expected, 2);
+ fitResidualSum += FastMath.pow(fit - expected, 2);
}
Assert.assertTrue(fitResidualSum < noisyResidualSum);
@@ -110,7 +111,7 @@ public class LoessInterpolatorTest {
double[] res = li.smooth(xval, yval);
for (int j = 1; j < res.length; ++j) {
- variances[i] += Math.pow(res[j] - res[j-1], 2);
+ variances[i] += FastMath.pow(res[j] - res[j-1], 2);
}
}
@@ -143,7 +144,7 @@ public class LoessInterpolatorTest {
double[] res = li.smooth(xval, yval);
for (int j = 1; j < res.length; ++j) {
- variances[i] += Math.abs(res[j] - res[j-1]);
+ variances[i] += FastMath.abs(res[j] - res[j-1]);
}
}
@@ -242,12 +243,12 @@ public class LoessInterpolatorTest {
}
private void generateSineData(double[] xval, double[] yval, double xnoise, double ynoise) {
- double dx = 2 * Math.PI / xval.length;
+ double dx = 2 * FastMath.PI / xval.length;
double x = 0;
for(int i = 0; i < xval.length; ++i) {
xval[i] = x;
- yval[i] = Math.sin(x) + (2 * Math.random() - 1) * ynoise;
- x += dx * (1 + (2 * Math.random() - 1) * xnoise);
+ yval[i] = FastMath.sin(x) + (2 * FastMath.random() - 1) * ynoise;
+ x += dx * (1 + (2 * FastMath.random() - 1) * xnoise);
}
}
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/MicrosphereInterpolatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/MicrosphereInterpolatorTest.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/MicrosphereInterpolatorTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/MicrosphereInterpolatorTest.java Sun Aug 29 21:49:40 2010
@@ -18,6 +18,7 @@ package org.apache.commons.math.analysis
import org.apache.commons.math.MathException;
import org.apache.commons.math.analysis.MultivariateRealFunction;
+import org.apache.commons.math.util.FastMath;
import org.junit.Assert;
import org.junit.Test;
@@ -69,7 +70,7 @@ public final class MicrosphereInterpolat
c[1] = 0;
expected = f.value(c);
result = p.value(c);
- Assert.assertEquals("On sample point", expected, result, Math.ulp(1d));
+ Assert.assertEquals("On sample point", expected, result, FastMath.ulp(1d));
c[0] = 0 + 1e-5;
c[1] = 1 - 1e-5;
@@ -121,7 +122,7 @@ public final class MicrosphereInterpolat
c[1] = 0;
expected = f.value(c);
result = p.value(c);
- Assert.assertEquals("On sample point", expected, result, Math.ulp(1d));
+ Assert.assertEquals("On sample point", expected, result, FastMath.ulp(1d));
c[0] = 2 + 1e-5;
c[1] = 2 - 1e-5;
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/NevilleInterpolatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/NevilleInterpolatorTest.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/NevilleInterpolatorTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/NevilleInterpolatorTest.java Sun Aug 29 21:49:40 2010
@@ -20,6 +20,7 @@ import org.apache.commons.math.MathExcep
import org.apache.commons.math.analysis.Expm1Function;
import org.apache.commons.math.analysis.SinFunction;
import org.apache.commons.math.analysis.UnivariateRealFunction;
+import org.apache.commons.math.util.FastMath;
import junit.framework.TestCase;
@@ -51,7 +52,7 @@ public final class NevilleInterpolatorTe
// 6 interpolating points on interval [0, 2*PI]
int n = 6;
- double min = 0.0, max = 2 * Math.PI;
+ double min = 0.0, max = 2 * FastMath.PI;
x = new double[n];
y = new double[n];
for (int i = 0; i < n; i++) {
@@ -61,12 +62,12 @@ public final class NevilleInterpolatorTe
double derivativebound = 1.0;
UnivariateRealFunction p = interpolator.interpolate(x, y);
- z = Math.PI / 4; expected = f.value(z); result = p.value(z);
- tolerance = Math.abs(derivativebound * partialerror(x, z));
+ z = FastMath.PI / 4; expected = f.value(z); result = p.value(z);
+ tolerance = FastMath.abs(derivativebound * partialerror(x, z));
assertEquals(expected, result, tolerance);
- z = Math.PI * 1.5; expected = f.value(z); result = p.value(z);
- tolerance = Math.abs(derivativebound * partialerror(x, z));
+ z = FastMath.PI * 1.5; expected = f.value(z); result = p.value(z);
+ tolerance = FastMath.abs(derivativebound * partialerror(x, z));
assertEquals(expected, result, tolerance);
}
@@ -89,19 +90,19 @@ public final class NevilleInterpolatorTe
x[i] = min + i * (max - min) / n;
y[i] = f.value(x[i]);
}
- double derivativebound = Math.E;
+ double derivativebound = FastMath.E;
UnivariateRealFunction p = interpolator.interpolate(x, y);
z = 0.0; expected = f.value(z); result = p.value(z);
- tolerance = Math.abs(derivativebound * partialerror(x, z));
+ tolerance = FastMath.abs(derivativebound * partialerror(x, z));
assertEquals(expected, result, tolerance);
z = 0.5; expected = f.value(z); result = p.value(z);
- tolerance = Math.abs(derivativebound * partialerror(x, z));
+ tolerance = FastMath.abs(derivativebound * partialerror(x, z));
assertEquals(expected, result, tolerance);
z = -0.5; expected = f.value(z); result = p.value(z);
- tolerance = Math.abs(derivativebound * partialerror(x, z));
+ tolerance = FastMath.abs(derivativebound * partialerror(x, z));
assertEquals(expected, result, tolerance);
}
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/SmoothingPolynomialBicubicSplineInterpolatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/SmoothingPolynomialBicubicSplineInterpolatorTest.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/SmoothingPolynomialBicubicSplineInterpolatorTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/SmoothingPolynomialBicubicSplineInterpolatorTest.java Sun Aug 29 21:49:40 2010
@@ -18,6 +18,7 @@ package org.apache.commons.math.analysis
import org.apache.commons.math.MathException;
import org.apache.commons.math.exception.DimensionMismatchException;
+import org.apache.commons.math.util.FastMath;
import org.apache.commons.math.analysis.BivariateRealFunction;
import org.junit.Assert;
import org.junit.Test;
@@ -91,7 +92,7 @@ public final class SmoothingPolynomialBi
BivariateRealFunction f = new BivariateRealFunction() {
public double value(double x, double y) {
return 2 * x - 3 * y + 5
- + ((int) (Math.abs(5 * x + 3 * y)) % 2 == 0 ? 1 : -1);
+ + ((int) (FastMath.abs(5 * x + 3 * y)) % 2 == 0 ? 1 : -1);
}
};
@@ -139,7 +140,7 @@ public final class SmoothingPolynomialBi
BivariateRealFunction f = new BivariateRealFunction() {
public double value(double x, double y) {
return 2 * x * x - 3 * y * y + 4 * x * y - 5
- + ((int) (Math.abs(5 * x + 3 * y)) % 2 == 0 ? 1 : -1);
+ + ((int) (FastMath.abs(5 * x + 3 * y)) % 2 == 0 ? 1 : -1);
}
};
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/SplineInterpolatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/SplineInterpolatorTest.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/SplineInterpolatorTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/SplineInterpolatorTest.java Sun Aug 29 21:49:40 2010
@@ -20,6 +20,7 @@ import org.apache.commons.math.MathExcep
import org.apache.commons.math.exception.NonMonotonousSequenceException;
import org.apache.commons.math.exception.DimensionMismatchException;
import org.apache.commons.math.exception.NumberIsTooSmallException;
+import org.apache.commons.math.util.FastMath;
import org.apache.commons.math.TestUtils;
import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.polynomials.PolynomialFunction;
@@ -112,14 +113,14 @@ public class SplineInterpolatorTest {
double x[] =
{
0.0,
- Math.PI / 6d,
- Math.PI / 2d,
- 5d * Math.PI / 6d,
- Math.PI,
- 7d * Math.PI / 6d,
- 3d * Math.PI / 2d,
- 11d * Math.PI / 6d,
- 2.d * Math.PI };
+ FastMath.PI / 6d,
+ FastMath.PI / 2d,
+ 5d * FastMath.PI / 6d,
+ FastMath.PI,
+ 7d * FastMath.PI / 6d,
+ 3d * FastMath.PI / 2d,
+ 11d * FastMath.PI / 6d,
+ 2.d * FastMath.PI };
double y[] = { 0d, 0.5d, 1d, 0.5d, 0d, -0.5d, -1d, -0.5d, 0d };
UnivariateRealInterpolator i = new SplineInterpolator();
UnivariateRealFunction f = i.interpolate(x, y);
@@ -154,8 +155,8 @@ public class SplineInterpolatorTest {
TestUtils.assertEquals(polynomials[7].getCoefficients(), target, coefficientTolerance);
//Check interpolation
- Assert.assertEquals(Math.sqrt(2d) / 2d,f.value(Math.PI/4d),interpolationTolerance);
- Assert.assertEquals(Math.sqrt(2d) / 2d,f.value(3d*Math.PI/4d),interpolationTolerance);
+ Assert.assertEquals(FastMath.sqrt(2d) / 2d,f.value(FastMath.PI/4d),interpolationTolerance);
+ Assert.assertEquals(FastMath.sqrt(2d) / 2d,f.value(3d*FastMath.PI/4d),interpolationTolerance);
}
@Test
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatingFunctionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatingFunctionTest.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatingFunctionTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatingFunctionTest.java Sun Aug 29 21:49:40 2010
@@ -18,6 +18,7 @@ package org.apache.commons.math.analysis
import org.apache.commons.math.MathException;
import org.apache.commons.math.exception.DimensionMismatchException;
+import org.apache.commons.math.util.FastMath;
import org.apache.commons.math.analysis.TrivariateRealFunction;
import org.junit.Assert;
import org.junit.Test;
@@ -392,7 +393,7 @@ public final class TricubicSplineInterpo
// Function values
TrivariateRealFunction f = new TrivariateRealFunction() {
public double value(double x, double y, double z) {
- return a * Math.cos(omega * z - kx * x - ky * y);
+ return a * FastMath.cos(omega * z - kx * x - ky * y);
}
};
@@ -409,7 +410,7 @@ public final class TricubicSplineInterpo
double[][][] dFdX = new double[xval.length][yval.length][zval.length];
TrivariateRealFunction dFdX_f = new TrivariateRealFunction() {
public double value(double x, double y, double z) {
- return a * Math.sin(omega * z - kx * x - ky * y) * kx;
+ return a * FastMath.sin(omega * z - kx * x - ky * y) * kx;
}
};
for (int i = 0; i < xval.length; i++) {
@@ -424,7 +425,7 @@ public final class TricubicSplineInterpo
double[][][] dFdY = new double[xval.length][yval.length][zval.length];
TrivariateRealFunction dFdY_f = new TrivariateRealFunction() {
public double value(double x, double y, double z) {
- return a * Math.sin(omega * z - kx * x - ky * y) * ky;
+ return a * FastMath.sin(omega * z - kx * x - ky * y) * ky;
}
};
for (int i = 0; i < xval.length; i++) {
@@ -439,7 +440,7 @@ public final class TricubicSplineInterpo
double[][][] dFdZ = new double[xval.length][yval.length][zval.length];
TrivariateRealFunction dFdZ_f = new TrivariateRealFunction() {
public double value(double x, double y, double z) {
- return -a * Math.sin(omega * z - kx * x - ky * y) * omega;
+ return -a * FastMath.sin(omega * z - kx * x - ky * y) * omega;
}
};
for (int i = 0; i < xval.length; i++) {
@@ -454,7 +455,7 @@ public final class TricubicSplineInterpo
double[][][] d2FdXdY = new double[xval.length][yval.length][zval.length];
TrivariateRealFunction d2FdXdY_f = new TrivariateRealFunction() {
public double value(double x, double y, double z) {
- return -a * Math.cos(omega * z - kx * x - ky * y) * kx * ky;
+ return -a * FastMath.cos(omega * z - kx * x - ky * y) * kx * ky;
}
};
for (int i = 0; i < xval.length; i++) {
@@ -469,7 +470,7 @@ public final class TricubicSplineInterpo
double[][][] d2FdXdZ = new double[xval.length][yval.length][zval.length];
TrivariateRealFunction d2FdXdZ_f = new TrivariateRealFunction() {
public double value(double x, double y, double z) {
- return a * Math.cos(omega * z - kx * x - ky * y) * kx * omega;
+ return a * FastMath.cos(omega * z - kx * x - ky * y) * kx * omega;
}
};
for (int i = 0; i < xval.length; i++) {
@@ -484,7 +485,7 @@ public final class TricubicSplineInterpo
double[][][] d2FdYdZ = new double[xval.length][yval.length][zval.length];
TrivariateRealFunction d2FdYdZ_f = new TrivariateRealFunction() {
public double value(double x, double y, double z) {
- return a * Math.cos(omega * z - kx * x - ky * y) * ky * omega;
+ return a * FastMath.cos(omega * z - kx * x - ky * y) * ky * omega;
}
};
for (int i = 0; i < xval.length; i++) {
@@ -499,7 +500,7 @@ public final class TricubicSplineInterpo
double[][][] d3FdXdYdZ = new double[xval.length][yval.length][zval.length];
TrivariateRealFunction d3FdXdYdZ_f = new TrivariateRealFunction() {
public double value(double x, double y, double z) {
- return a * Math.sin(omega * z - kx * x - ky * y) * kx * ky * omega;
+ return a * FastMath.sin(omega * z - kx * x - ky * y) * kx * ky * omega;
}
};
for (int i = 0; i < xval.length; i++) {
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatorTest.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatorTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/interpolation/TricubicSplineInterpolatorTest.java Sun Aug 29 21:49:40 2010
@@ -18,6 +18,7 @@ package org.apache.commons.math.analysis
import org.apache.commons.math.MathException;
import org.apache.commons.math.exception.DimensionMismatchException;
+import org.apache.commons.math.util.FastMath;
import org.apache.commons.math.analysis.TrivariateRealFunction;
import org.junit.Assert;
import org.junit.Test;
@@ -165,7 +166,7 @@ public final class TricubicSplineInterpo
// Function values
TrivariateRealFunction f = new TrivariateRealFunction() {
public double value(double x, double y, double z) {
- return a * Math.cos(omega * z - kx * x - ky * y);
+ return a * FastMath.cos(omega * z - kx * x - ky * y);
}
};
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionTest.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionTest.java Sun Aug 29 21:49:40 2010
@@ -19,6 +19,7 @@ package org.apache.commons.math.analysis
// commons-math
import org.apache.commons.math.MathException;
import org.apache.commons.math.TestUtils;
+import org.apache.commons.math.util.FastMath;
// junit
import junit.framework.TestCase;
@@ -155,8 +156,8 @@ public final class PolynomialFunctionTes
assertEquals( f.derivative().value(-3.25), g.value(-3.25), tolerance );
// compare g' = h
- assertEquals( g.derivative().value(Math.PI), h.value(Math.PI), tolerance );
- assertEquals( g.derivative().value(Math.E), h.value(Math.E), tolerance );
+ assertEquals( g.derivative().value(FastMath.PI), h.value(FastMath.PI), tolerance );
+ assertEquals( g.derivative().value(FastMath.E), h.value(FastMath.E), tolerance );
}
@@ -255,8 +256,8 @@ public final class PolynomialFunctionTes
assertEquals( f.derivative().value(-3.25), g.value(-3.25), tolerance );
// compare g' = h
- assertEquals( g.derivative().value(Math.PI), h.value(Math.PI), tolerance );
- assertEquals( g.derivative().value(Math.E), h.value(Math.E), tolerance );
+ assertEquals( g.derivative().value(FastMath.PI), h.value(FastMath.PI), tolerance );
+ assertEquals( g.derivative().value(FastMath.E), h.value(FastMath.E), tolerance );
}
public void checkPolynomial(PolynomialFunction p, String reference) {
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/polynomials/PolynomialsUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/polynomials/PolynomialsUtilsTest.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/polynomials/PolynomialsUtilsTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/polynomials/PolynomialsUtilsTest.java Sun Aug 29 21:49:40 2010
@@ -16,6 +16,8 @@
*/
package org.apache.commons.math.analysis.polynomials;
+import org.apache.commons.math.util.FastMath;
+
import junit.framework.TestCase;
/**
@@ -43,7 +45,7 @@ public class PolynomialsUtilsTest extend
for (int k = 0; k < 12; ++k) {
PolynomialFunction Tk = PolynomialsUtils.createChebyshevPolynomial(k);
for (double x = -1.0; x <= 1.0; x += 0.02) {
- assertTrue(k + " " + Tk.value(x), Math.abs(Tk.value(x)) < (1.0 + 1.0e-12));
+ assertTrue(k + " " + Tk.value(x), FastMath.abs(Tk.value(x)) < (1.0 + 1.0e-12));
}
}
}
@@ -191,7 +193,7 @@ public class PolynomialsUtilsTest extend
for (int i = 0; i < l40.length; ++i) {
if (i % 2 == 0) {
double ci = numerators[i / 2] / denominator;
- assertEquals(ci, l40[i], Math.abs(ci) * 1.0e-15);
+ assertEquals(ci, l40[i], FastMath.abs(ci) * 1.0e-15);
} else {
assertEquals(0.0, l40[i], 0.0);
}
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/solvers/BisectionSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/solvers/BisectionSolverTest.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/solvers/BisectionSolverTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/solvers/BisectionSolverTest.java Sun Aug 29 21:49:40 2010
@@ -20,6 +20,7 @@ import org.apache.commons.math.MathExcep
import org.apache.commons.math.analysis.QuinticFunction;
import org.apache.commons.math.analysis.SinFunction;
import org.apache.commons.math.analysis.UnivariateRealFunction;
+import org.apache.commons.math.util.FastMath;
import junit.framework.TestCase;
@@ -35,10 +36,10 @@ public final class BisectionSolverTest e
UnivariateRealSolver solver = new BisectionSolver(f);
result = solver.solve(3, 4);
- assertEquals(result, Math.PI, solver.getAbsoluteAccuracy());
+ assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
result = solver.solve(1, 4);
- assertEquals(result, Math.PI, solver.getAbsoluteAccuracy());
+ assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
}
public void testSinZero() throws MathException {
@@ -47,10 +48,10 @@ public final class BisectionSolverTest e
UnivariateRealSolver solver = new BisectionSolver();
result = solver.solve(f, 3, 4);
- assertEquals(result, Math.PI, solver.getAbsoluteAccuracy());
+ assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
result = solver.solve(f, 1, 4);
- assertEquals(result, Math.PI, solver.getAbsoluteAccuracy());
+ assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
}
public void testQuinticZero() throws MathException {
@@ -98,7 +99,7 @@ public final class BisectionSolverTest e
public void testMath369() throws Exception {
UnivariateRealFunction f = new SinFunction();
UnivariateRealSolver solver = new BisectionSolver();
- assertEquals(Math.PI, solver.solve(f, 3.0, 3.2, 3.1), solver.getAbsoluteAccuracy());
+ assertEquals(FastMath.PI, solver.solve(f, 3.0, 3.2, 3.1), solver.getAbsoluteAccuracy());
}
/**
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/solvers/BrentSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/solvers/BrentSolverTest.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/solvers/BrentSolverTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/solvers/BrentSolverTest.java Sun Aug 29 21:49:40 2010
@@ -23,6 +23,7 @@ import org.apache.commons.math.analysis.
import org.apache.commons.math.analysis.QuinticFunction;
import org.apache.commons.math.analysis.SinFunction;
import org.apache.commons.math.analysis.UnivariateRealFunction;
+import org.apache.commons.math.util.FastMath;
/**
* Testcase for UnivariateRealSolver.
@@ -53,27 +54,27 @@ public final class BrentSolverTest exten
result = solver.solve(3, 4);
//System.out.println(
// "Root: " + result + " Iterations: " + solver.getIterationCount());
- assertEquals(result, Math.PI, solver.getAbsoluteAccuracy());
+ assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
// 4 iterations on i586 JDK 1.4.1.
assertTrue(solver.getIterationCount() <= 5);
// Larger and somewhat less benign interval. The function is grows first.
result = solver.solve(1, 4);
//System.out.println(
// "Root: " + result + " Iterations: " + solver.getIterationCount());
- assertEquals(result, Math.PI, solver.getAbsoluteAccuracy());
+ assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
// 5 iterations on i586 JDK 1.4.1.
assertTrue(solver.getIterationCount() <= 6);
solver = new SecantSolver(f);
result = solver.solve(3, 4);
//System.out.println(
// "Root: " + result + " Iterations: " + solver.getIterationCount());
- assertEquals(result, Math.PI, solver.getAbsoluteAccuracy());
+ assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
// 4 iterations on i586 JDK 1.4.1.
assertTrue(solver.getIterationCount() <= 5);
result = solver.solve(1, 4);
//System.out.println(
// "Root: " + result + " Iterations: " + solver.getIterationCount());
- assertEquals(result, Math.PI, solver.getAbsoluteAccuracy());
+ assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
// 5 iterations on i586 JDK 1.4.1.
assertTrue(solver.getIterationCount() <= 6);
assertEquals(result, solver.getResult(), 0);
@@ -90,27 +91,27 @@ public final class BrentSolverTest exten
result = solver.solve(f, 3, 4);
//System.out.println(
// "Root: " + result + " Iterations: " + solver.getIterationCount());
- assertEquals(result, Math.PI, solver.getAbsoluteAccuracy());
+ assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
// 4 iterations on i586 JDK 1.4.1.
assertTrue(solver.getIterationCount() <= 5);
// Larger and somewhat less benign interval. The function is grows first.
result = solver.solve(f, 1, 4);
//System.out.println(
// "Root: " + result + " Iterations: " + solver.getIterationCount());
- assertEquals(result, Math.PI, solver.getAbsoluteAccuracy());
+ assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
// 5 iterations on i586 JDK 1.4.1.
assertTrue(solver.getIterationCount() <= 6);
solver = new SecantSolver();
result = solver.solve(f, 3, 4);
//System.out.println(
// "Root: " + result + " Iterations: " + solver.getIterationCount());
- assertEquals(result, Math.PI, solver.getAbsoluteAccuracy());
+ assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
// 4 iterations on i586 JDK 1.4.1.
assertTrue(solver.getIterationCount() <= 5);
result = solver.solve(f, 1, 4);
//System.out.println(
// "Root: " + result + " Iterations: " + solver.getIterationCount());
- assertEquals(result, Math.PI, solver.getAbsoluteAccuracy());
+ assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
// 5 iterations on i586 JDK 1.4.1.
assertTrue(solver.getIterationCount() <= 6);
assertEquals(result, solver.getResult(), 0);
@@ -307,17 +308,17 @@ public final class BrentSolverTest exten
UnivariateRealSolver solver = new BrentSolver();
// endpoint is root
- double result = solver.solve(f, Math.PI, 4);
- assertEquals(Math.PI, result, solver.getAbsoluteAccuracy());
+ double result = solver.solve(f, FastMath.PI, 4);
+ assertEquals(FastMath.PI, result, solver.getAbsoluteAccuracy());
- result = solver.solve(f, 3, Math.PI);
- assertEquals(Math.PI, result, solver.getAbsoluteAccuracy());
+ result = solver.solve(f, 3, FastMath.PI);
+ assertEquals(FastMath.PI, result, solver.getAbsoluteAccuracy());
- result = solver.solve(f, Math.PI, 4, 3.5);
- assertEquals(Math.PI, result, solver.getAbsoluteAccuracy());
+ result = solver.solve(f, FastMath.PI, 4, 3.5);
+ assertEquals(FastMath.PI, result, solver.getAbsoluteAccuracy());
- result = solver.solve(f, 3, Math.PI, 3.07);
- assertEquals(Math.PI, result, solver.getAbsoluteAccuracy());
+ result = solver.solve(f, 3, FastMath.PI, 3.07);
+ assertEquals(FastMath.PI, result, solver.getAbsoluteAccuracy());
}
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/solvers/LaguerreSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/solvers/LaguerreSolverTest.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/solvers/LaguerreSolverTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/analysis/solvers/LaguerreSolverTest.java Sun Aug 29 21:49:40 2010
@@ -21,6 +21,8 @@ import org.apache.commons.math.TestUtils
import org.apache.commons.math.analysis.SinFunction;
import org.apache.commons.math.analysis.polynomials.PolynomialFunction;
import org.apache.commons.math.complex.Complex;
+import org.apache.commons.math.util.FastMath;
+
import junit.framework.TestCase;
/**
@@ -48,8 +50,8 @@ public final class LaguerreSolverTest ex
UnivariateRealSolver solver = new LaguerreSolver(f);
min = 0.0; max = 1.0; expected = 0.25;
- tolerance = Math.max(solver.getAbsoluteAccuracy(),
- Math.abs(expected * solver.getRelativeAccuracy()));
+ tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+ FastMath.abs(expected * solver.getRelativeAccuracy()));
result = solver.solve(min, max);
assertEquals(expected, result, tolerance);
}
@@ -66,8 +68,8 @@ public final class LaguerreSolverTest ex
UnivariateRealSolver solver = new LaguerreSolver();
min = 0.0; max = 1.0; expected = 0.25;
- tolerance = Math.max(solver.getAbsoluteAccuracy(),
- Math.abs(expected * solver.getRelativeAccuracy()));
+ tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+ FastMath.abs(expected * solver.getRelativeAccuracy()));
result = solver.solve(f, min, max);
assertEquals(expected, result, tolerance);
}
@@ -84,14 +86,14 @@ public final class LaguerreSolverTest ex
UnivariateRealSolver solver = new LaguerreSolver();
min = 0.0; max = 2.0; expected = 0.5;
- tolerance = Math.max(solver.getAbsoluteAccuracy(),
- Math.abs(expected * solver.getRelativeAccuracy()));
+ tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+ FastMath.abs(expected * solver.getRelativeAccuracy()));
result = solver.solve(f, min, max);
assertEquals(expected, result, tolerance);
min = -4.0; max = -1.0; expected = -3.0;
- tolerance = Math.max(solver.getAbsoluteAccuracy(),
- Math.abs(expected * solver.getRelativeAccuracy()));
+ tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+ FastMath.abs(expected * solver.getRelativeAccuracy()));
result = solver.solve(f, min, max);
assertEquals(expected, result, tolerance);
}
@@ -108,20 +110,20 @@ public final class LaguerreSolverTest ex
UnivariateRealSolver solver = new LaguerreSolver();
min = -2.0; max = 2.0; expected = -1.0;
- tolerance = Math.max(solver.getAbsoluteAccuracy(),
- Math.abs(expected * solver.getRelativeAccuracy()));
+ tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+ FastMath.abs(expected * solver.getRelativeAccuracy()));
result = solver.solve(f, min, max);
assertEquals(expected, result, tolerance);
min = -5.0; max = -2.5; expected = -3.0;
- tolerance = Math.max(solver.getAbsoluteAccuracy(),
- Math.abs(expected * solver.getRelativeAccuracy()));
+ tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+ FastMath.abs(expected * solver.getRelativeAccuracy()));
result = solver.solve(f, min, max);
assertEquals(expected, result, tolerance);
min = 3.0; max = 6.0; expected = 4.0;
- tolerance = Math.max(solver.getAbsoluteAccuracy(),
- Math.abs(expected * solver.getRelativeAccuracy()));
+ tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+ FastMath.abs(expected * solver.getRelativeAccuracy()));
result = solver.solve(f, min, max);
assertEquals(expected, result, tolerance);
}
@@ -139,28 +141,28 @@ public final class LaguerreSolverTest ex
result = solver.solveAll(coefficients, initial);
expected = new Complex(0.0, -2.0);
- tolerance = Math.max(solver.getAbsoluteAccuracy(),
- Math.abs(expected.abs() * solver.getRelativeAccuracy()));
+ tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+ FastMath.abs(expected.abs() * solver.getRelativeAccuracy()));
TestUtils.assertContains(result, expected, tolerance);
expected = new Complex(0.0, 2.0);
- tolerance = Math.max(solver.getAbsoluteAccuracy(),
- Math.abs(expected.abs() * solver.getRelativeAccuracy()));
+ tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+ FastMath.abs(expected.abs() * solver.getRelativeAccuracy()));
TestUtils.assertContains(result, expected, tolerance);
- expected = new Complex(0.5, 0.5 * Math.sqrt(3.0));
- tolerance = Math.max(solver.getAbsoluteAccuracy(),
- Math.abs(expected.abs() * solver.getRelativeAccuracy()));
+ expected = new Complex(0.5, 0.5 * FastMath.sqrt(3.0));
+ tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+ FastMath.abs(expected.abs() * solver.getRelativeAccuracy()));
TestUtils.assertContains(result, expected, tolerance);
expected = new Complex(-1.0, 0.0);
- tolerance = Math.max(solver.getAbsoluteAccuracy(),
- Math.abs(expected.abs() * solver.getRelativeAccuracy()));
+ tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+ FastMath.abs(expected.abs() * solver.getRelativeAccuracy()));
TestUtils.assertContains(result, expected, tolerance);
- expected = new Complex(0.5, -0.5 * Math.sqrt(3.0));
- tolerance = Math.max(solver.getAbsoluteAccuracy(),
- Math.abs(expected.abs() * solver.getRelativeAccuracy()));
+ expected = new Complex(0.5, -0.5 * FastMath.sqrt(3.0));
+ tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
+ FastMath.abs(expected.abs() * solver.getRelativeAccuracy()));
TestUtils.assertContains(result, expected, tolerance);
}