This commit is contained in:
Gilles Sadowski 2021-06-25 14:51:00 +02:00
commit c98e638d73
92 changed files with 5454 additions and 5019 deletions

View File

@ -45,7 +45,7 @@ class ChineseRings {
* @param numPointsRing1 Number of points in the first ring.
* @param numPointsRing2 Number of points in the second ring.
*/
public ChineseRings(Vector3D orientationRing1,
ChineseRings(Vector3D orientationRing1,
double radiusRing1,
double halfWidthRing1,
double radiusRing2,
@ -113,6 +113,8 @@ class ChineseRings {
/**
* Gets all the points.
*
* @return the points
*/
public Vector3D[] getPoints() {
return points.clone();
@ -125,24 +127,28 @@ class ChineseRings {
*/
public Iterable<double[]> createIterable() {
return new Iterable<double[]>() {
@Override
public Iterator<double[]> iterator() {
return new Iterator<double[]>() {
/** Data. */
final Vector3D[] points = getPoints();
private final Vector3D[] points = getPoints();
/** Number of samples. */
private int n = 0;
/** {@inheritDoc} */
@Override
public boolean hasNext() {
return n < points.length;
}
/** {@inheritDoc} */
@Override
public double[] next() {
return points[n++].toArray();
}
/** {@inheritDoc} */
@Override
public void remove() {
throw new UnsupportedOperationException();
}

View File

@ -26,7 +26,6 @@ import org.apache.commons.geometry.euclidean.threed.Vector3D;
import org.apache.commons.math4.neuralnet.SquareNeighbourhood;
import org.apache.commons.math4.neuralnet.FeatureInitializer;
import org.apache.commons.math4.neuralnet.FeatureInitializerFactory;
import org.apache.commons.math4.neuralnet.MapUtils;
import org.apache.commons.math4.neuralnet.DistanceMeasure;
import org.apache.commons.math4.neuralnet.EuclideanDistance;
import org.apache.commons.math4.neuralnet.twod.NeuronSquareMesh2D;
@ -54,7 +53,7 @@ class ChineseRingsClassifier {
* @param dim1 Number of rows of the SOFM.
* @param dim2 Number of columns of the SOFM.
*/
public ChineseRingsClassifier(ChineseRings rings,
ChineseRingsClassifier(ChineseRings rings,
int dim1,
int dim2) {
this.rings = rings;
@ -164,24 +163,27 @@ class ChineseRingsClassifier {
private Iterator<double[]> createRandomIterator(final long numSamples) {
return new Iterator<double[]>() {
/** Data. */
final Vector3D[] points = rings.getPoints();
private final Vector3D[] points = rings.getPoints();
/** RNG. */
final UniformRandomProvider rng = RandomSource.create(RandomSource.KISS);
private final UniformRandomProvider rng = RandomSource.create(RandomSource.KISS);
/** Number of samples. */
private long n = 0;
/** {@inheritDoc} */
@Override
public boolean hasNext() {
return n < numSamples;
}
/** {@inheritDoc} */
@Override
public double[] next() {
++n;
return points[rng.nextInt(points.length)].toArray();
}
/** {@inheritDoc} */
@Override
public void remove() {
throw new UnsupportedOperationException();
}

View File

@ -35,19 +35,23 @@ import org.apache.commons.math4.neuralnet.twod.NeuronSquareMesh2D;
*/
@Command(description = "Run the application",
mixinStandardHelpOptions = true)
public class StandAlone implements Callable<Void> {
public final class StandAlone implements Callable<Void> {
/** The number of rows. */
@Option(names = { "-r" }, paramLabel = "numRows",
description = "Number of rows of the 2D SOFM (default: ${DEFAULT-VALUE}).")
private int _numRows = 15;
private int numRows = 15;
/** The number of columns. */
@Option(names = { "-c" }, paramLabel = "numCols",
description = "Number of columns of the 2D SOFM (default: ${DEFAULT-VALUE}).")
private int _numCols = 15;
private int numCols = 15;
/** The number of samples. */
@Option(names = { "-s" }, paramLabel = "numSamples",
description = "Number of samples for the training (default: ${DEFAULT-VALUE}).")
private long _numSamples = 100000;
private long numSamples = 100000;
/** The output file. */
@Option(names = { "-o" }, paramLabel = "outputFile", required = true,
description = "Output file name.")
private String _outputFile = null;
private String outputFile = null;
/**
* Program entry point.
@ -65,9 +69,9 @@ public class StandAlone implements Callable<Void> {
20, 1,
2000, 1500);
final ChineseRingsClassifier classifier = new ChineseRingsClassifier(rings, _numRows, _numCols);
classifier.createSequentialTask(_numSamples).run();
printResult(_outputFile, classifier);
final ChineseRingsClassifier classifier = new ChineseRingsClassifier(rings, numRows, numCols);
classifier.createSequentialTask(numSamples).run();
printResult(outputFile, classifier);
return null;
}
@ -81,10 +85,11 @@ public class StandAlone implements Callable<Void> {
* @throws FileNotFoundException If the file cannot be created.
*/
private static void printResult(String fileName,
ChineseRingsClassifier sofm) throws FileNotFoundException, UnsupportedEncodingException {
ChineseRingsClassifier sofm)
throws FileNotFoundException, UnsupportedEncodingException {
final NeuronSquareMesh2D.DataVisualization result = sofm.computeQualityIndicators();
try (final PrintWriter out = new PrintWriter(fileName, StandardCharsets.UTF_8.name())) {
try (PrintWriter out = new PrintWriter(fileName, StandardCharsets.UTF_8.name())) {
out.println("# Number of samples: " + result.getNumberOfSamples());
out.println("# Quantization error: " + result.getMeanQuantizationError());
out.println("# Topographic error: " + result.getMeanTopographicError());

View File

@ -0,0 +1,22 @@
/*
* 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.
*/
/**
* Self-organized feature map (SOFM) used for classification.
*/
package org.apache.commons.math4.examples.sofm.chineserings;

View File

@ -16,11 +16,13 @@
*/
package org.apache.commons.math3.examples.neuralnet.sofm.tsp;
import org.apache.commons.rng.simple.RandomSource;
/**
* Application class.
*/
public class StandAlone {
public final class StandAlone {
/** No instances. */
private StandAlone() {}
/**
* Program entry point.
*

View File

@ -0,0 +1,22 @@
/*
* 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.
*/
/**
* Self-organized feature map (ANN) sample codes.
*/
package org.apache.commons.math3.examples.neuralnet.sofm.tsp;

View File

@ -26,11 +26,11 @@ import java.util.HashSet;
*/
public class City {
/** Identifier. */
final String name;
private final String name;
/** x-coordinate. */
final double x;
private final double x;
/** y-coordinate. */
final double y;
private final double y;
/**
* @param name Name.

View File

@ -35,22 +35,27 @@ import org.apache.commons.rng.simple.RandomSource;
*/
@Command(description = "Run the application",
mixinStandardHelpOptions = true)
public class StandAlone implements Callable<Void> {
public final class StandAlone implements Callable<Void> {
/** The neurons per city. */
@Option(names = { "-n" }, paramLabel = "neuronsPerCity",
description = "Average number of neurons per city (default: ${DEFAULT-VALUE}).")
private double _neuronsPerCity = 2.2;
private double neuronsPerCity = 2.2;
/** The number of samples. */
@Option(names = { "-s" }, paramLabel = "numSamples",
description = "Number of samples for the training (default: ${DEFAULT-VALUE}).")
private long _numSamples = 2000L;
private long numSamples = 2000L;
/** The number of jobs. */
@Option(names = { "-j" }, paramLabel = "numJobs",
description = "Number of concurrent tasks (default: ${DEFAULT-VALUE}).")
private int _numJobs = Runtime.getRuntime().availableProcessors();
private int numJobs = Runtime.getRuntime().availableProcessors();
/** The maximum number of trials. */
@Option(names = { "-m" }, paramLabel = "maxTrials",
description = "Maximal number of trials (default: ${DEFAULT-VALUE}).")
private int _maxTrials = 10;
private int maxTrials = 10;
/** The output file. */
@Option(names = { "-o" }, paramLabel = "outputFile", required = true,
description = "Output file name.")
private String _outputFile = null;
private String outputFile = null;
/**
* Program entry point.
@ -62,7 +67,7 @@ public class StandAlone implements Callable<Void> {
}
@Override
public Void call() throws Exception {
public Void call() throws FileNotFoundException, UnsupportedEncodingException {
// Cities (in optimal travel order).
final City[] cities = new City[] {
new City("o0", 0, 0),
@ -87,11 +92,11 @@ public class StandAlone implements Callable<Void> {
double minDist = Double.POSITIVE_INFINITY;
int count = 0;
while (count++ < _maxTrials) {
while (count++ < maxTrials) {
final City[] travel = TravellingSalesmanSolver.solve(cities,
_neuronsPerCity,
_numSamples,
_numJobs,
neuronsPerCity,
numSamples,
numJobs,
rng);
final int numCities = City.unique(travel).size();
if (numCities > maxCities) {
@ -108,7 +113,7 @@ public class StandAlone implements Callable<Void> {
}
}
printSummary(_outputFile, best, computeDistance(cities));
printSummary(outputFile, best, computeDistance(cities));
return null;
}
@ -146,8 +151,9 @@ public class StandAlone implements Callable<Void> {
*/
private static void printSummary(String fileName,
City[] travel,
double optimalDistance) throws FileNotFoundException, UnsupportedEncodingException {
try (final PrintWriter out = new PrintWriter(fileName, StandardCharsets.UTF_8.name())) {
double optimalDistance)
throws FileNotFoundException, UnsupportedEncodingException {
try (PrintWriter out = new PrintWriter(fileName, StandardCharsets.UTF_8.name())) {
out.println("# Number of unique cities: " + City.unique(travel).size());
out.println("# Travel distance: " + computeDistance(travel));
out.println("# Optimal travel distance: " + optimalDistance);

View File

@ -51,7 +51,8 @@ import org.apache.commons.math4.neuralnet.sofm.LearningFactorFunction;
* "Travelling Salesman's Problem"</a> (i.e. trying to find the sequence of
* cities that minimizes the travel distance) using a 1D SOFM.
*/
public class TravellingSalesmanSolver {
public final class TravellingSalesmanSolver {
/** The ID for the first neuron. */
private static final long FIRST_NEURON_ID = 0;
/** SOFM. */
private final Network net;
@ -172,7 +173,7 @@ public class TravellingSalesmanSolver {
* in random order.
*
* @param numSamples Number of samples.
* @param cities Cities.
* @param uniqueCities Cities.
* @param random RNG.
* @return the iterator.
*/
@ -300,13 +301,13 @@ public class TravellingSalesmanSolver {
*/
class HarmonicOscillator implements DoubleUnaryOperator {
/** Amplitude. */
final double amplitude;
private final double amplitude;
/** Angular speed. */
final double omega;
private final double omega;
/** Phase. */
final double phase;
private final double phase;
/** Offset. */
final double offset;
private final double offset;
/**
* @param amplitude Amplitude.
@ -314,7 +315,7 @@ class HarmonicOscillator implements DoubleUnaryOperator {
* @param phase Phase.
* @param offset Offset (ordinate).
*/
public HarmonicOscillator(double amplitude,
HarmonicOscillator(double amplitude,
double omega,
double phase,
double offset) {

View File

@ -0,0 +1,22 @@
/*
* 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.
*/
/**
* Traveling Salesman Problem.
*/
package org.apache.commons.math4.examples.sofm.tsp;

View File

@ -49,10 +49,8 @@ public interface FieldElement<T> {
T negate();
/** Compute n &times; this. Multiplication by an integer number is defined
* as the following sum
* <center>
* n &times; this = &sum;<sub>i=1</sub><sup>n</sup> this.
* </center>
* as the following sum:
* <p>n &times; this = &sum;<sub>i=1</sub><sup>n</sup> this.
* @param n Number of times {@code this} must be added to itself.
* @return A new element representing n &times; this.
*/

View File

@ -29,7 +29,7 @@ import org.apache.commons.math4.legacy.exception.ZeroException;
*
* @since 3.6
*/
public class IntegerSequence {
public final class IntegerSequence {
/**
* Utility class contains only static methods.
*/
@ -128,7 +128,7 @@ public class IntegerSequence {
* custom {@link MaxCountExceededCallback callback}, in order to e.g.
* select which exception must be thrown.
*/
public static class Incrementor implements Iterator<Integer> {
public static final class Incrementor implements Iterator<Integer> {
/** Default callback. */
private static final MaxCountExceededCallback CALLBACK
= new MaxCountExceededCallback() {

View File

@ -18,12 +18,8 @@
package org.apache.commons.math4.legacy.core;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.TreeSet;
import org.apache.commons.numbers.core.Precision;
@ -46,7 +42,7 @@ import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
*
* @since 3.0
*/
public class MathArrays {
public final class MathArrays {
/**
* Private constructor.
@ -620,7 +616,7 @@ public class MathArrays {
* and equal elements.
*/
public static boolean equals(float[] x, float[] y) {
if ((x == null) || (y == null)) {
if (x == null || y == null) {
return !((x == null) ^ (y == null));
}
if (x.length != y.length) {
@ -646,7 +642,7 @@ public class MathArrays {
* @since 2.2
*/
public static boolean equalsIncludingNaN(float[] x, float[] y) {
if ((x == null) || (y == null)) {
if (x == null || y == null) {
return !((x == null) ^ (y == null));
}
if (x.length != y.length) {
@ -671,7 +667,7 @@ public class MathArrays {
* dimension and equal elements.
*/
public static boolean equals(double[] x, double[] y) {
if ((x == null) || (y == null)) {
if (x == null || y == null) {
return !((x == null) ^ (y == null));
}
if (x.length != y.length) {
@ -697,7 +693,7 @@ public class MathArrays {
* @since 2.2
*/
public static boolean equalsIncludingNaN(double[] x, double[] y) {
if ((x == null) || (y == null)) {
if (x == null || y == null) {
return !((x == null) ^ (y == null));
}
if (x.length != y.length) {
@ -1049,10 +1045,12 @@ public class MathArrays {
throw new MathIllegalArgumentException(LocalizedFormats.NAN_ELEMENT_AT_INDEX, Integer.valueOf(i));
}
if (Double.isInfinite(weight)) {
throw new MathIllegalArgumentException(LocalizedFormats.INFINITE_ARRAY_ELEMENT, Double.valueOf(weight), Integer.valueOf(i));
throw new MathIllegalArgumentException(LocalizedFormats.INFINITE_ARRAY_ELEMENT,
Double.valueOf(weight), Integer.valueOf(i));
}
if (weight < 0) {
throw new MathIllegalArgumentException(LocalizedFormats.NEGATIVE_ELEMENT_AT_INDEX, Integer.valueOf(i), Double.valueOf(weight));
throw new MathIllegalArgumentException(LocalizedFormats.NEGATIVE_ELEMENT_AT_INDEX,
Integer.valueOf(i), Double.valueOf(weight));
}
if (!containsPositiveWeight && weight > 0.0) {
containsPositiveWeight = true;

View File

@ -87,7 +87,8 @@ public interface RealFieldElement<T> extends FieldElement<T> {
*/
T floor();
/** Get the whole number that is the nearest to the instance, or the even one if x is exactly half way between two integers.
/** Get the whole number that is the nearest to the instance, or the even one if x is exactly
* half way between two integers.
* @return a double number r such that r is an integer r - 0.5 &le; this &le; r + 0.5
*/
T rint();
@ -405,7 +406,7 @@ public interface RealFieldElement<T> extends FieldElement<T> {
* @param e2 second element
* @return max(a1, e2)
*/
public static <T extends RealFieldElement<T>> T max(final T e1, final T e2) {
static <T extends RealFieldElement<T>> T max(final T e1, final T e2) {
return e1.subtract(e2).getReal() >= 0 ? e1 : e2;
}
@ -415,7 +416,7 @@ public interface RealFieldElement<T> extends FieldElement<T> {
* @param e2 second element
* @return min(a1, e2)
*/
public static <T extends RealFieldElement<T>> T min(final T e1, final T e2) {
static <T extends RealFieldElement<T>> T min(final T e1, final T e2) {
return e1.subtract(e2).getReal() >= 0 ? e2 : e1;
}
}

View File

@ -103,10 +103,10 @@ public class Dfp implements RealFieldElement<Dfp> {
public static final int MIN_EXP = -32767;
/** The maximum exponent before overflow is signaled and results flushed
* to infinity */
* to infinity. */
public static final int MAX_EXP = 32768;
/** The amount under/overflows are scaled by before going to trap handler */
/** The amount under/overflows are scaled by before going to trap handler. */
public static final int ERR_SCALE = 32760;
/** Indicator value for normal finite numbers. */
@ -302,7 +302,7 @@ public class Dfp implements RealFieldElement<Dfp> {
}
Dfp xdfp = new Dfp(field, mantissa);
xdfp = xdfp.divide(new Dfp(field, 4503599627370496l)).add(field.getOne()); // Divide by 2^52, then add one
xdfp = xdfp.divide(new Dfp(field, 4503599627370496L)).add(field.getOne()); // Divide by 2^52, then add one
xdfp = xdfp.multiply(DfpMath.pow(field.getTwo(), exponent));
if ((bits & 0x8000000000000000L) != 0) {
@ -313,7 +313,6 @@ public class Dfp implements RealFieldElement<Dfp> {
sign = xdfp.sign;
exp = xdfp.exp;
nans = xdfp.nans;
}
/** Copy constructor.
@ -378,10 +377,8 @@ public class Dfp implements RealFieldElement<Dfp> {
String fpexp = s.substring(p + 1);
boolean negative = false;
for (int i=0; i<fpexp.length(); i++)
{
if (fpexp.charAt(i) == '-')
{
for (int i = 0; i < fpexp.length(); i++) {
if (fpexp.charAt(i) == '-') {
negative = true;
continue;
}
@ -529,7 +526,6 @@ public class Dfp implements RealFieldElement<Dfp> {
// Is there possible another digit?
round((striped[q] - '0') * 1000);
}
}
/** Creates an instance with a non-finite value.
@ -602,7 +598,6 @@ public class Dfp implements RealFieldElement<Dfp> {
}
return new Dfp(d);
}
/** Create an instance from a String representation.
@ -624,7 +619,8 @@ public class Dfp implements RealFieldElement<Dfp> {
return field.newDfp(sig, code);
}
/** Get the {@link org.apache.commons.math4.legacy.core.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.
@ -744,7 +740,6 @@ public class Dfp implements RealFieldElement<Dfp> {
}
return lostdigit;
}
/** Check if instance is less than x.
@ -809,7 +804,6 @@ public class Dfp implements RealFieldElement<Dfp> {
}
return (sign < 0) || ((mant[mant.length - 1] == 0) && !isInfinite());
}
/** Check if instance is strictly less than 0.
@ -824,7 +818,6 @@ public class Dfp implements RealFieldElement<Dfp> {
}
return (sign < 0) && ((mant[mant.length - 1] != 0) || isInfinite());
}
/** Check if instance is greater than or equal to 0.
@ -839,7 +832,6 @@ public class Dfp implements RealFieldElement<Dfp> {
}
return (sign > 0) || ((mant[mant.length - 1] == 0) && !isInfinite());
}
/** Check if instance is strictly greater than 0.
@ -854,7 +846,6 @@ public class Dfp implements RealFieldElement<Dfp> {
}
return (sign > 0) && ((mant[mant.length - 1] != 0) || isInfinite());
}
/** Get the absolute value of instance.
@ -894,7 +885,6 @@ public class Dfp implements RealFieldElement<Dfp> {
}
return (mant[mant.length - 1] == 0) && !isInfinite();
}
/** Check if instance is equal to x.
@ -914,7 +904,6 @@ public class Dfp implements RealFieldElement<Dfp> {
}
return false;
}
/**
@ -941,7 +930,7 @@ public class Dfp implements RealFieldElement<Dfp> {
/** Compare two instances.
* @param a first instance in comparison
* @param b second instance in comparison
* @return -1 if a<b, 1 if a>b and 0 if a==b
* @return -1 if {@code a < b}, 1 if {@code a > b} and 0 if {@code a == b}
* Note this method does not properly handle NaNs or numbers with different precision.
*/
private static int compare(final Dfp a, final Dfp b) {
@ -995,7 +984,6 @@ public class Dfp implements RealFieldElement<Dfp> {
}
return 0;
}
/** Round to nearest integer using the round-half-even method.
@ -1045,7 +1033,6 @@ public class Dfp implements RealFieldElement<Dfp> {
}
return result;
}
/** Does the integer conversions with the specified rounding.
@ -1322,9 +1309,11 @@ public class Dfp implements RealFieldElement<Dfp> {
rsign = asign;
}
/* Handle special case when a or b is zero, by setting the exponent
of the zero number equal to the other one. This avoids an alignment
which would cause catastropic loss of precision */
/*
* Handle special case when a or b is zero, by setting the exponent of the zero
* number equal to the other one. This avoids an alignment which would cause
* catastropic loss of precision
*/
if (b.mant[mant.length - 1] == 0) {
b.exp = a.exp;
}
@ -1693,9 +1682,9 @@ public class Dfp implements RealFieldElement<Dfp> {
*/
@Override
public Dfp divide(Dfp divisor) {
int dividend[]; // current status of the dividend
int quotient[]; // quotient
int remainder[];// remainder
int[] dividend; // current status of the dividend
int[] quotient; // quotient
int[] remainder; // remainder
int qd; // current quotient digit we're working with
int nsqd; // number of significant quotient digits we have
int trial = 0; // trial quotient digit
@ -1766,8 +1755,7 @@ public class Dfp implements RealFieldElement<Dfp> {
quotient[mant.length + 1] = 0;
remainder[mant.length] = 0;
/* copy our mantissa into the dividend, initialize the
quotient while we are at it */
/* copy our mantissa into the dividend, initialize the quotient while we are at it */
for (int i = 0; i < mant.length; i++) {
dividend[i] = mant[i];
@ -1823,8 +1811,8 @@ public class Dfp implements RealFieldElement<Dfp> {
continue;
}
/* May have a good one here, check more thoroughly. Basically
its a good one if it is less than the divisor */
/* May have a good one here, check more thoroughly. Basically its a good
* one if it is less than the divisor */
trialgood = false; // assume false
for (int i = mant.length - 1; i >= 0; i--) {
if (divisor.mant[i] > remainder[i]) {
@ -1840,7 +1828,7 @@ public class Dfp implements RealFieldElement<Dfp> {
trialgood = false;
}
if (trialgood == false) {
if (!trialgood) {
min = trial + 1;
}
}
@ -2098,8 +2086,8 @@ public class Dfp implements RealFieldElement<Dfp> {
* @return string representation of the instance in scientific notation
*/
protected String dfp2sci() {
char rawdigits[] = new char[mant.length * 4];
char outputbuffer[] = new char[mant.length * 4 + 20];
char[] rawdigits = new char[mant.length * 4];
char[] outputbuffer = new char[mant.length * 4 + 20];
int p;
int q;
int e;
@ -2143,7 +2131,7 @@ public class Dfp implements RealFieldElement<Dfp> {
outputbuffer[q++] = '0';
outputbuffer[q++] = 'e';
outputbuffer[q++] = '0';
return new String(outputbuffer, 0, 5);
return String.valueOf(outputbuffer, 0, 5);
}
outputbuffer[q++] = 'e';
@ -2157,8 +2145,9 @@ public class Dfp implements RealFieldElement<Dfp> {
}
// Find the largest p such that p < e
for (p = 1000000000; p > ae; p /= 10) {
// nothing to do
p = 1000000000;
while (p > ae) {
p /= 10;
}
if (e < 0) {
@ -2171,15 +2160,14 @@ public class Dfp implements RealFieldElement<Dfp> {
p /= 10;
}
return new String(outputbuffer, 0, q);
return String.valueOf(outputbuffer, 0, q);
}
/** Convert an instance to a string using normal notation.
* @return string representation of the instance in normal notation
*/
protected String dfp2string() {
char buffer[] = new char[mant.length*4 + 20];
char[] buffer = new char[mant.length * 4 + 20];
int p = 1;
int q;
int e = exp;
@ -2244,8 +2232,7 @@ public class Dfp implements RealFieldElement<Dfp> {
buffer[--q] = '-';
}
return new String(buffer, q, p - q);
return String.valueOf(buffer, q, p - q);
}
/** Raises a trap. This does not set the corresponding flag however.
@ -2412,13 +2399,12 @@ public class Dfp implements RealFieldElement<Dfp> {
result = dotrap(DfpField.FLAG_INEXACT, NEXT_AFTER_TRAP, x, result);
}
if (result.equals(getZero()) && this.equals(getZero()) == false) {
if (result.equals(getZero()) && !this.equals(getZero())) {
field.setIEEEFlagsBits(DfpField.FLAG_INEXACT);
result = dotrap(DfpField.FLAG_INEXACT, NEXT_AFTER_TRAP, x, result);
}
return result;
}
/** Convert the instance into a double.
@ -2479,7 +2465,7 @@ public class Dfp implements RealFieldElement<Dfp> {
}
y = y.multiply(newInstance(4503599627370496l)).rint();
y = y.multiply(newInstance(4503599627370496L)).rint();
String str = y.toString();
str = str.substring(0, str.length() - 1);
long mantissa = Long.parseLong(str);
@ -2508,7 +2494,6 @@ public class Dfp implements RealFieldElement<Dfp> {
}
return x;
}
/** Convert the instance into a split double.
@ -2516,7 +2501,7 @@ public class Dfp implements RealFieldElement<Dfp> {
* @see #toDouble()
*/
public double[] toSplitDouble() {
double split[] = new double[2];
double[] split = new double[2];
long mask = 0xffffffffc0000000L;
split[0] = Double.longBitsToDouble(Double.doubleToLongBits(toDouble()) & mask);

View File

@ -357,7 +357,7 @@ public class DfpDec extends Dfp {
result = dotrap(DfpField.FLAG_INEXACT, trapName, x, result);
}
if (result.equals(getZero()) && this.equals(getZero()) == false) {
if (result.equals(getZero()) && !this.equals(getZero())) {
getField().setIEEEFlagsBits(DfpField.FLAG_INEXACT);
result = dotrap(DfpField.FLAG_INEXACT, trapName, x, result);
}

View File

@ -529,7 +529,7 @@ public class DfpField implements Field<Dfp> {
* @return an array of two {@link Dfp Dfp} instances which sum equals a
*/
private Dfp[] split(final String a) {
Dfp result[] = new Dfp[2];
Dfp[] result = new Dfp[2];
boolean leading = true;
int sp = 0;
int sig = 0;
@ -558,7 +558,7 @@ public class DfpField implements Field<Dfp> {
}
}
result[0] = new Dfp(this, new String(buf, 0, sp));
result[0] = new Dfp(this, String.valueOf(buf, 0, sp));
for (int i = 0; i < buf.length; i++) {
buf[i] = a.charAt(i);
@ -567,10 +567,9 @@ public class DfpField implements Field<Dfp> {
}
}
result[1] = new Dfp(this, new String(buf));
result[1] = new Dfp(this, String.valueOf(buf));
return result;
}
/** Recompute the high precision string constants.

View File

@ -21,7 +21,7 @@ package org.apache.commons.math4.legacy.core.dfp;
* The constants are defined in {@link DfpField}
* @since 2.2
*/
public class DfpMath {
public final class DfpMath {
/** Name for traps triggered by pow. */
private static final String POW_TRAP = "pow";
@ -42,7 +42,7 @@ public class DfpMath {
* @return an array of two {@link Dfp} which sum is a
*/
protected static Dfp[] split(final DfpField field, final String a) {
Dfp result[] = new Dfp[2];
Dfp[] result = new Dfp[2];
char[] buf;
boolean leading = true;
int sp = 0;
@ -72,7 +72,7 @@ public class DfpMath {
}
}
result[0] = field.newDfp(new String(buf, 0, sp));
result[0] = field.newDfp(String.valueOf(buf, 0, sp));
for (int i = 0; i < buf.length; i++) {
buf[i] = a.charAt(i);
@ -81,7 +81,7 @@ public class DfpMath {
}
}
result[1] = field.newDfp(new String(buf));
result[1] = field.newDfp(String.valueOf(buf));
return result;
}
@ -199,7 +199,6 @@ public class DfpMath {
}
return result[0];
}
/** Raises base to the power a by successive squaring.
@ -207,8 +206,7 @@ public class DfpMath {
* @param a power
* @return base<sup>a</sup>
*/
public static Dfp pow(Dfp base, int a)
{
public static Dfp pow(Dfp base, int a) {
boolean invert = false;
Dfp result = base.getOne();
@ -250,7 +248,6 @@ public class DfpMath {
}
return base.newInstance(result);
}
/** Computes e to the given power.
@ -374,7 +371,6 @@ public class DfpMath {
spz[1] = spz[1].add(spy[1]);
return a.newInstance(spz[0].add(spz[1]));
}
/** Computes the natural log of a number between 0 and 2.
@ -434,7 +430,7 @@ public class DfpMath {
* @param a number from which logarithm is requested, in split form
* @return log(a)
*/
protected static Dfp[] logInternal(final Dfp a[]) {
protected static Dfp[] logInternal(final Dfp[] a) {
/* Now we want to compute x = (a-1)/(a+1) but this is prone to
* loss of precision. So instead, compute x = (a/4 - 1/4) / (a/4 + 1/4)
@ -669,7 +665,7 @@ public class DfpMath {
* @param a number from which sine is desired, in split form
* @return sin(a)
*/
protected static Dfp sinInternal(Dfp a[]) {
protected static Dfp sinInternal(Dfp[] a) {
Dfp c = a[0].add(a[1]);
Dfp y = c;
@ -699,7 +695,7 @@ public class DfpMath {
* @param a number from which cosine is desired, in split form
* @return cos(a)
*/
protected static Dfp cosInternal(Dfp a[]) {
protected static Dfp cosInternal(Dfp[] a) {
final Dfp one = a[0].getOne();
@ -759,7 +755,7 @@ public class DfpMath {
if (x.lessThan(pi.divide(4))) {
y = sinInternal(split(x));
} else {
final Dfp c[] = new Dfp[2];
final Dfp[] c = new Dfp[2];
final Dfp[] piSplit = a.getField().getPiSplit();
c[0] = piSplit[0].divide(2).subtract(x);
c[1] = piSplit[1].divide(2);
@ -803,13 +799,13 @@ public class DfpMath {
Dfp y;
if (x.lessThan(pi.divide(4))) {
Dfp c[] = new Dfp[2];
Dfp[] c = new Dfp[2];
c[0] = x;
c[1] = zero;
y = cosInternal(c);
} else {
final Dfp c[] = new Dfp[2];
final Dfp[] c = new Dfp[2];
final Dfp[] piSplit = a.getField().getPiSplit();
c[0] = piSplit[0].divide(2).subtract(x);
c[1] = piSplit[1].divide(2);
@ -857,7 +853,7 @@ public class DfpMath {
}
/** computes the arc tangent of the argument
/** Computes the arc tangent of the argument.
*
* Uses the typical taylor series
*
@ -893,7 +889,7 @@ public class DfpMath {
}
if (x.greaterThan(ty)) {
Dfp sty[] = new Dfp[2];
Dfp[] sty = new Dfp[2];
sub = true;
sty[0] = sqr2Split[0].subtract(one);

View File

@ -85,7 +85,7 @@ import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
* </ul>
* @since 2.2
*/
public class AccurateMath {
public final class AccurateMath {
/** Archimede's constant PI, ratio of circle circumference to diameter. */
public static final double PI = 105414357.0 / 33554432.0 + 1.984187159361080883e-9;
@ -101,7 +101,7 @@ public class AccurateMath {
/** Exponential fractions table length. */
static final int EXP_FRAC_TABLE_LEN = 1025; // 0, 1/1024, ... 1024/1024
/** StrictMath.log(Double.MAX_VALUE): {@value} */
/** StrictMath.log(Double.MAX_VALUE): {@value}. */
private static final double LOG_MAX_VALUE = StrictMath.log(Double.MAX_VALUE);
/** Indicator for tables initialization.
@ -120,7 +120,7 @@ public class AccurateMath {
private static final double LN_2_B = 1.17304635250823482e-7;
/** Coefficients for log, when input 0.99 < x < 1.01. */
private static final double LN_QUICK_COEF[][] = {
private static final double[][] LN_QUICK_COEF = {
{1.0, 5.669184079525E-24},
{-0.25, -0.25},
{0.3333333134651184, 1.986821492305628E-8},
@ -133,7 +133,7 @@ public class AccurateMath {
};
/** Coefficients for log in the range of 1.0 < x < 1.0 + 2^-10. */
private static final double LN_HI_PREC_COEF[][] = {
private static final double[][] LN_HI_PREC_COEF = {
{1.0, -6.032174644509064E-23},
{-0.25, -0.25},
{0.3333333134651184, 1.9868161777724352E-8},
@ -146,7 +146,7 @@ public class AccurateMath {
private static final int SINE_TABLE_LEN = 14;
/** Sine table (high bits). */
private static final double SINE_TABLE_A[] =
private static final double[] SINE_TABLE_A =
{
+0.0d,
+0.1246747374534607d,
@ -165,7 +165,7 @@ public class AccurateMath {
};
/** Sine table (low bits). */
private static final double SINE_TABLE_B[] =
private static final double[] SINE_TABLE_B =
{
+0.0d,
-4.068233003401932E-9d,
@ -184,7 +184,7 @@ public class AccurateMath {
};
/** Cosine table (high bits). */
private static final double COSINE_TABLE_A[] =
private static final double[] COSINE_TABLE_A =
{
+1.0d,
+0.9921976327896118d,
@ -203,7 +203,7 @@ public class AccurateMath {
};
/** Cosine table (low bits). */
private static final double COSINE_TABLE_B[] =
private static final double[] COSINE_TABLE_B =
{
+0.0d,
+3.4439717236742845E-8d,
@ -223,7 +223,7 @@ public class AccurateMath {
/** Tangent table, used by atan() (high bits). */
private static final double TANGENT_TABLE_A[] =
private static final double[] TANGENT_TABLE_A =
{
+0.0d,
+0.1256551444530487d,
@ -242,7 +242,7 @@ public class AccurateMath {
};
/** Tangent table, used by atan() (low bits). */
private static final double TANGENT_TABLE_B[] =
private static final double[] TANGENT_TABLE_B =
{
+0.0d,
-7.877917738262007E-9d,
@ -261,7 +261,7 @@ public class AccurateMath {
};
/** Bits of 1/(2*pi), need for reducePayneHanek(). */
private static final long RECIP_2PI[] = new long[] {
private static final long[] RECIP_2PI = new long[] {
(0x28be60dbL << 32) | 0x9391054aL,
(0x7f09d5f4L << 32) | 0x7d4d3770L,
(0x36d8a566L << 32) | 0x4f10e410L,
@ -279,10 +279,10 @@ public class AccurateMath {
(0xd3d18fd9L << 32) | 0xa797fa8bL,
(0x5d49eeb1L << 32) | 0xfaf97c5eL,
(0xcf41ce7dL << 32) | 0xe294a4baL,
0x9afed7ecL << 32 };
(0x9afed7ecL << 32)};
/** Bits of pi/4, need for reducePayneHanek(). */
private static final long PI_O_4_BITS[] = new long[] {
private static final long[] PI_O_4_BITS = new long[] {
(0xc90fdaa2L << 32) | 0x2168c234L,
(0xc4c6628bL << 32) | 0x80dc1cd1L };
@ -290,10 +290,11 @@ public class AccurateMath {
* This is used by sinQ, because its faster to do a table lookup than
* a multiply in this time-critical routine
*/
private static final double EIGHTHS[] = {0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1.0, 1.125, 1.25, 1.375, 1.5, 1.625};
private static final double[] EIGHTHS = {
0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1.0, 1.125, 1.25, 1.375, 1.5, 1.625};
/** Table of 2^((n+2)/3) */
private static final double CBRTTWO[] = { 0.6299605249474366,
/** Table of 2^((n+2)/3). */
private static final double[] CBRTTWO = {0.6299605249474366,
0.7937005259840998,
1.0,
1.2599210498948732,
@ -312,14 +313,14 @@ public class AccurateMath {
*/
private static final long HEX_40000000 = 0x40000000L; // 1073741824L
/** Mask used to clear low order 30 bits */
/** Mask used to clear low order 30 bits. */
private static final long MASK_30BITS = -1L - (HEX_40000000 - 1); // 0xFFFFFFFFC0000000L;
/** Mask used to clear the non-sign part of an int. */
private static final int MASK_NON_SIGN_INT = 0x7fffffff;
/** Mask used to clear the non-sign part of a long. */
private static final long MASK_NON_SIGN_LONG = 0x7fffffffffffffffl;
private static final long MASK_NON_SIGN_LONG = 0x7fffffffffffffffL;
/** Mask used to extract exponent from double bits. */
private static final long MASK_DOUBLE_EXPONENT = 0x7ff0000000000000L;
@ -330,7 +331,7 @@ public class AccurateMath {
/** Mask used to add implicit high order bit for normalized double. */
private static final long IMPLICIT_HIGH_BIT = 0x0010000000000000L;
/** 2^52 - double numbers this large must be integral (no fraction) or NaN or Infinite */
/** 2^52 - double numbers this large must be integral (no fraction) or NaN or Infinite. */
private static final double TWO_POWER_52 = 4503599627370496.0;
/** Constant: {@value}. */
@ -369,7 +370,7 @@ public class AccurateMath {
private static final double F_1_4 = 1d / 4d;
/**
* Private Constructor
* Private Constructor.
*/
private AccurateMath() {}
@ -432,7 +433,7 @@ public class AccurateMath {
}
}
final double hiPrec[] = new double[2];
final double[] hiPrec = new double[2];
if (x < 0.0) {
x = -x;
}
@ -514,7 +515,7 @@ public class AccurateMath {
double result;
if (x > 0.25) {
double hiPrec[] = new double[2];
double[] hiPrec = new double[2];
exp(x, 0.0, hiPrec);
double ya = hiPrec[0] + hiPrec[1];
@ -548,9 +549,8 @@ public class AccurateMath {
result = ya + yb;
result *= 0.5;
}
else {
double hiPrec[] = new double[2];
} else {
double[] hiPrec = new double[2];
expm1(x, hiPrec);
double ya = hiPrec[0] + hiPrec[1];
@ -630,7 +630,7 @@ public class AccurateMath {
double result;
if (x >= 0.5) {
double hiPrec[] = new double[2];
double[] hiPrec = new double[2];
// tanh(x) = (exp(2x) - 1) / (exp(2x) + 1)
exp(x * 2.0, 0.0, hiPrec);
@ -670,9 +670,8 @@ public class AccurateMath {
ratiob += -db * na / da / da;
result = ratioa + ratiob;
}
else {
double hiPrec[] = new double[2];
} else {
double[] hiPrec = new double[2];
// tanh(x) = expm1(2x) / (expm1(2x) + 2)
expm1(x * 2.0, hiPrec);
@ -997,7 +996,8 @@ public class AccurateMath {
return result;
}
/** Compute exp(x) - 1
/**Compute exp(x) - 1.
*
* @param x number to compute shifted exponential
* @return exp(x) - 1
*/
@ -1005,12 +1005,12 @@ public class AccurateMath {
return expm1(x, null);
}
/** Internal helper method for expm1
/** Internal helper method for expm1.
* @param x number to compute shifted exponential
* @param hiPrecOut receive high precision result for -1.0 < x < 1.0
* @return exp(x) - 1
*/
private static double expm1(double x, double hiPrecOut[]) {
private static double expm1(double x, double[] hiPrecOut) {
if (Double.isNaN(x) || x == 0.0) { // NaN or zero
return x;
}
@ -1018,7 +1018,7 @@ public class AccurateMath {
if (x <= -1.0 || x >= 1.0) {
// If not between +/- 1.0
//return exp(x) - 1.0;
double hiPrec[] = new double[2];
double[] hiPrec = new double[2];
exp(x, 0.0, hiPrec);
if (x > 0.0) {
return -1.0 + hiPrec[0] + hiPrec[1];
@ -1040,7 +1040,6 @@ public class AccurateMath {
negative = true;
}
{
int intFrac = (int) (x * 1024.0);
double tempA = ExpFracTable.EXP_FRAC_TABLE_A[intFrac] - 1.0;
double tempB = ExpFracTable.EXP_FRAC_TABLE_B[intFrac];
@ -1054,7 +1053,6 @@ public class AccurateMath {
baseB = tempB + (tempA - baseA);
epsilon = x - intFrac / 1024.0;
}
/* Compute expm1(epsilon) */
@ -1066,7 +1064,7 @@ public class AccurateMath {
zb *= epsilon;
double za = epsilon;
double temp = za + zb;
temp = za + zb;
zb = -(temp - za - zb);
za = temp;
@ -1433,7 +1431,7 @@ public class AccurateMath {
* @return log10(x)
*/
public static double log10(final double x) {
final double hiPrec[] = new double[2];
final double[] hiPrec = new double[2];
final double lores = log(x, hiPrec);
if (Double.isInfinite(lores)) { // don't allow this to be converted to NaN
@ -1573,7 +1571,7 @@ public class AccurateMath {
final double yb = y - ya;
/* Compute ln(x) */
final double lns[] = new double[2];
final double[] lns = new double[2];
final double lores = log(x, lns);
if (Double.isInfinite(lores)) { // don't allow this to be converted to NaN
return lores;
@ -1776,8 +1774,7 @@ public class AccurateMath {
* @param x a number smaller than 1/16
* @return sin(x) - x
*/
private static double polySine(final double x)
{
private static double polySine(final double x) {
double x2 = x * x;
double p = 2.7553817452272217E-6;
@ -2107,8 +2104,7 @@ public class AccurateMath {
* @param x number to reduce
* @param result placeholder where to put the result
*/
private static void reducePayneHanek(double x, double result[])
{
private static void reducePayneHanek(double x, double[] result) {
/* Convert input double to bits */
long inbits = Double.doubleToRawLongBits(x);
int exponent = (int) ((inbits >> 52) & 0x7ff) - 1023;
@ -2356,7 +2352,7 @@ public class AccurateMath {
// PI * (2**20)
// Argument too big for CodyWaite reduction. Must use
// PayneHanek.
double reduceResults[] = new double[3];
double[] reduceResults = new double[3];
reducePayneHanek(xa, reduceResults);
quadrant = ((int) reduceResults[0]) & 3;
xa = reduceResults[1];
@ -2411,7 +2407,7 @@ public class AccurateMath {
// PI * (2**20)
// Argument too big for CodyWaite reduction. Must use
// PayneHanek.
double reduceResults[] = new double[3];
double[] reduceResults = new double[3];
reducePayneHanek(xa, reduceResults);
quadrant = ((int) reduceResults[0]) & 3;
xa = reduceResults[1];
@ -2476,7 +2472,7 @@ public class AccurateMath {
// PI * (2**20)
// Argument too big for CodyWaite reduction. Must use
// PayneHanek.
double reduceResults[] = new double[3];
double[] reduceResults = new double[3];
reducePayneHanek(xa, reduceResults);
quadrant = ((int) reduceResults[0]) & 3;
xa = reduceResults[1];
@ -2518,7 +2514,7 @@ public class AccurateMath {
}
/**
* Arctangent function
* Arctangent function.
* @param x a number
* @return atan(x)
*/
@ -2680,7 +2676,7 @@ public class AccurateMath {
}
/**
* Two arguments arctangent function
* Two arguments arctangent function.
* @param y ordinate
* @param x abscissa
* @return phase angle of point (x,y) between {@code -PI} and {@code PI}
@ -2750,8 +2746,7 @@ public class AccurateMath {
}
}
if (x == Double.NEGATIVE_INFINITY)
{
if (x == Double.NEGATIVE_INFINITY) {
if (y > 0.0 || 1 / y > 0.0) {
return Math.PI;
}
@ -2991,8 +2986,7 @@ public class AccurateMath {
int exp3 = exponent / 3;
/* p2 will be the nearest power of 2 to x with its exponent divided by 3 */
double p2 = Double.longBitsToDouble((inbits & 0x8000000000000000L) |
(long)(((exp3 + 1023) & 0x7ff)) << 52);
double p2 = Double.longBitsToDouble((inbits & 0x8000000000000000L) | (long) (((exp3 + 1023) & 0x7ff)) << 52);
/* This will be a number between 1 and 2 */
final double mant = Double.longBitsToDouble((inbits & 0x000fffffffffffffL) | 0x3ff0000000000000L);
@ -3045,12 +3039,11 @@ public class AccurateMath {
}
/**
* Convert degrees to radians, with error of less than 0.5 ULP
* Convert degrees to radians, with error of less than 0.5 ULP.
* @param x angle in degrees
* @return x converted into radians
*/
public static double toRadians(double x)
{
public static double toRadians(double x) {
if (Double.isInfinite(x) || x == 0.0) { // Matches +/- 0.0; return correct sign
return x;
}
@ -3070,12 +3063,11 @@ public class AccurateMath {
}
/**
* Convert radians to degrees, with error of less than 0.5 ULP
* Convert radians to degrees, with error of less than 0.5 ULP.
* @param x angle in radians
* @return x converted into degrees
*/
public static double toDegrees(double x)
{
public static double toDegrees(double x) {
if (Double.isInfinite(x) || x == 0.0) { // Matches +/- 0.0; return correct sign
return x;
}
@ -3357,7 +3349,6 @@ public class AccurateMath {
* @return the next machine representable number in the specified direction
*/
public static double nextAfter(double d, double direction) {
// handling of some important special cases
if (Double.isNaN(d) || Double.isNaN(direction)) {
return Double.NaN;
@ -3378,7 +3369,6 @@ public class AccurateMath {
} else {
return Double.longBitsToDouble(sign | ((bits & 0x7fffffffffffffffL) - 1));
}
}
/**
@ -3435,7 +3425,6 @@ public class AccurateMath {
} else {
return Float.intBitsToFloat(sign | ((bits & 0x7fffffff) - 1));
}
}
/** Get the largest whole number smaller than x.
@ -3565,7 +3554,7 @@ public class AccurateMath {
}
}
/** Compute the minimum of two values
/** Compute the minimum of two values.
* @param a first value
* @param b second value
* @return a if a is lesser or equal to b, b otherwise
@ -3574,7 +3563,7 @@ public class AccurateMath {
return (a <= b) ? a : b;
}
/** Compute the minimum of two values
/** Compute the minimum of two values.
* @param a first value
* @param b second value
* @return a if a is lesser or equal to b, b otherwise
@ -3583,7 +3572,7 @@ public class AccurateMath {
return (a <= b) ? a : b;
}
/** Compute the minimum of two values
/** Compute the minimum of two values.
* @param a first value
* @param b second value
* @return a if a is lesser or equal to b, b otherwise
@ -3608,7 +3597,7 @@ public class AccurateMath {
return b;
}
/** Compute the minimum of two values
/** Compute the minimum of two values.
* @param a first value
* @param b second value
* @return a if a is lesser or equal to b, b otherwise
@ -3633,7 +3622,7 @@ public class AccurateMath {
return b;
}
/** Compute the maximum of two values
/** Compute the maximum of two values.
* @param a first value
* @param b second value
* @return b if a is lesser or equal to b, a otherwise
@ -3642,7 +3631,7 @@ public class AccurateMath {
return (a <= b) ? b : a;
}
/** Compute the maximum of two values
/** Compute the maximum of two values.
* @param a first value
* @param b second value
* @return b if a is lesser or equal to b, a otherwise
@ -3651,7 +3640,7 @@ public class AccurateMath {
return (a <= b) ? b : a;
}
/** Compute the maximum of two values
/** Compute the maximum of two values.
* @param a first value
* @param b second value
* @return b if a is lesser or equal to b, a otherwise
@ -3676,7 +3665,7 @@ public class AccurateMath {
return a;
}
/** Compute the maximum of two values
/** Compute the maximum of two values.
* @param a first value
* @param b second value
* @return b if a is lesser or equal to b, a otherwise
@ -3721,7 +3710,6 @@ public class AccurateMath {
} else if (Double.isNaN(x) || Double.isNaN(y)) {
return Double.NaN;
} else {
final int expX = getExponent(x);
final int expY = getExponent(y);
if (expX > expY + 27) {
@ -3731,7 +3719,6 @@ public class AccurateMath {
// x is neglectible with respect to y
return abs(y);
} else {
// find an intermediate scale to avoid both overflow and underflow
final int middleExp = (expX + expY) / 2;
@ -3744,9 +3731,7 @@ public class AccurateMath {
// remove scaling
return scalb(scaledH, middleExp);
}
}
}
@ -3784,7 +3769,7 @@ public class AccurateMath {
}
}
/** Convert a long to integer, detecting overflows
/** Convert a long to integer, detecting overflows.
* @param n number to convert to int
* @return integer with same value as n if no overflows occur
* @exception MathArithmeticException if n cannot fit into an int
@ -3804,13 +3789,10 @@ public class AccurateMath {
* @since 3.4
*/
public static int incrementExact(final int n) throws MathArithmeticException {
if (n == Integer.MAX_VALUE) {
throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_ADDITION, n, 1);
}
return n + 1;
}
/** Increment a number, detecting overflows.
@ -3820,13 +3802,10 @@ public class AccurateMath {
* @since 3.4
*/
public static long incrementExact(final long n) throws MathArithmeticException {
if (n == Long.MAX_VALUE) {
throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_ADDITION, n, 1);
}
return n + 1;
}
/** Decrement a number, detecting overflows.
@ -3836,13 +3815,10 @@ public class AccurateMath {
* @since 3.4
*/
public static int decrementExact(final int n) throws MathArithmeticException {
if (n == Integer.MIN_VALUE) {
throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_SUBTRACTION, n, 1);
}
return n - 1;
}
/** Decrement a number, detecting overflows.
@ -3852,13 +3828,10 @@ public class AccurateMath {
* @since 3.4
*/
public static long decrementExact(final long n) throws MathArithmeticException {
if (n == Long.MIN_VALUE) {
throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_SUBTRACTION, n, 1);
}
return n - 1;
}
/** Add two numbers, detecting overflows.
@ -3869,7 +3842,6 @@ public class AccurateMath {
* @since 3.4
*/
public static int addExact(final int a, final int b) throws MathArithmeticException {
// compute sum
final int sum = a + b;
@ -3879,7 +3851,6 @@ public class AccurateMath {
}
return sum;
}
/** Add two numbers, detecting overflows.
@ -3890,7 +3861,6 @@ public class AccurateMath {
* @since 3.4
*/
public static long addExact(final long a, final long b) throws MathArithmeticException {
// compute sum
final long sum = a + b;
@ -3900,7 +3870,6 @@ public class AccurateMath {
}
return sum;
}
/** Subtract two numbers, detecting overflows.
@ -3911,7 +3880,6 @@ public class AccurateMath {
* @since 3.4
*/
public static int subtractExact(final int a, final int b) {
// compute subtraction
final int sub = a - b;
@ -3921,7 +3889,6 @@ public class AccurateMath {
}
return sub;
}
/** Subtract two numbers, detecting overflows.
@ -3932,7 +3899,6 @@ public class AccurateMath {
* @since 3.4
*/
public static long subtractExact(final long a, final long b) {
// compute subtraction
final long sub = a - b;
@ -3942,7 +3908,6 @@ public class AccurateMath {
}
return sub;
}
/** Multiply two numbers, detecting overflows.
@ -3969,9 +3934,9 @@ public class AccurateMath {
* @since 3.4
*/
public static long multiplyExact(final long a, final long b) {
if (((b > 0l) && (a > Long.MAX_VALUE / b || a < Long.MIN_VALUE / b)) ||
((b < -1l) && (a > Long.MIN_VALUE / b || a < Long.MAX_VALUE / b)) ||
((b == -1l) && (a == Long.MIN_VALUE))) {
if (((b > 0L) && (a > Long.MAX_VALUE / b || a < Long.MIN_VALUE / b)) ||
((b < -1L) && (a > Long.MIN_VALUE / b || a < Long.MAX_VALUE / b)) ||
((b == -1L) && (a == Long.MIN_VALUE))) {
throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_MULTIPLICATION, a, b);
}
return a * b;
@ -3991,7 +3956,6 @@ public class AccurateMath {
* @since 3.4
*/
public static int floorDiv(final int a, final int b) throws MathArithmeticException {
if (b == 0) {
throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR);
}
@ -4004,7 +3968,6 @@ public class AccurateMath {
// a and b have opposite signs and division is not exact
return (a / b) - 1;
}
}
/** Finds q such that a = q b + r with 0 &lt;= r &lt; b if b &gt; 0 and b &lt; r &lt;= 0 if b &lt; 0.
@ -4021,20 +3984,18 @@ public class AccurateMath {
* @since 3.4
*/
public static long floorDiv(final long a, final long b) throws MathArithmeticException {
if (b == 0l) {
if (b == 0L) {
throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR);
}
final long m = a % b;
if ((a ^ b) >= 0l || m == 0l) {
if ((a ^ b) >= 0L || m == 0L) {
// a an b have same sign, or division is exact
return a / b;
} else {
// a and b have opposite signs and division is not exact
return (a / b) - 1l;
return (a / b) - 1L;
}
}
/** Finds r such that a = q b + r with 0 &lt;= r &lt; b if b &gt; 0 and b &lt; r &lt;= 0 if b &lt; 0.
@ -4051,7 +4012,6 @@ public class AccurateMath {
* @since 3.4
*/
public static int floorMod(final int a, final int b) throws MathArithmeticException {
if (b == 0) {
throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR);
}
@ -4064,7 +4024,6 @@ public class AccurateMath {
// a and b have opposite signs and division is not exact
return b + m;
}
}
/** Finds r such that a = q b + r with 0 &lt;= r &lt; b if b &gt; 0 and b &lt; r &lt;= 0 if b &lt; 0.
@ -4081,20 +4040,18 @@ public class AccurateMath {
* @since 3.4
*/
public static long floorMod(final long a, final long b) {
if (b == 0l) {
if (b == 0L) {
throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR);
}
final long m = a % b;
if ((a ^ b) >= 0l || m == 0l) {
if ((a ^ b) >= 0L || m == 0L) {
// a an b have same sign, or division is exact
return m;
} else {
// a and b have opposite signs and division is not exact
return b + m;
}
}
/**
@ -4193,7 +4150,7 @@ public class AccurateMath {
* exp(x) = expIntTableA[x + EXP_INT_TABLE_MAX_INDEX] + expIntTableB[x+EXP_INT_TABLE_MAX_INDEX].
*/
private static final double[] EXP_INT_TABLE_A;
/** Exponential evaluated at integer values,
/** Exponential evaluated at integer values.
* exp(x) = expIntTableA[x + EXP_INT_TABLE_MAX_INDEX] + expIntTableB[x+EXP_INT_TABLE_MAX_INDEX]
*/
private static final double[] EXP_INT_TABLE_B;
@ -4203,8 +4160,8 @@ public class AccurateMath {
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];
final double[] tmp = new double[2];
final double[] recip = new double[2];
// Populate expIntTable
for (int i = 0; i < AccurateMath.EXP_INT_TABLE_MAX_INDEX; i++) {
@ -4243,7 +4200,7 @@ public class AccurateMath {
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];
final double[] tmp = new double[2];
// Populate expFracTable
final double factor = 1d / (EXP_FRAC_TABLE_LEN - 1);
@ -4281,11 +4238,11 @@ public class AccurateMath {
/** Enclose the Cody/Waite reduction (used in "sin", "cos" and "tan"). */
private static class CodyWaite {
/** k */
/** k. */
private final int finalK;
/** remA */
/** remA. */
private final double finalRemA;
/** remB */
/** remB. */
private final double finalRemB;
/**

View File

@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
/** Class used to compute the classical functions tables.
* @since 3.0
*/
class AccurateMathCalc {
final class AccurateMathCalc {
/**
* 0x40000000 - used to split a double into two parts, both with the low order bits cleared.
@ -32,7 +32,7 @@ class AccurateMathCalc {
private static final long HEX_40000000 = 0x40000000L; // 1073741824L
/** Factorial table, for Taylor series expansions. 0!, 1!, 2!, ... 19! */
private static final double FACT[] = new double[]
private static final double[] FACT = new double[]
{
+1.0d, // 0
+1.0d, // 1
@ -57,7 +57,7 @@ class AccurateMathCalc {
};
/** Coefficients for slowLog. */
private static final double LN_SPLIT_COEF[][] = {
private static final double[][] LN_SPLIT_COEF = {
{2.0, 0.0},
{0.6666666269302368, 3.9736429850260626E-8},
{0.3999999761581421, 2.3841857910019882E-8},
@ -101,7 +101,7 @@ class AccurateMathCalc {
private static void buildSinCosTables(double[] SINE_TABLE_A, double[] SINE_TABLE_B,
double[] COSINE_TABLE_A, double[] COSINE_TABLE_B,
int SINE_TABLE_LEN, double[] TANGENT_TABLE_A, double[] TANGENT_TABLE_B) {
final double result[] = new double[2];
final double[] result = new double[2];
/* Use taylor series for 0 <= x <= 6/8 */
for (int i = 0; i < 7; i++) {
@ -118,11 +118,11 @@ class AccurateMathCalc {
/* Use angle addition formula to complete table to 13/8, just beyond pi/2 */
for (int i = 7; i < SINE_TABLE_LEN; i++) {
double xs[] = new double[2];
double ys[] = new double[2];
double as[] = new double[2];
double bs[] = new double[2];
double temps[] = new double[2];
double[] xs = new double[2];
double[] ys = new double[2];
double[] as = new double[2];
double[] bs = new double[2];
double[] temps = new double[2];
if ((i & 1) == 0) {
// Even, use double angle
@ -174,9 +174,9 @@ class AccurateMathCalc {
/* Compute tangent = sine/cosine */
for (int i = 0; i < SINE_TABLE_LEN; i++) {
double xs[] = new double[2];
double ys[] = new double[2];
double as[] = new double[2];
double[] xs = new double[2];
double[] ys = new double[2];
double[] as = new double[2];
as[0] = COSINE_TABLE_A[i];
as[1] = COSINE_TABLE_B[i];
@ -191,7 +191,6 @@ class AccurateMathCalc {
TANGENT_TABLE_A[i] = as[0];
TANGENT_TABLE_B[i] = as[1];
}
}
/**
@ -202,18 +201,19 @@ class AccurateMathCalc {
* (may be null)
* @return cos(x)
*/
static double slowCos(final double x, final double result[]) {
static double slowCos(final double x, final double[] result) {
final double xs[] = new double[2];
final double ys[] = new double[2];
final double facts[] = new double[2];
final double as[] = new double[2];
final double[] xs = new double[2];
final double[] ys = new double[2];
final double[] facts = new double[2];
final double[] as = new double[2];
split(x, xs);
ys[0] = ys[1] = 0.0;
for (int i = FACT.length - 1; i >= 0; i--) {
splitMult(xs, ys, as);
ys[0] = as[0]; ys[1] = as[1];
ys[0] = as[0];
ys[1] = as[1];
if ((i & 1) != 0) { // skip odd entries
continue;
@ -247,17 +247,18 @@ class AccurateMathCalc {
* (may be null)
* @return sin(x)
*/
static double slowSin(final double x, final double result[]) {
final double xs[] = new double[2];
final double ys[] = new double[2];
final double facts[] = new double[2];
final double as[] = new double[2];
static double slowSin(final double x, final double[] result) {
final double[] xs = new double[2];
final double[] ys = new double[2];
final double[] facts = new double[2];
final double[] as = new double[2];
split(x, xs);
ys[0] = ys[1] = 0.0;
for (int i = FACT.length - 1; i >= 0; i--) {
splitMult(xs, ys, as);
ys[0] = as[0]; ys[1] = as[1];
ys[0] = as[0];
ys[1] = as[1];
if ((i & 1) == 0) { // Ignore even numbers
continue;
@ -285,17 +286,17 @@ class AccurateMathCalc {
/**
* For x between 0 and 1, returns exp(x), uses extended precision
* For x between 0 and 1, returns exp(x), uses extended precision.
* @param x argument of exponential
* @param result placeholder where to place exp(x) split in two terms
* for extra precision (i.e. exp(x) = result[0] + result[1]
* @return exp(x)
*/
static double slowexp(final double x, final double result[]) {
final double xs[] = new double[2];
final double ys[] = new double[2];
final double facts[] = new double[2];
final double as[] = new double[2];
static double slowexp(final double x, final double[] result) {
final double[] xs = new double[2];
final double[] ys = new double[2];
final double[] facts = new double[2];
final double[] as = new double[2];
split(x, xs);
ys[0] = ys[1] = 0.0;
@ -325,7 +326,7 @@ class AccurateMathCalc {
* @param d number to split
* @param split placeholder where to place the result
*/
private static void split(final double d, final double split[]) {
private static void split(final double d, final double[] split) {
if (d < 8e298 && d > -8e298) {
final double a = d * HEX_40000000;
split[0] = (d + a) - a;
@ -341,7 +342,7 @@ class AccurateMathCalc {
* @param a input/out array containing the split, changed
* on output
*/
private static void resplit(final double a[]) {
private static void resplit(final double[] a) {
final double c = a[0] + a[1];
final double d = -(c - a[0] - a[1]);
@ -361,7 +362,7 @@ class AccurateMathCalc {
* @param b second term of multiplication
* @param ans placeholder where to put the result
*/
private static void splitMult(double a[], double b[], double ans[]) {
private static void splitMult(double[] a, double[] b, double[] ans) {
ans[0] = a[0] * b[0];
ans[1] = a[0] * b[1] + a[1] * b[0] + a[1] * b[1];
@ -374,7 +375,7 @@ class AccurateMathCalc {
* @param b second term of addition
* @param ans placeholder where to put the result
*/
private static void splitAdd(final double a[], final double b[], final double ans[]) {
private static void splitAdd(final double[] a, final double[] b, final double[] ans) {
ans[0] = a[0] + b[0];
ans[1] = a[1] + b[1];
@ -399,7 +400,7 @@ class AccurateMathCalc {
* @param in initial number, in split form
* @param result placeholder where to put the result
*/
static void splitReciprocal(final double in[], final double result[]) {
static void splitReciprocal(final double[] in, final double[] result) {
final double b = 1.0 / 4194304.0;
final double a = 1.0 - b;
@ -434,10 +435,10 @@ class AccurateMathCalc {
* @param b second term of the multiplication
* @param result placeholder where to put the result
*/
private static void quadMult(final double a[], final double b[], final double result[]) {
final double xs[] = new double[2];
final double ys[] = new double[2];
final double zs[] = new double[2];
private static void quadMult(final double[] a, final double[] b, final double[] result) {
final double[] xs = new double[2];
final double[] ys = new double[2];
final double[] zs = new double[2];
/* a[0] * b[0] */
split(a[0], xs);
@ -488,11 +489,11 @@ class AccurateMathCalc {
* @param result placeholder where to put the result in extended precision
* @return exp(p) in standard precision (equal to result[0] + result[1])
*/
static double expint(int p, final double result[]) {
static double expint(int p, final double[] result) {
//double x = M_E;
final double xs[] = new double[2];
final double as[] = new double[2];
final double ys[] = new double[2];
final double[] xs = new double[2];
final double[] as = new double[2];
final double[] ys = new double[2];
//split(x, xs);
//xs[1] = (double)(2.7182818284590452353602874713526625L - xs[0]);
//xs[0] = 2.71827697753906250000;
@ -547,10 +548,10 @@ class AccurateMathCalc {
* @return log(xi)
*/
static double[] slowLog(double xi) {
double x[] = new double[2];
double x2[] = new double[2];
double y[] = new double[2];
double a[] = new double[2];
double[] x = new double[2];
double[] x2 = new double[2];
double[] y = new double[2];
double[] a = new double[2];
split(xi, x);
@ -654,5 +655,4 @@ class AccurateMathCalc {
throw new DimensionMismatchException(actual, expectedLen);
}
}
}

View File

@ -0,0 +1,21 @@
/*
* 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.
*/
/**
* Portable alternative to {@link java.lang.Math} and {@link java.lang.StrictMath}.
*/
package org.apache.commons.math4.legacy.core.jdkmath;

View File

@ -0,0 +1,21 @@
/*
* 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.
*/
/**
* Core math utilities.
*/
package org.apache.commons.math4.legacy.core;

View File

@ -391,7 +391,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
@Test
public void testLinearCombinationFaFa() {
UniformRandomProvider r = RandomSource.create(RandomSource.WELL_1024_A, 0xfafal);
UniformRandomProvider r = RandomSource.create(RandomSource.WELL_1024_A, 0xfafaL);
for (int i = 0; i < 50; ++i) {
double[] aD = generateDouble(r, 10);
double[] bD = generateDouble(r, 10);
@ -404,7 +404,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
@Test
public void testLinearCombinationDaFa() {
UniformRandomProvider r = RandomSource.create(RandomSource.WELL_1024_A, 0xdafal);
UniformRandomProvider r = RandomSource.create(RandomSource.WELL_1024_A, 0xdafaL);
for (int i = 0; i < 50; ++i) {
double[] aD = generateDouble(r, 10);
double[] bD = generateDouble(r, 10);
@ -416,7 +416,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
@Test
public void testLinearCombinationFF2() {
UniformRandomProvider r = RandomSource.create(RandomSource.WELL_1024_A, 0xff2l);
UniformRandomProvider r = RandomSource.create(RandomSource.WELL_1024_A, 0xff2L);
for (int i = 0; i < 50; ++i) {
double[] aD = generateDouble(r, 2);
double[] bD = generateDouble(r, 2);
@ -431,7 +431,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
@Test
public void testLinearCombinationDF2() {
UniformRandomProvider r = RandomSource.create(RandomSource.WELL_1024_A, 0xdf2l);
UniformRandomProvider r = RandomSource.create(RandomSource.WELL_1024_A, 0xdf2L);
for (int i = 0; i < 50; ++i) {
double[] aD = generateDouble(r, 2);
double[] bD = generateDouble(r, 2);
@ -445,7 +445,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
@Test
public void testLinearCombinationFF3() {
UniformRandomProvider r = RandomSource.create(RandomSource.WELL_1024_A, 0xff3l);
UniformRandomProvider r = RandomSource.create(RandomSource.WELL_1024_A, 0xff3L);
for (int i = 0; i < 50; ++i) {
double[] aD = generateDouble(r, 3);
double[] bD = generateDouble(r, 3);
@ -461,7 +461,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
@Test
public void testLinearCombinationDF3() {
UniformRandomProvider r = RandomSource.create(RandomSource.WELL_1024_A, 0xdf3l);
UniformRandomProvider r = RandomSource.create(RandomSource.WELL_1024_A, 0xdf3L);
for (int i = 0; i < 50; ++i) {
double[] aD = generateDouble(r, 3);
double[] bD = generateDouble(r, 3);
@ -476,7 +476,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
@Test
public void testLinearCombinationFF4() {
UniformRandomProvider r = RandomSource.create(RandomSource.WELL_1024_A, 0xff4l);
UniformRandomProvider r = RandomSource.create(RandomSource.WELL_1024_A, 0xff4L);
for (int i = 0; i < 50; ++i) {
double[] aD = generateDouble(r, 4);
double[] bD = generateDouble(r, 4);
@ -493,7 +493,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
@Test
public void testLinearCombinationDF4() {
UniformRandomProvider r = RandomSource.create(RandomSource.WELL_1024_A, 0xdf4l);
UniformRandomProvider r = RandomSource.create(RandomSource.WELL_1024_A, 0xdf4L);
for (int i = 0; i < 50; ++i) {
double[] aD = generateDouble(r, 4);
double[] bD = generateDouble(r, 4);
@ -537,7 +537,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
Assert.assertTrue(t1a.hashCode() != t2.hashCode());
}
private double[] generateDouble (final UniformRandomProvider r, int n) {
private static double[] generateDouble(final UniformRandomProvider r, int n) {
double[] a = new double[n];
for (int i = 0; i < n; ++i) {
a[i] = r.nextDouble();

View File

@ -1,15 +1,18 @@
/*
* 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.
* 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.
*/
package org.apache.commons.math4.legacy.core;

View File

@ -1,15 +1,18 @@
/*
* 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.
* 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.
*/
package org.apache.commons.math4.legacy.core;
@ -38,7 +41,6 @@ public class MathArraysTest {
private double[] testArray = {0, 1, 2, 3, 4, 5};
private double[] testWeightsArray = {0.3, 0.2, 1.3, 1.1, 1.0, 1.8};
private double[] testNegativeWeightsArray = {-0.3, 0.2, -1.3, 1.1, 1.0, 1.8};
private double[] nullArray = null;
private double[] singletonArray = {0};
@Test
@ -109,6 +111,7 @@ public class MathArraysTest {
Assert.assertEquals(a[i] - b[i], r[i], 0);
}
}
@Test
public void testEbeMultiply() {
final double[] a = {0, 1, 2};
@ -119,6 +122,7 @@ public class MathArraysTest {
Assert.assertEquals(a[i] * b[i], r[i], 0);
}
}
@Test
public void testEbeDivide() {
final double[] a = {0, 1, 2};
@ -499,26 +503,26 @@ public class MathArraysTest {
try {
MathArrays.normalizeArray(zeroSum, 1);
Assert.fail("expecting MathArithmeticException");
} catch (MathArithmeticException ex) {}
} catch (MathArithmeticException ex) { /* ignore */ }
// Infinite elements -> MathArithmeticException
double[] hasInf = new double[] {1, 2, 1, Double.NEGATIVE_INFINITY};
try {
MathArrays.normalizeArray(hasInf, 1);
Assert.fail("expecting MathIllegalArgumentException");
} catch (MathIllegalArgumentException ex) {}
} catch (MathIllegalArgumentException ex) { /* ignore */ }
// Infinite target -> MathIllegalArgumentException
try {
MathArrays.normalizeArray(testValues1, Double.POSITIVE_INFINITY);
Assert.fail("expecting MathIllegalArgumentException");
} catch (MathIllegalArgumentException ex) {}
} catch (MathIllegalArgumentException ex) { /* ignore */ }
// NaN target -> MathIllegalArgumentException
try {
MathArrays.normalizeArray(testValues1, Double.NaN);
Assert.fail("expecting MathIllegalArgumentException");
} catch (MathIllegalArgumentException ex) {}
} catch (MathIllegalArgumentException ex) { /* ignore */ }
}
@Test
@ -628,6 +632,7 @@ public class MathArraysTest {
@Test
public void testVerifyValuesNegative() {
final double[] nullArray = null;
Assert.assertFalse(MathArrays.verifyValues(singletonArray, 0, 0));
Assert.assertFalse(MathArrays.verifyValues(testArray, 0, 0));
try {

View File

@ -1,15 +1,18 @@
/*
* 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.
* 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.
*/
package org.apache.commons.math4.legacy.core;
@ -93,12 +96,12 @@ public class PairTest {
private static class MyInteger {
private int i;
public MyInteger(int i) {
MyInteger(int i) {
this.i = i;
}
public void set(int i) {
this.i = i;
public void set(int value) {
this.i = value;
}
@Override

View File

@ -50,24 +50,26 @@ public class DfpDecTest {
private void test(Dfp x, Dfp y, int flags, String desc) {
boolean b = x.equals(y);
if (!x.equals(y) && !x.unequal(y)) // NaNs involved
b = (x.toString().equals(y.toString()));
if (!x.equals(y) && !x.unequal(y)) { // NaNs involved
b = x.toString().equals(y.toString());
}
if (x.equals(new DfpDec(field, 0))) // distinguish +/- zero
b = (b && (x.toString().equals(y.toString())));
if (x.equals(new DfpDec(field, 0))) { // distinguish +/- zero
b = b && (x.toString().equals(y.toString()));
}
b = (b && x.getField().getIEEEFlags() == flags);
b = b && x.getField().getIEEEFlags() == flags;
if (!b) {
Assert.assertTrue("assertion failed "+desc+" x = "+x.toString()+" flags = "+x.getField().getIEEEFlags(), b);
Assert.assertTrue(
"assertion failed " + desc + " x = " + x.toString() + " flags = " + x.getField().getIEEEFlags(), b);
}
x.getField().clearIEEEFlags();
}
@Test
public void testRound()
{
public void testRound() {
field.setRoundingMode(DfpField.RoundingMode.ROUND_HALF_EVEN);
test(new DfpDec(field, "12345678901234567890"),
@ -283,8 +285,7 @@ public class DfpDecTest {
}
@Test
public void testRoundDecimal10()
{
public void testRoundDecimal10() {
field.setRoundingMode(DfpField.RoundingMode.ROUND_HALF_EVEN);
test(new Decimal10(field, "1234567891234567890"),
@ -390,7 +391,7 @@ public class DfpDecTest {
// RoundDecimal10 up
test(new Decimal10(field, 1234567890).add(new Decimal10(field, "0.1")),
new Decimal10(field, 1234567891l),
new Decimal10(field, 1234567891L),
DfpField.FLAG_INEXACT, "RoundDecimal10 #25");
test(new Decimal10(field, "1234567890").add(new Decimal10(field, "0.0001")),
@ -500,8 +501,7 @@ public class DfpDecTest {
}
@Test
public void testNextAfter()
{
public void testNextAfter() {
test(new DfpDec(field, 1).nextAfter(pinf),
new DfpDec(field, "1.0000000000000001"),
0, "NextAfter #1");
@ -531,7 +531,7 @@ public class DfpDecTest {
0, "NextAfter #6");
test(new DfpDec(field, (byte) 2).nextAfter(new DfpDec(field, 2)),
new DfpDec(field, 2l),
new DfpDec(field, 2L),
0, "NextAfter #7");
test(new DfpDec(field, 0).nextAfter(new DfpDec(field, 0)),

View File

@ -56,28 +56,29 @@ public class DfpMathTest {
// Generic test function. Takes params x and y and tests them for
// equality. Then checks the status flags against the flags argument.
// If the test fail, it prints the desc string
private void test(Dfp x, Dfp y, int flags, String desc)
{
private void test(Dfp x, Dfp y, int flags, String desc) {
boolean b = x.equals(y);
if (!x.equals(y) && !x.unequal(y)) // NaNs involved
b = (x.toString().equals(y.toString()));
if (!x.equals(y) && !x.unequal(y)) { // NaNs involved
b = x.toString().equals(y.toString());
}
if (x.equals(factory.newDfp("0"))) // distinguish +/- zero
b = (b && (x.toString().equals(y.toString())));
if (x.equals(factory.newDfp("0"))) { // distinguish +/- zero
b = b && (x.toString().equals(y.toString()));
}
b = (b && x.getField().getIEEEFlags() == flags);
b = b && x.getField().getIEEEFlags() == flags;
if (!b) {
Assert.assertTrue("assertion failed "+desc+" x = "+x.toString()+" flags = "+x.getField().getIEEEFlags(), b);
Assert.assertTrue(
"assertion failed " + desc + " x = " + x.toString() + " flags = " + x.getField().getIEEEFlags(), b);
}
x.getField().clearIEEEFlags();
}
@Test
public void testPow()
{
public void testPow() {
// Test special cases exponent of zero
test(DfpMath.pow(factory.newDfp("0"), factory.newDfp("0")),
factory.newDfp("1"),
@ -473,8 +474,7 @@ public class DfpMathTest {
}
@Test
public void testSin()
{
public void testSin() {
test(DfpMath.sin(pinf),
nan,
DfpField.FLAG_INVALID | DfpField.FLAG_INEXACT, "sin #1");

View File

@ -27,11 +27,6 @@ import org.junit.Test;
public class DfpTest extends ExtendedFieldElementAbstractTest<Dfp> {
@Override
protected Dfp build(final double x) {
return field.newDfp(x);
}
private DfpField field;
private Dfp pinf;
private Dfp ninf;
@ -39,6 +34,11 @@ public class DfpTest extends ExtendedFieldElementAbstractTest<Dfp> {
private Dfp snan;
private Dfp qnan;
@Override
protected Dfp build(final double x) {
return field.newDfp(x);
}
@Before
public void setUp() {
// Some basic setup. Define some constants and clear the status flags
@ -67,16 +67,20 @@ public class DfpTest extends ExtendedFieldElementAbstractTest<Dfp> {
private void test(Dfp x, Dfp y, int flags, String desc) {
boolean b = x.equals(y);
if (!x.equals(y) && !x.unequal(y)) // NaNs involved
b = (x.toString().equals(y.toString()));
if (!x.equals(y) && !x.unequal(y)) { // NaNs involved
b = x.toString().equals(y.toString());
}
if (x.equals(field.newDfp("0"))) // distinguish +/- zero
b = (b && (x.toString().equals(y.toString())));
if (x.equals(field.newDfp("0"))) { // distinguish +/- zero
b = b && (x.toString().equals(y.toString()));
}
b = (b && x.getField().getIEEEFlags() == flags);
b = b && x.getField().getIEEEFlags() == flags;
if (!b)
Assert.assertTrue("assertion failed "+desc+" x = "+x.toString()+" flags = "+x.getField().getIEEEFlags(), b);
if (!b) {
Assert.assertTrue(
"assertion failed " + desc + " x = " + x.toString() + " flags = " + x.getField().getIEEEFlags(), b);
}
x.getField().clearIEEEFlags();
}
@ -103,11 +107,11 @@ public class DfpTest extends ExtendedFieldElementAbstractTest<Dfp> {
@Test
public void testLongConstructor() {
Assert.assertEquals("0.", new Dfp(field, 0l).toString());
Assert.assertEquals("1.", new Dfp(field, 1l).toString());
Assert.assertEquals("-1.", new Dfp(field, -1l).toString());
Assert.assertEquals("1234567890.", new Dfp(field, 1234567890l).toString());
Assert.assertEquals("-1234567890.", new Dfp(field, -1234567890l).toString());
Assert.assertEquals("0.", new Dfp(field, 0L).toString());
Assert.assertEquals("1.", new Dfp(field, 1L).toString());
Assert.assertEquals("-1.", new Dfp(field, -1L).toString());
Assert.assertEquals("1234567890.", new Dfp(field, 1234567890L).toString());
Assert.assertEquals("-1234567890.", new Dfp(field, -1234567890L).toString());
Assert.assertEquals("-9223372036854775808.", new Dfp(field, Long.MIN_VALUE).toString());
Assert.assertEquals("9223372036854775807.", new Dfp(field, Long.MAX_VALUE).toString());
}
@ -370,25 +374,25 @@ public class DfpTest extends ExtendedFieldElementAbstractTest<Dfp> {
// utility function to help test comparisons
private void cmptst(Dfp a, Dfp b, String op, boolean result, double num) {
if (op == "equal") {
if (op.equals("equal")) {
if (a.equals(b) != result) {
assertionFailOpNum(op, num);
}
}
if (op == "unequal") {
if (op.equals("unequal")) {
if (a.unequal(b) != result) {
assertionFailOpNum(op, num);
}
}
if (op == "lessThan") {
if (op.equals("lessThan")) {
if (a.lessThan(b) != result) {
assertionFailOpNum(op, num);
}
}
if (op == "greaterThan") {
if (op.equals("greaterThan")) {
if (a.greaterThan(b) != result) {
assertionFailOpNum(op, num);
}
@ -1563,11 +1567,11 @@ public class DfpTest extends ExtendedFieldElementAbstractTest<Dfp> {
@Test
public void testIssue567() {
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, AccurateMath.copySign(1, field.newDfp(-0.0).toDouble()), Precision.EPSILON);
Assert.assertEquals(+1, AccurateMath.copySign(1, field.newDfp(+0.0).toDouble()), Precision.EPSILON);
DfpField localField = new DfpField(100);
Assert.assertEquals(0.0, localField.getZero().toDouble(), Precision.SAFE_MIN);
Assert.assertEquals(0.0, localField.newDfp(0.0).toDouble(), Precision.SAFE_MIN);
Assert.assertEquals(-1, AccurateMath.copySign(1, localField.newDfp(-0.0).toDouble()), Precision.EPSILON);
Assert.assertEquals(+1, AccurateMath.copySign(1, localField.newDfp(+0.0).toDouble()), Precision.EPSILON);
}
@Test
@ -1668,7 +1672,7 @@ public class DfpTest extends ExtendedFieldElementAbstractTest<Dfp> {
assertionFail(op + " compare #" + num);
}
private static final void assertionFailDfpField(DfpField field){
private static void assertionFailDfpField(DfpField field) {
assertionFail("compare flags = " + field.getIEEEFlags());
}
}

View File

@ -90,6 +90,7 @@ public class AccurateMathStrictComparisonTest {
public void test1() throws Exception {
setupMethodCall(mathMethod, fastMethod, types, valueArrays);
}
private static boolean isNumber(Double d) {
return !(d.isInfinite() || d.isNaN());
}
@ -156,7 +157,9 @@ public class AccurateMathStrictComparisonTest {
if (fatal) {
Assert.fail(message);
} else {
// CHECKSTYLE: stop Regexp
System.out.println(message);
// CHECKSTYLE: resume Regexp
}
}
@ -210,6 +213,7 @@ public class AccurateMathStrictComparisonTest {
@Parameters
public static List<Object[]> data() throws Exception {
// CHECKSTYLE: stop Regexp
String singleMethod = System.getProperty("testMethod");
List<Object[]> list = new ArrayList<>();
for (Method mathMethod : StrictMath.class.getDeclaredMethods()) {
@ -249,7 +253,8 @@ public class AccurateMathStrictComparisonTest {
list.add(new Object[]{mathMethod, fastMethod, types, values});
// setupMethodCall(mathMethod, fastMethod, params, data);
} else {
System.out.println("Cannot find public AccurateMath method corresponding to: "+mathMethod);
System.out
.println("Cannot find public AccurateMath method corresponding to: " + mathMethod);
}
} catch (NoSuchMethodException e) {
System.out.println("Cannot find AccurateMath method corresponding to: " + mathMethod);
@ -258,5 +263,6 @@ public class AccurateMathStrictComparisonTest {
}
}
return list;
// CHECKSTYLE: resume Regexp
}
}

View File

@ -42,6 +42,8 @@ import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.simple.RandomSource;
public class AccurateMathTest {
// CHECKSTYLE: stop Regexp
// The above comment allowa System.out.print
private static final double MAX_ERROR_ULP = 0.51;
private static final int NUMBER_OF_TRIALS = 1000;
@ -52,7 +54,7 @@ public class AccurateMathTest {
@Before
public void setUp() {
field = new DfpField(40);
generator = RandomSource.create(RandomSource.MT, 6176597458463500194l);
generator = RandomSource.create(RandomSource.MT, 6176597458463500194L);
}
@Test
@ -416,8 +418,7 @@ public class AccurateMathTest {
@Test(timeout = 20000L)
public void testPowAllSpecialCases() {
final double EXACT = -1.0;
final double DOUBLES[] = new double[]
{
final double[] DOUBLES = new double[] {
Double.NEGATIVE_INFINITY, -0.0, Double.NaN, 0.0, Double.POSITIVE_INFINITY,
Long.MIN_VALUE, Integer.MIN_VALUE, Short.MIN_VALUE, Byte.MIN_VALUE,
-(double)Long.MIN_VALUE, -(double)Integer.MIN_VALUE, -(double)Short.MIN_VALUE, -(double)Byte.MIN_VALUE,
@ -558,11 +559,15 @@ public class AccurateMathTest {
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(AccurateMath.pow(-d, i), AccurateMath.pow(d, i), EXACT);
if (i % 2.0 == 0.0) {
assertEquals(AccurateMath.pow(-d, i), AccurateMath.pow(d, i), EXACT);
} else if (Math.abs(i) % 2.0 == 1.0) {
// 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(-AccurateMath.pow(-d, i), AccurateMath.pow(d, i), EXACT);
assertEquals(-AccurateMath.pow(-d, i), AccurateMath.pow(d, i), EXACT);
} else {
// if the second argument is finite and not an integer, then the result is NaN.
else assertEquals(Double.NaN, AccurateMath.pow(d, i), EXACT);
assertEquals(Double.NaN, AccurateMath.pow(d, i), EXACT);
}
}
}
}
@ -1228,11 +1233,11 @@ public class AccurateMathTest {
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.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.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);
assertEquals(Double.POSITIVE_INFINITY, AccurateMath.scalb(+2.2250738585072014E-308, 2147483647), 0D);
}
@Test
@ -1337,10 +1342,10 @@ public class AccurateMathTest {
@Test
public void testIntPow() {
final int maxExp = 300;
DfpField field = new DfpField(40);
DfpField localField = new DfpField(40);
final double base = 1.23456789;
Dfp baseDfp = field.newDfp(base);
Dfp dfpPower = field.getOne();
Dfp baseDfp = localField.newDfp(base);
Dfp dfpPower = localField.getOne();
for (int i = 0; i < maxExp; i++) {
assertEquals("exp=" + i, dfpPower.toDouble(), AccurateMath.pow(base, i),
0.6 * AccurateMath.ulp(dfpPower.toDouble()));
@ -1361,8 +1366,7 @@ public class AccurateMathTest {
@Test(timeout = 5000L)
public void testIntPowSpecialCases() {
final double EXACT = -1.0;
final double DOUBLES[] = new double[]
{
final double[] DOUBLES = new double[] {
Double.NEGATIVE_INFINITY, -0.0, Double.NaN, 0.0, Double.POSITIVE_INFINITY,
Long.MIN_VALUE, Integer.MIN_VALUE, Short.MIN_VALUE, Byte.MIN_VALUE,
-(double)Long.MIN_VALUE, -(double)Integer.MIN_VALUE, -(double)Short.MIN_VALUE, -(double)Byte.MIN_VALUE,
@ -1374,7 +1378,7 @@ public class AccurateMathTest {
-0.5, -0.1, -0.2, -0.8, -1.1, -1.2, -1.5, -1.8, -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -1.3, -2.2, -2.5, -2.8, -33.0, -33.1, -33.5, -33.8, -10.0, -300.0, -400.0, -500.0
};
final long INTS[] = new long[]{Long.MAX_VALUE, Long.MAX_VALUE - 1, Long.MIN_VALUE, Long.MIN_VALUE + 1, Long.MIN_VALUE + 2, Integer.MAX_VALUE, Integer.MAX_VALUE - 1, Integer.MIN_VALUE, Integer.MIN_VALUE + 1, Integer.MIN_VALUE + 2, 0, 1, 2, 3, 5, 8, 10, 20, 100, 300, 500, -1, -2, -3, -5, -8, -10, -20, -100, -300, -500};
final long[] INTS = new long[]{Long.MAX_VALUE, Long.MAX_VALUE - 1, Long.MIN_VALUE, Long.MIN_VALUE + 1, Long.MIN_VALUE + 2, Integer.MAX_VALUE, Integer.MAX_VALUE - 1, Integer.MIN_VALUE, Integer.MIN_VALUE + 1, Integer.MIN_VALUE + 2, 0, 1, 2, 3, 5, 8, 10, 20, 100, 300, 500, -1, -2, -3, -5, -8, -10, -20, -100, -300, -500};
// 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) {
@ -1515,9 +1519,12 @@ public class AccurateMathTest {
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(AccurateMath.pow(-d, i), AccurateMath.pow(d, i), EXACT);
if ((i & 1L) == 0L) {
assertEquals(AccurateMath.pow(-d, i), AccurateMath.pow(d, i), EXACT);
} else {
// 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(-AccurateMath.pow(-d, i), AccurateMath.pow(d, i), EXACT);
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.
}
}
@ -1754,21 +1761,21 @@ public class AccurateMathTest {
@Test(expected = MathArithmeticException.class)
public void testToIntExactTooLow() {
AccurateMath.toIntExact(-1l + Integer.MIN_VALUE);
AccurateMath.toIntExact(-1L + Integer.MIN_VALUE);
}
@Test(expected = MathArithmeticException.class)
public void testToIntExactTooHigh() {
AccurateMath.toIntExact(+1l + Integer.MAX_VALUE);
AccurateMath.toIntExact(+1L + Integer.MAX_VALUE);
}
@Test
public void testToIntExact() {
for (int n = -1000; n < 1000; ++n) {
assertEquals(n, AccurateMath.toIntExact(0l + n));
assertEquals(n, AccurateMath.toIntExact(0L + n));
}
assertEquals(Integer.MIN_VALUE, AccurateMath.toIntExact(0l + Integer.MIN_VALUE));
assertEquals(Integer.MAX_VALUE, AccurateMath.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
@ -1815,11 +1822,11 @@ public class AccurateMathTest {
@Test
public void testFloorDivModInt() {
UniformRandomProvider generator = RandomSource.create(RandomSource.WELL_1024_A,
0x7ccab45edeaab90al);
UniformRandomProvider rng = RandomSource.create(RandomSource.WELL_1024_A,
0x7ccab45edeaab90aL);
for (int i = 0; i < 10000; ++i) {
int a = generator.nextInt();
int b = generator.nextInt();
int a = rng.nextInt();
int b = rng.nextInt();
if (b == 0) {
try {
AccurateMath.floorDiv(a, b);
@ -1846,18 +1853,18 @@ public class AccurateMathTest {
@Test
public void testFloorDivLong() {
assertEquals(+1l, AccurateMath.floorDiv(+4l, +3l));
assertEquals(-2l, AccurateMath.floorDiv(-4l, +3l));
assertEquals(-2l, AccurateMath.floorDiv(+4l, -3l));
assertEquals(+1l, AccurateMath.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 {
AccurateMath.floorDiv(1l, 0l);
AccurateMath.floorDiv(1L, 0L);
fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
}
for (long a = -100l; a <= 100l; ++a) {
for (long b = -100l; b <= 100l; ++b) {
for (long a = -100L; a <= 100L; ++a) {
for (long b = -100L; b <= 100L; ++b) {
if (b != 0) {
assertEquals(poorManFloorDiv(a, b), AccurateMath.floorDiv(a, b));
}
@ -1867,18 +1874,18 @@ public class AccurateMathTest {
@Test
public void testFloorModLong() {
assertEquals(+1l, AccurateMath.floorMod(+4l, +3l));
assertEquals(+2l, AccurateMath.floorMod(-4l, +3l));
assertEquals(-2l, AccurateMath.floorMod(+4l, -3l));
assertEquals(-1l, AccurateMath.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 {
AccurateMath.floorMod(1l, 0l);
AccurateMath.floorMod(1L, 0L);
fail("an exception should have been thrown");
} catch (MathArithmeticException mae) {
// expected
}
for (long a = -100l; a <= 100l; ++a) {
for (long b = -100l; b <= 100l; ++b) {
for (long a = -100L; a <= 100L; ++a) {
for (long b = -100L; b <= 100L; ++b) {
if (b != 0) {
assertEquals(poorManFloorMod(a, b), AccurateMath.floorMod(a, b));
}
@ -1888,11 +1895,11 @@ public class AccurateMathTest {
@Test
public void testFloorDivModLong() {
UniformRandomProvider generator = RandomSource.create(RandomSource.WELL_1024_A,
0xb87b9bc14c96ccd5l);
UniformRandomProvider rng = RandomSource.create(RandomSource.WELL_1024_A,
0xb87b9bc14c96ccd5L);
for (int i = 0; i < 10000; ++i) {
long a = generator.nextLong();
long b = generator.nextLong();
long a = rng.nextLong();
long b = rng.nextLong();
if (b == 0) {
try {
AccurateMath.floorDiv(a, b);
@ -1931,7 +1938,7 @@ public class AccurateMathTest {
BigInteger q = q0.subtract(bigK);
BigInteger r = r0.add(bigK.multiply(bigB));
if (r.abs().compareTo(bigB.abs()) < 0 &&
(r.longValue() == 0l || ((r.longValue() ^ b) & 0x8000000000000000l) == 0)) {
(r.longValue() == 0L || ((r.longValue() ^ b) & 0x8000000000000000L) == 0)) {
if (fd.compareTo(q) < 0) {
fd = q;
}

View File

@ -26,7 +26,7 @@ import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
*/
public class ZeroException extends MathIllegalNumberException {
/** Serializable version identifier */
/** Serializable version identifier. */
private static final long serialVersionUID = -1960874856936000015L;
/**

View File

@ -23,9 +23,8 @@ import java.util.ArrayList;
/**
* Utility class for transforming the list of arguments passed to
* constructors of exceptions.
*
*/
public class ArgUtils {
public final class ArgUtils {
/**
* Class contains only static methods.
*/

View File

@ -110,7 +110,7 @@ public class ExceptionContext implements Serializable {
}
/**
* Gets all the keys stored in the exception
* Gets all the keys stored in the exception.
*
* @return the set of keys.
*/
@ -328,7 +328,7 @@ public class ExceptionContext implements Serializable {
* interface.
* @return a string that mentions which class could not be serialized.
*/
private String nonSerializableReplacement(Object obj) {
private static String nonSerializableReplacement(Object obj) {
return "[Object could not be serialized: " + obj.getClass().getName() + "]";
}
}

View File

@ -1,23 +1,24 @@
/*
* 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.
* 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.
*/
package org.apache.commons.math4.legacy.exception;
import org.junit.Assert;
import org.junit.Test;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
/**
* Tests for {@link NotFiniteNumberException}.
*/

View File

@ -1,19 +1,21 @@
/*
* 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.
* 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.
*/
package org.apache.commons.math4.legacy.exception;
import org.junit.Assert;
import org.junit.Test;
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;

View File

@ -107,7 +107,6 @@ public class ExceptionContextTest {
String key = "Key 1";
cOut.setValue(key, new Unserializable());
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(cOut);
@ -119,7 +118,6 @@ public class ExceptionContextTest {
String nsObjStr = (String) cIn.getValue(key);
Assert.assertTrue(nsObjStr.matches(".*could not be serialized.*"));
}
}
/**
* Class used by {@link #testSerializeUnserializable()}.

View File

@ -145,6 +145,14 @@
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>${math.parent.dir}/src/main/resources/checkstyle/checkstyle-legacy.xml</configLocation>
<suppressionsLocation>${math.parent.dir}/src/main/resources/checkstyle/checkstyle-suppressions-legacy.xml</suppressionsLocation>
</configuration>
</plugin>
</plugins>
</build>

View File

@ -24,4 +24,6 @@ import java.util.function.ToDoubleBiFunction;
*
* @since 4.0
*/
public interface DistanceMeasure extends ToDoubleBiFunction<double[],double[]> {}
public interface DistanceMeasure extends ToDoubleBiFunction<double[], double[]> {
// Convenience interface
}

View File

@ -20,7 +20,6 @@ package org.apache.commons.math4.neuralnet;
import java.util.function.DoubleUnaryOperator;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.rng.sampling.distribution.ContinuousUniformSampler;
/**
@ -29,7 +28,7 @@ import org.apache.commons.rng.sampling.distribution.ContinuousUniformSampler;
*
* @since 3.3
*/
public class FeatureInitializerFactory {
public final class FeatureInitializerFactory {
/** Class contains only static methods. */
private FeatureInitializerFactory() {}
@ -48,7 +47,7 @@ public class FeatureInitializerFactory {
final double min,
final double max) {
return randomize(new ContinuousUniformSampler(rng, min, max),
function((x) -> 0, 0, 0));
function(x -> 0, 0, 0));
}
/**

View File

@ -26,7 +26,7 @@ import org.apache.commons.math4.neuralnet.internal.NeuralNetException;
*
* @since 3.3
*/
public class MapUtils {
public final class MapUtils {
/**
* Class contains only static methods.
*/

View File

@ -0,0 +1,22 @@
/*
* 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.
*/
/**
* Internal utility classes.
*/
package org.apache.commons.math4.neuralnet.internal;

View File

@ -31,7 +31,7 @@ import org.apache.commons.math4.neuralnet.Network;
* @since 3.3
*/
public class NeuronString implements Serializable {
/** Serial version ID */
/** Serial version ID. */
private static final long serialVersionUID = 1L;
/** Underlying network. */
private final Network network;

View File

@ -240,7 +240,7 @@ public class KohonenUpdateAction implements UpdateAction {
* @param norm Normalization factor.
* @param sigma Standard deviation.
*/
public Gaussian(double norm,
Gaussian(double norm,
double sigma) {
this.norm = norm;
i2s2 = 1d / (2 * sigma * sigma);

View File

@ -26,7 +26,7 @@ import org.apache.commons.math4.neuralnet.sofm.util.QuasiSigmoidDecayFunction;
*
* @since 3.3
*/
public class LearningFactorFunctionFactory {
public final class LearningFactorFunctionFactory {
/** Class contains only static methods. */
private LearningFactorFunctionFactory() {}

View File

@ -25,7 +25,7 @@ import org.apache.commons.math4.neuralnet.sofm.util.QuasiSigmoidDecayFunction;
*
* @since 3.3
*/
public class NeighbourhoodSizeFunctionFactory {
public final class NeighbourhoodSizeFunctionFactory {
/** Class contains only static methods. */
private NeighbourhoodSizeFunctionFactory() {}

View File

@ -66,7 +66,7 @@ public class QuasiSigmoidDecayFunction implements LongToDoubleFunction {
final double k = initValue;
final double m = numCall;
final double b = 4 * slope / initValue;
sigmoid = (x) -> k / (1 + Math.exp(b * (m - x)));
sigmoid = x -> k / (1 + Math.exp(b * (m - x)));
final double y0 = sigmoid.applyAsDouble(0d);
scale = k / y0;

View File

@ -48,7 +48,7 @@ import org.apache.commons.math4.neuralnet.twod.util.LocationFinder;
public class NeuronSquareMesh2D
implements Iterable<Neuron>,
Serializable {
/** Serial version ID */
/** Serial version ID. */
private static final long serialVersionUID = 1L;
/** Underlying network. */
private final Network network;
@ -643,7 +643,7 @@ public class NeuronSquareMesh2D
}
/**
* Miscellaneous indicators of the map quality:
* Miscellaneous indicators of the map quality.
* <ul>
* <li>Hit histogram</li>
* <li>Quantization error</li>
@ -651,7 +651,7 @@ public class NeuronSquareMesh2D
* <li>Unified distance matrix</li>
* </ul>
*/
public static class DataVisualization {
public static final class DataVisualization {
/** Distance function. */
private static final DistanceMeasure DISTANCE = new EuclideanDistance();
/** Total number of samples. */
@ -772,7 +772,7 @@ public class NeuronSquareMesh2D
/**
* @return the total number of samples.
*/
public final int getNumberOfSamples() {
public int getNumberOfSamples() {
return numberOfSamples;
}
@ -851,7 +851,7 @@ public class NeuronSquareMesh2D
* @param normalizedHits Hits histogram (normalized).
* @return the hit-weighted mean of the given {@code metrics}.
*/
private double hitWeightedMean(double[][] metrics,
private static double hitWeightedMean(double[][] metrics,
double[][] normalizedHits) {
double mean = 0;
final int rows = metrics.length;

View File

@ -34,7 +34,7 @@ import org.apache.commons.math4.neuralnet.twod.NeuronSquareMesh2D;
* unit of the 2D-map.
*
* @since 3.6
* @see NeuronSquareMesh2D.DataVisualization#getUMatrix()
* @see org.apache.commons.math4.neuralnet.twod.NeuronSquareMesh2D.DataVisualization#getUMatrix()
*/
public class UnifiedDistanceMatrix implements MapVisualization {
/** Distance. */

View File

@ -104,7 +104,9 @@ public class NetworkTest {
try {
net.getNeuron(1);
} catch (NoSuchElementException expected) {}
} catch (NoSuchElementException expected) {
// Ignore
}
Assert.assertEquals(1, net.getNeighbours(net.getNeuron(0)).size());
Assert.assertEquals(1, net.getNeighbours(net.getNeuron(3)).size());

View File

@ -17,7 +17,6 @@
package org.apache.commons.math4.neuralnet;
/**
* Wraps a given initializer.
*/

View File

@ -175,12 +175,12 @@ public class FastCosineTransform implements RealTransform {
final boolean inverse) {
if (inverse) {
return normalization == Norm.ORTHO ?
(f) -> TransformUtils.scaleInPlace(fct(f), Math.sqrt(2d / (f.length - 1))) :
(f) -> TransformUtils.scaleInPlace(fct(f), 2d / (f.length - 1));
f -> TransformUtils.scaleInPlace(fct(f), Math.sqrt(2d / (f.length - 1))) :
f -> TransformUtils.scaleInPlace(fct(f), 2d / (f.length - 1));
} else {
return normalization == Norm.ORTHO ?
(f) -> TransformUtils.scaleInPlace(fct(f), Math.sqrt(2d / (f.length - 1))) :
(f) -> fct(f);
f -> TransformUtils.scaleInPlace(fct(f), Math.sqrt(2d / (f.length - 1))) :
f -> fct(f);
}
}

View File

@ -135,7 +135,6 @@ public class FastFourierTransform implements ComplexTransform {
throw new TransformException(TransformException.SIZE_MISMATCH,
dataI.length, dataR.length);
}
final int n = dataR.length;
if (!ArithmeticUtils.isPowerOfTwo(n)) {
throw new TransformException(TransformException.NOT_POWER_OF_TWO,
@ -236,9 +235,7 @@ public class FastFourierTransform implements ComplexTransform {
}
// Combine even/odd transforms of size lastN0 into a transform of size N0 (lastN0 * 2).
for (int destEvenStartIndex = 0;
destEvenStartIndex < n;
destEvenStartIndex += n0) {
for (int destEvenStartIndex = 0; destEvenStartIndex < n; destEvenStartIndex += n0) {
final int destOddStartIndex = destEvenStartIndex + lastN0;
double wSubN0ToRR = 1;
@ -282,6 +279,7 @@ public class FastFourierTransform implements ComplexTransform {
*
* @throws IllegalArgumentException if the length of the data array is not a power of two.
*/
@Override
public Complex[] apply(final double[] f) {
final double[][] dataRI = new double[][] {
Arrays.copyOf(f, f.length),

View File

@ -308,9 +308,9 @@ public class FastHadamardTransform implements RealTransform {
*/
private UnaryOperator<double[]> create(final boolean inverse) {
if (inverse) {
return (f) -> TransformUtils.scaleInPlace(fht(f), 1d / f.length);
return f -> TransformUtils.scaleInPlace(fht(f), 1d / f.length);
} else {
return (f) -> fht(f);
return f -> fht(f);
}
}
}

View File

@ -183,12 +183,12 @@ public class FastSineTransform implements RealTransform {
final boolean inverse) {
if (inverse) {
return normalization == Norm.ORTHO ?
(f) -> TransformUtils.scaleInPlace(fst(f), Math.sqrt(2d / f.length)) :
(f) -> TransformUtils.scaleInPlace(fst(f), 2d / f.length);
f -> TransformUtils.scaleInPlace(fst(f), Math.sqrt(2d / f.length)) :
f -> TransformUtils.scaleInPlace(fst(f), 2d / f.length);
} else {
return normalization == Norm.ORTHO ?
(f) -> TransformUtils.scaleInPlace(fst(f), Math.sqrt(2d / f.length)) :
(f) -> fst(f);
f -> TransformUtils.scaleInPlace(fst(f), Math.sqrt(2d / f.length)) :
f -> fst(f);
}
}

View File

@ -46,7 +46,7 @@ class TransformException extends IllegalArgumentException {
* @param message Message format (with replaceable parameters).
* @param formatArguments Actual arguments to be displayed in the message.
*/
public TransformException(String message, Object... formatArguments) {
TransformException(String message, Object... formatArguments) {
super(MessageFormat.format(message, formatArguments));
}
}

View File

@ -16,7 +16,6 @@
*/
package org.apache.commons.math4.transform;
import java.util.Arrays;
import java.util.function.DoubleUnaryOperator;
import org.apache.commons.numbers.complex.Complex;
@ -25,7 +24,7 @@ import org.apache.commons.numbers.complex.Complex;
* Useful functions for the implementation of various transforms.
* Class is package-private (for internal use only).
*/
class TransformUtils {
final class TransformUtils {
/** Utility class. */
private TransformUtils() {}

View File

@ -110,7 +110,7 @@ public final class FastCosineTransformerTest
@Override
DoubleUnaryOperator getValidFunction() {
final UnivariateFunction sinc = new Sinc();
return (x) -> sinc.value(x);
return x -> sinc.value(x);
}
@Override
@ -169,12 +169,13 @@ public final class FastCosineTransformerTest
@Test
public void testAdHocData() {
FastCosineTransform transformer;
double result[], tolerance = 1e-12;
double[] result;
double tolerance = 1e-12;
final double x[] = {
final double[] x = {
0.0, 1.0, 4.0, 9.0, 16.0, 25.0, 36.0, 49.0, 64.0
};
final double y[] = {
final double[] y = {
172.0, -105.096569476353, 27.3137084989848, -12.9593152353742,
8.0, -5.78585076868676, 4.68629150101524, -4.15826451958632,
4.0
@ -211,7 +212,7 @@ public final class FastCosineTransformerTest
@Test
public void testParameters() throws Exception {
final UnivariateFunction sinFunction = new Sin();
final DoubleUnaryOperator f = (x) -> sinFunction.value(x);
final DoubleUnaryOperator f = x -> sinFunction.value(x);
final FastCosineTransform transformer = new FastCosineTransform(FastCosineTransform.Norm.STD);
try {
@ -241,26 +242,26 @@ public final class FastCosineTransformerTest
@Test
public void testSinFunction() {
final UnivariateFunction sinFunction = new Sin();
final DoubleUnaryOperator f = (x) -> sinFunction.value(x);
final DoubleUnaryOperator f = x -> sinFunction.value(x);
final FastCosineTransform transformer = new FastCosineTransform(FastCosineTransform.Norm.STD);
double min, max, result[], tolerance = 1e-12;
int N = 9;
double tolerance = 1e-12;
int size = 9;
final double expected[] = {
final double[] expected = {
0.0, 3.26197262739567, 0.0, -2.17958042710327, 0.0,
-0.648846697642915, 0.0, -0.433545502649478, 0.0
};
min = 0.0;
max = 2.0 * Math.PI * N / (N - 1);
result = transformer.apply(f, min, max, N);
for (int i = 0; i < N; i++) {
double min = 0.0;
double max = 2.0 * Math.PI * size / (size - 1);
double[] result = transformer.apply(f, min, max, size);
for (int i = 0; i < size; i++) {
Assert.assertEquals(expected[i], result[i], tolerance);
}
min = -Math.PI;
max = Math.PI * (N + 1) / (N - 1);
result = transformer.apply(f, min, max, N);
for (int i = 0; i < N; i++) {
max = Math.PI * (size + 1) / (size - 1);
result = transformer.apply(f, min, max, size);
for (int i = 0; i < size; i++) {
Assert.assertEquals(-expected[i], result[i], tolerance);
}
}

View File

@ -37,7 +37,7 @@ import org.apache.commons.math3.analysis.function.Sinc;
*/
public final class FastFourierTransformerTest {
private static final Sin SIN_FUNCTION = new Sin();
private static final DoubleUnaryOperator SIN = (x) -> SIN_FUNCTION.value(x);
private static final DoubleUnaryOperator SIN = x -> SIN_FUNCTION.value(x);
/** RNG. */
private static final UniformRandomProvider RNG = RandomSource.create(RandomSource.MWC_256);
@ -340,7 +340,7 @@ public final class FastFourierTransformerTest {
@Test
public void testStandardTransformFunction() {
final UnivariateFunction sinc = new Sinc();
final DoubleUnaryOperator f = (x) -> sinc.value(x);
final DoubleUnaryOperator f = x -> sinc.value(x);
final double min = -Math.PI;
final double max = Math.PI;
@ -367,10 +367,11 @@ public final class FastFourierTransformerTest {
@Test
public void testAdHocData() {
FastFourierTransform transformer;
Complex result[]; double tolerance = 1e-12;
Complex[] result;
double tolerance = 1e-12;
final double x[] = {1.3, 2.4, 1.7, 4.1, 2.9, 1.7, 5.1, 2.7};
final Complex y[] = {
final double[] x = {1.3, 2.4, 1.7, 4.1, 2.9, 1.7, 5.1, 2.7};
final Complex[] y = {
Complex.ofCartesian(21.9, 0.0),
Complex.ofCartesian(-2.09497474683058, 1.91507575950825),
Complex.ofCartesian(-2.6, 2.7),
@ -394,9 +395,9 @@ public final class FastFourierTransformerTest {
Assert.assertEquals(0.0, result[i].getImaginary(), tolerance);
}
double x2[] = {10.4, 21.6, 40.8, 13.6, 23.2, 32.8, 13.6, 19.2};
double[] x2 = {10.4, 21.6, 40.8, 13.6, 23.2, 32.8, 13.6, 19.2};
TransformUtils.scaleInPlace(x2, 1.0 / Math.sqrt(x2.length));
Complex y2[] = y;
Complex[] y2 = y;
transformer = new FastFourierTransform(FastFourierTransform.Norm.UNIT);
result = transformer.apply(y2);
@ -419,18 +420,19 @@ public final class FastFourierTransformerTest {
@Test
public void testSinFunction() {
FastFourierTransform transformer;
Complex result[]; int N = 1 << 8;
double min, max, tolerance = 1e-12;
Complex[] result;
int size = 1 << 8;
double tolerance = 1e-12;
min = 0.0;
max = 2 * Math.PI;
double min = 0.0;
double max = 2 * Math.PI;
transformer = new FastFourierTransform(FastFourierTransform.Norm.STD);
result = transformer.apply(SIN, min, max, N);
result = transformer.apply(SIN, min, max, size);
Assert.assertEquals(0.0, result[1].getReal(), tolerance);
Assert.assertEquals(-(N >> 1), result[1].getImaginary(), tolerance);
Assert.assertEquals(0.0, result[N-1].getReal(), tolerance);
Assert.assertEquals(N >> 1, result[N-1].getImaginary(), tolerance);
for (int i = 0; i < N-1; i += (i == 0 ? 2 : 1)) {
Assert.assertEquals(-(size >> 1), result[1].getImaginary(), tolerance);
Assert.assertEquals(0.0, result[size - 1].getReal(), tolerance);
Assert.assertEquals(size >> 1, result[size - 1].getImaginary(), tolerance);
for (int i = 0; i < size - 1; i += i == 0 ? 2 : 1) {
Assert.assertEquals(0.0, result[i].getReal(), tolerance);
Assert.assertEquals(0.0, result[i].getImaginary(), tolerance);
}
@ -438,12 +440,12 @@ public final class FastFourierTransformerTest {
min = -Math.PI;
max = Math.PI;
transformer = new FastFourierTransform(FastFourierTransform.Norm.STD, true);
result = transformer.apply(SIN, min, max, N);
result = transformer.apply(SIN, min, max, size);
Assert.assertEquals(0.0, result[1].getReal(), tolerance);
Assert.assertEquals(-0.5, result[1].getImaginary(), tolerance);
Assert.assertEquals(0.0, result[N-1].getReal(), tolerance);
Assert.assertEquals(0.5, result[N-1].getImaginary(), tolerance);
for (int i = 0; i < N-1; i += (i == 0 ? 2 : 1)) {
Assert.assertEquals(0.0, result[size - 1].getReal(), tolerance);
Assert.assertEquals(0.5, result[size - 1].getImaginary(), tolerance);
for (int i = 0; i < size - 1; i += i == 0 ? 2 : 1) {
Assert.assertEquals(0.0, result[i].getReal(), tolerance);
Assert.assertEquals(0.0, result[i].getImaginary(), tolerance);
}

View File

@ -23,7 +23,7 @@ import org.apache.commons.numbers.core.Precision;
/**
* Test for {@link FestHadamardTransform}.
* Test for {@link FastHadamardTransform}.
*/
public final class FastHadamardTransformerTest {
/**
@ -85,7 +85,7 @@ public final class FastHadamardTransformerTest {
for (int i = 0; i < dX.length; ++i) {
dX[i] = x[i];
}
final double dResult[] = transformer.apply(dX);
final double[] dResult = transformer.apply(dX);
for (int i = 0; i < dResult.length; i++) {
// compare computed results to precomputed results
Assert.assertTrue(Precision.equals(y[i], dResult[i], 1));
@ -97,12 +97,11 @@ public final class FastHadamardTransformerTest {
final FastHadamardTransform transformer = new FastHadamardTransform();
// check integer transform
final int iResult[] = transformer.apply(x);
final int[] iResult = transformer.apply(x);
for (int i = 0; i < iResult.length; i++) {
// compare computed results to precomputed results
Assert.assertEquals(y[i], iResult[i]);
}
}
private void checkInverseDoubleTransform(int[]x, int[] y) {
@ -114,12 +113,10 @@ public final class FastHadamardTransformerTest {
for (int i = 0; i < dY.length; ++i) {
dY[i] = y[i];
}
final double dResult[] = transformer.apply(dY);
final double[] dResult = transformer.apply(dY);
for (int i = 0; i < dResult.length; i++) {
// compare computed results to precomputed results
Assert.assertTrue(Precision.equals(x[i], dResult[i], 1));
}
}
}

View File

@ -122,7 +122,7 @@ public final class FastSineTransformerTest extends RealTransformerAbstractTest {
@Override
DoubleUnaryOperator getValidFunction() {
final UnivariateFunction sinc = new Sinc();
return (x) -> sinc.value(x);
return x -> sinc.value(x);
}
@Override
@ -199,19 +199,19 @@ public final class FastSineTransformerTest extends RealTransformerAbstractTest {
@Test
public void testAdHocData() {
FastSineTransform transformer;
double result[], tolerance = 1e-12;
double tolerance = 1e-12;
final double x[] = {
final double[] x = {
0, 1, 2, 3, 4, 5, 6, 7
};
final double y[] = {
final double[] y = {
0.0, 20.1093579685034, -9.65685424949238,
5.98642305066196, -4.0, 2.67271455167720,
-1.65685424949238, 0.795649469518633
};
transformer = new FastSineTransform(FastSineTransform.Norm.STD);
result = transformer.apply(x);
double[] result = transformer.apply(x);
for (int i = 0; i < result.length; i++) {
Assert.assertEquals(y[i], result[i], tolerance);
}
@ -243,23 +243,24 @@ public final class FastSineTransformerTest extends RealTransformerAbstractTest {
@Test
public void testSinFunction() {
final UnivariateFunction sinFunction = new Sin();
final DoubleUnaryOperator f = (x) -> sinFunction.value(x);
final DoubleUnaryOperator f = x -> sinFunction.value(x);
final FastSineTransform transformer = new FastSineTransform(FastSineTransform.Norm.STD);
double min, max, result[], tolerance = 1e-12; int N = 1 << 8;
double tolerance = 1e-12;
int size = 1 << 8;
min = 0.0;
max = 2 * Math.PI;
result = transformer.apply(f, min, max, N);
Assert.assertEquals(N >> 1, result[2], tolerance);
for (int i = 0; i < N; i += (i == 1 ? 2 : 1)) {
double min = 0.0;
double max = 2 * Math.PI;
double[] result = transformer.apply(f, min, max, size);
Assert.assertEquals(size >> 1, result[2], tolerance);
for (int i = 0; i < size; i += i == 1 ? 2 : 1) {
Assert.assertEquals(0.0, result[i], tolerance);
}
min = -Math.PI;
max = Math.PI;
result = transformer.apply(f, min, max, N);
Assert.assertEquals(-(N >> 1), result[2], tolerance);
for (int i = 0; i < N; i += (i == 1 ? 2 : 1)) {
result = transformer.apply(f, min, max, size);
Assert.assertEquals(-(size >> 1), result[2], tolerance);
for (int i = 0; i < size; i += i == 1 ? 2 : 1) {
Assert.assertEquals(0.0, result[i], tolerance);
}
}
@ -270,7 +271,7 @@ public final class FastSineTransformerTest extends RealTransformerAbstractTest {
@Test
public void testParameters() throws Exception {
final UnivariateFunction sinFunction = new Sin();
final DoubleUnaryOperator f = (x) -> sinFunction.value(x);
final DoubleUnaryOperator f = x -> sinFunction.value(x);
final FastSineTransform transformer = new FastSineTransform(FastSineTransform.Norm.STD);
try {

View File

@ -20,7 +20,6 @@ import org.junit.Assert;
import org.junit.Test;
import java.util.function.DoubleUnaryOperator;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.simple.RandomSource;
@ -29,7 +28,7 @@ import org.apache.commons.rng.simple.RandomSource;
* This abstract test handles the automatic generation of random data of various
* sizes. For each generated data array, actual values (returned by the
* transformer to be tested) are compared to expected values, returned by the
* {@link #apply(double[])} (to be implemented by the user: a naive method may
* {@link #transform(double[], boolean)} (to be implemented by the user: a naive method may
* be used). Methods are also provided to test that invalid parameters throw the
* expected exceptions.
*
@ -49,7 +48,7 @@ public abstract class RealTransformerAbstractTest {
/**
* Returns an invalid data size. Transforms with this data size should
* trigger a {@link MathIllegalArgumentException}.
* trigger a {@link IllegalArgumentException}.
*
* @param i the index of the invalid data size ({@code 0 <= i <}
* {@link #getNumberOfInvalidDataSizes()}
@ -116,7 +115,7 @@ public abstract class RealTransformerAbstractTest {
/**
* Returns a sampling upper bound for the accuracy check of
* {@link RealTransform#apply(DoubleUnaryOperator, double, double, int, TransformType)}.
* {@link RealTransform#apply(DoubleUnaryOperator, double, double, int)}.
* This upper bound should be valid. In other words, none of the above
* methods should throw an exception when passed this bound.
*
@ -156,7 +155,7 @@ public abstract class RealTransformerAbstractTest {
}
/**
* {@link RealTransformer#(DoubleUnaryOperator, double, double, int)}
* {@link RealTransform#apply(DoubleUnaryOperator, double, double, int)}
* should throw {@link IllegalArgumentException} if number of samples is
* invalid.
*/
@ -253,10 +252,11 @@ public abstract class RealTransformerAbstractTest {
/**
* Accuracy check of
* {@link RealTransform#apply(DoubleUnaryOperator, double, double, int, TransformType)}.
* {@link RealTransform#apply(DoubleUnaryOperator, double, double, int)}.
* For each valid data size returned by
* {@link #getValidDataSize(int) getValidDataSize(i)},
* the {@link UnivariateFunction} returned by {@link #getValidFunction()} is
* the {@link org.apache.commons.math3.analysis.UnivariateFunction UnivariateFunction}
* returned by {@link #getValidFunction()} is
* sampled. The actual transform is computed and compared to the expected
* transform, return by {@link #transform(double[], boolean)}. Actual
* and expected values should be equal to within the relative error returned

View File

@ -28,7 +28,7 @@ import org.apache.commons.math3.analysis.function.Sin;
*/
public class TransformUtilsTest {
private static final Sin SIN_FUNCTION = new Sin();
private static final DoubleUnaryOperator SIN = (x) -> SIN_FUNCTION.value(x);
private static final DoubleUnaryOperator SIN = x -> SIN_FUNCTION.value(x);
@Test(expected = TransformException.class)
public void testSampleWrongBounds() {

View File

@ -0,0 +1,260 @@
<?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.
-->
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<!--
Commons Numbers customization of default Checkstyle behavior:
https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/sun_checks.xml
-->
<module name="Checker">
<module name="SuppressionFilter">
<!-- Default property set by maven-checkstyle-plugin -->
<property name="file" value="${checkstyle.suppressions.file}"/>
<property name="optional" value="false"/>
</module>
<property name="localeLanguage" value="en"/>
<property name="fileExtensions" value="java, properties, xml" />
<!-- Excludes all 'module-info.java' files -->
<!-- See https://checkstyle.org/config_filefilters.html -->
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$" />
</module>
<!-- Checks that a package-info.java file exists for each package. -->
<!-- See http://checkstyle.sourceforge.net/config_javadoc.html#JavadocPackage -->
<module name="JavadocPackage" />
<!-- Checks whether files end with a new line. -->
<!-- See http://checkstyle.sourceforge.net/config_misc.html#NewlineAtEndOfFile -->
<module name="NewlineAtEndOfFile" />
<!-- Checks that property files contain the same keys. -->
<!-- See http://checkstyle.sourceforge.net/config_misc.html#Translation -->
<module name="Translation" />
<!-- Checks for Size Violations. -->
<!-- See http://checkstyle.sourceforge.net/config_sizes.html -->
<module name="FileLength" />
<module name="LineLength">
<property name="fileExtensions" value="java"/>
<!-- Ignore lines that begin with " * ", such as within a Javadoc comment. -->
<property name="ignorePattern" value="^ *\* *[^ ]"/>
<property name="max" value="120"/>
</module>
<!-- Checks for whitespace -->
<!-- See http://checkstyle.sourceforge.net/config_whitespace.html -->
<module name="FileTabCharacter" />
<!-- Miscellaneous other checks. -->
<!-- See http://checkstyle.sourceforge.net/config_misc.html -->
<module name="RegexpSingleline">
<property name="format" value="\s+$" />
<property name="minimum" value="0" />
<property name="maximum" value="0" />
<property name="message" value="Line has trailing spaces." />
</module>
<!-- Checks for Headers -->
<!-- See http://checkstyle.sourceforge.net/config_header.html -->
<module name="Header">
<property name="headerFile" value="${checkstyle.header.file}"/>
</module>
<module name="TreeWalker">
<!-- Checks for Javadoc comments. -->
<!-- See http://checkstyle.sourceforge.net/config_javadoc.html -->
<module name="InvalidJavadocPosition"/>
<module name="JavadocMethod" />
<module name="JavadocType" />
<module name="JavadocVariable" />
<module name="JavadocStyle" />
<!-- <module name="MissingJavadocType"/> -->
<!-- Checks for Naming Conventions. -->
<!-- See http://checkstyle.sourceforge.net/config_naming.html -->
<module name="ConstantName" />
<module name="LocalFinalVariableName" />
<module name="LocalVariableName" />
<module name="MemberName" />
<module name="MethodName" />
<module name="PackageName" />
<module name="ParameterName" />
<module name="StaticVariableName" />
<module name="TypeName" />
<!-- Checks for imports -->
<!-- See http://checkstyle.sourceforge.net/config_import.html -->
<module name="AvoidStarImport" />
<module name="IllegalImport" /> <!-- defaults to sun.* packages -->
<module name="RedundantImport" />
<module name="UnusedImports">
<property name="processJavadoc" value="false" />
</module>
<!-- Checks for Size Violations. -->
<!-- See http://checkstyle.sourceforge.net/config_sizes.html -->
<module name="MethodLength" />
<module name="ParameterNumber" />
<!-- Checks for whitespace -->
<!-- See http://checkstyle.sourceforge.net/config_whitespace.html -->
<module name="EmptyForIteratorPad" />
<module name="GenericWhitespace" />
<module name="MethodParamPad" />
<module name="NoWhitespaceAfter" />
<module name="NoWhitespaceBefore" />
<!-- Operator must be at end of wrapped line -->
<module name="OperatorWrap">
<property name="option" value="eol"/>
</module>
<module name="ParenPad" />
<module name="TypecastParenPad" />
<module name="WhitespaceAfter">
<property name="tokens" value="COMMA, SEMI, LITERAL_IF, LITERAL_ELSE, LITERAL_WHILE, LITERAL_DO, LITERAL_FOR, DO_WHILE"/>
</module>
<module name="WhitespaceAround">
<property name="allowEmptyConstructors" value="true"/>
<property name="allowEmptyTypes" value="true"/>
</module>
<!-- Modifier Checks -->
<!-- See http://checkstyle.sourceforge.net/config_modifiers.html -->
<module name="ModifierOrder" />
<module name="RedundantModifier" />
<!-- Checks for blocks. You know, those {}'s -->
<!-- See http://checkstyle.sourceforge.net/config_blocks.html -->
<module name="AvoidNestedBlocks" />
<module name="EmptyBlock" />
<module name="LeftCurly" />
<module name="NeedBraces" />
<module name="RightCurly" />
<!-- Checks for common coding problems -->
<!-- See http://checkstyle.sourceforge.net/config_coding.html -->
<module name="EmptyStatement" />
<module name="EqualsHashCode" />
<!-- Method parameters and local variables should not hide fields, except in constructors and setters -->
<module name="HiddenField">
<property name="ignoreConstructorParameter" value="true" />
<property name="ignoreSetter" value="true" />
</module>
<!-- Disallow unnecessary instantiation of Boolean, String -->
<module name="IllegalInstantiation">
<property name="classes" value="java.lang.Boolean, java.lang.String"/>
</module>
<!-- Allowed for algorithm implementations. -->
<!-- <module name="InnerAssignment" /> -->
<!-- <module name="MagicNumber" /> -->
<module name="MissingSwitchDefault" />
<module name="MultipleVariableDeclarations" />
<module name="SimplifyBooleanExpression" />
<module name="SimplifyBooleanReturn" />
<!-- Checks for class design -->
<!-- See http://checkstyle.sourceforge.net/config_design.html -->
<module name="DesignForExtension" />
<module name="FinalClass" />
<module name="HideUtilityClassConstructor" />
<module name="InterfaceIsType" />
<!-- No public fields -->
<module name="VisibilityModifier">
<property name="protectedAllowed" value="true"/>
</module>
<!-- Miscellaneous other checks. -->
<!-- See http://checkstyle.sourceforge.net/config_misc.html -->
<module name="ArrayTypeStyle" />
<!-- <module name="FinalParameters" /> -->
<module name="TodoComment">
<property name="severity" value="warning"/>
</module>
<module name="UpperEll" />
<!-- Addition to Checkstyle sun_checks.xml -->
<!-- Indentation of 4 spaces. -->
<module name="Indentation">
<!-- Indentation style recommended by Oracle -->
<property name="caseIndent" value="0"/>
</module>
<!-- Switch statements should have independent cases -->
<module name="FallThrough" />
<!-- Constant names should obey the traditional all uppercase naming convention -->
<module name="ConstantName" />
<!-- No System.out.println() statements -->
<module name="Regexp">
<!-- no sysouts -->
<property name="format" value="System\.(out|err)\."/>
<property name="illegalPattern" value="true"/>
</module>
<!-- Authors should be in pom.xml file -->
<module name="Regexp">
<property name="format" value="@author"/>
<property name="illegalPattern" value="true"/>
<property name="message" value="Developers names should be in pom file"/>
</module>
<!-- Use a consistent way to put declarations -->
<module name="DeclarationOrder" />
<!-- Don't add up parentheses when they are not required -->
<module name="UnnecessaryParentheses" />
<!-- Don't use too widespread catch (Exception, Throwable, RuntimeException) -->
<module name="IllegalCatch" />
<!-- Don't use = or != for string comparisons -->
<module name="StringLiteralEquality" />
<!-- String literals more than one character long should not be repeated several times -->
<!-- the "unchecked" string is also accepted to allow @SuppressWarnings("unchecked") -->
<module name="MultipleStringLiterals" >
<property name="ignoreStringsRegexp" value='^(("")|(".")|("unchecked"))$'/>
</module>
<!-- Check if @Override tags are present -->
<module name="MissingOverride" />
<!-- Setup special comments to suppress specific checks from source files -->
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="CHECKSTYLE\: stop ([\w\|]+)"/>
<property name="onCommentFormat" value="CHECKSTYLE\: resume ([\w\|]+)"/>
<property name="checkFormat" value="$1"/>
</module>
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="CHECKSTYLE\: stop all"/>
<property name="onCommentFormat" value="CHECKSTYLE\: resume all"/>
</module>
</module>
</module>

View File

@ -0,0 +1,26 @@
<?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.
-->
<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
<suppressions>
<!-- Disable all checks for main code! XXX -->
<suppress checks=".*" files=".*[/\\]main[/\\].*" />
<!-- Disable all checks for unit tests. -->
<suppress checks=".*" files=".*[/\\]test[/\\].*" />
</suppressions>

View File

@ -19,8 +19,32 @@
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
<suppressions>
<!-- Disable all checks for main code! XXX -->
<suppress checks=".*" files=".*[/\\]main[/\\].*" />
<!-- Disable all checks for unit tests. -->
<suppress checks=".*" files=".*[/\\]test[/\\].*" />
<suppress checks="HiddenField" files=".*[/\\]examples[/\\]sofm[/\\]tsp[/\\]City\.java" />
<suppress checks="LineLength" files=".*[/\\]LocalizedFormats\.java" />
<suppress checks="FileLength" files=".*[/\\]AccurateMath.*\.java" />
<suppress checks="FileLength" files=".*[/\\]Dfp.*\.java" />
<suppress checks="UnnecessaryParentheses" files=".*[/\\]AccurateMath.*\.java" />
<suppress checks="UnnecessaryParentheses" files=".*[/\\]Dfp.*\.java" />
<suppress checks="LineLength" files=".*[/\\]AccurateMath\.java" />
<suppress checks="LineLength" files=".*[/\\]Dfp\.java" />
<suppress checks="MethodLength" files=".*[/\\]Dfp.*\.java" />
<suppress checks="MethodLength" files=".*[/\\]AccurateMath\.java" />
<suppress checks="MethodName" files=".*[/\\]AccurateMath\.java" />
<suppress checks="LocalFinalVariableName" files=".*[/\\]AccurateMath\.java" />
<suppress checks="ParameterNumber" files=".*[/\\]RealFieldElement\.java" />
<suppress checks="ParameterNumber" files=".*[/\\]Dfp\.java" />
<suppress checks="TypeName" files=".*[/\\]AccurateMath\.java" />
<suppress checks="ParameterName" files=".*[/\\]AccurateMathCalc\.java" />
<!-- Be more lenient on tests. -->
<suppress checks="Javadoc" files=".*[/\\]test[/\\].*" />
<suppress checks="MultipleStringLiterals" files=".*[/\\]test[/\\].*" />
<suppress checks="DesignForExtension" files=".*[/\\]test[/\\].*" />
<suppress checks="LineLength" files=".*[/\\]test[/\\].*" />
<suppress checks="IllegalCatch" files=".*[/\\]test[/\\].*" />
<suppress checks="MethodName" files=".*[/\\]test[/\\].*" />
<suppress checks="ConstantName" files=".*[/\\]test[/\\].*" />
<suppress checks="MethodLength" files=".*/Dfp.*Test.java" />
<suppress checks="MethodLength" files=".*[/\\]AccurateMathTest\.java" />
<suppress checks="LocalFinalVariableName" files=".*[/\\]AccurateMathTest\.java" />
</suppressions>

View File

@ -81,6 +81,7 @@
<!-- See http://checkstyle.sourceforge.net/config_header.html -->
<module name="Header">
<property name="headerFile" value="${checkstyle.header.file}"/>
<property name="fileExtensions" value="java"/>
</module>
<module name="TreeWalker">