You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2021/05/31 22:42:14 UTC
[commons-math] branch master updated: Create module
"commons-math-legacy-core" for holding functionality needed by many
"legacy" modules.
This is an automated email from the ASF dual-hosted git repository.
erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git
The following commit(s) were added to refs/heads/master by this push:
new e85e8b5 Create module "commons-math-legacy-core" for holding functionality needed by many "legacy" modules.
e85e8b5 is described below
commit e85e8b53f22d6b470492862a67f39068117bd175
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Tue Jun 1 00:26:35 2021 +0200
Create module "commons-math-legacy-core" for holding functionality needed by many "legacy" modules.
"FastMath" (renamed "AccurateMath") and related classes moved to "o.a.c.m.legacy.core.jdkmath".
---
commons-math-examples/pom.xml | 2 +-
commons-math-legacy-core/LICENCE | 457 ++++++++++++
commons-math-legacy-core/NOTICE | 9 +
commons-math-legacy-core/pom.xml | 74 ++
.../apache/commons/math4/legacy/core}/Field.java | 2 +-
.../commons/math4/legacy/core}/FieldElement.java | 2 +-
.../commons/math4/legacy/core}/MathArrays.java | 18 +-
.../math4/legacy/core}/RealFieldElement.java | 2 +-
.../apache/commons/math4/legacy/core}/dfp/Dfp.java | 13 +-
.../commons/math4/legacy/core}/dfp/DfpDec.java | 2 +-
.../commons/math4/legacy/core}/dfp/DfpField.java | 6 +-
.../commons/math4/legacy/core}/dfp/DfpMath.java | 2 +-
.../math4/legacy/core/dfp/package-info.java | 88 +++
.../math4/legacy/core/jdkmath/AccurateMath.java | 104 +--
.../legacy/core/jdkmath/AccurateMath.java.bak | 102 +--
.../legacy/core/jdkmath/AccurateMathCalc.java | 6 +-
.../legacy/core/jdkmath/AccurateMathCalc.java.bak | 4 +-
.../core/jdkmath/AccurateMathLiteralArrays.java | 8 +-
.../jdkmath/AccurateMathLiteralArrays.java.bak | 6 +-
.../core}/ExtendedFieldElementAbstractTest.java | 86 +--
.../commons/math4/legacy/core}/MathArraysTest.java | 98 +--
.../commons/math4/legacy/core}/dfp/Decimal10.java | 2 +-
.../commons/math4/legacy/core}/dfp/DfpDecTest.java | 2 +-
.../math4/legacy/core}/dfp/DfpMathTest.java | 2 +-
.../commons/math4/legacy/core}/dfp/DfpTest.java | 10 +-
.../commons/math4/legacy/core/dfp/DfpTest.java.bak | 2 +-
.../jdkmath/AccurateMathStrictComparisonTest.java | 20 +-
.../AccurateMathStrictComparisonTest.java.bak | 18 +-
.../legacy/core/jdkmath/AccurateMathTest.java | 794 ++++++++++-----------
.../legacy/core/jdkmath/AccurateMathTest.java.bak | 776 ++++++++++----------
commons-math-legacy/pom.xml | 4 +-
.../analysis/RealFieldUnivariateFunction.java | 2 +-
.../analysis/differentiation/DSCompiler.java | 94 +--
.../differentiation/DerivativeStructure.java | 30 +-
.../FiniteDifferencesDifferentiator.java | 10 +-
.../analysis/differentiation/SparseGradient.java | 90 +--
.../math4/legacy/analysis/function/Abs.java | 4 +-
.../math4/legacy/analysis/function/Acos.java | 4 +-
.../math4/legacy/analysis/function/Acosh.java | 4 +-
.../math4/legacy/analysis/function/Asin.java | 4 +-
.../math4/legacy/analysis/function/Asinh.java | 4 +-
.../math4/legacy/analysis/function/Atan.java | 4 +-
.../math4/legacy/analysis/function/Atan2.java | 4 +-
.../math4/legacy/analysis/function/Atanh.java | 4 +-
.../math4/legacy/analysis/function/Cbrt.java | 4 +-
.../math4/legacy/analysis/function/Ceil.java | 4 +-
.../math4/legacy/analysis/function/Cos.java | 4 +-
.../math4/legacy/analysis/function/Cosh.java | 4 +-
.../math4/legacy/analysis/function/Exp.java | 4 +-
.../math4/legacy/analysis/function/Expm1.java | 4 +-
.../math4/legacy/analysis/function/Floor.java | 4 +-
.../math4/legacy/analysis/function/Gaussian.java | 8 +-
.../analysis/function/HarmonicOscillator.java | 10 +-
.../math4/legacy/analysis/function/Log.java | 4 +-
.../math4/legacy/analysis/function/Log10.java | 4 +-
.../math4/legacy/analysis/function/Log1p.java | 4 +-
.../math4/legacy/analysis/function/Logistic.java | 10 +-
.../math4/legacy/analysis/function/Logit.java | 6 +-
.../math4/legacy/analysis/function/Max.java | 4 +-
.../math4/legacy/analysis/function/Min.java | 4 +-
.../math4/legacy/analysis/function/Pow.java | 4 +-
.../math4/legacy/analysis/function/Power.java | 4 +-
.../math4/legacy/analysis/function/Rint.java | 4 +-
.../math4/legacy/analysis/function/Sigmoid.java | 8 +-
.../math4/legacy/analysis/function/Signum.java | 4 +-
.../math4/legacy/analysis/function/Sin.java | 4 +-
.../math4/legacy/analysis/function/Sinc.java | 20 +-
.../math4/legacy/analysis/function/Sinh.java | 4 +-
.../math4/legacy/analysis/function/Sqrt.java | 4 +-
.../legacy/analysis/function/StepFunction.java | 2 +-
.../math4/legacy/analysis/function/Tan.java | 4 +-
.../math4/legacy/analysis/function/Tanh.java | 4 +-
.../math4/legacy/analysis/function/Ulp.java | 4 +-
.../IterativeLegendreGaussIntegrator.java | 12 +-
.../analysis/integration/MidPointIntegrator.java | 8 +-
.../analysis/integration/RombergIntegrator.java | 6 +-
.../analysis/integration/SimpsonIntegrator.java | 6 +-
.../analysis/integration/TrapezoidIntegrator.java | 6 +-
.../integration/gauss/GaussIntegrator.java | 2 +-
.../integration/gauss/HermiteRuleFactory.java | 16 +-
.../interpolation/AkimaSplineInterpolator.java | 8 +-
.../BicubicInterpolatingFunction.java | 2 +-
.../interpolation/BicubicInterpolator.java | 2 +-
.../interpolation/FieldHermiteInterpolator.java | 4 +-
.../interpolation/InterpolatingMicrosphere.java | 8 +-
.../interpolation/InterpolatingMicrosphere2D.java | 6 +-
.../analysis/interpolation/LinearInterpolator.java | 2 +-
.../analysis/interpolation/LoessInterpolator.java | 14 +-
...iecewiseBicubicSplineInterpolatingFunction.java | 2 +-
.../PiecewiseBicubicSplineInterpolator.java | 2 +-
.../analysis/interpolation/SplineInterpolator.java | 2 +-
.../TricubicInterpolatingFunction.java | 2 +-
.../interpolation/TricubicInterpolator.java | 2 +-
.../UnivariatePeriodicInterpolator.java | 2 +-
.../analysis/polynomials/PolynomialFunction.java | 16 +-
.../PolynomialFunctionLagrangeForm.java | 6 +-
.../polynomials/PolynomialSplineFunction.java | 2 +-
.../analysis/polynomials/PolynomialsUtils.java | 8 +-
.../legacy/analysis/solvers/BaseSecantSolver.java | 6 +-
.../legacy/analysis/solvers/BisectionSolver.java | 4 +-
.../BracketedRealFieldUnivariateSolver.java | 2 +-
.../solvers/BracketingNthOrderBrentSolver.java | 14 +-
.../FieldBracketingNthOrderBrentSolver.java | 6 +-
.../legacy/analysis/solvers/LaguerreSolver.java | 14 +-
.../legacy/analysis/solvers/MullerSolver.java | 20 +-
.../legacy/analysis/solvers/MullerSolver2.java | 24 +-
.../analysis/solvers/NewtonRaphsonSolver.java | 4 +-
.../legacy/analysis/solvers/RiddersSolver.java | 18 +-
.../legacy/analysis/solvers/SecantSolver.java | 6 +-
.../analysis/solvers/UnivariateSolverUtils.java | 18 +-
.../distribution/AbstractIntegerDistribution.java | 12 +-
.../distribution/AbstractRealDistribution.java | 10 +-
.../legacy/distribution/EmpiricalDistribution.java | 6 +-
.../distribution/EnumeratedDistribution.java | 2 +-
.../MultivariateNormalDistribution.java | 12 +-
...ariateNormalMixtureExpectationMaximization.java | 10 +-
.../math4/legacy/fitting/GaussianCurveFitter.java | 4 +-
.../math4/legacy/fitting/HarmonicCurveFitter.java | 12 +-
.../fitting/leastsquares/AbstractEvaluation.java | 8 +-
.../fitting/leastsquares/LeastSquaresFactory.java | 4 +-
.../leastsquares/LevenbergMarquardtOptimizer.java | 54 +-
.../legacy/genetics/ElitisticListPopulation.java | 4 +-
.../math4/legacy/genetics/OrderedCrossover.java | 6 +-
.../math4/legacy/linear/AbstractFieldMatrix.java | 6 +-
.../math4/legacy/linear/AbstractRealMatrix.java | 8 +-
.../math4/legacy/linear/Array2DRowFieldMatrix.java | 6 +-
.../math4/legacy/linear/ArrayFieldVector.java | 6 +-
.../math4/legacy/linear/ArrayRealVector.java | 20 +-
.../math4/legacy/linear/BiDiagonalTransformer.java | 12 +-
.../commons/math4/legacy/linear/BigReal.java | 4 +-
.../commons/math4/legacy/linear/BigRealField.java | 4 +-
.../math4/legacy/linear/BlockFieldMatrix.java | 100 +--
.../math4/legacy/linear/BlockRealMatrix.java | 100 +--
.../math4/legacy/linear/CholeskyDecomposition.java | 8 +-
.../linear/DefaultFieldMatrixChangingVisitor.java | 2 +-
.../DefaultFieldMatrixPreservingVisitor.java | 2 +-
.../math4/legacy/linear/DiagonalMatrix.java | 4 +-
.../math4/legacy/linear/EigenDecomposition.java | 64 +-
.../legacy/linear/FieldDecompositionSolver.java | 2 +-
.../math4/legacy/linear/FieldLUDecomposition.java | 6 +-
.../commons/math4/legacy/linear/FieldMatrix.java | 4 +-
.../legacy/linear/FieldMatrixChangingVisitor.java | 2 +-
.../linear/FieldMatrixPreservingVisitor.java | 2 +-
.../commons/math4/legacy/linear/FieldVector.java | 4 +-
.../legacy/linear/FieldVectorChangingVisitor.java | 2 +-
.../linear/FieldVectorPreservingVisitor.java | 2 +-
.../math4/legacy/linear/HessenbergTransformer.java | 6 +-
.../math4/legacy/linear/JacobiPreconditioner.java | 2 +-
.../math4/legacy/linear/LUDecomposition.java | 8 +-
.../commons/math4/legacy/linear/MatrixUtils.java | 16 +-
.../legacy/linear/OpenIntToDoubleHashMap.java | 4 +-
.../math4/legacy/linear/OpenIntToFieldHashMap.java | 8 +-
.../math4/legacy/linear/OpenMapRealVector.java | 14 +-
.../math4/legacy/linear/QRDecomposition.java | 24 +-
.../math4/legacy/linear/RRQRDecomposition.java | 4 +-
.../commons/math4/legacy/linear/RealVector.java | 14 +-
.../linear/RectangularCholeskyDecomposition.java | 4 +-
.../math4/legacy/linear/SchurTransformer.java | 34 +-
.../legacy/linear/SingularValueDecomposition.java | 52 +-
.../math4/legacy/linear/SparseFieldMatrix.java | 4 +-
.../math4/legacy/linear/SparseFieldVector.java | 6 +-
.../apache/commons/math4/legacy/linear/SymmLQ.java | 38 +-
.../legacy/linear/TriDiagonalTransformer.java | 4 +-
.../legacy/ml/clustering/FuzzyKMeansClusterer.java | 18 +-
.../ml/clustering/evaluation/CalinskiHarabasz.java | 2 +-
.../math4/legacy/ml/distance/CanberraDistance.java | 8 +-
.../legacy/ml/distance/ChebyshevDistance.java | 2 +-
.../legacy/ml/distance/EarthMoversDistance.java | 6 +-
.../legacy/ml/distance/EuclideanDistance.java | 2 +-
.../legacy/ml/distance/ManhattanDistance.java | 2 +-
.../math4/legacy/ode/AbstractFieldIntegrator.java | 12 +-
.../math4/legacy/ode/AbstractIntegrator.java | 8 +-
.../legacy/ode/ContinuousOutputFieldModel.java | 10 +-
.../math4/legacy/ode/ContinuousOutputModel.java | 14 +-
.../math4/legacy/ode/FieldEquationsMapper.java | 4 +-
.../math4/legacy/ode/FieldExpandableODE.java | 4 +-
.../commons/math4/legacy/ode/FieldODEState.java | 6 +-
.../legacy/ode/FieldODEStateAndDerivative.java | 2 +-
.../math4/legacy/ode/FieldSecondaryEquations.java | 2 +-
.../ode/FirstOrderFieldDifferentialEquations.java | 2 +-
.../legacy/ode/FirstOrderFieldIntegrator.java | 2 +-
.../commons/math4/legacy/ode/JacobianMatrices.java | 2 +-
.../math4/legacy/ode/MultistepFieldIntegrator.java | 12 +-
.../math4/legacy/ode/MultistepIntegrator.java | 8 +-
.../math4/legacy/ode/events/EventState.java | 22 +-
.../math4/legacy/ode/events/FieldEventHandler.java | 2 +-
.../math4/legacy/ode/events/FieldEventState.java | 10 +-
.../math4/legacy/ode/events/Transformer.java | 6 +-
.../nonstiff/AdamsBashforthFieldIntegrator.java | 6 +-
.../ode/nonstiff/AdamsBashforthIntegrator.java | 6 +-
.../legacy/ode/nonstiff/AdamsFieldIntegrator.java | 4 +-
.../ode/nonstiff/AdamsFieldStepInterpolator.java | 4 +-
.../ode/nonstiff/AdamsMoultonFieldIntegrator.java | 6 +-
.../ode/nonstiff/AdamsMoultonIntegrator.java | 6 +-
.../nonstiff/AdamsNordsieckFieldTransformer.java | 6 +-
.../nonstiff/AdaptiveStepsizeFieldIntegrator.java | 16 +-
.../ode/nonstiff/AdaptiveStepsizeIntegrator.java | 30 +-
.../ClassicalRungeKuttaFieldIntegrator.java | 6 +-
.../ClassicalRungeKuttaFieldStepInterpolator.java | 4 +-
.../nonstiff/DormandPrince54FieldIntegrator.java | 6 +-
.../DormandPrince54FieldStepInterpolator.java | 4 +-
.../ode/nonstiff/DormandPrince54Integrator.java | 6 +-
.../nonstiff/DormandPrince853FieldIntegrator.java | 6 +-
.../DormandPrince853FieldStepInterpolator.java | 6 +-
.../ode/nonstiff/DormandPrince853Integrator.java | 46 +-
.../EmbeddedRungeKuttaFieldIntegrator.java | 6 +-
.../ode/nonstiff/EmbeddedRungeKuttaIntegrator.java | 12 +-
.../legacy/ode/nonstiff/EulerFieldIntegrator.java | 6 +-
.../ode/nonstiff/EulerFieldStepInterpolator.java | 4 +-
.../ode/nonstiff/FieldButcherArrayProvider.java | 2 +-
.../legacy/ode/nonstiff/GillFieldIntegrator.java | 6 +-
.../ode/nonstiff/GillFieldStepInterpolator.java | 4 +-
.../math4/legacy/ode/nonstiff/GillIntegrator.java | 8 +-
.../legacy/ode/nonstiff/GillStepInterpolator.java | 6 +-
.../ode/nonstiff/GraggBulirschStoerIntegrator.java | 50 +-
.../GraggBulirschStoerStepInterpolator.java | 6 +-
.../ode/nonstiff/HighamHall54FieldIntegrator.java | 6 +-
.../HighamHall54FieldStepInterpolator.java | 4 +-
.../ode/nonstiff/HighamHall54Integrator.java | 6 +-
.../legacy/ode/nonstiff/LutherFieldIntegrator.java | 6 +-
.../ode/nonstiff/LutherFieldStepInterpolator.java | 4 +-
.../legacy/ode/nonstiff/LutherIntegrator.java | 4 +-
.../ode/nonstiff/LutherStepInterpolator.java | 4 +-
.../ode/nonstiff/MidpointFieldIntegrator.java | 6 +-
.../nonstiff/MidpointFieldStepInterpolator.java | 4 +-
.../ode/nonstiff/RungeKuttaFieldIntegrator.java | 6 +-
.../nonstiff/RungeKuttaFieldStepInterpolator.java | 6 +-
.../legacy/ode/nonstiff/RungeKuttaIntegrator.java | 4 +-
.../ode/nonstiff/ThreeEighthesFieldIntegrator.java | 6 +-
.../ThreeEighthesFieldStepInterpolator.java | 4 +-
.../sampling/AbstractFieldStepInterpolator.java | 2 +-
.../legacy/ode/sampling/FieldFixedStepHandler.java | 2 +-
.../legacy/ode/sampling/FieldStepHandler.java | 2 +-
.../legacy/ode/sampling/FieldStepInterpolator.java | 2 +-
.../legacy/ode/sampling/FieldStepNormalizer.java | 8 +-
.../ode/sampling/NordsieckStepInterpolator.java | 4 +-
.../math4/legacy/ode/sampling/StepNormalizer.java | 6 +-
.../math4/legacy/optim/SimplePointChecker.java | 6 +-
.../math4/legacy/optim/SimpleValueChecker.java | 6 +-
.../legacy/optim/SimpleVectorValueChecker.java | 6 +-
.../math4/legacy/optim/linear/SimplexSolver.java | 4 +-
.../scalar/MultivariateFunctionMappingAdapter.java | 10 +-
.../scalar/MultivariateFunctionPenaltyAdapter.java | 4 +-
.../nonlinear/scalar/noderiv/BOBYQAOptimizer.java | 140 ++--
.../nonlinear/scalar/noderiv/CMAESOptimizer.java | 46 +-
.../nonlinear/scalar/noderiv/PowellOptimizer.java | 8 +-
.../legacy/optim/univariate/BracketFinder.java | 4 +-
.../legacy/optim/univariate/BrentOptimizer.java | 16 +-
.../univariate/SimpleUnivariateValueChecker.java | 6 +-
.../commons/math4/legacy/random/RngAdaptor.java | 10 +-
.../legacy/random/SobolSequenceGenerator.java | 4 +-
.../math4/legacy/random/StableRandomGenerator.java | 36 +-
.../legacy/random/UniformRandomGenerator.java | 4 +-
.../commons/math4/legacy/special/BesselJ.java | 26 +-
.../stat/correlation/KendallsCorrelation.java | 8 +-
.../stat/correlation/PearsonsCorrelation.java | 10 +-
.../AbstractStorelessUnivariateStatistic.java | 2 +-
.../descriptive/AbstractUnivariateStatistic.java | 2 +-
.../stat/descriptive/DescriptiveStatistics.java | 6 +-
.../descriptive/MultivariateSummaryStatistics.java | 6 +-
.../stat/descriptive/ResizableDoubleArray.java | 10 +-
.../stat/descriptive/StatisticalSummaryValues.java | 4 +-
.../legacy/stat/descriptive/SummaryStatistics.java | 6 +-
.../stat/descriptive/UnivariateStatistic.java | 2 +-
.../stat/descriptive/moment/GeometricMean.java | 6 +-
.../legacy/stat/descriptive/moment/Kurtosis.java | 12 +-
.../math4/legacy/stat/descriptive/moment/Mean.java | 2 +-
.../stat/descriptive/moment/SemiVariance.java | 2 +-
.../legacy/stat/descriptive/moment/Skewness.java | 8 +-
.../stat/descriptive/moment/StandardDeviation.java | 12 +-
.../legacy/stat/descriptive/moment/Variance.java | 2 +-
.../descriptive/rank/CentralPivotingStrategy.java | 2 +-
.../legacy/stat/descriptive/rank/KthSelector.java | 6 +-
.../math4/legacy/stat/descriptive/rank/Max.java | 2 +-
.../rank/MedianOf3PivotingStrategy.java | 2 +-
.../math4/legacy/stat/descriptive/rank/Min.java | 2 +-
.../stat/descriptive/rank/PSquarePercentile.java | 2 +-
.../legacy/stat/descriptive/rank/Percentile.java | 14 +-
.../descriptive/rank/RandomPivotingStrategy.java | 2 +-
.../legacy/stat/descriptive/summary/Product.java | 6 +-
.../math4/legacy/stat/descriptive/summary/Sum.java | 2 +-
.../legacy/stat/descriptive/summary/SumOfLogs.java | 10 +-
.../stat/descriptive/summary/SumOfSquares.java | 2 +-
.../math4/legacy/stat/inference/ChiSquareTest.java | 8 +-
.../commons/math4/legacy/stat/inference/GTest.java | 16 +-
.../stat/inference/KolmogorovSmirnovTest.java | 54 +-
.../legacy/stat/inference/MannWhitneyUTest.java | 6 +-
.../commons/math4/legacy/stat/inference/TTest.java | 14 +-
.../stat/inference/WilcoxonSignedRankTest.java | 8 +-
.../legacy/stat/interval/AgrestiCoullInterval.java | 6 +-
.../stat/interval/NormalApproximationInterval.java | 4 +-
.../legacy/stat/interval/WilsonScoreInterval.java | 4 +-
.../math4/legacy/stat/ranking/NaturalRanking.java | 6 +-
.../AbstractMultipleLinearRegression.java | 6 +-
.../stat/regression/MillerUpdatingRegression.java | 30 +-
.../legacy/stat/regression/RegressionResults.java | 6 +-
.../legacy/stat/regression/SimpleRegression.java | 18 +-
.../org/apache/commons/math4/legacy/TestUtils.java | 5 +-
.../math4/legacy/analysis/FunctionUtilsTest.java | 26 +-
.../differentiation/DerivativeStructureTest.java | 184 ++---
.../FiniteDifferencesDifferentiatorTest.java | 44 +-
.../differentiation/GradientFunctionTest.java | 4 +-
.../differentiation/JacobianFunctionTest.java | 18 +-
.../differentiation/SparseGradientTest.java | 128 ++--
.../analysis/function/BivariateFunctionTest.java | 4 +-
.../legacy/analysis/function/GaussianTest.java | 6 +-
.../analysis/function/HarmonicOscillatorTest.java | 20 +-
.../legacy/analysis/function/LogisticTest.java | 12 +-
.../math4/legacy/analysis/function/LogitTest.java | 4 +-
.../math4/legacy/analysis/function/SincTest.java | 10 +-
.../math4/legacy/analysis/function/SqrtTest.java | 8 +-
.../UnivariateDifferentiableFunctionTest.java | 76 +-
.../analysis/function/UnivariateFunctionTest.java | 4 +-
.../IterativeLegendreGaussIntegratorTest.java | 18 +-
.../integration/MidPointIntegratorTest.java | 20 +-
.../integration/RombergIntegratorTest.java | 16 +-
.../integration/SimpsonIntegratorTest.java | 36 +-
.../integration/TrapezoidIntegratorTest.java | 16 +-
.../gauss/GaussianQuadratureAbstractTest.java | 4 +-
.../integration/gauss/HermiteParametricTest.java | 4 +-
.../analysis/integration/gauss/HermiteTest.java | 10 +-
.../analysis/integration/gauss/LaguerreTest.java | 4 +-
.../interpolation/AkimaSplineInterpolatorTest.java | 4 +-
.../BicubicInterpolatingFunctionTest.java | 4 +-
.../DividedDifferenceInterpolatorTest.java | 20 +-
.../FieldHermiteInterpolatorTest.java | 18 +-
.../interpolation/HermiteInterpolatorTest.java | 30 +-
.../interpolation/LoessInterpolatorTest.java | 18 +-
.../MicrosphereProjectionInterpolatorTest.java | 6 +-
.../interpolation/NevilleInterpolatorTest.java | 20 +-
...wiseBicubicSplineInterpolatingFunctionTest.java | 4 +-
.../interpolation/SplineInterpolatorTest.java | 22 +-
.../TricubicInterpolatingFunctionTest.java | 20 +-
.../interpolation/TricubicInterpolatorTest.java | 4 +-
.../UnivariatePeriodicInterpolatorTest.java | 8 +-
.../polynomials/PolynomialFunctionTest.java | 10 +-
.../analysis/polynomials/PolynomialsUtilsTest.java | 18 +-
.../solvers/BaseSecantSolverAbstractTest.java | 6 +-
.../analysis/solvers/BisectionSolverTest.java | 8 +-
.../legacy/analysis/solvers/BrentSolverTest.java | 22 +-
.../FieldBracketingNthOrderBrentSolverTest.java | 6 +-
.../analysis/solvers/LaguerreSolverTest.java | 34 +-
.../legacy/analysis/solvers/MullerSolver2Test.java | 36 +-
.../legacy/analysis/solvers/MullerSolverTest.java | 36 +-
.../analysis/solvers/NewtonRaphsonSolverTest.java | 6 +-
.../analysis/solvers/RegulaFalsiSolverTest.java | 4 +-
.../legacy/analysis/solvers/RiddersSolverTest.java | 36 +-
.../solvers/UnivariateSolverUtilsTest.java | 6 +-
.../legacy/complex/ComplexFormatAbstractTest.java | 4 +-
.../distribution/EmpiricalDistributionTest.java | 8 +-
.../EnumeratedIntegerDistributionTest.java | 4 +-
.../EnumeratedRealDistributionTest.java | 4 +-
.../IntegerDistributionAbstractTest.java | 4 +-
.../distribution/RealDistributionAbstractTest.java | 8 +-
.../ExtendedFieldElementAbstractTest.java | 88 +--
.../math4/legacy/filter/KalmanFilterTest.java | 26 +-
.../legacy/fitting/HarmonicCurveFitterTest.java | 4 +-
.../legacy/fitting/PolynomialCurveFitterTest.java | 22 +-
.../AbstractLeastSquaresOptimizerAbstractTest.java | 14 +-
.../fitting/leastsquares/BevingtonProblem.java | 14 +-
.../legacy/fitting/leastsquares/CircleProblem.java | 6 +-
...atorVectorMultivariateJacobianFunctionTest.java | 6 +-
.../fitting/leastsquares/EvaluationTest.java | 10 +-
.../leastsquares/EvaluationTestValidation.java | 4 +-
.../GaussNewtonOptimizerWithSVDTest.java | 4 +-
.../LevenbergMarquardtOptimizerTest.java | 8 +-
.../legacy/fitting/leastsquares/MinpackTest.java | 80 +--
.../leastsquares/RandomCirclePointGenerator.java | 6 +-
.../StatisticalReferenceDatasetFactory.java | 22 +-
.../legacy/genetics/FixedElapsedTimeTest.java | 4 +-
.../genetics/GeneticAlgorithmTestPermutations.java | 4 +-
.../legacy/linear/Array2DRowRealMatrixTest.java | 6 +-
.../math4/legacy/linear/ArrayFieldVectorTest.java | 6 +-
.../legacy/linear/BiDiagonalTransformerTest.java | 10 +-
.../commons/math4/legacy/linear/BigRealTest.java | 10 +-
.../math4/legacy/linear/BlockFieldMatrixTest.java | 2 +-
.../math4/legacy/linear/BlockRealMatrixTest.java | 6 +-
.../math4/legacy/linear/ConjugateGradientTest.java | 20 +-
.../apache/commons/math4/legacy/linear/Dfp25.java | 6 +-
.../legacy/linear/EigenDecompositionTest.java | 22 +-
.../legacy/linear/FieldLUDecompositionTest.java | 2 +-
.../math4/legacy/linear/FieldLUSolverTest.java | 2 +-
.../math4/legacy/linear/FieldMatrixImplTest.java | 2 +-
.../math4/legacy/linear/MatrixUtilsTest.java | 2 +-
.../math4/legacy/linear/OpenIntToFieldTest.java | 6 +-
.../legacy/linear/RealVectorAbstractTest.java | 28 +-
.../math4/legacy/linear/SparseFieldMatrixTest.java | 4 +-
.../math4/legacy/linear/SparseFieldVectorTest.java | 4 +-
.../commons/math4/legacy/linear/SymmLQTest.java | 20 +-
.../legacy/linear/TriDiagonalTransformerTest.java | 4 +-
.../linear/UnmodifiableRealVectorAbstractTest.java | 12 +-
.../legacy/ml/distance/EuclideanDistanceTest.java | 4 +-
.../legacy/ode/ContinuousOutputFieldModelTest.java | 24 +-
.../legacy/ode/ContinuousOutputModelTest.java | 22 +-
.../math4/legacy/ode/FieldExpandableODETest.java | 6 +-
.../math4/legacy/ode/FirstOrderConverterTest.java | 20 +-
.../math4/legacy/ode/JacobianMatricesTest.java | 46 +-
.../math4/legacy/ode/TestFieldProblem1.java | 6 +-
.../math4/legacy/ode/TestFieldProblem2.java | 6 +-
.../math4/legacy/ode/TestFieldProblem3.java | 6 +-
.../math4/legacy/ode/TestFieldProblem4.java | 16 +-
.../math4/legacy/ode/TestFieldProblem5.java | 4 +-
.../math4/legacy/ode/TestFieldProblem6.java | 6 +-
.../math4/legacy/ode/TestFieldProblemAbstract.java | 6 +-
.../math4/legacy/ode/TestFieldProblemHandler.java | 2 +-
.../commons/math4/legacy/ode/TestProblem1.java | 4 +-
.../commons/math4/legacy/ode/TestProblem2.java | 4 +-
.../commons/math4/legacy/ode/TestProblem3.java | 20 +-
.../commons/math4/legacy/ode/TestProblem4.java | 18 +-
.../math4/legacy/ode/TestProblemHandler.java | 18 +-
.../math4/legacy/ode/events/EventFilterTest.java | 52 +-
...tractEmbeddedRungeKuttaFieldIntegratorTest.java | 18 +-
.../AbstractRungeKuttaFieldIntegratorTest.java | 22 +-
.../AdamsBashforthFieldIntegratorTest.java | 4 +-
.../ode/nonstiff/AdamsBashforthIntegratorTest.java | 8 +-
.../nonstiff/AdamsFieldIntegratorAbstractTest.java | 8 +-
.../nonstiff/AdamsMoultonFieldIntegratorTest.java | 4 +-
.../ode/nonstiff/AdamsMoultonIntegratorTest.java | 8 +-
...lassicalRungKuttaFieldStepInterpolatorTest.java | 4 +-
.../ClassicalRungeKuttaFieldIntegratorTest.java | 4 +-
.../ClassicalRungeKuttaIntegratorTest.java | 18 +-
.../math4/legacy/ode/nonstiff/Decimal64.java | 80 +--
.../math4/legacy/ode/nonstiff/Decimal64Field.java | 4 +-
.../math4/legacy/ode/nonstiff/Decimal64Test.java | 2 +-
.../DormandPrince54FieldIntegratorTest.java | 4 +-
.../DormandPrince54FieldStepInterpolatorTest.java | 4 +-
.../nonstiff/DormandPrince54IntegratorTest.java | 12 +-
.../DormandPrince54StepInterpolatorTest.java | 6 +-
.../DormandPrince853FieldIntegratorTest.java | 4 +-
.../DormandPrince853FieldStepInterpolatorTest.java | 4 +-
.../nonstiff/DormandPrince853IntegratorTest.java | 18 +-
.../DormandPrince853StepInterpolatorTest.java | 6 +-
...eddedRungeKuttaFieldIntegratorAbstractTest.java | 18 +-
.../ode/nonstiff/EulerFieldIntegratorTest.java | 4 +-
.../nonstiff/EulerFieldStepInterpolatorTest.java | 4 +-
.../legacy/ode/nonstiff/EulerIntegratorTest.java | 10 +-
.../ode/nonstiff/EulerStepInterpolatorTest.java | 20 +-
.../ode/nonstiff/GillFieldIntegratorTest.java | 4 +-
.../nonstiff/GillFieldStepInterpolatorTest.java | 4 +-
.../legacy/ode/nonstiff/GillIntegratorTest.java | 10 +-
.../nonstiff/GraggBulirschStoerIntegratorTest.java | 16 +-
.../GraggBulirschStoerStepInterpolatorTest.java | 6 +-
.../nonstiff/HighamHall54FieldIntegratorTest.java | 4 +-
.../HighamHall54FieldStepInterpolatorTest.java | 4 +-
.../ode/nonstiff/HighamHall54IntegratorTest.java | 4 +-
.../nonstiff/HighamHall54StepInterpolatorTest.java | 6 +-
.../ode/nonstiff/LutherFieldIntegratorTest.java | 4 +-
.../nonstiff/LutherFieldStepInterpolatorTest.java | 4 +-
.../legacy/ode/nonstiff/LutherIntegratorTest.java | 14 +-
.../ode/nonstiff/MidpointFieldIntegratorTest.java | 4 +-
.../MidpointFieldStepInterpolatorTest.java | 4 +-
.../ode/nonstiff/MidpointIntegratorTest.java | 10 +-
.../RungeKuttaFieldIntegratorAbstractTest.java | 22 +-
...ungeKuttaFieldStepInterpolatorAbstractTest.java | 20 +-
.../legacy/ode/nonstiff/StepFieldProblem.java | 6 +-
.../nonstiff/ThreeEighthesFieldIntegratorTest.java | 4 +-
.../ThreeEighthesFieldStepInterpolatorTest.java | 4 +-
.../ode/nonstiff/ThreeEighthesIntegratorTest.java | 10 +-
.../ode/sampling/DummyFieldStepInterpolator.java | 2 +-
.../ode/sampling/DummyStepInterpolatorTest.java | 10 +-
.../ode/sampling/StepInterpolatorTestUtils.java | 8 +-
.../legacy/ode/sampling/StepNormalizerTest.java | 4 +-
.../scalar/noderiv/CMAESOptimizerTest.java | 30 +-
.../nonlinear/scalar/noderiv/OptimTestUtils.java | 28 +-
.../scalar/noderiv/PowellOptimizerTest.java | 4 +-
.../SimplexOptimizerMultiDirectionalTest.java | 2 +-
.../noderiv/SimplexOptimizerNelderMeadTest.java | 2 +-
.../optim/univariate/BrentOptimizerTest.java | 4 +-
.../MultiStartUnivariateOptimizerTest.java | 6 +-
.../CorrelatedRandomVectorGeneratorTest.java | 8 +-
.../RandomUtilsDataGeneratorAbstractTest.java | 6 +-
.../commons/math4/legacy/stat/StatUtilsTest.java | 18 +-
.../stat/correlation/PearsonsCorrelationTest.java | 4 +-
.../MultivariateSummaryStatisticsTest.java | 6 +-
.../stat/descriptive/ResizableDoubleArrayTest.java | 2 +-
.../StorelessUnivariateStatisticAbstractTest.java | 4 +-
.../stat/descriptive/SummaryStatisticsTest.java | 6 +-
.../UnivariateStatisticAbstractTest.java | 6 +-
.../descriptive/moment/StandardDeviationTest.java | 4 +-
.../stat/descriptive/moment/VarianceTest.java | 2 +-
.../descriptive/rank/PSquarePercentileTest.java | 10 +-
.../math4/legacy/stat/inference/GTestTest.java | 20 +-
.../stat/inference/InferenceTestUtilsTest.java | 20 +-
.../stat/inference/KolmogorovSmirnovTestTest.java | 6 +-
.../legacy/stat/ranking/NaturalRankingTest.java | 12 +-
.../regression/MillerUpdatingRegressionTest.java | 124 ++--
.../stat/regression/SimpleRegressionTest.java | 30 +-
.../RealFunctionValidation.java | 8 +-
pom.xml | 7 +
489 files changed, 4396 insertions(+), 3759 deletions(-)
diff --git a/commons-math-examples/pom.xml b/commons-math-examples/pom.xml
index 2b37839..e182af0 100644
--- a/commons-math-examples/pom.xml
+++ b/commons-math-examples/pom.xml
@@ -27,7 +27,7 @@
<artifactId>commons-math-examples</artifactId>
<version>4.0-SNAPSHOT</version>
<packaging>pom</packaging>
- <name>Apache Commons Math Examples</name>
+ <name>Example applications</name>
<description>Examples of use of the "Commons Math" library.
Codes in this module and its sub-modules are not part of the public API.
diff --git a/commons-math-legacy-core/LICENCE b/commons-math-legacy-core/LICENCE
new file mode 100644
index 0000000..d97b49a
--- /dev/null
+++ b/commons-math-legacy-core/LICENCE
@@ -0,0 +1,457 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (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
+
+ 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.
+
+
+Apache Commons Math includes the following code provided to the ASF under the
+Apache License 2.0:
+
+ - The inverse error function implementation in the Erf class is based on CUDA
+ code developed by Mike Giles, Oxford-Man Institute of Quantitative Finance,
+ and published in GPU Computing Gems, volume 2, 2010 (grant received on
+ March 23th 2013)
+ - The LinearConstraint, LinearObjectiveFunction, LinearOptimizer,
+ RelationShip, SimplexSolver and SimplexTableau classes in package
+ org.apache.commons.math3.optimization.linear include software developed by
+ Benjamin McCann (http://www.benmccann.com) and distributed with
+ the following copyright: Copyright 2009 Google Inc. (grant received on
+ March 16th 2009)
+ - The class "org.apache.commons.math3.exception.util.LocalizedFormatsTest" which
+ is an adapted version of "OrekitMessagesTest" test class for the Orekit library
+ - The "org.apache.commons.math3.analysis.interpolation.HermiteInterpolator"
+ has been imported from the Orekit space flight dynamics library.
+
+===============================================================================
+
+
+
+APACHE COMMONS MATH DERIVATIVE WORKS:
+
+The Apache commons-math library includes a number of subcomponents
+whose implementation is derived from original sources written
+in C or Fortran. License terms of the original sources
+are reproduced below.
+
+===============================================================================
+For the lmder, lmpar and qrsolv Fortran routine from minpack and translated in
+the LevenbergMarquardtOptimizer class in package
+org.apache.commons.math3.optimization.general
+Original source copyright and license statement:
+
+Minpack Copyright Notice (1999) University of Chicago. All rights reserved
+
+Redistribution and use in source and binary forms, with or
+without modification, are permitted provided that the
+following conditions are met:
+
+1. Redistributions of source code must retain the above
+copyright notice, this list of conditions and the following
+disclaimer.
+
+2. Redistributions in binary form must reproduce the above
+copyright notice, this list of conditions and the following
+disclaimer in the documentation and/or other materials
+provided with the distribution.
+
+3. The end-user documentation included with the
+redistribution, if any, must include the following
+acknowledgment:
+
+ "This product includes software developed by the
+ University of Chicago, as Operator of Argonne National
+ Laboratory.
+
+Alternately, this acknowledgment may appear in the software
+itself, if and wherever such third-party acknowledgments
+normally appear.
+
+4. WARRANTY DISCLAIMER. THE SOFTWARE IS SUPPLIED "AS IS"
+WITHOUT WARRANTY OF ANY KIND. THE COPYRIGHT HOLDER, THE
+UNITED STATES, THE UNITED STATES DEPARTMENT OF ENERGY, AND
+THEIR EMPLOYEES: (1) DISCLAIM ANY WARRANTIES, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO ANY IMPLIED WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE
+OR NON-INFRINGEMENT, (2) DO NOT ASSUME ANY LEGAL LIABILITY
+OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, OR
+USEFULNESS OF THE SOFTWARE, (3) DO NOT REPRESENT THAT USE OF
+THE SOFTWARE WOULD NOT INFRINGE PRIVATELY OWNED RIGHTS, (4)
+DO NOT WARRANT THAT THE SOFTWARE WILL FUNCTION
+UNINTERRUPTED, THAT IT IS ERROR-FREE OR THAT ANY ERRORS WILL
+BE CORRECTED.
+
+5. LIMITATION OF LIABILITY. IN NO EVENT WILL THE COPYRIGHT
+HOLDER, THE UNITED STATES, THE UNITED STATES DEPARTMENT OF
+ENERGY, OR THEIR EMPLOYEES: BE LIABLE FOR ANY INDIRECT,
+INCIDENTAL, CONSEQUENTIAL, SPECIAL OR PUNITIVE DAMAGES OF
+ANY KIND OR NATURE, INCLUDING BUT NOT LIMITED TO LOSS OF
+PROFITS OR LOSS OF DATA, FOR ANY REASON WHATSOEVER, WHETHER
+SUCH LIABILITY IS ASSERTED ON THE BASIS OF CONTRACT, TORT
+(INCLUDING NEGLIGENCE OR STRICT LIABILITY), OR OTHERWISE,
+EVEN IF ANY OF SAID PARTIES HAS BEEN WARNED OF THE
+POSSIBILITY OF SUCH LOSS OR DAMAGES.
+===============================================================================
+
+Copyright and license statement for the odex Fortran routine developed by
+E. Hairer and G. Wanner and translated in GraggBulirschStoerIntegrator class
+in package org.apache.commons.math3.ode.nonstiff:
+
+
+Copyright (c) 2004, Ernst Hairer
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+- Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+- Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+===============================================================================
+
+Copyright and license statement for the original Mersenne twister C
+routines translated in MersenneTwister class in package
+org.apache.commons.math3.random:
+
+ Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ 3. The names of its contributors may not be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+===============================================================================
+
+The initial code for shuffling an array (originally in class
+"org.apache.commons.math3.random.RandomDataGenerator", now replaced by
+a method in class "org.apache.commons.math3.util.MathArrays") was
+inspired from the algorithm description provided in
+"Algorithms", by Ian Craw and John Pulham (University of Aberdeen 1999).
+The textbook (containing a proof that the shuffle is uniformly random) is
+available here:
+ http://citeseerx.ist.psu.edu/viewdoc/download;?doi=10.1.1.173.1898&rep=rep1&type=pdf
+
+===============================================================================
+License statement for the direction numbers in the resource files for Sobol sequences.
+
+-----------------------------------------------------------------------------
+Licence pertaining to sobol.cc and the accompanying sets of direction numbers
+
+-----------------------------------------------------------------------------
+Copyright (c) 2008, Frances Y. Kuo and Stephen Joe
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the names of the copyright holders nor the names of the
+ University of New South Wales and the University of Waikato
+ and its contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+===============================================================================
+
+The initial commit of package "org.apache.commons.math3.ml.neuralnet" is
+an adapted version of code developed in the context of the Data Processing
+and Analysis Consortium (DPAC) of the "Gaia" project of the European Space
+Agency (ESA).
+===============================================================================
+
+The initial commit of the class "org.apache.commons.math3.special.BesselJ" is
+an adapted version of code translated from the netlib Fortran program, rjbesl
+http://www.netlib.org/specfun/rjbesl by R.J. Cody at Argonne National
+Laboratory (USA). There is no license or copyright statement included with the
+original Fortran sources.
+===============================================================================
+
+
+The BracketFinder (package org.apache.commons.math3.optimization.univariate)
+and PowellOptimizer (package org.apache.commons.math3.optimization.general)
+classes are based on the Python code in module "optimize.py" (version 0.5)
+developed by Travis E. Oliphant for the SciPy library (http://www.scipy.org/)
+Copyright © 2003-2009 SciPy Developers.
+
+SciPy license
+Copyright © 2001, 2002 Enthought, Inc.
+All rights reserved.
+
+Copyright © 2003-2013 SciPy Developers.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Enthought nor the names of the SciPy Developers may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+===============================================================================
+
diff --git a/commons-math-legacy-core/NOTICE b/commons-math-legacy-core/NOTICE
new file mode 100644
index 0000000..587cd7f
--- /dev/null
+++ b/commons-math-legacy-core/NOTICE
@@ -0,0 +1,9 @@
+Apache Commons Math
+Copyright 2001-2020 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+This product includes software developed for Orekit by
+CS Systèmes d'Information (http://www.c-s.fr/)
+Copyright 2010-2012 CS Systèmes d'Information
diff --git a/commons-math-legacy-core/pom.xml b/commons-math-legacy-core/pom.xml
new file mode 100644
index 0000000..8b14ff6
--- /dev/null
+++ b/commons-math-legacy-core/pom.xml
@@ -0,0 +1,74 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (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
+
+ 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.
+-->
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-math-parent</artifactId>
+ <version>4.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>commons-math4-legacy-core</artifactId>
+ <name>Miscellaneous core classes (Legacy)</name>
+
+ <description>Field, Dfp, ...</description>
+
+ <properties>
+ <!-- The Java Module System Name -->
+ <commons.module.name>org.apache.commons.math4.legacy.core</commons.module.name>
+ <!-- This value must reflect the current name of the base package. -->
+ <commons.osgi.symbolicName>org.apache.commons.math4.legacy.core</commons.osgi.symbolicName>
+ <!-- OSGi -->
+ <commons.osgi.export>org.apache.commons.math4.legacy.core</commons.osgi.export>
+ <!-- Workaround to avoid duplicating config files. -->
+ <math.parent.dir>${basedir}/..</math.parent.dir>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-math4-legacy-exception</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-arrays</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-rng-client-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-rng-simple</artifactId>
+ </dependency>
+
+ </dependencies>
+
+</project>
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/Field.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/Field.java
similarity index 97%
rename from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/Field.java
rename to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/Field.java
index f6168c4..4330212 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/Field.java
+++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/Field.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.math4.legacy;
+package org.apache.commons.math4.legacy.core;
/**
* Interface representing a <a href="http://mathworld.wolfram.com/Field.html">field</a>.
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/FieldElement.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/FieldElement.java
similarity index 98%
rename from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/FieldElement.java
rename to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/FieldElement.java
index bcd1dae..e2ee0fe 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/FieldElement.java
+++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/FieldElement.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.math4.legacy;
+package org.apache.commons.math4.legacy.core;
import org.apache.commons.math4.legacy.exception.MathArithmeticException;
import org.apache.commons.math4.legacy.exception.NullArgumentException;
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/MathArrays.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/MathArrays.java
similarity index 98%
rename from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/MathArrays.java
rename to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/MathArrays.java
index 3d55cc8..10a8ed1 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/MathArrays.java
+++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/MathArrays.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.commons.math4.legacy.util;
+package org.apache.commons.math4.legacy.core;
import java.lang.reflect.Array;
import java.util.ArrayList;
@@ -27,7 +27,6 @@ import java.util.List;
import java.util.TreeSet;
import org.apache.commons.numbers.core.Precision;
-import org.apache.commons.math4.legacy.Field;
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.MathArithmeticException;
import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException;
@@ -40,6 +39,7 @@ import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException;
import org.apache.commons.math4.legacy.exception.NullArgumentException;
import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Arrays utilities.
@@ -196,7 +196,7 @@ public class MathArrays {
checkEqualLength(p1, p2);
double sum = 0;
for (int i = 0; i < p1.length; i++) {
- sum += FastMath.abs(p1[i] - p2[i]);
+ sum += AccurateMath.abs(p1[i] - p2[i]);
}
return sum;
}
@@ -213,7 +213,7 @@ public class MathArrays {
checkEqualLength(p1, p2);
int sum = 0;
for (int i = 0; i < p1.length; i++) {
- sum += FastMath.abs(p1[i] - p2[i]);
+ sum += AccurateMath.abs(p1[i] - p2[i]);
}
return sum;
}
@@ -233,7 +233,7 @@ public class MathArrays {
final double dp = p1[i] - p2[i];
sum += dp * dp;
}
- return FastMath.sqrt(sum);
+ return AccurateMath.sqrt(sum);
}
/**
@@ -251,7 +251,7 @@ public class MathArrays {
final double dp = p1[i] - p2[i];
sum += dp * dp;
}
- return FastMath.sqrt(sum);
+ return AccurateMath.sqrt(sum);
}
/**
@@ -266,7 +266,7 @@ public class MathArrays {
checkEqualLength(p1, p2);
double max = 0;
for (int i = 0; i < p1.length; i++) {
- max = FastMath.max(max, FastMath.abs(p1[i] - p2[i]));
+ max = AccurateMath.max(max, AccurateMath.abs(p1[i] - p2[i]));
}
return max;
}
@@ -283,7 +283,7 @@ public class MathArrays {
checkEqualLength(p1, p2);
int max = 0;
for (int i = 0; i < p1.length; i++) {
- max = FastMath.max(max, FastMath.abs(p1[i] - p2[i]));
+ max = AccurateMath.max(max, AccurateMath.abs(p1[i] - p2[i]));
}
return max;
}
@@ -990,7 +990,7 @@ public class MathArrays {
// straightforward implementation of the convolution sum
for (int n = 0; n < totalLength; n++) {
double yn = 0;
- int k = FastMath.max(0, n + 1 - xLen);
+ int k = AccurateMath.max(0, n + 1 - xLen);
int j = n - k;
while (k < hLen && j >= 0) {
yn += x[j--] * h[k++];
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/RealFieldElement.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/RealFieldElement.java
similarity index 99%
rename from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/RealFieldElement.java
rename to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/RealFieldElement.java
index 1bce77b..2d8b0a4 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/RealFieldElement.java
+++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/RealFieldElement.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.math4.legacy;
+package org.apache.commons.math4.legacy.core;
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/dfp/Dfp.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/Dfp.java
similarity index 99%
rename from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/dfp/Dfp.java
rename to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/Dfp.java
index 3daefad..d6ece89 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/dfp/Dfp.java
+++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/Dfp.java
@@ -15,13 +15,12 @@
* limitations under the License.
*/
-package org.apache.commons.math4.legacy.dfp;
+package org.apache.commons.math4.legacy.core.dfp;
import java.util.Arrays;
-import org.apache.commons.math4.legacy.RealFieldElement;
+import org.apache.commons.math4.legacy.core.RealFieldElement;
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
-import org.apache.commons.math4.legacy.util.FastMath;
/**
* Decimal floating point library for Java
@@ -625,12 +624,12 @@ public class Dfp implements RealFieldElement<Dfp> {
return field.newDfp(sig, code);
}
- /** Get the {@link org.apache.commons.math4.legacy.Field Field} (really a {@link DfpField}) to which the instance belongs.
+ /** Get the {@link org.apache.commons.math4.legacy.core.Field Field} (really a {@link DfpField}) to which the instance belongs.
* <p>
* The field is linked to the number of digits and acts as a factory
* for {@link Dfp} instances.
* </p>
- * @return {@link org.apache.commons.math4.legacy.Field Field} (really a {@link DfpField}) to which the instance belongs
+ * @return {@link org.apache.commons.math4.legacy.core.Field Field} (really a {@link DfpField}) to which the instance belongs
*/
@Override
public DfpField getField() {
@@ -2579,7 +2578,7 @@ public class Dfp implements RealFieldElement<Dfp> {
*/
@Override
public long round() {
- return FastMath.round(toDouble());
+ return Math.round(toDouble());
}
/** {@inheritDoc}
@@ -2782,7 +2781,7 @@ public class Dfp implements RealFieldElement<Dfp> {
// compute atan2(y, x) = +/- pi - 2 atan(y / (r - x))
final Dfp tmp = getTwo().multiply(divide(r.subtract(x)).atan());
- final Dfp pmPi = newInstance((tmp.sign <= 0) ? -FastMath.PI : FastMath.PI);
+ final Dfp pmPi = newInstance((tmp.sign <= 0) ? -Math.PI : Math.PI);
return pmPi.subtract(tmp);
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/dfp/DfpDec.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/DfpDec.java
similarity index 99%
rename from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/dfp/DfpDec.java
rename to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/DfpDec.java
index c42003bc..4e12053 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/dfp/DfpDec.java
+++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/DfpDec.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.commons.math4.legacy.dfp;
+package org.apache.commons.math4.legacy.core.dfp;
/** Subclass of {@link Dfp} which hides the radix-10000 artifacts of the superclass.
* This should give outward appearances of being a decimal number with DIGITS*4-3
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/dfp/DfpField.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/DfpField.java
similarity index 99%
rename from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/dfp/DfpField.java
rename to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/DfpField.java
index fd4ae54..10b30cd 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/dfp/DfpField.java
+++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/DfpField.java
@@ -15,10 +15,10 @@
* limitations under the License.
*/
-package org.apache.commons.math4.legacy.dfp;
+package org.apache.commons.math4.legacy.core.dfp;
-import org.apache.commons.math4.legacy.Field;
-import org.apache.commons.math4.legacy.FieldElement;
+import org.apache.commons.math4.legacy.core.Field;
+import org.apache.commons.math4.legacy.core.FieldElement;
/** Field for Decimal floating point instances.
* @since 2.2
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/dfp/DfpMath.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/DfpMath.java
similarity index 99%
rename from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/dfp/DfpMath.java
rename to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/DfpMath.java
index 81eb2a6..b1b9856 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/dfp/DfpMath.java
+++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/DfpMath.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.commons.math4.legacy.dfp;
+package org.apache.commons.math4.legacy.core.dfp;
/** Mathematical routines for use with {@link Dfp}.
* The constants are defined in {@link DfpField}
diff --git a/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/package-info.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/package-info.java
new file mode 100644
index 0000000..f9186c4
--- /dev/null
+++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/package-info.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (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
+ *
+ * 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.
+ */
+/**
+ *
+ * Decimal floating point library for Java
+ *
+ * <p>Another floating point class. This one is built using radix 10000
+ * which is 10<sup>4</sup>, so its almost decimal.</p>
+ *
+ * <p>The design goals here are:
+ * <ol>
+ * <li>Decimal math, or close to it</li>
+ * <li>Settable precision (but no mix between numbers using different settings)</li>
+ * <li>Portability. Code should be keep as portable as possible.</li>
+ * <li>Performance</li>
+ * <li>Accuracy - Results should always be +/- 1 ULP for basic
+ * algebraic operation</li>
+ * <li>Comply with IEEE 854-1987 as much as possible.
+ * (See IEEE 854-1987 notes below)</li>
+ * </ol>
+ *
+ * <p>Trade offs:
+ * <ol>
+ * <li>Memory foot print. I'm using more memory than necessary to
+ * represent numbers to get better performance.</li>
+ * <li>Digits are bigger, so rounding is a greater loss. So, if you
+ * really need 12 decimal digits, better use 4 base 10000 digits
+ * there can be one partially filled.</li>
+ * </ol>
+ *
+ * <p>Numbers are represented in the following form:
+ * <div style="white-space: pre"><code>
+ * n = sign × mant × (radix)<sup>exp</sup>;
+ * </code></div>
+ * where sign is ±1, mantissa represents a fractional number between
+ * zero and one. mant[0] is the least significant digit.
+ * exp is in the range of -32767 to 32768
+ *
+ * <p>IEEE 854-1987 Notes and differences</p>
+ *
+ * <p>IEEE 854 requires the radix to be either 2 or 10. The radix here is
+ * 10000, so that requirement is not met, but it is possible that a
+ * subclassed can be made to make it behave as a radix 10
+ * number. It is my opinion that if it looks and behaves as a radix
+ * 10 number then it is one and that requirement would be met.</p>
+ *
+ * <p>The radix of 10000 was chosen because it should be faster to operate
+ * on 4 decimal digits at once instead of one at a time. Radix 10 behavior
+ * can be realized by add an additional rounding step to ensure that
+ * the number of decimal digits represented is constant.</p>
+ *
+ * <p>The IEEE standard specifically leaves out internal data encoding,
+ * so it is reasonable to conclude that such a subclass of this radix
+ * 10000 system is merely an encoding of a radix 10 system.</p>
+ *
+ * <p>IEEE 854 also specifies the existence of "sub-normal" numbers. This
+ * class does not contain any such entities. The most significant radix
+ * 10000 digit is always non-zero. Instead, we support "gradual underflow"
+ * by raising the underflow flag for numbers less with exponent less than
+ * expMin, but don't flush to zero until the exponent reaches MIN_EXP-digits.
+ * Thus the smallest number we can represent would be:
+ * 1E(-(MIN_EXP-digits-1)∗4), eg, for digits=5, MIN_EXP=-32767, that would
+ * be 1e-131092.</p>
+ *
+ * <p>IEEE 854 defines that the implied radix point lies just to the right
+ * of the most significant digit and to the left of the remaining digits.
+ * This implementation puts the implied radix point to the left of all
+ * digits including the most significant one. The most significant digit
+ * here is the one just to the right of the radix point. This is a fine
+ * detail and is really only a matter of definition. Any side effects of
+ * this can be rendered invisible by a subclass.</p>
+ *
+ */
+package org.apache.commons.math4.legacy.core.dfp;
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMath.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMath.java
similarity index 97%
copy from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMath.java
copy to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMath.java
index 07175f4..a6307fb 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMath.java
+++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMath.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.math4.legacy.util;
+package org.apache.commons.math4.legacy.core.jdkmath;
import java.io.PrintStream;
@@ -25,36 +25,36 @@ import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
/**
* Portable alternative to {@link Math} and {@link StrictMath}.
* <p>
- * Caveat: At the time of implementation, the {@code FastMath} functions
+ * Caveat: At the time of implementation, the {@code AccurateMath} functions
* were often faster and/or more accurate than their JDK equivalent.
* Nowadays, it would not be surprising that they are always slower (due
* to the various JVM optimizations that have appeared since Java 5).
* However, any change to this class should ensure that the current
* accuracy is not lost.
* <p>
- * FastMath is a drop-in replacement for both Math and StrictMath. This
+ * AccurateMath is a drop-in replacement for both Math and StrictMath. This
* means that for any method in Math (say {@code Math.sin(x)} or
* {@code Math.cbrt(y)}), user can directly change the class and use the
- * methods as is (using {@code FastMath.sin(x)} or {@code FastMath.cbrt(y)}
+ * methods as is (using {@code AccurateMath.sin(x)} or {@code AccurateMath.cbrt(y)}
* in the previous example).
* </p>
* <p>
- * FastMath speed is achieved by relying heavily on optimizing compilers
+ * AccurateMath 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 initialized on first use, so that the setup
* time does not penalize methods that don't need them.
* </p>
* <p>
- * Note that FastMath is
+ * Note that AccurateMath is
* extensively used inside Apache Commons Math, so by calling some algorithms,
* the overhead when the tables need to be initialized will occur
- * regardless of the end-user calling FastMath methods directly or not.
+ * regardless of the end-user calling AccurateMath methods directly or not.
* Performance figures for a specific JVM and hardware can be evaluated by
- * running the FastMathTestPerformance tests in the test directory of the source
+ * running the AccurateMathTestPerformance tests in the test directory of the source
* distribution.
* </p>
* <p>
- * FastMath accuracy should be mostly independent of the JVM as it relies only
+ * AccurateMath accuracy should be mostly independent of the JVM as it relies only
* on IEEE-754 basic operations and on embedded tables. Almost all operations
* are accurate to about 0.5 ulp throughout the domain range. This statement,
* of course is only a rough global observed behavior, it is <em>not</em> a
@@ -63,14 +63,14 @@ import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
* Maker's Dilemma</a>).
* </p>
* <p>
- * FastMath additionally implements the following methods not found in Math/StrictMath:
+ * AccurateMath additionally implements the following methods not found in Math/StrictMath:
* <ul>
* <li>{@link #asinh(double)}</li>
* <li>{@link #acosh(double)}</li>
* <li>{@link #atanh(double)}</li>
* </ul>
* The following methods are found in Math/StrictMath since 1.6 only, they are provided
- * by FastMath even in 1.5 Java virtual machines
+ * by AccurateMath even in 1.5 Java virtual machines
* <ul>
* <li>{@link #copySign(double, double)}</li>
* <li>{@link #getExponent(double)}</li>
@@ -85,7 +85,7 @@ import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
* </ul>
* @since 2.2
*/
-public class FastMath {
+public class AccurateMath {
/** Archimede's constant PI, ratio of circle circumference to diameter. */
public static final double PI = 105414357.0 / 33554432.0 + 1.984187159361080883e-9;
@@ -371,7 +371,7 @@ public class FastMath {
/**
* Private Constructor
*/
- private FastMath() {}
+ private AccurateMath() {}
// Generic helper methods
@@ -723,7 +723,7 @@ public class FastMath {
* @return inverse hyperbolic cosine of a
*/
public static double acosh(final double a) {
- return FastMath.log(a + FastMath.sqrt(a * a - 1));
+ return AccurateMath.log(a + AccurateMath.sqrt(a * a - 1));
}
/** Compute the inverse hyperbolic sine of a number.
@@ -739,7 +739,7 @@ public class FastMath {
double absAsinh;
if (a > 0.167) {
- absAsinh = FastMath.log(FastMath.sqrt(a * a + 1) + a);
+ absAsinh = AccurateMath.log(AccurateMath.sqrt(a * a + 1) + a);
} else {
final double a2 = a * a;
if (a > 0.097) {
@@ -769,7 +769,7 @@ public class FastMath {
double absAtanh;
if (a > 0.15) {
- absAtanh = 0.5 * FastMath.log((1 + a) / (1 - a));
+ absAtanh = 0.5 * AccurateMath.log((1 + a) / (1 - a));
} else {
final double a2 = a * a;
if (a > 0.087) {
@@ -1536,13 +1536,13 @@ public class FastMath {
if ((yFullMantissa & integralMask) == yFullMantissa) {
// all fractional bits are 0, the number is really integral
final long l = yFullMantissa >> (1075 - yRawExp);
- return FastMath.pow(x, (y < 0) ? -l : l);
+ return AccurateMath.pow(x, (y < 0) ? -l : l);
}
} else {
// normal number with positive shift, always an integral value
// we know it fits in a primitive long because yRawExp > 1085 has been handled above
final long l = yFullMantissa << (yRawExp - 1075);
- return FastMath.pow(x, (y < 0) ? -l : l);
+ return AccurateMath.pow(x, (y < 0) ? -l : l);
}
}
@@ -1754,8 +1754,8 @@ public class FastMath {
} else {
// some intermediate numbers exceeded capacity,
// and the low order bits became NaN (because infinity - infinity = NaN)
- if (FastMath.abs(full) < 1) {
- return new Split(FastMath.copySign(0.0, full), 0.0);
+ if (AccurateMath.abs(full) < 1) {
+ return new Split(AccurateMath.copySign(0.0, full), 0.0);
} else if (full < 0 && (e & 0x1) == 1) {
return Split.NEGATIVE_INFINITY;
} else {
@@ -3778,9 +3778,9 @@ public class FastMath {
}
} else {
// we are in the general case
- final double n = FastMath.rint(dividend / divisor);
+ final double n = AccurateMath.rint(dividend / divisor);
final double remainder = Double.isInfinite(n) ? 0.0 : dividend - divisor * n;
- return (remainder == 0) ? FastMath.copySign(remainder, dividend) : remainder;
+ return (remainder == 0) ? AccurateMath.copySign(remainder, dividend) : remainder;
}
}
@@ -4174,17 +4174,17 @@ public class FastMath {
*/
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);
+ AccurateMathCalc.printarray(out, "EXP_INT_TABLE_A", EXP_INT_TABLE_LEN, ExpIntTable.EXP_INT_TABLE_A);
+ AccurateMathCalc.printarray(out, "EXP_INT_TABLE_B", EXP_INT_TABLE_LEN, ExpIntTable.EXP_INT_TABLE_B);
+ AccurateMathCalc.printarray(out, "EXP_FRAC_TABLE_A", EXP_FRAC_TABLE_LEN, ExpFracTable.EXP_FRAC_TABLE_A);
+ AccurateMathCalc.printarray(out, "EXP_FRAC_TABLE_B", EXP_FRAC_TABLE_LEN, ExpFracTable.EXP_FRAC_TABLE_B);
+ AccurateMathCalc.printarray(out, "LN_MANT",LN_MANT_LEN, lnMant.LN_MANT);
+ AccurateMathCalc.printarray(out, "SINE_TABLE_A", SINE_TABLE_LEN, SINE_TABLE_A);
+ AccurateMathCalc.printarray(out, "SINE_TABLE_B", SINE_TABLE_LEN, SINE_TABLE_B);
+ AccurateMathCalc.printarray(out, "COSINE_TABLE_A", SINE_TABLE_LEN, COSINE_TABLE_A);
+ AccurateMathCalc.printarray(out, "COSINE_TABLE_B", SINE_TABLE_LEN, COSINE_TABLE_B);
+ AccurateMathCalc.printarray(out, "TANGENT_TABLE_A", SINE_TABLE_LEN, TANGENT_TABLE_A);
+ AccurateMathCalc.printarray(out, "TANGENT_TABLE_B", SINE_TABLE_LEN, TANGENT_TABLE_B);
}
/** Enclose large data table in nested static class so it's only loaded on first access. */
@@ -4200,28 +4200,28 @@ public class FastMath {
static {
if (RECOMPUTE_TABLES_AT_RUNTIME) {
- EXP_INT_TABLE_A = new double[FastMath.EXP_INT_TABLE_LEN];
- EXP_INT_TABLE_B = new double[FastMath.EXP_INT_TABLE_LEN];
+ EXP_INT_TABLE_A = new double[AccurateMath.EXP_INT_TABLE_LEN];
+ EXP_INT_TABLE_B = new double[AccurateMath.EXP_INT_TABLE_LEN];
final double tmp[] = new double[2];
final double recip[] = new double[2];
// Populate expIntTable
- for (int i = 0; i < FastMath.EXP_INT_TABLE_MAX_INDEX; i++) {
- FastMathCalc.expint(i, tmp);
- EXP_INT_TABLE_A[i + FastMath.EXP_INT_TABLE_MAX_INDEX] = tmp[0];
- EXP_INT_TABLE_B[i + FastMath.EXP_INT_TABLE_MAX_INDEX] = tmp[1];
+ for (int i = 0; i < AccurateMath.EXP_INT_TABLE_MAX_INDEX; i++) {
+ AccurateMathCalc.expint(i, tmp);
+ EXP_INT_TABLE_A[i + AccurateMath.EXP_INT_TABLE_MAX_INDEX] = tmp[0];
+ EXP_INT_TABLE_B[i + AccurateMath.EXP_INT_TABLE_MAX_INDEX] = tmp[1];
if (i != 0) {
// Negative integer powers
- FastMathCalc.splitReciprocal(tmp, recip);
- EXP_INT_TABLE_A[FastMath.EXP_INT_TABLE_MAX_INDEX - i] = recip[0];
- EXP_INT_TABLE_B[FastMath.EXP_INT_TABLE_MAX_INDEX - i] = recip[1];
+ AccurateMathCalc.splitReciprocal(tmp, recip);
+ EXP_INT_TABLE_A[AccurateMath.EXP_INT_TABLE_MAX_INDEX - i] = recip[0];
+ EXP_INT_TABLE_B[AccurateMath.EXP_INT_TABLE_MAX_INDEX - i] = recip[1];
}
}
} else {
- EXP_INT_TABLE_A = FastMathLiteralArrays.loadExpIntA();
- EXP_INT_TABLE_B = FastMathLiteralArrays.loadExpIntB();
+ EXP_INT_TABLE_A = AccurateMathLiteralArrays.loadExpIntA();
+ EXP_INT_TABLE_B = AccurateMathLiteralArrays.loadExpIntB();
}
}
}
@@ -4240,21 +4240,21 @@ public class FastMath {
static {
if (RECOMPUTE_TABLES_AT_RUNTIME) {
- EXP_FRAC_TABLE_A = new double[FastMath.EXP_FRAC_TABLE_LEN];
- EXP_FRAC_TABLE_B = new double[FastMath.EXP_FRAC_TABLE_LEN];
+ EXP_FRAC_TABLE_A = new double[AccurateMath.EXP_FRAC_TABLE_LEN];
+ EXP_FRAC_TABLE_B = new double[AccurateMath.EXP_FRAC_TABLE_LEN];
final double tmp[] = new double[2];
// Populate expFracTable
final double factor = 1d / (EXP_FRAC_TABLE_LEN - 1);
for (int i = 0; i < EXP_FRAC_TABLE_A.length; i++) {
- FastMathCalc.slowexp(i * factor, tmp);
+ AccurateMathCalc.slowexp(i * factor, tmp);
EXP_FRAC_TABLE_A[i] = tmp[0];
EXP_FRAC_TABLE_B[i] = tmp[1];
}
} else {
- EXP_FRAC_TABLE_A = FastMathLiteralArrays.loadExpFracA();
- EXP_FRAC_TABLE_B = FastMathLiteralArrays.loadExpFracB();
+ EXP_FRAC_TABLE_A = AccurateMathLiteralArrays.loadExpFracA();
+ EXP_FRAC_TABLE_B = AccurateMathLiteralArrays.loadExpFracB();
}
}
}
@@ -4266,15 +4266,15 @@ public class FastMath {
static {
if (RECOMPUTE_TABLES_AT_RUNTIME) {
- LN_MANT = new double[FastMath.LN_MANT_LEN][];
+ LN_MANT = new double[AccurateMath.LN_MANT_LEN][];
// Populate lnMant table
for (int i = 0; i < LN_MANT.length; i++) {
final double d = Double.longBitsToDouble( (((long) i) << 42) | 0x3ff0000000000000L );
- LN_MANT[i] = FastMathCalc.slowLog(d);
+ LN_MANT[i] = AccurateMathCalc.slowLog(d);
}
} else {
- LN_MANT = FastMathLiteralArrays.loadLnMant();
+ LN_MANT = AccurateMathLiteralArrays.loadLnMant();
}
}
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMath.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMath.java.bak
similarity index 97%
rename from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMath.java
rename to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMath.java.bak
index 07175f4..7a39abc 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMath.java
+++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMath.java.bak
@@ -25,36 +25,36 @@ import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
/**
* Portable alternative to {@link Math} and {@link StrictMath}.
* <p>
- * Caveat: At the time of implementation, the {@code FastMath} functions
+ * Caveat: At the time of implementation, the {@code AccurateMath} functions
* were often faster and/or more accurate than their JDK equivalent.
* Nowadays, it would not be surprising that they are always slower (due
* to the various JVM optimizations that have appeared since Java 5).
* However, any change to this class should ensure that the current
* accuracy is not lost.
* <p>
- * FastMath is a drop-in replacement for both Math and StrictMath. This
+ * AccurateMath is a drop-in replacement for both Math and StrictMath. This
* means that for any method in Math (say {@code Math.sin(x)} or
* {@code Math.cbrt(y)}), user can directly change the class and use the
- * methods as is (using {@code FastMath.sin(x)} or {@code FastMath.cbrt(y)}
+ * methods as is (using {@code AccurateMath.sin(x)} or {@code AccurateMath.cbrt(y)}
* in the previous example).
* </p>
* <p>
- * FastMath speed is achieved by relying heavily on optimizing compilers
+ * AccurateMath 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 initialized on first use, so that the setup
* time does not penalize methods that don't need them.
* </p>
* <p>
- * Note that FastMath is
+ * Note that AccurateMath is
* extensively used inside Apache Commons Math, so by calling some algorithms,
* the overhead when the tables need to be initialized will occur
- * regardless of the end-user calling FastMath methods directly or not.
+ * regardless of the end-user calling AccurateMath methods directly or not.
* Performance figures for a specific JVM and hardware can be evaluated by
- * running the FastMathTestPerformance tests in the test directory of the source
+ * running the AccurateMathTestPerformance tests in the test directory of the source
* distribution.
* </p>
* <p>
- * FastMath accuracy should be mostly independent of the JVM as it relies only
+ * AccurateMath accuracy should be mostly independent of the JVM as it relies only
* on IEEE-754 basic operations and on embedded tables. Almost all operations
* are accurate to about 0.5 ulp throughout the domain range. This statement,
* of course is only a rough global observed behavior, it is <em>not</em> a
@@ -63,14 +63,14 @@ import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
* Maker's Dilemma</a>).
* </p>
* <p>
- * FastMath additionally implements the following methods not found in Math/StrictMath:
+ * AccurateMath additionally implements the following methods not found in Math/StrictMath:
* <ul>
* <li>{@link #asinh(double)}</li>
* <li>{@link #acosh(double)}</li>
* <li>{@link #atanh(double)}</li>
* </ul>
* The following methods are found in Math/StrictMath since 1.6 only, they are provided
- * by FastMath even in 1.5 Java virtual machines
+ * by AccurateMath even in 1.5 Java virtual machines
* <ul>
* <li>{@link #copySign(double, double)}</li>
* <li>{@link #getExponent(double)}</li>
@@ -85,7 +85,7 @@ import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
* </ul>
* @since 2.2
*/
-public class FastMath {
+public class AccurateMath {
/** Archimede's constant PI, ratio of circle circumference to diameter. */
public static final double PI = 105414357.0 / 33554432.0 + 1.984187159361080883e-9;
@@ -371,7 +371,7 @@ public class FastMath {
/**
* Private Constructor
*/
- private FastMath() {}
+ private AccurateMath() {}
// Generic helper methods
@@ -723,7 +723,7 @@ public class FastMath {
* @return inverse hyperbolic cosine of a
*/
public static double acosh(final double a) {
- return FastMath.log(a + FastMath.sqrt(a * a - 1));
+ return AccurateMath.log(a + AccurateMath.sqrt(a * a - 1));
}
/** Compute the inverse hyperbolic sine of a number.
@@ -739,7 +739,7 @@ public class FastMath {
double absAsinh;
if (a > 0.167) {
- absAsinh = FastMath.log(FastMath.sqrt(a * a + 1) + a);
+ absAsinh = AccurateMath.log(AccurateMath.sqrt(a * a + 1) + a);
} else {
final double a2 = a * a;
if (a > 0.097) {
@@ -769,7 +769,7 @@ public class FastMath {
double absAtanh;
if (a > 0.15) {
- absAtanh = 0.5 * FastMath.log((1 + a) / (1 - a));
+ absAtanh = 0.5 * AccurateMath.log((1 + a) / (1 - a));
} else {
final double a2 = a * a;
if (a > 0.087) {
@@ -1536,13 +1536,13 @@ public class FastMath {
if ((yFullMantissa & integralMask) == yFullMantissa) {
// all fractional bits are 0, the number is really integral
final long l = yFullMantissa >> (1075 - yRawExp);
- return FastMath.pow(x, (y < 0) ? -l : l);
+ return AccurateMath.pow(x, (y < 0) ? -l : l);
}
} else {
// normal number with positive shift, always an integral value
// we know it fits in a primitive long because yRawExp > 1085 has been handled above
final long l = yFullMantissa << (yRawExp - 1075);
- return FastMath.pow(x, (y < 0) ? -l : l);
+ return AccurateMath.pow(x, (y < 0) ? -l : l);
}
}
@@ -1754,8 +1754,8 @@ public class FastMath {
} else {
// some intermediate numbers exceeded capacity,
// and the low order bits became NaN (because infinity - infinity = NaN)
- if (FastMath.abs(full) < 1) {
- return new Split(FastMath.copySign(0.0, full), 0.0);
+ if (AccurateMath.abs(full) < 1) {
+ return new Split(AccurateMath.copySign(0.0, full), 0.0);
} else if (full < 0 && (e & 0x1) == 1) {
return Split.NEGATIVE_INFINITY;
} else {
@@ -3778,9 +3778,9 @@ public class FastMath {
}
} else {
// we are in the general case
- final double n = FastMath.rint(dividend / divisor);
+ final double n = AccurateMath.rint(dividend / divisor);
final double remainder = Double.isInfinite(n) ? 0.0 : dividend - divisor * n;
- return (remainder == 0) ? FastMath.copySign(remainder, dividend) : remainder;
+ return (remainder == 0) ? AccurateMath.copySign(remainder, dividend) : remainder;
}
}
@@ -4174,17 +4174,17 @@ public class FastMath {
*/
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);
+ AccurateMathCalc.printarray(out, "EXP_INT_TABLE_A", EXP_INT_TABLE_LEN, ExpIntTable.EXP_INT_TABLE_A);
+ AccurateMathCalc.printarray(out, "EXP_INT_TABLE_B", EXP_INT_TABLE_LEN, ExpIntTable.EXP_INT_TABLE_B);
+ AccurateMathCalc.printarray(out, "EXP_FRAC_TABLE_A", EXP_FRAC_TABLE_LEN, ExpFracTable.EXP_FRAC_TABLE_A);
+ AccurateMathCalc.printarray(out, "EXP_FRAC_TABLE_B", EXP_FRAC_TABLE_LEN, ExpFracTable.EXP_FRAC_TABLE_B);
+ AccurateMathCalc.printarray(out, "LN_MANT",LN_MANT_LEN, lnMant.LN_MANT);
+ AccurateMathCalc.printarray(out, "SINE_TABLE_A", SINE_TABLE_LEN, SINE_TABLE_A);
+ AccurateMathCalc.printarray(out, "SINE_TABLE_B", SINE_TABLE_LEN, SINE_TABLE_B);
+ AccurateMathCalc.printarray(out, "COSINE_TABLE_A", SINE_TABLE_LEN, COSINE_TABLE_A);
+ AccurateMathCalc.printarray(out, "COSINE_TABLE_B", SINE_TABLE_LEN, COSINE_TABLE_B);
+ AccurateMathCalc.printarray(out, "TANGENT_TABLE_A", SINE_TABLE_LEN, TANGENT_TABLE_A);
+ AccurateMathCalc.printarray(out, "TANGENT_TABLE_B", SINE_TABLE_LEN, TANGENT_TABLE_B);
}
/** Enclose large data table in nested static class so it's only loaded on first access. */
@@ -4200,28 +4200,28 @@ public class FastMath {
static {
if (RECOMPUTE_TABLES_AT_RUNTIME) {
- EXP_INT_TABLE_A = new double[FastMath.EXP_INT_TABLE_LEN];
- EXP_INT_TABLE_B = new double[FastMath.EXP_INT_TABLE_LEN];
+ EXP_INT_TABLE_A = new double[AccurateMath.EXP_INT_TABLE_LEN];
+ EXP_INT_TABLE_B = new double[AccurateMath.EXP_INT_TABLE_LEN];
final double tmp[] = new double[2];
final double recip[] = new double[2];
// Populate expIntTable
- for (int i = 0; i < FastMath.EXP_INT_TABLE_MAX_INDEX; i++) {
- FastMathCalc.expint(i, tmp);
- EXP_INT_TABLE_A[i + FastMath.EXP_INT_TABLE_MAX_INDEX] = tmp[0];
- EXP_INT_TABLE_B[i + FastMath.EXP_INT_TABLE_MAX_INDEX] = tmp[1];
+ for (int i = 0; i < AccurateMath.EXP_INT_TABLE_MAX_INDEX; i++) {
+ AccurateMathCalc.expint(i, tmp);
+ EXP_INT_TABLE_A[i + AccurateMath.EXP_INT_TABLE_MAX_INDEX] = tmp[0];
+ EXP_INT_TABLE_B[i + AccurateMath.EXP_INT_TABLE_MAX_INDEX] = tmp[1];
if (i != 0) {
// Negative integer powers
- FastMathCalc.splitReciprocal(tmp, recip);
- EXP_INT_TABLE_A[FastMath.EXP_INT_TABLE_MAX_INDEX - i] = recip[0];
- EXP_INT_TABLE_B[FastMath.EXP_INT_TABLE_MAX_INDEX - i] = recip[1];
+ AccurateMathCalc.splitReciprocal(tmp, recip);
+ EXP_INT_TABLE_A[AccurateMath.EXP_INT_TABLE_MAX_INDEX - i] = recip[0];
+ EXP_INT_TABLE_B[AccurateMath.EXP_INT_TABLE_MAX_INDEX - i] = recip[1];
}
}
} else {
- EXP_INT_TABLE_A = FastMathLiteralArrays.loadExpIntA();
- EXP_INT_TABLE_B = FastMathLiteralArrays.loadExpIntB();
+ EXP_INT_TABLE_A = AccurateMathLiteralArrays.loadExpIntA();
+ EXP_INT_TABLE_B = AccurateMathLiteralArrays.loadExpIntB();
}
}
}
@@ -4240,21 +4240,21 @@ public class FastMath {
static {
if (RECOMPUTE_TABLES_AT_RUNTIME) {
- EXP_FRAC_TABLE_A = new double[FastMath.EXP_FRAC_TABLE_LEN];
- EXP_FRAC_TABLE_B = new double[FastMath.EXP_FRAC_TABLE_LEN];
+ EXP_FRAC_TABLE_A = new double[AccurateMath.EXP_FRAC_TABLE_LEN];
+ EXP_FRAC_TABLE_B = new double[AccurateMath.EXP_FRAC_TABLE_LEN];
final double tmp[] = new double[2];
// Populate expFracTable
final double factor = 1d / (EXP_FRAC_TABLE_LEN - 1);
for (int i = 0; i < EXP_FRAC_TABLE_A.length; i++) {
- FastMathCalc.slowexp(i * factor, tmp);
+ AccurateMathCalc.slowexp(i * factor, tmp);
EXP_FRAC_TABLE_A[i] = tmp[0];
EXP_FRAC_TABLE_B[i] = tmp[1];
}
} else {
- EXP_FRAC_TABLE_A = FastMathLiteralArrays.loadExpFracA();
- EXP_FRAC_TABLE_B = FastMathLiteralArrays.loadExpFracB();
+ EXP_FRAC_TABLE_A = AccurateMathLiteralArrays.loadExpFracA();
+ EXP_FRAC_TABLE_B = AccurateMathLiteralArrays.loadExpFracB();
}
}
}
@@ -4266,15 +4266,15 @@ public class FastMath {
static {
if (RECOMPUTE_TABLES_AT_RUNTIME) {
- LN_MANT = new double[FastMath.LN_MANT_LEN][];
+ LN_MANT = new double[AccurateMath.LN_MANT_LEN][];
// Populate lnMant table
for (int i = 0; i < LN_MANT.length; i++) {
final double d = Double.longBitsToDouble( (((long) i) << 42) | 0x3ff0000000000000L );
- LN_MANT[i] = FastMathCalc.slowLog(d);
+ LN_MANT[i] = AccurateMathCalc.slowLog(d);
}
} else {
- LN_MANT = FastMathLiteralArrays.loadLnMant();
+ LN_MANT = AccurateMathLiteralArrays.loadLnMant();
}
}
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMathCalc.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathCalc.java
similarity index 99%
copy from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMathCalc.java
copy to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathCalc.java
index 342d4b2..bb189f2 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMathCalc.java
+++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathCalc.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.math4.legacy.util;
+package org.apache.commons.math4.legacy.core.jdkmath;
import java.io.PrintStream;
@@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
/** Class used to compute the classical functions tables.
* @since 3.0
*/
-class FastMathCalc {
+class AccurateMathCalc {
/**
* 0x40000000 - used to split a double into two parts, both with the low order bits cleared.
@@ -85,7 +85,7 @@ class FastMathCalc {
/**
* Private Constructor.
*/
- private FastMathCalc() {
+ private AccurateMathCalc() {
}
/** Build the sine and cosine tables.
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMathCalc.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathCalc.java.bak
similarity index 99%
rename from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMathCalc.java
rename to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathCalc.java.bak
index 342d4b2..13ff2f1 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMathCalc.java
+++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathCalc.java.bak
@@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
/** Class used to compute the classical functions tables.
* @since 3.0
*/
-class FastMathCalc {
+class AccurateMathCalc {
/**
* 0x40000000 - used to split a double into two parts, both with the low order bits cleared.
@@ -85,7 +85,7 @@ class FastMathCalc {
/**
* Private Constructor.
*/
- private FastMathCalc() {
+ private AccurateMathCalc() {
}
/** Build the sine and cosine tables.
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMathLiteralArrays.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathLiteralArrays.java
similarity index 99%
copy from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMathLiteralArrays.java
copy to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathLiteralArrays.java
index d4cc666..6461eac 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMathLiteralArrays.java
+++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathLiteralArrays.java
@@ -15,13 +15,13 @@
* limitations under the License.
*/
-package org.apache.commons.math4.legacy.util;
+package org.apache.commons.math4.legacy.core.jdkmath;
/**
- * Utility class for loading tabulated data used by {@link FastMath}.
+ * Utility class for loading tabulated data used by {@link AccurateMath}.
*
*/
-class FastMathLiteralArrays {
+class AccurateMathLiteralArrays {
/** Exponential evaluated at integer values,
* exp(x) = expIntTableA[x + EXP_INT_TABLE_MAX_INDEX] + expIntTableB[x+EXP_INT_TABLE_MAX_INDEX].
*/
@@ -6130,7 +6130,7 @@ class FastMathLiteralArrays {
/**
* Class contains only static methods.
*/
- private FastMathLiteralArrays() {}
+ private AccurateMathLiteralArrays() {}
/**
* Load "EXP_INT_A".
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMathLiteralArrays.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathLiteralArrays.java.bak
similarity index 99%
rename from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMathLiteralArrays.java
rename to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathLiteralArrays.java.bak
index d4cc666..1767ddf 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMathLiteralArrays.java
+++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathLiteralArrays.java.bak
@@ -18,10 +18,10 @@
package org.apache.commons.math4.legacy.util;
/**
- * Utility class for loading tabulated data used by {@link FastMath}.
+ * Utility class for loading tabulated data used by {@link AccurateMath}.
*
*/
-class FastMathLiteralArrays {
+class AccurateMathLiteralArrays {
/** Exponential evaluated at integer values,
* exp(x) = expIntTableA[x + EXP_INT_TABLE_MAX_INDEX] + expIntTableB[x+EXP_INT_TABLE_MAX_INDEX].
*/
@@ -6130,7 +6130,7 @@ class FastMathLiteralArrays {
/**
* Class contains only static methods.
*/
- private FastMathLiteralArrays() {}
+ private AccurateMathLiteralArrays() {}
/**
* Load "EXP_INT_A".
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/ExtendedFieldElementAbstractTest.java b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/ExtendedFieldElementAbstractTest.java
similarity index 83%
copy from commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/ExtendedFieldElementAbstractTest.java
copy to commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/ExtendedFieldElementAbstractTest.java
index dde0c5b..7f5087c 100644
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/ExtendedFieldElementAbstractTest.java
+++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/ExtendedFieldElementAbstractTest.java
@@ -14,15 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.math4.legacy;
+package org.apache.commons.math4.legacy.core;
+
+import org.junit.Assert;
+import org.junit.Test;
import org.apache.commons.numbers.arrays.LinearCombination;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.simple.RandomSource;
-import org.apache.commons.math4.legacy.util.FastMath;
-import org.apache.commons.math4.legacy.util.MathArrays;
-import org.junit.Assert;
-import org.junit.Test;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElement<T>> {
@@ -113,7 +113,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
public void testRemainderField() {
for (double x = -3; x < 3; x += 0.2) {
for (double y = -3; y < 3; y += 0.2) {
- checkRelative(FastMath.IEEEremainder(x, y), build(x).remainder(build(y)));
+ checkRelative(AccurateMath.IEEEremainder(x, y), build(x).remainder(build(y)));
}
}
}
@@ -122,7 +122,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
public void testRemainderDouble() {
for (double x = -3; x < 3; x += 0.2) {
for (double y = -3.2; y < 3.2; y += 0.25) {
- checkRelative(FastMath.IEEEremainder(x, y), build(x).remainder(y));
+ checkRelative(AccurateMath.IEEEremainder(x, y), build(x).remainder(y));
}
}
}
@@ -130,42 +130,42 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
@Test
public void testCos() {
for (double x = -0.9; x < 0.9; x += 0.05) {
- checkRelative(FastMath.cos(x), build(x).cos());
+ checkRelative(AccurateMath.cos(x), build(x).cos());
}
}
@Test
public void testAcos() {
for (double x = -0.9; x < 0.9; x += 0.05) {
- checkRelative(FastMath.acos(x), build(x).acos());
+ checkRelative(AccurateMath.acos(x), build(x).acos());
}
}
@Test
public void testSin() {
for (double x = -0.9; x < 0.9; x += 0.05) {
- checkRelative(FastMath.sin(x), build(x).sin());
+ checkRelative(AccurateMath.sin(x), build(x).sin());
}
}
@Test
public void testAsin() {
for (double x = -0.9; x < 0.9; x += 0.05) {
- checkRelative(FastMath.asin(x), build(x).asin());
+ checkRelative(AccurateMath.asin(x), build(x).asin());
}
}
@Test
public void testTan() {
for (double x = -0.9; x < 0.9; x += 0.05) {
- checkRelative(FastMath.tan(x), build(x).tan());
+ checkRelative(AccurateMath.tan(x), build(x).tan());
}
}
@Test
public void testAtan() {
for (double x = -0.9; x < 0.9; x += 0.05) {
- checkRelative(FastMath.atan(x), build(x).atan());
+ checkRelative(AccurateMath.atan(x), build(x).atan());
}
}
@@ -173,7 +173,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
public void testAtan2() {
for (double x = -3; x < 3; x += 0.2) {
for (double y = -3; y < 3; y += 0.2) {
- checkRelative(FastMath.atan2(x, y), build(x).atan2(build(y)));
+ checkRelative(AccurateMath.atan2(x, y), build(x).atan2(build(y)));
}
}
}
@@ -181,56 +181,56 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
@Test
public void testCosh() {
for (double x = -0.9; x < 0.9; x += 0.05) {
- checkRelative(FastMath.cosh(x), build(x).cosh());
+ checkRelative(AccurateMath.cosh(x), build(x).cosh());
}
}
@Test
public void testAcosh() {
for (double x = 1.1; x < 5.0; x += 0.05) {
- checkRelative(FastMath.acosh(x), build(x).acosh());
+ checkRelative(AccurateMath.acosh(x), build(x).acosh());
}
}
@Test
public void testSinh() {
for (double x = -0.9; x < 0.9; x += 0.05) {
- checkRelative(FastMath.sinh(x), build(x).sinh());
+ checkRelative(AccurateMath.sinh(x), build(x).sinh());
}
}
@Test
public void testAsinh() {
for (double x = -0.9; x < 0.9; x += 0.05) {
- checkRelative(FastMath.asinh(x), build(x).asinh());
+ checkRelative(AccurateMath.asinh(x), build(x).asinh());
}
}
@Test
public void testTanh() {
for (double x = -0.9; x < 0.9; x += 0.05) {
- checkRelative(FastMath.tanh(x), build(x).tanh());
+ checkRelative(AccurateMath.tanh(x), build(x).tanh());
}
}
@Test
public void testAtanh() {
for (double x = -0.9; x < 0.9; x += 0.05) {
- checkRelative(FastMath.atanh(x), build(x).atanh());
+ checkRelative(AccurateMath.atanh(x), build(x).atanh());
}
}
@Test
public void testSqrt() {
for (double x = 0.01; x < 0.9; x += 0.05) {
- checkRelative(FastMath.sqrt(x), build(x).sqrt());
+ checkRelative(AccurateMath.sqrt(x), build(x).sqrt());
}
}
@Test
public void testCbrt() {
for (double x = -0.9; x < 0.9; x += 0.05) {
- checkRelative(FastMath.cbrt(x), build(x).cbrt());
+ checkRelative(AccurateMath.cbrt(x), build(x).cbrt());
}
}
@@ -238,7 +238,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
public void testHypot() {
for (double x = -3; x < 3; x += 0.2) {
for (double y = -3; y < 3; y += 0.2) {
- checkRelative(FastMath.hypot(x, y), build(x).hypot(build(y)));
+ checkRelative(AccurateMath.hypot(x, y), build(x).hypot(build(y)));
}
}
}
@@ -249,10 +249,10 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
for (int n = 1; n < 5; ++n) {
if (x < 0) {
if (n % 2 == 1) {
- checkRelative(-FastMath.pow(-x, 1.0 / n), build(x).rootN(n));
+ checkRelative(-AccurateMath.pow(-x, 1.0 / n), build(x).rootN(n));
}
} else {
- checkRelative(FastMath.pow(x, 1.0 / n), build(x).rootN(n));
+ checkRelative(AccurateMath.pow(x, 1.0 / n), build(x).rootN(n));
}
}
}
@@ -262,7 +262,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
public void testPowField() {
for (double x = -0.9; x < 0.9; x += 0.05) {
for (double y = 0.1; y < 4; y += 0.2) {
- checkRelative(FastMath.pow(x, y), build(x).pow(build(y)));
+ checkRelative(AccurateMath.pow(x, y), build(x).pow(build(y)));
}
}
}
@@ -271,7 +271,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
public void testPowDouble() {
for (double x = -0.9; x < 0.9; x += 0.05) {
for (double y = 0.1; y < 4; y += 0.2) {
- checkRelative(FastMath.pow(x, y), build(x).pow(y));
+ checkRelative(AccurateMath.pow(x, y), build(x).pow(y));
}
}
}
@@ -280,7 +280,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
public void testPowInt() {
for (double x = -0.9; x < 0.9; x += 0.05) {
for (int n = 0; n < 5; ++n) {
- checkRelative(FastMath.pow(x, n), build(x).pow(n));
+ checkRelative(AccurateMath.pow(x, n), build(x).pow(n));
}
}
}
@@ -288,28 +288,28 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
@Test
public void testExp() {
for (double x = -0.9; x < 0.9; x += 0.05) {
- checkRelative(FastMath.exp(x), build(x).exp());
+ checkRelative(AccurateMath.exp(x), build(x).exp());
}
}
@Test
public void testExpm1() {
for (double x = -0.9; x < 0.9; x += 0.05) {
- checkRelative(FastMath.expm1(x), build(x).expm1());
+ checkRelative(AccurateMath.expm1(x), build(x).expm1());
}
}
@Test
public void testLog() {
for (double x = 0.01; x < 0.9; x += 0.05) {
- checkRelative(FastMath.log(x), build(x).log());
+ checkRelative(AccurateMath.log(x), build(x).log());
}
}
@Test
public void testLog1p() {
for (double x = -0.9; x < 0.9; x += 0.05) {
- checkRelative(FastMath.log1p(x), build(x).log1p());
+ checkRelative(AccurateMath.log1p(x), build(x).log1p());
}
}
@@ -318,49 +318,49 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
// @Test
// public void testLog10() {
// for (double x = -0.9; x < 0.9; x += 0.05) {
-// checkRelative(FastMath.log10(x), build(x).log10());
+// checkRelative(AccurateMath.log10(x), build(x).log10());
// }
// }
@Test
public void testAbs() {
for (double x = -0.9; x < 0.9; x += 0.05) {
- checkRelative(FastMath.abs(x), build(x).abs());
+ checkRelative(AccurateMath.abs(x), build(x).abs());
}
}
@Test
public void testCeil() {
for (double x = -0.9; x < 0.9; x += 0.05) {
- checkRelative(FastMath.ceil(x), build(x).ceil());
+ checkRelative(AccurateMath.ceil(x), build(x).ceil());
}
}
@Test
public void testFloor() {
for (double x = -0.9; x < 0.9; x += 0.05) {
- checkRelative(FastMath.floor(x), build(x).floor());
+ checkRelative(AccurateMath.floor(x), build(x).floor());
}
}
@Test
public void testRint() {
for (double x = -0.9; x < 0.9; x += 0.05) {
- checkRelative(FastMath.rint(x), build(x).rint());
+ checkRelative(AccurateMath.rint(x), build(x).rint());
}
}
@Test
public void testRound() {
for (double x = -0.9; x < 0.9; x += 0.05) {
- Assert.assertEquals(FastMath.round(x), build(x).round());
+ Assert.assertEquals(AccurateMath.round(x), build(x).round());
}
}
@Test
public void testSignum() {
for (double x = -0.9; x < 0.9; x += 0.05) {
- checkRelative(FastMath.signum(x), build(x).signum());
+ checkRelative(AccurateMath.signum(x), build(x).signum());
}
}
@@ -368,7 +368,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
public void testCopySignField() {
for (double x = -3; x < 3; x += 0.2) {
for (double y = -3; y < 3; y += 0.2) {
- checkRelative(FastMath.copySign(x, y), build(x).copySign(build(y)));
+ checkRelative(AccurateMath.copySign(x, y), build(x).copySign(build(y)));
}
}
}
@@ -377,7 +377,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
public void testCopySignDouble() {
for (double x = -3; x < 3; x += 0.2) {
for (double y = -3; y < 3; y += 0.2) {
- checkRelative(FastMath.copySign(x, y), build(x).copySign(y));
+ checkRelative(AccurateMath.copySign(x, y), build(x).copySign(y));
}
}
}
@@ -386,7 +386,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
public void testScalb() {
for (double x = -0.9; x < 0.9; x += 0.05) {
for (int n = -100; n < 100; ++n) {
- checkRelative(FastMath.scalb(x, n), build(x).scalb(n));
+ checkRelative(AccurateMath.scalb(x, n), build(x).scalb(n));
}
}
}
@@ -498,7 +498,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
}
private void checkRelative(double expected, T obtained) {
- Assert.assertEquals(expected, obtained.getReal(), 1.0e-15 * (1 + FastMath.abs(expected)));
+ Assert.assertEquals(expected, obtained.getReal(), 1.0e-15 * (1 + AccurateMath.abs(expected)));
}
@Test
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/MathArraysTest.java b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/MathArraysTest.java
similarity index 91%
rename from commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/MathArraysTest.java
rename to commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/MathArraysTest.java
index 357beaa..7904f9d 100644
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/MathArraysTest.java
+++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/MathArraysTest.java
@@ -11,11 +11,14 @@
* KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
-package org.apache.commons.math4.legacy.util;
+package org.apache.commons.math4.legacy.core;
import java.util.Arrays;
-import org.apache.commons.math4.legacy.TestUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.commons.numbers.core.Precision;
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.MathArithmeticException;
import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException;
@@ -25,13 +28,10 @@ import org.apache.commons.math4.legacy.exception.NotANumberException;
import org.apache.commons.math4.legacy.exception.NotPositiveException;
import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException;
import org.apache.commons.math4.legacy.exception.NullArgumentException;
-import org.apache.commons.numbers.core.Precision;
-import org.junit.Assert;
-import org.junit.Test;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Test cases for the {@link MathArrays} class.
- *
*/
public class MathArraysTest {
@@ -390,7 +390,7 @@ public class MathArraysTest {
-Double.MAX_VALUE,
-1, 0,
Double.MIN_VALUE,
- FastMath.ulp(1d),
+ AccurateMath.ulp(1d),
1, 3, 113, 4769,
Double.MAX_VALUE,
Double.POSITIVE_INFINITY };
@@ -399,7 +399,7 @@ public class MathArraysTest {
-Double.MAX_VALUE,
-1, 0,
Double.MIN_VALUE,
- FastMath.ulp(1d),
+ AccurateMath.ulp(1d),
1, 3, 113, 4769,
Double.MAX_VALUE,
Double.POSITIVE_INFINITY,
@@ -445,25 +445,25 @@ public class MathArraysTest {
MathArrays.sortInPlace(x1, x2, x3);
- Assert.assertEquals(-3, x1[0], FastMath.ulp(1d));
- Assert.assertEquals(9, x2[0], FastMath.ulp(1d));
- Assert.assertEquals(-27, x3[0], FastMath.ulp(1d));
+ Assert.assertEquals(-3, x1[0], AccurateMath.ulp(1d));
+ Assert.assertEquals(9, x2[0], AccurateMath.ulp(1d));
+ Assert.assertEquals(-27, x3[0], AccurateMath.ulp(1d));
- Assert.assertEquals(1, x1[1], FastMath.ulp(1d));
- Assert.assertEquals(1, x2[1], FastMath.ulp(1d));
- Assert.assertEquals(1, x3[1], FastMath.ulp(1d));
+ Assert.assertEquals(1, x1[1], AccurateMath.ulp(1d));
+ Assert.assertEquals(1, x2[1], AccurateMath.ulp(1d));
+ Assert.assertEquals(1, x3[1], AccurateMath.ulp(1d));
- Assert.assertEquals(2, x1[2], FastMath.ulp(1d));
- Assert.assertEquals(4, x2[2], FastMath.ulp(1d));
- Assert.assertEquals(8, x3[2], FastMath.ulp(1d));
+ Assert.assertEquals(2, x1[2], AccurateMath.ulp(1d));
+ Assert.assertEquals(4, x2[2], AccurateMath.ulp(1d));
+ Assert.assertEquals(8, x3[2], AccurateMath.ulp(1d));
- Assert.assertEquals(4, x1[3], FastMath.ulp(1d));
- Assert.assertEquals(16, x2[3], FastMath.ulp(1d));
- Assert.assertEquals(64, x3[3], FastMath.ulp(1d));
+ Assert.assertEquals(4, x1[3], AccurateMath.ulp(1d));
+ Assert.assertEquals(16, x2[3], AccurateMath.ulp(1d));
+ Assert.assertEquals(64, x3[3], AccurateMath.ulp(1d));
- Assert.assertEquals(5, x1[4], FastMath.ulp(1d));
- Assert.assertEquals(25, x2[4], FastMath.ulp(1d));
- Assert.assertEquals(125, x3[4], FastMath.ulp(1d));
+ Assert.assertEquals(5, x1[4], AccurateMath.ulp(1d));
+ Assert.assertEquals(25, x2[4], AccurateMath.ulp(1d));
+ Assert.assertEquals(125, x3[4], AccurateMath.ulp(1d));
}
@Test
@@ -476,25 +476,25 @@ public class MathArraysTest {
MathArrays.OrderDirection.DECREASING,
x2, x3);
- Assert.assertEquals(-3, x1[4], FastMath.ulp(1d));
- Assert.assertEquals(9, x2[4], FastMath.ulp(1d));
- Assert.assertEquals(-27, x3[4], FastMath.ulp(1d));
+ Assert.assertEquals(-3, x1[4], AccurateMath.ulp(1d));
+ Assert.assertEquals(9, x2[4], AccurateMath.ulp(1d));
+ Assert.assertEquals(-27, x3[4], AccurateMath.ulp(1d));
- Assert.assertEquals(1, x1[3], FastMath.ulp(1d));
- Assert.assertEquals(1, x2[3], FastMath.ulp(1d));
- Assert.assertEquals(1, x3[3], FastMath.ulp(1d));
+ Assert.assertEquals(1, x1[3], AccurateMath.ulp(1d));
+ Assert.assertEquals(1, x2[3], AccurateMath.ulp(1d));
+ Assert.assertEquals(1, x3[3], AccurateMath.ulp(1d));
- Assert.assertEquals(2, x1[2], FastMath.ulp(1d));
- Assert.assertEquals(4, x2[2], FastMath.ulp(1d));
- Assert.assertEquals(8, x3[2], FastMath.ulp(1d));
+ Assert.assertEquals(2, x1[2], AccurateMath.ulp(1d));
+ Assert.assertEquals(4, x2[2], AccurateMath.ulp(1d));
+ Assert.assertEquals(8, x3[2], AccurateMath.ulp(1d));
- Assert.assertEquals(4, x1[1], FastMath.ulp(1d));
- Assert.assertEquals(16, x2[1], FastMath.ulp(1d));
- Assert.assertEquals(64, x3[1], FastMath.ulp(1d));
+ Assert.assertEquals(4, x1[1], AccurateMath.ulp(1d));
+ Assert.assertEquals(16, x2[1], AccurateMath.ulp(1d));
+ Assert.assertEquals(64, x3[1], AccurateMath.ulp(1d));
- Assert.assertEquals(5, x1[0], FastMath.ulp(1d));
- Assert.assertEquals(25, x2[0], FastMath.ulp(1d));
- Assert.assertEquals(125, x3[0], FastMath.ulp(1d));
+ Assert.assertEquals(5, x1[0], AccurateMath.ulp(1d));
+ Assert.assertEquals(25, x2[0], AccurateMath.ulp(1d));
+ Assert.assertEquals(125, x3[0], AccurateMath.ulp(1d));
}
/** Example in javadoc */
@@ -555,7 +555,7 @@ public class MathArraysTest {
Assert.assertFalse(MathArrays.equals(new double[] { Double.POSITIVE_INFINITY },
new double[] { Double.NEGATIVE_INFINITY }));
Assert.assertFalse(MathArrays.equals(new double[] { 1d },
- new double[] { FastMath.nextAfter(FastMath.nextAfter(1d, 2d), 2d) }));
+ new double[] { AccurateMath.nextAfter(AccurateMath.nextAfter(1d, 2d), 2d) }));
}
@@ -574,26 +574,26 @@ public class MathArraysTest {
Assert.assertFalse(MathArrays.equalsIncludingNaN(new double[] { Double.POSITIVE_INFINITY },
new double[] { Double.NEGATIVE_INFINITY }));
Assert.assertFalse(MathArrays.equalsIncludingNaN(new double[] { 1d },
- new double[] { FastMath.nextAfter(FastMath.nextAfter(1d, 2d), 2d) }));
+ new double[] { AccurateMath.nextAfter(AccurateMath.nextAfter(1d, 2d), 2d) }));
}
@Test
public void testNormalizeArray() {
double[] testValues1 = new double[] {1, 1, 2};
- TestUtils.assertEquals( new double[] {.25, .25, .5},
- MathArrays.normalizeArray(testValues1, 1),
- Double.MIN_VALUE);
+ Assert.assertArrayEquals(new double[] {.25, .25, .5},
+ MathArrays.normalizeArray(testValues1, 1),
+ Double.MIN_VALUE);
double[] testValues2 = new double[] {-1, -1, 1};
- TestUtils.assertEquals( new double[] {1, 1, -1},
- MathArrays.normalizeArray(testValues2, 1),
- Double.MIN_VALUE);
+ Assert.assertArrayEquals(new double[] {1, 1, -1},
+ MathArrays.normalizeArray(testValues2, 1),
+ Double.MIN_VALUE);
// Ignore NaNs
double[] testValues3 = new double[] {-1, -1, Double.NaN, 1, Double.NaN};
- TestUtils.assertEquals( new double[] {1, 1,Double.NaN, -1, Double.NaN},
- MathArrays.normalizeArray(testValues3, 1),
- Double.MIN_VALUE);
+ Assert.assertArrayEquals(new double[] {1, 1,Double.NaN, -1, Double.NaN},
+ MathArrays.normalizeArray(testValues3, 1),
+ Double.MIN_VALUE);
// Zero sum -> MathArithmeticException
double[] zeroSum = new double[] {-1, 1};
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/Decimal10.java b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/Decimal10.java
similarity index 98%
rename from commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/Decimal10.java
rename to commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/Decimal10.java
index b9e84f6..05bc1dc 100644
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/Decimal10.java
+++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/Decimal10.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.commons.math4.legacy.dfp;
+package org.apache.commons.math4.legacy.core.dfp;
public class Decimal10 extends DfpDec {
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/DfpDecTest.java b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/DfpDecTest.java
similarity index 99%
rename from commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/DfpDecTest.java
rename to commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/DfpDecTest.java
index 33c42e7..55351da 100644
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/DfpDecTest.java
+++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/DfpDecTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.commons.math4.legacy.dfp;
+package org.apache.commons.math4.legacy.core.dfp;
import org.junit.After;
import org.junit.Assert;
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/DfpMathTest.java b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/DfpMathTest.java
similarity index 99%
rename from commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/DfpMathTest.java
rename to commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/DfpMathTest.java
index 227d914..94a0686 100644
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/DfpMathTest.java
+++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/DfpMathTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.commons.math4.legacy.dfp;
+package org.apache.commons.math4.legacy.core.dfp;
import org.junit.After;
import org.junit.Assert;
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/DfpTest.java b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/DfpTest.java
similarity index 99%
copy from commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/DfpTest.java
copy to commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/DfpTest.java
index ca2360e..c8bbe86 100644
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/DfpTest.java
+++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/DfpTest.java
@@ -15,10 +15,10 @@
* limitations under the License.
*/
-package org.apache.commons.math4.legacy.dfp;
+package org.apache.commons.math4.legacy.core.dfp;
-import org.apache.commons.math4.legacy.ExtendedFieldElementAbstractTest;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.ExtendedFieldElementAbstractTest;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
import org.apache.commons.numbers.core.Precision;
import org.junit.After;
import org.junit.Assert;
@@ -1566,8 +1566,8 @@ public class DfpTest extends ExtendedFieldElementAbstractTest<Dfp> {
DfpField field = new DfpField(100);
Assert.assertEquals(0.0, field.getZero().toDouble(), Precision.SAFE_MIN);
Assert.assertEquals(0.0, field.newDfp(0.0).toDouble(), Precision.SAFE_MIN);
- Assert.assertEquals(-1, FastMath.copySign(1, field.newDfp(-0.0).toDouble()), Precision.EPSILON);
- Assert.assertEquals(+1, FastMath.copySign(1, field.newDfp(+0.0).toDouble()), Precision.EPSILON);
+ Assert.assertEquals(-1, AccurateMath.copySign(1, field.newDfp(-0.0).toDouble()), Precision.EPSILON);
+ Assert.assertEquals(+1, AccurateMath.copySign(1, field.newDfp(+0.0).toDouble()), Precision.EPSILON);
}
@Test
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/DfpTest.java b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/DfpTest.java.bak
similarity index 99%
rename from commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/DfpTest.java
rename to commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/DfpTest.java.bak
index ca2360e..cf0fc82 100644
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/DfpTest.java
+++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/DfpTest.java.bak
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.commons.math4.legacy.dfp;
+package org.apache.commons.math4.legacy.core.dfp;
import org.apache.commons.math4.legacy.ExtendedFieldElementAbstractTest;
import org.apache.commons.math4.legacy.util.FastMath;
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/FastMathStrictComparisonTest.java b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathStrictComparisonTest.java
similarity index 92%
copy from commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/FastMathStrictComparisonTest.java
copy to commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathStrictComparisonTest.java
index 4a99fb3..7f12c19 100644
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/FastMathStrictComparisonTest.java
+++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathStrictComparisonTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.math4.legacy.util;
+package org.apache.commons.math4.legacy.core.jdkmath;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -33,16 +33,16 @@ import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
/**
- * Test to compare FastMath results against StrictMath results for boundary values.
+ * Test to compare AccurateMath results against StrictMath results for boundary values.
* <p>
* Running all tests independently: <br>
- * {@code mvn test -Dtest=FastMathStrictComparisonTest}<br>
+ * {@code mvn test -Dtest=AccurateMathStrictComparisonTest}<br>
* or just run tests against a single method (e.g. scalb):<br>
- * {@code mvn test -Dtest=FastMathStrictComparisonTest -DargLine="-DtestMethod=scalb"}
+ * {@code mvn test -Dtest=AccurateMathStrictComparisonTest -DargLine="-DtestMethod=scalb"}
*/
@SuppressWarnings("boxing")
@RunWith(Parameterized.class)
-public class FastMathStrictComparisonTest {
+public class AccurateMathStrictComparisonTest {
// Values which often need special handling
private static final Double[] DOUBLE_SPECIAL_VALUES = {
@@ -79,7 +79,7 @@ public class FastMathStrictComparisonTest {
private final Type[] types;
private final Object[][] valueArrays;
- public FastMathStrictComparisonTest(Method m, Method f, Type[] types, Object[][] data) throws Exception{
+ public AccurateMathStrictComparisonTest(Method m, Method f, Type[] types, Object[][] data) throws Exception{
this.mathMethod=m;
this.fastMethod=f;
this.types=types;
@@ -218,8 +218,8 @@ public class FastMathStrictComparisonTest {
Type []types = mathMethod.getGenericParameterTypes();
if (types.length >=1) { // Only check methods with at least one parameter
try {
- // Get the corresponding FastMath method
- Method fastMethod = FastMath.class.getDeclaredMethod(mathMethod.getName(), (Class[]) types);
+ // Get the corresponding AccurateMath method
+ Method fastMethod = AccurateMath.class.getDeclaredMethod(mathMethod.getName(), (Class[]) types);
if (Modifier.isPublic(fastMethod.getModifiers())) { // It must be public too
if (singleMethod != null && !fastMethod.getName().equals(singleMethod)) {
break method;
@@ -249,10 +249,10 @@ public class FastMathStrictComparisonTest {
list.add(new Object[]{mathMethod, fastMethod, types, values});
// setupMethodCall(mathMethod, fastMethod, params, data);
} else {
- System.out.println("Cannot find public FastMath method corresponding to: "+mathMethod);
+ System.out.println("Cannot find public AccurateMath method corresponding to: "+mathMethod);
}
} catch (NoSuchMethodException e) {
- System.out.println("Cannot find FastMath method corresponding to: "+mathMethod);
+ System.out.println("Cannot find AccurateMath method corresponding to: "+mathMethod);
}
}
}
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/FastMathStrictComparisonTest.java b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathStrictComparisonTest.java.bak
similarity index 93%
rename from commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/FastMathStrictComparisonTest.java
rename to commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathStrictComparisonTest.java.bak
index 4a99fb3..64f4557 100644
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/FastMathStrictComparisonTest.java
+++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathStrictComparisonTest.java.bak
@@ -33,16 +33,16 @@ import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
/**
- * Test to compare FastMath results against StrictMath results for boundary values.
+ * Test to compare AccurateMath results against StrictMath results for boundary values.
* <p>
* Running all tests independently: <br>
- * {@code mvn test -Dtest=FastMathStrictComparisonTest}<br>
+ * {@code mvn test -Dtest=AccurateMathStrictComparisonTest}<br>
* or just run tests against a single method (e.g. scalb):<br>
- * {@code mvn test -Dtest=FastMathStrictComparisonTest -DargLine="-DtestMethod=scalb"}
+ * {@code mvn test -Dtest=AccurateMathStrictComparisonTest -DargLine="-DtestMethod=scalb"}
*/
@SuppressWarnings("boxing")
@RunWith(Parameterized.class)
-public class FastMathStrictComparisonTest {
+public class AccurateMathStrictComparisonTest {
// Values which often need special handling
private static final Double[] DOUBLE_SPECIAL_VALUES = {
@@ -79,7 +79,7 @@ public class FastMathStrictComparisonTest {
private final Type[] types;
private final Object[][] valueArrays;
- public FastMathStrictComparisonTest(Method m, Method f, Type[] types, Object[][] data) throws Exception{
+ public AccurateMathStrictComparisonTest(Method m, Method f, Type[] types, Object[][] data) throws Exception{
this.mathMethod=m;
this.fastMethod=f;
this.types=types;
@@ -218,8 +218,8 @@ public class FastMathStrictComparisonTest {
Type []types = mathMethod.getGenericParameterTypes();
if (types.length >=1) { // Only check methods with at least one parameter
try {
- // Get the corresponding FastMath method
- Method fastMethod = FastMath.class.getDeclaredMethod(mathMethod.getName(), (Class[]) types);
+ // Get the corresponding AccurateMath method
+ Method fastMethod = AccurateMath.class.getDeclaredMethod(mathMethod.getName(), (Class[]) types);
if (Modifier.isPublic(fastMethod.getModifiers())) { // It must be public too
if (singleMethod != null && !fastMethod.getName().equals(singleMethod)) {
break method;
@@ -249,10 +249,10 @@ public class FastMathStrictComparisonTest {
list.add(new Object[]{mathMethod, fastMethod, types, values});
// setupMethodCall(mathMethod, fastMethod, params, data);
} else {
- System.out.println("Cannot find public FastMath method corresponding to: "+mathMethod);
+ System.out.println("Cannot find public AccurateMath method corresponding to: "+mathMethod);
}
} catch (NoSuchMethodException e) {
- System.out.println("Cannot find FastMath method corresponding to: "+mathMethod);
+ System.out.println("Cannot find AccurateMath method corresponding to: "+mathMethod);
}
}
}
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/FastMathTest.java b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathTest.java
similarity index 67%
copy from commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/FastMathTest.java
copy to commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathTest.java
index b376239..6a8ff27 100644
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/FastMathTest.java
+++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.math4.legacy.util;
+package org.apache.commons.math4.legacy.core.jdkmath;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -27,21 +27,21 @@ import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
import org.apache.commons.numbers.core.ArithmeticUtils;
import org.apache.commons.numbers.core.Precision;
-import org.apache.commons.math4.legacy.TestUtils;
-import org.apache.commons.math4.legacy.dfp.Dfp;
-import org.apache.commons.math4.legacy.dfp.DfpField;
-import org.apache.commons.math4.legacy.dfp.DfpMath;
+import org.apache.commons.math4.legacy.core.dfp.Dfp;
+import org.apache.commons.math4.legacy.core.dfp.DfpField;
+import org.apache.commons.math4.legacy.core.dfp.DfpMath;
import org.apache.commons.math4.legacy.exception.MathArithmeticException;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.simple.RandomSource;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-public class FastMathTest {
+public class AccurateMathTest {
private static final double MAX_ERROR_ULP = 0.51;
private static final int NUMBER_OF_TRIALS = 1000;
@@ -72,19 +72,19 @@ public class FastMathTest {
for (double[] pair : pairs) {
assertEquals("min(" + pair[0] + ", " + pair[1] + ")",
Math.min(pair[0], pair[1]),
- FastMath.min(pair[0], pair[1]),
+ AccurateMath.min(pair[0], pair[1]),
Precision.EPSILON);
assertEquals("min(" + pair[1] + ", " + pair[0] + ")",
Math.min(pair[1], pair[0]),
- FastMath.min(pair[1], pair[0]),
+ AccurateMath.min(pair[1], pair[0]),
Precision.EPSILON);
assertEquals("max(" + pair[0] + ", " + pair[1] + ")",
Math.max(pair[0], pair[1]),
- FastMath.max(pair[0], pair[1]),
+ AccurateMath.max(pair[0], pair[1]),
Precision.EPSILON);
assertEquals("max(" + pair[1] + ", " + pair[0] + ")",
Math.max(pair[1], pair[0]),
- FastMath.max(pair[1], pair[0]),
+ AccurateMath.max(pair[1], pair[0]),
Precision.EPSILON);
}
}
@@ -105,62 +105,62 @@ public class FastMathTest {
for (float[] pair : pairs) {
assertEquals("min(" + pair[0] + ", " + pair[1] + ")",
Math.min(pair[0], pair[1]),
- FastMath.min(pair[0], pair[1]),
+ AccurateMath.min(pair[0], pair[1]),
Precision.EPSILON);
assertEquals("min(" + pair[1] + ", " + pair[0] + ")",
Math.min(pair[1], pair[0]),
- FastMath.min(pair[1], pair[0]),
+ AccurateMath.min(pair[1], pair[0]),
Precision.EPSILON);
assertEquals("max(" + pair[0] + ", " + pair[1] + ")",
Math.max(pair[0], pair[1]),
- FastMath.max(pair[0], pair[1]),
+ AccurateMath.max(pair[0], pair[1]),
Precision.EPSILON);
assertEquals("max(" + pair[1] + ", " + pair[0] + ")",
Math.max(pair[1], pair[0]),
- FastMath.max(pair[1], pair[0]),
+ AccurateMath.max(pair[1], pair[0]),
Precision.EPSILON);
}
}
@Test
public void testConstants() {
- assertEquals(Math.PI, FastMath.PI, 1.0e-20);
- assertEquals(Math.E, FastMath.E, 1.0e-20);
+ assertEquals(Math.PI, AccurateMath.PI, 1.0e-20);
+ assertEquals(Math.E, AccurateMath.E, 1.0e-20);
}
@Test
public void testAtan2() {
double y1 = 1.2713504628280707e10;
double x1 = -5.674940885228782e-10;
- assertEquals(Math.atan2(y1, x1), FastMath.atan2(y1, x1), 2 * Precision.EPSILON);
+ assertEquals(Math.atan2(y1, x1), AccurateMath.atan2(y1, x1), 2 * Precision.EPSILON);
double y2 = 0.0;
double x2 = Double.POSITIVE_INFINITY;
- assertEquals(Math.atan2(y2, x2), FastMath.atan2(y2, x2), Precision.SAFE_MIN);
+ assertEquals(Math.atan2(y2, x2), AccurateMath.atan2(y2, x2), Precision.SAFE_MIN);
}
@Test
public void testHyperbolic() {
double maxErr = 0;
for (double x = -30; x < 30; x += 0.001) {
- double tst = FastMath.sinh(x);
+ double tst = AccurateMath.sinh(x);
double ref = Math.sinh(x);
- maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref));
+ maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref));
}
assertEquals(0, maxErr, 2);
maxErr = 0;
for (double x = -30; x < 30; x += 0.001) {
- double tst = FastMath.cosh(x);
+ double tst = AccurateMath.cosh(x);
double ref = Math.cosh(x);
- maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref));
+ maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref));
}
assertEquals(0, maxErr, 2);
maxErr = 0;
for (double x = -0.5; x < 0.5; x += 0.001) {
- double tst = FastMath.tanh(x);
+ double tst = AccurateMath.tanh(x);
double ref = Math.tanh(x);
- maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref));
+ maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref));
}
assertEquals(0, maxErr, 4);
@@ -171,9 +171,9 @@ public class FastMathTest {
final double x = -1;
final double y = (5 + 1e-15) * 1e15;
assertEquals(Math.pow(x, y),
- FastMath.pow(x, y), 0);
+ AccurateMath.pow(x, y), 0);
assertEquals(Math.pow(x, -y),
- FastMath.pow(x, -y), 0);
+ AccurateMath.pow(x, -y), 0);
}
@Test
@@ -184,16 +184,16 @@ public class FastMathTest {
double maxErr = 0;
for (double x = start; x < end; x += 1e-3) {
- final double tst = FastMath.cosh(x);
+ final double tst = AccurateMath.cosh(x);
final double ref = Math.cosh(x);
- maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref));
+ maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref));
}
assertEquals(0, maxErr, 3);
for (double x = start; x < end; x += 1e-3) {
- final double tst = FastMath.sinh(x);
+ final double tst = AccurateMath.sinh(x);
final double ref = Math.sinh(x);
- maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref));
+ maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref));
}
assertEquals(0, maxErr, 3);
}
@@ -206,16 +206,16 @@ public class FastMathTest {
double maxErr = 0;
for (double x = start; x > end; x -= 1e-3) {
- final double tst = FastMath.cosh(x);
+ final double tst = AccurateMath.cosh(x);
final double ref = Math.cosh(x);
- maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref));
+ maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref));
}
assertEquals(0, maxErr, 3);
for (double x = start; x > end; x -= 1e-3) {
- final double tst = FastMath.sinh(x);
+ final double tst = AccurateMath.sinh(x);
final double ref = Math.sinh(x);
- maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref));
+ maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref));
}
assertEquals(0, maxErr, 3);
}
@@ -224,7 +224,7 @@ public class FastMathTest {
public void testMath1269() {
final double arg = 709.8125;
final double vM = Math.exp(arg);
- final double vFM = FastMath.exp(arg);
+ final double vFM = AccurateMath.exp(arg);
assertTrue("exp(" + arg + ") is " + vFM + " instead of " + vM,
Precision.equalsIncludingNaN(vM, vFM));
}
@@ -233,19 +233,19 @@ public class FastMathTest {
public void testHyperbolicInverses() {
double maxErr = 0;
for (double x = -30; x < 30; x += 0.01) {
- maxErr = FastMath.max(maxErr, FastMath.abs(x - FastMath.sinh(FastMath.asinh(x))) / (2 * FastMath.ulp(x)));
+ maxErr = AccurateMath.max(maxErr, AccurateMath.abs(x - AccurateMath.sinh(AccurateMath.asinh(x))) / (2 * AccurateMath.ulp(x)));
}
assertEquals(0, maxErr, 3);
maxErr = 0;
for (double x = 1; x < 30; x += 0.01) {
- maxErr = FastMath.max(maxErr, FastMath.abs(x - FastMath.cosh(FastMath.acosh(x))) / (2 * FastMath.ulp(x)));
+ maxErr = AccurateMath.max(maxErr, AccurateMath.abs(x - AccurateMath.cosh(AccurateMath.acosh(x))) / (2 * AccurateMath.ulp(x)));
}
assertEquals(0, maxErr, 2);
maxErr = 0;
for (double x = -1 + Precision.EPSILON; x < 1 - Precision.EPSILON; x += 0.0001) {
- maxErr = FastMath.max(maxErr, FastMath.abs(x - FastMath.tanh(FastMath.atanh(x))) / (2 * FastMath.ulp(x)));
+ maxErr = AccurateMath.max(maxErr, AccurateMath.abs(x - AccurateMath.tanh(AccurateMath.atanh(x))) / (2 * AccurateMath.ulp(x)));
}
assertEquals(0, maxErr, 2);
}
@@ -257,7 +257,7 @@ public class FastMathTest {
for (int i = 0; i < NUMBER_OF_TRIALS; i++) {
double x = Math.exp(generator.nextDouble() * 1416.0 - 708.0) * generator.nextDouble();
// double x = generator.nextDouble()*2.0;
- double tst = FastMath.log(x);
+ double tst = AccurateMath.log(x);
double ref = DfpMath.log(field.newDfp(x)).toDouble();
double err = (tst - ref) / ref;
@@ -281,7 +281,7 @@ public class FastMathTest {
for (int i = 0; i < NUMBER_OF_TRIALS; i++) {
double x = Math.exp(generator.nextDouble() * 1416.0 - 708.0) * generator.nextDouble();
// double x = generator.nextDouble()*2.0;
- double tst = FastMath.log10(x);
+ double tst = AccurateMath.log10(x);
double ref = DfpMath.log(field.newDfp(x)).divide(DfpMath.log(field.newDfp("10"))).toDouble();
double err = (tst - ref) / ref;
@@ -305,7 +305,7 @@ public class FastMathTest {
for (int i = 0; i < NUMBER_OF_TRIALS; i++) {
double x = Math.exp(generator.nextDouble() * 10.0 - 5.0) * generator.nextDouble();
// double x = generator.nextDouble()*2.0;
- double tst = FastMath.log1p(x);
+ double tst = AccurateMath.log1p(x);
double ref = DfpMath.log(field.newDfp(x).add(field.getOne())).toDouble();
double err = (tst - ref) / ref;
@@ -324,93 +324,93 @@ public class FastMathTest {
@Test
public void testLog1pSpecialCases() {
- assertTrue("Logp of -1.0 should be -Inf", Double.isInfinite(FastMath.log1p(-1.0)));
+ assertTrue("Logp of -1.0 should be -Inf", Double.isInfinite(AccurateMath.log1p(-1.0)));
}
@Test
public void testLogSpecialCases() {
- assertEquals("Log of zero should be -Inf", Double.NEGATIVE_INFINITY, FastMath.log(0.0), 1.0);
- assertEquals("Log of -zero should be -Inf", Double.NEGATIVE_INFINITY, FastMath.log(-0.0), 1.0);
- assertTrue("Log of NaN should be NaN", Double.isNaN(FastMath.log(Double.NaN)));
- assertTrue("Log of negative number should be NaN", Double.isNaN(FastMath.log(-1.0)));
- assertEquals("Log of Double.MIN_VALUE should be -744.4400719213812", -744.4400719213812, FastMath.log(Double.MIN_VALUE), Precision.EPSILON);
- assertEquals("Log of infinity should be infinity", Double.POSITIVE_INFINITY, FastMath.log(Double.POSITIVE_INFINITY), 1.0);
+ assertEquals("Log of zero should be -Inf", Double.NEGATIVE_INFINITY, AccurateMath.log(0.0), 1.0);
+ assertEquals("Log of -zero should be -Inf", Double.NEGATIVE_INFINITY, AccurateMath.log(-0.0), 1.0);
+ assertTrue("Log of NaN should be NaN", Double.isNaN(AccurateMath.log(Double.NaN)));
+ assertTrue("Log of negative number should be NaN", Double.isNaN(AccurateMath.log(-1.0)));
+ assertEquals("Log of Double.MIN_VALUE should be -744.4400719213812", -744.4400719213812, AccurateMath.log(Double.MIN_VALUE), Precision.EPSILON);
+ assertEquals("Log of infinity should be infinity", Double.POSITIVE_INFINITY, AccurateMath.log(Double.POSITIVE_INFINITY), 1.0);
}
@Test
public void testExpSpecialCases() {
// Smallest value that will round up to Double.MIN_VALUE
- assertEquals(Double.MIN_VALUE, FastMath.exp(-745.1332191019411), Precision.EPSILON);
- assertEquals("exp(-745.1332191019412) should be 0.0", 0.0, FastMath.exp(-745.1332191019412), Precision.EPSILON);
- assertTrue("exp of NaN should be NaN", Double.isNaN(FastMath.exp(Double.NaN)));
- assertEquals("exp of infinity should be infinity", Double.POSITIVE_INFINITY, FastMath.exp(Double.POSITIVE_INFINITY), 1.0);
- assertEquals("exp of -infinity should be 0.0", 0.0, FastMath.exp(Double.NEGATIVE_INFINITY), Precision.EPSILON);
- assertEquals("exp(1) should be Math.E", Math.E, FastMath.exp(1.0), Precision.EPSILON);
+ assertEquals(Double.MIN_VALUE, AccurateMath.exp(-745.1332191019411), Precision.EPSILON);
+ assertEquals("exp(-745.1332191019412) should be 0.0", 0.0, AccurateMath.exp(-745.1332191019412), Precision.EPSILON);
+ assertTrue("exp of NaN should be NaN", Double.isNaN(AccurateMath.exp(Double.NaN)));
+ assertEquals("exp of infinity should be infinity", Double.POSITIVE_INFINITY, AccurateMath.exp(Double.POSITIVE_INFINITY), 1.0);
+ assertEquals("exp of -infinity should be 0.0", 0.0, AccurateMath.exp(Double.NEGATIVE_INFINITY), Precision.EPSILON);
+ assertEquals("exp(1) should be Math.E", Math.E, AccurateMath.exp(1.0), Precision.EPSILON);
}
@Test
public void testPowSpecialCases() {
final double EXACT = -1.0;
- assertEquals("pow(-1, 0) should be 1.0", 1.0, FastMath.pow(-1.0, 0.0), Precision.EPSILON);
- assertEquals("pow(-1, -0) should be 1.0", 1.0, FastMath.pow(-1.0, -0.0), Precision.EPSILON);
- assertEquals("pow(PI, 1.0) should be PI", FastMath.PI, FastMath.pow(FastMath.PI, 1.0), Precision.EPSILON);
- assertEquals("pow(-PI, 1.0) should be -PI", -FastMath.PI, FastMath.pow(-FastMath.PI, 1.0), Precision.EPSILON);
- assertTrue("pow(PI, NaN) should be NaN", Double.isNaN(FastMath.pow(Math.PI, Double.NaN)));
- assertTrue("pow(NaN, PI) should be NaN", Double.isNaN(FastMath.pow(Double.NaN, Math.PI)));
- assertEquals("pow(2.0, Infinity) should be Infinity", Double.POSITIVE_INFINITY, FastMath.pow(2.0, Double.POSITIVE_INFINITY), 1.0);
- assertEquals("pow(0.5, -Infinity) should be Infinity", Double.POSITIVE_INFINITY, FastMath.pow(0.5, Double.NEGATIVE_INFINITY), 1.0);
- assertEquals("pow(0.5, Infinity) should be 0.0", 0.0, FastMath.pow(0.5, Double.POSITIVE_INFINITY), Precision.EPSILON);
- assertEquals("pow(2.0, -Infinity) should be 0.0", 0.0, FastMath.pow(2.0, Double.NEGATIVE_INFINITY), Precision.EPSILON);
- assertEquals("pow(0.0, 0.5) should be 0.0", 0.0, FastMath.pow(0.0, 0.5), Precision.EPSILON);
- assertEquals("pow(Infinity, -0.5) should be 0.0", 0.0, FastMath.pow(Double.POSITIVE_INFINITY, -0.5), Precision.EPSILON);
- assertEquals("pow(0.0, -0.5) should be Inf", Double.POSITIVE_INFINITY, FastMath.pow(0.0, -0.5), 1.0);
- assertEquals("pow(Inf, 0.5) should be Inf", Double.POSITIVE_INFINITY, FastMath.pow(Double.POSITIVE_INFINITY, 0.5), 1.0);
- assertEquals("pow(-0.0, -3.0) should be -Inf", Double.NEGATIVE_INFINITY, FastMath.pow(-0.0, -3.0), 1.0);
- assertEquals("pow(-0.0, Infinity) should be 0.0", 0.0, FastMath.pow(-0.0, Double.POSITIVE_INFINITY), Precision.EPSILON);
- assertTrue("pow(-0.0, NaN) should be NaN", Double.isNaN(FastMath.pow(-0.0, Double.NaN)));
- assertEquals("pow(-0.0, -tiny) should be Infinity", Double.POSITIVE_INFINITY, FastMath.pow(-0.0, -Double.MIN_VALUE), 1.0);
- assertEquals("pow(-0.0, -huge) should be Infinity", Double.POSITIVE_INFINITY, FastMath.pow(-0.0, -Double.MAX_VALUE), 1.0);
- assertEquals("pow(-Inf, 3.0) should be -Inf", Double.NEGATIVE_INFINITY, FastMath.pow(Double.NEGATIVE_INFINITY, 3.0), 1.0);
- assertEquals("pow(-Inf, -3.0) should be -0.0", -0.0, FastMath.pow(Double.NEGATIVE_INFINITY, -3.0), EXACT);
- assertEquals("pow(-0.0, -3.5) should be Inf", Double.POSITIVE_INFINITY, FastMath.pow(-0.0, -3.5), 1.0);
- assertEquals("pow(Inf, 3.5) should be Inf", Double.POSITIVE_INFINITY, FastMath.pow(Double.POSITIVE_INFINITY, 3.5), 1.0);
- assertEquals("pow(-2.0, 3.0) should be -8.0", -8.0, FastMath.pow(-2.0, 3.0), Precision.EPSILON);
- assertTrue("pow(-2.0, 3.5) should be NaN", Double.isNaN(FastMath.pow(-2.0, 3.5)));
- assertTrue("pow(NaN, -Infinity) should be NaN", Double.isNaN(FastMath.pow(Double.NaN, Double.NEGATIVE_INFINITY)));
- assertEquals("pow(NaN, 0.0) should be 1.0", 1.0, FastMath.pow(Double.NaN, 0.0), Precision.EPSILON);
- assertEquals("pow(-Infinity, -Infinity) should be 0.0", 0.0, FastMath.pow(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON);
- assertEquals("pow(-huge, -huge) should be 0.0", 0.0, FastMath.pow(-Double.MAX_VALUE, -Double.MAX_VALUE), Precision.EPSILON);
- assertTrue("pow(-huge, huge) should be +Inf", Double.isInfinite(FastMath.pow(-Double.MAX_VALUE, Double.MAX_VALUE)));
- assertTrue("pow(NaN, -Infinity) should be NaN", Double.isNaN(FastMath.pow(Double.NaN, Double.NEGATIVE_INFINITY)));
- assertEquals("pow(NaN, -0.0) should be 1.0", 1.0, FastMath.pow(Double.NaN, -0.0), Precision.EPSILON);
- assertEquals("pow(-Infinity, -Infinity) should be 0.0", 0.0, FastMath.pow(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON);
- assertEquals("pow(-huge, -huge) should be 0.0", 0.0, FastMath.pow(-Double.MAX_VALUE, -Double.MAX_VALUE), Precision.EPSILON);
- assertEquals("pow(-huge, huge) should be +Inf", Double.POSITIVE_INFINITY, FastMath.pow(-Double.MAX_VALUE, Double.MAX_VALUE), 1.0);
+ assertEquals("pow(-1, 0) should be 1.0", 1.0, AccurateMath.pow(-1.0, 0.0), Precision.EPSILON);
+ assertEquals("pow(-1, -0) should be 1.0", 1.0, AccurateMath.pow(-1.0, -0.0), Precision.EPSILON);
+ assertEquals("pow(PI, 1.0) should be PI", AccurateMath.PI, AccurateMath.pow(AccurateMath.PI, 1.0), Precision.EPSILON);
+ assertEquals("pow(-PI, 1.0) should be -PI", -AccurateMath.PI, AccurateMath.pow(-AccurateMath.PI, 1.0), Precision.EPSILON);
+ assertTrue("pow(PI, NaN) should be NaN", Double.isNaN(AccurateMath.pow(Math.PI, Double.NaN)));
+ assertTrue("pow(NaN, PI) should be NaN", Double.isNaN(AccurateMath.pow(Double.NaN, Math.PI)));
+ assertEquals("pow(2.0, Infinity) should be Infinity", Double.POSITIVE_INFINITY, AccurateMath.pow(2.0, Double.POSITIVE_INFINITY), 1.0);
+ assertEquals("pow(0.5, -Infinity) should be Infinity", Double.POSITIVE_INFINITY, AccurateMath.pow(0.5, Double.NEGATIVE_INFINITY), 1.0);
+ assertEquals("pow(0.5, Infinity) should be 0.0", 0.0, AccurateMath.pow(0.5, Double.POSITIVE_INFINITY), Precision.EPSILON);
+ assertEquals("pow(2.0, -Infinity) should be 0.0", 0.0, AccurateMath.pow(2.0, Double.NEGATIVE_INFINITY), Precision.EPSILON);
+ assertEquals("pow(0.0, 0.5) should be 0.0", 0.0, AccurateMath.pow(0.0, 0.5), Precision.EPSILON);
+ assertEquals("pow(Infinity, -0.5) should be 0.0", 0.0, AccurateMath.pow(Double.POSITIVE_INFINITY, -0.5), Precision.EPSILON);
+ assertEquals("pow(0.0, -0.5) should be Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(0.0, -0.5), 1.0);
+ assertEquals("pow(Inf, 0.5) should be Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(Double.POSITIVE_INFINITY, 0.5), 1.0);
+ assertEquals("pow(-0.0, -3.0) should be -Inf", Double.NEGATIVE_INFINITY, AccurateMath.pow(-0.0, -3.0), 1.0);
+ assertEquals("pow(-0.0, Infinity) should be 0.0", 0.0, AccurateMath.pow(-0.0, Double.POSITIVE_INFINITY), Precision.EPSILON);
+ assertTrue("pow(-0.0, NaN) should be NaN", Double.isNaN(AccurateMath.pow(-0.0, Double.NaN)));
+ assertEquals("pow(-0.0, -tiny) should be Infinity", Double.POSITIVE_INFINITY, AccurateMath.pow(-0.0, -Double.MIN_VALUE), 1.0);
+ assertEquals("pow(-0.0, -huge) should be Infinity", Double.POSITIVE_INFINITY, AccurateMath.pow(-0.0, -Double.MAX_VALUE), 1.0);
+ assertEquals("pow(-Inf, 3.0) should be -Inf", Double.NEGATIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, 3.0), 1.0);
+ assertEquals("pow(-Inf, -3.0) should be -0.0", -0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, -3.0), EXACT);
+ assertEquals("pow(-0.0, -3.5) should be Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(-0.0, -3.5), 1.0);
+ assertEquals("pow(Inf, 3.5) should be Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(Double.POSITIVE_INFINITY, 3.5), 1.0);
+ assertEquals("pow(-2.0, 3.0) should be -8.0", -8.0, AccurateMath.pow(-2.0, 3.0), Precision.EPSILON);
+ assertTrue("pow(-2.0, 3.5) should be NaN", Double.isNaN(AccurateMath.pow(-2.0, 3.5)));
+ assertTrue("pow(NaN, -Infinity) should be NaN", Double.isNaN(AccurateMath.pow(Double.NaN, Double.NEGATIVE_INFINITY)));
+ assertEquals("pow(NaN, 0.0) should be 1.0", 1.0, AccurateMath.pow(Double.NaN, 0.0), Precision.EPSILON);
+ assertEquals("pow(-Infinity, -Infinity) should be 0.0", 0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON);
+ assertEquals("pow(-huge, -huge) should be 0.0", 0.0, AccurateMath.pow(-Double.MAX_VALUE, -Double.MAX_VALUE), Precision.EPSILON);
+ assertTrue("pow(-huge, huge) should be +Inf", Double.isInfinite(AccurateMath.pow(-Double.MAX_VALUE, Double.MAX_VALUE)));
+ assertTrue("pow(NaN, -Infinity) should be NaN", Double.isNaN(AccurateMath.pow(Double.NaN, Double.NEGATIVE_INFINITY)));
+ assertEquals("pow(NaN, -0.0) should be 1.0", 1.0, AccurateMath.pow(Double.NaN, -0.0), Precision.EPSILON);
+ assertEquals("pow(-Infinity, -Infinity) should be 0.0", 0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON);
+ assertEquals("pow(-huge, -huge) should be 0.0", 0.0, AccurateMath.pow(-Double.MAX_VALUE, -Double.MAX_VALUE), Precision.EPSILON);
+ assertEquals("pow(-huge, huge) should be +Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(-Double.MAX_VALUE, Double.MAX_VALUE), 1.0);
// Added tests for a 100% coverage
- assertTrue("pow(+Inf, NaN) should be NaN", Double.isNaN(FastMath.pow(Double.POSITIVE_INFINITY, Double.NaN)));
- assertTrue("pow(1.0, +Inf) should be NaN", Double.isNaN(FastMath.pow(1.0, Double.POSITIVE_INFINITY)));
- assertTrue("pow(-Inf, NaN) should be NaN", Double.isNaN(FastMath.pow(Double.NEGATIVE_INFINITY, Double.NaN)));
- assertEquals("pow(-Inf, -1.0) should be -0.0", -0.0, FastMath.pow(Double.NEGATIVE_INFINITY, -1.0), EXACT);
- assertEquals("pow(-Inf, -2.0) should be 0.0", 0.0, FastMath.pow(Double.NEGATIVE_INFINITY, -2.0), EXACT);
- assertEquals("pow(-Inf, 1.0) should be -Inf", Double.NEGATIVE_INFINITY, FastMath.pow(Double.NEGATIVE_INFINITY, 1.0), 1.0);
- assertEquals("pow(-Inf, 2.0) should be +Inf", Double.POSITIVE_INFINITY, FastMath.pow(Double.NEGATIVE_INFINITY, 2.0), 1.0);
- assertTrue("pow(1.0, -Inf) should be NaN", Double.isNaN(FastMath.pow(1.0, Double.NEGATIVE_INFINITY)));
- assertEquals("pow(-0.0, 1.0) should be -0.0", -0.0, FastMath.pow(-0.0, 1.0), EXACT);
- assertEquals("pow(0.0, 1.0) should be 0.0", 0.0, FastMath.pow(0.0, 1.0), EXACT);
- assertEquals("pow(0.0, +Inf) should be 0.0", 0.0, FastMath.pow(0.0, Double.POSITIVE_INFINITY), EXACT);
- assertEquals("pow(-0.0, even) should be 0.0", 0.0, FastMath.pow(-0.0, 6.0), EXACT);
- assertEquals("pow(-0.0, odd) should be -0.0", -0.0, FastMath.pow(-0.0, 13.0), EXACT);
- assertEquals("pow(-0.0, -even) should be +Inf", Double.POSITIVE_INFINITY, FastMath.pow(-0.0, -6.0), EXACT);
- assertEquals("pow(-0.0, -odd) should be -Inf", Double.NEGATIVE_INFINITY, FastMath.pow(-0.0, -13.0), EXACT);
- assertEquals("pow(-2.0, 4.0) should be 16.0", 16.0, FastMath.pow(-2.0, 4.0), EXACT);
- assertEquals("pow(-2.0, 4.5) should be NaN", Double.NaN, FastMath.pow(-2.0, 4.5), EXACT);
- assertEquals("pow(-0.0, -0.0) should be 1.0", 1.0, FastMath.pow(-0.0, -0.0), EXACT);
- assertEquals("pow(-0.0, 0.0) should be 1.0", 1.0, FastMath.pow(-0.0, 0.0), EXACT);
- assertEquals("pow(0.0, -0.0) should be 1.0", 1.0, FastMath.pow(0.0, -0.0), EXACT);
- assertEquals("pow(0.0, 0.0) should be 1.0", 1.0, FastMath.pow(0.0, 0.0), EXACT);
+ assertTrue("pow(+Inf, NaN) should be NaN", Double.isNaN(AccurateMath.pow(Double.POSITIVE_INFINITY, Double.NaN)));
+ assertTrue("pow(1.0, +Inf) should be NaN", Double.isNaN(AccurateMath.pow(1.0, Double.POSITIVE_INFINITY)));
+ assertTrue("pow(-Inf, NaN) should be NaN", Double.isNaN(AccurateMath.pow(Double.NEGATIVE_INFINITY, Double.NaN)));
+ assertEquals("pow(-Inf, -1.0) should be -0.0", -0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, -1.0), EXACT);
+ assertEquals("pow(-Inf, -2.0) should be 0.0", 0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, -2.0), EXACT);
+ assertEquals("pow(-Inf, 1.0) should be -Inf", Double.NEGATIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, 1.0), 1.0);
+ assertEquals("pow(-Inf, 2.0) should be +Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, 2.0), 1.0);
+ assertTrue("pow(1.0, -Inf) should be NaN", Double.isNaN(AccurateMath.pow(1.0, Double.NEGATIVE_INFINITY)));
+ assertEquals("pow(-0.0, 1.0) should be -0.0", -0.0, AccurateMath.pow(-0.0, 1.0), EXACT);
+ assertEquals("pow(0.0, 1.0) should be 0.0", 0.0, AccurateMath.pow(0.0, 1.0), EXACT);
+ assertEquals("pow(0.0, +Inf) should be 0.0", 0.0, AccurateMath.pow(0.0, Double.POSITIVE_INFINITY), EXACT);
+ assertEquals("pow(-0.0, even) should be 0.0", 0.0, AccurateMath.pow(-0.0, 6.0), EXACT);
+ assertEquals("pow(-0.0, odd) should be -0.0", -0.0, AccurateMath.pow(-0.0, 13.0), EXACT);
+ assertEquals("pow(-0.0, -even) should be +Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(-0.0, -6.0), EXACT);
+ assertEquals("pow(-0.0, -odd) should be -Inf", Double.NEGATIVE_INFINITY, AccurateMath.pow(-0.0, -13.0), EXACT);
+ assertEquals("pow(-2.0, 4.0) should be 16.0", 16.0, AccurateMath.pow(-2.0, 4.0), EXACT);
+ assertEquals("pow(-2.0, 4.5) should be NaN", Double.NaN, AccurateMath.pow(-2.0, 4.5), EXACT);
+ assertEquals("pow(-0.0, -0.0) should be 1.0", 1.0, AccurateMath.pow(-0.0, -0.0), EXACT);
+ assertEquals("pow(-0.0, 0.0) should be 1.0", 1.0, AccurateMath.pow(-0.0, 0.0), EXACT);
+ assertEquals("pow(0.0, -0.0) should be 1.0", 1.0, AccurateMath.pow(0.0, -0.0), EXACT);
+ assertEquals("pow(0.0, 0.0) should be 1.0", 1.0, AccurateMath.pow(0.0, 0.0), EXACT);
}
@Test(timeout=20000L)
@@ -432,124 +432,124 @@ public class FastMathTest {
// Special cases from Math.pow javadoc:
// If the second argument is positive or negative zero, then the result is 1.0.
for (double d : DOUBLES) {
- assertEquals(1.0, FastMath.pow(d, 0.0), EXACT);
+ assertEquals(1.0, AccurateMath.pow(d, 0.0), EXACT);
}
for (double d : DOUBLES) {
- assertEquals(1.0, FastMath.pow(d, -0.0), EXACT);
+ assertEquals(1.0, AccurateMath.pow(d, -0.0), EXACT);
}
// If the second argument is 1.0, then the result is the same as the first argument.
for (double d : DOUBLES) {
- assertEquals(d, FastMath.pow(d, 1.0), EXACT);
+ assertEquals(d, AccurateMath.pow(d, 1.0), EXACT);
}
// If the second argument is NaN, then the result is NaN.
for (double d : DOUBLES) {
- assertEquals(Double.NaN, FastMath.pow(d, Double.NaN), EXACT);
+ assertEquals(Double.NaN, AccurateMath.pow(d, Double.NaN), EXACT);
}
// If the first argument is NaN and the second argument is nonzero, then the result is NaN.
for (double i : DOUBLES) {
if (i != 0.0) {
- assertEquals(Double.NaN, FastMath.pow(Double.NaN, i), EXACT);
+ assertEquals(Double.NaN, AccurateMath.pow(Double.NaN, i), EXACT);
}
}
// If the absolute value of the first argument is greater than 1 and the second argument is positive infinity, or
// the absolute value of the first argument is less than 1 and the second argument is negative infinity, then the result is positive infinity.
for (double d : DOUBLES) {
if (Math.abs(d) > 1.0) {
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(d, Double.POSITIVE_INFINITY), EXACT);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(d, Double.POSITIVE_INFINITY), EXACT);
}
}
for (double d : DOUBLES) {
if (Math.abs(d) < 1.0) {
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(d, Double.NEGATIVE_INFINITY), EXACT);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(d, Double.NEGATIVE_INFINITY), EXACT);
}
}
// If the absolute value of the first argument is greater than 1 and the second argument is negative infinity, or
// the absolute value of the first argument is less than 1 and the second argument is positive infinity, then the result is positive zero.
for (double d : DOUBLES) {
if (Math.abs(d) > 1.0) {
- assertEquals(0.0, FastMath.pow(d, Double.NEGATIVE_INFINITY), EXACT);
+ assertEquals(0.0, AccurateMath.pow(d, Double.NEGATIVE_INFINITY), EXACT);
}
}
for (double d : DOUBLES) {
if (Math.abs(d) < 1.0) {
- assertEquals(0.0, FastMath.pow(d, Double.POSITIVE_INFINITY), EXACT);
+ assertEquals(0.0, AccurateMath.pow(d, Double.POSITIVE_INFINITY), EXACT);
}
}
// If the absolute value of the first argument equals 1 and the second argument is infinite, then the result is NaN.
- assertEquals(Double.NaN, FastMath.pow(1.0, Double.POSITIVE_INFINITY), EXACT);
- assertEquals(Double.NaN, FastMath.pow(1.0, Double.NEGATIVE_INFINITY), EXACT);
- assertEquals(Double.NaN, FastMath.pow(-1.0, Double.POSITIVE_INFINITY), EXACT);
- assertEquals(Double.NaN, FastMath.pow(-1.0, Double.NEGATIVE_INFINITY), EXACT);
+ assertEquals(Double.NaN, AccurateMath.pow(1.0, Double.POSITIVE_INFINITY), EXACT);
+ assertEquals(Double.NaN, AccurateMath.pow(1.0, Double.NEGATIVE_INFINITY), EXACT);
+ assertEquals(Double.NaN, AccurateMath.pow(-1.0, Double.POSITIVE_INFINITY), EXACT);
+ assertEquals(Double.NaN, AccurateMath.pow(-1.0, Double.NEGATIVE_INFINITY), EXACT);
// If the first argument is positive zero and the second argument is greater than zero, or
// the first argument is positive infinity and the second argument is less than zero, then the result is positive zero.
for (double i : DOUBLES) {
if (i > 0.0) {
- assertEquals(0.0, FastMath.pow(0.0, i), EXACT);
+ assertEquals(0.0, AccurateMath.pow(0.0, i), EXACT);
}
}
for (double i : DOUBLES) {
if (i < 0.0) {
- assertEquals(0.0, FastMath.pow(Double.POSITIVE_INFINITY, i), EXACT);
+ assertEquals(0.0, AccurateMath.pow(Double.POSITIVE_INFINITY, i), EXACT);
}
}
// If the first argument is positive zero and the second argument is less than zero, or
// the first argument is positive infinity and the second argument is greater than zero, then the result is positive infinity.
for (double i : DOUBLES) {
if (i < 0.0) {
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(0.0, i), EXACT);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(0.0, i), EXACT);
}
}
for (double i : DOUBLES) {
if (i > 0.0) {
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(Double.POSITIVE_INFINITY, i), EXACT);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(Double.POSITIVE_INFINITY, i), EXACT);
}
}
// If the first argument is negative zero and the second argument is greater than zero but not a finite odd integer, or
// the first argument is negative infinity and the second argument is less than zero but not a finite odd integer, then the result is positive zero.
for (double i : DOUBLES) {
if (i > 0.0 && (Double.isInfinite(i) || i % 2.0 == 0.0)) {
- assertEquals(0.0, FastMath.pow(-0.0, i), EXACT);
+ assertEquals(0.0, AccurateMath.pow(-0.0, i), EXACT);
}
}
for (double i : DOUBLES) {
if (i < 0.0 && (Double.isInfinite(i) || i % 2.0 == 0.0)) {
- assertEquals(0.0, FastMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
+ assertEquals(0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
}
}
// If the first argument is negative zero and the second argument is a positive finite odd integer, or
// the first argument is negative infinity and the second argument is a negative finite odd integer, then the result is negative zero.
for (double i : DOUBLES) {
if (i > 0.0 && i % 2.0 == 1.0) {
- assertEquals(-0.0, FastMath.pow(-0.0, i), EXACT);
+ assertEquals(-0.0, AccurateMath.pow(-0.0, i), EXACT);
}
}
for (double i : DOUBLES) {
if (i < 0.0 && i % 2.0 == -1.0) {
- assertEquals(-0.0, FastMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
+ assertEquals(-0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
}
}
// If the first argument is negative zero and the second argument is less than zero but not a finite odd integer, or
// the first argument is negative infinity and the second argument is greater than zero but not a finite odd integer, then the result is positive infinity.
for (double i : DOUBLES) {
if (i > 0.0 && (Double.isInfinite(i) || i % 2.0 == 0.0)) {
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
}
}
for (double i : DOUBLES) {
if (i < 0.0 && (Double.isInfinite(i) || i % 2.0 == 0.0)) {
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(-0.0, i), EXACT);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(-0.0, i), EXACT);
}
}
// If the first argument is negative zero and the second argument is a negative finite odd integer, or
// the first argument is negative infinity and the second argument is a positive finite odd integer, then the result is negative infinity.
for (double i : DOUBLES) {
if (i > 0.0 && i % 2.0 == 1.0) {
- assertEquals(Double.NEGATIVE_INFINITY, FastMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
+ assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
}
}
for (double i : DOUBLES) {
if (i < 0.0 && i % 2.0 == -1.0) {
- assertEquals(Double.NEGATIVE_INFINITY, FastMath.pow(-0.0, i), EXACT);
+ assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.pow(-0.0, i), EXACT);
}
}
for (double d : DOUBLES) {
@@ -558,11 +558,11 @@ public class FastMathTest {
for (double i : DOUBLES) {
if (Math.abs(i) <= Double.MAX_VALUE) {
// if the second argument is a finite even integer, the result is equal to the result of raising the absolute value of the first argument to the power of the second argument
- if (i % 2.0 == 0.0) assertEquals(FastMath.pow(-d, i), FastMath.pow(d, i), EXACT);
+ if (i % 2.0 == 0.0) assertEquals(AccurateMath.pow(-d, i), AccurateMath.pow(d, i), EXACT);
// if the second argument is a finite odd integer, the result is equal to the negative of the result of raising the absolute value of the first argument to the power of the second argument
- else if (Math.abs(i) % 2.0 == 1.0) assertEquals(-FastMath.pow(-d, i), FastMath.pow(d, i), EXACT);
+ else if (Math.abs(i) % 2.0 == 1.0) assertEquals(-AccurateMath.pow(-d, i), AccurateMath.pow(d, i), EXACT);
// if the second argument is finite and not an integer, then the result is NaN.
- else assertEquals(Double.NaN, FastMath.pow(d, i), EXACT);
+ else assertEquals(Double.NaN, AccurateMath.pow(d, i), EXACT);
}
}
}
@@ -594,7 +594,7 @@ public class FastMathTest {
if (dNegative && bi.testBit( 0 )) {
expected = -expected;
}
- assertEquals(d + "^" + i + "=" + expected + ", Math.pow=" + Math.pow(d, i), expected, FastMath.pow(d, i), expected == 0.0 || Double.isInfinite(expected) || Double.isNaN(expected) ? EXACT : 2.0 * Math.ulp(expected));
+ assertEquals(d + "^" + i + "=" + expected + ", Math.pow=" + Math.pow(d, i), expected, AccurateMath.pow(d, i), expected == 0.0 || Double.isInfinite(expected) || Double.isNaN(expected) ? EXACT : 2.0 * Math.ulp(expected));
}
}
}
@@ -603,46 +603,46 @@ public class FastMathTest {
@Test
public void testPowLargeIntegralDouble() {
- double y = FastMath.scalb(1.0, 65);
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(FastMath.nextUp(1.0), y), 1.0);
- assertEquals(1.0, FastMath.pow(1.0, y), 1.0);
- assertEquals(0.0, FastMath.pow(FastMath.nextDown(1.0), y), 1.0);
- assertEquals(0.0, FastMath.pow(FastMath.nextUp(-1.0), y), 1.0);
- assertEquals(1.0, FastMath.pow(-1.0, y), 1.0);
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(FastMath.nextDown(-1.0), y), 1.0);
+ double y = AccurateMath.scalb(1.0, 65);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(AccurateMath.nextUp(1.0), y), 1.0);
+ assertEquals(1.0, AccurateMath.pow(1.0, y), 1.0);
+ assertEquals(0.0, AccurateMath.pow(AccurateMath.nextDown(1.0), y), 1.0);
+ assertEquals(0.0, AccurateMath.pow(AccurateMath.nextUp(-1.0), y), 1.0);
+ assertEquals(1.0, AccurateMath.pow(-1.0, y), 1.0);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(AccurateMath.nextDown(-1.0), y), 1.0);
}
@Test
public void testAtan2SpecialCases() {
- assertTrue("atan2(NaN, 0.0) should be NaN", Double.isNaN(FastMath.atan2(Double.NaN, 0.0)));
- assertTrue("atan2(0.0, NaN) should be NaN", Double.isNaN(FastMath.atan2(0.0, Double.NaN)));
- assertEquals("atan2(0.0, 0.0) should be 0.0", 0.0, FastMath.atan2(0.0, 0.0), Precision.EPSILON);
- assertEquals("atan2(0.0, 0.001) should be 0.0", 0.0, FastMath.atan2(0.0, 0.001), Precision.EPSILON);
- assertEquals("atan2(0.1, +Inf) should be 0.0", 0.0, FastMath.atan2(0.1, Double.POSITIVE_INFINITY), Precision.EPSILON);
- assertEquals("atan2(-0.0, 0.0) should be -0.0", -0.0, FastMath.atan2(-0.0, 0.0), Precision.EPSILON);
- assertEquals("atan2(-0.0, 0.001) should be -0.0", -0.0, FastMath.atan2(-0.0, 0.001), Precision.EPSILON);
- assertEquals("atan2(-0.0, +Inf) should be -0.0", -0.0, FastMath.atan2(-0.1, Double.POSITIVE_INFINITY), Precision.EPSILON);
- assertEquals("atan2(0.0, -0.0) should be PI", FastMath.PI, FastMath.atan2(0.0, -0.0), Precision.EPSILON);
- assertEquals("atan2(0.1, -Inf) should be PI", FastMath.PI, FastMath.atan2(0.1, Double.NEGATIVE_INFINITY), Precision.EPSILON);
- assertEquals("atan2(-0.0, -0.0) should be -PI", -FastMath.PI, FastMath.atan2(-0.0, -0.0), Precision.EPSILON);
- assertEquals("atan2(0.1, -Inf) should be -PI", -FastMath.PI, FastMath.atan2(-0.1, Double.NEGATIVE_INFINITY), Precision.EPSILON);
- assertEquals("atan2(0.1, 0.0) should be PI/2", FastMath.PI / 2.0, FastMath.atan2(0.1, 0.0), Precision.EPSILON);
- assertEquals("atan2(0.1, -0.0) should be PI/2", FastMath.PI / 2.0, FastMath.atan2(0.1, -0.0), Precision.EPSILON);
- assertEquals("atan2(Inf, 0.1) should be PI/2", FastMath.PI / 2.0, FastMath.atan2(Double.POSITIVE_INFINITY, 0.1), Precision.EPSILON);
- assertEquals("atan2(Inf, -0.1) should be PI/2", FastMath.PI / 2.0, FastMath.atan2(Double.POSITIVE_INFINITY, -0.1), Precision.EPSILON);
- assertEquals("atan2(-0.1, 0.0) should be -PI/2", -FastMath.PI / 2.0, FastMath.atan2(-0.1, 0.0), Precision.EPSILON);
- assertEquals("atan2(-0.1, -0.0) should be -PI/2", -FastMath.PI / 2.0, FastMath.atan2(-0.1, -0.0), Precision.EPSILON);
- assertEquals("atan2(-Inf, 0.1) should be -PI/2", -FastMath.PI / 2.0, FastMath.atan2(Double.NEGATIVE_INFINITY, 0.1), Precision.EPSILON);
- assertEquals("atan2(-Inf, -0.1) should be -PI/2", -FastMath.PI / 2.0, FastMath.atan2(Double.NEGATIVE_INFINITY, -0.1), Precision.EPSILON);
- assertEquals("atan2(Inf, Inf) should be PI/4", FastMath.PI / 4.0, FastMath.atan2(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY),
+ assertTrue("atan2(NaN, 0.0) should be NaN", Double.isNaN(AccurateMath.atan2(Double.NaN, 0.0)));
+ assertTrue("atan2(0.0, NaN) should be NaN", Double.isNaN(AccurateMath.atan2(0.0, Double.NaN)));
+ assertEquals("atan2(0.0, 0.0) should be 0.0", 0.0, AccurateMath.atan2(0.0, 0.0), Precision.EPSILON);
+ assertEquals("atan2(0.0, 0.001) should be 0.0", 0.0, AccurateMath.atan2(0.0, 0.001), Precision.EPSILON);
+ assertEquals("atan2(0.1, +Inf) should be 0.0", 0.0, AccurateMath.atan2(0.1, Double.POSITIVE_INFINITY), Precision.EPSILON);
+ assertEquals("atan2(-0.0, 0.0) should be -0.0", -0.0, AccurateMath.atan2(-0.0, 0.0), Precision.EPSILON);
+ assertEquals("atan2(-0.0, 0.001) should be -0.0", -0.0, AccurateMath.atan2(-0.0, 0.001), Precision.EPSILON);
+ assertEquals("atan2(-0.0, +Inf) should be -0.0", -0.0, AccurateMath.atan2(-0.1, Double.POSITIVE_INFINITY), Precision.EPSILON);
+ assertEquals("atan2(0.0, -0.0) should be PI", AccurateMath.PI, AccurateMath.atan2(0.0, -0.0), Precision.EPSILON);
+ assertEquals("atan2(0.1, -Inf) should be PI", AccurateMath.PI, AccurateMath.atan2(0.1, Double.NEGATIVE_INFINITY), Precision.EPSILON);
+ assertEquals("atan2(-0.0, -0.0) should be -PI", -AccurateMath.PI, AccurateMath.atan2(-0.0, -0.0), Precision.EPSILON);
+ assertEquals("atan2(0.1, -Inf) should be -PI", -AccurateMath.PI, AccurateMath.atan2(-0.1, Double.NEGATIVE_INFINITY), Precision.EPSILON);
+ assertEquals("atan2(0.1, 0.0) should be PI/2", AccurateMath.PI / 2.0, AccurateMath.atan2(0.1, 0.0), Precision.EPSILON);
+ assertEquals("atan2(0.1, -0.0) should be PI/2", AccurateMath.PI / 2.0, AccurateMath.atan2(0.1, -0.0), Precision.EPSILON);
+ assertEquals("atan2(Inf, 0.1) should be PI/2", AccurateMath.PI / 2.0, AccurateMath.atan2(Double.POSITIVE_INFINITY, 0.1), Precision.EPSILON);
+ assertEquals("atan2(Inf, -0.1) should be PI/2", AccurateMath.PI / 2.0, AccurateMath.atan2(Double.POSITIVE_INFINITY, -0.1), Precision.EPSILON);
+ assertEquals("atan2(-0.1, 0.0) should be -PI/2", -AccurateMath.PI / 2.0, AccurateMath.atan2(-0.1, 0.0), Precision.EPSILON);
+ assertEquals("atan2(-0.1, -0.0) should be -PI/2", -AccurateMath.PI / 2.0, AccurateMath.atan2(-0.1, -0.0), Precision.EPSILON);
+ assertEquals("atan2(-Inf, 0.1) should be -PI/2", -AccurateMath.PI / 2.0, AccurateMath.atan2(Double.NEGATIVE_INFINITY, 0.1), Precision.EPSILON);
+ assertEquals("atan2(-Inf, -0.1) should be -PI/2", -AccurateMath.PI / 2.0, AccurateMath.atan2(Double.NEGATIVE_INFINITY, -0.1), Precision.EPSILON);
+ assertEquals("atan2(Inf, Inf) should be PI/4", AccurateMath.PI / 4.0, AccurateMath.atan2(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY),
Precision.EPSILON);
- assertEquals("atan2(Inf, -Inf) should be PI * 3/4", FastMath.PI * 3.0 / 4.0,
- FastMath.atan2(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON);
- assertEquals("atan2(-Inf, Inf) should be -PI/4", -FastMath.PI / 4.0, FastMath.atan2(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY),
+ assertEquals("atan2(Inf, -Inf) should be PI * 3/4", AccurateMath.PI * 3.0 / 4.0,
+ AccurateMath.atan2(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON);
+ assertEquals("atan2(-Inf, Inf) should be -PI/4", -AccurateMath.PI / 4.0, AccurateMath.atan2(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY),
Precision.EPSILON);
- assertEquals("atan2(-Inf, -Inf) should be -PI * 3/4", - FastMath.PI * 3.0 / 4.0,
- FastMath.atan2(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON);
+ assertEquals("atan2(-Inf, -Inf) should be -PI * 3/4", - AccurateMath.PI * 3.0 / 4.0,
+ AccurateMath.atan2(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON);
}
@Test
@@ -653,14 +653,14 @@ public class FastMathTest {
double x = (generator.nextDouble() * 2.0 + 0.25);
double y = (generator.nextDouble() * 1200.0 - 600.0) * generator.nextDouble();
/*
- * double x = FastMath.floor(generator.nextDouble()*1024.0 - 512.0); double
- * y; if (x != 0) y = FastMath.floor(512.0 / FastMath.abs(x)); else
- * y = generator.nextDouble()*1200.0; y = y - y/2; x = FastMath.pow(2.0, x) *
+ * double x = AccurateMath.floor(generator.nextDouble()*1024.0 - 512.0); double
+ * y; if (x != 0) y = AccurateMath.floor(512.0 / AccurateMath.abs(x)); else
+ * y = generator.nextDouble()*1200.0; y = y - y/2; x = AccurateMath.pow(2.0, x) *
* generator.nextDouble(); y = y * generator.nextDouble();
*/
// double x = generator.nextDouble()*2.0;
- double tst = FastMath.pow(x, y);
+ double tst = AccurateMath.pow(x, y);
double ref = DfpMath.pow(field.newDfp(x), field.newDfp(y)).toDouble();
double err = (tst - ref) / ref;
@@ -687,7 +687,7 @@ public class FastMathTest {
// double x = (generator.nextDouble() * 20.0) - 10.0;
// double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble();
/* double x = 3.0 / 512.0 * i - 3.0; */
- double tst = FastMath.exp(x);
+ double tst = AccurateMath.exp(x);
double ref = DfpMath.exp(field.newDfp(x)).toDouble();
double err = (tst - ref) / ref;
@@ -716,7 +716,7 @@ public class FastMathTest {
// double x = (generator.nextDouble() * 20.0) - 10.0;
// double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble();
/* double x = 3.0 / 512.0 * i - 3.0; */
- double tst = FastMath.sin(x);
+ double tst = AccurateMath.sin(x);
double ref = DfpMath.sin(field.newDfp(x)).toDouble();
double err = (tst - ref) / ref;
@@ -745,7 +745,7 @@ public class FastMathTest {
// double x = (generator.nextDouble() * 20.0) - 10.0;
// double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble();
/* double x = 3.0 / 512.0 * i - 3.0; */
- double tst = FastMath.cos(x);
+ double tst = AccurateMath.cos(x);
double ref = DfpMath.cos(field.newDfp(x)).toDouble();
double err = (tst - ref) / ref;
@@ -774,7 +774,7 @@ public class FastMathTest {
// double x = (generator.nextDouble() * 20.0) - 10.0;
// double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble();
/* double x = 3.0 / 512.0 * i - 3.0; */
- double tst = FastMath.tan(x);
+ double tst = AccurateMath.tan(x);
double ref = DfpMath.tan(field.newDfp(x)).toDouble();
double err = (tst - ref) / ref;
@@ -805,7 +805,7 @@ public class FastMathTest {
// double x = (generator.nextDouble() * 20.0) - 10.0;
// double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble();
/* double x = 3.0 / 512.0 * i - 3.0; */
- double tst = FastMath.atan(x);
+ double tst = AccurateMath.atan(x);
double ref = DfpMath.atan(field.newDfp(x)).toDouble();
double err = (tst - ref) / ref;
@@ -834,7 +834,7 @@ public class FastMathTest {
// double x = (generator.nextDouble() * 20.0) - 10.0;
// double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble();
/* double x = 3.0 / 512.0 * i - 3.0; */
- double tst = FastMath.atan2(y, x);
+ double tst = AccurateMath.atan2(y, x);
Dfp refdfp = DfpMath.atan(field.newDfp(y).divide(field.newDfp(x)));
/* Make adjustments for sign */
if (x < 0.0) {
@@ -870,7 +870,7 @@ public class FastMathTest {
// double x = (generator.nextDouble() * 20.0) - 10.0;
double x = ((generator.nextDouble() * 16.0) - 8.0) * generator.nextDouble();
/* double x = 3.0 / 512.0 * i - 3.0; */
- double tst = FastMath.expm1(x);
+ double tst = AccurateMath.expm1(x);
double ref = DfpMath.exp(field.newDfp(x)).subtract(field.getOne()).toDouble();
double err = (tst - ref) / ref;
@@ -894,7 +894,7 @@ public class FastMathTest {
for (int i=0; i<10000; i++) {
double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble();
- double tst = FastMath.asin(x);
+ double tst = AccurateMath.asin(x);
double ref = DfpMath.asin(field.newDfp(x)).toDouble();
double err = (tst - ref) / ref;
@@ -917,7 +917,7 @@ public class FastMathTest {
for (int i=0; i<10000; i++) {
double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble();
- double tst = FastMath.acos(x);
+ double tst = AccurateMath.acos(x);
double ref = DfpMath.acos(field.newDfp(x)).toDouble();
double err = (tst - ref) / ref;
@@ -939,12 +939,12 @@ public class FastMathTest {
@Test
public void testAcosSpecialCases() {
- assertTrue("acos(NaN) should be NaN", Double.isNaN(FastMath.acos(Double.NaN)));
- assertTrue("acos(-1.1) should be NaN", Double.isNaN(FastMath.acos(-1.1)));
- assertTrue("acos(-1.1) should be NaN", Double.isNaN(FastMath.acos(1.1)));
- assertEquals("acos(-1.0) should be PI", FastMath.acos(-1.0), FastMath.PI, Precision.EPSILON);
- assertEquals("acos(1.0) should be 0.0", FastMath.acos(1.0), 0.0, Precision.EPSILON);
- assertEquals("acos(0.0) should be PI/2", FastMath.acos(0.0), FastMath.PI / 2.0, Precision.EPSILON);
+ assertTrue("acos(NaN) should be NaN", Double.isNaN(AccurateMath.acos(Double.NaN)));
+ assertTrue("acos(-1.1) should be NaN", Double.isNaN(AccurateMath.acos(-1.1)));
+ assertTrue("acos(-1.1) should be NaN", Double.isNaN(AccurateMath.acos(1.1)));
+ assertEquals("acos(-1.0) should be PI", AccurateMath.acos(-1.0), AccurateMath.PI, Precision.EPSILON);
+ assertEquals("acos(1.0) should be 0.0", AccurateMath.acos(1.0), 0.0, Precision.EPSILON);
+ assertEquals("acos(0.0) should be PI/2", AccurateMath.acos(0.0), AccurateMath.PI / 2.0, Precision.EPSILON);
}
/**
@@ -953,12 +953,12 @@ public class FastMathTest {
@Test
public void testAsinSpecialCases() {
- assertTrue("asin(NaN) should be NaN", Double.isNaN(FastMath.asin(Double.NaN)));
- assertTrue("asin(1.1) should be NaN", Double.isNaN(FastMath.asin(1.1)));
- assertTrue("asin(-1.1) should be NaN", Double.isNaN(FastMath.asin(-1.1)));
- assertEquals("asin(1.0) should be PI/2", FastMath.asin(1.0), FastMath.PI / 2.0, Precision.EPSILON);
- assertEquals("asin(-1.0) should be -PI/2", FastMath.asin(-1.0), -FastMath.PI / 2.0, Precision.EPSILON);
- assertEquals("asin(0.0) should be 0.0", FastMath.asin(0.0), 0.0, Precision.EPSILON);
+ assertTrue("asin(NaN) should be NaN", Double.isNaN(AccurateMath.asin(Double.NaN)));
+ assertTrue("asin(1.1) should be NaN", Double.isNaN(AccurateMath.asin(1.1)));
+ assertTrue("asin(-1.1) should be NaN", Double.isNaN(AccurateMath.asin(-1.1)));
+ assertEquals("asin(1.0) should be PI/2", AccurateMath.asin(1.0), AccurateMath.PI / 2.0, Precision.EPSILON);
+ assertEquals("asin(-1.0) should be -PI/2", AccurateMath.asin(-1.0), -AccurateMath.PI / 2.0, Precision.EPSILON);
+ assertEquals("asin(0.0) should be 0.0", AccurateMath.asin(0.0), 0.0, Precision.EPSILON);
}
private Dfp cosh(Dfp x) {
@@ -980,7 +980,7 @@ public class FastMathTest {
for (int i=0; i<10000; i++) {
double x = ((generator.nextDouble() * 16.0) - 8.0) * generator.nextDouble();
- double tst = FastMath.sinh(x);
+ double tst = AccurateMath.sinh(x);
double ref = sinh(field.newDfp(x)).toDouble();
double err = (tst - ref) / ref;
@@ -1002,7 +1002,7 @@ public class FastMathTest {
for (int i=0; i<10000; i++) {
double x = ((generator.nextDouble() * 16.0) - 8.0) * generator.nextDouble();
- double tst = FastMath.cosh(x);
+ double tst = AccurateMath.cosh(x);
double ref = cosh(field.newDfp(x)).toDouble();
double err = (tst - ref) / ref;
@@ -1024,7 +1024,7 @@ public class FastMathTest {
for (int i=0; i<10000; i++) {
double x = ((generator.nextDouble() * 16.0) - 8.0) * generator.nextDouble();
- double tst = FastMath.tanh(x);
+ double tst = AccurateMath.tanh(x);
double ref = tanh(field.newDfp(x)).toDouble();
double err = (tst - ref) / ref;
@@ -1046,7 +1046,7 @@ public class FastMathTest {
for (int i=0; i<10000; i++) {
double x = ((generator.nextDouble() * 200.0) - 100.0) * generator.nextDouble();
- double tst = FastMath.cbrt(x);
+ double tst = AccurateMath.cbrt(x);
double ref = cbrt(field.newDfp(x)).toDouble();
double err = (tst - ref) / ref;
@@ -1084,7 +1084,7 @@ public class FastMathTest {
for (int i = 0; i < NUMBER_OF_TRIALS; i++) {
double x = generator.nextDouble();
double tst = field.newDfp(x).multiply(180).divide(field.getPi()).toDouble();
- double ref = FastMath.toDegrees(x);
+ double ref = AccurateMath.toDegrees(x);
double err = (tst - ref) / ref;
if (err != 0) {
@@ -1105,7 +1105,7 @@ public class FastMathTest {
for (int i = 0; i < NUMBER_OF_TRIALS; i++) {
double x = generator.nextDouble();
double tst = field.newDfp(x).multiply(field.getPi()).divide(180).toDouble();
- double ref = FastMath.toRadians(x);
+ double ref = AccurateMath.toRadians(x);
double err = (tst - ref) / ref;
if (err != 0) {
@@ -1124,133 +1124,133 @@ public class FastMathTest {
@Test
public void testNextAfter() {
// 0x402fffffffffffff 0x404123456789abcd -> 4030000000000000
- assertEquals(16.0, FastMath.nextUp(15.999999999999998), 0.0);
+ assertEquals(16.0, AccurateMath.nextUp(15.999999999999998), 0.0);
// 0xc02fffffffffffff 0x404123456789abcd -> c02ffffffffffffe
- assertEquals(-15.999999999999996, FastMath.nextAfter(-15.999999999999998, 34.27555555555555), 0.0);
+ assertEquals(-15.999999999999996, AccurateMath.nextAfter(-15.999999999999998, 34.27555555555555), 0.0);
// 0x402fffffffffffff 0x400123456789abcd -> 402ffffffffffffe
- assertEquals(15.999999999999996, FastMath.nextDown(15.999999999999998), 0.0);
+ assertEquals(15.999999999999996, AccurateMath.nextDown(15.999999999999998), 0.0);
// 0xc02fffffffffffff 0x400123456789abcd -> c02ffffffffffffe
- assertEquals(-15.999999999999996, FastMath.nextAfter(-15.999999999999998, 2.142222222222222), 0.0);
+ assertEquals(-15.999999999999996, AccurateMath.nextAfter(-15.999999999999998, 2.142222222222222), 0.0);
// 0x4020000000000000 0x404123456789abcd -> 4020000000000001
- assertEquals(8.000000000000002, FastMath.nextAfter(8.0, 34.27555555555555), 0.0);
+ assertEquals(8.000000000000002, AccurateMath.nextAfter(8.0, 34.27555555555555), 0.0);
// 0xc020000000000000 0x404123456789abcd -> c01fffffffffffff
- assertEquals(-7.999999999999999, FastMath.nextAfter(-8.0, 34.27555555555555), 0.0);
+ assertEquals(-7.999999999999999, AccurateMath.nextAfter(-8.0, 34.27555555555555), 0.0);
// 0x4020000000000000 0x400123456789abcd -> 401fffffffffffff
- assertEquals(7.999999999999999, FastMath.nextAfter(8.0, 2.142222222222222), 0.0);
+ assertEquals(7.999999999999999, AccurateMath.nextAfter(8.0, 2.142222222222222), 0.0);
// 0xc020000000000000 0x400123456789abcd -> c01fffffffffffff
- assertEquals(-7.999999999999999, FastMath.nextAfter(-8.0, 2.142222222222222), 0.0);
+ assertEquals(-7.999999999999999, AccurateMath.nextAfter(-8.0, 2.142222222222222), 0.0);
// 0x3f2e43753d36a223 0x3f2e43753d36a224 -> 3f2e43753d36a224
- assertEquals(2.308922399667661E-4, FastMath.nextAfter(2.3089223996676606E-4, 2.308922399667661E-4), 0.0);
+ assertEquals(2.308922399667661E-4, AccurateMath.nextAfter(2.3089223996676606E-4, 2.308922399667661E-4), 0.0);
// 0x3f2e43753d36a223 0x3f2e43753d36a223 -> 3f2e43753d36a223
- assertEquals(2.3089223996676606E-4, FastMath.nextAfter(2.3089223996676606E-4, 2.3089223996676606E-4), 0.0);
+ assertEquals(2.3089223996676606E-4, AccurateMath.nextAfter(2.3089223996676606E-4, 2.3089223996676606E-4), 0.0);
// 0x3f2e43753d36a223 0x3f2e43753d36a222 -> 3f2e43753d36a222
- assertEquals(2.3089223996676603E-4, FastMath.nextAfter(2.3089223996676606E-4, 2.3089223996676603E-4), 0.0);
+ assertEquals(2.3089223996676603E-4, AccurateMath.nextAfter(2.3089223996676606E-4, 2.3089223996676603E-4), 0.0);
// 0x3f2e43753d36a223 0xbf2e43753d36a224 -> 3f2e43753d36a222
- assertEquals(2.3089223996676603E-4, FastMath.nextAfter(2.3089223996676606E-4, -2.308922399667661E-4), 0.0);
+ assertEquals(2.3089223996676603E-4, AccurateMath.nextAfter(2.3089223996676606E-4, -2.308922399667661E-4), 0.0);
// 0x3f2e43753d36a223 0xbf2e43753d36a223 -> 3f2e43753d36a222
- assertEquals(2.3089223996676603E-4, FastMath.nextAfter(2.3089223996676606E-4, -2.3089223996676606E-4), 0.0);
+ assertEquals(2.3089223996676603E-4, AccurateMath.nextAfter(2.3089223996676606E-4, -2.3089223996676606E-4), 0.0);
// 0x3f2e43753d36a223 0xbf2e43753d36a222 -> 3f2e43753d36a222
- assertEquals(2.3089223996676603E-4, FastMath.nextAfter(2.3089223996676606E-4, -2.3089223996676603E-4), 0.0);
+ assertEquals(2.3089223996676603E-4, AccurateMath.nextAfter(2.3089223996676606E-4, -2.3089223996676603E-4), 0.0);
// 0xbf2e43753d36a223 0x3f2e43753d36a224 -> bf2e43753d36a222
- assertEquals(-2.3089223996676603E-4, FastMath.nextAfter(-2.3089223996676606E-4, 2.308922399667661E-4), 0.0);
+ assertEquals(-2.3089223996676603E-4, AccurateMath.nextAfter(-2.3089223996676606E-4, 2.308922399667661E-4), 0.0);
// 0xbf2e43753d36a223 0x3f2e43753d36a223 -> bf2e43753d36a222
- assertEquals(-2.3089223996676603E-4, FastMath.nextAfter(-2.3089223996676606E-4, 2.3089223996676606E-4), 0.0);
+ assertEquals(-2.3089223996676603E-4, AccurateMath.nextAfter(-2.3089223996676606E-4, 2.3089223996676606E-4), 0.0);
// 0xbf2e43753d36a223 0x3f2e43753d36a222 -> bf2e43753d36a222
- assertEquals(-2.3089223996676603E-4, FastMath.nextAfter(-2.3089223996676606E-4, 2.3089223996676603E-4), 0.0);
+ assertEquals(-2.3089223996676603E-4, AccurateMath.nextAfter(-2.3089223996676606E-4, 2.3089223996676603E-4), 0.0);
// 0xbf2e43753d36a223 0xbf2e43753d36a224 -> bf2e43753d36a224
- assertEquals(-2.308922399667661E-4, FastMath.nextAfter(-2.3089223996676606E-4, -2.308922399667661E-4), 0.0);
+ assertEquals(-2.308922399667661E-4, AccurateMath.nextAfter(-2.3089223996676606E-4, -2.308922399667661E-4), 0.0);
// 0xbf2e43753d36a223 0xbf2e43753d36a223 -> bf2e43753d36a223
- assertEquals(-2.3089223996676606E-4, FastMath.nextAfter(-2.3089223996676606E-4, -2.3089223996676606E-4), 0.0);
+ assertEquals(-2.3089223996676606E-4, AccurateMath.nextAfter(-2.3089223996676606E-4, -2.3089223996676606E-4), 0.0);
// 0xbf2e43753d36a223 0xbf2e43753d36a222 -> bf2e43753d36a222
- assertEquals(-2.3089223996676603E-4, FastMath.nextAfter(-2.3089223996676606E-4, -2.3089223996676603E-4), 0.0);
+ assertEquals(-2.3089223996676603E-4, AccurateMath.nextAfter(-2.3089223996676606E-4, -2.3089223996676603E-4), 0.0);
}
@Test
public void testDoubleNextAfterSpecialCases() {
- assertEquals(-Double.MAX_VALUE,FastMath.nextAfter(Double.NEGATIVE_INFINITY, 0D), 0D);
- assertEquals(Double.MAX_VALUE,FastMath.nextAfter(Double.POSITIVE_INFINITY, 0D), 0D);
- assertEquals(Double.NaN,FastMath.nextAfter(Double.NaN, 0D), 0D);
- assertEquals(Double.POSITIVE_INFINITY,FastMath.nextAfter(Double.MAX_VALUE, Double.POSITIVE_INFINITY), 0D);
- assertEquals(Double.NEGATIVE_INFINITY,FastMath.nextAfter(-Double.MAX_VALUE, Double.NEGATIVE_INFINITY), 0D);
- assertEquals(Double.MIN_VALUE, FastMath.nextAfter(0D, 1D), 0D);
- assertEquals(-Double.MIN_VALUE, FastMath.nextAfter(0D, -1D), 0D);
- assertEquals(0D, FastMath.nextAfter(Double.MIN_VALUE, -1), 0D);
- assertEquals(0D, FastMath.nextAfter(-Double.MIN_VALUE, 1), 0D);
+ assertEquals(-Double.MAX_VALUE,AccurateMath.nextAfter(Double.NEGATIVE_INFINITY, 0D), 0D);
+ assertEquals(Double.MAX_VALUE,AccurateMath.nextAfter(Double.POSITIVE_INFINITY, 0D), 0D);
+ assertEquals(Double.NaN,AccurateMath.nextAfter(Double.NaN, 0D), 0D);
+ assertEquals(Double.POSITIVE_INFINITY,AccurateMath.nextAfter(Double.MAX_VALUE, Double.POSITIVE_INFINITY), 0D);
+ assertEquals(Double.NEGATIVE_INFINITY,AccurateMath.nextAfter(-Double.MAX_VALUE, Double.NEGATIVE_INFINITY), 0D);
+ assertEquals(Double.MIN_VALUE, AccurateMath.nextAfter(0D, 1D), 0D);
+ assertEquals(-Double.MIN_VALUE, AccurateMath.nextAfter(0D, -1D), 0D);
+ assertEquals(0D, AccurateMath.nextAfter(Double.MIN_VALUE, -1), 0D);
+ assertEquals(0D, AccurateMath.nextAfter(-Double.MIN_VALUE, 1), 0D);
}
@Test
public void testFloatNextAfterSpecialCases() {
- assertEquals(-Float.MAX_VALUE, FastMath.nextAfter(Float.NEGATIVE_INFINITY, 0F), 0F);
- assertEquals(Float.MAX_VALUE, FastMath.nextAfter(Float.POSITIVE_INFINITY, 0F), 0F);
- assertEquals(Float.NaN, FastMath.nextAfter(Float.NaN, 0F), 0F);
- assertEquals(Float.POSITIVE_INFINITY, FastMath.nextUp(Float.MAX_VALUE), 0F);
- assertEquals(Float.NEGATIVE_INFINITY, FastMath.nextDown(-Float.MAX_VALUE), 0F);
- assertEquals(Float.MIN_VALUE, FastMath.nextAfter(0F, 1F), 0F);
- assertEquals(-Float.MIN_VALUE, FastMath.nextAfter(0F, -1F), 0F);
- assertEquals(0F, FastMath.nextAfter(Float.MIN_VALUE, -1F), 0F);
- assertEquals(0F, FastMath.nextAfter(-Float.MIN_VALUE, 1F), 0F);
+ assertEquals(-Float.MAX_VALUE, AccurateMath.nextAfter(Float.NEGATIVE_INFINITY, 0F), 0F);
+ assertEquals(Float.MAX_VALUE, AccurateMath.nextAfter(Float.POSITIVE_INFINITY, 0F), 0F);
+ assertEquals(Float.NaN, AccurateMath.nextAfter(Float.NaN, 0F), 0F);
+ assertEquals(Float.POSITIVE_INFINITY, AccurateMath.nextUp(Float.MAX_VALUE), 0F);
+ assertEquals(Float.NEGATIVE_INFINITY, AccurateMath.nextDown(-Float.MAX_VALUE), 0F);
+ assertEquals(Float.MIN_VALUE, AccurateMath.nextAfter(0F, 1F), 0F);
+ assertEquals(-Float.MIN_VALUE, AccurateMath.nextAfter(0F, -1F), 0F);
+ assertEquals(0F, AccurateMath.nextAfter(Float.MIN_VALUE, -1F), 0F);
+ assertEquals(0F, AccurateMath.nextAfter(-Float.MIN_VALUE, 1F), 0F);
}
@Test
public void testDoubleScalbSpecialCases() {
- assertEquals(2.5269841324701218E-175, FastMath.scalb(2.2250738585072014E-308, 442), 0D);
- assertEquals(1.307993905256674E297, FastMath.scalb(1.1102230246251565E-16, 1040), 0D);
- assertEquals(7.2520887996488946E-217, FastMath.scalb(Double.MIN_VALUE, 356), 0D);
- assertEquals(8.98846567431158E307, FastMath.scalb(Double.MIN_VALUE, 2097), 0D);
- assertEquals(Double.POSITIVE_INFINITY, FastMath.scalb(Double.MIN_VALUE, 2098), 0D);
- assertEquals(1.1125369292536007E-308, FastMath.scalb(2.225073858507201E-308, -1), 0D);
- assertEquals(1.0E-323, FastMath.scalb(Double.MAX_VALUE, -2097), 0D);
- assertEquals(Double.MIN_VALUE, FastMath.scalb(Double.MAX_VALUE, -2098), 0D);
- assertEquals(0, FastMath.scalb(Double.MAX_VALUE, -2099), 0D);
- assertEquals(Double.POSITIVE_INFINITY, FastMath.scalb(Double.POSITIVE_INFINITY, -1000000), 0D);
- assertEquals(Double.NEGATIVE_INFINITY, FastMath.scalb(-1.1102230246251565E-16, 1078), 0D);
- assertEquals(Double.NEGATIVE_INFINITY, FastMath.scalb(-1.1102230246251565E-16, 1079), 0D);
- assertEquals(Double.NEGATIVE_INFINITY, FastMath.scalb(-2.2250738585072014E-308, 2047), 0D);
- assertEquals(Double.NEGATIVE_INFINITY, FastMath.scalb(-2.2250738585072014E-308, 2048), 0D);
- assertEquals(Double.NEGATIVE_INFINITY, FastMath.scalb(-1.7976931348623157E308, 2147483647), 0D);
- assertEquals(Double.POSITIVE_INFINITY, FastMath.scalb( 1.7976931348623157E308, 2147483647), 0D);
- assertEquals(Double.NEGATIVE_INFINITY, FastMath.scalb(-1.1102230246251565E-16, 2147483647), 0D);
- assertEquals(Double.POSITIVE_INFINITY, FastMath.scalb( 1.1102230246251565E-16, 2147483647), 0D);
- assertEquals(Double.NEGATIVE_INFINITY, FastMath.scalb(-2.2250738585072014E-308, 2147483647), 0D);
- assertEquals(Double.POSITIVE_INFINITY, FastMath.scalb( 2.2250738585072014E-308, 2147483647), 0D);
+ assertEquals(2.5269841324701218E-175, AccurateMath.scalb(2.2250738585072014E-308, 442), 0D);
+ assertEquals(1.307993905256674E297, AccurateMath.scalb(1.1102230246251565E-16, 1040), 0D);
+ assertEquals(7.2520887996488946E-217, AccurateMath.scalb(Double.MIN_VALUE, 356), 0D);
+ assertEquals(8.98846567431158E307, AccurateMath.scalb(Double.MIN_VALUE, 2097), 0D);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.scalb(Double.MIN_VALUE, 2098), 0D);
+ assertEquals(1.1125369292536007E-308, AccurateMath.scalb(2.225073858507201E-308, -1), 0D);
+ assertEquals(1.0E-323, AccurateMath.scalb(Double.MAX_VALUE, -2097), 0D);
+ assertEquals(Double.MIN_VALUE, AccurateMath.scalb(Double.MAX_VALUE, -2098), 0D);
+ assertEquals(0, AccurateMath.scalb(Double.MAX_VALUE, -2099), 0D);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.scalb(Double.POSITIVE_INFINITY, -1000000), 0D);
+ assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-1.1102230246251565E-16, 1078), 0D);
+ assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-1.1102230246251565E-16, 1079), 0D);
+ assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-2.2250738585072014E-308, 2047), 0D);
+ assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-2.2250738585072014E-308, 2048), 0D);
+ assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-1.7976931348623157E308, 2147483647), 0D);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.scalb( 1.7976931348623157E308, 2147483647), 0D);
+ assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-1.1102230246251565E-16, 2147483647), 0D);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.scalb( 1.1102230246251565E-16, 2147483647), 0D);
+ assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-2.2250738585072014E-308, 2147483647), 0D);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.scalb( 2.2250738585072014E-308, 2147483647), 0D);
}
@Test
public void testFloatScalbSpecialCases() {
- assertEquals(0f, FastMath.scalb(Float.MIN_VALUE, -30), 0F);
- assertEquals(2 * Float.MIN_VALUE, FastMath.scalb(Float.MIN_VALUE, 1), 0F);
- assertEquals(7.555786e22f, FastMath.scalb(Float.MAX_VALUE, -52), 0F);
- assertEquals(1.7014118e38f, FastMath.scalb(Float.MIN_VALUE, 276), 0F);
- assertEquals(Float.POSITIVE_INFINITY, FastMath.scalb(Float.MIN_VALUE, 277), 0F);
- assertEquals(5.8774718e-39f, FastMath.scalb(1.1754944e-38f, -1), 0F);
- assertEquals(2 * Float.MIN_VALUE, FastMath.scalb(Float.MAX_VALUE, -276), 0F);
- assertEquals(Float.MIN_VALUE, FastMath.scalb(Float.MAX_VALUE, -277), 0F);
- assertEquals(0, FastMath.scalb(Float.MAX_VALUE, -278), 0F);
- assertEquals(Float.POSITIVE_INFINITY, FastMath.scalb(Float.POSITIVE_INFINITY, -1000000), 0F);
- assertEquals(-3.13994498e38f, FastMath.scalb(-1.1e-7f, 151), 0F);
- assertEquals(Float.NEGATIVE_INFINITY, FastMath.scalb(-1.1e-7f, 152), 0F);
- assertEquals(Float.POSITIVE_INFINITY, FastMath.scalb(3.4028235E38f, 2147483647), 0F);
- assertEquals(Float.NEGATIVE_INFINITY, FastMath.scalb(-3.4028235E38f, 2147483647), 0F);
+ assertEquals(0f, AccurateMath.scalb(Float.MIN_VALUE, -30), 0F);
+ assertEquals(2 * Float.MIN_VALUE, AccurateMath.scalb(Float.MIN_VALUE, 1), 0F);
+ assertEquals(7.555786e22f, AccurateMath.scalb(Float.MAX_VALUE, -52), 0F);
+ assertEquals(1.7014118e38f, AccurateMath.scalb(Float.MIN_VALUE, 276), 0F);
+ assertEquals(Float.POSITIVE_INFINITY, AccurateMath.scalb(Float.MIN_VALUE, 277), 0F);
+ assertEquals(5.8774718e-39f, AccurateMath.scalb(1.1754944e-38f, -1), 0F);
+ assertEquals(2 * Float.MIN_VALUE, AccurateMath.scalb(Float.MAX_VALUE, -276), 0F);
+ assertEquals(Float.MIN_VALUE, AccurateMath.scalb(Float.MAX_VALUE, -277), 0F);
+ assertEquals(0, AccurateMath.scalb(Float.MAX_VALUE, -278), 0F);
+ assertEquals(Float.POSITIVE_INFINITY, AccurateMath.scalb(Float.POSITIVE_INFINITY, -1000000), 0F);
+ assertEquals(-3.13994498e38f, AccurateMath.scalb(-1.1e-7f, 151), 0F);
+ assertEquals(Float.NEGATIVE_INFINITY, AccurateMath.scalb(-1.1e-7f, 152), 0F);
+ assertEquals(Float.POSITIVE_INFINITY, AccurateMath.scalb(3.4028235E38f, 2147483647), 0F);
+ assertEquals(Float.NEGATIVE_INFINITY, AccurateMath.scalb(-3.4028235E38f, 2147483647), 0F);
}
private boolean compareClassMethods(Class<?> class1, Class<?> class2){
@@ -1270,68 +1270,68 @@ public class FastMathTest {
}
@Test
- public void checkMissingFastMathClasses() {
- boolean ok = compareClassMethods(StrictMath.class, FastMath.class);
- assertTrue("FastMath should implement all StrictMath methods", ok);
+ public void checkMissingAccurateMathClasses() {
+ boolean ok = compareClassMethods(StrictMath.class, AccurateMath.class);
+ assertTrue("AccurateMath should implement all StrictMath methods", ok);
}
@Ignore
@Test
- public void checkExtraFastMathClasses() {
- compareClassMethods(FastMath.class, StrictMath.class);
+ public void checkExtraAccurateMathClasses() {
+ compareClassMethods(AccurateMath.class, StrictMath.class);
}
@Test
public void testSignumDouble() {
final double delta = 0.0;
- assertEquals(1.0, FastMath.signum(2.0), delta);
- assertEquals(0.0, FastMath.signum(0.0), delta);
- assertEquals(-1.0, FastMath.signum(-2.0), delta);
- TestUtils.assertSame(-0. / 0., FastMath.signum(Double.NaN));
+ assertEquals(1.0, AccurateMath.signum(2.0), delta);
+ assertEquals(0.0, AccurateMath.signum(0.0), delta);
+ assertEquals(-1.0, AccurateMath.signum(-2.0), delta);
+ Assert.assertTrue(Double.isNaN(AccurateMath.signum(Double.NaN)));
}
@Test
public void testSignumFloat() {
final float delta = 0.0F;
- assertEquals(1.0F, FastMath.signum(2.0F), delta);
- assertEquals(0.0F, FastMath.signum(0.0F), delta);
- assertEquals(-1.0F, FastMath.signum(-2.0F), delta);
- TestUtils.assertSame(Float.NaN, FastMath.signum(Float.NaN));
+ assertEquals(1.0F, AccurateMath.signum(2.0F), delta);
+ assertEquals(0.0F, AccurateMath.signum(0.0F), delta);
+ assertEquals(-1.0F, AccurateMath.signum(-2.0F), delta);
+ Assert.assertTrue(Double.isNaN(AccurateMath.signum(Float.NaN)));
}
@Test
public void testLogWithBase() {
- assertEquals(2.0, FastMath.log(2, 4), 0);
- assertEquals(3.0, FastMath.log(2, 8), 0);
- assertTrue(Double.isNaN(FastMath.log(-1, 1)));
- assertTrue(Double.isNaN(FastMath.log(1, -1)));
- assertTrue(Double.isNaN(FastMath.log(0, 0)));
- assertEquals(0, FastMath.log(0, 10), 0);
- assertEquals(Double.NEGATIVE_INFINITY, FastMath.log(10, 0), 0);
+ assertEquals(2.0, AccurateMath.log(2, 4), 0);
+ assertEquals(3.0, AccurateMath.log(2, 8), 0);
+ assertTrue(Double.isNaN(AccurateMath.log(-1, 1)));
+ assertTrue(Double.isNaN(AccurateMath.log(1, -1)));
+ assertTrue(Double.isNaN(AccurateMath.log(0, 0)));
+ assertEquals(0, AccurateMath.log(0, 10), 0);
+ assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.log(10, 0), 0);
}
@Test
public void testIndicatorDouble() {
double delta = 0.0;
- assertEquals(1.0, FastMath.copySign(1d, 2.0), delta);
- assertEquals(1.0, FastMath.copySign(1d, 0.0), delta);
- assertEquals(-1.0, FastMath.copySign(1d, -0.0), delta);
- assertEquals(1.0, FastMath.copySign(1d, Double.POSITIVE_INFINITY), delta);
- assertEquals(-1.0, FastMath.copySign(1d, Double.NEGATIVE_INFINITY), delta);
- assertEquals(1.0, FastMath.copySign(1d, Double.NaN), delta);
- assertEquals(-1.0, FastMath.copySign(1d, -2.0), delta);
+ assertEquals(1.0, AccurateMath.copySign(1d, 2.0), delta);
+ assertEquals(1.0, AccurateMath.copySign(1d, 0.0), delta);
+ assertEquals(-1.0, AccurateMath.copySign(1d, -0.0), delta);
+ assertEquals(1.0, AccurateMath.copySign(1d, Double.POSITIVE_INFINITY), delta);
+ assertEquals(-1.0, AccurateMath.copySign(1d, Double.NEGATIVE_INFINITY), delta);
+ assertEquals(1.0, AccurateMath.copySign(1d, Double.NaN), delta);
+ assertEquals(-1.0, AccurateMath.copySign(1d, -2.0), delta);
}
@Test
public void testIndicatorFloat() {
float delta = 0.0F;
- assertEquals(1.0F, FastMath.copySign(1d, 2.0F), delta);
- assertEquals(1.0F, FastMath.copySign(1d, 0.0F), delta);
- assertEquals(-1.0F, FastMath.copySign(1d, -0.0F), delta);
- assertEquals(1.0F, FastMath.copySign(1d, Float.POSITIVE_INFINITY), delta);
- assertEquals(-1.0F, FastMath.copySign(1d, Float.NEGATIVE_INFINITY), delta);
- assertEquals(1.0F, FastMath.copySign(1d, Float.NaN), delta);
- assertEquals(-1.0F, FastMath.copySign(1d, -2.0F), delta);
+ assertEquals(1.0F, AccurateMath.copySign(1d, 2.0F), delta);
+ assertEquals(1.0F, AccurateMath.copySign(1d, 0.0F), delta);
+ assertEquals(-1.0F, AccurateMath.copySign(1d, -0.0F), delta);
+ assertEquals(1.0F, AccurateMath.copySign(1d, Float.POSITIVE_INFINITY), delta);
+ assertEquals(-1.0F, AccurateMath.copySign(1d, Float.NEGATIVE_INFINITY), delta);
+ assertEquals(1.0F, AccurateMath.copySign(1d, Float.NaN), delta);
+ assertEquals(-1.0F, AccurateMath.copySign(1d, -2.0F), delta);
}
@Test
@@ -1342,20 +1342,20 @@ public class FastMathTest {
Dfp baseDfp = field.newDfp(base);
Dfp dfpPower = field.getOne();
for (int i = 0; i < maxExp; i++) {
- assertEquals("exp=" + i, dfpPower.toDouble(), FastMath.pow(base, i),
- 0.6 * FastMath.ulp(dfpPower.toDouble()));
+ assertEquals("exp=" + i, dfpPower.toDouble(), AccurateMath.pow(base, i),
+ 0.6 * AccurateMath.ulp(dfpPower.toDouble()));
dfpPower = dfpPower.multiply(baseDfp);
}
}
@Test
public void testIntPowHuge() {
- assertTrue(Double.isInfinite(FastMath.pow(FastMath.scalb(1.0, 500), 4)));
+ assertTrue(Double.isInfinite(AccurateMath.pow(AccurateMath.scalb(1.0, 500), 4)));
}
@Test(timeout=5000L) // This test must finish in finite time.
public void testIntPowLongMinValue() {
- assertEquals(1.0, FastMath.pow(1.0, Long.MIN_VALUE), -1.0);
+ assertEquals(1.0, AccurateMath.pow(1.0, Long.MIN_VALUE), -1.0);
}
@Test(timeout=5000L)
@@ -1378,63 +1378,63 @@ public class FastMathTest {
// Special cases from Math.pow javadoc:
// If the second argument is positive or negative zero, then the result is 1.0.
for (double d : DOUBLES) {
- assertEquals(1.0, FastMath.pow(d, 0L), EXACT);
+ assertEquals(1.0, AccurateMath.pow(d, 0L), EXACT);
}
// If the second argument is 1.0, then the result is the same as the first argument.
for (double d : DOUBLES) {
- assertEquals(d, FastMath.pow(d, 1L), EXACT);
+ assertEquals(d, AccurateMath.pow(d, 1L), EXACT);
}
// If the second argument is NaN, then the result is NaN. <- Impossible with int.
// If the first argument is NaN and the second argument is nonzero, then the result is NaN.
for (long i : INTS) {
if (i != 0L) {
- assertEquals(Double.NaN, FastMath.pow(Double.NaN, i), EXACT);
+ assertEquals(Double.NaN, AccurateMath.pow(Double.NaN, i), EXACT);
}
}
// If the absolute value of the first argument is greater than 1 and the second argument is positive infinity, or
// the absolute value of the first argument is less than 1 and the second argument is negative infinity, then the result is positive infinity.
for (double d : DOUBLES) {
if (Math.abs(d) > 1.0) {
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(d, Long.MAX_VALUE - 1L), EXACT);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(d, Long.MAX_VALUE - 1L), EXACT);
}
}
for (double d : DOUBLES) {
if (Math.abs(d) < 1.0) {
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(d, Long.MIN_VALUE), EXACT);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(d, Long.MIN_VALUE), EXACT);
}
}
// Note: Long.MAX_VALUE isn't actually an infinity, so its parity affects the sign of resulting infinity.
for (double d : DOUBLES) {
if (Math.abs(d) > 1.0) {
- assertTrue(Double.isInfinite(FastMath.pow(d, Long.MAX_VALUE)));
+ assertTrue(Double.isInfinite(AccurateMath.pow(d, Long.MAX_VALUE)));
}
}
for (double d : DOUBLES) {
if (Math.abs(d) < 1.0) {
- assertTrue(Double.isInfinite(FastMath.pow(d, Long.MIN_VALUE + 1L)));
+ assertTrue(Double.isInfinite(AccurateMath.pow(d, Long.MIN_VALUE + 1L)));
}
}
// If the absolute value of the first argument is greater than 1 and the second argument is negative infinity, or
// the absolute value of the first argument is less than 1 and the second argument is positive infinity, then the result is positive zero.
for (double d : DOUBLES) {
if (Math.abs(d) > 1.0) {
- assertEquals(0.0, FastMath.pow(d, Long.MIN_VALUE), EXACT);
+ assertEquals(0.0, AccurateMath.pow(d, Long.MIN_VALUE), EXACT);
}
}
for (double d : DOUBLES) {
if (Math.abs(d) < 1.0) {
- assertEquals(0.0, FastMath.pow(d, Long.MAX_VALUE - 1L), EXACT);
+ assertEquals(0.0, AccurateMath.pow(d, Long.MAX_VALUE - 1L), EXACT);
}
}
// Note: Long.MAX_VALUE isn't actually an infinity, so its parity affects the sign of resulting zero.
for (double d : DOUBLES) {
if (Math.abs(d) > 1.0) {
- assertTrue(FastMath.pow(d, Long.MIN_VALUE + 1L) == 0.0);
+ assertTrue(AccurateMath.pow(d, Long.MIN_VALUE + 1L) == 0.0);
}
}
for (double d : DOUBLES) {
if (Math.abs(d) < 1.0) {
- assertTrue(FastMath.pow(d, Long.MAX_VALUE) == 0.0);
+ assertTrue(AccurateMath.pow(d, Long.MAX_VALUE) == 0.0);
}
}
// If the absolute value of the first argument equals 1 and the second argument is infinite, then the result is NaN. <- Impossible with int.
@@ -1442,72 +1442,72 @@ public class FastMathTest {
// the first argument is positive infinity and the second argument is less than zero, then the result is positive zero.
for (long i : INTS) {
if (i > 0L) {
- assertEquals(0.0, FastMath.pow(0.0, i), EXACT);
+ assertEquals(0.0, AccurateMath.pow(0.0, i), EXACT);
}
}
for (long i : INTS) {
if (i < 0L) {
- assertEquals(0.0, FastMath.pow(Double.POSITIVE_INFINITY, i), EXACT);
+ assertEquals(0.0, AccurateMath.pow(Double.POSITIVE_INFINITY, i), EXACT);
}
}
// If the first argument is positive zero and the second argument is less than zero, or
// the first argument is positive infinity and the second argument is greater than zero, then the result is positive infinity.
for (long i : INTS) {
if (i < 0L) {
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(0.0, i), EXACT);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(0.0, i), EXACT);
}
}
for (long i : INTS) {
if (i > 0L) {
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(Double.POSITIVE_INFINITY, i), EXACT);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(Double.POSITIVE_INFINITY, i), EXACT);
}
}
// If the first argument is negative zero and the second argument is greater than zero but not a finite odd integer, or
// the first argument is negative infinity and the second argument is less than zero but not a finite odd integer, then the result is positive zero.
for (long i : INTS) {
if (i > 0L && (i & 1L) == 0L) {
- assertEquals(0.0, FastMath.pow(-0.0, i), EXACT);
+ assertEquals(0.0, AccurateMath.pow(-0.0, i), EXACT);
}
}
for (long i : INTS) {
if (i < 0L && (i & 1L) == 0L) {
- assertEquals(0.0, FastMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
+ assertEquals(0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
}
}
// If the first argument is negative zero and the second argument is a positive finite odd integer, or
// the first argument is negative infinity and the second argument is a negative finite odd integer, then the result is negative zero.
for (long i : INTS) {
if (i > 0L && (i & 1L) == 1L) {
- assertEquals(-0.0, FastMath.pow(-0.0, i), EXACT);
+ assertEquals(-0.0, AccurateMath.pow(-0.0, i), EXACT);
}
}
for (long i : INTS) {
if (i < 0L && (i & 1L) == 1L) {
- assertEquals(-0.0, FastMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
+ assertEquals(-0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
}
}
// If the first argument is negative zero and the second argument is less than zero but not a finite odd integer, or
// the first argument is negative infinity and the second argument is greater than zero but not a finite odd integer, then the result is positive infinity.
for (long i : INTS) {
if (i > 0L && (i & 1L) == 0L) {
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
}
}
for (long i : INTS) {
if (i < 0L && (i & 1L) == 0L) {
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(-0.0, i), EXACT);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(-0.0, i), EXACT);
}
}
// If the first argument is negative zero and the second argument is a negative finite odd integer, or
// the first argument is negative infinity and the second argument is a positive finite odd integer, then the result is negative infinity.
for (long i : INTS) {
if (i > 0L && (i & 1L) == 1L) {
- assertEquals(Double.NEGATIVE_INFINITY, FastMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
+ assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
}
}
for (long i : INTS) {
if (i < 0L && (i & 1L) == 1L) {
- assertEquals(Double.NEGATIVE_INFINITY, FastMath.pow(-0.0, i), EXACT);
+ assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.pow(-0.0, i), EXACT);
}
}
for (double d : DOUBLES) {
@@ -1515,9 +1515,9 @@ public class FastMathTest {
if (d < 0.0 && Math.abs(d) <= Double.MAX_VALUE) {
for (long i : INTS) {
// if the second argument is a finite even integer, the result is equal to the result of raising the absolute value of the first argument to the power of the second argument
- if ((i & 1L) == 0L) assertEquals(FastMath.pow(-d, i), FastMath.pow(d, i), EXACT);
+ if ((i & 1L) == 0L) assertEquals(AccurateMath.pow(-d, i), AccurateMath.pow(d, i), EXACT);
// if the second argument is a finite odd integer, the result is equal to the negative of the result of raising the absolute value of the first argument to the power of the second argument
- else assertEquals(-FastMath.pow(-d, i), FastMath.pow(d, i), EXACT);
+ else assertEquals(-AccurateMath.pow(-d, i), AccurateMath.pow(d, i), EXACT);
// if the second argument is finite and not an integer, then the result is NaN. <- Impossible with int.
}
}
@@ -1541,13 +1541,13 @@ public class FastMathTest {
if (bdSum.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0 ||
bdSum.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) {
try {
- FastMath.incrementExact(a);
+ AccurateMath.incrementExact(a);
Assert.fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
}
} else {
- assertEquals(bdSum, BigInteger.valueOf(FastMath.incrementExact(a)));
+ assertEquals(bdSum, BigInteger.valueOf(AccurateMath.incrementExact(a)));
}
}
}
@@ -1567,13 +1567,13 @@ public class FastMathTest {
if (bdSub.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0 ||
bdSub.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) {
try {
- FastMath.decrementExact(a);
+ AccurateMath.decrementExact(a);
fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
}
} else {
- assertEquals(bdSub, BigInteger.valueOf(FastMath.decrementExact(a)));
+ assertEquals(bdSub, BigInteger.valueOf(AccurateMath.decrementExact(a)));
}
}
}
@@ -1595,13 +1595,13 @@ public class FastMathTest {
if (bdSum.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0 ||
bdSum.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) {
try {
- FastMath.addExact(a, b);
+ AccurateMath.addExact(a, b);
fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
}
} else {
- assertEquals(bdSum, BigInteger.valueOf(FastMath.addExact(a, b)));
+ assertEquals(bdSum, BigInteger.valueOf(AccurateMath.addExact(a, b)));
}
}
}
@@ -1624,13 +1624,13 @@ public class FastMathTest {
if (bdSum.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < 0 ||
bdSum.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) {
try {
- FastMath.addExact(a, b);
+ AccurateMath.addExact(a, b);
fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
}
} else {
- assertEquals(bdSum, BigInteger.valueOf(FastMath.addExact(a, b)));
+ assertEquals(bdSum, BigInteger.valueOf(AccurateMath.addExact(a, b)));
}
}
}
@@ -1653,13 +1653,13 @@ public class FastMathTest {
if (bdSub.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0 ||
bdSub.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) {
try {
- FastMath.subtractExact(a, b);
+ AccurateMath.subtractExact(a, b);
fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
}
} else {
- assertEquals(bdSub, BigInteger.valueOf(FastMath.subtractExact(a, b)));
+ assertEquals(bdSub, BigInteger.valueOf(AccurateMath.subtractExact(a, b)));
}
}
}
@@ -1682,13 +1682,13 @@ public class FastMathTest {
if (bdSub.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < 0 ||
bdSub.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) {
try {
- FastMath.subtractExact(a, b);
+ AccurateMath.subtractExact(a, b);
fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
}
} else {
- assertEquals(bdSub, BigInteger.valueOf(FastMath.subtractExact(a, b)));
+ assertEquals(bdSub, BigInteger.valueOf(AccurateMath.subtractExact(a, b)));
}
}
}
@@ -1711,13 +1711,13 @@ public class FastMathTest {
if (bdMul.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0 ||
bdMul.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) {
try {
- FastMath.multiplyExact(a, b);
+ AccurateMath.multiplyExact(a, b);
fail("an exception should have been thrown " + a + b);
} catch (MathArithmeticException mae) {
// expected
}
} else {
- assertEquals(bdMul, BigInteger.valueOf(FastMath.multiplyExact(a, b)));
+ assertEquals(bdMul, BigInteger.valueOf(AccurateMath.multiplyExact(a, b)));
}
}
}
@@ -1740,13 +1740,13 @@ public class FastMathTest {
if (bdMul.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < 0 ||
bdMul.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) {
try {
- FastMath.multiplyExact(a, b);
+ AccurateMath.multiplyExact(a, b);
fail("an exception should have been thrown " + a + b);
} catch (MathArithmeticException mae) {
// expected
}
} else {
- assertEquals(bdMul, BigInteger.valueOf(FastMath.multiplyExact(a, b)));
+ assertEquals(bdMul, BigInteger.valueOf(AccurateMath.multiplyExact(a, b)));
}
}
}
@@ -1754,31 +1754,31 @@ public class FastMathTest {
@Test(expected=MathArithmeticException.class)
public void testToIntExactTooLow() {
- FastMath.toIntExact(-1l + Integer.MIN_VALUE);
+ AccurateMath.toIntExact(-1l + Integer.MIN_VALUE);
}
@Test(expected=MathArithmeticException.class)
public void testToIntExactTooHigh() {
- FastMath.toIntExact(+1l + Integer.MAX_VALUE);
+ AccurateMath.toIntExact(+1l + Integer.MAX_VALUE);
}
@Test
public void testToIntExact() {
for (int n = -1000; n < 1000; ++n) {
- assertEquals(n, FastMath.toIntExact(0l + n));
+ assertEquals(n, AccurateMath.toIntExact(0l + n));
}
- assertEquals(Integer.MIN_VALUE, FastMath.toIntExact(0l + Integer.MIN_VALUE));
- assertEquals(Integer.MAX_VALUE, FastMath.toIntExact(0l + Integer.MAX_VALUE));
+ assertEquals(Integer.MIN_VALUE, AccurateMath.toIntExact(0l + Integer.MIN_VALUE));
+ assertEquals(Integer.MAX_VALUE, AccurateMath.toIntExact(0l + Integer.MAX_VALUE));
}
@Test
public void testFloorDivInt() {
- assertEquals(+1, FastMath.floorDiv(+4, +3));
- assertEquals(-2, FastMath.floorDiv(-4, +3));
- assertEquals(-2, FastMath.floorDiv(+4, -3));
- assertEquals(+1, FastMath.floorDiv(-4, -3));
+ assertEquals(+1, AccurateMath.floorDiv(+4, +3));
+ assertEquals(-2, AccurateMath.floorDiv(-4, +3));
+ assertEquals(-2, AccurateMath.floorDiv(+4, -3));
+ assertEquals(+1, AccurateMath.floorDiv(-4, -3));
try {
- FastMath.floorDiv(1, 0);
+ AccurateMath.floorDiv(1, 0);
fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
@@ -1786,7 +1786,7 @@ public class FastMathTest {
for (int a = -100; a <= 100; ++a) {
for (int b = -100; b <= 100; ++b) {
if (b != 0) {
- assertEquals(poorManFloorDiv(a, b), FastMath.floorDiv(a, b));
+ assertEquals(poorManFloorDiv(a, b), AccurateMath.floorDiv(a, b));
}
}
}
@@ -1794,12 +1794,12 @@ public class FastMathTest {
@Test
public void testFloorModInt() {
- assertEquals(+1, FastMath.floorMod(+4, +3));
- assertEquals(+2, FastMath.floorMod(-4, +3));
- assertEquals(-2, FastMath.floorMod(+4, -3));
- assertEquals(-1, FastMath.floorMod(-4, -3));
+ assertEquals(+1, AccurateMath.floorMod(+4, +3));
+ assertEquals(+2, AccurateMath.floorMod(-4, +3));
+ assertEquals(-2, AccurateMath.floorMod(+4, -3));
+ assertEquals(-1, AccurateMath.floorMod(-4, -3));
try {
- FastMath.floorMod(1, 0);
+ AccurateMath.floorMod(1, 0);
fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
@@ -1807,7 +1807,7 @@ public class FastMathTest {
for (int a = -100; a <= 100; ++a) {
for (int b = -100; b <= 100; ++b) {
if (b != 0) {
- assertEquals(poorManFloorMod(a, b), FastMath.floorMod(a, b));
+ assertEquals(poorManFloorMod(a, b), AccurateMath.floorMod(a, b));
}
}
}
@@ -1822,16 +1822,16 @@ public class FastMathTest {
int b = generator.nextInt();
if (b == 0) {
try {
- FastMath.floorDiv(a, b);
+ AccurateMath.floorDiv(a, b);
fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
}
} else {
- int d = FastMath.floorDiv(a, b);
- int m = FastMath.floorMod(a, b);
- assertEquals(FastMath.toIntExact(poorManFloorDiv(a, b)), d);
- assertEquals(FastMath.toIntExact(poorManFloorMod(a, b)), m);
+ int d = AccurateMath.floorDiv(a, b);
+ int m = AccurateMath.floorMod(a, b);
+ assertEquals(AccurateMath.toIntExact(poorManFloorDiv(a, b)), d);
+ assertEquals(AccurateMath.toIntExact(poorManFloorMod(a, b)), m);
assertEquals(a, d * b + m);
if (b < 0) {
assertTrue(m <= 0);
@@ -1846,12 +1846,12 @@ public class FastMathTest {
@Test
public void testFloorDivLong() {
- assertEquals(+1l, FastMath.floorDiv(+4l, +3l));
- assertEquals(-2l, FastMath.floorDiv(-4l, +3l));
- assertEquals(-2l, FastMath.floorDiv(+4l, -3l));
- assertEquals(+1l, FastMath.floorDiv(-4l, -3l));
+ assertEquals(+1l, AccurateMath.floorDiv(+4l, +3l));
+ assertEquals(-2l, AccurateMath.floorDiv(-4l, +3l));
+ assertEquals(-2l, AccurateMath.floorDiv(+4l, -3l));
+ assertEquals(+1l, AccurateMath.floorDiv(-4l, -3l));
try {
- FastMath.floorDiv(1l, 0l);
+ AccurateMath.floorDiv(1l, 0l);
fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
@@ -1859,7 +1859,7 @@ public class FastMathTest {
for (long a = -100l; a <= 100l; ++a) {
for (long b = -100l; b <= 100l; ++b) {
if (b != 0) {
- assertEquals(poorManFloorDiv(a, b), FastMath.floorDiv(a, b));
+ assertEquals(poorManFloorDiv(a, b), AccurateMath.floorDiv(a, b));
}
}
}
@@ -1867,12 +1867,12 @@ public class FastMathTest {
@Test
public void testFloorModLong() {
- assertEquals(+1l, FastMath.floorMod(+4l, +3l));
- assertEquals(+2l, FastMath.floorMod(-4l, +3l));
- assertEquals(-2l, FastMath.floorMod(+4l, -3l));
- assertEquals(-1l, FastMath.floorMod(-4l, -3l));
+ assertEquals(+1l, AccurateMath.floorMod(+4l, +3l));
+ assertEquals(+2l, AccurateMath.floorMod(-4l, +3l));
+ assertEquals(-2l, AccurateMath.floorMod(+4l, -3l));
+ assertEquals(-1l, AccurateMath.floorMod(-4l, -3l));
try {
- FastMath.floorMod(1l, 0l);
+ AccurateMath.floorMod(1l, 0l);
fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
@@ -1880,7 +1880,7 @@ public class FastMathTest {
for (long a = -100l; a <= 100l; ++a) {
for (long b = -100l; b <= 100l; ++b) {
if (b != 0) {
- assertEquals(poorManFloorMod(a, b), FastMath.floorMod(a, b));
+ assertEquals(poorManFloorMod(a, b), AccurateMath.floorMod(a, b));
}
}
}
@@ -1895,14 +1895,14 @@ public class FastMathTest {
long b = generator.nextLong();
if (b == 0) {
try {
- FastMath.floorDiv(a, b);
+ AccurateMath.floorDiv(a, b);
fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
}
} else {
- long d = FastMath.floorDiv(a, b);
- long m = FastMath.floorMod(a, b);
+ long d = AccurateMath.floorDiv(a, b);
+ long m = AccurateMath.floorMod(a, b);
assertEquals(poorManFloorDiv(a, b), d);
assertEquals(poorManFloorMod(a, b), m);
assertEquals(a, d * b + m);
@@ -1953,12 +1953,12 @@ public class FastMathTest {
public void testRoundDown() {
double x = 0x1.fffffffffffffp-2; // greatest floating point value less than 0.5
assertTrue(x < 0.5d);
- assertEquals(0, FastMath.round(x));
+ assertEquals(0, AccurateMath.round(x));
x = 4503599627370497.0; // x = Math.pow(2, 52) + 1;
assertEquals("4503599627370497", new BigDecimal(x).toString());
assertTrue(x == Math.rint(x));
- assertTrue(x == FastMath.round(x));
+ assertTrue(x == AccurateMath.round(x));
//assertTrue(x == Math.round(x)); // fails with Java 7, fixed in Java 8
}
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/FastMathTest.java b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathTest.java.bak
similarity index 67%
rename from commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/FastMathTest.java
rename to commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathTest.java.bak
index b376239..52b58f0 100644
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/FastMathTest.java
+++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathTest.java.bak
@@ -41,7 +41,7 @@ import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
-public class FastMathTest {
+public class AccurateMathTest {
private static final double MAX_ERROR_ULP = 0.51;
private static final int NUMBER_OF_TRIALS = 1000;
@@ -72,19 +72,19 @@ public class FastMathTest {
for (double[] pair : pairs) {
assertEquals("min(" + pair[0] + ", " + pair[1] + ")",
Math.min(pair[0], pair[1]),
- FastMath.min(pair[0], pair[1]),
+ AccurateMath.min(pair[0], pair[1]),
Precision.EPSILON);
assertEquals("min(" + pair[1] + ", " + pair[0] + ")",
Math.min(pair[1], pair[0]),
- FastMath.min(pair[1], pair[0]),
+ AccurateMath.min(pair[1], pair[0]),
Precision.EPSILON);
assertEquals("max(" + pair[0] + ", " + pair[1] + ")",
Math.max(pair[0], pair[1]),
- FastMath.max(pair[0], pair[1]),
+ AccurateMath.max(pair[0], pair[1]),
Precision.EPSILON);
assertEquals("max(" + pair[1] + ", " + pair[0] + ")",
Math.max(pair[1], pair[0]),
- FastMath.max(pair[1], pair[0]),
+ AccurateMath.max(pair[1], pair[0]),
Precision.EPSILON);
}
}
@@ -105,62 +105,62 @@ public class FastMathTest {
for (float[] pair : pairs) {
assertEquals("min(" + pair[0] + ", " + pair[1] + ")",
Math.min(pair[0], pair[1]),
- FastMath.min(pair[0], pair[1]),
+ AccurateMath.min(pair[0], pair[1]),
Precision.EPSILON);
assertEquals("min(" + pair[1] + ", " + pair[0] + ")",
Math.min(pair[1], pair[0]),
- FastMath.min(pair[1], pair[0]),
+ AccurateMath.min(pair[1], pair[0]),
Precision.EPSILON);
assertEquals("max(" + pair[0] + ", " + pair[1] + ")",
Math.max(pair[0], pair[1]),
- FastMath.max(pair[0], pair[1]),
+ AccurateMath.max(pair[0], pair[1]),
Precision.EPSILON);
assertEquals("max(" + pair[1] + ", " + pair[0] + ")",
Math.max(pair[1], pair[0]),
- FastMath.max(pair[1], pair[0]),
+ AccurateMath.max(pair[1], pair[0]),
Precision.EPSILON);
}
}
@Test
public void testConstants() {
- assertEquals(Math.PI, FastMath.PI, 1.0e-20);
- assertEquals(Math.E, FastMath.E, 1.0e-20);
+ assertEquals(Math.PI, AccurateMath.PI, 1.0e-20);
+ assertEquals(Math.E, AccurateMath.E, 1.0e-20);
}
@Test
public void testAtan2() {
double y1 = 1.2713504628280707e10;
double x1 = -5.674940885228782e-10;
- assertEquals(Math.atan2(y1, x1), FastMath.atan2(y1, x1), 2 * Precision.EPSILON);
+ assertEquals(Math.atan2(y1, x1), AccurateMath.atan2(y1, x1), 2 * Precision.EPSILON);
double y2 = 0.0;
double x2 = Double.POSITIVE_INFINITY;
- assertEquals(Math.atan2(y2, x2), FastMath.atan2(y2, x2), Precision.SAFE_MIN);
+ assertEquals(Math.atan2(y2, x2), AccurateMath.atan2(y2, x2), Precision.SAFE_MIN);
}
@Test
public void testHyperbolic() {
double maxErr = 0;
for (double x = -30; x < 30; x += 0.001) {
- double tst = FastMath.sinh(x);
+ double tst = AccurateMath.sinh(x);
double ref = Math.sinh(x);
- maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref));
+ maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref));
}
assertEquals(0, maxErr, 2);
maxErr = 0;
for (double x = -30; x < 30; x += 0.001) {
- double tst = FastMath.cosh(x);
+ double tst = AccurateMath.cosh(x);
double ref = Math.cosh(x);
- maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref));
+ maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref));
}
assertEquals(0, maxErr, 2);
maxErr = 0;
for (double x = -0.5; x < 0.5; x += 0.001) {
- double tst = FastMath.tanh(x);
+ double tst = AccurateMath.tanh(x);
double ref = Math.tanh(x);
- maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref));
+ maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref));
}
assertEquals(0, maxErr, 4);
@@ -171,9 +171,9 @@ public class FastMathTest {
final double x = -1;
final double y = (5 + 1e-15) * 1e15;
assertEquals(Math.pow(x, y),
- FastMath.pow(x, y), 0);
+ AccurateMath.pow(x, y), 0);
assertEquals(Math.pow(x, -y),
- FastMath.pow(x, -y), 0);
+ AccurateMath.pow(x, -y), 0);
}
@Test
@@ -184,16 +184,16 @@ public class FastMathTest {
double maxErr = 0;
for (double x = start; x < end; x += 1e-3) {
- final double tst = FastMath.cosh(x);
+ final double tst = AccurateMath.cosh(x);
final double ref = Math.cosh(x);
- maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref));
+ maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref));
}
assertEquals(0, maxErr, 3);
for (double x = start; x < end; x += 1e-3) {
- final double tst = FastMath.sinh(x);
+ final double tst = AccurateMath.sinh(x);
final double ref = Math.sinh(x);
- maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref));
+ maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref));
}
assertEquals(0, maxErr, 3);
}
@@ -206,16 +206,16 @@ public class FastMathTest {
double maxErr = 0;
for (double x = start; x > end; x -= 1e-3) {
- final double tst = FastMath.cosh(x);
+ final double tst = AccurateMath.cosh(x);
final double ref = Math.cosh(x);
- maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref));
+ maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref));
}
assertEquals(0, maxErr, 3);
for (double x = start; x > end; x -= 1e-3) {
- final double tst = FastMath.sinh(x);
+ final double tst = AccurateMath.sinh(x);
final double ref = Math.sinh(x);
- maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref));
+ maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref));
}
assertEquals(0, maxErr, 3);
}
@@ -224,7 +224,7 @@ public class FastMathTest {
public void testMath1269() {
final double arg = 709.8125;
final double vM = Math.exp(arg);
- final double vFM = FastMath.exp(arg);
+ final double vFM = AccurateMath.exp(arg);
assertTrue("exp(" + arg + ") is " + vFM + " instead of " + vM,
Precision.equalsIncludingNaN(vM, vFM));
}
@@ -233,19 +233,19 @@ public class FastMathTest {
public void testHyperbolicInverses() {
double maxErr = 0;
for (double x = -30; x < 30; x += 0.01) {
- maxErr = FastMath.max(maxErr, FastMath.abs(x - FastMath.sinh(FastMath.asinh(x))) / (2 * FastMath.ulp(x)));
+ maxErr = AccurateMath.max(maxErr, AccurateMath.abs(x - AccurateMath.sinh(AccurateMath.asinh(x))) / (2 * AccurateMath.ulp(x)));
}
assertEquals(0, maxErr, 3);
maxErr = 0;
for (double x = 1; x < 30; x += 0.01) {
- maxErr = FastMath.max(maxErr, FastMath.abs(x - FastMath.cosh(FastMath.acosh(x))) / (2 * FastMath.ulp(x)));
+ maxErr = AccurateMath.max(maxErr, AccurateMath.abs(x - AccurateMath.cosh(AccurateMath.acosh(x))) / (2 * AccurateMath.ulp(x)));
}
assertEquals(0, maxErr, 2);
maxErr = 0;
for (double x = -1 + Precision.EPSILON; x < 1 - Precision.EPSILON; x += 0.0001) {
- maxErr = FastMath.max(maxErr, FastMath.abs(x - FastMath.tanh(FastMath.atanh(x))) / (2 * FastMath.ulp(x)));
+ maxErr = AccurateMath.max(maxErr, AccurateMath.abs(x - AccurateMath.tanh(AccurateMath.atanh(x))) / (2 * AccurateMath.ulp(x)));
}
assertEquals(0, maxErr, 2);
}
@@ -257,7 +257,7 @@ public class FastMathTest {
for (int i = 0; i < NUMBER_OF_TRIALS; i++) {
double x = Math.exp(generator.nextDouble() * 1416.0 - 708.0) * generator.nextDouble();
// double x = generator.nextDouble()*2.0;
- double tst = FastMath.log(x);
+ double tst = AccurateMath.log(x);
double ref = DfpMath.log(field.newDfp(x)).toDouble();
double err = (tst - ref) / ref;
@@ -281,7 +281,7 @@ public class FastMathTest {
for (int i = 0; i < NUMBER_OF_TRIALS; i++) {
double x = Math.exp(generator.nextDouble() * 1416.0 - 708.0) * generator.nextDouble();
// double x = generator.nextDouble()*2.0;
- double tst = FastMath.log10(x);
+ double tst = AccurateMath.log10(x);
double ref = DfpMath.log(field.newDfp(x)).divide(DfpMath.log(field.newDfp("10"))).toDouble();
double err = (tst - ref) / ref;
@@ -305,7 +305,7 @@ public class FastMathTest {
for (int i = 0; i < NUMBER_OF_TRIALS; i++) {
double x = Math.exp(generator.nextDouble() * 10.0 - 5.0) * generator.nextDouble();
// double x = generator.nextDouble()*2.0;
- double tst = FastMath.log1p(x);
+ double tst = AccurateMath.log1p(x);
double ref = DfpMath.log(field.newDfp(x).add(field.getOne())).toDouble();
double err = (tst - ref) / ref;
@@ -324,93 +324,93 @@ public class FastMathTest {
@Test
public void testLog1pSpecialCases() {
- assertTrue("Logp of -1.0 should be -Inf", Double.isInfinite(FastMath.log1p(-1.0)));
+ assertTrue("Logp of -1.0 should be -Inf", Double.isInfinite(AccurateMath.log1p(-1.0)));
}
@Test
public void testLogSpecialCases() {
- assertEquals("Log of zero should be -Inf", Double.NEGATIVE_INFINITY, FastMath.log(0.0), 1.0);
- assertEquals("Log of -zero should be -Inf", Double.NEGATIVE_INFINITY, FastMath.log(-0.0), 1.0);
- assertTrue("Log of NaN should be NaN", Double.isNaN(FastMath.log(Double.NaN)));
- assertTrue("Log of negative number should be NaN", Double.isNaN(FastMath.log(-1.0)));
- assertEquals("Log of Double.MIN_VALUE should be -744.4400719213812", -744.4400719213812, FastMath.log(Double.MIN_VALUE), Precision.EPSILON);
- assertEquals("Log of infinity should be infinity", Double.POSITIVE_INFINITY, FastMath.log(Double.POSITIVE_INFINITY), 1.0);
+ assertEquals("Log of zero should be -Inf", Double.NEGATIVE_INFINITY, AccurateMath.log(0.0), 1.0);
+ assertEquals("Log of -zero should be -Inf", Double.NEGATIVE_INFINITY, AccurateMath.log(-0.0), 1.0);
+ assertTrue("Log of NaN should be NaN", Double.isNaN(AccurateMath.log(Double.NaN)));
+ assertTrue("Log of negative number should be NaN", Double.isNaN(AccurateMath.log(-1.0)));
+ assertEquals("Log of Double.MIN_VALUE should be -744.4400719213812", -744.4400719213812, AccurateMath.log(Double.MIN_VALUE), Precision.EPSILON);
+ assertEquals("Log of infinity should be infinity", Double.POSITIVE_INFINITY, AccurateMath.log(Double.POSITIVE_INFINITY), 1.0);
}
@Test
public void testExpSpecialCases() {
// Smallest value that will round up to Double.MIN_VALUE
- assertEquals(Double.MIN_VALUE, FastMath.exp(-745.1332191019411), Precision.EPSILON);
- assertEquals("exp(-745.1332191019412) should be 0.0", 0.0, FastMath.exp(-745.1332191019412), Precision.EPSILON);
- assertTrue("exp of NaN should be NaN", Double.isNaN(FastMath.exp(Double.NaN)));
- assertEquals("exp of infinity should be infinity", Double.POSITIVE_INFINITY, FastMath.exp(Double.POSITIVE_INFINITY), 1.0);
- assertEquals("exp of -infinity should be 0.0", 0.0, FastMath.exp(Double.NEGATIVE_INFINITY), Precision.EPSILON);
- assertEquals("exp(1) should be Math.E", Math.E, FastMath.exp(1.0), Precision.EPSILON);
+ assertEquals(Double.MIN_VALUE, AccurateMath.exp(-745.1332191019411), Precision.EPSILON);
+ assertEquals("exp(-745.1332191019412) should be 0.0", 0.0, AccurateMath.exp(-745.1332191019412), Precision.EPSILON);
+ assertTrue("exp of NaN should be NaN", Double.isNaN(AccurateMath.exp(Double.NaN)));
+ assertEquals("exp of infinity should be infinity", Double.POSITIVE_INFINITY, AccurateMath.exp(Double.POSITIVE_INFINITY), 1.0);
+ assertEquals("exp of -infinity should be 0.0", 0.0, AccurateMath.exp(Double.NEGATIVE_INFINITY), Precision.EPSILON);
+ assertEquals("exp(1) should be Math.E", Math.E, AccurateMath.exp(1.0), Precision.EPSILON);
}
@Test
public void testPowSpecialCases() {
final double EXACT = -1.0;
- assertEquals("pow(-1, 0) should be 1.0", 1.0, FastMath.pow(-1.0, 0.0), Precision.EPSILON);
- assertEquals("pow(-1, -0) should be 1.0", 1.0, FastMath.pow(-1.0, -0.0), Precision.EPSILON);
- assertEquals("pow(PI, 1.0) should be PI", FastMath.PI, FastMath.pow(FastMath.PI, 1.0), Precision.EPSILON);
- assertEquals("pow(-PI, 1.0) should be -PI", -FastMath.PI, FastMath.pow(-FastMath.PI, 1.0), Precision.EPSILON);
- assertTrue("pow(PI, NaN) should be NaN", Double.isNaN(FastMath.pow(Math.PI, Double.NaN)));
- assertTrue("pow(NaN, PI) should be NaN", Double.isNaN(FastMath.pow(Double.NaN, Math.PI)));
- assertEquals("pow(2.0, Infinity) should be Infinity", Double.POSITIVE_INFINITY, FastMath.pow(2.0, Double.POSITIVE_INFINITY), 1.0);
- assertEquals("pow(0.5, -Infinity) should be Infinity", Double.POSITIVE_INFINITY, FastMath.pow(0.5, Double.NEGATIVE_INFINITY), 1.0);
- assertEquals("pow(0.5, Infinity) should be 0.0", 0.0, FastMath.pow(0.5, Double.POSITIVE_INFINITY), Precision.EPSILON);
- assertEquals("pow(2.0, -Infinity) should be 0.0", 0.0, FastMath.pow(2.0, Double.NEGATIVE_INFINITY), Precision.EPSILON);
- assertEquals("pow(0.0, 0.5) should be 0.0", 0.0, FastMath.pow(0.0, 0.5), Precision.EPSILON);
- assertEquals("pow(Infinity, -0.5) should be 0.0", 0.0, FastMath.pow(Double.POSITIVE_INFINITY, -0.5), Precision.EPSILON);
- assertEquals("pow(0.0, -0.5) should be Inf", Double.POSITIVE_INFINITY, FastMath.pow(0.0, -0.5), 1.0);
- assertEquals("pow(Inf, 0.5) should be Inf", Double.POSITIVE_INFINITY, FastMath.pow(Double.POSITIVE_INFINITY, 0.5), 1.0);
- assertEquals("pow(-0.0, -3.0) should be -Inf", Double.NEGATIVE_INFINITY, FastMath.pow(-0.0, -3.0), 1.0);
- assertEquals("pow(-0.0, Infinity) should be 0.0", 0.0, FastMath.pow(-0.0, Double.POSITIVE_INFINITY), Precision.EPSILON);
- assertTrue("pow(-0.0, NaN) should be NaN", Double.isNaN(FastMath.pow(-0.0, Double.NaN)));
- assertEquals("pow(-0.0, -tiny) should be Infinity", Double.POSITIVE_INFINITY, FastMath.pow(-0.0, -Double.MIN_VALUE), 1.0);
- assertEquals("pow(-0.0, -huge) should be Infinity", Double.POSITIVE_INFINITY, FastMath.pow(-0.0, -Double.MAX_VALUE), 1.0);
- assertEquals("pow(-Inf, 3.0) should be -Inf", Double.NEGATIVE_INFINITY, FastMath.pow(Double.NEGATIVE_INFINITY, 3.0), 1.0);
- assertEquals("pow(-Inf, -3.0) should be -0.0", -0.0, FastMath.pow(Double.NEGATIVE_INFINITY, -3.0), EXACT);
- assertEquals("pow(-0.0, -3.5) should be Inf", Double.POSITIVE_INFINITY, FastMath.pow(-0.0, -3.5), 1.0);
- assertEquals("pow(Inf, 3.5) should be Inf", Double.POSITIVE_INFINITY, FastMath.pow(Double.POSITIVE_INFINITY, 3.5), 1.0);
- assertEquals("pow(-2.0, 3.0) should be -8.0", -8.0, FastMath.pow(-2.0, 3.0), Precision.EPSILON);
- assertTrue("pow(-2.0, 3.5) should be NaN", Double.isNaN(FastMath.pow(-2.0, 3.5)));
- assertTrue("pow(NaN, -Infinity) should be NaN", Double.isNaN(FastMath.pow(Double.NaN, Double.NEGATIVE_INFINITY)));
- assertEquals("pow(NaN, 0.0) should be 1.0", 1.0, FastMath.pow(Double.NaN, 0.0), Precision.EPSILON);
- assertEquals("pow(-Infinity, -Infinity) should be 0.0", 0.0, FastMath.pow(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON);
- assertEquals("pow(-huge, -huge) should be 0.0", 0.0, FastMath.pow(-Double.MAX_VALUE, -Double.MAX_VALUE), Precision.EPSILON);
- assertTrue("pow(-huge, huge) should be +Inf", Double.isInfinite(FastMath.pow(-Double.MAX_VALUE, Double.MAX_VALUE)));
- assertTrue("pow(NaN, -Infinity) should be NaN", Double.isNaN(FastMath.pow(Double.NaN, Double.NEGATIVE_INFINITY)));
- assertEquals("pow(NaN, -0.0) should be 1.0", 1.0, FastMath.pow(Double.NaN, -0.0), Precision.EPSILON);
- assertEquals("pow(-Infinity, -Infinity) should be 0.0", 0.0, FastMath.pow(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON);
- assertEquals("pow(-huge, -huge) should be 0.0", 0.0, FastMath.pow(-Double.MAX_VALUE, -Double.MAX_VALUE), Precision.EPSILON);
- assertEquals("pow(-huge, huge) should be +Inf", Double.POSITIVE_INFINITY, FastMath.pow(-Double.MAX_VALUE, Double.MAX_VALUE), 1.0);
+ assertEquals("pow(-1, 0) should be 1.0", 1.0, AccurateMath.pow(-1.0, 0.0), Precision.EPSILON);
+ assertEquals("pow(-1, -0) should be 1.0", 1.0, AccurateMath.pow(-1.0, -0.0), Precision.EPSILON);
+ assertEquals("pow(PI, 1.0) should be PI", AccurateMath.PI, AccurateMath.pow(AccurateMath.PI, 1.0), Precision.EPSILON);
+ assertEquals("pow(-PI, 1.0) should be -PI", -AccurateMath.PI, AccurateMath.pow(-AccurateMath.PI, 1.0), Precision.EPSILON);
+ assertTrue("pow(PI, NaN) should be NaN", Double.isNaN(AccurateMath.pow(Math.PI, Double.NaN)));
+ assertTrue("pow(NaN, PI) should be NaN", Double.isNaN(AccurateMath.pow(Double.NaN, Math.PI)));
+ assertEquals("pow(2.0, Infinity) should be Infinity", Double.POSITIVE_INFINITY, AccurateMath.pow(2.0, Double.POSITIVE_INFINITY), 1.0);
+ assertEquals("pow(0.5, -Infinity) should be Infinity", Double.POSITIVE_INFINITY, AccurateMath.pow(0.5, Double.NEGATIVE_INFINITY), 1.0);
+ assertEquals("pow(0.5, Infinity) should be 0.0", 0.0, AccurateMath.pow(0.5, Double.POSITIVE_INFINITY), Precision.EPSILON);
+ assertEquals("pow(2.0, -Infinity) should be 0.0", 0.0, AccurateMath.pow(2.0, Double.NEGATIVE_INFINITY), Precision.EPSILON);
+ assertEquals("pow(0.0, 0.5) should be 0.0", 0.0, AccurateMath.pow(0.0, 0.5), Precision.EPSILON);
+ assertEquals("pow(Infinity, -0.5) should be 0.0", 0.0, AccurateMath.pow(Double.POSITIVE_INFINITY, -0.5), Precision.EPSILON);
+ assertEquals("pow(0.0, -0.5) should be Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(0.0, -0.5), 1.0);
+ assertEquals("pow(Inf, 0.5) should be Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(Double.POSITIVE_INFINITY, 0.5), 1.0);
+ assertEquals("pow(-0.0, -3.0) should be -Inf", Double.NEGATIVE_INFINITY, AccurateMath.pow(-0.0, -3.0), 1.0);
+ assertEquals("pow(-0.0, Infinity) should be 0.0", 0.0, AccurateMath.pow(-0.0, Double.POSITIVE_INFINITY), Precision.EPSILON);
+ assertTrue("pow(-0.0, NaN) should be NaN", Double.isNaN(AccurateMath.pow(-0.0, Double.NaN)));
+ assertEquals("pow(-0.0, -tiny) should be Infinity", Double.POSITIVE_INFINITY, AccurateMath.pow(-0.0, -Double.MIN_VALUE), 1.0);
+ assertEquals("pow(-0.0, -huge) should be Infinity", Double.POSITIVE_INFINITY, AccurateMath.pow(-0.0, -Double.MAX_VALUE), 1.0);
+ assertEquals("pow(-Inf, 3.0) should be -Inf", Double.NEGATIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, 3.0), 1.0);
+ assertEquals("pow(-Inf, -3.0) should be -0.0", -0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, -3.0), EXACT);
+ assertEquals("pow(-0.0, -3.5) should be Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(-0.0, -3.5), 1.0);
+ assertEquals("pow(Inf, 3.5) should be Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(Double.POSITIVE_INFINITY, 3.5), 1.0);
+ assertEquals("pow(-2.0, 3.0) should be -8.0", -8.0, AccurateMath.pow(-2.0, 3.0), Precision.EPSILON);
+ assertTrue("pow(-2.0, 3.5) should be NaN", Double.isNaN(AccurateMath.pow(-2.0, 3.5)));
+ assertTrue("pow(NaN, -Infinity) should be NaN", Double.isNaN(AccurateMath.pow(Double.NaN, Double.NEGATIVE_INFINITY)));
+ assertEquals("pow(NaN, 0.0) should be 1.0", 1.0, AccurateMath.pow(Double.NaN, 0.0), Precision.EPSILON);
+ assertEquals("pow(-Infinity, -Infinity) should be 0.0", 0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON);
+ assertEquals("pow(-huge, -huge) should be 0.0", 0.0, AccurateMath.pow(-Double.MAX_VALUE, -Double.MAX_VALUE), Precision.EPSILON);
+ assertTrue("pow(-huge, huge) should be +Inf", Double.isInfinite(AccurateMath.pow(-Double.MAX_VALUE, Double.MAX_VALUE)));
+ assertTrue("pow(NaN, -Infinity) should be NaN", Double.isNaN(AccurateMath.pow(Double.NaN, Double.NEGATIVE_INFINITY)));
+ assertEquals("pow(NaN, -0.0) should be 1.0", 1.0, AccurateMath.pow(Double.NaN, -0.0), Precision.EPSILON);
+ assertEquals("pow(-Infinity, -Infinity) should be 0.0", 0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON);
+ assertEquals("pow(-huge, -huge) should be 0.0", 0.0, AccurateMath.pow(-Double.MAX_VALUE, -Double.MAX_VALUE), Precision.EPSILON);
+ assertEquals("pow(-huge, huge) should be +Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(-Double.MAX_VALUE, Double.MAX_VALUE), 1.0);
// Added tests for a 100% coverage
- assertTrue("pow(+Inf, NaN) should be NaN", Double.isNaN(FastMath.pow(Double.POSITIVE_INFINITY, Double.NaN)));
- assertTrue("pow(1.0, +Inf) should be NaN", Double.isNaN(FastMath.pow(1.0, Double.POSITIVE_INFINITY)));
- assertTrue("pow(-Inf, NaN) should be NaN", Double.isNaN(FastMath.pow(Double.NEGATIVE_INFINITY, Double.NaN)));
- assertEquals("pow(-Inf, -1.0) should be -0.0", -0.0, FastMath.pow(Double.NEGATIVE_INFINITY, -1.0), EXACT);
- assertEquals("pow(-Inf, -2.0) should be 0.0", 0.0, FastMath.pow(Double.NEGATIVE_INFINITY, -2.0), EXACT);
- assertEquals("pow(-Inf, 1.0) should be -Inf", Double.NEGATIVE_INFINITY, FastMath.pow(Double.NEGATIVE_INFINITY, 1.0), 1.0);
- assertEquals("pow(-Inf, 2.0) should be +Inf", Double.POSITIVE_INFINITY, FastMath.pow(Double.NEGATIVE_INFINITY, 2.0), 1.0);
- assertTrue("pow(1.0, -Inf) should be NaN", Double.isNaN(FastMath.pow(1.0, Double.NEGATIVE_INFINITY)));
- assertEquals("pow(-0.0, 1.0) should be -0.0", -0.0, FastMath.pow(-0.0, 1.0), EXACT);
- assertEquals("pow(0.0, 1.0) should be 0.0", 0.0, FastMath.pow(0.0, 1.0), EXACT);
- assertEquals("pow(0.0, +Inf) should be 0.0", 0.0, FastMath.pow(0.0, Double.POSITIVE_INFINITY), EXACT);
- assertEquals("pow(-0.0, even) should be 0.0", 0.0, FastMath.pow(-0.0, 6.0), EXACT);
- assertEquals("pow(-0.0, odd) should be -0.0", -0.0, FastMath.pow(-0.0, 13.0), EXACT);
- assertEquals("pow(-0.0, -even) should be +Inf", Double.POSITIVE_INFINITY, FastMath.pow(-0.0, -6.0), EXACT);
- assertEquals("pow(-0.0, -odd) should be -Inf", Double.NEGATIVE_INFINITY, FastMath.pow(-0.0, -13.0), EXACT);
- assertEquals("pow(-2.0, 4.0) should be 16.0", 16.0, FastMath.pow(-2.0, 4.0), EXACT);
- assertEquals("pow(-2.0, 4.5) should be NaN", Double.NaN, FastMath.pow(-2.0, 4.5), EXACT);
- assertEquals("pow(-0.0, -0.0) should be 1.0", 1.0, FastMath.pow(-0.0, -0.0), EXACT);
- assertEquals("pow(-0.0, 0.0) should be 1.0", 1.0, FastMath.pow(-0.0, 0.0), EXACT);
- assertEquals("pow(0.0, -0.0) should be 1.0", 1.0, FastMath.pow(0.0, -0.0), EXACT);
- assertEquals("pow(0.0, 0.0) should be 1.0", 1.0, FastMath.pow(0.0, 0.0), EXACT);
+ assertTrue("pow(+Inf, NaN) should be NaN", Double.isNaN(AccurateMath.pow(Double.POSITIVE_INFINITY, Double.NaN)));
+ assertTrue("pow(1.0, +Inf) should be NaN", Double.isNaN(AccurateMath.pow(1.0, Double.POSITIVE_INFINITY)));
+ assertTrue("pow(-Inf, NaN) should be NaN", Double.isNaN(AccurateMath.pow(Double.NEGATIVE_INFINITY, Double.NaN)));
+ assertEquals("pow(-Inf, -1.0) should be -0.0", -0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, -1.0), EXACT);
+ assertEquals("pow(-Inf, -2.0) should be 0.0", 0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, -2.0), EXACT);
+ assertEquals("pow(-Inf, 1.0) should be -Inf", Double.NEGATIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, 1.0), 1.0);
+ assertEquals("pow(-Inf, 2.0) should be +Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, 2.0), 1.0);
+ assertTrue("pow(1.0, -Inf) should be NaN", Double.isNaN(AccurateMath.pow(1.0, Double.NEGATIVE_INFINITY)));
+ assertEquals("pow(-0.0, 1.0) should be -0.0", -0.0, AccurateMath.pow(-0.0, 1.0), EXACT);
+ assertEquals("pow(0.0, 1.0) should be 0.0", 0.0, AccurateMath.pow(0.0, 1.0), EXACT);
+ assertEquals("pow(0.0, +Inf) should be 0.0", 0.0, AccurateMath.pow(0.0, Double.POSITIVE_INFINITY), EXACT);
+ assertEquals("pow(-0.0, even) should be 0.0", 0.0, AccurateMath.pow(-0.0, 6.0), EXACT);
+ assertEquals("pow(-0.0, odd) should be -0.0", -0.0, AccurateMath.pow(-0.0, 13.0), EXACT);
+ assertEquals("pow(-0.0, -even) should be +Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(-0.0, -6.0), EXACT);
+ assertEquals("pow(-0.0, -odd) should be -Inf", Double.NEGATIVE_INFINITY, AccurateMath.pow(-0.0, -13.0), EXACT);
+ assertEquals("pow(-2.0, 4.0) should be 16.0", 16.0, AccurateMath.pow(-2.0, 4.0), EXACT);
+ assertEquals("pow(-2.0, 4.5) should be NaN", Double.NaN, AccurateMath.pow(-2.0, 4.5), EXACT);
+ assertEquals("pow(-0.0, -0.0) should be 1.0", 1.0, AccurateMath.pow(-0.0, -0.0), EXACT);
+ assertEquals("pow(-0.0, 0.0) should be 1.0", 1.0, AccurateMath.pow(-0.0, 0.0), EXACT);
+ assertEquals("pow(0.0, -0.0) should be 1.0", 1.0, AccurateMath.pow(0.0, -0.0), EXACT);
+ assertEquals("pow(0.0, 0.0) should be 1.0", 1.0, AccurateMath.pow(0.0, 0.0), EXACT);
}
@Test(timeout=20000L)
@@ -432,124 +432,124 @@ public class FastMathTest {
// Special cases from Math.pow javadoc:
// If the second argument is positive or negative zero, then the result is 1.0.
for (double d : DOUBLES) {
- assertEquals(1.0, FastMath.pow(d, 0.0), EXACT);
+ assertEquals(1.0, AccurateMath.pow(d, 0.0), EXACT);
}
for (double d : DOUBLES) {
- assertEquals(1.0, FastMath.pow(d, -0.0), EXACT);
+ assertEquals(1.0, AccurateMath.pow(d, -0.0), EXACT);
}
// If the second argument is 1.0, then the result is the same as the first argument.
for (double d : DOUBLES) {
- assertEquals(d, FastMath.pow(d, 1.0), EXACT);
+ assertEquals(d, AccurateMath.pow(d, 1.0), EXACT);
}
// If the second argument is NaN, then the result is NaN.
for (double d : DOUBLES) {
- assertEquals(Double.NaN, FastMath.pow(d, Double.NaN), EXACT);
+ assertEquals(Double.NaN, AccurateMath.pow(d, Double.NaN), EXACT);
}
// If the first argument is NaN and the second argument is nonzero, then the result is NaN.
for (double i : DOUBLES) {
if (i != 0.0) {
- assertEquals(Double.NaN, FastMath.pow(Double.NaN, i), EXACT);
+ assertEquals(Double.NaN, AccurateMath.pow(Double.NaN, i), EXACT);
}
}
// If the absolute value of the first argument is greater than 1 and the second argument is positive infinity, or
// the absolute value of the first argument is less than 1 and the second argument is negative infinity, then the result is positive infinity.
for (double d : DOUBLES) {
if (Math.abs(d) > 1.0) {
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(d, Double.POSITIVE_INFINITY), EXACT);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(d, Double.POSITIVE_INFINITY), EXACT);
}
}
for (double d : DOUBLES) {
if (Math.abs(d) < 1.0) {
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(d, Double.NEGATIVE_INFINITY), EXACT);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(d, Double.NEGATIVE_INFINITY), EXACT);
}
}
// If the absolute value of the first argument is greater than 1 and the second argument is negative infinity, or
// the absolute value of the first argument is less than 1 and the second argument is positive infinity, then the result is positive zero.
for (double d : DOUBLES) {
if (Math.abs(d) > 1.0) {
- assertEquals(0.0, FastMath.pow(d, Double.NEGATIVE_INFINITY), EXACT);
+ assertEquals(0.0, AccurateMath.pow(d, Double.NEGATIVE_INFINITY), EXACT);
}
}
for (double d : DOUBLES) {
if (Math.abs(d) < 1.0) {
- assertEquals(0.0, FastMath.pow(d, Double.POSITIVE_INFINITY), EXACT);
+ assertEquals(0.0, AccurateMath.pow(d, Double.POSITIVE_INFINITY), EXACT);
}
}
// If the absolute value of the first argument equals 1 and the second argument is infinite, then the result is NaN.
- assertEquals(Double.NaN, FastMath.pow(1.0, Double.POSITIVE_INFINITY), EXACT);
- assertEquals(Double.NaN, FastMath.pow(1.0, Double.NEGATIVE_INFINITY), EXACT);
- assertEquals(Double.NaN, FastMath.pow(-1.0, Double.POSITIVE_INFINITY), EXACT);
- assertEquals(Double.NaN, FastMath.pow(-1.0, Double.NEGATIVE_INFINITY), EXACT);
+ assertEquals(Double.NaN, AccurateMath.pow(1.0, Double.POSITIVE_INFINITY), EXACT);
+ assertEquals(Double.NaN, AccurateMath.pow(1.0, Double.NEGATIVE_INFINITY), EXACT);
+ assertEquals(Double.NaN, AccurateMath.pow(-1.0, Double.POSITIVE_INFINITY), EXACT);
+ assertEquals(Double.NaN, AccurateMath.pow(-1.0, Double.NEGATIVE_INFINITY), EXACT);
// If the first argument is positive zero and the second argument is greater than zero, or
// the first argument is positive infinity and the second argument is less than zero, then the result is positive zero.
for (double i : DOUBLES) {
if (i > 0.0) {
- assertEquals(0.0, FastMath.pow(0.0, i), EXACT);
+ assertEquals(0.0, AccurateMath.pow(0.0, i), EXACT);
}
}
for (double i : DOUBLES) {
if (i < 0.0) {
- assertEquals(0.0, FastMath.pow(Double.POSITIVE_INFINITY, i), EXACT);
+ assertEquals(0.0, AccurateMath.pow(Double.POSITIVE_INFINITY, i), EXACT);
}
}
// If the first argument is positive zero and the second argument is less than zero, or
// the first argument is positive infinity and the second argument is greater than zero, then the result is positive infinity.
for (double i : DOUBLES) {
if (i < 0.0) {
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(0.0, i), EXACT);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(0.0, i), EXACT);
}
}
for (double i : DOUBLES) {
if (i > 0.0) {
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(Double.POSITIVE_INFINITY, i), EXACT);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(Double.POSITIVE_INFINITY, i), EXACT);
}
}
// If the first argument is negative zero and the second argument is greater than zero but not a finite odd integer, or
// the first argument is negative infinity and the second argument is less than zero but not a finite odd integer, then the result is positive zero.
for (double i : DOUBLES) {
if (i > 0.0 && (Double.isInfinite(i) || i % 2.0 == 0.0)) {
- assertEquals(0.0, FastMath.pow(-0.0, i), EXACT);
+ assertEquals(0.0, AccurateMath.pow(-0.0, i), EXACT);
}
}
for (double i : DOUBLES) {
if (i < 0.0 && (Double.isInfinite(i) || i % 2.0 == 0.0)) {
- assertEquals(0.0, FastMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
+ assertEquals(0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
}
}
// If the first argument is negative zero and the second argument is a positive finite odd integer, or
// the first argument is negative infinity and the second argument is a negative finite odd integer, then the result is negative zero.
for (double i : DOUBLES) {
if (i > 0.0 && i % 2.0 == 1.0) {
- assertEquals(-0.0, FastMath.pow(-0.0, i), EXACT);
+ assertEquals(-0.0, AccurateMath.pow(-0.0, i), EXACT);
}
}
for (double i : DOUBLES) {
if (i < 0.0 && i % 2.0 == -1.0) {
- assertEquals(-0.0, FastMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
+ assertEquals(-0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
}
}
// If the first argument is negative zero and the second argument is less than zero but not a finite odd integer, or
// the first argument is negative infinity and the second argument is greater than zero but not a finite odd integer, then the result is positive infinity.
for (double i : DOUBLES) {
if (i > 0.0 && (Double.isInfinite(i) || i % 2.0 == 0.0)) {
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
}
}
for (double i : DOUBLES) {
if (i < 0.0 && (Double.isInfinite(i) || i % 2.0 == 0.0)) {
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(-0.0, i), EXACT);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(-0.0, i), EXACT);
}
}
// If the first argument is negative zero and the second argument is a negative finite odd integer, or
// the first argument is negative infinity and the second argument is a positive finite odd integer, then the result is negative infinity.
for (double i : DOUBLES) {
if (i > 0.0 && i % 2.0 == 1.0) {
- assertEquals(Double.NEGATIVE_INFINITY, FastMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
+ assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
}
}
for (double i : DOUBLES) {
if (i < 0.0 && i % 2.0 == -1.0) {
- assertEquals(Double.NEGATIVE_INFINITY, FastMath.pow(-0.0, i), EXACT);
+ assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.pow(-0.0, i), EXACT);
}
}
for (double d : DOUBLES) {
@@ -558,11 +558,11 @@ public class FastMathTest {
for (double i : DOUBLES) {
if (Math.abs(i) <= Double.MAX_VALUE) {
// if the second argument is a finite even integer, the result is equal to the result of raising the absolute value of the first argument to the power of the second argument
- if (i % 2.0 == 0.0) assertEquals(FastMath.pow(-d, i), FastMath.pow(d, i), EXACT);
+ if (i % 2.0 == 0.0) assertEquals(AccurateMath.pow(-d, i), AccurateMath.pow(d, i), EXACT);
// if the second argument is a finite odd integer, the result is equal to the negative of the result of raising the absolute value of the first argument to the power of the second argument
- else if (Math.abs(i) % 2.0 == 1.0) assertEquals(-FastMath.pow(-d, i), FastMath.pow(d, i), EXACT);
+ else if (Math.abs(i) % 2.0 == 1.0) assertEquals(-AccurateMath.pow(-d, i), AccurateMath.pow(d, i), EXACT);
// if the second argument is finite and not an integer, then the result is NaN.
- else assertEquals(Double.NaN, FastMath.pow(d, i), EXACT);
+ else assertEquals(Double.NaN, AccurateMath.pow(d, i), EXACT);
}
}
}
@@ -594,7 +594,7 @@ public class FastMathTest {
if (dNegative && bi.testBit( 0 )) {
expected = -expected;
}
- assertEquals(d + "^" + i + "=" + expected + ", Math.pow=" + Math.pow(d, i), expected, FastMath.pow(d, i), expected == 0.0 || Double.isInfinite(expected) || Double.isNaN(expected) ? EXACT : 2.0 * Math.ulp(expected));
+ assertEquals(d + "^" + i + "=" + expected + ", Math.pow=" + Math.pow(d, i), expected, AccurateMath.pow(d, i), expected == 0.0 || Double.isInfinite(expected) || Double.isNaN(expected) ? EXACT : 2.0 * Math.ulp(expected));
}
}
}
@@ -603,46 +603,46 @@ public class FastMathTest {
@Test
public void testPowLargeIntegralDouble() {
- double y = FastMath.scalb(1.0, 65);
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(FastMath.nextUp(1.0), y), 1.0);
- assertEquals(1.0, FastMath.pow(1.0, y), 1.0);
- assertEquals(0.0, FastMath.pow(FastMath.nextDown(1.0), y), 1.0);
- assertEquals(0.0, FastMath.pow(FastMath.nextUp(-1.0), y), 1.0);
- assertEquals(1.0, FastMath.pow(-1.0, y), 1.0);
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(FastMath.nextDown(-1.0), y), 1.0);
+ double y = AccurateMath.scalb(1.0, 65);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(AccurateMath.nextUp(1.0), y), 1.0);
+ assertEquals(1.0, AccurateMath.pow(1.0, y), 1.0);
+ assertEquals(0.0, AccurateMath.pow(AccurateMath.nextDown(1.0), y), 1.0);
+ assertEquals(0.0, AccurateMath.pow(AccurateMath.nextUp(-1.0), y), 1.0);
+ assertEquals(1.0, AccurateMath.pow(-1.0, y), 1.0);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(AccurateMath.nextDown(-1.0), y), 1.0);
}
@Test
public void testAtan2SpecialCases() {
- assertTrue("atan2(NaN, 0.0) should be NaN", Double.isNaN(FastMath.atan2(Double.NaN, 0.0)));
- assertTrue("atan2(0.0, NaN) should be NaN", Double.isNaN(FastMath.atan2(0.0, Double.NaN)));
- assertEquals("atan2(0.0, 0.0) should be 0.0", 0.0, FastMath.atan2(0.0, 0.0), Precision.EPSILON);
- assertEquals("atan2(0.0, 0.001) should be 0.0", 0.0, FastMath.atan2(0.0, 0.001), Precision.EPSILON);
- assertEquals("atan2(0.1, +Inf) should be 0.0", 0.0, FastMath.atan2(0.1, Double.POSITIVE_INFINITY), Precision.EPSILON);
- assertEquals("atan2(-0.0, 0.0) should be -0.0", -0.0, FastMath.atan2(-0.0, 0.0), Precision.EPSILON);
- assertEquals("atan2(-0.0, 0.001) should be -0.0", -0.0, FastMath.atan2(-0.0, 0.001), Precision.EPSILON);
- assertEquals("atan2(-0.0, +Inf) should be -0.0", -0.0, FastMath.atan2(-0.1, Double.POSITIVE_INFINITY), Precision.EPSILON);
- assertEquals("atan2(0.0, -0.0) should be PI", FastMath.PI, FastMath.atan2(0.0, -0.0), Precision.EPSILON);
- assertEquals("atan2(0.1, -Inf) should be PI", FastMath.PI, FastMath.atan2(0.1, Double.NEGATIVE_INFINITY), Precision.EPSILON);
- assertEquals("atan2(-0.0, -0.0) should be -PI", -FastMath.PI, FastMath.atan2(-0.0, -0.0), Precision.EPSILON);
- assertEquals("atan2(0.1, -Inf) should be -PI", -FastMath.PI, FastMath.atan2(-0.1, Double.NEGATIVE_INFINITY), Precision.EPSILON);
- assertEquals("atan2(0.1, 0.0) should be PI/2", FastMath.PI / 2.0, FastMath.atan2(0.1, 0.0), Precision.EPSILON);
- assertEquals("atan2(0.1, -0.0) should be PI/2", FastMath.PI / 2.0, FastMath.atan2(0.1, -0.0), Precision.EPSILON);
- assertEquals("atan2(Inf, 0.1) should be PI/2", FastMath.PI / 2.0, FastMath.atan2(Double.POSITIVE_INFINITY, 0.1), Precision.EPSILON);
- assertEquals("atan2(Inf, -0.1) should be PI/2", FastMath.PI / 2.0, FastMath.atan2(Double.POSITIVE_INFINITY, -0.1), Precision.EPSILON);
- assertEquals("atan2(-0.1, 0.0) should be -PI/2", -FastMath.PI / 2.0, FastMath.atan2(-0.1, 0.0), Precision.EPSILON);
- assertEquals("atan2(-0.1, -0.0) should be -PI/2", -FastMath.PI / 2.0, FastMath.atan2(-0.1, -0.0), Precision.EPSILON);
- assertEquals("atan2(-Inf, 0.1) should be -PI/2", -FastMath.PI / 2.0, FastMath.atan2(Double.NEGATIVE_INFINITY, 0.1), Precision.EPSILON);
- assertEquals("atan2(-Inf, -0.1) should be -PI/2", -FastMath.PI / 2.0, FastMath.atan2(Double.NEGATIVE_INFINITY, -0.1), Precision.EPSILON);
- assertEquals("atan2(Inf, Inf) should be PI/4", FastMath.PI / 4.0, FastMath.atan2(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY),
+ assertTrue("atan2(NaN, 0.0) should be NaN", Double.isNaN(AccurateMath.atan2(Double.NaN, 0.0)));
+ assertTrue("atan2(0.0, NaN) should be NaN", Double.isNaN(AccurateMath.atan2(0.0, Double.NaN)));
+ assertEquals("atan2(0.0, 0.0) should be 0.0", 0.0, AccurateMath.atan2(0.0, 0.0), Precision.EPSILON);
+ assertEquals("atan2(0.0, 0.001) should be 0.0", 0.0, AccurateMath.atan2(0.0, 0.001), Precision.EPSILON);
+ assertEquals("atan2(0.1, +Inf) should be 0.0", 0.0, AccurateMath.atan2(0.1, Double.POSITIVE_INFINITY), Precision.EPSILON);
+ assertEquals("atan2(-0.0, 0.0) should be -0.0", -0.0, AccurateMath.atan2(-0.0, 0.0), Precision.EPSILON);
+ assertEquals("atan2(-0.0, 0.001) should be -0.0", -0.0, AccurateMath.atan2(-0.0, 0.001), Precision.EPSILON);
+ assertEquals("atan2(-0.0, +Inf) should be -0.0", -0.0, AccurateMath.atan2(-0.1, Double.POSITIVE_INFINITY), Precision.EPSILON);
+ assertEquals("atan2(0.0, -0.0) should be PI", AccurateMath.PI, AccurateMath.atan2(0.0, -0.0), Precision.EPSILON);
+ assertEquals("atan2(0.1, -Inf) should be PI", AccurateMath.PI, AccurateMath.atan2(0.1, Double.NEGATIVE_INFINITY), Precision.EPSILON);
+ assertEquals("atan2(-0.0, -0.0) should be -PI", -AccurateMath.PI, AccurateMath.atan2(-0.0, -0.0), Precision.EPSILON);
+ assertEquals("atan2(0.1, -Inf) should be -PI", -AccurateMath.PI, AccurateMath.atan2(-0.1, Double.NEGATIVE_INFINITY), Precision.EPSILON);
+ assertEquals("atan2(0.1, 0.0) should be PI/2", AccurateMath.PI / 2.0, AccurateMath.atan2(0.1, 0.0), Precision.EPSILON);
+ assertEquals("atan2(0.1, -0.0) should be PI/2", AccurateMath.PI / 2.0, AccurateMath.atan2(0.1, -0.0), Precision.EPSILON);
+ assertEquals("atan2(Inf, 0.1) should be PI/2", AccurateMath.PI / 2.0, AccurateMath.atan2(Double.POSITIVE_INFINITY, 0.1), Precision.EPSILON);
+ assertEquals("atan2(Inf, -0.1) should be PI/2", AccurateMath.PI / 2.0, AccurateMath.atan2(Double.POSITIVE_INFINITY, -0.1), Precision.EPSILON);
+ assertEquals("atan2(-0.1, 0.0) should be -PI/2", -AccurateMath.PI / 2.0, AccurateMath.atan2(-0.1, 0.0), Precision.EPSILON);
+ assertEquals("atan2(-0.1, -0.0) should be -PI/2", -AccurateMath.PI / 2.0, AccurateMath.atan2(-0.1, -0.0), Precision.EPSILON);
+ assertEquals("atan2(-Inf, 0.1) should be -PI/2", -AccurateMath.PI / 2.0, AccurateMath.atan2(Double.NEGATIVE_INFINITY, 0.1), Precision.EPSILON);
+ assertEquals("atan2(-Inf, -0.1) should be -PI/2", -AccurateMath.PI / 2.0, AccurateMath.atan2(Double.NEGATIVE_INFINITY, -0.1), Precision.EPSILON);
+ assertEquals("atan2(Inf, Inf) should be PI/4", AccurateMath.PI / 4.0, AccurateMath.atan2(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY),
Precision.EPSILON);
- assertEquals("atan2(Inf, -Inf) should be PI * 3/4", FastMath.PI * 3.0 / 4.0,
- FastMath.atan2(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON);
- assertEquals("atan2(-Inf, Inf) should be -PI/4", -FastMath.PI / 4.0, FastMath.atan2(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY),
+ assertEquals("atan2(Inf, -Inf) should be PI * 3/4", AccurateMath.PI * 3.0 / 4.0,
+ AccurateMath.atan2(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON);
+ assertEquals("atan2(-Inf, Inf) should be -PI/4", -AccurateMath.PI / 4.0, AccurateMath.atan2(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY),
Precision.EPSILON);
- assertEquals("atan2(-Inf, -Inf) should be -PI * 3/4", - FastMath.PI * 3.0 / 4.0,
- FastMath.atan2(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON);
+ assertEquals("atan2(-Inf, -Inf) should be -PI * 3/4", - AccurateMath.PI * 3.0 / 4.0,
+ AccurateMath.atan2(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON);
}
@Test
@@ -653,14 +653,14 @@ public class FastMathTest {
double x = (generator.nextDouble() * 2.0 + 0.25);
double y = (generator.nextDouble() * 1200.0 - 600.0) * generator.nextDouble();
/*
- * double x = FastMath.floor(generator.nextDouble()*1024.0 - 512.0); double
- * y; if (x != 0) y = FastMath.floor(512.0 / FastMath.abs(x)); else
- * y = generator.nextDouble()*1200.0; y = y - y/2; x = FastMath.pow(2.0, x) *
+ * double x = AccurateMath.floor(generator.nextDouble()*1024.0 - 512.0); double
+ * y; if (x != 0) y = AccurateMath.floor(512.0 / AccurateMath.abs(x)); else
+ * y = generator.nextDouble()*1200.0; y = y - y/2; x = AccurateMath.pow(2.0, x) *
* generator.nextDouble(); y = y * generator.nextDouble();
*/
// double x = generator.nextDouble()*2.0;
- double tst = FastMath.pow(x, y);
+ double tst = AccurateMath.pow(x, y);
double ref = DfpMath.pow(field.newDfp(x), field.newDfp(y)).toDouble();
double err = (tst - ref) / ref;
@@ -687,7 +687,7 @@ public class FastMathTest {
// double x = (generator.nextDouble() * 20.0) - 10.0;
// double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble();
/* double x = 3.0 / 512.0 * i - 3.0; */
- double tst = FastMath.exp(x);
+ double tst = AccurateMath.exp(x);
double ref = DfpMath.exp(field.newDfp(x)).toDouble();
double err = (tst - ref) / ref;
@@ -716,7 +716,7 @@ public class FastMathTest {
// double x = (generator.nextDouble() * 20.0) - 10.0;
// double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble();
/* double x = 3.0 / 512.0 * i - 3.0; */
- double tst = FastMath.sin(x);
+ double tst = AccurateMath.sin(x);
double ref = DfpMath.sin(field.newDfp(x)).toDouble();
double err = (tst - ref) / ref;
@@ -745,7 +745,7 @@ public class FastMathTest {
// double x = (generator.nextDouble() * 20.0) - 10.0;
// double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble();
/* double x = 3.0 / 512.0 * i - 3.0; */
- double tst = FastMath.cos(x);
+ double tst = AccurateMath.cos(x);
double ref = DfpMath.cos(field.newDfp(x)).toDouble();
double err = (tst - ref) / ref;
@@ -774,7 +774,7 @@ public class FastMathTest {
// double x = (generator.nextDouble() * 20.0) - 10.0;
// double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble();
/* double x = 3.0 / 512.0 * i - 3.0; */
- double tst = FastMath.tan(x);
+ double tst = AccurateMath.tan(x);
double ref = DfpMath.tan(field.newDfp(x)).toDouble();
double err = (tst - ref) / ref;
@@ -805,7 +805,7 @@ public class FastMathTest {
// double x = (generator.nextDouble() * 20.0) - 10.0;
// double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble();
/* double x = 3.0 / 512.0 * i - 3.0; */
- double tst = FastMath.atan(x);
+ double tst = AccurateMath.atan(x);
double ref = DfpMath.atan(field.newDfp(x)).toDouble();
double err = (tst - ref) / ref;
@@ -834,7 +834,7 @@ public class FastMathTest {
// double x = (generator.nextDouble() * 20.0) - 10.0;
// double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble();
/* double x = 3.0 / 512.0 * i - 3.0; */
- double tst = FastMath.atan2(y, x);
+ double tst = AccurateMath.atan2(y, x);
Dfp refdfp = DfpMath.atan(field.newDfp(y).divide(field.newDfp(x)));
/* Make adjustments for sign */
if (x < 0.0) {
@@ -870,7 +870,7 @@ public class FastMathTest {
// double x = (generator.nextDouble() * 20.0) - 10.0;
double x = ((generator.nextDouble() * 16.0) - 8.0) * generator.nextDouble();
/* double x = 3.0 / 512.0 * i - 3.0; */
- double tst = FastMath.expm1(x);
+ double tst = AccurateMath.expm1(x);
double ref = DfpMath.exp(field.newDfp(x)).subtract(field.getOne()).toDouble();
double err = (tst - ref) / ref;
@@ -894,7 +894,7 @@ public class FastMathTest {
for (int i=0; i<10000; i++) {
double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble();
- double tst = FastMath.asin(x);
+ double tst = AccurateMath.asin(x);
double ref = DfpMath.asin(field.newDfp(x)).toDouble();
double err = (tst - ref) / ref;
@@ -917,7 +917,7 @@ public class FastMathTest {
for (int i=0; i<10000; i++) {
double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble();
- double tst = FastMath.acos(x);
+ double tst = AccurateMath.acos(x);
double ref = DfpMath.acos(field.newDfp(x)).toDouble();
double err = (tst - ref) / ref;
@@ -939,12 +939,12 @@ public class FastMathTest {
@Test
public void testAcosSpecialCases() {
- assertTrue("acos(NaN) should be NaN", Double.isNaN(FastMath.acos(Double.NaN)));
- assertTrue("acos(-1.1) should be NaN", Double.isNaN(FastMath.acos(-1.1)));
- assertTrue("acos(-1.1) should be NaN", Double.isNaN(FastMath.acos(1.1)));
- assertEquals("acos(-1.0) should be PI", FastMath.acos(-1.0), FastMath.PI, Precision.EPSILON);
- assertEquals("acos(1.0) should be 0.0", FastMath.acos(1.0), 0.0, Precision.EPSILON);
- assertEquals("acos(0.0) should be PI/2", FastMath.acos(0.0), FastMath.PI / 2.0, Precision.EPSILON);
+ assertTrue("acos(NaN) should be NaN", Double.isNaN(AccurateMath.acos(Double.NaN)));
+ assertTrue("acos(-1.1) should be NaN", Double.isNaN(AccurateMath.acos(-1.1)));
+ assertTrue("acos(-1.1) should be NaN", Double.isNaN(AccurateMath.acos(1.1)));
+ assertEquals("acos(-1.0) should be PI", AccurateMath.acos(-1.0), AccurateMath.PI, Precision.EPSILON);
+ assertEquals("acos(1.0) should be 0.0", AccurateMath.acos(1.0), 0.0, Precision.EPSILON);
+ assertEquals("acos(0.0) should be PI/2", AccurateMath.acos(0.0), AccurateMath.PI / 2.0, Precision.EPSILON);
}
/**
@@ -953,12 +953,12 @@ public class FastMathTest {
@Test
public void testAsinSpecialCases() {
- assertTrue("asin(NaN) should be NaN", Double.isNaN(FastMath.asin(Double.NaN)));
- assertTrue("asin(1.1) should be NaN", Double.isNaN(FastMath.asin(1.1)));
- assertTrue("asin(-1.1) should be NaN", Double.isNaN(FastMath.asin(-1.1)));
- assertEquals("asin(1.0) should be PI/2", FastMath.asin(1.0), FastMath.PI / 2.0, Precision.EPSILON);
- assertEquals("asin(-1.0) should be -PI/2", FastMath.asin(-1.0), -FastMath.PI / 2.0, Precision.EPSILON);
- assertEquals("asin(0.0) should be 0.0", FastMath.asin(0.0), 0.0, Precision.EPSILON);
+ assertTrue("asin(NaN) should be NaN", Double.isNaN(AccurateMath.asin(Double.NaN)));
+ assertTrue("asin(1.1) should be NaN", Double.isNaN(AccurateMath.asin(1.1)));
+ assertTrue("asin(-1.1) should be NaN", Double.isNaN(AccurateMath.asin(-1.1)));
+ assertEquals("asin(1.0) should be PI/2", AccurateMath.asin(1.0), AccurateMath.PI / 2.0, Precision.EPSILON);
+ assertEquals("asin(-1.0) should be -PI/2", AccurateMath.asin(-1.0), -AccurateMath.PI / 2.0, Precision.EPSILON);
+ assertEquals("asin(0.0) should be 0.0", AccurateMath.asin(0.0), 0.0, Precision.EPSILON);
}
private Dfp cosh(Dfp x) {
@@ -980,7 +980,7 @@ public class FastMathTest {
for (int i=0; i<10000; i++) {
double x = ((generator.nextDouble() * 16.0) - 8.0) * generator.nextDouble();
- double tst = FastMath.sinh(x);
+ double tst = AccurateMath.sinh(x);
double ref = sinh(field.newDfp(x)).toDouble();
double err = (tst - ref) / ref;
@@ -1002,7 +1002,7 @@ public class FastMathTest {
for (int i=0; i<10000; i++) {
double x = ((generator.nextDouble() * 16.0) - 8.0) * generator.nextDouble();
- double tst = FastMath.cosh(x);
+ double tst = AccurateMath.cosh(x);
double ref = cosh(field.newDfp(x)).toDouble();
double err = (tst - ref) / ref;
@@ -1024,7 +1024,7 @@ public class FastMathTest {
for (int i=0; i<10000; i++) {
double x = ((generator.nextDouble() * 16.0) - 8.0) * generator.nextDouble();
- double tst = FastMath.tanh(x);
+ double tst = AccurateMath.tanh(x);
double ref = tanh(field.newDfp(x)).toDouble();
double err = (tst - ref) / ref;
@@ -1046,7 +1046,7 @@ public class FastMathTest {
for (int i=0; i<10000; i++) {
double x = ((generator.nextDouble() * 200.0) - 100.0) * generator.nextDouble();
- double tst = FastMath.cbrt(x);
+ double tst = AccurateMath.cbrt(x);
double ref = cbrt(field.newDfp(x)).toDouble();
double err = (tst - ref) / ref;
@@ -1084,7 +1084,7 @@ public class FastMathTest {
for (int i = 0; i < NUMBER_OF_TRIALS; i++) {
double x = generator.nextDouble();
double tst = field.newDfp(x).multiply(180).divide(field.getPi()).toDouble();
- double ref = FastMath.toDegrees(x);
+ double ref = AccurateMath.toDegrees(x);
double err = (tst - ref) / ref;
if (err != 0) {
@@ -1105,7 +1105,7 @@ public class FastMathTest {
for (int i = 0; i < NUMBER_OF_TRIALS; i++) {
double x = generator.nextDouble();
double tst = field.newDfp(x).multiply(field.getPi()).divide(180).toDouble();
- double ref = FastMath.toRadians(x);
+ double ref = AccurateMath.toRadians(x);
double err = (tst - ref) / ref;
if (err != 0) {
@@ -1124,133 +1124,133 @@ public class FastMathTest {
@Test
public void testNextAfter() {
// 0x402fffffffffffff 0x404123456789abcd -> 4030000000000000
- assertEquals(16.0, FastMath.nextUp(15.999999999999998), 0.0);
+ assertEquals(16.0, AccurateMath.nextUp(15.999999999999998), 0.0);
// 0xc02fffffffffffff 0x404123456789abcd -> c02ffffffffffffe
- assertEquals(-15.999999999999996, FastMath.nextAfter(-15.999999999999998, 34.27555555555555), 0.0);
+ assertEquals(-15.999999999999996, AccurateMath.nextAfter(-15.999999999999998, 34.27555555555555), 0.0);
// 0x402fffffffffffff 0x400123456789abcd -> 402ffffffffffffe
- assertEquals(15.999999999999996, FastMath.nextDown(15.999999999999998), 0.0);
+ assertEquals(15.999999999999996, AccurateMath.nextDown(15.999999999999998), 0.0);
// 0xc02fffffffffffff 0x400123456789abcd -> c02ffffffffffffe
- assertEquals(-15.999999999999996, FastMath.nextAfter(-15.999999999999998, 2.142222222222222), 0.0);
+ assertEquals(-15.999999999999996, AccurateMath.nextAfter(-15.999999999999998, 2.142222222222222), 0.0);
// 0x4020000000000000 0x404123456789abcd -> 4020000000000001
- assertEquals(8.000000000000002, FastMath.nextAfter(8.0, 34.27555555555555), 0.0);
+ assertEquals(8.000000000000002, AccurateMath.nextAfter(8.0, 34.27555555555555), 0.0);
// 0xc020000000000000 0x404123456789abcd -> c01fffffffffffff
- assertEquals(-7.999999999999999, FastMath.nextAfter(-8.0, 34.27555555555555), 0.0);
+ assertEquals(-7.999999999999999, AccurateMath.nextAfter(-8.0, 34.27555555555555), 0.0);
// 0x4020000000000000 0x400123456789abcd -> 401fffffffffffff
- assertEquals(7.999999999999999, FastMath.nextAfter(8.0, 2.142222222222222), 0.0);
+ assertEquals(7.999999999999999, AccurateMath.nextAfter(8.0, 2.142222222222222), 0.0);
// 0xc020000000000000 0x400123456789abcd -> c01fffffffffffff
- assertEquals(-7.999999999999999, FastMath.nextAfter(-8.0, 2.142222222222222), 0.0);
+ assertEquals(-7.999999999999999, AccurateMath.nextAfter(-8.0, 2.142222222222222), 0.0);
// 0x3f2e43753d36a223 0x3f2e43753d36a224 -> 3f2e43753d36a224
- assertEquals(2.308922399667661E-4, FastMath.nextAfter(2.3089223996676606E-4, 2.308922399667661E-4), 0.0);
+ assertEquals(2.308922399667661E-4, AccurateMath.nextAfter(2.3089223996676606E-4, 2.308922399667661E-4), 0.0);
// 0x3f2e43753d36a223 0x3f2e43753d36a223 -> 3f2e43753d36a223
- assertEquals(2.3089223996676606E-4, FastMath.nextAfter(2.3089223996676606E-4, 2.3089223996676606E-4), 0.0);
+ assertEquals(2.3089223996676606E-4, AccurateMath.nextAfter(2.3089223996676606E-4, 2.3089223996676606E-4), 0.0);
// 0x3f2e43753d36a223 0x3f2e43753d36a222 -> 3f2e43753d36a222
- assertEquals(2.3089223996676603E-4, FastMath.nextAfter(2.3089223996676606E-4, 2.3089223996676603E-4), 0.0);
+ assertEquals(2.3089223996676603E-4, AccurateMath.nextAfter(2.3089223996676606E-4, 2.3089223996676603E-4), 0.0);
// 0x3f2e43753d36a223 0xbf2e43753d36a224 -> 3f2e43753d36a222
- assertEquals(2.3089223996676603E-4, FastMath.nextAfter(2.3089223996676606E-4, -2.308922399667661E-4), 0.0);
+ assertEquals(2.3089223996676603E-4, AccurateMath.nextAfter(2.3089223996676606E-4, -2.308922399667661E-4), 0.0);
// 0x3f2e43753d36a223 0xbf2e43753d36a223 -> 3f2e43753d36a222
- assertEquals(2.3089223996676603E-4, FastMath.nextAfter(2.3089223996676606E-4, -2.3089223996676606E-4), 0.0);
+ assertEquals(2.3089223996676603E-4, AccurateMath.nextAfter(2.3089223996676606E-4, -2.3089223996676606E-4), 0.0);
// 0x3f2e43753d36a223 0xbf2e43753d36a222 -> 3f2e43753d36a222
- assertEquals(2.3089223996676603E-4, FastMath.nextAfter(2.3089223996676606E-4, -2.3089223996676603E-4), 0.0);
+ assertEquals(2.3089223996676603E-4, AccurateMath.nextAfter(2.3089223996676606E-4, -2.3089223996676603E-4), 0.0);
// 0xbf2e43753d36a223 0x3f2e43753d36a224 -> bf2e43753d36a222
- assertEquals(-2.3089223996676603E-4, FastMath.nextAfter(-2.3089223996676606E-4, 2.308922399667661E-4), 0.0);
+ assertEquals(-2.3089223996676603E-4, AccurateMath.nextAfter(-2.3089223996676606E-4, 2.308922399667661E-4), 0.0);
// 0xbf2e43753d36a223 0x3f2e43753d36a223 -> bf2e43753d36a222
- assertEquals(-2.3089223996676603E-4, FastMath.nextAfter(-2.3089223996676606E-4, 2.3089223996676606E-4), 0.0);
+ assertEquals(-2.3089223996676603E-4, AccurateMath.nextAfter(-2.3089223996676606E-4, 2.3089223996676606E-4), 0.0);
// 0xbf2e43753d36a223 0x3f2e43753d36a222 -> bf2e43753d36a222
- assertEquals(-2.3089223996676603E-4, FastMath.nextAfter(-2.3089223996676606E-4, 2.3089223996676603E-4), 0.0);
+ assertEquals(-2.3089223996676603E-4, AccurateMath.nextAfter(-2.3089223996676606E-4, 2.3089223996676603E-4), 0.0);
// 0xbf2e43753d36a223 0xbf2e43753d36a224 -> bf2e43753d36a224
- assertEquals(-2.308922399667661E-4, FastMath.nextAfter(-2.3089223996676606E-4, -2.308922399667661E-4), 0.0);
+ assertEquals(-2.308922399667661E-4, AccurateMath.nextAfter(-2.3089223996676606E-4, -2.308922399667661E-4), 0.0);
// 0xbf2e43753d36a223 0xbf2e43753d36a223 -> bf2e43753d36a223
- assertEquals(-2.3089223996676606E-4, FastMath.nextAfter(-2.3089223996676606E-4, -2.3089223996676606E-4), 0.0);
+ assertEquals(-2.3089223996676606E-4, AccurateMath.nextAfter(-2.3089223996676606E-4, -2.3089223996676606E-4), 0.0);
// 0xbf2e43753d36a223 0xbf2e43753d36a222 -> bf2e43753d36a222
- assertEquals(-2.3089223996676603E-4, FastMath.nextAfter(-2.3089223996676606E-4, -2.3089223996676603E-4), 0.0);
+ assertEquals(-2.3089223996676603E-4, AccurateMath.nextAfter(-2.3089223996676606E-4, -2.3089223996676603E-4), 0.0);
}
@Test
public void testDoubleNextAfterSpecialCases() {
- assertEquals(-Double.MAX_VALUE,FastMath.nextAfter(Double.NEGATIVE_INFINITY, 0D), 0D);
- assertEquals(Double.MAX_VALUE,FastMath.nextAfter(Double.POSITIVE_INFINITY, 0D), 0D);
- assertEquals(Double.NaN,FastMath.nextAfter(Double.NaN, 0D), 0D);
- assertEquals(Double.POSITIVE_INFINITY,FastMath.nextAfter(Double.MAX_VALUE, Double.POSITIVE_INFINITY), 0D);
- assertEquals(Double.NEGATIVE_INFINITY,FastMath.nextAfter(-Double.MAX_VALUE, Double.NEGATIVE_INFINITY), 0D);
- assertEquals(Double.MIN_VALUE, FastMath.nextAfter(0D, 1D), 0D);
- assertEquals(-Double.MIN_VALUE, FastMath.nextAfter(0D, -1D), 0D);
- assertEquals(0D, FastMath.nextAfter(Double.MIN_VALUE, -1), 0D);
- assertEquals(0D, FastMath.nextAfter(-Double.MIN_VALUE, 1), 0D);
+ assertEquals(-Double.MAX_VALUE,AccurateMath.nextAfter(Double.NEGATIVE_INFINITY, 0D), 0D);
+ assertEquals(Double.MAX_VALUE,AccurateMath.nextAfter(Double.POSITIVE_INFINITY, 0D), 0D);
+ assertEquals(Double.NaN,AccurateMath.nextAfter(Double.NaN, 0D), 0D);
+ assertEquals(Double.POSITIVE_INFINITY,AccurateMath.nextAfter(Double.MAX_VALUE, Double.POSITIVE_INFINITY), 0D);
+ assertEquals(Double.NEGATIVE_INFINITY,AccurateMath.nextAfter(-Double.MAX_VALUE, Double.NEGATIVE_INFINITY), 0D);
+ assertEquals(Double.MIN_VALUE, AccurateMath.nextAfter(0D, 1D), 0D);
+ assertEquals(-Double.MIN_VALUE, AccurateMath.nextAfter(0D, -1D), 0D);
+ assertEquals(0D, AccurateMath.nextAfter(Double.MIN_VALUE, -1), 0D);
+ assertEquals(0D, AccurateMath.nextAfter(-Double.MIN_VALUE, 1), 0D);
}
@Test
public void testFloatNextAfterSpecialCases() {
- assertEquals(-Float.MAX_VALUE, FastMath.nextAfter(Float.NEGATIVE_INFINITY, 0F), 0F);
- assertEquals(Float.MAX_VALUE, FastMath.nextAfter(Float.POSITIVE_INFINITY, 0F), 0F);
- assertEquals(Float.NaN, FastMath.nextAfter(Float.NaN, 0F), 0F);
- assertEquals(Float.POSITIVE_INFINITY, FastMath.nextUp(Float.MAX_VALUE), 0F);
- assertEquals(Float.NEGATIVE_INFINITY, FastMath.nextDown(-Float.MAX_VALUE), 0F);
- assertEquals(Float.MIN_VALUE, FastMath.nextAfter(0F, 1F), 0F);
- assertEquals(-Float.MIN_VALUE, FastMath.nextAfter(0F, -1F), 0F);
- assertEquals(0F, FastMath.nextAfter(Float.MIN_VALUE, -1F), 0F);
- assertEquals(0F, FastMath.nextAfter(-Float.MIN_VALUE, 1F), 0F);
+ assertEquals(-Float.MAX_VALUE, AccurateMath.nextAfter(Float.NEGATIVE_INFINITY, 0F), 0F);
+ assertEquals(Float.MAX_VALUE, AccurateMath.nextAfter(Float.POSITIVE_INFINITY, 0F), 0F);
+ assertEquals(Float.NaN, AccurateMath.nextAfter(Float.NaN, 0F), 0F);
+ assertEquals(Float.POSITIVE_INFINITY, AccurateMath.nextUp(Float.MAX_VALUE), 0F);
+ assertEquals(Float.NEGATIVE_INFINITY, AccurateMath.nextDown(-Float.MAX_VALUE), 0F);
+ assertEquals(Float.MIN_VALUE, AccurateMath.nextAfter(0F, 1F), 0F);
+ assertEquals(-Float.MIN_VALUE, AccurateMath.nextAfter(0F, -1F), 0F);
+ assertEquals(0F, AccurateMath.nextAfter(Float.MIN_VALUE, -1F), 0F);
+ assertEquals(0F, AccurateMath.nextAfter(-Float.MIN_VALUE, 1F), 0F);
}
@Test
public void testDoubleScalbSpecialCases() {
- assertEquals(2.5269841324701218E-175, FastMath.scalb(2.2250738585072014E-308, 442), 0D);
- assertEquals(1.307993905256674E297, FastMath.scalb(1.1102230246251565E-16, 1040), 0D);
- assertEquals(7.2520887996488946E-217, FastMath.scalb(Double.MIN_VALUE, 356), 0D);
- assertEquals(8.98846567431158E307, FastMath.scalb(Double.MIN_VALUE, 2097), 0D);
- assertEquals(Double.POSITIVE_INFINITY, FastMath.scalb(Double.MIN_VALUE, 2098), 0D);
- assertEquals(1.1125369292536007E-308, FastMath.scalb(2.225073858507201E-308, -1), 0D);
- assertEquals(1.0E-323, FastMath.scalb(Double.MAX_VALUE, -2097), 0D);
- assertEquals(Double.MIN_VALUE, FastMath.scalb(Double.MAX_VALUE, -2098), 0D);
- assertEquals(0, FastMath.scalb(Double.MAX_VALUE, -2099), 0D);
- assertEquals(Double.POSITIVE_INFINITY, FastMath.scalb(Double.POSITIVE_INFINITY, -1000000), 0D);
- assertEquals(Double.NEGATIVE_INFINITY, FastMath.scalb(-1.1102230246251565E-16, 1078), 0D);
- assertEquals(Double.NEGATIVE_INFINITY, FastMath.scalb(-1.1102230246251565E-16, 1079), 0D);
- assertEquals(Double.NEGATIVE_INFINITY, FastMath.scalb(-2.2250738585072014E-308, 2047), 0D);
- assertEquals(Double.NEGATIVE_INFINITY, FastMath.scalb(-2.2250738585072014E-308, 2048), 0D);
- assertEquals(Double.NEGATIVE_INFINITY, FastMath.scalb(-1.7976931348623157E308, 2147483647), 0D);
- assertEquals(Double.POSITIVE_INFINITY, FastMath.scalb( 1.7976931348623157E308, 2147483647), 0D);
- assertEquals(Double.NEGATIVE_INFINITY, FastMath.scalb(-1.1102230246251565E-16, 2147483647), 0D);
- assertEquals(Double.POSITIVE_INFINITY, FastMath.scalb( 1.1102230246251565E-16, 2147483647), 0D);
- assertEquals(Double.NEGATIVE_INFINITY, FastMath.scalb(-2.2250738585072014E-308, 2147483647), 0D);
- assertEquals(Double.POSITIVE_INFINITY, FastMath.scalb( 2.2250738585072014E-308, 2147483647), 0D);
+ assertEquals(2.5269841324701218E-175, AccurateMath.scalb(2.2250738585072014E-308, 442), 0D);
+ assertEquals(1.307993905256674E297, AccurateMath.scalb(1.1102230246251565E-16, 1040), 0D);
+ assertEquals(7.2520887996488946E-217, AccurateMath.scalb(Double.MIN_VALUE, 356), 0D);
+ assertEquals(8.98846567431158E307, AccurateMath.scalb(Double.MIN_VALUE, 2097), 0D);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.scalb(Double.MIN_VALUE, 2098), 0D);
+ assertEquals(1.1125369292536007E-308, AccurateMath.scalb(2.225073858507201E-308, -1), 0D);
+ assertEquals(1.0E-323, AccurateMath.scalb(Double.MAX_VALUE, -2097), 0D);
+ assertEquals(Double.MIN_VALUE, AccurateMath.scalb(Double.MAX_VALUE, -2098), 0D);
+ assertEquals(0, AccurateMath.scalb(Double.MAX_VALUE, -2099), 0D);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.scalb(Double.POSITIVE_INFINITY, -1000000), 0D);
+ assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-1.1102230246251565E-16, 1078), 0D);
+ assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-1.1102230246251565E-16, 1079), 0D);
+ assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-2.2250738585072014E-308, 2047), 0D);
+ assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-2.2250738585072014E-308, 2048), 0D);
+ assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-1.7976931348623157E308, 2147483647), 0D);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.scalb( 1.7976931348623157E308, 2147483647), 0D);
+ assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-1.1102230246251565E-16, 2147483647), 0D);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.scalb( 1.1102230246251565E-16, 2147483647), 0D);
+ assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-2.2250738585072014E-308, 2147483647), 0D);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.scalb( 2.2250738585072014E-308, 2147483647), 0D);
}
@Test
public void testFloatScalbSpecialCases() {
- assertEquals(0f, FastMath.scalb(Float.MIN_VALUE, -30), 0F);
- assertEquals(2 * Float.MIN_VALUE, FastMath.scalb(Float.MIN_VALUE, 1), 0F);
- assertEquals(7.555786e22f, FastMath.scalb(Float.MAX_VALUE, -52), 0F);
- assertEquals(1.7014118e38f, FastMath.scalb(Float.MIN_VALUE, 276), 0F);
- assertEquals(Float.POSITIVE_INFINITY, FastMath.scalb(Float.MIN_VALUE, 277), 0F);
- assertEquals(5.8774718e-39f, FastMath.scalb(1.1754944e-38f, -1), 0F);
- assertEquals(2 * Float.MIN_VALUE, FastMath.scalb(Float.MAX_VALUE, -276), 0F);
- assertEquals(Float.MIN_VALUE, FastMath.scalb(Float.MAX_VALUE, -277), 0F);
- assertEquals(0, FastMath.scalb(Float.MAX_VALUE, -278), 0F);
- assertEquals(Float.POSITIVE_INFINITY, FastMath.scalb(Float.POSITIVE_INFINITY, -1000000), 0F);
- assertEquals(-3.13994498e38f, FastMath.scalb(-1.1e-7f, 151), 0F);
- assertEquals(Float.NEGATIVE_INFINITY, FastMath.scalb(-1.1e-7f, 152), 0F);
- assertEquals(Float.POSITIVE_INFINITY, FastMath.scalb(3.4028235E38f, 2147483647), 0F);
- assertEquals(Float.NEGATIVE_INFINITY, FastMath.scalb(-3.4028235E38f, 2147483647), 0F);
+ assertEquals(0f, AccurateMath.scalb(Float.MIN_VALUE, -30), 0F);
+ assertEquals(2 * Float.MIN_VALUE, AccurateMath.scalb(Float.MIN_VALUE, 1), 0F);
+ assertEquals(7.555786e22f, AccurateMath.scalb(Float.MAX_VALUE, -52), 0F);
+ assertEquals(1.7014118e38f, AccurateMath.scalb(Float.MIN_VALUE, 276), 0F);
+ assertEquals(Float.POSITIVE_INFINITY, AccurateMath.scalb(Float.MIN_VALUE, 277), 0F);
+ assertEquals(5.8774718e-39f, AccurateMath.scalb(1.1754944e-38f, -1), 0F);
+ assertEquals(2 * Float.MIN_VALUE, AccurateMath.scalb(Float.MAX_VALUE, -276), 0F);
+ assertEquals(Float.MIN_VALUE, AccurateMath.scalb(Float.MAX_VALUE, -277), 0F);
+ assertEquals(0, AccurateMath.scalb(Float.MAX_VALUE, -278), 0F);
+ assertEquals(Float.POSITIVE_INFINITY, AccurateMath.scalb(Float.POSITIVE_INFINITY, -1000000), 0F);
+ assertEquals(-3.13994498e38f, AccurateMath.scalb(-1.1e-7f, 151), 0F);
+ assertEquals(Float.NEGATIVE_INFINITY, AccurateMath.scalb(-1.1e-7f, 152), 0F);
+ assertEquals(Float.POSITIVE_INFINITY, AccurateMath.scalb(3.4028235E38f, 2147483647), 0F);
+ assertEquals(Float.NEGATIVE_INFINITY, AccurateMath.scalb(-3.4028235E38f, 2147483647), 0F);
}
private boolean compareClassMethods(Class<?> class1, Class<?> class2){
@@ -1270,68 +1270,68 @@ public class FastMathTest {
}
@Test
- public void checkMissingFastMathClasses() {
- boolean ok = compareClassMethods(StrictMath.class, FastMath.class);
- assertTrue("FastMath should implement all StrictMath methods", ok);
+ public void checkMissingAccurateMathClasses() {
+ boolean ok = compareClassMethods(StrictMath.class, AccurateMath.class);
+ assertTrue("AccurateMath should implement all StrictMath methods", ok);
}
@Ignore
@Test
- public void checkExtraFastMathClasses() {
- compareClassMethods(FastMath.class, StrictMath.class);
+ public void checkExtraAccurateMathClasses() {
+ compareClassMethods(AccurateMath.class, StrictMath.class);
}
@Test
public void testSignumDouble() {
final double delta = 0.0;
- assertEquals(1.0, FastMath.signum(2.0), delta);
- assertEquals(0.0, FastMath.signum(0.0), delta);
- assertEquals(-1.0, FastMath.signum(-2.0), delta);
- TestUtils.assertSame(-0. / 0., FastMath.signum(Double.NaN));
+ assertEquals(1.0, AccurateMath.signum(2.0), delta);
+ assertEquals(0.0, AccurateMath.signum(0.0), delta);
+ assertEquals(-1.0, AccurateMath.signum(-2.0), delta);
+ TestUtils.assertSame(-0. / 0., AccurateMath.signum(Double.NaN));
}
@Test
public void testSignumFloat() {
final float delta = 0.0F;
- assertEquals(1.0F, FastMath.signum(2.0F), delta);
- assertEquals(0.0F, FastMath.signum(0.0F), delta);
- assertEquals(-1.0F, FastMath.signum(-2.0F), delta);
- TestUtils.assertSame(Float.NaN, FastMath.signum(Float.NaN));
+ assertEquals(1.0F, AccurateMath.signum(2.0F), delta);
+ assertEquals(0.0F, AccurateMath.signum(0.0F), delta);
+ assertEquals(-1.0F, AccurateMath.signum(-2.0F), delta);
+ TestUtils.assertSame(Float.NaN, AccurateMath.signum(Float.NaN));
}
@Test
public void testLogWithBase() {
- assertEquals(2.0, FastMath.log(2, 4), 0);
- assertEquals(3.0, FastMath.log(2, 8), 0);
- assertTrue(Double.isNaN(FastMath.log(-1, 1)));
- assertTrue(Double.isNaN(FastMath.log(1, -1)));
- assertTrue(Double.isNaN(FastMath.log(0, 0)));
- assertEquals(0, FastMath.log(0, 10), 0);
- assertEquals(Double.NEGATIVE_INFINITY, FastMath.log(10, 0), 0);
+ assertEquals(2.0, AccurateMath.log(2, 4), 0);
+ assertEquals(3.0, AccurateMath.log(2, 8), 0);
+ assertTrue(Double.isNaN(AccurateMath.log(-1, 1)));
+ assertTrue(Double.isNaN(AccurateMath.log(1, -1)));
+ assertTrue(Double.isNaN(AccurateMath.log(0, 0)));
+ assertEquals(0, AccurateMath.log(0, 10), 0);
+ assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.log(10, 0), 0);
}
@Test
public void testIndicatorDouble() {
double delta = 0.0;
- assertEquals(1.0, FastMath.copySign(1d, 2.0), delta);
- assertEquals(1.0, FastMath.copySign(1d, 0.0), delta);
- assertEquals(-1.0, FastMath.copySign(1d, -0.0), delta);
- assertEquals(1.0, FastMath.copySign(1d, Double.POSITIVE_INFINITY), delta);
- assertEquals(-1.0, FastMath.copySign(1d, Double.NEGATIVE_INFINITY), delta);
- assertEquals(1.0, FastMath.copySign(1d, Double.NaN), delta);
- assertEquals(-1.0, FastMath.copySign(1d, -2.0), delta);
+ assertEquals(1.0, AccurateMath.copySign(1d, 2.0), delta);
+ assertEquals(1.0, AccurateMath.copySign(1d, 0.0), delta);
+ assertEquals(-1.0, AccurateMath.copySign(1d, -0.0), delta);
+ assertEquals(1.0, AccurateMath.copySign(1d, Double.POSITIVE_INFINITY), delta);
+ assertEquals(-1.0, AccurateMath.copySign(1d, Double.NEGATIVE_INFINITY), delta);
+ assertEquals(1.0, AccurateMath.copySign(1d, Double.NaN), delta);
+ assertEquals(-1.0, AccurateMath.copySign(1d, -2.0), delta);
}
@Test
public void testIndicatorFloat() {
float delta = 0.0F;
- assertEquals(1.0F, FastMath.copySign(1d, 2.0F), delta);
- assertEquals(1.0F, FastMath.copySign(1d, 0.0F), delta);
- assertEquals(-1.0F, FastMath.copySign(1d, -0.0F), delta);
- assertEquals(1.0F, FastMath.copySign(1d, Float.POSITIVE_INFINITY), delta);
- assertEquals(-1.0F, FastMath.copySign(1d, Float.NEGATIVE_INFINITY), delta);
- assertEquals(1.0F, FastMath.copySign(1d, Float.NaN), delta);
- assertEquals(-1.0F, FastMath.copySign(1d, -2.0F), delta);
+ assertEquals(1.0F, AccurateMath.copySign(1d, 2.0F), delta);
+ assertEquals(1.0F, AccurateMath.copySign(1d, 0.0F), delta);
+ assertEquals(-1.0F, AccurateMath.copySign(1d, -0.0F), delta);
+ assertEquals(1.0F, AccurateMath.copySign(1d, Float.POSITIVE_INFINITY), delta);
+ assertEquals(-1.0F, AccurateMath.copySign(1d, Float.NEGATIVE_INFINITY), delta);
+ assertEquals(1.0F, AccurateMath.copySign(1d, Float.NaN), delta);
+ assertEquals(-1.0F, AccurateMath.copySign(1d, -2.0F), delta);
}
@Test
@@ -1342,20 +1342,20 @@ public class FastMathTest {
Dfp baseDfp = field.newDfp(base);
Dfp dfpPower = field.getOne();
for (int i = 0; i < maxExp; i++) {
- assertEquals("exp=" + i, dfpPower.toDouble(), FastMath.pow(base, i),
- 0.6 * FastMath.ulp(dfpPower.toDouble()));
+ assertEquals("exp=" + i, dfpPower.toDouble(), AccurateMath.pow(base, i),
+ 0.6 * AccurateMath.ulp(dfpPower.toDouble()));
dfpPower = dfpPower.multiply(baseDfp);
}
}
@Test
public void testIntPowHuge() {
- assertTrue(Double.isInfinite(FastMath.pow(FastMath.scalb(1.0, 500), 4)));
+ assertTrue(Double.isInfinite(AccurateMath.pow(AccurateMath.scalb(1.0, 500), 4)));
}
@Test(timeout=5000L) // This test must finish in finite time.
public void testIntPowLongMinValue() {
- assertEquals(1.0, FastMath.pow(1.0, Long.MIN_VALUE), -1.0);
+ assertEquals(1.0, AccurateMath.pow(1.0, Long.MIN_VALUE), -1.0);
}
@Test(timeout=5000L)
@@ -1378,63 +1378,63 @@ public class FastMathTest {
// Special cases from Math.pow javadoc:
// If the second argument is positive or negative zero, then the result is 1.0.
for (double d : DOUBLES) {
- assertEquals(1.0, FastMath.pow(d, 0L), EXACT);
+ assertEquals(1.0, AccurateMath.pow(d, 0L), EXACT);
}
// If the second argument is 1.0, then the result is the same as the first argument.
for (double d : DOUBLES) {
- assertEquals(d, FastMath.pow(d, 1L), EXACT);
+ assertEquals(d, AccurateMath.pow(d, 1L), EXACT);
}
// If the second argument is NaN, then the result is NaN. <- Impossible with int.
// If the first argument is NaN and the second argument is nonzero, then the result is NaN.
for (long i : INTS) {
if (i != 0L) {
- assertEquals(Double.NaN, FastMath.pow(Double.NaN, i), EXACT);
+ assertEquals(Double.NaN, AccurateMath.pow(Double.NaN, i), EXACT);
}
}
// If the absolute value of the first argument is greater than 1 and the second argument is positive infinity, or
// the absolute value of the first argument is less than 1 and the second argument is negative infinity, then the result is positive infinity.
for (double d : DOUBLES) {
if (Math.abs(d) > 1.0) {
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(d, Long.MAX_VALUE - 1L), EXACT);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(d, Long.MAX_VALUE - 1L), EXACT);
}
}
for (double d : DOUBLES) {
if (Math.abs(d) < 1.0) {
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(d, Long.MIN_VALUE), EXACT);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(d, Long.MIN_VALUE), EXACT);
}
}
// Note: Long.MAX_VALUE isn't actually an infinity, so its parity affects the sign of resulting infinity.
for (double d : DOUBLES) {
if (Math.abs(d) > 1.0) {
- assertTrue(Double.isInfinite(FastMath.pow(d, Long.MAX_VALUE)));
+ assertTrue(Double.isInfinite(AccurateMath.pow(d, Long.MAX_VALUE)));
}
}
for (double d : DOUBLES) {
if (Math.abs(d) < 1.0) {
- assertTrue(Double.isInfinite(FastMath.pow(d, Long.MIN_VALUE + 1L)));
+ assertTrue(Double.isInfinite(AccurateMath.pow(d, Long.MIN_VALUE + 1L)));
}
}
// If the absolute value of the first argument is greater than 1 and the second argument is negative infinity, or
// the absolute value of the first argument is less than 1 and the second argument is positive infinity, then the result is positive zero.
for (double d : DOUBLES) {
if (Math.abs(d) > 1.0) {
- assertEquals(0.0, FastMath.pow(d, Long.MIN_VALUE), EXACT);
+ assertEquals(0.0, AccurateMath.pow(d, Long.MIN_VALUE), EXACT);
}
}
for (double d : DOUBLES) {
if (Math.abs(d) < 1.0) {
- assertEquals(0.0, FastMath.pow(d, Long.MAX_VALUE - 1L), EXACT);
+ assertEquals(0.0, AccurateMath.pow(d, Long.MAX_VALUE - 1L), EXACT);
}
}
// Note: Long.MAX_VALUE isn't actually an infinity, so its parity affects the sign of resulting zero.
for (double d : DOUBLES) {
if (Math.abs(d) > 1.0) {
- assertTrue(FastMath.pow(d, Long.MIN_VALUE + 1L) == 0.0);
+ assertTrue(AccurateMath.pow(d, Long.MIN_VALUE + 1L) == 0.0);
}
}
for (double d : DOUBLES) {
if (Math.abs(d) < 1.0) {
- assertTrue(FastMath.pow(d, Long.MAX_VALUE) == 0.0);
+ assertTrue(AccurateMath.pow(d, Long.MAX_VALUE) == 0.0);
}
}
// If the absolute value of the first argument equals 1 and the second argument is infinite, then the result is NaN. <- Impossible with int.
@@ -1442,72 +1442,72 @@ public class FastMathTest {
// the first argument is positive infinity and the second argument is less than zero, then the result is positive zero.
for (long i : INTS) {
if (i > 0L) {
- assertEquals(0.0, FastMath.pow(0.0, i), EXACT);
+ assertEquals(0.0, AccurateMath.pow(0.0, i), EXACT);
}
}
for (long i : INTS) {
if (i < 0L) {
- assertEquals(0.0, FastMath.pow(Double.POSITIVE_INFINITY, i), EXACT);
+ assertEquals(0.0, AccurateMath.pow(Double.POSITIVE_INFINITY, i), EXACT);
}
}
// If the first argument is positive zero and the second argument is less than zero, or
// the first argument is positive infinity and the second argument is greater than zero, then the result is positive infinity.
for (long i : INTS) {
if (i < 0L) {
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(0.0, i), EXACT);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(0.0, i), EXACT);
}
}
for (long i : INTS) {
if (i > 0L) {
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(Double.POSITIVE_INFINITY, i), EXACT);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(Double.POSITIVE_INFINITY, i), EXACT);
}
}
// If the first argument is negative zero and the second argument is greater than zero but not a finite odd integer, or
// the first argument is negative infinity and the second argument is less than zero but not a finite odd integer, then the result is positive zero.
for (long i : INTS) {
if (i > 0L && (i & 1L) == 0L) {
- assertEquals(0.0, FastMath.pow(-0.0, i), EXACT);
+ assertEquals(0.0, AccurateMath.pow(-0.0, i), EXACT);
}
}
for (long i : INTS) {
if (i < 0L && (i & 1L) == 0L) {
- assertEquals(0.0, FastMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
+ assertEquals(0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
}
}
// If the first argument is negative zero and the second argument is a positive finite odd integer, or
// the first argument is negative infinity and the second argument is a negative finite odd integer, then the result is negative zero.
for (long i : INTS) {
if (i > 0L && (i & 1L) == 1L) {
- assertEquals(-0.0, FastMath.pow(-0.0, i), EXACT);
+ assertEquals(-0.0, AccurateMath.pow(-0.0, i), EXACT);
}
}
for (long i : INTS) {
if (i < 0L && (i & 1L) == 1L) {
- assertEquals(-0.0, FastMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
+ assertEquals(-0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
}
}
// If the first argument is negative zero and the second argument is less than zero but not a finite odd integer, or
// the first argument is negative infinity and the second argument is greater than zero but not a finite odd integer, then the result is positive infinity.
for (long i : INTS) {
if (i > 0L && (i & 1L) == 0L) {
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
}
}
for (long i : INTS) {
if (i < 0L && (i & 1L) == 0L) {
- assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(-0.0, i), EXACT);
+ assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(-0.0, i), EXACT);
}
}
// If the first argument is negative zero and the second argument is a negative finite odd integer, or
// the first argument is negative infinity and the second argument is a positive finite odd integer, then the result is negative infinity.
for (long i : INTS) {
if (i > 0L && (i & 1L) == 1L) {
- assertEquals(Double.NEGATIVE_INFINITY, FastMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
+ assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT);
}
}
for (long i : INTS) {
if (i < 0L && (i & 1L) == 1L) {
- assertEquals(Double.NEGATIVE_INFINITY, FastMath.pow(-0.0, i), EXACT);
+ assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.pow(-0.0, i), EXACT);
}
}
for (double d : DOUBLES) {
@@ -1515,9 +1515,9 @@ public class FastMathTest {
if (d < 0.0 && Math.abs(d) <= Double.MAX_VALUE) {
for (long i : INTS) {
// if the second argument is a finite even integer, the result is equal to the result of raising the absolute value of the first argument to the power of the second argument
- if ((i & 1L) == 0L) assertEquals(FastMath.pow(-d, i), FastMath.pow(d, i), EXACT);
+ if ((i & 1L) == 0L) assertEquals(AccurateMath.pow(-d, i), AccurateMath.pow(d, i), EXACT);
// if the second argument is a finite odd integer, the result is equal to the negative of the result of raising the absolute value of the first argument to the power of the second argument
- else assertEquals(-FastMath.pow(-d, i), FastMath.pow(d, i), EXACT);
+ else assertEquals(-AccurateMath.pow(-d, i), AccurateMath.pow(d, i), EXACT);
// if the second argument is finite and not an integer, then the result is NaN. <- Impossible with int.
}
}
@@ -1541,13 +1541,13 @@ public class FastMathTest {
if (bdSum.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0 ||
bdSum.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) {
try {
- FastMath.incrementExact(a);
+ AccurateMath.incrementExact(a);
Assert.fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
}
} else {
- assertEquals(bdSum, BigInteger.valueOf(FastMath.incrementExact(a)));
+ assertEquals(bdSum, BigInteger.valueOf(AccurateMath.incrementExact(a)));
}
}
}
@@ -1567,13 +1567,13 @@ public class FastMathTest {
if (bdSub.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0 ||
bdSub.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) {
try {
- FastMath.decrementExact(a);
+ AccurateMath.decrementExact(a);
fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
}
} else {
- assertEquals(bdSub, BigInteger.valueOf(FastMath.decrementExact(a)));
+ assertEquals(bdSub, BigInteger.valueOf(AccurateMath.decrementExact(a)));
}
}
}
@@ -1595,13 +1595,13 @@ public class FastMathTest {
if (bdSum.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0 ||
bdSum.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) {
try {
- FastMath.addExact(a, b);
+ AccurateMath.addExact(a, b);
fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
}
} else {
- assertEquals(bdSum, BigInteger.valueOf(FastMath.addExact(a, b)));
+ assertEquals(bdSum, BigInteger.valueOf(AccurateMath.addExact(a, b)));
}
}
}
@@ -1624,13 +1624,13 @@ public class FastMathTest {
if (bdSum.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < 0 ||
bdSum.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) {
try {
- FastMath.addExact(a, b);
+ AccurateMath.addExact(a, b);
fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
}
} else {
- assertEquals(bdSum, BigInteger.valueOf(FastMath.addExact(a, b)));
+ assertEquals(bdSum, BigInteger.valueOf(AccurateMath.addExact(a, b)));
}
}
}
@@ -1653,13 +1653,13 @@ public class FastMathTest {
if (bdSub.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0 ||
bdSub.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) {
try {
- FastMath.subtractExact(a, b);
+ AccurateMath.subtractExact(a, b);
fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
}
} else {
- assertEquals(bdSub, BigInteger.valueOf(FastMath.subtractExact(a, b)));
+ assertEquals(bdSub, BigInteger.valueOf(AccurateMath.subtractExact(a, b)));
}
}
}
@@ -1682,13 +1682,13 @@ public class FastMathTest {
if (bdSub.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < 0 ||
bdSub.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) {
try {
- FastMath.subtractExact(a, b);
+ AccurateMath.subtractExact(a, b);
fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
}
} else {
- assertEquals(bdSub, BigInteger.valueOf(FastMath.subtractExact(a, b)));
+ assertEquals(bdSub, BigInteger.valueOf(AccurateMath.subtractExact(a, b)));
}
}
}
@@ -1711,13 +1711,13 @@ public class FastMathTest {
if (bdMul.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0 ||
bdMul.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) {
try {
- FastMath.multiplyExact(a, b);
+ AccurateMath.multiplyExact(a, b);
fail("an exception should have been thrown " + a + b);
} catch (MathArithmeticException mae) {
// expected
}
} else {
- assertEquals(bdMul, BigInteger.valueOf(FastMath.multiplyExact(a, b)));
+ assertEquals(bdMul, BigInteger.valueOf(AccurateMath.multiplyExact(a, b)));
}
}
}
@@ -1740,13 +1740,13 @@ public class FastMathTest {
if (bdMul.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < 0 ||
bdMul.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) {
try {
- FastMath.multiplyExact(a, b);
+ AccurateMath.multiplyExact(a, b);
fail("an exception should have been thrown " + a + b);
} catch (MathArithmeticException mae) {
// expected
}
} else {
- assertEquals(bdMul, BigInteger.valueOf(FastMath.multiplyExact(a, b)));
+ assertEquals(bdMul, BigInteger.valueOf(AccurateMath.multiplyExact(a, b)));
}
}
}
@@ -1754,31 +1754,31 @@ public class FastMathTest {
@Test(expected=MathArithmeticException.class)
public void testToIntExactTooLow() {
- FastMath.toIntExact(-1l + Integer.MIN_VALUE);
+ AccurateMath.toIntExact(-1l + Integer.MIN_VALUE);
}
@Test(expected=MathArithmeticException.class)
public void testToIntExactTooHigh() {
- FastMath.toIntExact(+1l + Integer.MAX_VALUE);
+ AccurateMath.toIntExact(+1l + Integer.MAX_VALUE);
}
@Test
public void testToIntExact() {
for (int n = -1000; n < 1000; ++n) {
- assertEquals(n, FastMath.toIntExact(0l + n));
+ assertEquals(n, AccurateMath.toIntExact(0l + n));
}
- assertEquals(Integer.MIN_VALUE, FastMath.toIntExact(0l + Integer.MIN_VALUE));
- assertEquals(Integer.MAX_VALUE, FastMath.toIntExact(0l + Integer.MAX_VALUE));
+ assertEquals(Integer.MIN_VALUE, AccurateMath.toIntExact(0l + Integer.MIN_VALUE));
+ assertEquals(Integer.MAX_VALUE, AccurateMath.toIntExact(0l + Integer.MAX_VALUE));
}
@Test
public void testFloorDivInt() {
- assertEquals(+1, FastMath.floorDiv(+4, +3));
- assertEquals(-2, FastMath.floorDiv(-4, +3));
- assertEquals(-2, FastMath.floorDiv(+4, -3));
- assertEquals(+1, FastMath.floorDiv(-4, -3));
+ assertEquals(+1, AccurateMath.floorDiv(+4, +3));
+ assertEquals(-2, AccurateMath.floorDiv(-4, +3));
+ assertEquals(-2, AccurateMath.floorDiv(+4, -3));
+ assertEquals(+1, AccurateMath.floorDiv(-4, -3));
try {
- FastMath.floorDiv(1, 0);
+ AccurateMath.floorDiv(1, 0);
fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
@@ -1786,7 +1786,7 @@ public class FastMathTest {
for (int a = -100; a <= 100; ++a) {
for (int b = -100; b <= 100; ++b) {
if (b != 0) {
- assertEquals(poorManFloorDiv(a, b), FastMath.floorDiv(a, b));
+ assertEquals(poorManFloorDiv(a, b), AccurateMath.floorDiv(a, b));
}
}
}
@@ -1794,12 +1794,12 @@ public class FastMathTest {
@Test
public void testFloorModInt() {
- assertEquals(+1, FastMath.floorMod(+4, +3));
- assertEquals(+2, FastMath.floorMod(-4, +3));
- assertEquals(-2, FastMath.floorMod(+4, -3));
- assertEquals(-1, FastMath.floorMod(-4, -3));
+ assertEquals(+1, AccurateMath.floorMod(+4, +3));
+ assertEquals(+2, AccurateMath.floorMod(-4, +3));
+ assertEquals(-2, AccurateMath.floorMod(+4, -3));
+ assertEquals(-1, AccurateMath.floorMod(-4, -3));
try {
- FastMath.floorMod(1, 0);
+ AccurateMath.floorMod(1, 0);
fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
@@ -1807,7 +1807,7 @@ public class FastMathTest {
for (int a = -100; a <= 100; ++a) {
for (int b = -100; b <= 100; ++b) {
if (b != 0) {
- assertEquals(poorManFloorMod(a, b), FastMath.floorMod(a, b));
+ assertEquals(poorManFloorMod(a, b), AccurateMath.floorMod(a, b));
}
}
}
@@ -1822,16 +1822,16 @@ public class FastMathTest {
int b = generator.nextInt();
if (b == 0) {
try {
- FastMath.floorDiv(a, b);
+ AccurateMath.floorDiv(a, b);
fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
}
} else {
- int d = FastMath.floorDiv(a, b);
- int m = FastMath.floorMod(a, b);
- assertEquals(FastMath.toIntExact(poorManFloorDiv(a, b)), d);
- assertEquals(FastMath.toIntExact(poorManFloorMod(a, b)), m);
+ int d = AccurateMath.floorDiv(a, b);
+ int m = AccurateMath.floorMod(a, b);
+ assertEquals(AccurateMath.toIntExact(poorManFloorDiv(a, b)), d);
+ assertEquals(AccurateMath.toIntExact(poorManFloorMod(a, b)), m);
assertEquals(a, d * b + m);
if (b < 0) {
assertTrue(m <= 0);
@@ -1846,12 +1846,12 @@ public class FastMathTest {
@Test
public void testFloorDivLong() {
- assertEquals(+1l, FastMath.floorDiv(+4l, +3l));
- assertEquals(-2l, FastMath.floorDiv(-4l, +3l));
- assertEquals(-2l, FastMath.floorDiv(+4l, -3l));
- assertEquals(+1l, FastMath.floorDiv(-4l, -3l));
+ assertEquals(+1l, AccurateMath.floorDiv(+4l, +3l));
+ assertEquals(-2l, AccurateMath.floorDiv(-4l, +3l));
+ assertEquals(-2l, AccurateMath.floorDiv(+4l, -3l));
+ assertEquals(+1l, AccurateMath.floorDiv(-4l, -3l));
try {
- FastMath.floorDiv(1l, 0l);
+ AccurateMath.floorDiv(1l, 0l);
fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
@@ -1859,7 +1859,7 @@ public class FastMathTest {
for (long a = -100l; a <= 100l; ++a) {
for (long b = -100l; b <= 100l; ++b) {
if (b != 0) {
- assertEquals(poorManFloorDiv(a, b), FastMath.floorDiv(a, b));
+ assertEquals(poorManFloorDiv(a, b), AccurateMath.floorDiv(a, b));
}
}
}
@@ -1867,12 +1867,12 @@ public class FastMathTest {
@Test
public void testFloorModLong() {
- assertEquals(+1l, FastMath.floorMod(+4l, +3l));
- assertEquals(+2l, FastMath.floorMod(-4l, +3l));
- assertEquals(-2l, FastMath.floorMod(+4l, -3l));
- assertEquals(-1l, FastMath.floorMod(-4l, -3l));
+ assertEquals(+1l, AccurateMath.floorMod(+4l, +3l));
+ assertEquals(+2l, AccurateMath.floorMod(-4l, +3l));
+ assertEquals(-2l, AccurateMath.floorMod(+4l, -3l));
+ assertEquals(-1l, AccurateMath.floorMod(-4l, -3l));
try {
- FastMath.floorMod(1l, 0l);
+ AccurateMath.floorMod(1l, 0l);
fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
@@ -1880,7 +1880,7 @@ public class FastMathTest {
for (long a = -100l; a <= 100l; ++a) {
for (long b = -100l; b <= 100l; ++b) {
if (b != 0) {
- assertEquals(poorManFloorMod(a, b), FastMath.floorMod(a, b));
+ assertEquals(poorManFloorMod(a, b), AccurateMath.floorMod(a, b));
}
}
}
@@ -1895,14 +1895,14 @@ public class FastMathTest {
long b = generator.nextLong();
if (b == 0) {
try {
- FastMath.floorDiv(a, b);
+ AccurateMath.floorDiv(a, b);
fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
}
} else {
- long d = FastMath.floorDiv(a, b);
- long m = FastMath.floorMod(a, b);
+ long d = AccurateMath.floorDiv(a, b);
+ long m = AccurateMath.floorMod(a, b);
assertEquals(poorManFloorDiv(a, b), d);
assertEquals(poorManFloorMod(a, b), m);
assertEquals(a, d * b + m);
@@ -1953,12 +1953,12 @@ public class FastMathTest {
public void testRoundDown() {
double x = 0x1.fffffffffffffp-2; // greatest floating point value less than 0.5
assertTrue(x < 0.5d);
- assertEquals(0, FastMath.round(x));
+ assertEquals(0, AccurateMath.round(x));
x = 4503599627370497.0; // x = Math.pow(2, 52) + 1;
assertEquals("4503599627370497", new BigDecimal(x).toString());
assertTrue(x == Math.rint(x));
- assertTrue(x == FastMath.round(x));
+ assertTrue(x == AccurateMath.round(x));
//assertTrue(x == Math.round(x)); // fails with Java 7, fixed in Java 8
}
diff --git a/commons-math-legacy/pom.xml b/commons-math-legacy/pom.xml
index 56876b3..3350422 100644
--- a/commons-math-legacy/pom.xml
+++ b/commons-math-legacy/pom.xml
@@ -116,12 +116,12 @@
<dependency>
<groupId>org.apache.commons</groupId>
- <artifactId>commons-rng-sampling</artifactId>
+ <artifactId>commons-math4-legacy-exception</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
- <artifactId>commons-math4-legacy-exception</artifactId>
+ <artifactId>commons-math4-legacy-core</artifactId>
</dependency>
<dependency>
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/RealFieldUnivariateFunction.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/RealFieldUnivariateFunction.java
index e08744c..5c0a9a3 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/RealFieldUnivariateFunction.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/RealFieldUnivariateFunction.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.math4.legacy.analysis;
-import org.apache.commons.math4.legacy.RealFieldElement;
+import org.apache.commons.math4.legacy.core.RealFieldElement;
/**
* An interface representing a univariate real function.
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/DSCompiler.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/DSCompiler.java
index 6310c1f..646d855 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/DSCompiler.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/DSCompiler.java
@@ -28,7 +28,7 @@ import org.apache.commons.math4.legacy.exception.MathInternalError;
import org.apache.commons.math4.legacy.exception.NotPositiveException;
import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
import org.apache.commons.numbers.combinatorics.FactorialDouble;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/** Class holding "compiled" computation rules for derivative structures.
* <p>This class implements the computation rules described in Dan Kalman's paper <a
@@ -199,8 +199,8 @@ public class DSCompiler {
}
// we need to create more compilers
- final int maxParameters = FastMath.max(parameters, cache == null ? 0 : cache.length);
- final int maxOrder = FastMath.max(order, cache == null ? 0 : cache[0].length);
+ final int maxParameters = AccurateMath.max(parameters, cache == null ? 0 : cache.length);
+ final int maxOrder = AccurateMath.max(order, cache == null ? 0 : cache[0].length);
final DSCompiler[][] newCache = new DSCompiler[maxParameters + 1][maxOrder + 1];
if (cache != null) {
@@ -212,7 +212,7 @@ public class DSCompiler {
// create the array in increasing diagonal order
for (int diag = 0; diag <= parameters + order; ++diag) {
- for (int o = FastMath.max(0, diag - parameters); o <= FastMath.min(order, diag); ++o) {
+ for (int o = AccurateMath.max(0, diag - parameters); o <= AccurateMath.min(order, diag); ++o) {
final int p = diag - o;
if (newCache[p][o] == null) {
final DSCompiler valueCompiler = (p == 0) ? null : newCache[p - 1][o];
@@ -610,7 +610,7 @@ public class DSCompiler {
final int destP, final int destO, final int[][] destSizes)
throws NumberIsTooLargeException {
int[] orders = new int[destP];
- System.arraycopy(srcDerivativesIndirection[index], 0, orders, 0, FastMath.min(srcP, destP));
+ System.arraycopy(srcDerivativesIndirection[index], 0, orders, 0, AccurateMath.min(srcP, destP));
return getPartialDerivativeIndex(destP, destO, destSizes, orders);
}
@@ -821,8 +821,8 @@ public class DSCompiler {
final double[] result, final int resultOffset) {
// compute k such that lhs % rhs = lhs - k rhs
- final double rem = FastMath.IEEEremainder(lhs[lhsOffset], rhs[rhsOffset]);
- final double k = FastMath.rint((lhs[lhsOffset] - rem) / rhs[rhsOffset]);
+ final double rem = AccurateMath.IEEEremainder(lhs[lhsOffset], rhs[rhsOffset]);
+ final double k = AccurateMath.rint((lhs[lhsOffset] - rem) / rhs[rhsOffset]);
// set up value
result[resultOffset] = rem;
@@ -863,8 +863,8 @@ public class DSCompiler {
Arrays.fill(function, Double.NaN);
}
} else {
- function[0] = FastMath.pow(a, operand[operandOffset]);
- final double lnA = FastMath.log(a);
+ function[0] = AccurateMath.pow(a, operand[operandOffset]);
+ final double lnA = AccurateMath.log(a);
for (int i = 1; i < function.length; ++i) {
function[i] = lnA * function[i - 1];
}
@@ -904,7 +904,7 @@ public class DSCompiler {
// create the function value and derivatives
// [x^p, px^(p-1), p(p-1)x^(p-2), ... ]
double[] function = new double[1 + order];
- double xk = FastMath.pow(operand[operandOffset], p - order);
+ double xk = AccurateMath.pow(operand[operandOffset], p - order);
for (int i = order; i > 0; --i) {
function[i] = xk;
xk *= operand[operandOffset];
@@ -946,8 +946,8 @@ public class DSCompiler {
if (n > 0) {
// strictly positive power
- final int maxOrder = FastMath.min(order, n);
- double xk = FastMath.pow(operand[operandOffset], n - maxOrder);
+ final int maxOrder = AccurateMath.min(order, n);
+ double xk = AccurateMath.pow(operand[operandOffset], n - maxOrder);
for (int i = maxOrder; i > 0; --i) {
function[i] = xk;
xk *= operand[operandOffset];
@@ -956,7 +956,7 @@ public class DSCompiler {
} else {
// strictly negative power
final double inv = 1.0 / operand[operandOffset];
- double xk = FastMath.pow(inv, -n);
+ double xk = AccurateMath.pow(inv, -n);
for (int i = 0; i <= order; ++i) {
function[i] = xk;
xk *= inv;
@@ -1011,14 +1011,14 @@ public class DSCompiler {
double[] function = new double[1 + order];
double xk;
if (n == 2) {
- function[0] = FastMath.sqrt(operand[operandOffset]);
+ function[0] = AccurateMath.sqrt(operand[operandOffset]);
xk = 0.5 / function[0];
} else if (n == 3) {
- function[0] = FastMath.cbrt(operand[operandOffset]);
+ function[0] = AccurateMath.cbrt(operand[operandOffset]);
xk = 1.0 / (3.0 * function[0] * function[0]);
} else {
- function[0] = FastMath.pow(operand[operandOffset], 1.0 / n);
- xk = 1.0 / (n * FastMath.pow(function[0], n - 1));
+ function[0] = AccurateMath.pow(operand[operandOffset], 1.0 / n);
+ xk = 1.0 / (n * AccurateMath.pow(function[0], n - 1));
}
final double nReciprocal = 1.0 / n;
final double xReciprocal = 1.0 / operand[operandOffset];
@@ -1045,7 +1045,7 @@ public class DSCompiler {
// create the function value and derivatives
double[] function = new double[1 + order];
- Arrays.fill(function, FastMath.exp(operand[operandOffset]));
+ Arrays.fill(function, AccurateMath.exp(operand[operandOffset]));
// apply function composition
compose(operand, operandOffset, function, result, resultOffset);
@@ -1065,8 +1065,8 @@ public class DSCompiler {
// create the function value and derivatives
double[] function = new double[1 + order];
- function[0] = FastMath.expm1(operand[operandOffset]);
- Arrays.fill(function, 1, 1 + order, FastMath.exp(operand[operandOffset]));
+ function[0] = AccurateMath.expm1(operand[operandOffset]);
+ Arrays.fill(function, 1, 1 + order, AccurateMath.exp(operand[operandOffset]));
// apply function composition
compose(operand, operandOffset, function, result, resultOffset);
@@ -1086,7 +1086,7 @@ public class DSCompiler {
// create the function value and derivatives
double[] function = new double[1 + order];
- function[0] = FastMath.log(operand[operandOffset]);
+ function[0] = AccurateMath.log(operand[operandOffset]);
if (order > 0) {
double inv = 1.0 / operand[operandOffset];
double xk = inv;
@@ -1113,7 +1113,7 @@ public class DSCompiler {
// create the function value and derivatives
double[] function = new double[1 + order];
- function[0] = FastMath.log1p(operand[operandOffset]);
+ function[0] = AccurateMath.log1p(operand[operandOffset]);
if (order > 0) {
double inv = 1.0 / (1.0 + operand[operandOffset]);
double xk = inv;
@@ -1140,10 +1140,10 @@ public class DSCompiler {
// create the function value and derivatives
double[] function = new double[1 + order];
- function[0] = FastMath.log10(operand[operandOffset]);
+ function[0] = AccurateMath.log10(operand[operandOffset]);
if (order > 0) {
double inv = 1.0 / operand[operandOffset];
- double xk = inv / FastMath.log(10.0);
+ double xk = inv / AccurateMath.log(10.0);
for (int i = 1; i <= order; ++i) {
function[i] = xk;
xk *= -i * inv;
@@ -1168,9 +1168,9 @@ public class DSCompiler {
// create the function value and derivatives
double[] function = new double[1 + order];
- function[0] = FastMath.cos(operand[operandOffset]);
+ function[0] = AccurateMath.cos(operand[operandOffset]);
if (order > 0) {
- function[1] = -FastMath.sin(operand[operandOffset]);
+ function[1] = -AccurateMath.sin(operand[operandOffset]);
for (int i = 2; i <= order; ++i) {
function[i] = -function[i - 2];
}
@@ -1194,9 +1194,9 @@ public class DSCompiler {
// create the function value and derivatives
double[] function = new double[1 + order];
- function[0] = FastMath.sin(operand[operandOffset]);
+ function[0] = AccurateMath.sin(operand[operandOffset]);
if (order > 0) {
- function[1] = FastMath.cos(operand[operandOffset]);
+ function[1] = AccurateMath.cos(operand[operandOffset]);
for (int i = 2; i <= order; ++i) {
function[i] = -function[i - 2];
}
@@ -1220,7 +1220,7 @@ public class DSCompiler {
// create the function value and derivatives
final double[] function = new double[1 + order];
- final double t = FastMath.tan(operand[operandOffset]);
+ final double t = AccurateMath.tan(operand[operandOffset]);
function[0] = t;
if (order > 0) {
@@ -1276,7 +1276,7 @@ public class DSCompiler {
// create the function value and derivatives
double[] function = new double[1 + order];
final double x = operand[operandOffset];
- function[0] = FastMath.acos(x);
+ function[0] = AccurateMath.acos(x);
if (order > 0) {
// the nth order derivative of acos has the form:
// dn(acos(x)/dxn = P_n(x) / [1 - x^2]^((2n-1)/2)
@@ -1289,7 +1289,7 @@ public class DSCompiler {
p[0] = -1;
final double x2 = x * x;
final double f = 1.0 / (1 - x2);
- double coeff = FastMath.sqrt(f);
+ double coeff = AccurateMath.sqrt(f);
function[1] = coeff * p[0];
for (int n = 2; n <= order; ++n) {
@@ -1333,7 +1333,7 @@ public class DSCompiler {
// create the function value and derivatives
double[] function = new double[1 + order];
final double x = operand[operandOffset];
- function[0] = FastMath.asin(x);
+ function[0] = AccurateMath.asin(x);
if (order > 0) {
// the nth order derivative of asin has the form:
// dn(asin(x)/dxn = P_n(x) / [1 - x^2]^((2n-1)/2)
@@ -1346,7 +1346,7 @@ public class DSCompiler {
p[0] = 1;
final double x2 = x * x;
final double f = 1.0 / (1 - x2);
- double coeff = FastMath.sqrt(f);
+ double coeff = AccurateMath.sqrt(f);
function[1] = coeff * p[0];
for (int n = 2; n <= order; ++n) {
@@ -1390,7 +1390,7 @@ public class DSCompiler {
// create the function value and derivatives
double[] function = new double[1 + order];
final double x = operand[operandOffset];
- function[0] = FastMath.atan(x);
+ function[0] = AccurateMath.atan(x);
if (order > 0) {
// the nth order derivative of atan has the form:
// dn(atan(x)/dxn = Q_n(x) / (1 + x^2)^n
@@ -1472,7 +1472,7 @@ public class DSCompiler {
divide(y, yOffset, tmp2, 0, tmp1, 0); // y /(r - x)
atan(tmp1, 0, tmp2, 0); // atan(y / (r - x))
result[resultOffset] =
- ((tmp2[0] <= 0) ? -FastMath.PI : FastMath.PI) - 2 * tmp2[0]; // +/-pi - 2 * atan(y / (r - x))
+ ((tmp2[0] <= 0) ? -AccurateMath.PI : AccurateMath.PI) - 2 * tmp2[0]; // +/-pi - 2 * atan(y / (r - x))
for (int i = 1; i < tmp2.length; ++i) {
result[resultOffset + i] = -2 * tmp2[i]; // +/-pi - 2 * atan(y / (r - x))
}
@@ -1480,7 +1480,7 @@ public class DSCompiler {
}
// fix value to take special cases (+0/+0, +0/-0, -0/+0, -0/-0, +/-infinity) correctly
- result[resultOffset] = FastMath.atan2(y[yOffset], x[xOffset]);
+ result[resultOffset] = AccurateMath.atan2(y[yOffset], x[xOffset]);
}
@@ -1497,9 +1497,9 @@ public class DSCompiler {
// create the function value and derivatives
double[] function = new double[1 + order];
- function[0] = FastMath.cosh(operand[operandOffset]);
+ function[0] = AccurateMath.cosh(operand[operandOffset]);
if (order > 0) {
- function[1] = FastMath.sinh(operand[operandOffset]);
+ function[1] = AccurateMath.sinh(operand[operandOffset]);
for (int i = 2; i <= order; ++i) {
function[i] = function[i - 2];
}
@@ -1523,9 +1523,9 @@ public class DSCompiler {
// create the function value and derivatives
double[] function = new double[1 + order];
- function[0] = FastMath.sinh(operand[operandOffset]);
+ function[0] = AccurateMath.sinh(operand[operandOffset]);
if (order > 0) {
- function[1] = FastMath.cosh(operand[operandOffset]);
+ function[1] = AccurateMath.cosh(operand[operandOffset]);
for (int i = 2; i <= order; ++i) {
function[i] = function[i - 2];
}
@@ -1549,7 +1549,7 @@ public class DSCompiler {
// create the function value and derivatives
final double[] function = new double[1 + order];
- final double t = FastMath.tanh(operand[operandOffset]);
+ final double t = AccurateMath.tanh(operand[operandOffset]);
function[0] = t;
if (order > 0) {
@@ -1605,7 +1605,7 @@ public class DSCompiler {
// create the function value and derivatives
double[] function = new double[1 + order];
final double x = operand[operandOffset];
- function[0] = FastMath.acosh(x);
+ function[0] = AccurateMath.acosh(x);
if (order > 0) {
// the nth order derivative of acosh has the form:
// dn(acosh(x)/dxn = P_n(x) / [x^2 - 1]^((2n-1)/2)
@@ -1618,7 +1618,7 @@ public class DSCompiler {
p[0] = 1;
final double x2 = x * x;
final double f = 1.0 / (x2 - 1);
- double coeff = FastMath.sqrt(f);
+ double coeff = AccurateMath.sqrt(f);
function[1] = coeff * p[0];
for (int n = 2; n <= order; ++n) {
@@ -1662,7 +1662,7 @@ public class DSCompiler {
// create the function value and derivatives
double[] function = new double[1 + order];
final double x = operand[operandOffset];
- function[0] = FastMath.asinh(x);
+ function[0] = AccurateMath.asinh(x);
if (order > 0) {
// the nth order derivative of asinh has the form:
// dn(asinh(x)/dxn = P_n(x) / [x^2 + 1]^((2n-1)/2)
@@ -1675,7 +1675,7 @@ public class DSCompiler {
p[0] = 1;
final double x2 = x * x;
final double f = 1.0 / (1 + x2);
- double coeff = FastMath.sqrt(f);
+ double coeff = AccurateMath.sqrt(f);
function[1] = coeff * p[0];
for (int n = 2; n <= order; ++n) {
@@ -1719,7 +1719,7 @@ public class DSCompiler {
// create the function value and derivatives
double[] function = new double[1 + order];
final double x = operand[operandOffset];
- function[0] = FastMath.atanh(x);
+ function[0] = AccurateMath.atanh(x);
if (order > 0) {
// the nth order derivative of atanh has the form:
// dn(atanh(x)/dxn = Q_n(x) / (1 - x^2)^n
@@ -1805,7 +1805,7 @@ public class DSCompiler {
for (int k = 0; k < orders.length; ++k) {
if (orders[k] > 0) {
try {
- term *= FastMath.pow(delta[k], orders[k]) / FACTORIAL.value(orders[k]);
+ term *= AccurateMath.pow(delta[k], orders[k]) / FACTORIAL.value(orders[k]);
} catch (NotPositiveException e) {
// this cannot happen
throw new MathInternalError(e);
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/DerivativeStructure.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/DerivativeStructure.java
index db3d152..36c13f6 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/DerivativeStructure.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/DerivativeStructure.java
@@ -20,14 +20,14 @@ import java.util.Arrays;
import java.io.Serializable;
import org.apache.commons.numbers.arrays.LinearCombination;
-import org.apache.commons.math4.legacy.Field;
-import org.apache.commons.math4.legacy.FieldElement;
-import org.apache.commons.math4.legacy.RealFieldElement;
+import org.apache.commons.math4.legacy.core.Field;
+import org.apache.commons.math4.legacy.core.FieldElement;
+import org.apache.commons.math4.legacy.core.RealFieldElement;
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.MathArithmeticException;
import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
-import org.apache.commons.math4.legacy.util.FastMath;
-import org.apache.commons.math4.legacy.util.MathArrays;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
+import org.apache.commons.math4.legacy.core.MathArrays;
/** Class representing both the value and the differentials of a function.
* <p>This class is the workhorse of the differentiation package.</p>
@@ -389,7 +389,7 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
@Override
public DerivativeStructure remainder(final double a) {
final DerivativeStructure ds = new DerivativeStructure(this);
- ds.data[0] = FastMath.IEEEremainder(ds.data[0], a);
+ ds.data[0] = AccurateMath.IEEEremainder(ds.data[0], a);
return ds;
}
@@ -437,7 +437,7 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
public DerivativeStructure ceil() {
return new DerivativeStructure(compiler.getFreeParameters(),
compiler.getOrder(),
- FastMath.ceil(data[0]));
+ AccurateMath.ceil(data[0]));
}
/** {@inheritDoc}
@@ -447,7 +447,7 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
public DerivativeStructure floor() {
return new DerivativeStructure(compiler.getFreeParameters(),
compiler.getOrder(),
- FastMath.floor(data[0]));
+ AccurateMath.floor(data[0]));
}
/** {@inheritDoc}
@@ -457,13 +457,13 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
public DerivativeStructure rint() {
return new DerivativeStructure(compiler.getFreeParameters(),
compiler.getOrder(),
- FastMath.rint(data[0]));
+ AccurateMath.rint(data[0]));
}
/** {@inheritDoc} */
@Override
public long round() {
- return FastMath.round(data[0]);
+ return AccurateMath.round(data[0]);
}
/** {@inheritDoc}
@@ -473,7 +473,7 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
public DerivativeStructure signum() {
return new DerivativeStructure(compiler.getFreeParameters(),
compiler.getOrder(),
- FastMath.signum(data[0]));
+ AccurateMath.signum(data[0]));
}
/** {@inheritDoc}
@@ -511,7 +511,7 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
* @return exponent for instance in IEEE754 representation, without bias
*/
public int getExponent() {
- return FastMath.getExponent(data[0]);
+ return AccurateMath.getExponent(data[0]);
}
/** {@inheritDoc}
@@ -521,7 +521,7 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
public DerivativeStructure scalb(final int n) {
final DerivativeStructure ds = new DerivativeStructure(compiler);
for (int i = 0; i < ds.data.length; ++i) {
- ds.data[i] = FastMath.scalb(data[i], n);
+ ds.data[i] = AccurateMath.scalb(data[i], n);
}
return ds;
}
@@ -923,7 +923,7 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
public DerivativeStructure toDegrees() {
final DerivativeStructure ds = new DerivativeStructure(compiler);
for (int i = 0; i < ds.data.length; ++i) {
- ds.data[i] = FastMath.toDegrees(data[i]);
+ ds.data[i] = AccurateMath.toDegrees(data[i]);
}
return ds;
}
@@ -934,7 +934,7 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
public DerivativeStructure toRadians() {
final DerivativeStructure ds = new DerivativeStructure(compiler);
for (int i = 0; i < ds.data.length; ++i) {
- ds.data[i] = FastMath.toRadians(data[i]);
+ ds.data[i] = AccurateMath.toRadians(data[i]);
}
return ds;
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/FiniteDifferencesDifferentiator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/FiniteDifferencesDifferentiator.java
index c008751..1441097 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/FiniteDifferencesDifferentiator.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/FiniteDifferencesDifferentiator.java
@@ -25,7 +25,7 @@ import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException;
import org.apache.commons.math4.legacy.exception.NotPositiveException;
import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/** Univariate functions differentiator using finite differences.
* <p>
@@ -156,7 +156,7 @@ public class FiniteDifferencesDifferentiator
if (2 * halfSampleSpan >= tUpper - tLower) {
throw new NumberIsTooLargeException(2 * halfSampleSpan, tUpper - tLower, false);
}
- final double safety = FastMath.ulp(halfSampleSpan);
+ final double safety = AccurateMath.ulp(halfSampleSpan);
this.tMin = tLower + halfSampleSpan + safety;
this.tMax = tUpper - halfSampleSpan - safety;
@@ -262,7 +262,7 @@ public class FiniteDifferencesDifferentiator
}
// compute sample position, trying to be centered if possible
- final double t0 = FastMath.max(FastMath.min(t.getValue(), tMax), tMin) - halfSampleSpan;
+ final double t0 = AccurateMath.max(AccurateMath.min(t.getValue(), tMax), tMin) - halfSampleSpan;
// compute sample points
final double[] y = new double[nbPoints];
@@ -305,7 +305,7 @@ public class FiniteDifferencesDifferentiator
}
// compute sample position, trying to be centered if possible
- final double t0 = FastMath.max(FastMath.min(t.getValue(), tMax), tMin) - halfSampleSpan;
+ final double t0 = AccurateMath.max(AccurateMath.min(t.getValue(), tMax), tMin) - halfSampleSpan;
// compute sample points
double[][] y = null;
@@ -359,7 +359,7 @@ public class FiniteDifferencesDifferentiator
}
// compute sample position, trying to be centered if possible
- final double t0 = FastMath.max(FastMath.min(t.getValue(), tMax), tMin) - halfSampleSpan;
+ final double t0 = AccurateMath.max(AccurateMath.min(t.getValue(), tMax), tMin) - halfSampleSpan;
// compute sample points
double[][][] y = null;
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/SparseGradient.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/SparseGradient.java
index 84a2320..bb59997 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/SparseGradient.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/SparseGradient.java
@@ -23,11 +23,11 @@ import java.util.Map;
import org.apache.commons.numbers.arrays.LinearCombination;
import org.apache.commons.numbers.core.Precision;
-import org.apache.commons.math4.legacy.Field;
-import org.apache.commons.math4.legacy.FieldElement;
-import org.apache.commons.math4.legacy.RealFieldElement;
+import org.apache.commons.math4.legacy.core.Field;
+import org.apache.commons.math4.legacy.core.FieldElement;
+import org.apache.commons.math4.legacy.core.RealFieldElement;
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* First derivative computation with large number of variables.
@@ -330,7 +330,7 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, Seriali
/** {@inheritDoc} */
@Override
public SparseGradient remainder(final double a) {
- return new SparseGradient(FastMath.IEEEremainder(value, a), derivatives);
+ return new SparseGradient(AccurateMath.IEEEremainder(value, a), derivatives);
}
/** {@inheritDoc} */
@@ -338,8 +338,8 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, Seriali
public SparseGradient remainder(final SparseGradient a) {
// compute k such that lhs % rhs = lhs - k rhs
- final double rem = FastMath.IEEEremainder(value, a.value);
- final double k = FastMath.rint((value - rem) / a.value);
+ final double rem = AccurateMath.IEEEremainder(value, a.value);
+ final double k = AccurateMath.rint((value - rem) / a.value);
return subtract(a.multiply(k));
@@ -359,31 +359,31 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, Seriali
/** {@inheritDoc} */
@Override
public SparseGradient ceil() {
- return createConstant(FastMath.ceil(value));
+ return createConstant(AccurateMath.ceil(value));
}
/** {@inheritDoc} */
@Override
public SparseGradient floor() {
- return createConstant(FastMath.floor(value));
+ return createConstant(AccurateMath.floor(value));
}
/** {@inheritDoc} */
@Override
public SparseGradient rint() {
- return createConstant(FastMath.rint(value));
+ return createConstant(AccurateMath.rint(value));
}
/** {@inheritDoc} */
@Override
public long round() {
- return FastMath.round(value);
+ return AccurateMath.round(value);
}
/** {@inheritDoc} */
@Override
public SparseGradient signum() {
- return createConstant(FastMath.signum(value));
+ return createConstant(AccurateMath.signum(value));
}
/** {@inheritDoc} */
@@ -411,9 +411,9 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, Seriali
/** {@inheritDoc} */
@Override
public SparseGradient scalb(final int n) {
- final SparseGradient out = new SparseGradient(FastMath.scalb(value, n), Collections.<Integer, Double> emptyMap());
+ final SparseGradient out = new SparseGradient(AccurateMath.scalb(value, n), Collections.<Integer, Double> emptyMap());
for (Map.Entry<Integer, Double> entry : derivatives.entrySet()) {
- out.derivatives.put(entry.getKey(), FastMath.scalb(entry.getValue(), n));
+ out.derivatives.put(entry.getKey(), AccurateMath.scalb(entry.getValue(), n));
}
return out;
}
@@ -427,8 +427,8 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, Seriali
return createConstant(Double.NaN);
} else {
- final int expX = FastMath.getExponent(value);
- final int expY = FastMath.getExponent(y.value);
+ final int expX = AccurateMath.getExponent(value);
+ final int expY = AccurateMath.getExponent(y.value);
if (expX > expY + 27) {
// y is negligible with respect to x
return abs();
@@ -483,14 +483,14 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, Seriali
/** {@inheritDoc} */
@Override
public SparseGradient sqrt() {
- final double sqrt = FastMath.sqrt(value);
+ final double sqrt = AccurateMath.sqrt(value);
return new SparseGradient(sqrt, 0.5 / sqrt, derivatives);
}
/** {@inheritDoc} */
@Override
public SparseGradient cbrt() {
- final double cbrt = FastMath.cbrt(value);
+ final double cbrt = AccurateMath.cbrt(value);
return new SparseGradient(cbrt, 1.0 / (3 * cbrt * cbrt), derivatives);
}
@@ -502,15 +502,15 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, Seriali
} else if (n == 3) {
return cbrt();
} else {
- final double root = FastMath.pow(value, 1.0 / n);
- return new SparseGradient(root, 1.0 / (n * FastMath.pow(root, n - 1)), derivatives);
+ final double root = AccurateMath.pow(value, 1.0 / n);
+ return new SparseGradient(root, 1.0 / (n * AccurateMath.pow(root, n - 1)), derivatives);
}
}
/** {@inheritDoc} */
@Override
public SparseGradient pow(final double p) {
- return new SparseGradient(FastMath.pow(value, p), p * FastMath.pow(value, p - 1), derivatives);
+ return new SparseGradient(AccurateMath.pow(value, p), p * AccurateMath.pow(value, p - 1), derivatives);
}
/** {@inheritDoc} */
@@ -519,7 +519,7 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, Seriali
if (n == 0) {
return getField().getOne();
} else {
- final double valueNm1 = FastMath.pow(value, n - 1);
+ final double valueNm1 = AccurateMath.pow(value, n - 1);
return new SparseGradient(value * valueNm1, n * valueNm1, derivatives);
}
}
@@ -545,28 +545,28 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, Seriali
return x.getField().getZero();
}
} else {
- final double ax = FastMath.pow(a, x.value);
- return new SparseGradient(ax, ax * FastMath.log(a), x.derivatives);
+ final double ax = AccurateMath.pow(a, x.value);
+ return new SparseGradient(ax, ax * AccurateMath.log(a), x.derivatives);
}
}
/** {@inheritDoc} */
@Override
public SparseGradient exp() {
- final double e = FastMath.exp(value);
+ final double e = AccurateMath.exp(value);
return new SparseGradient(e, e, derivatives);
}
/** {@inheritDoc} */
@Override
public SparseGradient expm1() {
- return new SparseGradient(FastMath.expm1(value), FastMath.exp(value), derivatives);
+ return new SparseGradient(AccurateMath.expm1(value), AccurateMath.exp(value), derivatives);
}
/** {@inheritDoc} */
@Override
public SparseGradient log() {
- return new SparseGradient(FastMath.log(value), 1.0 / value, derivatives);
+ return new SparseGradient(AccurateMath.log(value), 1.0 / value, derivatives);
}
/** Base 10 logarithm.
@@ -574,50 +574,50 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, Seriali
*/
@Override
public SparseGradient log10() {
- return new SparseGradient(FastMath.log10(value), 1.0 / (FastMath.log(10.0) * value), derivatives);
+ return new SparseGradient(AccurateMath.log10(value), 1.0 / (AccurateMath.log(10.0) * value), derivatives);
}
/** {@inheritDoc} */
@Override
public SparseGradient log1p() {
- return new SparseGradient(FastMath.log1p(value), 1.0 / (1.0 + value), derivatives);
+ return new SparseGradient(AccurateMath.log1p(value), 1.0 / (1.0 + value), derivatives);
}
/** {@inheritDoc} */
@Override
public SparseGradient cos() {
- return new SparseGradient(FastMath.cos(value), -FastMath.sin(value), derivatives);
+ return new SparseGradient(AccurateMath.cos(value), -AccurateMath.sin(value), derivatives);
}
/** {@inheritDoc} */
@Override
public SparseGradient sin() {
- return new SparseGradient(FastMath.sin(value), FastMath.cos(value), derivatives);
+ return new SparseGradient(AccurateMath.sin(value), AccurateMath.cos(value), derivatives);
}
/** {@inheritDoc} */
@Override
public SparseGradient tan() {
- final double t = FastMath.tan(value);
+ final double t = AccurateMath.tan(value);
return new SparseGradient(t, 1 + t * t, derivatives);
}
/** {@inheritDoc} */
@Override
public SparseGradient acos() {
- return new SparseGradient(FastMath.acos(value), -1.0 / FastMath.sqrt(1 - value * value), derivatives);
+ return new SparseGradient(AccurateMath.acos(value), -1.0 / AccurateMath.sqrt(1 - value * value), derivatives);
}
/** {@inheritDoc} */
@Override
public SparseGradient asin() {
- return new SparseGradient(FastMath.asin(value), 1.0 / FastMath.sqrt(1 - value * value), derivatives);
+ return new SparseGradient(AccurateMath.asin(value), 1.0 / AccurateMath.sqrt(1 - value * value), derivatives);
}
/** {@inheritDoc} */
@Override
public SparseGradient atan() {
- return new SparseGradient(FastMath.atan(value), 1.0 / (1 + value * value), derivatives);
+ return new SparseGradient(AccurateMath.atan(value), 1.0 / (1 + value * value), derivatives);
}
/** {@inheritDoc} */
@@ -637,12 +637,12 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, Seriali
// compute atan2(y, x) = +/- pi - 2 atan(y / (r - x))
final SparseGradient tmp = divide(r.subtract(x)).atan().multiply(-2);
- a = tmp.add(tmp.value <= 0 ? -FastMath.PI : FastMath.PI);
+ a = tmp.add(tmp.value <= 0 ? -AccurateMath.PI : AccurateMath.PI);
}
// fix value to take special cases (+0/+0, +0/-0, -0/+0, -0/-0, +/-infinity) correctly
- a.value = FastMath.atan2(value, x.value);
+ a.value = AccurateMath.atan2(value, x.value);
return a;
@@ -660,52 +660,52 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, Seriali
/** {@inheritDoc} */
@Override
public SparseGradient cosh() {
- return new SparseGradient(FastMath.cosh(value), FastMath.sinh(value), derivatives);
+ return new SparseGradient(AccurateMath.cosh(value), AccurateMath.sinh(value), derivatives);
}
/** {@inheritDoc} */
@Override
public SparseGradient sinh() {
- return new SparseGradient(FastMath.sinh(value), FastMath.cosh(value), derivatives);
+ return new SparseGradient(AccurateMath.sinh(value), AccurateMath.cosh(value), derivatives);
}
/** {@inheritDoc} */
@Override
public SparseGradient tanh() {
- final double t = FastMath.tanh(value);
+ final double t = AccurateMath.tanh(value);
return new SparseGradient(t, 1 - t * t, derivatives);
}
/** {@inheritDoc} */
@Override
public SparseGradient acosh() {
- return new SparseGradient(FastMath.acosh(value), 1.0 / FastMath.sqrt(value * value - 1.0), derivatives);
+ return new SparseGradient(AccurateMath.acosh(value), 1.0 / AccurateMath.sqrt(value * value - 1.0), derivatives);
}
/** {@inheritDoc} */
@Override
public SparseGradient asinh() {
- return new SparseGradient(FastMath.asinh(value), 1.0 / FastMath.sqrt(value * value + 1.0), derivatives);
+ return new SparseGradient(AccurateMath.asinh(value), 1.0 / AccurateMath.sqrt(value * value + 1.0), derivatives);
}
/** {@inheritDoc} */
@Override
public SparseGradient atanh() {
- return new SparseGradient(FastMath.atanh(value), 1.0 / (1.0 - value * value), derivatives);
+ return new SparseGradient(AccurateMath.atanh(value), 1.0 / (1.0 - value * value), derivatives);
}
/** Convert radians to degrees, with error of less than 0.5 ULP
* @return instance converted into degrees
*/
public SparseGradient toDegrees() {
- return new SparseGradient(FastMath.toDegrees(value), FastMath.toDegrees(1.0), derivatives);
+ return new SparseGradient(AccurateMath.toDegrees(value), AccurateMath.toDegrees(1.0), derivatives);
}
/** Convert degrees to radians, with error of less than 0.5 ULP
* @return instance converted into radians
*/
public SparseGradient toRadians() {
- return new SparseGradient(FastMath.toRadians(value), FastMath.toRadians(1.0), derivatives);
+ return new SparseGradient(AccurateMath.toRadians(value), AccurateMath.toRadians(1.0), derivatives);
}
/** Evaluate Taylor expansion of a sparse gradient.
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Abs.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Abs.java
index 0989736..668a886 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Abs.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Abs.java
@@ -18,7 +18,7 @@
package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.UnivariateFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Absolute value function.
@@ -29,6 +29,6 @@ public class Abs implements UnivariateFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.abs(x);
+ return AccurateMath.abs(x);
}
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Acos.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Acos.java
index ffaaeb4..fcfde56 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Acos.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Acos.java
@@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Arc-cosine function.
@@ -30,7 +30,7 @@ public class Acos implements UnivariateDifferentiableFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.acos(x);
+ return AccurateMath.acos(x);
}
/** {@inheritDoc}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Acosh.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Acosh.java
index 215697c..3f85696 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Acosh.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Acosh.java
@@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Hyperbolic arc-cosine function.
@@ -30,7 +30,7 @@ public class Acosh implements UnivariateDifferentiableFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.acosh(x);
+ return AccurateMath.acosh(x);
}
/** {@inheritDoc}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Asin.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Asin.java
index 4cf92d4..fc94591 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Asin.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Asin.java
@@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Arc-sine function.
@@ -30,7 +30,7 @@ public class Asin implements UnivariateDifferentiableFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.asin(x);
+ return AccurateMath.asin(x);
}
/** {@inheritDoc}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Asinh.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Asinh.java
index c7e3833..98e38ce 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Asinh.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Asinh.java
@@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Hyperbolic arc-sine function.
@@ -30,7 +30,7 @@ public class Asinh implements UnivariateDifferentiableFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.asinh(x);
+ return AccurateMath.asinh(x);
}
/** {@inheritDoc}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atan.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atan.java
index df53ea5..c52d686 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atan.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atan.java
@@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Arc-tangent function.
@@ -30,7 +30,7 @@ public class Atan implements UnivariateDifferentiableFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.atan(x);
+ return AccurateMath.atan(x);
}
/** {@inheritDoc}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atan2.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atan2.java
index bc95323..927787b 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atan2.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atan2.java
@@ -18,7 +18,7 @@
package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.BivariateFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Arc-tangent function.
@@ -29,6 +29,6 @@ public class Atan2 implements BivariateFunction {
/** {@inheritDoc} */
@Override
public double value(double y, double x) {
- return FastMath.atan2(y, x);
+ return AccurateMath.atan2(y, x);
}
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atanh.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atanh.java
index e48625f..6061dd1 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atanh.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atanh.java
@@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Hyperbolic arc-tangent function.
@@ -30,7 +30,7 @@ public class Atanh implements UnivariateDifferentiableFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.atanh(x);
+ return AccurateMath.atanh(x);
}
/** {@inheritDoc}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cbrt.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cbrt.java
index 622ffaf..ed97844 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cbrt.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cbrt.java
@@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Cube root function.
@@ -30,7 +30,7 @@ public class Cbrt implements UnivariateDifferentiableFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.cbrt(x);
+ return AccurateMath.cbrt(x);
}
/** {@inheritDoc}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Ceil.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Ceil.java
index 11423e1..5ec6b36 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Ceil.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Ceil.java
@@ -18,7 +18,7 @@
package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.UnivariateFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* {@code ceil} function.
@@ -29,6 +29,6 @@ public class Ceil implements UnivariateFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.ceil(x);
+ return AccurateMath.ceil(x);
}
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cos.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cos.java
index c816c19..c82e237 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cos.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cos.java
@@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Cosine function.
@@ -30,7 +30,7 @@ public class Cos implements UnivariateDifferentiableFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.cos(x);
+ return AccurateMath.cos(x);
}
/** {@inheritDoc}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cosh.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cosh.java
index a54342f..32aa17e 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cosh.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cosh.java
@@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Hyperbolic cosine function.
@@ -30,7 +30,7 @@ public class Cosh implements UnivariateDifferentiableFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.cosh(x);
+ return AccurateMath.cosh(x);
}
/** {@inheritDoc}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Exp.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Exp.java
index 4ae9373..bc8530e 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Exp.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Exp.java
@@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Exponential function.
@@ -30,7 +30,7 @@ public class Exp implements UnivariateDifferentiableFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.exp(x);
+ return AccurateMath.exp(x);
}
/** {@inheritDoc}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Expm1.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Expm1.java
index 4a430f8..1d683e2 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Expm1.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Expm1.java
@@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* <code>e<sup>x</sup>-1</code> function.
@@ -30,7 +30,7 @@ public class Expm1 implements UnivariateDifferentiableFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.expm1(x);
+ return AccurateMath.expm1(x);
}
/** {@inheritDoc}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Floor.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Floor.java
index 9f8f996..26267ce 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Floor.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Floor.java
@@ -18,7 +18,7 @@
package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.UnivariateFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* {@code floor} function.
@@ -29,6 +29,6 @@ public class Floor implements UnivariateFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.floor(x);
+ return AccurateMath.floor(x);
}
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Gaussian.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Gaussian.java
index 0c6d46f..b5c6af4 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Gaussian.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Gaussian.java
@@ -25,7 +25,7 @@ import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDiffer
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException;
import org.apache.commons.math4.legacy.exception.NullArgumentException;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
import org.apache.commons.numbers.core.Precision;
/**
@@ -76,7 +76,7 @@ public class Gaussian implements UnivariateDifferentiableFunction {
public Gaussian(double mean,
double sigma)
throws NotStrictlyPositiveException {
- this(1 / (sigma * FastMath.sqrt(2 * Math.PI)), mean, sigma);
+ this(1 / (sigma * AccurateMath.sqrt(2 * Math.PI)), mean, sigma);
}
/**
@@ -194,7 +194,7 @@ public class Gaussian implements UnivariateDifferentiableFunction {
private static double value(double xMinusMean,
double norm,
double i2s2) {
- return norm * FastMath.exp(-xMinusMean * xMinusMean * i2s2);
+ return norm * AccurateMath.exp(-xMinusMean * xMinusMean * i2s2);
}
/** {@inheritDoc}
@@ -217,7 +217,7 @@ public class Gaussian implements UnivariateDifferentiableFunction {
final double[] p = new double[f.length];
p[0] = 1;
final double u2 = u * u;
- double coeff = norm * FastMath.exp(-0.5 * u2);
+ double coeff = norm * AccurateMath.exp(-0.5 * u2);
if (coeff <= Precision.SAFE_MIN) {
Arrays.fill(f, 0.0);
} else {
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/HarmonicOscillator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/HarmonicOscillator.java
index b8fac67..4c8a29e 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/HarmonicOscillator.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/HarmonicOscillator.java
@@ -22,7 +22,7 @@ import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStruct
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.NullArgumentException;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* <a href="http://en.wikipedia.org/wiki/Harmonic_oscillator">
@@ -112,7 +112,7 @@ public class HarmonicOscillator implements UnivariateDifferentiableFunction {
final double xTimesOmegaPlusPhase = omega * x + phase;
final double a = HarmonicOscillator.value(xTimesOmegaPlusPhase, 1);
- final double p = -amplitude * FastMath.sin(xTimesOmegaPlusPhase);
+ final double p = -amplitude * AccurateMath.sin(xTimesOmegaPlusPhase);
final double w = p * x;
return new double[] { a, w, p };
@@ -147,7 +147,7 @@ public class HarmonicOscillator implements UnivariateDifferentiableFunction {
*/
private static double value(double xTimesOmegaPlusPhase,
double amplitude) {
- return amplitude * FastMath.cos(xTimesOmegaPlusPhase);
+ return amplitude * AccurateMath.cos(xTimesOmegaPlusPhase);
}
/** {@inheritDoc}
@@ -160,9 +160,9 @@ public class HarmonicOscillator implements UnivariateDifferentiableFunction {
double[] f = new double[t.getOrder() + 1];
final double alpha = omega * x + phase;
- f[0] = amplitude * FastMath.cos(alpha);
+ f[0] = amplitude * AccurateMath.cos(alpha);
if (f.length > 1) {
- f[1] = -amplitude * omega * FastMath.sin(alpha);
+ f[1] = -amplitude * omega * AccurateMath.sin(alpha);
final double mo2 = - omega * omega;
for (int i = 2; i < f.length; ++i) {
f[i] = mo2 * f[i - 2];
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log.java
index 0db005b..6dfdb21 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log.java
@@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Natural logarithm function.
@@ -30,7 +30,7 @@ public class Log implements UnivariateDifferentiableFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.log(x);
+ return AccurateMath.log(x);
}
/** {@inheritDoc}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log10.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log10.java
index c0b36ae..e7228a3 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log10.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log10.java
@@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Base 10 logarithm function.
@@ -31,7 +31,7 @@ public class Log10 implements UnivariateDifferentiableFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.log10(x);
+ return AccurateMath.log10(x);
}
/** {@inheritDoc}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log1p.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log1p.java
index d6f0b14..1f24404 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log1p.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log1p.java
@@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* <code>log(1 + p)</code> function.
@@ -30,7 +30,7 @@ public class Log1p implements UnivariateDifferentiableFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.log1p(x);
+ return AccurateMath.log1p(x);
}
/** {@inheritDoc}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logistic.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logistic.java
index e5bfe7b..18c2770 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logistic.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logistic.java
@@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDiffer
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException;
import org.apache.commons.math4.legacy.exception.NullArgumentException;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* <a href="http://en.wikipedia.org/wiki/Generalised_logistic_function">
@@ -147,10 +147,10 @@ public class Logistic implements UnivariateDifferentiableFunction {
final double mMinusX = param[1] - x;
final double oneOverN = 1 / param[5];
- final double exp = FastMath.exp(b * mMinusX);
+ final double exp = AccurateMath.exp(b * mMinusX);
final double qExp = q * exp;
final double qExp1 = qExp + 1;
- final double factor1 = (param[0] - param[4]) * oneOverN / FastMath.pow(qExp1, oneOverN);
+ final double factor1 = (param[0] - param[4]) * oneOverN / AccurateMath.pow(qExp1, oneOverN);
final double factor2 = -factor1 / qExp1;
// Components of the gradient.
@@ -159,7 +159,7 @@ public class Logistic implements UnivariateDifferentiableFunction {
final double gb = factor2 * mMinusX * qExp;
final double gq = factor2 * exp;
final double ga = Logistic.value(mMinusX, 0, b, q, 1, oneOverN);
- final double gn = factor1 * FastMath.log(qExp1) * oneOverN;
+ final double gn = factor1 * AccurateMath.log(qExp1) * oneOverN;
return new double[] { gk, gm, gb, gq, ga, gn };
}
@@ -207,7 +207,7 @@ public class Logistic implements UnivariateDifferentiableFunction {
double q,
double a,
double oneOverN) {
- return a + (k - a) / FastMath.pow(1 + q * FastMath.exp(b * mMinusX), oneOverN);
+ return a + (k - a) / AccurateMath.pow(1 + q * AccurateMath.exp(b * mMinusX), oneOverN);
}
/** {@inheritDoc}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logit.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logit.java
index 2d0c720..c04baf6 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logit.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logit.java
@@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDiffer
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.NullArgumentException;
import org.apache.commons.math4.legacy.exception.OutOfRangeException;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* <a href="http://en.wikipedia.org/wiki/Logit">
@@ -153,7 +153,7 @@ public class Logit implements UnivariateDifferentiableFunction {
if (x < lo || x > hi) {
throw new OutOfRangeException(x, lo, hi);
}
- return FastMath.log((x - lo) / (hi - x));
+ return AccurateMath.log((x - lo) / (hi - x));
}
/** {@inheritDoc}
@@ -170,7 +170,7 @@ public class Logit implements UnivariateDifferentiableFunction {
double[] f = new double[t.getOrder() + 1];
// function value
- f[0] = FastMath.log((x - lo) / (hi - x));
+ f[0] = AccurateMath.log((x - lo) / (hi - x));
if (Double.isInfinite(f[0])) {
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Max.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Max.java
index 023fd25..f338b813 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Max.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Max.java
@@ -18,7 +18,7 @@
package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.BivariateFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Maximum function.
@@ -29,6 +29,6 @@ public class Max implements BivariateFunction {
/** {@inheritDoc} */
@Override
public double value(double x, double y) {
- return FastMath.max(x, y);
+ return AccurateMath.max(x, y);
}
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Min.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Min.java
index b9d4960..90eba84 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Min.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Min.java
@@ -18,7 +18,7 @@
package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.BivariateFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Minimum function.
@@ -29,6 +29,6 @@ public class Min implements BivariateFunction {
/** {@inheritDoc} */
@Override
public double value(double x, double y) {
- return FastMath.min(x, y);
+ return AccurateMath.min(x, y);
}
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Pow.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Pow.java
index 1452c80..70b6915 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Pow.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Pow.java
@@ -18,7 +18,7 @@
package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.BivariateFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Power function.
@@ -29,6 +29,6 @@ public class Pow implements BivariateFunction {
/** {@inheritDoc} */
@Override
public double value(double x, double y) {
- return FastMath.pow(x, y);
+ return AccurateMath.pow(x, y);
}
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Power.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Power.java
index 584b801..91cfc58 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Power.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Power.java
@@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Power function.
@@ -40,7 +40,7 @@ public class Power implements UnivariateDifferentiableFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.pow(x, p);
+ return AccurateMath.pow(x, p);
}
/** {@inheritDoc}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Rint.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Rint.java
index 90c812c..7b81161 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Rint.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Rint.java
@@ -18,7 +18,7 @@
package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.UnivariateFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* {@code rint} function.
@@ -29,6 +29,6 @@ public class Rint implements UnivariateFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.rint(x);
+ return AccurateMath.rint(x);
}
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sigmoid.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sigmoid.java
index 1f298c4..811fb8a 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sigmoid.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sigmoid.java
@@ -24,7 +24,7 @@ import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStruct
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.NullArgumentException;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* <a href="http://en.wikipedia.org/wiki/Sigmoid_function">
@@ -114,7 +114,7 @@ public class Sigmoid implements UnivariateDifferentiableFunction {
DimensionMismatchException {
validateParameters(param);
- final double invExp1 = 1 / (1 + FastMath.exp(-x));
+ final double invExp1 = 1 / (1 + AccurateMath.exp(-x));
return new double[] { 1 - invExp1, invExp1 };
}
@@ -150,7 +150,7 @@ public class Sigmoid implements UnivariateDifferentiableFunction {
private static double value(double x,
double lo,
double hi) {
- return lo + (hi - lo) / (1 + FastMath.exp(-x));
+ return lo + (hi - lo) / (1 + AccurateMath.exp(-x));
}
/** {@inheritDoc}
@@ -161,7 +161,7 @@ public class Sigmoid implements UnivariateDifferentiableFunction {
throws DimensionMismatchException {
double[] f = new double[t.getOrder() + 1];
- final double exp = FastMath.exp(-t.getValue());
+ final double exp = AccurateMath.exp(-t.getValue());
if (Double.isInfinite(exp)) {
// special handling near lower boundary, to avoid NaN
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Signum.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Signum.java
index 858a48b..067eac3 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Signum.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Signum.java
@@ -18,7 +18,7 @@
package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.UnivariateFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* {@code signum} function.
@@ -29,6 +29,6 @@ public class Signum implements UnivariateFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.signum(x);
+ return AccurateMath.signum(x);
}
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sin.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sin.java
index ee72285..81aaedd 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sin.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sin.java
@@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Sine function.
@@ -30,7 +30,7 @@ public class Sin implements UnivariateDifferentiableFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.sin(x);
+ return AccurateMath.sin(x);
}
/** {@inheritDoc}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sinc.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sinc.java
index f23c542..a33e0da 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sinc.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sinc.java
@@ -20,7 +20,7 @@ package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* <a href="http://en.wikipedia.org/wiki/Sinc_function">Sinc</a> function,
@@ -81,14 +81,14 @@ public class Sinc implements UnivariateDifferentiableFunction {
/** {@inheritDoc} */
@Override
public double value(final double x) {
- final double scaledX = normalized ? FastMath.PI * x : x;
- if (FastMath.abs(scaledX) <= SHORTCUT) {
+ final double scaledX = normalized ? AccurateMath.PI * x : x;
+ if (AccurateMath.abs(scaledX) <= SHORTCUT) {
// use Taylor series
final double scaledX2 = scaledX * scaledX;
return ((scaledX2 - 20) * scaledX2 + 120) / 120;
} else {
// use definition expression
- return FastMath.sin(scaledX) / scaledX;
+ return AccurateMath.sin(scaledX) / scaledX;
}
}
@@ -99,12 +99,12 @@ public class Sinc implements UnivariateDifferentiableFunction {
public DerivativeStructure value(final DerivativeStructure t)
throws DimensionMismatchException {
- final double scaledX = (normalized ? FastMath.PI : 1) * t.getValue();
+ final double scaledX = (normalized ? AccurateMath.PI : 1) * t.getValue();
final double scaledX2 = scaledX * scaledX;
double[] f = new double[t.getOrder() + 1];
- if (FastMath.abs(scaledX) <= SHORTCUT) {
+ if (AccurateMath.abs(scaledX) <= SHORTCUT) {
for (int i = 0; i < f.length; ++i) {
final int k = i / 2;
@@ -122,8 +122,8 @@ public class Sinc implements UnivariateDifferentiableFunction {
} else {
final double inv = 1 / scaledX;
- final double cos = FastMath.cos(scaledX);
- final double sin = FastMath.sin(scaledX);
+ final double cos = AccurateMath.cos(scaledX);
+ final double sin = AccurateMath.sin(scaledX);
f[0] = inv * sin;
@@ -182,10 +182,10 @@ public class Sinc implements UnivariateDifferentiableFunction {
}
if (normalized) {
- double scale = FastMath.PI;
+ double scale = AccurateMath.PI;
for (int i = 1; i < f.length; ++i) {
f[i] *= scale;
- scale *= FastMath.PI;
+ scale *= AccurateMath.PI;
}
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sinh.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sinh.java
index 98e11d9..4a9a515 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sinh.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sinh.java
@@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Hyperbolic sine function.
@@ -30,7 +30,7 @@ public class Sinh implements UnivariateDifferentiableFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.sinh(x);
+ return AccurateMath.sinh(x);
}
/** {@inheritDoc}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sqrt.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sqrt.java
index 3a3da21..f8146aa 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sqrt.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sqrt.java
@@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Square-root function.
@@ -30,7 +30,7 @@ public class Sqrt implements UnivariateDifferentiableFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.sqrt(x);
+ return AccurateMath.sqrt(x);
}
/** {@inheritDoc}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/StepFunction.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/StepFunction.java
index edb5e64..d4fb09f 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/StepFunction.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/StepFunction.java
@@ -24,7 +24,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.NoDataException;
import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException;
import org.apache.commons.math4.legacy.exception.NullArgumentException;
-import org.apache.commons.math4.legacy.util.MathArrays;
+import org.apache.commons.math4.legacy.core.MathArrays;
/**
* <a href="http://en.wikipedia.org/wiki/Step_function">
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Tan.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Tan.java
index b79bbbe..5fa6f4f 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Tan.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Tan.java
@@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Tangent function.
@@ -30,7 +30,7 @@ public class Tan implements UnivariateDifferentiableFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.tan(x);
+ return AccurateMath.tan(x);
}
/** {@inheritDoc}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Tanh.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Tanh.java
index 6972626..26f8016 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Tanh.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Tanh.java
@@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Hyperbolic tangent function.
@@ -30,7 +30,7 @@ public class Tanh implements UnivariateDifferentiableFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.tanh(x);
+ return AccurateMath.tanh(x);
}
/** {@inheritDoc}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Ulp.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Ulp.java
index 5a193c9..8400240 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Ulp.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Ulp.java
@@ -18,7 +18,7 @@
package org.apache.commons.math4.legacy.analysis.function;
import org.apache.commons.math4.legacy.analysis.UnivariateFunction;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* {@code ulp} function.
@@ -29,6 +29,6 @@ public class Ulp implements UnivariateFunction {
/** {@inheritDoc} */
@Override
public double value(double x) {
- return FastMath.ulp(x);
+ return AccurateMath.ulp(x);
}
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/IterativeLegendreGaussIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/IterativeLegendreGaussIntegrator.java
index e768c6e..e9011bc 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/IterativeLegendreGaussIntegrator.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/IterativeLegendreGaussIntegrator.java
@@ -22,7 +22,7 @@ import org.apache.commons.math4.legacy.analysis.integration.gauss.GaussIntegrato
import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException;
import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* This algorithm divides the integration interval into equally-sized
@@ -122,10 +122,10 @@ public class IterativeLegendreGaussIntegrator
final double t = stage(n);
// Estimate the error.
- final double delta = FastMath.abs(t - oldt);
+ final double delta = AccurateMath.abs(t - oldt);
final double limit =
- FastMath.max(getAbsoluteAccuracy(),
- getRelativeAccuracy() * (FastMath.abs(oldt) + FastMath.abs(t)) * 0.5);
+ AccurateMath.max(getAbsoluteAccuracy(),
+ getRelativeAccuracy() * (AccurateMath.abs(oldt) + AccurateMath.abs(t)) * 0.5);
// check convergence
if (iterations.getCount() + 1 >= getMinimalIterationCount() &&
@@ -134,8 +134,8 @@ public class IterativeLegendreGaussIntegrator
}
// Prepare next iteration.
- final double ratio = FastMath.min(4, FastMath.pow(delta / limit, 0.5 / numberOfPoints));
- n = FastMath.max((int) (ratio * n), n + 1);
+ final double ratio = AccurateMath.min(4, AccurateMath.pow(delta / limit, 0.5 / numberOfPoints));
+ n = AccurateMath.max((int) (ratio * n), n + 1);
oldt = t;
iterations.increment();
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/MidPointIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/MidPointIntegrator.java
index e748425..3066851 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/MidPointIntegrator.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/MidPointIntegrator.java
@@ -17,7 +17,7 @@
package org.apache.commons.math4.legacy.analysis.integration;
import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Implements the <a href="https://en.wikipedia.org/wiki/Riemann_sum#Midpoint_rule">
@@ -113,7 +113,7 @@ public class MidPointIntegrator extends BaseAbstractUnivariateIntegrator {
double diffMaxMin) {
// number of points in the previous stage. This stage will contribute
// 2*3^{n-1} more points.
- final long np = (long) FastMath.pow(3, n - 1);
+ final long np = (long) AccurateMath.pow(3, n - 1);
double sum = 0;
// spacing between adjacent new points
@@ -151,9 +151,9 @@ public class MidPointIntegrator extends BaseAbstractUnivariateIntegrator {
final int i = iterations.getCount();
final double t = stage(i, oldt, min, diff);
if (i >= getMinimalIterationCount()) {
- final double delta = FastMath.abs(t - oldt);
+ final double delta = AccurateMath.abs(t - oldt);
final double rLimit =
- getRelativeAccuracy() * (FastMath.abs(oldt) + FastMath.abs(t)) * 0.5;
+ getRelativeAccuracy() * (AccurateMath.abs(oldt) + AccurateMath.abs(t)) * 0.5;
if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) {
return t;
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/RombergIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/RombergIntegrator.java
index c2c6aa6..771a7b8 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/RombergIntegrator.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/RombergIntegrator.java
@@ -17,7 +17,7 @@
package org.apache.commons.math4.legacy.analysis.integration;
import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Implements the <a href="http://mathworld.wolfram.com/RombergIntegration.html">
@@ -120,8 +120,8 @@ public class RombergIntegrator extends BaseAbstractUnivariateIntegrator {
}
final double s = currentRow[i];
if (i >= getMinimalIterationCount()) {
- final double delta = FastMath.abs(s - olds);
- final double rLimit = getRelativeAccuracy() * (FastMath.abs(olds) + FastMath.abs(s)) * 0.5;
+ final double delta = AccurateMath.abs(s - olds);
+ final double rLimit = getRelativeAccuracy() * (AccurateMath.abs(olds) + AccurateMath.abs(s)) * 0.5;
if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) {
return s;
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/SimpsonIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/SimpsonIntegrator.java
index caf36d7..26630aa 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/SimpsonIntegrator.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/SimpsonIntegrator.java
@@ -17,7 +17,7 @@
package org.apache.commons.math4.legacy.analysis.integration;
import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Implements <a href="http://mathworld.wolfram.com/SimpsonsRule.html">
@@ -106,8 +106,8 @@ public class SimpsonIntegrator extends BaseAbstractUnivariateIntegrator {
final double t = qtrap.stage(this, i + 1); // 1-stage ahead of the iteration
final double s = (4 * t - oldt) / 3.0;
if (i >= getMinimalIterationCount()) {
- final double delta = FastMath.abs(s - olds);
- final double rLimit = getRelativeAccuracy() * (FastMath.abs(olds) + FastMath.abs(s)) * 0.5;
+ final double delta = AccurateMath.abs(s - olds);
+ final double rLimit = getRelativeAccuracy() * (AccurateMath.abs(olds) + AccurateMath.abs(s)) * 0.5;
if (delta <= rLimit ||
delta <= getAbsoluteAccuracy()) {
return s;
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/TrapezoidIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/TrapezoidIntegrator.java
index 7f7fa6e..ed1176f 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/TrapezoidIntegrator.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/TrapezoidIntegrator.java
@@ -17,7 +17,7 @@
package org.apache.commons.math4.legacy.analysis.integration;
import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Implements the <a href="http://mathworld.wolfram.com/TrapezoidalRule.html">
@@ -139,9 +139,9 @@ public class TrapezoidIntegrator extends BaseAbstractUnivariateIntegrator {
final int i = iterations.getCount();
final double t = stage(this, i);
if (i >= getMinimalIterationCount()) {
- final double delta = FastMath.abs(t - oldt);
+ final double delta = AccurateMath.abs(t - oldt);
final double rLimit =
- getRelativeAccuracy() * (FastMath.abs(oldt) + FastMath.abs(t)) * 0.5;
+ getRelativeAccuracy() * (AccurateMath.abs(oldt) + AccurateMath.abs(t)) * 0.5;
if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) {
return t;
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/gauss/GaussIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/gauss/GaussIntegrator.java
index 967ca87..616b48b 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/gauss/GaussIntegrator.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/gauss/GaussIntegrator.java
@@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.integration.gauss;
import org.apache.commons.math4.legacy.analysis.UnivariateFunction;
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
-import org.apache.commons.math4.legacy.util.MathArrays;
+import org.apache.commons.math4.legacy.core.MathArrays;
import org.apache.commons.math4.legacy.util.Pair;
/**
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/gauss/HermiteRuleFactory.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/gauss/HermiteRuleFactory.java
index 76cd4ca..edc5a94 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/gauss/HermiteRuleFactory.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/gauss/HermiteRuleFactory.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.math4.legacy.analysis.integration.gauss;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
import org.apache.commons.math4.legacy.util.Pair;
/**
@@ -74,8 +74,8 @@ public class HermiteRuleFactory extends BaseRuleFactory<Double> {
final Double[] points = new Double[numberOfPoints];
final Double[] weights = new Double[numberOfPoints];
- final double sqrtTwoTimesLastNumPoints = FastMath.sqrt(2 * lastNumPoints);
- final double sqrtTwoTimesNumPoints = FastMath.sqrt(2 * numberOfPoints);
+ final double sqrtTwoTimesLastNumPoints = AccurateMath.sqrt(2 * lastNumPoints);
+ final double sqrtTwoTimesNumPoints = AccurateMath.sqrt(2 * numberOfPoints);
// Find i-th root of H[n+1] by bracketing.
final int iMax = numberOfPoints / 2;
@@ -96,8 +96,8 @@ public class HermiteRuleFactory extends BaseRuleFactory<Double> {
for (int j = 1; j < numberOfPoints; j++) {
// Compute H[j+1](a) and H[j+1](b)
final double jp1 = j + 1;
- final double s = FastMath.sqrt(2 / jp1);
- final double sm = FastMath.sqrt(j / jp1);
+ final double s = AccurateMath.sqrt(2 / jp1);
+ final double sm = AccurateMath.sqrt(j / jp1);
final double hpa = s * a * ha - sm * hma;
final double hpb = s * b * hb - sm * hmb;
hma = ha;
@@ -121,8 +121,8 @@ public class HermiteRuleFactory extends BaseRuleFactory<Double> {
for (int j = 1; j < numberOfPoints; j++) {
// Compute H[j+1](c)
final double jp1 = j + 1;
- final double s = FastMath.sqrt(2 / jp1);
- final double sm = FastMath.sqrt(j / jp1);
+ final double s = AccurateMath.sqrt(2 / jp1);
+ final double sm = AccurateMath.sqrt(j / jp1);
final double hpc = s * c * hc - sm * hmc;
hmc = hc;
hc = hpc;
@@ -160,7 +160,7 @@ public class HermiteRuleFactory extends BaseRuleFactory<Double> {
double hm = H0;
for (int j = 1; j < numberOfPoints; j += 2) {
final double jp1 = j + 1;
- hm = -FastMath.sqrt(j / jp1) * hm;
+ hm = -AccurateMath.sqrt(j / jp1) * hm;
}
final double d = sqrtTwoTimesNumPoints * hm;
final double w = 2 / (d * d);
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/AkimaSplineInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/AkimaSplineInterpolator.java
index d24e45d..2d1520d 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/AkimaSplineInterpolator.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/AkimaSplineInterpolator.java
@@ -23,8 +23,8 @@ import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException;
import org.apache.commons.math4.legacy.exception.NullArgumentException;
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
-import org.apache.commons.math4.legacy.util.FastMath;
-import org.apache.commons.math4.legacy.util.MathArrays;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
+import org.apache.commons.math4.legacy.core.MathArrays;
import org.apache.commons.numbers.core.Precision;
/**
@@ -123,11 +123,11 @@ public class AkimaSplineInterpolator
for (int i = 1; i < weights.length; i++) {
final double a = differences[i];
final double b = differences[i - 1];
- weights[i] = FastMath.abs(a - b) + 0.5 * FastMath.abs(a + b);
+ weights[i] = AccurateMath.abs(a - b) + 0.5 * AccurateMath.abs(a + b);
}
} else {
for (int i = 1; i < weights.length; i++) {
- weights[i] = FastMath.abs(differences[i] - differences[i - 1]);
+ weights[i] = AccurateMath.abs(differences[i] - differences[i - 1]);
}
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/BicubicInterpolatingFunction.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/BicubicInterpolatingFunction.java
index 62c9861..faf4ce5 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/BicubicInterpolatingFunction.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/BicubicInterpolatingFunction.java
@@ -24,7 +24,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.NoDataException;
import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException;
import org.apache.commons.math4.legacy.exception.OutOfRangeException;
-import org.apache.commons.math4.legacy.util.MathArrays;
+import org.apache.commons.math4.legacy.core.MathArrays;
/**
* Function that implements the
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/BicubicInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/BicubicInterpolator.java
index 60016a5..97a6b89 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/BicubicInterpolator.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/BicubicInterpolator.java
@@ -20,7 +20,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.NoDataException;
import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException;
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
-import org.apache.commons.math4.legacy.util.MathArrays;
+import org.apache.commons.math4.legacy.core.MathArrays;
/**
* Generates a {@link BicubicInterpolatingFunction bicubic interpolating
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/FieldHermiteInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/FieldHermiteInterpolator.java
index b5c3528..587bedd 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/FieldHermiteInterpolator.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/FieldHermiteInterpolator.java
@@ -19,14 +19,14 @@ package org.apache.commons.math4.legacy.analysis.interpolation;
import java.util.ArrayList;
import java.util.List;
-import org.apache.commons.math4.legacy.FieldElement;
+import org.apache.commons.math4.legacy.core.FieldElement;
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.MathArithmeticException;
import org.apache.commons.math4.legacy.exception.NoDataException;
import org.apache.commons.math4.legacy.exception.NullArgumentException;
import org.apache.commons.math4.legacy.exception.ZeroException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
-import org.apache.commons.math4.legacy.util.MathArrays;
+import org.apache.commons.math4.legacy.core.MathArrays;
/** Polynomial interpolator using both sample values and sample derivatives.
* <p>
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere.java
index 9134d0d..525cc21 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere.java
@@ -26,8 +26,8 @@ import org.apache.commons.math4.legacy.exception.NotPositiveException;
import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException;
import org.apache.commons.math4.legacy.exception.MaxCountExceededException;
import org.apache.commons.math4.legacy.exception.OutOfRangeException;
-import org.apache.commons.math4.legacy.util.FastMath;
-import org.apache.commons.math4.legacy.util.MathArrays;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
+import org.apache.commons.math4.legacy.core.MathArrays;
/**
* Utility class for the {@link MicrosphereProjectionInterpolator} algorithm.
@@ -224,13 +224,13 @@ public class InterpolatingMicrosphere {
final double[] diff = MathArrays.ebeSubtract(samplePoints[i], point);
final double diffNorm = SafeNorm.value(diff);
- if (FastMath.abs(diffNorm) < noInterpolationTolerance) {
+ if (AccurateMath.abs(diffNorm) < noInterpolationTolerance) {
// No need to interpolate, as the interpolation point is
// actually (very close to) one of the sampled points.
return sampleValues[i];
}
- final double weight = FastMath.pow(diffNorm, -exponent);
+ final double weight = AccurateMath.pow(diffNorm, -exponent);
illuminate(diff, sampleValues[i], weight);
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere2D.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere2D.java
index 64af4fc..e0db5d6 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere2D.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere2D.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.math4.legacy.analysis.interpolation;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
import org.apache.commons.numbers.angle.PlaneAngleRadians;
/**
@@ -60,8 +60,8 @@ public class InterpolatingMicrosphere2D extends InterpolatingMicrosphere {
for (int i = 0; i < size; i++) {
final double angle = i * PlaneAngleRadians.TWO_PI / size;
- add(new double[] { FastMath.cos(angle),
- FastMath.sin(angle) },
+ add(new double[] { AccurateMath.cos(angle),
+ AccurateMath.sin(angle) },
false);
}
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/LinearInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/LinearInterpolator.java
index aece388..a2679df 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/LinearInterpolator.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/LinearInterpolator.java
@@ -22,7 +22,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException;
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
-import org.apache.commons.math4.legacy.util.MathArrays;
+import org.apache.commons.math4.legacy.core.MathArrays;
/**
* Implements a linear function for interpolation of real univariate functions.
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/LoessInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/LoessInterpolator.java
index c56955c..37557aa 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/LoessInterpolator.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/LoessInterpolator.java
@@ -28,8 +28,8 @@ import org.apache.commons.math4.legacy.exception.NotPositiveException;
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
import org.apache.commons.math4.legacy.exception.OutOfRangeException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
-import org.apache.commons.math4.legacy.util.FastMath;
-import org.apache.commons.math4.legacy.util.MathArrays;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
+import org.apache.commons.math4.legacy.core.MathArrays;
/**
* Implements the <a href="http://en.wikipedia.org/wiki/Local_regression">
@@ -296,7 +296,7 @@ public class LoessInterpolator
double sumXSquared = 0;
double sumY = 0;
double sumXY = 0;
- double denom = FastMath.abs(1.0 / (xval[edge] - x));
+ double denom = AccurateMath.abs(1.0 / (xval[edge] - x));
for (int k = ileft; k <= iright; ++k) {
final double xk = xval[k];
final double yk = yval[k];
@@ -316,7 +316,7 @@ public class LoessInterpolator
final double meanXSquared = sumXSquared / sumWeights;
final double beta;
- if (FastMath.sqrt(FastMath.abs(meanXSquared - meanX * meanX)) < accuracy) {
+ if (AccurateMath.sqrt(AccurateMath.abs(meanXSquared - meanX * meanX)) < accuracy) {
beta = 0;
} else {
beta = (meanXY - meanX * meanY) / (meanXSquared - meanX * meanX);
@@ -325,7 +325,7 @@ public class LoessInterpolator
final double alpha = meanY - beta * meanX;
res[i] = beta * x + alpha;
- residuals[i] = FastMath.abs(yval[i] - res[i]);
+ residuals[i] = AccurateMath.abs(yval[i] - res[i]);
}
// No need to recompute the robustness weights at the last
@@ -343,7 +343,7 @@ public class LoessInterpolator
Arrays.sort(sortedResiduals);
final double medianResidual = sortedResiduals[n / 2];
- if (FastMath.abs(medianResidual) < accuracy) {
+ if (AccurateMath.abs(medianResidual) < accuracy) {
break;
}
@@ -450,7 +450,7 @@ public class LoessInterpolator
* @return <code>(1 - |x|<sup>3</sup>)<sup>3</sup></code> for |x| < 1, 0 otherwise.
*/
private static double tricube(final double x) {
- final double absX = FastMath.abs(x);
+ final double absX = AccurateMath.abs(x);
if (absX >= 1.0) {
return 0.0;
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/PiecewiseBicubicSplineInterpolatingFunction.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/PiecewiseBicubicSplineInterpolatingFunction.java
index 26d040d..31e0c52 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/PiecewiseBicubicSplineInterpolatingFunction.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/PiecewiseBicubicSplineInterpolatingFunction.java
@@ -26,7 +26,7 @@ import org.apache.commons.math4.legacy.exception.NoDataException;
import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException;
import org.apache.commons.math4.legacy.exception.NullArgumentException;
import org.apache.commons.math4.legacy.exception.OutOfRangeException;
-import org.apache.commons.math4.legacy.util.MathArrays;
+import org.apache.commons.math4.legacy.core.MathArrays;
/**
* Function that implements the
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/PiecewiseBicubicSplineInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/PiecewiseBicubicSplineInterpolator.java
index 09797cc..09f91a3 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/PiecewiseBicubicSplineInterpolator.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/PiecewiseBicubicSplineInterpolator.java
@@ -20,7 +20,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.NoDataException;
import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException;
import org.apache.commons.math4.legacy.exception.NullArgumentException;
-import org.apache.commons.math4.legacy.util.MathArrays;
+import org.apache.commons.math4.legacy.core.MathArrays;
/**
* Generates a piecewise-bicubic interpolating function.
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/SplineInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/SplineInterpolator.java
index 4999219..be313dd 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/SplineInterpolator.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/SplineInterpolator.java
@@ -22,7 +22,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException;
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
-import org.apache.commons.math4.legacy.util.MathArrays;
+import org.apache.commons.math4.legacy.core.MathArrays;
/**
* Computes a natural (also known as "free", "unclamped") cubic spline interpolation for the data set.
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/TricubicInterpolatingFunction.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/TricubicInterpolatingFunction.java
index 94f0a46..0977eb8 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/TricubicInterpolatingFunction.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/TricubicInterpolatingFunction.java
@@ -21,7 +21,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.NoDataException;
import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException;
import org.apache.commons.math4.legacy.exception.OutOfRangeException;
-import org.apache.commons.math4.legacy.util.MathArrays;
+import org.apache.commons.math4.legacy.core.MathArrays;
/**
* Function that implements the
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/TricubicInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/TricubicInterpolator.java
index 2159c4b..0ff84eb 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/TricubicInterpolator.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/TricubicInterpolator.java
@@ -20,7 +20,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.NoDataException;
import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException;
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
-import org.apache.commons.math4.legacy.util.MathArrays;
+import org.apache.commons.math4.legacy.core.MathArrays;
/**
* Generates a tricubic interpolating function.
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/UnivariatePeriodicInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/UnivariatePeriodicInterpolator.java
index 3b6bdec..ee1618a 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/UnivariatePeriodicInterpolator.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/UnivariatePeriodicInterpolator.java
@@ -22,7 +22,7 @@ import org.apache.commons.math4.legacy.analysis.UnivariateFunction;
import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException;
import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException;
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
-import org.apache.commons.math4.legacy.util.MathArrays;
+import org.apache.commons.math4.legacy.core.MathArrays;
/**
* Adapter for classes implementing the {@link UnivariateInterpolator}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunction.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunction.java
index 9d8068f..29f7dc6 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunction.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunction.java
@@ -25,7 +25,7 @@ import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDiffer
import org.apache.commons.math4.legacy.exception.NoDataException;
import org.apache.commons.math4.legacy.exception.NullArgumentException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Immutable representation of a real polynomial function with real coefficients.
@@ -167,8 +167,8 @@ public class PolynomialFunction implements UnivariateDifferentiableFunction, Ser
*/
public PolynomialFunction add(final PolynomialFunction p) {
// identify the lowest degree polynomial
- final int lowLength = FastMath.min(coefficients.length, p.coefficients.length);
- final int highLength = FastMath.max(coefficients.length, p.coefficients.length);
+ final int lowLength = AccurateMath.min(coefficients.length, p.coefficients.length);
+ final int highLength = AccurateMath.max(coefficients.length, p.coefficients.length);
// build the coefficients array
double[] newCoefficients = new double[highLength];
@@ -192,8 +192,8 @@ public class PolynomialFunction implements UnivariateDifferentiableFunction, Ser
*/
public PolynomialFunction subtract(final PolynomialFunction p) {
// identify the lowest degree polynomial
- int lowLength = FastMath.min(coefficients.length, p.coefficients.length);
- int highLength = FastMath.max(coefficients.length, p.coefficients.length);
+ int lowLength = AccurateMath.min(coefficients.length, p.coefficients.length);
+ int highLength = AccurateMath.max(coefficients.length, p.coefficients.length);
// build the coefficients array
double[] newCoefficients = new double[highLength];
@@ -236,8 +236,8 @@ public class PolynomialFunction implements UnivariateDifferentiableFunction, Ser
for (int i = 0; i < newCoefficients.length; ++i) {
newCoefficients[i] = 0.0;
- for (int j = FastMath.max(0, i + 1 - p.coefficients.length);
- j < FastMath.min(coefficients.length, i + 1);
+ for (int j = AccurateMath.max(0, i + 1 - p.coefficients.length);
+ j < AccurateMath.min(coefficients.length, i + 1);
++j) {
newCoefficients[i] += coefficients[j] * p.coefficients[i-j];
}
@@ -320,7 +320,7 @@ public class PolynomialFunction implements UnivariateDifferentiableFunction, Ser
}
}
- double absAi = FastMath.abs(coefficients[i]);
+ double absAi = AccurateMath.abs(coefficients[i]);
if ((absAi - 1) != 0) {
s.append(toString(absAi));
s.append(' ');
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunctionLagrangeForm.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunctionLagrangeForm.java
index 55f70c0..e376e2f 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunctionLagrangeForm.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunctionLagrangeForm.java
@@ -21,8 +21,8 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException;
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
-import org.apache.commons.math4.legacy.util.FastMath;
-import org.apache.commons.math4.legacy.util.MathArrays;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
+import org.apache.commons.math4.legacy.core.MathArrays;
/**
* Implements the representation of a real polynomial function in
@@ -215,7 +215,7 @@ public class PolynomialFunctionLagrangeForm implements UnivariateFunction {
c[i] = y[i];
d[i] = y[i];
// find out the abscissa closest to z
- final double dist = FastMath.abs(z - x[i]);
+ final double dist = AccurateMath.abs(z - x[i]);
if (dist < min_dist) {
nearest = i;
min_dist = dist;
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialSplineFunction.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialSplineFunction.java
index 89f576d..e232c97 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialSplineFunction.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialSplineFunction.java
@@ -26,7 +26,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException;
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
import org.apache.commons.math4.legacy.exception.OutOfRangeException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
-import org.apache.commons.math4.legacy.util.MathArrays;
+import org.apache.commons.math4.legacy.core.MathArrays;
/**
* Represents a polynomial spline function.
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialsUtils.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialsUtils.java
index 2a1958a..6497c73 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialsUtils.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialsUtils.java
@@ -23,7 +23,7 @@ import java.util.Map;
import org.apache.commons.numbers.fraction.BigFraction;
import org.apache.commons.numbers.combinatorics.BinomialCoefficient;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* A collection of static methods that operate on or return polynomials.
@@ -341,7 +341,7 @@ public class PolynomialsUtils {
// First polynomial coefficient.
for (int i = 0; i < dp1; i++){
- newCoefficients[0] += coefficients[i] * FastMath.pow(shift, i);
+ newCoefficients[0] += coefficients[i] * AccurateMath.pow(shift, i);
}
// Superior order.
@@ -349,7 +349,7 @@ public class PolynomialsUtils {
for (int i = 0; i < d; i++) {
for (int j = i; j < d; j++){
newCoefficients[i + 1] += coeff[j + 1][j - i] *
- coefficients[j + 1] * FastMath.pow(shift, j - i);
+ coefficients[j + 1] * AccurateMath.pow(shift, j - i);
}
}
@@ -368,7 +368,7 @@ public class PolynomialsUtils {
final RecurrenceCoefficientsGenerator generator) {
synchronized (coefficients) {
- final int maxDegree = (int) FastMath.floor(FastMath.sqrt(2 * coefficients.size())) - 1;
+ final int maxDegree = (int) AccurateMath.floor(AccurateMath.sqrt(2 * coefficients.size())) - 1;
if (degree > maxDegree) {
computeUpToDegree(degree, maxDegree, generator, coefficients);
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BaseSecantSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BaseSecantSolver.java
index a9e81f3..8f952e1 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BaseSecantSolver.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BaseSecantSolver.java
@@ -20,7 +20,7 @@ package org.apache.commons.math4.legacy.analysis.solvers;
import org.apache.commons.math4.legacy.analysis.UnivariateFunction;
import org.apache.commons.math4.legacy.exception.ConvergenceException;
import org.apache.commons.math4.legacy.exception.MathInternalError;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Base class for all bracketing <em>Secant</em>-based methods for root-finding
@@ -210,7 +210,7 @@ public abstract class BaseSecantSolver
// If the function value of the last approximation is too small,
// given the function value accuracy, then we can't get closer to
// the root than we already are.
- if (FastMath.abs(f1) <= ftol) {
+ if (AccurateMath.abs(f1) <= ftol) {
switch (allowed) {
case ANY_SIDE:
return x1;
@@ -241,7 +241,7 @@ public abstract class BaseSecantSolver
// If the current interval is within the given accuracies, we
// are satisfied with the current approximation.
- if (FastMath.abs(x1 - x0) < FastMath.max(rtol * FastMath.abs(x1),
+ if (AccurateMath.abs(x1 - x0) < AccurateMath.max(rtol * AccurateMath.abs(x1),
atol)) {
switch (allowed) {
case ANY_SIDE:
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BisectionSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BisectionSolver.java
index 8799e4f..ff0290c 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BisectionSolver.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BisectionSolver.java
@@ -17,7 +17,7 @@
package org.apache.commons.math4.legacy.analysis.solvers;
import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Implements the <a href="http://mathworld.wolfram.com/Bisection.html">
@@ -82,7 +82,7 @@ public class BisectionSolver extends AbstractUnivariateSolver {
max = m;
}
- if (FastMath.abs(max - min) <= absoluteAccuracy) {
+ if (AccurateMath.abs(max - min) <= absoluteAccuracy) {
m = UnivariateSolverUtils.midpoint(min, max);
return m;
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BracketedRealFieldUnivariateSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BracketedRealFieldUnivariateSolver.java
index 4e3cdd9..623dee7 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BracketedRealFieldUnivariateSolver.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BracketedRealFieldUnivariateSolver.java
@@ -17,7 +17,7 @@
package org.apache.commons.math4.legacy.analysis.solvers;
-import org.apache.commons.math4.legacy.RealFieldElement;
+import org.apache.commons.math4.legacy.core.RealFieldElement;
import org.apache.commons.math4.legacy.analysis.RealFieldUnivariateFunction;
/** Interface for {@link UnivariateSolver (univariate real) root-finding
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BracketingNthOrderBrentSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BracketingNthOrderBrentSolver.java
index cb54e98..3bad262 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BracketingNthOrderBrentSolver.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BracketingNthOrderBrentSolver.java
@@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.exception.NoBracketingException;
import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
import org.apache.commons.numbers.core.Precision;
/**
@@ -199,11 +199,11 @@ public class BracketingNthOrderBrentSolver
// current tightest bracketing of the root
double xA = x[signChangeIndex - 1];
double yA = y[signChangeIndex - 1];
- double absYA = FastMath.abs(yA);
+ double absYA = AccurateMath.abs(yA);
int agingA = 0;
double xB = x[signChangeIndex];
double yB = y[signChangeIndex];
- double absYB = FastMath.abs(yB);
+ double absYB = AccurateMath.abs(yB);
int agingB = 0;
// search loop
@@ -211,8 +211,8 @@ public class BracketingNthOrderBrentSolver
// check convergence of bracketing interval
final double xTol = getAbsoluteAccuracy() +
- getRelativeAccuracy() * FastMath.max(FastMath.abs(xA), FastMath.abs(xB));
- if (((xB - xA) <= xTol) || (FastMath.max(absYA, absYB) < getFunctionValueAccuracy())) {
+ getRelativeAccuracy() * AccurateMath.max(AccurateMath.abs(xA), AccurateMath.abs(xB));
+ if (((xB - xA) <= xTol) || (AccurateMath.max(absYA, absYB) < getFunctionValueAccuracy())) {
switch (allowed) {
case ANY_SIDE :
return absYA < absYB ? xA : xB;
@@ -332,14 +332,14 @@ public class BracketingNthOrderBrentSolver
// the sign change occurs before the inserted point
xB = nextX;
yB = nextY;
- absYB = FastMath.abs(yB);
+ absYB = AccurateMath.abs(yB);
++agingA;
agingB = 0;
} else {
// the sign change occurs after the inserted point
xA = nextX;
yA = nextY;
- absYA = FastMath.abs(yA);
+ absYA = AccurateMath.abs(yA);
agingA = 0;
++agingB;
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/FieldBracketingNthOrderBrentSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/FieldBracketingNthOrderBrentSolver.java
index 9d5de5e..05d0ef0 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/FieldBracketingNthOrderBrentSolver.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/FieldBracketingNthOrderBrentSolver.java
@@ -17,15 +17,15 @@
package org.apache.commons.math4.legacy.analysis.solvers;
-import org.apache.commons.math4.legacy.Field;
-import org.apache.commons.math4.legacy.RealFieldElement;
+import org.apache.commons.math4.legacy.core.Field;
+import org.apache.commons.math4.legacy.core.RealFieldElement;
import org.apache.commons.math4.legacy.analysis.RealFieldUnivariateFunction;
import org.apache.commons.math4.legacy.exception.MathInternalError;
import org.apache.commons.math4.legacy.exception.NoBracketingException;
import org.apache.commons.math4.legacy.exception.NullArgumentException;
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
import org.apache.commons.math4.legacy.util.IntegerSequence;
-import org.apache.commons.math4.legacy.util.MathArrays;
+import org.apache.commons.math4.legacy.core.MathArrays;
import org.apache.commons.numbers.core.Precision;
/**
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/LaguerreSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/LaguerreSolver.java
index 4de3ca1..0f8b4ad 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/LaguerreSolver.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/LaguerreSolver.java
@@ -25,7 +25,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException;
import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Implements the <a href="http://mathworld.wolfram.com/LaguerresMethod.html">
@@ -101,13 +101,13 @@ public class LaguerreSolver extends AbstractPolynomialSolver {
// Return the initial guess if it is good enough.
final double yInitial = computeObjectiveValue(initial);
- if (FastMath.abs(yInitial) <= functionValueAccuracy) {
+ if (AccurateMath.abs(yInitial) <= functionValueAccuracy) {
return initial;
}
// Return the first endpoint if it is good enough.
final double yMin = computeObjectiveValue(min);
- if (FastMath.abs(yMin) <= functionValueAccuracy) {
+ if (AccurateMath.abs(yMin) <= functionValueAccuracy) {
return min;
}
@@ -118,7 +118,7 @@ public class LaguerreSolver extends AbstractPolynomialSolver {
// Return the second endpoint if it is good enough.
final double yMax = computeObjectiveValue(max);
- if (FastMath.abs(yMax) <= functionValueAccuracy) {
+ if (AccurateMath.abs(yMax) <= functionValueAccuracy) {
return max;
}
@@ -242,8 +242,8 @@ public class LaguerreSolver extends AbstractPolynomialSolver {
*/
public boolean isRoot(double min, double max, Complex z) {
if (isSequence(min, z.getReal(), max)) {
- double tolerance = FastMath.max(getRelativeAccuracy() * z.abs(), getAbsoluteAccuracy());
- return (FastMath.abs(z.getImaginary()) <= tolerance) ||
+ double tolerance = AccurateMath.max(getRelativeAccuracy() * z.abs(), getAbsoluteAccuracy());
+ return (AccurateMath.abs(z.getImaginary()) <= tolerance) ||
(z.abs() <= getFunctionValueAccuracy());
}
return false;
@@ -348,7 +348,7 @@ public class LaguerreSolver extends AbstractPolynomialSolver {
d2v = d2v.multiply(Complex.ofCartesian(2.0, 0.0));
// Check for convergence.
- final double tolerance = FastMath.max(relativeAccuracy * z.abs(),
+ final double tolerance = AccurateMath.max(relativeAccuracy * z.abs(),
absoluteAccuracy);
if ((z.subtract(oldz)).abs() <= tolerance) {
return z;
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/MullerSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/MullerSolver.java
index f8ae70e..ac262cc 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/MullerSolver.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/MullerSolver.java
@@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.solvers;
import org.apache.commons.math4.legacy.exception.NoBracketingException;
import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* This class implements the <a href="http://mathworld.wolfram.com/MullersMethod.html">
@@ -94,15 +94,15 @@ public class MullerSolver extends AbstractUnivariateSolver {
// check for zeros before verifying bracketing
final double fMin = computeObjectiveValue(min);
- if (FastMath.abs(fMin) < functionValueAccuracy) {
+ if (AccurateMath.abs(fMin) < functionValueAccuracy) {
return min;
}
final double fMax = computeObjectiveValue(max);
- if (FastMath.abs(fMax) < functionValueAccuracy) {
+ if (AccurateMath.abs(fMax) < functionValueAccuracy) {
return max;
}
final double fInitial = computeObjectiveValue(initial);
- if (FastMath.abs(fInitial) < functionValueAccuracy) {
+ if (AccurateMath.abs(fInitial) < functionValueAccuracy) {
return initial;
}
@@ -156,17 +156,17 @@ public class MullerSolver extends AbstractUnivariateSolver {
final double d012 = (d12 - d01) / (x2 - x0);
final double c1 = d01 + (x1 - x0) * d012;
final double delta = c1 * c1 - 4 * y1 * d012;
- final double xplus = x1 + (-2.0 * y1) / (c1 + FastMath.sqrt(delta));
- final double xminus = x1 + (-2.0 * y1) / (c1 - FastMath.sqrt(delta));
+ final double xplus = x1 + (-2.0 * y1) / (c1 + AccurateMath.sqrt(delta));
+ final double xminus = x1 + (-2.0 * y1) / (c1 - AccurateMath.sqrt(delta));
// xplus and xminus are two roots of parabola and at least
// one of them should lie in (x0, x2)
final double x = isSequence(x0, xplus, x2) ? xplus : xminus;
final double y = computeObjectiveValue(x);
// check for convergence
- final double tolerance = FastMath.max(relativeAccuracy * FastMath.abs(x), absoluteAccuracy);
- if (FastMath.abs(x - oldx) <= tolerance ||
- FastMath.abs(y) <= functionValueAccuracy) {
+ final double tolerance = AccurateMath.max(relativeAccuracy * AccurateMath.abs(x), absoluteAccuracy);
+ if (AccurateMath.abs(x - oldx) <= tolerance ||
+ AccurateMath.abs(y) <= functionValueAccuracy) {
return x;
}
@@ -188,7 +188,7 @@ public class MullerSolver extends AbstractUnivariateSolver {
} else {
double xm = 0.5 * (x0 + x2);
double ym = computeObjectiveValue(xm);
- if (FastMath.signum(y0) + FastMath.signum(ym) == 0.0) {
+ if (AccurateMath.signum(y0) + AccurateMath.signum(ym) == 0.0) {
x2 = xm; y2 = ym;
} else {
x0 = xm; y0 = ym;
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/MullerSolver2.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/MullerSolver2.java
index 9ab450e..e137ef8 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/MullerSolver2.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/MullerSolver2.java
@@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.solvers;
import org.apache.commons.math4.legacy.exception.NoBracketingException;
import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* This class implements the <a href="http://mathworld.wolfram.com/MullersMethod.html">
@@ -99,12 +99,12 @@ public class MullerSolver2 extends AbstractUnivariateSolver {
double x0 = min;
double y0 = computeObjectiveValue(x0);
- if (FastMath.abs(y0) < functionValueAccuracy) {
+ if (AccurateMath.abs(y0) < functionValueAccuracy) {
return x0;
}
double x1 = max;
double y1 = computeObjectiveValue(x1);
- if (FastMath.abs(y1) < functionValueAccuracy) {
+ if (AccurateMath.abs(y1) < functionValueAccuracy) {
return x1;
}
@@ -127,12 +127,12 @@ public class MullerSolver2 extends AbstractUnivariateSolver {
final double denominator;
if (delta >= 0.0) {
// choose a denominator larger in magnitude
- double dplus = b + FastMath.sqrt(delta);
- double dminus = b - FastMath.sqrt(delta);
- denominator = FastMath.abs(dplus) > FastMath.abs(dminus) ? dplus : dminus;
+ double dplus = b + AccurateMath.sqrt(delta);
+ double dminus = b - AccurateMath.sqrt(delta);
+ denominator = AccurateMath.abs(dplus) > AccurateMath.abs(dminus) ? dplus : dminus;
} else {
- // take the modulus of (B +/- FastMath.sqrt(delta))
- denominator = FastMath.sqrt(b * b - delta);
+ // take the modulus of (B +/- AccurateMath.sqrt(delta))
+ denominator = AccurateMath.sqrt(b * b - delta);
}
if (denominator != 0) {
x = x2 - 2.0 * c * (x2 - x1) / denominator;
@@ -143,15 +143,15 @@ public class MullerSolver2 extends AbstractUnivariateSolver {
}
} else {
// extremely rare case, get a random number to skip it
- x = min + FastMath.random() * (max - min);
+ x = min + AccurateMath.random() * (max - min);
oldx = Double.POSITIVE_INFINITY;
}
final double y = computeObjectiveValue(x);
// check for convergence
- final double tolerance = FastMath.max(relativeAccuracy * FastMath.abs(x), absoluteAccuracy);
- if (FastMath.abs(x - oldx) <= tolerance ||
- FastMath.abs(y) <= functionValueAccuracy) {
+ final double tolerance = AccurateMath.max(relativeAccuracy * AccurateMath.abs(x), absoluteAccuracy);
+ if (AccurateMath.abs(x - oldx) <= tolerance ||
+ AccurateMath.abs(y) <= functionValueAccuracy) {
return x;
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/NewtonRaphsonSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/NewtonRaphsonSolver.java
index be3c27d..4b29826 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/NewtonRaphsonSolver.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/NewtonRaphsonSolver.java
@@ -20,7 +20,7 @@ package org.apache.commons.math4.legacy.analysis.solvers;
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Implements <a href="http://mathworld.wolfram.com/NewtonsMethod.html">
@@ -82,7 +82,7 @@ public class NewtonRaphsonSolver extends AbstractUnivariateDifferentiableSolver
while (true) {
final DerivativeStructure y0 = computeObjectiveValueAndDerivative(x0);
x1 = x0 - (y0.getValue() / y0.getPartialDerivative(1));
- if (FastMath.abs(x1 - x0) <= absoluteAccuracy) {
+ if (AccurateMath.abs(x1 - x0) <= absoluteAccuracy) {
return x1;
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/RiddersSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/RiddersSolver.java
index 40f2680..8b05975 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/RiddersSolver.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/RiddersSolver.java
@@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.solvers;
import org.apache.commons.math4.legacy.exception.NoBracketingException;
import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Implements the <a href="http://mathworld.wolfram.com/RiddersMethod.html">
@@ -95,28 +95,28 @@ public class RiddersSolver extends AbstractUnivariateSolver {
// calculate the new root approximation
final double x3 = 0.5 * (x1 + x2);
final double y3 = computeObjectiveValue(x3);
- if (FastMath.abs(y3) <= functionValueAccuracy) {
+ if (AccurateMath.abs(y3) <= functionValueAccuracy) {
return x3;
}
final double delta = 1 - (y1 * y2) / (y3 * y3); // delta > 1 due to bracketing
- final double correction = (FastMath.signum(y2) * FastMath.signum(y3)) *
- (x3 - x1) / FastMath.sqrt(delta);
+ final double correction = (AccurateMath.signum(y2) * AccurateMath.signum(y3)) *
+ (x3 - x1) / AccurateMath.sqrt(delta);
final double x = x3 - correction; // correction != 0
final double y = computeObjectiveValue(x);
// check for convergence
- final double tolerance = FastMath.max(relativeAccuracy * FastMath.abs(x), absoluteAccuracy);
- if (FastMath.abs(x - oldx) <= tolerance) {
+ final double tolerance = AccurateMath.max(relativeAccuracy * AccurateMath.abs(x), absoluteAccuracy);
+ if (AccurateMath.abs(x - oldx) <= tolerance) {
return x;
}
- if (FastMath.abs(y) <= functionValueAccuracy) {
+ if (AccurateMath.abs(y) <= functionValueAccuracy) {
return x;
}
// prepare the new interval for next iteration
// Ridders' method guarantees x1 < x < x2
if (correction > 0.0) { // x1 < x < x3
- if (FastMath.signum(y1) + FastMath.signum(y) == 0.0) {
+ if (AccurateMath.signum(y1) + AccurateMath.signum(y) == 0.0) {
x2 = x;
y2 = y;
} else {
@@ -126,7 +126,7 @@ public class RiddersSolver extends AbstractUnivariateSolver {
y2 = y3;
}
} else { // x3 < x < x2
- if (FastMath.signum(y2) + FastMath.signum(y) == 0.0) {
+ if (AccurateMath.signum(y2) + AccurateMath.signum(y) == 0.0) {
x1 = x;
y1 = y;
} else {
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/SecantSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/SecantSolver.java
index 0f42598..5c1e241 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/SecantSolver.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/SecantSolver.java
@@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.solvers;
import org.apache.commons.math4.legacy.exception.NoBracketingException;
import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Implements the <em>Secant</em> method for root-finding (approximating a
@@ -120,13 +120,13 @@ public class SecantSolver extends AbstractUnivariateSolver {
// If the function value of the last approximation is too small,
// given the function value accuracy, then we can't get closer to
// the root than we already are.
- if (FastMath.abs(f1) <= ftol) {
+ if (AccurateMath.abs(f1) <= ftol) {
return x1;
}
// If the current interval is within the given accuracies, we
// are satisfied with the current approximation.
- if (FastMath.abs(x1 - x0) < FastMath.max(rtol * FastMath.abs(x1), atol)) {
+ if (AccurateMath.abs(x1 - x0) < AccurateMath.max(rtol * AccurateMath.abs(x1), atol)) {
return x1;
}
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/UnivariateSolverUtils.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/UnivariateSolverUtils.java
index d03c41f..d734345 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/UnivariateSolverUtils.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/UnivariateSolverUtils.java
@@ -22,7 +22,7 @@ import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException;
import org.apache.commons.math4.legacy.exception.NullArgumentException;
import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Utility routines for {@link UnivariateSolver} objects.
@@ -111,11 +111,11 @@ public class UnivariateSolverUtils {
}
// find a very small interval bracketing the root
- final double step = FastMath.max(bracketing.getAbsoluteAccuracy(),
- FastMath.abs(baseRoot * bracketing.getRelativeAccuracy()));
- double xLo = FastMath.max(min, baseRoot - step);
+ final double step = AccurateMath.max(bracketing.getAbsoluteAccuracy(),
+ AccurateMath.abs(baseRoot * bracketing.getRelativeAccuracy()));
+ double xLo = AccurateMath.max(min, baseRoot - step);
double fLo = f.value(xLo);
- double xHi = FastMath.min(max, baseRoot + step);
+ double xHi = AccurateMath.min(max, baseRoot + step);
double fHi = f.value(xHi);
int remainingEval = maxEval - 2;
while (remainingEval > 0) {
@@ -150,14 +150,14 @@ public class UnivariateSolverUtils {
// update the lower bound
if (changeLo) {
- xLo = FastMath.max(min, xLo - step);
+ xLo = AccurateMath.max(min, xLo - step);
fLo = f.value(xLo);
remainingEval--;
}
// update the higher bound
if (changeHi) {
- xHi = FastMath.min(max, xHi + step);
+ xHi = AccurateMath.min(max, xHi + step);
fHi = f.value(xHi);
remainingEval--;
}
@@ -325,8 +325,8 @@ public class UnivariateSolverUtils {
final double previousFb = fb;
delta = r * delta + q;
- a = FastMath.max(initial - delta, lowerBound);
- b = FastMath.min(initial + delta, upperBound);
+ a = AccurateMath.max(initial - delta, lowerBound);
+ b = AccurateMath.min(initial + delta, upperBound);
fa = function.value(a);
fb = function.value(b);
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractIntegerDistribution.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractIntegerDistribution.java
index ab71159..78e81c6 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractIntegerDistribution.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractIntegerDistribution.java
@@ -27,7 +27,7 @@ import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.sampling.distribution.InverseTransformDiscreteSampler;
import org.apache.commons.rng.sampling.distribution.DiscreteInverseCumulativeProbabilityFunction;
import org.apache.commons.rng.sampling.distribution.DiscreteSampler;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Base class for integer-valued discrete distributions. Default
@@ -94,19 +94,19 @@ public abstract class AbstractIntegerDistribution implements DiscreteDistributio
// use the one-sided Chebyshev inequality to narrow the bracket
// cf. AbstractRealDistribution.inverseCumulativeProbability(double)
final double mu = getMean();
- final double sigma = FastMath.sqrt(getVariance());
+ final double sigma = AccurateMath.sqrt(getVariance());
final boolean chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) ||
Double.isInfinite(sigma) || Double.isNaN(sigma) || sigma == 0.0);
if (chebyshevApplies) {
- double k = FastMath.sqrt((1.0 - p) / p);
+ double k = AccurateMath.sqrt((1.0 - p) / p);
double tmp = mu - k * sigma;
if (tmp > lower) {
- lower = ((int) FastMath.ceil(tmp)) - 1;
+ lower = ((int) AccurateMath.ceil(tmp)) - 1;
}
k = 1.0 / k;
tmp = mu + k * sigma;
if (tmp < upper) {
- upper = ((int) FastMath.ceil(tmp)) - 1;
+ upper = ((int) AccurateMath.ceil(tmp)) - 1;
}
}
@@ -175,7 +175,7 @@ public abstract class AbstractIntegerDistribution implements DiscreteDistributio
*/
@Override
public double logProbability(int x) {
- return FastMath.log(probability(x));
+ return AccurateMath.log(probability(x));
}
/**
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractRealDistribution.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractRealDistribution.java
index 069565d..23cb7be 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractRealDistribution.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractRealDistribution.java
@@ -28,7 +28,7 @@ import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.sampling.distribution.InverseTransformContinuousSampler;
import org.apache.commons.rng.sampling.distribution.ContinuousInverseCumulativeProbabilityFunction;
import org.apache.commons.rng.sampling.distribution.ContinuousSampler;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Base class for probability distributions on the reals.
@@ -134,14 +134,14 @@ public abstract class AbstractRealDistribution
}
final double mu = getMean();
- final double sig = FastMath.sqrt(getVariance());
+ final double sig = AccurateMath.sqrt(getVariance());
final boolean chebyshevApplies;
chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) ||
Double.isInfinite(sig) || Double.isNaN(sig));
if (lowerBound == Double.NEGATIVE_INFINITY) {
if (chebyshevApplies) {
- lowerBound = mu - sig * FastMath.sqrt((1. - p) / p);
+ lowerBound = mu - sig * AccurateMath.sqrt((1. - p) / p);
} else {
lowerBound = -1.0;
while (cumulativeProbability(lowerBound) >= p) {
@@ -152,7 +152,7 @@ public abstract class AbstractRealDistribution
if (upperBound == Double.POSITIVE_INFINITY) {
if (chebyshevApplies) {
- upperBound = mu + sig * FastMath.sqrt(p / (1. - p));
+ upperBound = mu + sig * AccurateMath.sqrt(p / (1. - p));
} else {
upperBound = 1.0;
while (cumulativeProbability(upperBound) < p) {
@@ -225,7 +225,7 @@ public abstract class AbstractRealDistribution
*/
@Override
public double logDensity(double x) {
- return FastMath.log(density(x));
+ return AccurateMath.log(density(x));
}
/**
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EmpiricalDistribution.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EmpiricalDistribution.java
index 63da838..47814f9 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EmpiricalDistribution.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EmpiricalDistribution.java
@@ -42,7 +42,7 @@ import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
import org.apache.commons.math4.legacy.stat.descriptive.StatisticalSummary;
import org.apache.commons.math4.legacy.stat.descriptive.SummaryStatistics;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* <p>Represents an <a href="http://en.wikipedia.org/wiki/Empirical_distribution_function">
@@ -399,8 +399,8 @@ public class EmpiricalDistribution extends AbstractRealDistribution
* @return the index of the bin containing the value
*/
private int findBin(double value) {
- return FastMath.min(
- FastMath.max((int) FastMath.ceil((value - min) / delta) - 1, 0),
+ return AccurateMath.min(
+ AccurateMath.max((int) AccurateMath.ceil((value - min) / delta) - 1, 0),
binCount - 1);
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EnumeratedDistribution.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EnumeratedDistribution.java
index 8c032a0..a7d4d93 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EnumeratedDistribution.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EnumeratedDistribution.java
@@ -30,7 +30,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.sampling.DiscreteProbabilityCollectionSampler;
-import org.apache.commons.math4.legacy.util.MathArrays;
+import org.apache.commons.math4.legacy.core.MathArrays;
import org.apache.commons.math4.legacy.util.Pair;
/**
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/MultivariateNormalDistribution.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/MultivariateNormalDistribution.java
index e220d10..6a72dbb 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/MultivariateNormalDistribution.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/MultivariateNormalDistribution.java
@@ -26,7 +26,7 @@ import org.apache.commons.math4.legacy.linear.NonPositiveDefiniteMatrixException
import org.apache.commons.math4.legacy.linear.RealMatrix;
import org.apache.commons.math4.legacy.linear.SingularMatrixException;
import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Implementation of the multivariate normal (Gaussian) distribution.
@@ -120,7 +120,7 @@ public class MultivariateNormalDistribution
// Scale each eigenvector by the square root of its eigenvalue.
for (int row = 0; row < dim; row++) {
- final double factor = FastMath.sqrt(covMatEigenvalues[row]);
+ final double factor = AccurateMath.sqrt(covMatEigenvalues[row]);
for (int col = 0; col < dim; col++) {
tmpMatrix.multiplyEntry(row, col, factor);
}
@@ -155,8 +155,8 @@ public class MultivariateNormalDistribution
throw new DimensionMismatchException(vals.length, dim);
}
- return FastMath.pow(2 * FastMath.PI, -0.5 * dim) *
- FastMath.pow(covarianceMatrixDeterminant, -0.5) *
+ return AccurateMath.pow(2 * AccurateMath.PI, -0.5 * dim) *
+ AccurateMath.pow(covarianceMatrixDeterminant, -0.5) *
getExponentTerm(vals);
}
@@ -171,7 +171,7 @@ public class MultivariateNormalDistribution
final double[] std = new double[dim];
final double[][] s = covarianceMatrix.getData();
for (int i = 0; i < dim; i++) {
- std[i] = FastMath.sqrt(s[i][i]);
+ std[i] = AccurateMath.sqrt(s[i][i]);
}
return std;
}
@@ -220,6 +220,6 @@ public class MultivariateNormalDistribution
for (int i = 0; i < preMultiplied.length; i++) {
sum += preMultiplied[i] * centered[i];
}
- return FastMath.exp(-0.5 * sum);
+ return AccurateMath.exp(-0.5 * sum);
}
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/fitting/MultivariateNormalMixtureExpectationMaximization.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/fitting/MultivariateNormalMixtureExpectationMaximization.java
index f2de4aa..c5b2c3a 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/fitting/MultivariateNormalMixtureExpectationMaximization.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/fitting/MultivariateNormalMixtureExpectationMaximization.java
@@ -32,8 +32,8 @@ import org.apache.commons.math4.legacy.linear.Array2DRowRealMatrix;
import org.apache.commons.math4.legacy.linear.RealMatrix;
import org.apache.commons.math4.legacy.linear.SingularMatrixException;
import org.apache.commons.math4.legacy.stat.correlation.Covariance;
-import org.apache.commons.math4.legacy.util.FastMath;
-import org.apache.commons.math4.legacy.util.MathArrays;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
+import org.apache.commons.math4.legacy.core.MathArrays;
import org.apache.commons.math4.legacy.util.Pair;
/**
@@ -166,7 +166,7 @@ public class MultivariateNormalMixtureExpectationMaximization {
fittedModel = new MixtureMultivariateNormalDistribution(initialMixture.getComponents());
while (numIterations++ <= maxIterations &&
- FastMath.abs(previousLogLikelihood - logLikelihood) > threshold) {
+ AccurateMath.abs(previousLogLikelihood - logLikelihood) > threshold) {
previousLogLikelihood = logLikelihood;
double sumLogLikelihood = 0d;
@@ -198,7 +198,7 @@ public class MultivariateNormalMixtureExpectationMaximization {
for (int i = 0; i < n; i++) {
final double rowDensity = fittedModel.density(data[i]);
- sumLogLikelihood += FastMath.log(rowDensity);
+ sumLogLikelihood += AccurateMath.log(rowDensity);
for (int j = 0; j < k; j++) {
gamma[i][j] = weights[j] * mvns[j].density(data[i]) / rowDensity;
@@ -252,7 +252,7 @@ public class MultivariateNormalMixtureExpectationMaximization {
newCovMatArrays);
}
- if (FastMath.abs(previousLogLikelihood - logLikelihood) > threshold) {
+ if (AccurateMath.abs(previousLogLikelihood - logLikelihood) > threshold) {
// Did not converge before the maximum number of iterations
throw new ConvergenceException();
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/GaussianCurveFitter.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/GaussianCurveFitter.java
index 69a4802..e2d8897 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/GaussianCurveFitter.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/GaussianCurveFitter.java
@@ -25,7 +25,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException;
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
import org.apache.commons.math4.legacy.exception.OutOfRangeException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Fits points to a {@link
@@ -173,7 +173,7 @@ public class GaussianCurveFitter extends SimpleCurveFitter {
// TODO: Exceptions should not be used for flow control.
fwhmApprox = points[points.length - 1].getX() - points[0].getX();
}
- final double s = fwhmApprox / (2 * FastMath.sqrt(2 * FastMath.log(2)));
+ final double s = fwhmApprox / (2 * AccurateMath.sqrt(2 * AccurateMath.log(2)));
return new double[] { n, points[maxYIdx].getX(), s };
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/HarmonicCurveFitter.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/HarmonicCurveFitter.java
index 51c6b67..5642113 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/HarmonicCurveFitter.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/HarmonicCurveFitter.java
@@ -25,7 +25,7 @@ import org.apache.commons.math4.legacy.exception.MathIllegalStateException;
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
import org.apache.commons.math4.legacy.exception.ZeroException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Fits points to a {@link
@@ -290,8 +290,8 @@ public class HarmonicCurveFitter extends SimpleCurveFitter {
throw new MathIllegalStateException(LocalizedFormats.ZERO_DENOMINATOR);
}
- aOmega[0] = FastMath.sqrt(c1 / c2);
- aOmega[1] = FastMath.sqrt(c2 / c3);
+ aOmega[0] = AccurateMath.sqrt(c1 / c2);
+ aOmega[1] = AccurateMath.sqrt(c2 / c3);
}
return aOmega;
@@ -321,13 +321,13 @@ public class HarmonicCurveFitter extends SimpleCurveFitter {
final double currentYPrime = (currentY - previousY) / (currentX - previousX);
double omegaX = omega * currentX;
- double cosine = FastMath.cos(omegaX);
- double sine = FastMath.sin(omegaX);
+ double cosine = AccurateMath.cos(omegaX);
+ double sine = AccurateMath.sin(omegaX);
fcMean += omega * currentY * cosine - currentYPrime * sine;
fsMean += omega * currentY * sine + currentYPrime * cosine;
}
- return FastMath.atan2(-fsMean, fcMean);
+ return AccurateMath.atan2(-fsMean, fcMean);
}
}
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/AbstractEvaluation.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/AbstractEvaluation.java
index b7516dc..d65f100 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/AbstractEvaluation.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/AbstractEvaluation.java
@@ -22,7 +22,7 @@ import org.apache.commons.math4.legacy.linear.DecompositionSolver;
import org.apache.commons.math4.legacy.linear.QRDecomposition;
import org.apache.commons.math4.legacy.linear.RealMatrix;
import org.apache.commons.math4.legacy.linear.RealVector;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* An implementation of {@link Evaluation} that is designed for extension. All of the
@@ -69,7 +69,7 @@ public abstract class AbstractEvaluation implements Evaluation {
final int nC = cov.getColumnDimension();
final RealVector sig = new ArrayRealVector(nC);
for (int i = 0; i < nC; ++i) {
- sig.setEntry(i, FastMath.sqrt(cov.getEntry(i,i)));
+ sig.setEntry(i, AccurateMath.sqrt(cov.getEntry(i,i)));
}
return sig;
}
@@ -77,13 +77,13 @@ public abstract class AbstractEvaluation implements Evaluation {
/** {@inheritDoc} */
@Override
public double getRMS() {
- return FastMath.sqrt(getReducedChiSquare(1));
+ return AccurateMath.sqrt(getReducedChiSquare(1));
}
/** {@inheritDoc} */
@Override
public double getCost() {
- return FastMath.sqrt(getChiSquare());
+ return AccurateMath.sqrt(getChiSquare());
}
/** {@inheritDoc} */
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LeastSquaresFactory.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LeastSquaresFactory.java
index d8153ff..07af542 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LeastSquaresFactory.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LeastSquaresFactory.java
@@ -30,7 +30,7 @@ import org.apache.commons.math4.legacy.linear.RealVector;
import org.apache.commons.math4.legacy.optim.AbstractOptimizationProblem;
import org.apache.commons.math4.legacy.optim.ConvergenceChecker;
import org.apache.commons.math4.legacy.optim.PointVectorValuePair;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
import org.apache.commons.math4.legacy.util.IntegerSequence;
import org.apache.commons.math4.legacy.util.Pair;
@@ -278,7 +278,7 @@ public class LeastSquaresFactory {
final int dim = m.getRowDimension();
final RealMatrix sqrtM = new DiagonalMatrix(dim);
for (int i = 0; i < dim; i++) {
- sqrtM.setEntry(i, i, FastMath.sqrt(m.getEntry(i, i)));
+ sqrtM.setEntry(i, i, AccurateMath.sqrt(m.getEntry(i, i)));
}
return sqrtM;
} else {
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LevenbergMarquardtOptimizer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LevenbergMarquardtOptimizer.java
index 7bd1749..a44caad 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LevenbergMarquardtOptimizer.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LevenbergMarquardtOptimizer.java
@@ -24,7 +24,7 @@ import org.apache.commons.math4.legacy.fitting.leastsquares.LeastSquaresProblem.
import org.apache.commons.math4.legacy.linear.ArrayRealVector;
import org.apache.commons.math4.legacy.linear.RealMatrix;
import org.apache.commons.math4.legacy.optim.ConvergenceChecker;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
import org.apache.commons.math4.legacy.util.IntegerSequence;
import org.apache.commons.numbers.core.Precision;
@@ -305,7 +305,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer {
final ConvergenceChecker<Evaluation> checker = problem.getConvergenceChecker();
// arrays shared with the other private methods
- final int solvedCols = FastMath.min(nR, nC);
+ final int solvedCols = AccurateMath.min(nR, nC);
/* Parameters evolution direction associated with lmPar. */
double[] lmDir = new double[nC];
/* Levenberg-Marquardt parameter. */
@@ -375,7 +375,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer {
xNorm += xk * xk;
diag[k] = dk;
}
- xNorm = FastMath.sqrt(xNorm);
+ xNorm = AccurateMath.sqrt(xNorm);
// initialize the step bound delta
delta = (xNorm == 0) ? initialStepBoundFactor : (initialStepBoundFactor * xNorm);
@@ -392,7 +392,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer {
for (int i = 0; i <= j; ++i) {
sum += weightedJacobian[i][pj] * qtf[i];
}
- maxCosine = FastMath.max(maxCosine, FastMath.abs(sum) / (s * currentCost));
+ maxCosine = AccurateMath.max(maxCosine, AccurateMath.abs(sum) / (s * currentCost));
}
}
}
@@ -406,7 +406,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer {
// rescale if necessary
for (int j = 0; j < nC; ++j) {
- diag[j] = FastMath.max(diag[j], jacNorm[j]);
+ diag[j] = AccurateMath.max(diag[j], jacNorm[j]);
}
// Inner loop.
@@ -436,10 +436,10 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer {
double s = diag[pj] * lmDir[pj];
lmNorm += s * s;
}
- lmNorm = FastMath.sqrt(lmNorm);
+ lmNorm = AccurateMath.sqrt(lmNorm);
// on the first iteration, adjust the initial step bound.
if (firstIteration) {
- delta = FastMath.min(delta, lmNorm);
+ delta = AccurateMath.min(delta, lmNorm);
}
// Evaluate the function at x + p and calculate its norm.
@@ -486,7 +486,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer {
if ((0.1 * currentCost >= previousCost) || (tmp < 0.1)) {
tmp = 0.1;
}
- delta = tmp * FastMath.min(delta, 10.0 * lmNorm);
+ delta = tmp * AccurateMath.min(delta, 10.0 * lmNorm);
lmPar /= tmp;
} else if ((lmPar == 0) || (ratio >= 0.75)) {
delta = 2 * lmNorm;
@@ -502,7 +502,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer {
double xK = diag[k] * currentPoint[k];
xNorm += xK * xK;
}
- xNorm = FastMath.sqrt(xNorm);
+ xNorm = AccurateMath.sqrt(xNorm);
// tests for convergence.
if (checker != null && checker.converged(iterationCounter.getCount(), previous, current)) {
@@ -523,7 +523,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer {
}
// Default convergence criteria.
- if ((FastMath.abs(actRed) <= costRelativeTolerance &&
+ if ((AccurateMath.abs(actRed) <= costRelativeTolerance &&
preRed <= costRelativeTolerance &&
ratio <= 2.0) ||
delta <= parRelativeTolerance * xNorm) {
@@ -531,7 +531,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer {
}
// tests for termination and stringent tolerances
- if (FastMath.abs(actRed) <= TWO_EPS &&
+ if (AccurateMath.abs(actRed) <= TWO_EPS &&
preRed <= TWO_EPS &&
ratio <= 2.0) {
throw new ConvergenceException(LocalizedFormats.TOO_SMALL_COST_RELATIVE_TOLERANCE,
@@ -655,7 +655,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer {
work1[pj] = s;
dxNorm += s * s;
}
- dxNorm = FastMath.sqrt(dxNorm);
+ dxNorm = AccurateMath.sqrt(dxNorm);
double fp = dxNorm - delta;
if (fp <= 0.1 * delta) {
lmPar = 0;
@@ -697,15 +697,15 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer {
sum /= diag[pj];
sum2 += sum * sum;
}
- double gNorm = FastMath.sqrt(sum2);
+ double gNorm = AccurateMath.sqrt(sum2);
double paru = gNorm / delta;
if (paru == 0) {
- paru = Precision.SAFE_MIN / FastMath.min(delta, 0.1);
+ paru = Precision.SAFE_MIN / AccurateMath.min(delta, 0.1);
}
// if the input par lies outside of the interval (parl,paru),
// set par to the closer endpoint
- lmPar = FastMath.min(paru, FastMath.max(lmPar, parl));
+ lmPar = AccurateMath.min(paru, AccurateMath.max(lmPar, parl));
if (lmPar == 0) {
lmPar = gNorm / dxNorm;
}
@@ -714,9 +714,9 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer {
// evaluate the function at the current value of lmPar
if (lmPar == 0) {
- lmPar = FastMath.max(Precision.SAFE_MIN, 0.001 * paru);
+ lmPar = AccurateMath.max(Precision.SAFE_MIN, 0.001 * paru);
}
- double sPar = FastMath.sqrt(lmPar);
+ double sPar = AccurateMath.sqrt(lmPar);
for (int j = 0; j < solvedCols; ++j) {
int pj = permutation[j];
work1[pj] = sPar * diag[pj];
@@ -730,13 +730,13 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer {
work3[pj] = s;
dxNorm += s * s;
}
- dxNorm = FastMath.sqrt(dxNorm);
+ dxNorm = AccurateMath.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 (FastMath.abs(fp) <= 0.1 * delta ||
+ if (AccurateMath.abs(fp) <= 0.1 * delta ||
(parl == 0 &&
fp <= previousFP &&
previousFP < 0)) {
@@ -765,13 +765,13 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer {
// depending on the sign of the function, update parl or paru.
if (fp > 0) {
- parl = FastMath.max(parl, lmPar);
+ parl = AccurateMath.max(parl, lmPar);
} else if (fp < 0) {
- paru = FastMath.min(paru, lmPar);
+ paru = AccurateMath.min(paru, lmPar);
}
// compute an improved estimate for lmPar
- lmPar = FastMath.max(parl, lmPar + correction);
+ lmPar = AccurateMath.max(parl, lmPar + correction);
}
return lmPar;
@@ -847,13 +847,13 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer {
final double sin;
final double cos;
double rkk = weightedJacobian[k][pk];
- if (FastMath.abs(rkk) < FastMath.abs(lmDiag[k])) {
+ if (AccurateMath.abs(rkk) < AccurateMath.abs(lmDiag[k])) {
final double cotan = rkk / lmDiag[k];
- sin = 1.0 / FastMath.sqrt(1.0 + cotan * cotan);
+ sin = 1.0 / AccurateMath.sqrt(1.0 + cotan * cotan);
cos = sin * cotan;
} else {
final double tan = lmDiag[k] / rkk;
- cos = 1.0 / FastMath.sqrt(1.0 + tan * tan);
+ cos = 1.0 / AccurateMath.sqrt(1.0 + tan * tan);
sin = cos * tan;
}
@@ -956,7 +956,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer {
double akk = weightedJacobian[i][k];
norm2 += akk * akk;
}
- jacNorm[k] = FastMath.sqrt(norm2);
+ jacNorm[k] = AccurateMath.sqrt(norm2);
}
// transform the matrix column after column
@@ -989,7 +989,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer {
// choose alpha such that Hk.u = alpha ek
double akk = weightedJacobian[k][pk];
- double alpha = (akk > 0) ? -FastMath.sqrt(ak2) : FastMath.sqrt(ak2);
+ double alpha = (akk > 0) ? -AccurateMath.sqrt(ak2) : AccurateMath.sqrt(ak2);
double betak = 1.0 / (ak2 - akk * alpha);
beta[pk] = betak;
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/ElitisticListPopulation.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/ElitisticListPopulation.java
index 716af3a..1bb7822 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/ElitisticListPopulation.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/ElitisticListPopulation.java
@@ -24,7 +24,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException;
import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
import org.apache.commons.math4.legacy.exception.OutOfRangeException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Population of chromosomes which uses elitism (certain percentage of the best
@@ -87,7 +87,7 @@ public class ElitisticListPopulation extends ListPopulation {
Collections.sort(oldChromosomes);
// index of the last "not good enough" chromosome
- int boundIndex = (int) FastMath.ceil((1.0 - getElitismRate()) * oldChromosomes.size());
+ int boundIndex = (int) AccurateMath.ceil((1.0 - getElitismRate()) * oldChromosomes.size());
for (int i = boundIndex; i < oldChromosomes.size(); i++) {
nextGeneration.addChromosome(oldChromosomes.get(i));
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/OrderedCrossover.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/OrderedCrossover.java
index b145198..c28c253 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/OrderedCrossover.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/OrderedCrossover.java
@@ -26,7 +26,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Order 1 Crossover [OX1] builds offspring from <b>ordered</b> chromosomes by copying a
@@ -111,8 +111,8 @@ public class OrderedCrossover<T> implements CrossoverPolicy {
b = random.nextInt(length);
} while (a == b);
// determine the lower and upper bounds
- final int lb = FastMath.min(a, b);
- final int ub = FastMath.max(a, b);
+ final int lb = AccurateMath.min(a, b);
+ final int ub = AccurateMath.max(a, b);
// add the subLists that are between lb and ub
child1.addAll(parent1Rep.subList(lb, ub + 1));
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/AbstractFieldMatrix.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/AbstractFieldMatrix.java
index f5c21b5..8042345 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/AbstractFieldMatrix.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/AbstractFieldMatrix.java
@@ -19,8 +19,8 @@ package org.apache.commons.math4.legacy.linear;
import java.util.ArrayList;
-import org.apache.commons.math4.legacy.Field;
-import org.apache.commons.math4.legacy.FieldElement;
+import org.apache.commons.math4.legacy.core.Field;
+import org.apache.commons.math4.legacy.core.FieldElement;
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.NoDataException;
import org.apache.commons.math4.legacy.exception.NotPositiveException;
@@ -29,7 +29,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException;
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
import org.apache.commons.math4.legacy.exception.OutOfRangeException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
-import org.apache.commons.math4.legacy.util.MathArrays;
+import org.apache.commons.math4.legacy.core.MathArrays;
/**
* Basic implementation of {@link FieldMatrix} methods regardless of the underlying storage.
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/AbstractRealMatrix.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/AbstractRealMatrix.java
index c1539b8..264cbcb 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/AbstractRealMatrix.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/AbstractRealMatrix.java
@@ -28,7 +28,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException;
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
import org.apache.commons.math4.legacy.exception.OutOfRangeException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* Basic implementation of RealMatrix methods regardless of the underlying storage.
@@ -270,9 +270,9 @@ public abstract class AbstractRealMatrix
/** {@inheritDoc} */
@Override
public void visit(final int row, final int column, final double value) {
- columnSum += FastMath.abs(value);
+ columnSum += AccurateMath.abs(value);
if (row == endRow) {
- maxColSum = FastMath.max(maxColSum, columnSum);
+ maxColSum = AccurateMath.max(maxColSum, columnSum);
columnSum = 0;
}
}
@@ -310,7 +310,7 @@ public abstract class AbstractRealMatrix
/** {@inheritDoc} */
@Override
public double end() {
- return FastMath.sqrt(sum);
+ return AccurateMath.sqrt(sum);
}
});
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/Array2DRowFieldMatrix.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/Array2DRowFieldMatrix.java
index 474a6cb..215ee16 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/Array2DRowFieldMatrix.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/Array2DRowFieldMatrix.java
@@ -19,8 +19,8 @@ package org.apache.commons.math4.legacy.linear;
import java.io.Serializable;
-import org.apache.commons.math4.legacy.Field;
-import org.apache.commons.math4.legacy.FieldElement;
+import org.apache.commons.math4.legacy.core.Field;
+import org.apache.commons.math4.legacy.core.FieldElement;
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.MathIllegalStateException;
import org.apache.commons.math4.legacy.exception.NoDataException;
@@ -29,7 +29,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException;
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
import org.apache.commons.math4.legacy.exception.OutOfRangeException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
-import org.apache.commons.math4.legacy.util.MathArrays;
+import org.apache.commons.math4.legacy.core.MathArrays;
/**
* Implementation of {@code FieldMatrix<T>} using a {@link FieldElement}[][] array to store entries.
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/ArrayFieldVector.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/ArrayFieldVector.java
index 9d8944f..46789dd 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/ArrayFieldVector.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/ArrayFieldVector.java
@@ -19,8 +19,8 @@ package org.apache.commons.math4.legacy.linear;
import java.io.Serializable;
import java.util.Arrays;
-import org.apache.commons.math4.legacy.Field;
-import org.apache.commons.math4.legacy.FieldElement;
+import org.apache.commons.math4.legacy.core.Field;
+import org.apache.commons.math4.legacy.core.FieldElement;
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
import org.apache.commons.math4.legacy.exception.MathArithmeticException;
import org.apache.commons.math4.legacy.exception.NotPositiveException;
@@ -30,7 +30,7 @@ import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
import org.apache.commons.math4.legacy.exception.OutOfRangeException;
import org.apache.commons.math4.legacy.exception.ZeroException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
-import org.apache.commons.math4.legacy.util.MathArrays;
+import org.apache.commons.math4.legacy.core.MathArrays;
/**
* This class implements the {@link FieldVector} interface with a {@link FieldElement} array.
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/ArrayRealVector.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/ArrayRealVector.java
index 95b8f7b..0858c86 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/ArrayRealVector.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/ArrayRealVector.java
@@ -28,7 +28,7 @@ import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
import org.apache.commons.math4.legacy.exception.OutOfRangeException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
* This class implements the {@link RealVector} interface with a double array.
@@ -470,7 +470,7 @@ public class ArrayRealVector extends RealVector implements Serializable {
for (double a : data) {
sum += a * a;
}
- return FastMath.sqrt(sum);
+ return AccurateMath.sqrt(sum);
}
/** {@inheritDoc} */
@@ -478,7 +478,7 @@ public class ArrayRealVector extends RealVector implements Serializable {
public double getL1Norm() {
double sum = 0;
for (double a : data) {
- sum += FastMath.abs(a);
+ sum += AccurateMath.abs(a);
}
return sum;
}
@@ -488,7 +488,7 @@ public class ArrayRealVector extends RealVector implements Serializable {
public double getLInfNorm() {
double max = 0;
for (double a : data) {
- max = FastMath.max(max, FastMath.abs(a));
+ max = AccurateMath.max(max, AccurateMath.abs(a));
}
return max;
}
@@ -504,7 +504,7 @@ public class ArrayRealVector extends RealVector implements Serializable {
final double delta = data[i] - vData[i];
sum += delta * delta;
}
- return FastMath.sqrt(sum);
+ return AccurateMath.sqrt(sum);
} else {
checkVectorDimensions(v);
double sum = 0;
@@ -512,7 +512,7 @@ public class ArrayRealVector extends RealVector implements Serializable {
final double delta = data[i] - v.getEntry(i);
sum += delta * delta;
}
- return FastMath.sqrt(sum);
+ return AccurateMath.sqrt(sum);
}
}
@@ -526,7 +526,7 @@ public class ArrayRealVector extends RealVector implements Serializable {
double sum = 0;
for (int i = 0; i < data.length; ++i) {
final double delta = data[i] - vData[i];
- sum += FastMath.abs(delta);
+ sum += AccurateMath.abs(delta);
}
return sum;
} else {
@@ -534,7 +534,7 @@ public class ArrayRealVector extends RealVector implements Serializable {
double sum = 0;
for (int i = 0; i < data.length; ++i) {
final double delta = data[i] - v.getEntry(i);
- sum += FastMath.abs(delta);
+ sum += AccurateMath.abs(delta);
}
return sum;
}
@@ -550,7 +550,7 @@ public class ArrayRealVector extends RealVector implements Serializable {
double max = 0;
for (int i = 0; i < data.length; ++i) {
final double delta = data[i] - vData[i];
- max = FastMath.max(max, FastMath.abs(delta));
+ max = AccurateMath.max(max, AccurateMath.abs(delta));
}
return max;
} else {
@@ -558,7 +558,7 @@ public class ArrayRealVector extends RealVector implements Serializable {
double max = 0;
for (int i = 0; i < data.length; ++i) {
final double delta = data[i] - v.getEntry(i);
- max = FastMath.max(max, FastMath.abs(delta));
+ max = AccurateMath.max(max, AccurateMath.abs(delta));
}
return max;
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BiDiagonalTransformer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BiDiagonalTransformer.java
index 8e185d5..e0630a0 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BiDiagonalTransformer.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BiDiagonalTransformer.java
@@ -17,7 +17,7 @@
package org.apache.commons.math4.legacy.linear;
-import org.apache.commons.math4.legacy.util.FastMath;
+import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
/**
@@ -62,7 +62,7 @@ class BiDiagonalTransformer {
final int m = matrix.getRowDimension();
final int n = matrix.getColumnDimension();
- final int p = FastMath.min(m, n);
+ final int p = AccurateMath.min(m, n);
householderVectors = matrix.getData();
main = new double[p];
secondary = new double[p - 1];
@@ -266,7 +266,7 @@ class BiDiagonalTransformer {
xNormSqr += c * c;
}
final double[] hK = householderVectors[k];
- final double a = (hK[k] > 0) ? -FastMath.sqrt(xNormSqr) : FastMath.sqrt(xNormSqr);
+ final double a = (hK[k] > 0) ? -AccurateMath.sqrt(xNormSqr) : AccurateMath.sqrt(xNormSqr);
main[k] = a;
if (a != 0.0) {
hK[k] -= a;
@@ -291,7 +291,7 @@ class BiDiagonalTransformer {
final double c = hK[j];
xNormSqr += c * c;
}
- final double b = (hK[k + 1] > 0) ? -FastMath.sqrt(xNormSqr) : FastMath.sqrt(xNormSqr);
+ final double b = (hK[k + 1] > 0) ? -AccurateMath.sqrt(xNormSqr) : AccurateMath.sqrt(xNormSqr);
secondary[k] = b;
if (b != 0.0) {
hK[k + 1] -= b;
@@ -330,7 +330,7 @@ class BiDiagonalTransformer {
final double c = hK[j];
xNormSqr += c * c;
}
- final double a = (hK[k] > 0) ? -FastMath.sqrt(xNormSqr) : FastMath.sqrt(xNormSqr);
+ final double a = (hK[k] > 0) ? -AccurateMath.sqrt(xNormSqr) : AccurateMath.sqrt(xNormSqr);
main[k] = a;
if (a != 0.0) {
hK[k] -= a;
@@ -355,7 +355,7 @@ class BiDiagonalTransformer {
final double c = householderVectors[i][k];
xNormSqr += c * c;
}
- final double b = (hKp1[k] > 0) ? -FastMath.sqrt(xNormSqr) : FastMath.sqrt(xNormSqr);
+ final double b = (hKp1[k] > 0) ? -AccurateMath.sqrt(xNormSqr) : AccurateMath.sqrt(xNormSqr);
secondary[k] = b;
if (b != 0.0) {
hKp1[k] -= b;
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BigReal.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BigReal.java
index ec22cca..8078544 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BigReal.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BigReal.java
@@ -23,8 +23,8 @@ import java.math.BigInteger;
import java.math.MathContext;
import java.math.RoundingMode;
-import org.apache.commons.math4.legacy.Field;
-import org.apache.commons.math4.legacy.FieldElement;
+import org.apache.commons.math4.legacy.core.Field;
+import org.apache.commons.math4.legacy.core.FieldElement;
import org.apache.commons.math4.legacy.exception.MathArithmeticException;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BigRealField.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BigRealField.java
index 71755bb..cddfe68 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BigRealField.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BigRealField.java
@@ -19,8 +19,8 @@ package org.apache.commons.math4.legacy.linear;
import java.io.Serializable;
-import org.apache.commons.math4.legacy.Field;
-import org.apache.commons.math4.legacy.FieldElement;
+import org.apache.commons.math4.legacy.core.Field;
+import org.apache.commons.math4.legacy.core.FieldElement;
/**
* Representation of real numbers with arbitrary precision field.
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockFieldMatrix.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockFieldMatrix.java
index b255b9c..3caf51e 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockFieldMatrix.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockFieldMatrix.java
@@ -19,8 +19,8 @@ package org.apache.commons.math4.legacy.linear;
import java.io.Serializable;
-import org.apache.commons.math4.legacy.Field;
-import org.apache.commons.math4.legacy.FieldElement;
+import org.apache.commons.math4.legacy.core.Field;
+import org.apache.commons.math4.legacy.core.FieldElement;
... 16221 lines suppressed ...