Fixed about 90 checkstyle errors.

The errors were mainly trailing blanks, missing javadoc, wrong javadoc
parameters, hidden variables ...

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1178235 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2011-10-02 19:43:17 +00:00
parent 76b57cddf3
commit 3ae07f34ab
26 changed files with 217 additions and 165 deletions

View File

@ -49,8 +49,8 @@ public interface Field<T> {
T getOne();
/**
* Returns the runtime class of the FieldElement.
*
* Returns the runtime class of the FieldElement.
*
* @return The {@code Class} object that represents the runtime
* class of this object.
*/

View File

@ -214,23 +214,23 @@ public abstract class UnivariateRealIntegratorImpl implements UnivariateRealInte
*
* @param maxEval Maximum number of evaluations.
* @param f the integrand function
* @param min the min bound for the interval
* @param max the upper bound for the interval
* @param lower the min bound for the interval
* @param upper the upper bound for the interval
* @throws NullArgumentException if {@code f} is {@code null}.
* @throws MathIllegalArgumentException if {@code min >= max}.
*/
protected void setup(final int maxEval,
final UnivariateRealFunction f,
final double min, final double max)
final double lower, final double upper)
throws NullArgumentException, MathIllegalArgumentException {
// Checks.
MathUtils.checkNotNull(f);
UnivariateRealSolverUtils.verifyInterval(min, max);
UnivariateRealSolverUtils.verifyInterval(lower, upper);
// Reset.
this.min = min;
this.max = max;
this.min = lower;
this.max = upper;
function = f;
evaluations.setMaximalCount(maxEval);
evaluations.resetCount();
@ -240,12 +240,12 @@ public abstract class UnivariateRealIntegratorImpl implements UnivariateRealInte
/** {@inheritDoc} */
public double integrate(final int maxEval, final UnivariateRealFunction f,
final double min, final double max)
final double lower, final double upper)
throws TooManyEvaluationsException, MaxCountExceededException,
MathIllegalArgumentException, NullArgumentException {
// Initialization.
setup(maxEval, f, min, max);
setup(maxEval, f, lower, upper);
// Perform computation.
return doIntegrate();

View File

@ -268,7 +268,7 @@ public class PolynomialsUtils {
}
/** Interface for recurrence coefficients generation. */
private static interface RecurrenceCoefficientsGenerator {
private interface RecurrenceCoefficientsGenerator {
/**
* Generate recurrence coefficients.
* @param k highest degree of the polynomials used in the recurrence

View File

@ -272,7 +272,7 @@ public class KolmogorovSmirnovDistributionImpl implements KolmogorovSmirnovDistr
* {@code k, m} and {@code 0 <= h < 1}.
*/
private FieldMatrix<BigFraction> createH(double d)
throws MathArithmeticException {
throws NumberIsTooLargeException, FractionConversionException {
int k = (int) Math.ceil(n * d);

View File

@ -167,7 +167,7 @@ public class BigFraction
* @param value the double value to convert to a fraction.
* @exception MathIllegalArgumentException if value is NaN or infinite
*/
public BigFraction(final double value) throws IllegalArgumentException {
public BigFraction(final double value) throws MathIllegalArgumentException {
if (Double.isNaN(value)) {
throw new MathIllegalArgumentException(LocalizedFormats.NAN_VALUE_CONVERSION);
}

View File

@ -429,7 +429,7 @@ public class BSPTree<S extends Space> {
* difference and symmetric difference (exclusive or).</p>
* @param <S> Type of the space.
*/
public static interface LeafMerger<S extends Space> {
public interface LeafMerger<S extends Space> {
/** Merge a leaf node and a tree node.
* <p>This method is called at the end of a recursive merging

View File

@ -76,8 +76,8 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator {
/** Counter for number of evaluations. */
private Incrementor evaluations;
/** Differential equations to integrate. */
private transient ExpandableStatefulODE equations;
/** Differential expandable to integrate. */
private transient ExpandableStatefulODE expandable;
/** Build an instance.
* @param name name of the method
@ -189,7 +189,7 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator {
* @param equations equations to set
*/
protected void setEquations(final ExpandableStatefulODE equations) {
this.equations = equations;
this.expandable = equations;
}
/** {@inheritDoc} */
@ -204,31 +204,31 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator {
throw new DimensionMismatchException(y.length, equations.getDimension());
}
// prepare expandable stateful equations
final ExpandableStatefulODE expandable = new ExpandableStatefulODE(equations);
expandable.setTime(t0);
expandable.setPrimaryState(y0);
// prepare expandable stateful expandable
final ExpandableStatefulODE expandableODE = new ExpandableStatefulODE(equations);
expandableODE.setTime(t0);
expandableODE.setPrimaryState(y0);
// perform integration
integrate(expandable, t);
integrate(expandableODE, t);
// extract results back from the stateful equations
System.arraycopy(expandable.getPrimaryState(), 0, y, 0, y.length);
return expandable.getTime();
// extract results back from the stateful expandable
System.arraycopy(expandableODE.getPrimaryState(), 0, y, 0, y.length);
return expandableODE.getTime();
}
/** Integrate a set of differential equations up to the given time.
/** Integrate a set of differential expandable up to the given time.
* <p>This method solves an Initial Value Problem (IVP).</p>
* <p>The set of differential equations is composed of a main set, which
* can be extended by some sets of secondary equations. The set of
* equations must be already set up with initial time and partial states.
* <p>The set of differential expandable is composed of a main set, which
* can be extended by some sets of secondary expandable. The set of
* expandable must be already set up with initial time and partial states.
* At integration completion, the final time and partial states will be
* available in the same object.</p>
* <p>Since this method stores some internal state variables made
* available in its public interface during integration ({@link
* #getCurrentSignedStepsize()}), it is <em>not</em> thread-safe.</p>
* @param equations complete set of differential equations to integrate
* @param equations complete set of differential expandable to integrate
* @param t target time for the integration
* (can be set to a value smaller than <code>t0</code> for backward integration)
* @throws MathIllegalStateException if the integrator cannot perform integration
@ -247,7 +247,7 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator {
public void computeDerivatives(final double t, final double[] y, final double[] yDot)
throws MaxCountExceededException {
evaluations.incrementCount();
equations.computeDerivatives(t, y, yDot);
expandable.computeDerivatives(t, y, yDot);
}
/** Set the stateInitialized flag.
@ -374,6 +374,7 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator {
}
/** Check the integration span.
* @param equations set of differential equations
* @param t target time for the integration
* @exception NumberIsTooSmallException if integration span is too small
*/

View File

@ -37,10 +37,10 @@ public class EquationsMapper implements Serializable {
private static final long serialVersionUID = 20110925L;
/** Index of the first equation element in complete state arrays. */
final int firstIndex;
private final int firstIndex;
/** Dimension of the secondary state parameters. */
final int dimension;
private final int dimension;
/** simple constructor.
* @param firstIndex index of the first equation element in complete state arrays

View File

@ -297,7 +297,6 @@ public class ExpandableStatefulODE {
/** Components of the compound stateful ODE. */
private static class SecondaryComponent {
/** Secondary differential equation. */
private final SecondaryEquations equation;
@ -312,7 +311,7 @@ public class ExpandableStatefulODE {
/** Simple constructor.
* @param equation secondary differential equation
* @param first index index to use for the first element in the complete arrays
* @param firstIndex index to use for the first element in the complete arrays
*/
public SecondaryComponent(final SecondaryEquations equation, final int firstIndex) {
final int n = equation.getDimension();

View File

@ -154,6 +154,7 @@ public class JacobianMatrices {
}
/** Register the variational equations for the Jacobians matrices to the expandable set.
* @param expandable expandable set into which variational equations should be registered
* @exception MathIllegalArgumentException if the primary set of the expandable set does
* not match the one used to build the instance
* @see ExpandableStatefulODE#addSecondaryEquations(SecondaryEquations)
@ -183,10 +184,10 @@ public class JacobianMatrices {
}
/** Add a parameter Jacobian provider.
* @param pode the parameterized ODE to compute the parameter Jacobian matrix using finite differences
* @param parameterizedOde the parameterized ODE to compute the parameter Jacobian matrix using finite differences
*/
public void setParameterizedODE(final ParameterizedODE pode) {
this.pode = pode;
public void setParameterizedODE(final ParameterizedODE parameterizedOde) {
this.pode = parameterizedOde;
dirtyParameter = true;
}
@ -227,10 +228,10 @@ public class JacobianMatrices {
* matrix with respect to state is set to identity.
* </p>
* @param dYdY0 initial Jacobian matrix w.r.t. state
* @exception IllegalArgumentException if matrix dimensions are incorrect
* @exception DimensionMismatchException if matrix dimensions are incorrect
*/
public void setInitialMainStateJacobian(final double[][] dYdY0)
throws MathIllegalArgumentException {
throws DimensionMismatchException {
// Check dimensions
checkDimension(stateDim, dYdY0);
@ -289,16 +290,16 @@ public class JacobianMatrices {
// get current state for this set of equations from the expandable fode
double[] p = efode.getSecondaryState(index);
int index = 0;
int j = 0;
for (int i = 0; i < stateDim; i++) {
System.arraycopy(p, index, dYdY0[i], 0, stateDim);
index += stateDim;
System.arraycopy(p, j, dYdY0[i], 0, stateDim);
j += stateDim;
}
}
/** Get the current value of the Jacobian matrix with respect to one parameter.
* @param pName name of the parameter for the computed Jacobian matrix
* @param pName name of the parameter for the computed Jacobian matrix
* @param dYdP current Jacobian matrix with respect to the named parameter
*/
public void getCurrentParameterJacobian(String pName, final double[] dYdP) {
@ -306,13 +307,13 @@ public class JacobianMatrices {
// get current state for this set of equations from the expandable fode
double[] p = efode.getSecondaryState(index);
int index = stateDim * stateDim;
int i = stateDim * stateDim;
for (ParameterConfiguration param: selectedParameters) {
if (param.getParameterName().equals(pName)) {
System.arraycopy(p, index, dYdP, 0, stateDim);
break;
System.arraycopy(p, i, dYdP, 0, stateDim);
return;
}
index += stateDim;
i += stateDim;
}
}

View File

@ -19,7 +19,7 @@ package org.apache.commons.math.ode;
/** Interface expanding {@link FirstOrderDifferentialEquations first order
* differential equations} in order to compute exactly the main state jacobian
* matrix for {@link JacobianMatrices partial derivatives equations}.
*
*
* @version $Id$
* @since 3.0
*/

View File

@ -294,7 +294,7 @@ public abstract class MultistepIntegrator extends AdaptiveStepsizeIntegrator {
}
/** Transformer used to convert the first step to Nordsieck representation. */
public static interface NordsieckTransformer {
public interface NordsieckTransformer {
/** Initialize the high order scaled derivatives at step start.
* @param h step size to use for scaling
* @param t first steps times

View File

@ -19,8 +19,8 @@ package org.apache.commons.math.ode;
import java.io.Serializable;
/** Simple container pairing a parameter name with a step in order to compute
* the associated jacobian matrix by finite difference.
*
* the associated Jacobian matrix by finite difference.
*
* @version $Id$
* @since 3.0
*/

View File

@ -20,7 +20,7 @@ import org.apache.commons.math.exception.MathIllegalArgumentException;
/** Interface to compute exactly Jacobian matrix for some parameter
* when computing {@link JacobianMatrices partial derivatives equations}.
*
*
* @version $Id$
* @since 3.0
*/

View File

@ -22,7 +22,7 @@ import java.util.Map;
/** Wrapper class to compute Jacobian matrices by finite differences for ODE
* which do not compute them by themselves.
*
*
* @version $Id$
* @since 3.0
*/
@ -85,7 +85,7 @@ class ParameterJacobianWrapper implements ParameterJacobianProvider {
dFdP[i] = (tmpDot[i] - yDot[i]) / hP;
}
pode.setParameter(paramName, p);
}
}

View File

@ -18,7 +18,7 @@ package org.apache.commons.math.ode;
/** Interface to compute by finite difference Jacobian matrix for some parameter
* when computing {@link JacobianMatrices partial derivatives equations}.
*
*
* @version $Id$
* @since 3.0
*/

View File

@ -22,10 +22,9 @@ import java.util.Collection;
import org.apache.commons.math.exception.MathIllegalArgumentException;
import org.apache.commons.math.exception.util.LocalizedFormats;
/** Wrapper class enabling {@link FirstOrderDifferentialEquations basic simple}
* ODE instances to be used when processing {@link JacobianMatrices}.
*
*
* @version $Id$
* @since 3.0
*/

View File

@ -24,7 +24,6 @@ import org.apache.commons.math.exception.NumberIsTooSmallException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.ode.AbstractIntegrator;
import org.apache.commons.math.ode.ExpandableStatefulODE;
import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
import org.apache.commons.math.util.FastMath;
/**
@ -44,7 +43,8 @@ import org.apache.commons.math.util.FastMath;
* </p>
* <p>
* If the Ordinary Differential Equations is an {@link ExpandableStatefulODE
* extended ODE} rather than a {@link FirstOrderDifferentialEquations basic ODE}, then
* extended ODE} rather than a {@link
* org.apache.commons.math.ode.FirstOrderDifferentialEquations basic ODE}, then
* <em>only</em> the {@link ExpandableStatefulODE#getPrimaryState() primary part}
* of the state vector is used for stepsize control, not the complete state vector.
* </p>
@ -316,7 +316,7 @@ public abstract class AdaptiveStepsizeIntegrator
* @exception NumberIsTooSmallException if the step is too small and acceptSmall is false
*/
protected double filterStep(final double h, final boolean forward, final boolean acceptSmall)
throws MathIllegalArgumentException {
throws NumberIsTooSmallException {
double filteredH = h;
if (FastMath.abs(h) < minStep) {

View File

@ -433,14 +433,9 @@ class DormandPrince853StepInterpolator
public void writeExternal(final ObjectOutput out)
throws IOException {
try {
// save the local attributes
finalizeStep();
} catch (Exception e) {
IOException ioe = new IOException(e.getLocalizedMessage());
ioe.initCause(e);
throw ioe;
}
// save the local attributes
finalizeStep();
final int dimension = (currentState == null) ? -1 : currentState.length;
out.writeInt(dimension);
for (int i = 0; i < dimension; ++i) {

View File

@ -121,7 +121,7 @@ public abstract class AbstractStepInterpolator
this.dirtyState = true;
primaryMapper = null;
secondaryMappers = null;
allocateInterpolatedArrays(-1, null, null);
allocateInterpolatedArrays(-1);
}
/** Simple constructor.
@ -147,7 +147,7 @@ public abstract class AbstractStepInterpolator
this.dirtyState = true;
this.primaryMapper = primaryMapper;
this.secondaryMappers = (secondaryMappers == null) ? null : secondaryMappers.clone();
allocateInterpolatedArrays(y.length, primaryMapper, secondaryMappers);
allocateInterpolatedArrays(y.length);
}
@ -178,8 +178,10 @@ public abstract class AbstractStepInterpolator
interpolatedTime = interpolator.interpolatedTime;
if (interpolator.currentState == null) {
currentState = null;
allocateInterpolatedArrays(-1, null, null);
currentState = null;
primaryMapper = null;
secondaryMappers = null;
allocateInterpolatedArrays(-1);
} else {
currentState = interpolator.currentState.clone();
interpolatedState = interpolator.interpolatedState.clone();
@ -205,12 +207,8 @@ public abstract class AbstractStepInterpolator
/** Allocate the various interpolated states arrays.
* @param dimension total dimension (negative if arrays should be set to null)
* @param primaryMapper equations mapper for the primary equations set
* @param secondaryMappers equations mappers for the secondary equations sets
*/
private void allocateInterpolatedArrays(final int dimension,
final EquationsMapper primaryMapper,
final EquationsMapper[] secondaryMappers) {
private void allocateInterpolatedArrays(final int dimension) {
if (dimension < 0) {
interpolatedState = null;
interpolatedDerivatives = null;
@ -240,12 +238,12 @@ public abstract class AbstractStepInterpolator
/** Reinitialize the instance
* @param y reference to the integrator array holding the state at the end of the step
* @param isForward integration direction indicator
* @param primaryMapper equations mapper for the primary equations set
* @param secondaryMappers equations mappers for the secondary equations sets
* @param primary equations mapper for the primary equations set
* @param secondary equations mappers for the secondary equations sets
*/
protected void reinitialize(final double[] y, final boolean isForward,
final EquationsMapper primaryMapper,
final EquationsMapper[] secondaryMappers) {
final EquationsMapper primary,
final EquationsMapper[] secondary) {
globalPreviousTime = Double.NaN;
globalCurrentTime = Double.NaN;
@ -257,9 +255,9 @@ public abstract class AbstractStepInterpolator
finalized = false;
this.forward = isForward;
this.dirtyState = true;
this.primaryMapper = primaryMapper;
this.secondaryMappers = secondaryMappers.clone();
allocateInterpolatedArrays(y.length, primaryMapper, secondaryMappers);
this.primaryMapper = primary;
this.secondaryMappers = secondary.clone();
allocateInterpolatedArrays(y.length);
}
@ -540,13 +538,7 @@ public abstract class AbstractStepInterpolator
// it will be recomputed as needed after reading
// finalize the step (and don't bother saving the now true flag)
try {
finalizeStep();
} catch (Exception e) {
IOException ioe = new IOException(e.getLocalizedMessage());
ioe.initCause(e);
throw ioe;
}
finalizeStep();
}
@ -558,6 +550,8 @@ public abstract class AbstractStepInterpolator
* @param in stream where to read the state from
* @return interpolated time to be set later by the caller
* @exception IOException in case of read error
* @exception ClassNotFoundException if an equation mapper class
* cannot be found
*/
protected double readBaseExternal(final ObjectInput in)
throws IOException, ClassNotFoundException {
@ -587,7 +581,7 @@ public abstract class AbstractStepInterpolator
// we do NOT handle the interpolated time and state here
interpolatedTime = Double.NaN;
allocateInterpolatedArrays(dimension, primaryMapper, secondaryMappers);
allocateInterpolatedArrays(dimension);
finalized = true;

View File

@ -42,32 +42,34 @@ public class StorelessBivariateCovariance {
private boolean biasCorrected = true;
public StorelessBivariateCovariance(){
public StorelessBivariateCovariance() {
}
public StorelessBivariateCovariance(boolean biasCorrected){
public StorelessBivariateCovariance(boolean biasCorrected) {
this.biasCorrected = biasCorrected;
}
public void increment(double x, double y){
public void increment(double x, double y) {
n++;
deltaX = x - meanX;
deltaY = y - meanY;
meanX += deltaX / n;
meanY += deltaY / n;
covarianceNumerator += ((n-1.0) / n) * deltaX * deltaY;
covarianceNumerator += ((n - 1.0) / n) * deltaX * deltaY;
}
public double getN(){
public double getN() {
return n;
}
public double getResult()throws IllegalArgumentException{
if (n < 2) throw new MathIllegalArgumentException(
LocalizedFormats.INSUFFICIENT_DIMENSION, n, 2);
if(biasCorrected){
public double getResult() throws IllegalArgumentException {
if (n < 2) {
throw new MathIllegalArgumentException(LocalizedFormats.INSUFFICIENT_DIMENSION,
n, 2);
}
if (biasCorrected) {
return covarianceNumerator / (n - 1d);
}else{
} else {
return covarianceNumerator / n;
}
}

View File

@ -109,9 +109,12 @@ public class StorelessCovariance extends Covariance {
* This {@link Covariance} method is not supported by StorelessCovariance, since
* the number of bivariate observations does not have to be the same for different
* pairs of covariates - i.e., N as defined in {@link Covariance#getN()} is undefined.
* @return nothing as this implementation always throws a {@link MathUnsupportedOperationException}
* @throws MathUnsupportedOperationException in all cases
*/
@Override
public int getN() {
public int getN()
throws MathUnsupportedOperationException {
throw new MathUnsupportedOperationException();
}

View File

@ -24,20 +24,20 @@
* <code>/&lowast; evaluation approach &lowast;/<br/>
* double[] values = new double[] { 1, 2, 3, 4, 5 };<br/>
* <span style="font-weight: bold;">UnivariateStatistic stat = new Mean();</span><br/>
* System.out.println("mean = " + <span style="font-weight: bold;">stat.evaluate(values)</span>);<br/>
* out.println("mean = " + <span style="font-weight: bold;">stat.evaluate(values)</span>);<br/>
* </code>
*
* <h4>StorelessUnivariateStatistic:</h4>
* <code>/&lowast; incremental approach &lowast;/<br/>
* double[] values = new double[] { 1, 2, 3, 4, 5 };<br/>
* <span style="font-weight: bold;">StorelessUnivariateStatistic stat = new Mean();</span><br/>
* System.out.println("mean before adding a value is NaN = " + <span style="font-weight: bold;">stat.getResult()</span>);<br/>
* out.println("mean before adding a value is NaN = " + <span style="font-weight: bold;">stat.getResult()</span>);<br/>
* for (int i = 0; i &lt; values.length; i++) {<br/>
* &nbsp;&nbsp;&nbsp; <span style="font-weight: bold;">stat.increment(values[i]);</span><br/>
* &nbsp;&nbsp;&nbsp; System.out.println("current mean = " + <span style="font-weight: bold;">stat2.getResult()</span>);<br/>
* &nbsp;&nbsp;&nbsp; out.println("current mean = " + <span style="font-weight: bold;">stat2.getResult()</span>);<br/>
* }<br/>
* <span style="font-weight: bold;"> stat.clear();</span><br/>
* System.out.println("mean after clear is NaN = " + <span style="font-weight: bold;">stat.getResult()</span>);
* out.println("mean after clear is NaN = " + <span style="font-weight: bold;">stat.getResult()</span>);
* </code>
*
*/

View File

@ -16,6 +16,8 @@
*/
package org.apache.commons.math.util;
import java.io.PrintStream;
/**
* Faster, more accurate, portable alternative to {@link Math} and
* {@link StrictMath} for large scale computation.
@ -30,7 +32,7 @@ package org.apache.commons.math.util;
* FastMath speed is achieved by relying heavily on optimizing compilers
* to native code present in many JVMs today and use of large tables.
* The larger tables are lazily initialised on first use, so that the setup
* time does not penalise methods that don't need them.
* time does not penalise methods that don't need them.
* </p>
* <p>
* Note that FastMath is
@ -83,6 +85,7 @@ public class FastMath {
/** Napier's constant e, base of the natural logarithm. */
public static final double E = 2850325.0 / 1048576.0 + 8.254840070411028747e-8;
/** Constant 2<sup>10</sup>. */
private static final int TWO_POWER_10 = 1024;
/** Indicator for tables initialization.
@ -127,7 +130,7 @@ public class FastMath {
/** Sine, Cosine, Tangent tables are for 0, 1/8, 2/8, ... 13/8 = PI/2 approx. */
private static final int SINE_TABLE_LEN = 14;
/** Sine table (high bits). */
private static final double SINE_TABLE_A[] =
{
@ -300,7 +303,7 @@ public class FastMath {
/** 2^52 - double numbers this large must be integral (no fraction) or NaN or Infinite */
private static final double TWO_POWER_52 = 4503599627370496.0;
/**
* Private Constructor
*/
@ -345,7 +348,7 @@ public class FastMath {
// cosh[z] = (exp(z) + exp(-z))/2
// for numbers with magnitude 20 or so,
// for numbers with magnitude 20 or so,
// exp(-z) can be ignored in comparison with exp(z)
if (x > 20.0) {
@ -404,10 +407,10 @@ public class FastMath {
}
// sinh[z] = (exp(z) - exp(-z) / 2
// for values of z larger than about 20,
// for values of z larger than about 20,
// exp(-z) can be ignored in comparison with exp(z)
if (x > 20.0) {
return exp(x)/2.0;
}
@ -519,10 +522,10 @@ public class FastMath {
return x;
}
// tanh[z] = sinh[z] / cosh[z]
// tanh[z] = sinh[z] / cosh[z]
// = (exp(z) - exp(-z)) / (exp(z) + exp(-z))
// = (exp(2x) - 1) / (exp(2x) + 1)
// for magnitude > 20, sinh[z] == cosh[z] in double precision
if (x > 20.0) {
@ -3630,20 +3633,24 @@ public class FastMath {
return ((Float.floatToIntBits(f) >>> 23) & 0xff) - 127;
}
// print out contents of arrays, and check the length
// used to generate the preset arrays originally
public static void main(String[] a){
FastMathCalc.printarray("EXP_INT_TABLE_A", EXP_INT_TABLE_LEN, ExpIntTable.EXP_INT_TABLE_A);
FastMathCalc.printarray("EXP_INT_TABLE_B", EXP_INT_TABLE_LEN, ExpIntTable.EXP_INT_TABLE_B);
FastMathCalc.printarray("EXP_FRAC_TABLE_A", EXP_FRAC_TABLE_LEN, ExpFracTable.EXP_FRAC_TABLE_A);
FastMathCalc.printarray("EXP_FRAC_TABLE_B", EXP_FRAC_TABLE_LEN, ExpFracTable.EXP_FRAC_TABLE_B);
FastMathCalc.printarray("LN_MANT",LN_MANT_LEN, lnMant.LN_MANT);
FastMathCalc.printarray("SINE_TABLE_A", SINE_TABLE_LEN, SINE_TABLE_A);
FastMathCalc.printarray("SINE_TABLE_B", SINE_TABLE_LEN, SINE_TABLE_B);
FastMathCalc.printarray("COSINE_TABLE_A", SINE_TABLE_LEN, COSINE_TABLE_A);
FastMathCalc.printarray("COSINE_TABLE_B", SINE_TABLE_LEN, COSINE_TABLE_B);
FastMathCalc.printarray("TANGENT_TABLE_A", SINE_TABLE_LEN, TANGENT_TABLE_A);
FastMathCalc.printarray("TANGENT_TABLE_B", SINE_TABLE_LEN, TANGENT_TABLE_B);
/**
* Print out contents of arrays, and check the length.
* <p>used to generate the preset arrays originally.</p>
* @param a unused
*/
public static void main(String[] a) {
PrintStream out = System.out;
FastMathCalc.printarray(out, "EXP_INT_TABLE_A", EXP_INT_TABLE_LEN, ExpIntTable.EXP_INT_TABLE_A);
FastMathCalc.printarray(out, "EXP_INT_TABLE_B", EXP_INT_TABLE_LEN, ExpIntTable.EXP_INT_TABLE_B);
FastMathCalc.printarray(out, "EXP_FRAC_TABLE_A", EXP_FRAC_TABLE_LEN, ExpFracTable.EXP_FRAC_TABLE_A);
FastMathCalc.printarray(out, "EXP_FRAC_TABLE_B", EXP_FRAC_TABLE_LEN, ExpFracTable.EXP_FRAC_TABLE_B);
FastMathCalc.printarray(out, "LN_MANT",LN_MANT_LEN, lnMant.LN_MANT);
FastMathCalc.printarray(out, "SINE_TABLE_A", SINE_TABLE_LEN, SINE_TABLE_A);
FastMathCalc.printarray(out, "SINE_TABLE_B", SINE_TABLE_LEN, SINE_TABLE_B);
FastMathCalc.printarray(out, "COSINE_TABLE_A", SINE_TABLE_LEN, COSINE_TABLE_A);
FastMathCalc.printarray(out, "COSINE_TABLE_B", SINE_TABLE_LEN, COSINE_TABLE_B);
FastMathCalc.printarray(out, "TANGENT_TABLE_A", SINE_TABLE_LEN, TANGENT_TABLE_A);
FastMathCalc.printarray(out, "TANGENT_TABLE_B", SINE_TABLE_LEN, TANGENT_TABLE_B);
}
@ -3656,7 +3663,7 @@ public class FastMath {
/** Length of the array of integer exponentials. */
static final int EXP_INT_TABLE_LEN = EXP_INT_TABLE_MAX_INDEX * 2;
// Enclose large data table in nested static class so it's only loaded on first access
/** Enclose large data table in nested static class so it's only loaded on first access. */
private static class ExpIntTable {
/** Exponential evaluated at integer values,
* exp(x) = expIntTableA[x + EXP_INT_TABLE_MAX_INDEX] + expIntTableB[x+EXP_INT_TABLE_MAX_INDEX].
@ -6702,9 +6709,10 @@ public class FastMath {
}
}
/** Exponential fractions table length. */
static final int EXP_FRAC_TABLE_LEN = TWO_POWER_10 + 1; // 0, 1/1024, ... 1024/1024
// Enclose large data table in nested static class so it's only loaded on first access
/** Enclose large data table in nested static class so it's only loaded on first access. */
private static class ExpFracTable {
/** Exponential over the range of 0 - 1 in increments of 2^-10
* exp(x/1024) = expFracTableA[x] + expFracTableB[x].
@ -8793,9 +8801,10 @@ public class FastMath {
}
}
/** Logarithm table length. */
static final int LN_MANT_LEN = TWO_POWER_10; // (see LN_MANT comment below)
// Enclose large data table in nested static class so it's only loaded on first access
/** Enclose large data table in nested static class so it's only loaded on first access. */
private static class lnMant {
/** Extended precision logarithm table over the range 1 - 2 in increments of 2^-10. */
private static final double[][] LN_MANT;
@ -8812,7 +8821,7 @@ public class FastMath {
} else if (LOAD_RESOURCES) {
LN_MANT = FastMathResources.loadLnMant();
} else {
LN_MANT = new double[][] {
LN_MANT = new double[][] {
{+0.0d, +0.0d, }, // 0
{+9.760860120877624E-4d, -3.903230345984362E-11d, }, // 1
{+0.0019512202125042677d, -8.124251825289188E-11d, }, // 2

View File

@ -6,20 +6,24 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.commons.math.util;
import java.io.PrintStream;
import org.apache.commons.math.exception.DimensionMismatchException;
/** Class used to compute the classical functions tables.
* @version $Id$
* @since 3.0
*/
class FastMathCalc {
/**
@ -29,9 +33,9 @@ class FastMathCalc {
private static final long HEX_40000000 = 0x40000000L; // 1073741824L
/** Factorial table, for Taylor series expansions. 0!, 1!, 2!, ... 19! */
private static final double FACT[] = new double[]
private static final double FACT[] = new double[]
{
+1.0d, // 0
+1.0d, // 0
+1.0d, // 1
+2.0d, // 2
+6.0d, // 3
@ -73,17 +77,31 @@ class FastMathCalc {
{0.14982303977012634, 1.225743062930824E-8},
};
/** Table start declaration. */
private static final String TABLE_START_DECL = " {";
/** Table end declaration. */
private static final String TABLE_END_DECL = " };";
/**
* Private Constructor.
*/
private FastMathCalc() {
}
/** Build the sine and cosine tables.
* @param SINE_TABLE_A
* @param SINE_TABLE_B
* @param COSINE_TABLE_A
* @param COSINE_TABLE_B
* @param SINE_TABLE_LEN
* @param TANGENT_TABLE_A
* @param TANGENT_TABLE_B
* @param SINE_TABLE_A table of the most significant part of the sines
* @param SINE_TABLE_B table of the least significant part of the sines
* @param COSINE_TABLE_A table of the most significant part of the cosines
* @param COSINE_TABLE_B table of the most significant part of the cosines
* @param SINE_TABLE_LEN length of the tables
* @param TANGENT_TABLE_A table of the most significant part of the tangents
* @param TANGENT_TABLE_B table of the most significant part of the tangents
*/
@SuppressWarnings("unused")
private static void buildSinCosTables(double[] SINE_TABLE_A, double[] SINE_TABLE_B, double[] COSINE_TABLE_A, double[] COSINE_TABLE_B, int SINE_TABLE_LEN, double[] TANGENT_TABLE_A, double[] TANGENT_TABLE_B) {
private static void buildSinCosTables(double[] SINE_TABLE_A, double[] SINE_TABLE_B,
double[] COSINE_TABLE_A, double[] COSINE_TABLE_B,
int SINE_TABLE_LEN, double[] TANGENT_TABLE_A, double[] TANGENT_TABLE_B) {
final double result[] = new double[2];
/* Use taylor series for 0 <= x <= 6/8 */
@ -574,34 +592,65 @@ class FastMathCalc {
}
static void printarray(String string, int expectedLen, double[][] array2d) {
System.out.println(string);
/**
* Print an array.
* @param out text output stream where output should be printed
* @param name array name
* @param expectedLen expected length of the array
* @param array2d array data
*/
static void printarray(PrintStream out, String name, int expectedLen, double[][] array2d) {
out.println(name);
checkLen(expectedLen, array2d.length);
System.out.println(" { ");
out.println(TABLE_START_DECL + " ");
int i = 0;
for(double array[] : array2d) {
System.out.print(" {");
out.print(" {");
for(double d : array) { // assume inner array has very few entries
String ds = d >= 0 ? "+"+Double.toString(d)+"d," : Double.toString(d)+"d,";
System.out.printf("%-25.25s",ds); // multiple entries per line
out.printf("%-25.25s", format(d)); // multiple entries per line
}
System.out.println("}, // "+i++);
out.println("}, // " + i++);
}
System.out.println(" };");
out.println(TABLE_END_DECL);
}
static void printarray(String string, int expectedLen, double[] array) {
System.out.println(string+"=");
/**
* Print an array.
* @param out text output stream where output should be printed
* @param name array name
* @param expectedLen expected length of the array
* @param array array data
*/
static void printarray(PrintStream out, String name, int expectedLen, double[] array) {
out.println(name + "=");
checkLen(expectedLen, array.length);
System.out.println(" {");
out.println(TABLE_START_DECL);
for(double d : array){
String ds = d!=d ? "Double.NaN," : d >= 0 ? "+"+Double.toString(d)+"d," : Double.toString(d)+"d,";
System.out.printf(" %s%n",ds); // one entry per line
out.printf(" %s%n", format(d)); // one entry per line
}
System.out.println(" };");
out.println(TABLE_END_DECL);
}
private static void checkLen(int expectedLen, int actual) {
/** Format a double.
* @param d double number to format
* @return formatted number
*/
static String format(double d) {
if (d != d) {
return "Double.NaN,";
} else {
return ((d >= 0) ? "+" : "") + Double.toString(d) + "d,";
}
}
/**
* Check two lengths are equal.
* @param expectedLen expected length
* @param actual actual length
* @exception DimensionMismatchException if the two lengths are not equal
*/
private static void checkLen(int expectedLen, int actual)
throws DimensionMismatchException {
if (expectedLen != actual) {
throw new DimensionMismatchException(actual, expectedLen);
}

View File

@ -115,9 +115,9 @@ public class DummyStepInterpolatorTest {
try {
oos.writeObject(interpolator);
Assert.fail("an exception should have been thrown");
} catch (IOException ioe) {
} catch (MathIllegalStateException mise) {
// expected behavior
Assert.assertEquals(0, ioe.getMessage().length());
Assert.assertEquals(0, mise.getMessage().length());
}
}