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 [2/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...
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/complex/Complex.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/complex/Complex.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/complex/Complex.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/complex/Complex.java Sun Aug 29 21:49:40 2010
@@ -25,6 +25,7 @@ import org.apache.commons.math.FieldElem
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.util.MathUtils;
+import org.apache.commons.math.util.FastMath;
/**
* Representation of a Complex number - a number which has both a
@@ -113,18 +114,18 @@ public class Complex implements FieldEle
return Double.POSITIVE_INFINITY;
}
- if (Math.abs(real) < Math.abs(imaginary)) {
+ if (FastMath.abs(real) < FastMath.abs(imaginary)) {
if (imaginary == 0.0) {
- return Math.abs(real);
+ return FastMath.abs(real);
}
double q = real / imaginary;
- return Math.abs(imaginary) * Math.sqrt(1 + q * q);
+ return FastMath.abs(imaginary) * FastMath.sqrt(1 + q * q);
} else {
if (real == 0.0) {
- return Math.abs(imaginary);
+ return FastMath.abs(imaginary);
}
double q = imaginary / real;
- return Math.abs(real) * Math.sqrt(1 + q * q);
+ return FastMath.abs(real) * FastMath.sqrt(1 + q * q);
}
}
@@ -221,7 +222,7 @@ public class Complex implements FieldEle
return ZERO;
}
- if (Math.abs(c) < Math.abs(d)) {
+ if (FastMath.abs(c) < FastMath.abs(d)) {
double q = c / d;
double denominator = c * q + d;
return createComplex((real * q + imaginary) / denominator,
@@ -547,8 +548,8 @@ public class Complex implements FieldEle
return Complex.NaN;
}
- return createComplex(Math.cos(real) * MathUtils.cosh(imaginary),
- -Math.sin(real) * MathUtils.sinh(imaginary));
+ return createComplex(FastMath.cos(real) * MathUtils.cosh(imaginary),
+ -FastMath.sin(real) * MathUtils.sinh(imaginary));
}
/**
@@ -581,8 +582,8 @@ public class Complex implements FieldEle
return Complex.NaN;
}
- return createComplex(MathUtils.cosh(real) * Math.cos(imaginary),
- MathUtils.sinh(real) * Math.sin(imaginary));
+ return createComplex(MathUtils.cosh(real) * FastMath.cos(imaginary),
+ MathUtils.sinh(real) * FastMath.sin(imaginary));
}
/**
@@ -616,8 +617,8 @@ public class Complex implements FieldEle
return Complex.NaN;
}
- double expReal = Math.exp(real);
- return createComplex(expReal * Math.cos(imaginary), expReal * Math.sin(imaginary));
+ double expReal = FastMath.exp(real);
+ return createComplex(expReal * FastMath.cos(imaginary), expReal * FastMath.sin(imaginary));
}
/**
@@ -654,8 +655,8 @@ public class Complex implements FieldEle
return Complex.NaN;
}
- return createComplex(Math.log(abs()),
- Math.atan2(imaginary, real));
+ return createComplex(FastMath.log(abs()),
+ FastMath.atan2(imaginary, real));
}
/**
@@ -713,8 +714,8 @@ public class Complex implements FieldEle
return Complex.NaN;
}
- return createComplex(Math.sin(real) * MathUtils.cosh(imaginary),
- Math.cos(real) * MathUtils.sinh(imaginary));
+ return createComplex(FastMath.sin(real) * MathUtils.cosh(imaginary),
+ FastMath.cos(real) * MathUtils.sinh(imaginary));
}
/**
@@ -747,8 +748,8 @@ public class Complex implements FieldEle
return Complex.NaN;
}
- return createComplex(MathUtils.sinh(real) * Math.cos(imaginary),
- MathUtils.cosh(real) * Math.sin(imaginary));
+ return createComplex(MathUtils.sinh(real) * FastMath.cos(imaginary),
+ MathUtils.cosh(real) * FastMath.sin(imaginary));
}
/**
@@ -793,11 +794,11 @@ public class Complex implements FieldEle
return createComplex(0.0, 0.0);
}
- double t = Math.sqrt((Math.abs(real) + abs()) / 2.0);
+ double t = FastMath.sqrt((FastMath.abs(real) + abs()) / 2.0);
if (real >= 0.0) {
return createComplex(t, imaginary / (2.0 * t));
} else {
- return createComplex(Math.abs(imaginary) / (2.0 * t),
+ return createComplex(FastMath.abs(imaginary) / (2.0 * t),
MathUtils.indicator(imaginary) * t);
}
}
@@ -857,9 +858,9 @@ public class Complex implements FieldEle
double real2 = 2.0 * real;
double imaginary2 = 2.0 * imaginary;
- double d = Math.cos(real2) + MathUtils.cosh(imaginary2);
+ double d = FastMath.cos(real2) + MathUtils.cosh(imaginary2);
- return createComplex(Math.sin(real2) / d, MathUtils.sinh(imaginary2) / d);
+ return createComplex(FastMath.sin(real2) / d, MathUtils.sinh(imaginary2) / d);
}
/**
@@ -895,9 +896,9 @@ public class Complex implements FieldEle
double real2 = 2.0 * real;
double imaginary2 = 2.0 * imaginary;
- double d = MathUtils.cosh(real2) + Math.cos(imaginary2);
+ double d = MathUtils.cosh(real2) + FastMath.cos(imaginary2);
- return createComplex(MathUtils.sinh(real2) / d, Math.sin(imaginary2) / d);
+ return createComplex(MathUtils.sinh(real2) / d, FastMath.sin(imaginary2) / d);
}
@@ -917,7 +918,7 @@ public class Complex implements FieldEle
* @return the argument of this complex number
*/
public double getArgument() {
- return Math.atan2(getImaginary(), getReal());
+ return FastMath.atan2(getImaginary(), getReal());
}
/**
@@ -959,16 +960,16 @@ public class Complex implements FieldEle
}
// nth root of abs -- faster / more accurate to use a solver here?
- final double nthRootOfAbs = Math.pow(abs(), 1.0 / n);
+ final double nthRootOfAbs = FastMath.pow(abs(), 1.0 / n);
// Compute nth roots of complex number with k = 0, 1, ... n-1
final double nthPhi = getArgument()/n;
- final double slice = 2 * Math.PI / n;
+ final double slice = 2 * FastMath.PI / n;
double innerPart = nthPhi;
for (int k = 0; k < n ; k++) {
// inner part
- final double realPart = nthRootOfAbs * Math.cos(innerPart);
- final double imaginaryPart = nthRootOfAbs * Math.sin(innerPart);
+ final double realPart = nthRootOfAbs * FastMath.cos(innerPart);
+ final double imaginaryPart = nthRootOfAbs * FastMath.sin(innerPart);
result.add(createComplex(realPart, imaginaryPart));
innerPart += slice;
}
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/complex/ComplexUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/complex/ComplexUtils.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/complex/ComplexUtils.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/complex/ComplexUtils.java Sun Aug 29 21:49:40 2010
@@ -19,6 +19,7 @@ package org.apache.commons.math.complex;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.exception.util.LocalizedFormats;
+import org.apache.commons.math.util.FastMath;
/**
* Static implementations of common
@@ -65,7 +66,7 @@ public class ComplexUtils {
throw MathRuntimeException.createIllegalArgumentException(
LocalizedFormats.NEGATIVE_COMPLEX_MODULE, r);
}
- return new Complex(r * Math.cos(theta), r * Math.sin(theta));
+ return new Complex(r * FastMath.cos(theta), r * FastMath.sin(theta));
}
}
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java Sun Aug 29 21:49:40 2010
@@ -27,6 +27,7 @@ import org.apache.commons.math.analysis.
import org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.random.RandomDataImpl;
+import org.apache.commons.math.util.FastMath;
/**
* Base class for continuous distributions. Default implementations are
@@ -124,10 +125,10 @@ public abstract class AbstractContinuous
* the default solver's defaultAbsoluteAccuracy of 0 (will be the
* case if density has bounded support and p is 0 or 1).
*/
- if (Math.abs(rootFindingFunction.value(lowerBound)) < getSolverAbsoluteAccuracy()) {
+ if (FastMath.abs(rootFindingFunction.value(lowerBound)) < getSolverAbsoluteAccuracy()) {
return lowerBound;
}
- if (Math.abs(rootFindingFunction.value(upperBound)) < getSolverAbsoluteAccuracy()) {
+ if (FastMath.abs(rootFindingFunction.value(upperBound)) < getSolverAbsoluteAccuracy()) {
return upperBound;
}
// Failed bracket convergence was not because of corner solution
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java Sun Aug 29 21:49:40 2010
@@ -23,6 +23,7 @@ import org.apache.commons.math.MathExcep
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.random.RandomDataImpl;
+import org.apache.commons.math.util.FastMath;
/**
@@ -67,7 +68,7 @@ public abstract class AbstractIntegerDis
* computed due to convergence or other numerical errors.
*/
public double cumulativeProbability(double x) throws MathException {
- return cumulativeProbability((int) Math.floor(x));
+ return cumulativeProbability((int) FastMath.floor(x));
}
/**
@@ -90,12 +91,12 @@ public abstract class AbstractIntegerDis
throw MathRuntimeException.createIllegalArgumentException(
LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT, x0, x1);
}
- if (Math.floor(x0) < x0) {
- return cumulativeProbability(((int) Math.floor(x0)) + 1,
- (int) Math.floor(x1)); // don't want to count mass below x0
+ if (FastMath.floor(x0) < x0) {
+ return cumulativeProbability(((int) FastMath.floor(x0)) + 1,
+ (int) FastMath.floor(x1)); // don't want to count mass below x0
} else { // x0 is mathematical integer, so use as is
- return cumulativeProbability((int) Math.floor(x0),
- (int) Math.floor(x1));
+ return cumulativeProbability((int) FastMath.floor(x0),
+ (int) FastMath.floor(x1));
}
}
@@ -123,7 +124,7 @@ public abstract class AbstractIntegerDis
* @return the value of the probability density function at x
*/
public double probability(double x) {
- double fl = Math.floor(x);
+ double fl = FastMath.floor(x);
if (fl == x) {
return this.probability((int) x);
} else {
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java Sun Aug 29 21:49:40 2010
@@ -21,6 +21,7 @@ import org.apache.commons.math.MathRunti
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.special.Gamma;
import org.apache.commons.math.special.Beta;
+import org.apache.commons.math.util.FastMath;
/**
* Implements the Beta distribution.
@@ -156,9 +157,9 @@ public class BetaDistributionImpl
}
return 0;
} else {
- double logX = Math.log(x);
- double log1mX = Math.log1p(-x);
- return Math.exp((alpha - 1) * logX + (beta - 1) * log1mX - z);
+ double logX = FastMath.log(x);
+ double log1mX = FastMath.log1p(-x);
+ return FastMath.exp((alpha - 1) * logX + (beta - 1) * log1mX - z);
}
}
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java Sun Aug 29 21:49:40 2010
@@ -22,6 +22,7 @@ import org.apache.commons.math.MathExcep
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.special.Beta;
+import org.apache.commons.math.util.FastMath;
/**
* The default implementation of {@link BinomialDistribution}.
@@ -184,7 +185,7 @@ public class BinomialDistributionImpl ex
if (x < 0 || x > numberOfTrials) {
ret = 0.0;
} else {
- ret = Math.exp(SaddlePointExpansion.logBinomialProbability(x,
+ ret = FastMath.exp(SaddlePointExpansion.logBinomialProbability(x,
numberOfTrials, probabilityOfSuccess,
1.0 - probabilityOfSuccess));
}
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java Sun Aug 29 21:49:40 2010
@@ -21,6 +21,7 @@ import java.io.Serializable;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.exception.util.LocalizedFormats;
+import org.apache.commons.math.util.FastMath;
/**
* Default implementation of
@@ -88,7 +89,7 @@ public class CauchyDistributionImpl exte
* @return CDF evaluted at <code>x</code>.
*/
public double cumulativeProbability(double x) {
- return 0.5 + (Math.atan((x - median) / scale) / Math.PI);
+ return 0.5 + (FastMath.atan((x - median) / scale) / FastMath.PI);
}
/**
@@ -117,7 +118,7 @@ public class CauchyDistributionImpl exte
@Override
public double density(double x) {
final double dev = x - median;
- return (1 / Math.PI) * (scale / (dev * dev + scale * scale));
+ return (1 / FastMath.PI) * (scale / (dev * dev + scale * scale));
}
/**
@@ -143,7 +144,7 @@ public class CauchyDistributionImpl exte
} else if (p == 1) {
ret = Double.POSITIVE_INFINITY;
} else {
- ret = median + scale * Math.tan(Math.PI * (p - .5));
+ ret = median + scale * FastMath.tan(FastMath.PI * (p - .5));
}
return ret;
}
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java Sun Aug 29 21:49:40 2010
@@ -21,6 +21,7 @@ import java.io.Serializable;
import org.apache.commons.math.MathException;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.exception.util.LocalizedFormats;
+import org.apache.commons.math.util.FastMath;
/**
* The default implementation of {@link ExponentialDistribution}.
@@ -120,7 +121,7 @@ public class ExponentialDistributionImpl
if (x < 0) {
return 0;
}
- return Math.exp(-x / mean) / mean;
+ return FastMath.exp(-x / mean) / mean;
}
/**
@@ -143,7 +144,7 @@ public class ExponentialDistributionImpl
if (x <= 0.0) {
ret = 0.0;
} else {
- ret = 1.0 - Math.exp(-x / mean);
+ ret = 1.0 - FastMath.exp(-x / mean);
}
return ret;
}
@@ -170,7 +171,7 @@ public class ExponentialDistributionImpl
} else if (p == 1.0) {
ret = Double.POSITIVE_INFINITY;
} else {
- ret = -mean * Math.log(1.0 - p);
+ ret = -mean * FastMath.log(1.0 - p);
}
return ret;
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/FDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/FDistributionImpl.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/FDistributionImpl.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/FDistributionImpl.java Sun Aug 29 21:49:40 2010
@@ -22,6 +22,7 @@ import org.apache.commons.math.MathExcep
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.special.Beta;
+import org.apache.commons.math.util.FastMath;
/**
* Default implementation of
@@ -88,11 +89,11 @@ public class FDistributionImpl
public double density(double x) {
final double nhalf = numeratorDegreesOfFreedom / 2;
final double mhalf = denominatorDegreesOfFreedom / 2;
- final double logx = Math.log(x);
- final double logn = Math.log(numeratorDegreesOfFreedom);
- final double logm = Math.log(denominatorDegreesOfFreedom);
- final double lognxm = Math.log(numeratorDegreesOfFreedom * x + denominatorDegreesOfFreedom);
- return Math.exp(nhalf*logn + nhalf*logx - logx + mhalf*logm - nhalf*lognxm -
+ final double logx = FastMath.log(x);
+ final double logn = FastMath.log(numeratorDegreesOfFreedom);
+ final double logm = FastMath.log(denominatorDegreesOfFreedom);
+ final double lognxm = FastMath.log(numeratorDegreesOfFreedom * x + denominatorDegreesOfFreedom);
+ return FastMath.exp(nhalf*logn + nhalf*logx - logx + mhalf*logm - nhalf*lognxm -
mhalf*lognxm - Beta.logBeta(nhalf, mhalf));
}
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java Sun Aug 29 21:49:40 2010
@@ -22,6 +22,7 @@ import org.apache.commons.math.MathExcep
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.special.Gamma;
+import org.apache.commons.math.util.FastMath;
/**
* The default implementation of {@link GammaDistribution}.
@@ -202,7 +203,7 @@ public class GammaDistributionImpl exten
@Override
public double density(double x) {
if (x < 0) return 0;
- return Math.pow(x / beta, alpha - 1) / beta * Math.exp(-x / beta) / Math.exp(Gamma.logGamma(alpha));
+ return FastMath.pow(x / beta, alpha - 1) / beta * FastMath.exp(-x / beta) / FastMath.exp(Gamma.logGamma(alpha));
}
/**
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java Sun Aug 29 21:49:40 2010
@@ -22,6 +22,7 @@ import java.io.Serializable;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.util.MathUtils;
+import org.apache.commons.math.util.FastMath;
/**
* The default implementation of {@link HypergeometricDistribution}.
@@ -144,7 +145,7 @@ public class HypergeometricDistributionI
* @return the lowest domain value of the hypergeometric distribution.
*/
private int getLowerDomain(int n, int m, int k) {
- return Math.max(0, m - (n - k));
+ return FastMath.max(0, m - (n - k));
}
/**
@@ -183,7 +184,7 @@ public class HypergeometricDistributionI
* @return the highest domain value of the hypergeometric distribution.
*/
private int getUpperDomain(int m, int k) {
- return Math.min(k, m);
+ return FastMath.min(k, m);
}
/**
@@ -208,7 +209,7 @@ public class HypergeometricDistributionI
populationSize - numberOfSuccesses, p, q);
double p3 =
SaddlePointExpansion.logBinomialProbability(sampleSize, populationSize, p, q);
- ret = Math.exp(p1 + p2 - p3);
+ ret = FastMath.exp(p1 + p2 - p3);
}
return ret;
@@ -225,7 +226,7 @@ public class HypergeometricDistributionI
* @return PMF for the distribution.
*/
private double probability(int n, int m, int k, int x) {
- return Math.exp(MathUtils.binomialCoefficientLog(m, x) +
+ return FastMath.exp(MathUtils.binomialCoefficientLog(m, x) +
MathUtils.binomialCoefficientLog(n - m, k - x) -
MathUtils.binomialCoefficientLog(n, k));
}
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java Sun Aug 29 21:49:40 2010
@@ -24,6 +24,7 @@ import org.apache.commons.math.MathRunti
import org.apache.commons.math.MaxIterationsExceededException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.special.Erf;
+import org.apache.commons.math.util.FastMath;
/**
* Default implementation of
@@ -44,7 +45,7 @@ public class NormalDistributionImpl exte
private static final long serialVersionUID = 8589540077390120676L;
/** &sqrt;(2 π) */
- private static final double SQRT2PI = Math.sqrt(2 * Math.PI);
+ private static final double SQRT2PI = FastMath.sqrt(2 * FastMath.PI);
/** The mean of this distribution. */
private double mean = 0;
@@ -165,7 +166,7 @@ public class NormalDistributionImpl exte
*/
public double density(double x) {
double x0 = x - mean;
- return Math.exp(-x0 * x0 / (2 * standardDeviation * standardDeviation)) / (standardDeviation * SQRT2PI);
+ return FastMath.exp(-x0 * x0 / (2 * standardDeviation * standardDeviation)) / (standardDeviation * SQRT2PI);
}
/**
@@ -179,7 +180,7 @@ public class NormalDistributionImpl exte
public double cumulativeProbability(double x) throws MathException {
try {
return 0.5 * (1.0 + Erf.erf((x - mean) /
- (standardDeviation * Math.sqrt(2.0))));
+ (standardDeviation * FastMath.sqrt(2.0))));
} catch (MaxIterationsExceededException ex) {
if (x < (mean - 20 * standardDeviation)) { // JDK 1.5 blows at 38
return 0.0d;
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/PascalDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/PascalDistributionImpl.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/PascalDistributionImpl.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/PascalDistributionImpl.java Sun Aug 29 21:49:40 2010
@@ -23,6 +23,7 @@ import org.apache.commons.math.MathRunti
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.special.Beta;
import org.apache.commons.math.util.MathUtils;
+import org.apache.commons.math.util.FastMath;
/**
* The default implementation of {@link PascalDistribution}.
@@ -176,8 +177,8 @@ public class PascalDistributionImpl exte
} else {
ret = MathUtils.binomialCoefficientDouble(x +
numberOfSuccesses - 1, numberOfSuccesses - 1) *
- Math.pow(probabilityOfSuccess, numberOfSuccesses) *
- Math.pow(1.0 - probabilityOfSuccess, x);
+ FastMath.pow(probabilityOfSuccess, numberOfSuccesses) *
+ FastMath.pow(1.0 - probabilityOfSuccess, x);
}
return ret;
}
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java Sun Aug 29 21:49:40 2010
@@ -23,6 +23,7 @@ import org.apache.commons.math.MathRunti
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.special.Gamma;
import org.apache.commons.math.util.MathUtils;
+import org.apache.commons.math.util.FastMath;
/**
* Implementation for the {@link PoissonDistribution}.
@@ -174,7 +175,7 @@ public class PoissonDistributionImpl ext
mean = p;
normal = z;
normal.setMean(p);
- normal.setStandardDeviation(Math.sqrt(p));
+ normal.setStandardDeviation(FastMath.sqrt(p));
}
/**
@@ -189,11 +190,11 @@ public class PoissonDistributionImpl ext
if (x < 0 || x == Integer.MAX_VALUE) {
ret = 0.0;
} else if (x == 0) {
- ret = Math.exp(-mean);
+ ret = FastMath.exp(-mean);
} else {
- ret = Math.exp(-SaddlePointExpansion.getStirlingError(x) -
+ ret = FastMath.exp(-SaddlePointExpansion.getStirlingError(x) -
SaddlePointExpansion.getDeviancePart(x, mean)) /
- Math.sqrt(MathUtils.TWO_PI * x);
+ FastMath.sqrt(MathUtils.TWO_PI * x);
}
return ret;
}
@@ -257,7 +258,7 @@ public class PoissonDistributionImpl ext
*/
@Override
public int sample() throws MathException {
- return (int) Math.min(randomData.nextPoisson(mean), Integer.MAX_VALUE);
+ return (int) FastMath.min(randomData.nextPoisson(mean), Integer.MAX_VALUE);
}
/**
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/SaddlePointExpansion.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/SaddlePointExpansion.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/SaddlePointExpansion.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/SaddlePointExpansion.java Sun Aug 29 21:49:40 2010
@@ -17,6 +17,7 @@
package org.apache.commons.math.distribution;
import org.apache.commons.math.special.Gamma;
+import org.apache.commons.math.util.FastMath;
import org.apache.commons.math.util.MathUtils;
/**
@@ -45,7 +46,7 @@ import org.apache.commons.math.util.Math
final class SaddlePointExpansion {
/** 1/2 * log(2 π). */
- private static final double HALF_LOG_2_PI = 0.5 * Math.log(MathUtils.TWO_PI);
+ private static final double HALF_LOG_2_PI = 0.5 * FastMath.log(MathUtils.TWO_PI);
/** exact Stirling expansion error for certain values. */
private static final double[] EXACT_STIRLING_ERRORS = { 0.0, /* 0.0 */
@@ -107,10 +108,10 @@ final class SaddlePointExpansion {
double ret;
if (z < 15.0) {
double z2 = 2.0 * z;
- if (Math.floor(z2) == z2) {
+ if (FastMath.floor(z2) == z2) {
ret = EXACT_STIRLING_ERRORS[(int) z2];
} else {
- ret = Gamma.logGamma(z + 1.0) - (z + 0.5) * Math.log(z) +
+ ret = Gamma.logGamma(z + 1.0) - (z + 0.5) * FastMath.log(z) +
z - HALF_LOG_2_PI;
}
} else {
@@ -143,7 +144,7 @@ final class SaddlePointExpansion {
*/
static double getDeviancePart(double x, double mu) {
double ret;
- if (Math.abs(x - mu) < 0.1 * (x + mu)) {
+ if (FastMath.abs(x - mu) < 0.1 * (x + mu)) {
double d = x - mu;
double v = d / (x + mu);
double s1 = v * d;
@@ -159,7 +160,7 @@ final class SaddlePointExpansion {
}
ret = s1;
} else {
- ret = x * Math.log(x / mu) + mu - x;
+ ret = x * FastMath.log(x / mu) + mu - x;
}
return ret;
}
@@ -180,20 +181,20 @@ final class SaddlePointExpansion {
if (p < 0.1) {
ret = -getDeviancePart(n, n * q) - n * p;
} else {
- ret = n * Math.log(q);
+ ret = n * FastMath.log(q);
}
} else if (x == n) {
if (q < 0.1) {
ret = -getDeviancePart(n, n * p) - n * q;
} else {
- ret = n * Math.log(p);
+ ret = n * FastMath.log(p);
}
} else {
ret = getStirlingError(n) - getStirlingError(x) -
getStirlingError(n - x) - getDeviancePart(x, n * p) -
getDeviancePart(n - x, n * q);
double f = (MathUtils.TWO_PI * x * (n - x)) / n;
- ret = -0.5 * Math.log(f) + ret;
+ ret = -0.5 * FastMath.log(f) + ret;
}
return ret;
}
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/TDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/TDistributionImpl.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/TDistributionImpl.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/TDistributionImpl.java Sun Aug 29 21:49:40 2010
@@ -23,6 +23,7 @@ import org.apache.commons.math.MathRunti
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.special.Beta;
import org.apache.commons.math.special.Gamma;
+import org.apache.commons.math.util.FastMath;
/**
* Default implementation of
@@ -113,8 +114,8 @@ public class TDistributionImpl
public double density(double x) {
final double n = degreesOfFreedom;
final double nPlus1Over2 = (n + 1) / 2;
- return Math.exp(Gamma.logGamma(nPlus1Over2) - 0.5 * (Math.log(Math.PI) + Math.log(n)) -
- Gamma.logGamma(n/2) - nPlus1Over2 * Math.log(1 + x * x /n));
+ return FastMath.exp(Gamma.logGamma(nPlus1Over2) - 0.5 * (FastMath.log(FastMath.PI) + FastMath.log(n)) -
+ Gamma.logGamma(n/2) - nPlus1Over2 * FastMath.log(1 + x * x /n));
}
/**
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java Sun Aug 29 21:49:40 2010
@@ -21,6 +21,7 @@ import java.io.Serializable;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.exception.util.LocalizedFormats;
+import org.apache.commons.math.util.FastMath;
/**
* Default implementation of
@@ -86,7 +87,7 @@ public class WeibullDistributionImpl ext
if (x <= 0.0) {
ret = 0.0;
} else {
- ret = 1.0 - Math.exp(-Math.pow(x / scale, shape));
+ ret = 1.0 - FastMath.exp(-FastMath.pow(x / scale, shape));
}
return ret;
}
@@ -121,16 +122,16 @@ public class WeibullDistributionImpl ext
}
final double xscale = x / scale;
- final double xscalepow = Math.pow(xscale, shape - 1);
+ final double xscalepow = FastMath.pow(xscale, shape - 1);
/*
- * Math.pow(x / scale, shape) =
- * Math.pow(xscale, shape) =
- * Math.pow(xscale, shape - 1) * xscale
+ * FastMath.pow(x / scale, shape) =
+ * FastMath.pow(xscale, shape) =
+ * FastMath.pow(xscale, shape - 1) * xscale
*/
final double xscalepowshape = xscalepow * xscale;
- return (shape / scale) * xscalepow * Math.exp(-xscalepowshape);
+ return (shape / scale) * xscalepow * FastMath.exp(-xscalepowshape);
}
/**
@@ -156,7 +157,7 @@ public class WeibullDistributionImpl ext
} else if (p == 1) {
ret = Double.POSITIVE_INFINITY;
} else {
- ret = scale * Math.pow(-Math.log(1.0 - p), 1.0 / shape);
+ ret = scale * FastMath.pow(-FastMath.log(1.0 - p), 1.0 / shape);
}
return ret;
}
@@ -244,7 +245,7 @@ public class WeibullDistributionImpl ext
@Override
protected double getInitialDomain(double p) {
// use median
- return Math.pow(scale * Math.log(2.0), 1.0 / shape);
+ return FastMath.pow(scale * FastMath.log(2.0), 1.0 / shape);
}
/**
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/ZipfDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/ZipfDistributionImpl.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/ZipfDistributionImpl.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/distribution/ZipfDistributionImpl.java Sun Aug 29 21:49:40 2010
@@ -21,6 +21,7 @@ import java.io.Serializable;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.exception.util.LocalizedFormats;
+import org.apache.commons.math.util.FastMath;
/**
* Implementation for the {@link ZipfDistribution}.
@@ -144,7 +145,7 @@ public class ZipfDistributionImpl extend
return 0.0;
}
- return (1.0 / Math.pow(x, exponent)) / generalizedHarmonic(numberOfElements, exponent);
+ return (1.0 / FastMath.pow(x, exponent)) / generalizedHarmonic(numberOfElements, exponent);
}
@@ -205,7 +206,7 @@ public class ZipfDistributionImpl extend
private double generalizedHarmonic(final int n, final double m) {
double value = 0;
for (int k = n; k > 0; --k) {
- value += 1.0 / Math.pow(k, m);
+ value += 1.0 / FastMath.pow(k, m);
}
return value;
}
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/estimation/AbstractEstimator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/estimation/AbstractEstimator.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/estimation/AbstractEstimator.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/estimation/AbstractEstimator.java Sun Aug 29 21:49:40 2010
@@ -24,6 +24,7 @@ import org.apache.commons.math.linear.In
import org.apache.commons.math.linear.LUDecompositionImpl;
import org.apache.commons.math.linear.MatrixUtils;
import org.apache.commons.math.linear.RealMatrix;
+import org.apache.commons.math.util.FastMath;
/**
* Base class for implementing estimators.
@@ -128,7 +129,7 @@ public abstract class AbstractEstimator
int index = 0;
for (int i = 0; i < rows; i++) {
WeightedMeasurement wm = measurements[i];
- double factor = -Math.sqrt(wm.getWeight());
+ double factor = -FastMath.sqrt(wm.getWeight());
for (int j = 0; j < cols; ++j) {
jacobian[index++] = factor * wm.getPartial(parameters[j]);
}
@@ -160,10 +161,10 @@ public abstract class AbstractEstimator
for (int i = 0; i < rows; i++, index += cols) {
WeightedMeasurement wm = measurements[i];
double residual = wm.getResidual();
- residuals[i] = Math.sqrt(wm.getWeight()) * residual;
+ residuals[i] = FastMath.sqrt(wm.getWeight()) * residual;
cost += wm.getWeight() * residual * residual;
}
- cost = Math.sqrt(cost);
+ cost = FastMath.sqrt(cost);
}
@@ -185,7 +186,7 @@ public abstract class AbstractEstimator
double residual = wm[i].getResidual();
criterion += wm[i].getWeight() * residual * residual;
}
- return Math.sqrt(criterion / wm.length);
+ return FastMath.sqrt(criterion / wm.length);
}
/**
@@ -262,10 +263,10 @@ public abstract class AbstractEstimator
m, p);
}
double[] errors = new double[problem.getUnboundParameters().length];
- final double c = Math.sqrt(getChiSquare(problem) / (m - p));
+ final double c = FastMath.sqrt(getChiSquare(problem) / (m - p));
double[][] covar = getCovariances(problem);
for (int i = 0; i < errors.length; ++i) {
- errors[i] = Math.sqrt(covar[i][i]) * c;
+ errors[i] = FastMath.sqrt(covar[i][i]) * c;
}
return errors;
}
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java Sun Aug 29 21:49:40 2010
@@ -26,6 +26,7 @@ import org.apache.commons.math.linear.Ma
import org.apache.commons.math.linear.RealMatrix;
import org.apache.commons.math.linear.RealVector;
import org.apache.commons.math.linear.ArrayRealVector;
+import org.apache.commons.math.util.FastMath;
/**
* This class implements a solver for estimation problems.
@@ -97,7 +98,7 @@ public class GaussNewtonEstimator extend
* to improve the criterion anymore
* @param steadyStateThreshold steady state detection threshold, the
* problem has converged has reached a steady state if
- * <code>Math.abs(J<sub>n</sub> - J<sub>n-1</sub>) <
+ * <code>FastMath.abs(J<sub>n</sub> - J<sub>n-1</sub>) <
* J<sub>n</sub> × convergence</code>, where <code>J<sub>n</sub></code>
* and <code>J<sub>n-1</sub></code> are the current and preceding criterion
* values (square sum of the weighted residuals of considered measurements).
@@ -122,7 +123,7 @@ public class GaussNewtonEstimator extend
* Set the steady state detection threshold.
* <p>
* The problem has converged has reached a steady state if
- * <code>Math.abs(J<sub>n</sub> - J<sub>n-1</sub>) <
+ * <code>FastMath.abs(J<sub>n</sub> - J<sub>n-1</sub>) <
* J<sub>n</sub> × convergence</code>, where <code>J<sub>n</sub></code>
* and <code>J<sub>n-1</sub></code> are the current and preceding criterion
* values (square sum of the weighted residuals of considered measurements).
@@ -222,8 +223,8 @@ public class GaussNewtonEstimator extend
updateResidualsAndCost();
} while ((getCostEvaluations() < 2) ||
- (Math.abs(previous - cost) > (cost * steadyStateThreshold) &&
- (Math.abs(cost) > convergence)));
+ (FastMath.abs(previous - cost) > (cost * steadyStateThreshold) &&
+ (FastMath.abs(cost) > convergence)));
}
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/estimation/LevenbergMarquardtEstimator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/estimation/LevenbergMarquardtEstimator.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/estimation/LevenbergMarquardtEstimator.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/estimation/LevenbergMarquardtEstimator.java Sun Aug 29 21:49:40 2010
@@ -20,6 +20,7 @@ import java.io.Serializable;
import java.util.Arrays;
import org.apache.commons.math.exception.util.LocalizedFormats;
+import org.apache.commons.math.util.FastMath;
/**
@@ -250,7 +251,7 @@ public class LevenbergMarquardtEstimator
initializeEstimate(problem);
// arrays shared with the other private methods
- solvedCols = Math.min(rows, cols);
+ solvedCols = FastMath.min(rows, cols);
diagR = new double[cols];
jacNorm = new double[cols];
beta = new double[cols];
@@ -303,7 +304,7 @@ public class LevenbergMarquardtEstimator
xNorm += xk * xk;
diag[k] = dk;
}
- xNorm = Math.sqrt(xNorm);
+ xNorm = FastMath.sqrt(xNorm);
// initialize the step bound delta
delta = (xNorm == 0) ? initialStepBoundFactor : (initialStepBoundFactor * xNorm);
@@ -323,7 +324,7 @@ public class LevenbergMarquardtEstimator
sum += jacobian[index] * residuals[i];
index += cols;
}
- maxCosine = Math.max(maxCosine, Math.abs(sum) / (s * cost));
+ maxCosine = FastMath.max(maxCosine, FastMath.abs(sum) / (s * cost));
}
}
}
@@ -333,7 +334,7 @@ public class LevenbergMarquardtEstimator
// rescale if necessary
for (int j = 0; j < cols; ++j) {
- diag[j] = Math.max(diag[j], jacNorm[j]);
+ diag[j] = FastMath.max(diag[j], jacNorm[j]);
}
// inner loop
@@ -361,11 +362,11 @@ public class LevenbergMarquardtEstimator
double s = diag[pj] * lmDir[pj];
lmNorm += s * s;
}
- lmNorm = Math.sqrt(lmNorm);
+ lmNorm = FastMath.sqrt(lmNorm);
// on the first iteration, adjust the initial step bound.
if (firstIteration) {
- delta = Math.min(delta, lmNorm);
+ delta = FastMath.min(delta, lmNorm);
}
// evaluate the function at x + p and calculate its norm
@@ -410,7 +411,7 @@ public class LevenbergMarquardtEstimator
if ((0.1 * cost >= previousCost) || (tmp < 0.1)) {
tmp = 0.1;
}
- delta = tmp * Math.min(delta, 10.0 * lmNorm);
+ delta = tmp * FastMath.min(delta, 10.0 * lmNorm);
lmPar /= tmp;
} else if ((lmPar == 0) || (ratio >= 0.75)) {
delta = 2 * lmNorm;
@@ -426,7 +427,7 @@ public class LevenbergMarquardtEstimator
double xK = diag[k] * parameters[k].getEstimate();
xNorm += xK * xK;
}
- xNorm = Math.sqrt(xNorm);
+ xNorm = FastMath.sqrt(xNorm);
} else {
// failed iteration, reset the previous values
cost = previousCost;
@@ -440,7 +441,7 @@ public class LevenbergMarquardtEstimator
}
// tests for convergence.
- if (((Math.abs(actRed) <= costRelativeTolerance) &&
+ if (((FastMath.abs(actRed) <= costRelativeTolerance) &&
(preRed <= costRelativeTolerance) &&
(ratio <= 2.0)) ||
(delta <= parRelativeTolerance * xNorm)) {
@@ -449,7 +450,7 @@ public class LevenbergMarquardtEstimator
// tests for termination and stringent tolerances
// (2.2204e-16 is the machine epsilon for IEEE754)
- if ((Math.abs(actRed) <= 2.2204e-16) && (preRed <= 2.2204e-16) && (ratio <= 2.0)) {
+ if ((FastMath.abs(actRed) <= 2.2204e-16) && (preRed <= 2.2204e-16) && (ratio <= 2.0)) {
throw new EstimationException("cost relative tolerance is too small ({0})," +
" no further reduction in the" +
" sum of squares is possible",
@@ -524,7 +525,7 @@ public class LevenbergMarquardtEstimator
work1[pj] = s;
dxNorm += s * s;
}
- dxNorm = Math.sqrt(dxNorm);
+ dxNorm = FastMath.sqrt(dxNorm);
double fp = dxNorm - delta;
if (fp <= 0.1 * delta) {
lmPar = 0;
@@ -570,16 +571,16 @@ public class LevenbergMarquardtEstimator
sum /= diag[pj];
sum2 += sum * sum;
}
- double gNorm = Math.sqrt(sum2);
+ double gNorm = FastMath.sqrt(sum2);
double paru = gNorm / delta;
if (paru == 0) {
// 2.2251e-308 is the smallest positive real for IEE754
- paru = 2.2251e-308 / Math.min(delta, 0.1);
+ paru = 2.2251e-308 / FastMath.min(delta, 0.1);
}
// if the input par lies outside of the interval (parl,paru),
// set par to the closer endpoint
- lmPar = Math.min(paru, Math.max(lmPar, parl));
+ lmPar = FastMath.min(paru, FastMath.max(lmPar, parl));
if (lmPar == 0) {
lmPar = gNorm / dxNorm;
}
@@ -588,9 +589,9 @@ public class LevenbergMarquardtEstimator
// evaluate the function at the current value of lmPar
if (lmPar == 0) {
- lmPar = Math.max(2.2251e-308, 0.001 * paru);
+ lmPar = FastMath.max(2.2251e-308, 0.001 * paru);
}
- double sPar = Math.sqrt(lmPar);
+ double sPar = FastMath.sqrt(lmPar);
for (int j = 0; j < solvedCols; ++j) {
int pj = permutation[j];
work1[pj] = sPar * diag[pj];
@@ -604,13 +605,13 @@ public class LevenbergMarquardtEstimator
work3[pj] = s;
dxNorm += s * s;
}
- dxNorm = Math.sqrt(dxNorm);
+ dxNorm = FastMath.sqrt(dxNorm);
double previousFP = fp;
fp = dxNorm - delta;
// if the function is small enough, accept the current value
// of lmPar, also test for the exceptional cases where parl is zero
- if ((Math.abs(fp) <= 0.1 * delta) ||
+ if ((FastMath.abs(fp) <= 0.1 * delta) ||
((parl == 0) && (fp <= previousFP) && (previousFP < 0))) {
return;
}
@@ -637,13 +638,13 @@ public class LevenbergMarquardtEstimator
// depending on the sign of the function, update parl or paru.
if (fp > 0) {
- parl = Math.max(parl, lmPar);
+ parl = FastMath.max(parl, lmPar);
} else if (fp < 0) {
- paru = Math.min(paru, lmPar);
+ paru = FastMath.min(paru, lmPar);
}
// compute an improved estimate for lmPar
- lmPar = Math.max(parl, lmPar + correction);
+ lmPar = FastMath.max(parl, lmPar + correction);
}
}
@@ -708,13 +709,13 @@ public class LevenbergMarquardtEstimator
final double sin;
final double cos;
double rkk = jacobian[k * cols + pk];
- if (Math.abs(rkk) < Math.abs(lmDiag[k])) {
+ if (FastMath.abs(rkk) < FastMath.abs(lmDiag[k])) {
final double cotan = rkk / lmDiag[k];
- sin = 1.0 / Math.sqrt(1.0 + cotan * cotan);
+ sin = 1.0 / FastMath.sqrt(1.0 + cotan * cotan);
cos = sin * cotan;
} else {
final double tan = lmDiag[k] / rkk;
- cos = 1.0 / Math.sqrt(1.0 + tan * tan);
+ cos = 1.0 / FastMath.sqrt(1.0 + tan * tan);
sin = cos * tan;
}
@@ -805,7 +806,7 @@ public class LevenbergMarquardtEstimator
double akk = jacobian[index];
norm2 += akk * akk;
}
- jacNorm[k] = Math.sqrt(norm2);
+ jacNorm[k] = FastMath.sqrt(norm2);
}
// transform the matrix column after column
@@ -842,7 +843,7 @@ public class LevenbergMarquardtEstimator
// choose alpha such that Hk.u = alpha ek
int kDiag = k * cols + pk;
double akk = jacobian[kDiag];
- double alpha = (akk > 0) ? -Math.sqrt(ak2) : Math.sqrt(ak2);
+ double alpha = (akk > 0) ? -FastMath.sqrt(ak2) : FastMath.sqrt(ak2);
double betak = 1.0 / (ak2 - akk * alpha);
beta[pk] = betak;
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/fraction/BigFraction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/fraction/BigFraction.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/fraction/BigFraction.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/fraction/BigFraction.java Sun Aug 29 21:49:40 2010
@@ -25,6 +25,7 @@ import org.apache.commons.math.MathRunti
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.exception.NullArgumentException;
import org.apache.commons.math.util.MathUtils;
+import org.apache.commons.math.util.FastMath;
/**
* Representation of a rational number without any overflow. This class is
@@ -270,14 +271,14 @@ public class BigFraction
throws FractionConversionException {
long overflow = Integer.MAX_VALUE;
double r0 = value;
- long a0 = (long) Math.floor(r0);
+ long a0 = (long) FastMath.floor(r0);
if (a0 > overflow) {
throw new FractionConversionException(value, a0, 1l);
}
// check for (almost) integer arguments, which should not go
// to iterations.
- if (Math.abs(a0 - value) < epsilon) {
+ if (FastMath.abs(a0 - value) < epsilon) {
numerator = BigInteger.valueOf(a0);
denominator = BigInteger.ONE;
return;
@@ -296,7 +297,7 @@ public class BigFraction
do {
++n;
final double r1 = 1.0 / (r0 - a0);
- final long a1 = (long) Math.floor(r1);
+ final long a1 = (long) FastMath.floor(r1);
p2 = (a1 * p1) + p0;
q2 = (a1 * q1) + q0;
if ((p2 > overflow) || (q2 > overflow)) {
@@ -305,7 +306,7 @@ public class BigFraction
final double convergent = (double) p2 / (double) q2;
if ((n < maxIterations) &&
- (Math.abs(convergent - value) > epsilon) &&
+ (FastMath.abs(convergent - value) > epsilon) &&
(q2 < maxDenominator)) {
p0 = p1;
p1 = p2;
@@ -994,8 +995,8 @@ public class BigFraction
* @return <tt>this<sup>exponent</sup></tt>.
*/
public double pow(final double exponent) {
- return Math.pow(numerator.doubleValue(), exponent) /
- Math.pow(denominator.doubleValue(), exponent);
+ return FastMath.pow(numerator.doubleValue(), exponent) /
+ FastMath.pow(denominator.doubleValue(), exponent);
}
/**
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/fraction/Fraction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/fraction/Fraction.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/fraction/Fraction.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/fraction/Fraction.java Sun Aug 29 21:49:40 2010
@@ -24,6 +24,7 @@ import org.apache.commons.math.MathRunti
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.exception.NullArgumentException;
import org.apache.commons.math.util.MathUtils;
+import org.apache.commons.math.util.FastMath;
/**
* Representation of a rational number.
@@ -176,14 +177,14 @@ public class Fraction
{
long overflow = Integer.MAX_VALUE;
double r0 = value;
- long a0 = (long)Math.floor(r0);
+ long a0 = (long)FastMath.floor(r0);
if (a0 > overflow) {
throw new FractionConversionException(value, a0, 1l);
}
// check for (almost) integer arguments, which should not go
// to iterations.
- if (Math.abs(a0 - value) < epsilon) {
+ if (FastMath.abs(a0 - value) < epsilon) {
this.numerator = (int) a0;
this.denominator = 1;
return;
@@ -202,7 +203,7 @@ public class Fraction
do {
++n;
double r1 = 1.0 / (r0 - a0);
- long a1 = (long)Math.floor(r1);
+ long a1 = (long)FastMath.floor(r1);
p2 = (a1 * p1) + p0;
q2 = (a1 * q1) + q0;
if ((p2 > overflow) || (q2 > overflow)) {
@@ -210,7 +211,7 @@ public class Fraction
}
double convergent = (double)p2 / (double)q2;
- if (n < maxIterations && Math.abs(convergent - value) > epsilon && q2 < maxDenominator) {
+ if (n < maxIterations && FastMath.abs(convergent - value) > epsilon && q2 < maxDenominator) {
p0 = p1;
p1 = p2;
q0 = q1;
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/genetics/ElitisticListPopulation.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/genetics/ElitisticListPopulation.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/genetics/ElitisticListPopulation.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/genetics/ElitisticListPopulation.java Sun Aug 29 21:49:40 2010
@@ -19,6 +19,8 @@ package org.apache.commons.math.genetics
import java.util.Collections;
import java.util.List;
+import org.apache.commons.math.util.FastMath;
+
/**
* Population of chromosomes which uses elitism (certain percentace of the best
* chromosomes is directly copied to the next generation).
@@ -76,7 +78,7 @@ public class ElitisticListPopulation ext
Collections.sort(oldChromosomes);
// index of the last "not good enough" chromosome
- int boundIndex = (int) Math.ceil((1.0 - this.getElitismRate()) * oldChromosomes.size());
+ int boundIndex = (int) FastMath.ceil((1.0 - this.getElitismRate()) * oldChromosomes.size());
for (int i=boundIndex; i<oldChromosomes.size(); i++) {
nextGeneration.addChromosome(oldChromosomes.get(i));
}
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/geometry/Rotation.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/geometry/Rotation.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/geometry/Rotation.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/geometry/Rotation.java Sun Aug 29 21:49:40 2010
@@ -21,6 +21,7 @@ import java.io.Serializable;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.exception.util.LocalizedFormats;
+import org.apache.commons.math.util.FastMath;
/**
* This class implements rotations in a three-dimensional space.
@@ -134,7 +135,7 @@ public class Rotation implements Seriali
if (needsNormalization) {
// normalization preprocessing
- double inv = 1.0 / Math.sqrt(q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3);
+ double inv = 1.0 / FastMath.sqrt(q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3);
q0 *= inv;
q1 *= inv;
q2 *= inv;
@@ -177,9 +178,9 @@ public class Rotation implements Seriali
}
double halfAngle = -0.5 * angle;
- double coeff = Math.sin(halfAngle) / norm;
+ double coeff = FastMath.sin(halfAngle) / norm;
- q0 = Math.cos (halfAngle);
+ q0 = FastMath.cos (halfAngle);
q1 = coeff * axis.getX();
q2 = coeff * axis.getY();
q3 = coeff * axis.getZ();
@@ -254,7 +255,7 @@ public class Rotation implements Seriali
double s = ort[0][0] + ort[1][1] + ort[2][2];
if (s > -0.19) {
// compute q0 and deduce q1, q2 and q3
- q0 = 0.5 * Math.sqrt(s + 1.0);
+ q0 = 0.5 * FastMath.sqrt(s + 1.0);
double inv = 0.25 / q0;
q1 = inv * (ort[1][2] - ort[2][1]);
q2 = inv * (ort[2][0] - ort[0][2]);
@@ -263,7 +264,7 @@ public class Rotation implements Seriali
s = ort[0][0] - ort[1][1] - ort[2][2];
if (s > -0.19) {
// compute q1 and deduce q0, q2 and q3
- q1 = 0.5 * Math.sqrt(s + 1.0);
+ q1 = 0.5 * FastMath.sqrt(s + 1.0);
double inv = 0.25 / q1;
q0 = inv * (ort[1][2] - ort[2][1]);
q2 = inv * (ort[0][1] + ort[1][0]);
@@ -272,7 +273,7 @@ public class Rotation implements Seriali
s = ort[1][1] - ort[0][0] - ort[2][2];
if (s > -0.19) {
// compute q2 and deduce q0, q1 and q3
- q2 = 0.5 * Math.sqrt(s + 1.0);
+ q2 = 0.5 * FastMath.sqrt(s + 1.0);
double inv = 0.25 / q2;
q0 = inv * (ort[2][0] - ort[0][2]);
q1 = inv * (ort[0][1] + ort[1][0]);
@@ -280,7 +281,7 @@ public class Rotation implements Seriali
} else {
// compute q3 and deduce q0, q1 and q2
s = ort[2][2] - ort[0][0] - ort[1][1];
- q3 = 0.5 * Math.sqrt(s + 1.0);
+ q3 = 0.5 * FastMath.sqrt(s + 1.0);
double inv = 0.25 / q3;
q0 = inv * (ort[0][1] - ort[1][0]);
q1 = inv * (ort[0][2] + ort[2][0]);
@@ -329,7 +330,7 @@ public class Rotation implements Seriali
double u2z = u2.getZ();
// normalize v1 in order to have (v1'|v1') = (u1|u1)
- double coeff = Math.sqrt (u1u1 / v1v1);
+ double coeff = FastMath.sqrt (u1u1 / v1v1);
double v1x = coeff * v1.getX();
double v1y = coeff * v1.getY();
double v1z = coeff * v1.getZ();
@@ -340,7 +341,7 @@ public class Rotation implements Seriali
double v1v2 = Vector3D.dotProduct(v1, v2);
double coeffU = u1u2 / u1u1;
double coeffV = v1v2 / u1u1;
- double beta = Math.sqrt((u2u2 - u1u2 * coeffU) / (v2v2 - v1v2 * coeffV));
+ double beta = FastMath.sqrt((u2u2 - u1u2 * coeffU) / (v2v2 - v1v2 * coeffV));
double alpha = coeffU - beta * coeffV;
double v2x = alpha * v1x + beta * v2.getX();
double v2y = alpha * v1y + beta * v2.getY();
@@ -416,7 +417,7 @@ public class Rotation implements Seriali
}
// compute the vectorial part
- c = Math.sqrt(c);
+ c = FastMath.sqrt(c);
double inv = 1.0 / (c + c);
q1 = inv * k.getX();
q2 = inv * k.getY();
@@ -464,7 +465,7 @@ public class Rotation implements Seriali
} else {
// general case: (u, v) defines a plane, we select
// the shortest possible rotation: axis orthogonal to this plane
- q0 = Math.sqrt(0.5 * (1.0 + dot / normProduct));
+ q0 = FastMath.sqrt(0.5 * (1.0 + dot / normProduct));
double coeff = 1.0 / (2.0 * q0 * normProduct);
q1 = coeff * (v.getY() * u.getZ() - v.getZ() * u.getY());
q2 = coeff * (v.getZ() * u.getX() - v.getX() * u.getZ());
@@ -552,10 +553,10 @@ public class Rotation implements Seriali
if (squaredSine == 0) {
return new Vector3D(1, 0, 0);
} else if (q0 < 0) {
- double inverse = 1 / Math.sqrt(squaredSine);
+ double inverse = 1 / FastMath.sqrt(squaredSine);
return new Vector3D(q1 * inverse, q2 * inverse, q3 * inverse);
}
- double inverse = -1 / Math.sqrt(squaredSine);
+ double inverse = -1 / FastMath.sqrt(squaredSine);
return new Vector3D(q1 * inverse, q2 * inverse, q3 * inverse);
}
@@ -565,11 +566,11 @@ public class Rotation implements Seriali
*/
public double getAngle() {
if ((q0 < -0.1) || (q0 > 0.1)) {
- return 2 * Math.asin(Math.sqrt(q1 * q1 + q2 * q2 + q3 * q3));
+ return 2 * FastMath.asin(FastMath.sqrt(q1 * q1 + q2 * q2 + q3 * q3));
} else if (q0 < 0) {
- return 2 * Math.acos(-q0);
+ return 2 * FastMath.acos(-q0);
}
- return 2 * Math.acos(q0);
+ return 2 * FastMath.acos(q0);
}
/** Get the Cardan or Euler angles corresponding to the instance.
@@ -623,9 +624,9 @@ public class Rotation implements Seriali
throw new CardanEulerSingularityException(true);
}
return new double[] {
- Math.atan2(-(v1.getY()), v1.getZ()),
- Math.asin(v2.getZ()),
- Math.atan2(-(v2.getY()), v2.getX())
+ FastMath.atan2(-(v1.getY()), v1.getZ()),
+ FastMath.asin(v2.getZ()),
+ FastMath.atan2(-(v2.getY()), v2.getX())
};
} else if (order == RotationOrder.XZY) {
@@ -641,9 +642,9 @@ public class Rotation implements Seriali
throw new CardanEulerSingularityException(true);
}
return new double[] {
- Math.atan2(v1.getZ(), v1.getY()),
- -Math.asin(v2.getY()),
- Math.atan2(v2.getZ(), v2.getX())
+ FastMath.atan2(v1.getZ(), v1.getY()),
+ -FastMath.asin(v2.getY()),
+ FastMath.atan2(v2.getZ(), v2.getX())
};
} else if (order == RotationOrder.YXZ) {
@@ -659,9 +660,9 @@ public class Rotation implements Seriali
throw new CardanEulerSingularityException(true);
}
return new double[] {
- Math.atan2(v1.getX(), v1.getZ()),
- -Math.asin(v2.getZ()),
- Math.atan2(v2.getX(), v2.getY())
+ FastMath.atan2(v1.getX(), v1.getZ()),
+ -FastMath.asin(v2.getZ()),
+ FastMath.atan2(v2.getX(), v2.getY())
};
} else if (order == RotationOrder.YZX) {
@@ -677,9 +678,9 @@ public class Rotation implements Seriali
throw new CardanEulerSingularityException(true);
}
return new double[] {
- Math.atan2(-(v1.getZ()), v1.getX()),
- Math.asin(v2.getX()),
- Math.atan2(-(v2.getZ()), v2.getY())
+ FastMath.atan2(-(v1.getZ()), v1.getX()),
+ FastMath.asin(v2.getX()),
+ FastMath.atan2(-(v2.getZ()), v2.getY())
};
} else if (order == RotationOrder.ZXY) {
@@ -695,9 +696,9 @@ public class Rotation implements Seriali
throw new CardanEulerSingularityException(true);
}
return new double[] {
- Math.atan2(-(v1.getX()), v1.getY()),
- Math.asin(v2.getY()),
- Math.atan2(-(v2.getX()), v2.getZ())
+ FastMath.atan2(-(v1.getX()), v1.getY()),
+ FastMath.asin(v2.getY()),
+ FastMath.atan2(-(v2.getX()), v2.getZ())
};
} else if (order == RotationOrder.ZYX) {
@@ -713,9 +714,9 @@ public class Rotation implements Seriali
throw new CardanEulerSingularityException(true);
}
return new double[] {
- Math.atan2(v1.getY(), v1.getX()),
- -Math.asin(v2.getX()),
- Math.atan2(v2.getY(), v2.getZ())
+ FastMath.atan2(v1.getY(), v1.getX()),
+ -FastMath.asin(v2.getX()),
+ FastMath.atan2(v2.getY(), v2.getZ())
};
} else if (order == RotationOrder.XYX) {
@@ -731,9 +732,9 @@ public class Rotation implements Seriali
throw new CardanEulerSingularityException(false);
}
return new double[] {
- Math.atan2(v1.getY(), -v1.getZ()),
- Math.acos(v2.getX()),
- Math.atan2(v2.getY(), v2.getZ())
+ FastMath.atan2(v1.getY(), -v1.getZ()),
+ FastMath.acos(v2.getX()),
+ FastMath.atan2(v2.getY(), v2.getZ())
};
} else if (order == RotationOrder.XZX) {
@@ -749,9 +750,9 @@ public class Rotation implements Seriali
throw new CardanEulerSingularityException(false);
}
return new double[] {
- Math.atan2(v1.getZ(), v1.getY()),
- Math.acos(v2.getX()),
- Math.atan2(v2.getZ(), -v2.getY())
+ FastMath.atan2(v1.getZ(), v1.getY()),
+ FastMath.acos(v2.getX()),
+ FastMath.atan2(v2.getZ(), -v2.getY())
};
} else if (order == RotationOrder.YXY) {
@@ -767,9 +768,9 @@ public class Rotation implements Seriali
throw new CardanEulerSingularityException(false);
}
return new double[] {
- Math.atan2(v1.getX(), v1.getZ()),
- Math.acos(v2.getY()),
- Math.atan2(v2.getX(), -v2.getZ())
+ FastMath.atan2(v1.getX(), v1.getZ()),
+ FastMath.acos(v2.getY()),
+ FastMath.atan2(v2.getX(), -v2.getZ())
};
} else if (order == RotationOrder.YZY) {
@@ -785,9 +786,9 @@ public class Rotation implements Seriali
throw new CardanEulerSingularityException(false);
}
return new double[] {
- Math.atan2(v1.getZ(), -v1.getX()),
- Math.acos(v2.getY()),
- Math.atan2(v2.getZ(), v2.getX())
+ FastMath.atan2(v1.getZ(), -v1.getX()),
+ FastMath.acos(v2.getY()),
+ FastMath.atan2(v2.getZ(), v2.getX())
};
} else if (order == RotationOrder.ZXZ) {
@@ -803,9 +804,9 @@ public class Rotation implements Seriali
throw new CardanEulerSingularityException(false);
}
return new double[] {
- Math.atan2(v1.getX(), -v1.getY()),
- Math.acos(v2.getZ()),
- Math.atan2(v2.getX(), v2.getY())
+ FastMath.atan2(v1.getX(), -v1.getY()),
+ FastMath.acos(v2.getZ()),
+ FastMath.atan2(v2.getX(), v2.getY())
};
} else { // last possibility is ZYZ
@@ -821,9 +822,9 @@ public class Rotation implements Seriali
throw new CardanEulerSingularityException(false);
}
return new double[] {
- Math.atan2(v1.getY(), v1.getX()),
- Math.acos(v2.getZ()),
- Math.atan2(v2.getY(), -v2.getX())
+ FastMath.atan2(v1.getY(), v1.getX()),
+ FastMath.acos(v2.getZ()),
+ FastMath.atan2(v2.getY(), -v2.getX())
};
}
@@ -1017,7 +1018,7 @@ public class Rotation implements Seriali
corr20 * corr20 + corr21 * corr21 + corr22 * corr22;
// convergence test
- if (Math.abs(fn1 - fn) <= threshold)
+ if (FastMath.abs(fn1 - fn) <= threshold)
return o;
// prepare next iteration
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/geometry/Vector3D.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/geometry/Vector3D.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/geometry/Vector3D.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/geometry/Vector3D.java Sun Aug 29 21:49:40 2010
@@ -22,6 +22,7 @@ import java.io.Serializable;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.util.MathUtils;
+import org.apache.commons.math.util.FastMath;
/**
* This class implements vectors in a three-dimensional space.
@@ -107,10 +108,10 @@ public class Vector3D
* @see #getDelta()
*/
public Vector3D(double alpha, double delta) {
- double cosDelta = Math.cos(delta);
- this.x = Math.cos(alpha) * cosDelta;
- this.y = Math.sin(alpha) * cosDelta;
- this.z = Math.sin(delta);
+ double cosDelta = FastMath.cos(delta);
+ this.x = FastMath.cos(alpha) * cosDelta;
+ this.y = FastMath.sin(alpha) * cosDelta;
+ this.z = FastMath.sin(delta);
}
/** Multiplicative constructor
@@ -203,14 +204,14 @@ public class Vector3D
* @return L<sub>1</sub> norm for the vector
*/
public double getNorm1() {
- return Math.abs(x) + Math.abs(y) + Math.abs(z);
+ return FastMath.abs(x) + FastMath.abs(y) + FastMath.abs(z);
}
/** Get the L<sub>2</sub> norm for the vector.
* @return euclidian norm for the vector
*/
public double getNorm() {
- return Math.sqrt (x * x + y * y + z * z);
+ return FastMath.sqrt (x * x + y * y + z * z);
}
/** Get the square of the norm for the vector.
@@ -224,7 +225,7 @@ public class Vector3D
* @return L<sub>∞</sub> norm for the vector
*/
public double getNormInf() {
- return Math.max(Math.max(Math.abs(x), Math.abs(y)), Math.abs(z));
+ return FastMath.max(FastMath.max(FastMath.abs(x), FastMath.abs(y)), FastMath.abs(z));
}
/** Get the azimuth of the vector.
@@ -232,7 +233,7 @@ public class Vector3D
* @see #Vector3D(double, double)
*/
public double getAlpha() {
- return Math.atan2(y, x);
+ return FastMath.atan2(y, x);
}
/** Get the elevation of the vector.
@@ -240,7 +241,7 @@ public class Vector3D
* @see #Vector3D(double, double)
*/
public double getDelta() {
- return Math.asin(z / getNorm());
+ return FastMath.asin(z / getNorm());
}
/** Add a vector to the instance.
@@ -312,13 +313,13 @@ public class Vector3D
}
if ((x >= -threshold) && (x <= threshold)) {
- double inverse = 1 / Math.sqrt(y * y + z * z);
+ double inverse = 1 / FastMath.sqrt(y * y + z * z);
return new Vector3D(0, inverse * z, -inverse * y);
} else if ((y >= -threshold) && (y <= threshold)) {
- double inverse = 1 / Math.sqrt(x * x + z * z);
+ double inverse = 1 / FastMath.sqrt(x * x + z * z);
return new Vector3D(-inverse * z, 0, inverse * x);
}
- double inverse = 1 / Math.sqrt(x * x + y * y);
+ double inverse = 1 / FastMath.sqrt(x * x + y * y);
return new Vector3D(inverse * y, -inverse * x, 0);
}
@@ -347,13 +348,13 @@ public class Vector3D
// the vectors are almost aligned, compute using the sine
Vector3D v3 = crossProduct(v1, v2);
if (dot >= 0) {
- return Math.asin(v3.getNorm() / normProduct);
+ return FastMath.asin(v3.getNorm() / normProduct);
}
- return Math.PI - Math.asin(v3.getNorm() / normProduct);
+ return FastMath.PI - FastMath.asin(v3.getNorm() / normProduct);
}
// the vectors are sufficiently separated to use the cosine
- return Math.acos(dot / normProduct);
+ return FastMath.acos(dot / normProduct);
}
@@ -471,9 +472,9 @@ public class Vector3D
* @return the distance between v1 and v2 according to the L<sub>1</sub> norm
*/
public static double distance1(Vector3D v1, Vector3D v2) {
- final double dx = Math.abs(v2.x - v1.x);
- final double dy = Math.abs(v2.y - v1.y);
- final double dz = Math.abs(v2.z - v1.z);
+ final double dx = FastMath.abs(v2.x - v1.x);
+ final double dy = FastMath.abs(v2.y - v1.y);
+ final double dz = FastMath.abs(v2.z - v1.z);
return dx + dy + dz;
}
@@ -489,7 +490,7 @@ public class Vector3D
final double dx = v2.x - v1.x;
final double dy = v2.y - v1.y;
final double dz = v2.z - v1.z;
- return Math.sqrt(dx * dx + dy * dy + dz * dz);
+ return FastMath.sqrt(dx * dx + dy * dy + dz * dz);
}
/** Compute the distance between two vectors according to the L<sub>∞</sub> norm.
@@ -501,10 +502,10 @@ public class Vector3D
* @return the distance between v1 and v2 according to the L<sub>∞</sub> norm
*/
public static double distanceInf(Vector3D v1, Vector3D v2) {
- final double dx = Math.abs(v2.x - v1.x);
- final double dy = Math.abs(v2.y - v1.y);
- final double dz = Math.abs(v2.z - v1.z);
- return Math.max(Math.max(dx, dy), dz);
+ final double dx = FastMath.abs(v2.x - v1.x);
+ final double dy = FastMath.abs(v2.y - v1.y);
+ final double dz = FastMath.abs(v2.z - v1.z);
+ return FastMath.max(FastMath.max(dx, dy), dz);
}
/** Compute the square of the distance between two vectors.
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java Sun Aug 29 21:49:40 2010
@@ -20,6 +20,7 @@ package org.apache.commons.math.linear;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.util.MathUtils;
+import org.apache.commons.math.util.FastMath;
/**
* Basic implementation of RealMatrix methods regardless of the underlying storage.
@@ -213,9 +214,9 @@ public abstract class AbstractRealMatrix
/** {@inheritDoc} */
public void visit(final int row, final int column, final double value) {
- columnSum += Math.abs(value);
+ columnSum += FastMath.abs(value);
if (row == endRow) {
- maxColSum = Math.max(maxColSum, columnSum);
+ maxColSum = FastMath.max(maxColSum, columnSum);
columnSum = 0;
}
}
@@ -249,7 +250,7 @@ public abstract class AbstractRealMatrix
/** {@inheritDoc} */
public double end() {
- return Math.sqrt(sum);
+ return FastMath.sqrt(sum);
}
});
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java?rev=990655&r1=990654&r2=990655&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java Sun Aug 29 21:49:40 2010
@@ -27,6 +27,7 @@ import org.apache.commons.math.analysis.
import org.apache.commons.math.analysis.ComposableFunction;
import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.exception.util.LocalizedFormats;
+import org.apache.commons.math.util.FastMath;
/**
* This class provides default basic implementations for many methods in the
@@ -202,7 +203,7 @@ public abstract class AbstractRealVector
final double diff = e.getValue() - v.getEntry(e.getIndex());
d += diff * diff;
}
- return Math.sqrt(d);
+ return FastMath.sqrt(d);
}
/** {@inheritDoc} */
@@ -214,7 +215,7 @@ public abstract class AbstractRealVector
final double value = e.getValue();
sum += value * value;
}
- return Math.sqrt(sum);
+ return FastMath.sqrt(sum);
}
/** {@inheritDoc} */
@@ -223,7 +224,7 @@ public abstract class AbstractRealVector
Iterator<Entry> it = sparseIterator();
Entry e;
while (it.hasNext() && (e = it.next()) != null) {
- norm += Math.abs(e.getValue());
+ norm += FastMath.abs(e.getValue());
}
return norm;
}
@@ -234,7 +235,7 @@ public abstract class AbstractRealVector
Iterator<Entry> it = sparseIterator();
Entry e;
while (it.hasNext() && (e = it.next()) != null) {
- norm = Math.max(norm, Math.abs(e.getValue()));
+ norm = FastMath.max(norm, FastMath.abs(e.getValue()));
}
return norm;
}
@@ -251,7 +252,7 @@ public abstract class AbstractRealVector
Iterator<Entry> it = iterator();
Entry e;
while (it.hasNext() && (e = it.next()) != null) {
- d += Math.abs(e.getValue() - v.getEntry(e.getIndex()));
+ d += FastMath.abs(e.getValue() - v.getEntry(e.getIndex()));
}
return d;
}
@@ -263,7 +264,7 @@ public abstract class AbstractRealVector
Iterator<Entry> it = iterator();
Entry e;
while (it.hasNext() && (e = it.next()) != null) {
- d += Math.abs(e.getValue() - v[e.getIndex()]);
+ d += FastMath.abs(e.getValue() - v[e.getIndex()]);
}
return d;
}
@@ -275,7 +276,7 @@ public abstract class AbstractRealVector
Iterator<Entry> it = iterator();
Entry e;
while (it.hasNext() && (e = it.next()) != null) {
- d = Math.max(Math.abs(e.getValue() - v.getEntry(e.getIndex())), d);
+ d = FastMath.max(FastMath.abs(e.getValue() - v.getEntry(e.getIndex())), d);
}
return d;
}
@@ -287,7 +288,7 @@ public abstract class AbstractRealVector
Iterator<Entry> it = iterator();
Entry e;
while (it.hasNext() && (e = it.next()) != null) {
- d = Math.max(Math.abs(e.getValue() - v[e.getIndex()]), d);
+ d = FastMath.max(FastMath.abs(e.getValue() - v[e.getIndex()]), d);
}
return d;
}