You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2017/01/20 14:45:48 UTC
[01/31] commons-numbers git commit: Cleanup (massive delete).
Repository: commons-numbers
Updated Branches:
refs/heads/master 0d64d85ed -> c5de65a2c
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/java/org/apache/commons/complex/TestUtils.java.orig
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/complex/TestUtils.java.orig b/src/test/java/org/apache/commons/complex/TestUtils.java.orig
deleted file mode 100755
index c02484e..0000000
--- a/src/test/java/org/apache/commons/complex/TestUtils.java.orig
+++ /dev/null
@@ -1,662 +0,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.
- */
-
-package org.apache.commons.math4;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.text.DecimalFormat;
-
-import org.apache.commons.complex.FieldElement;
-import org.apache.commons.complex.complex.Complex;
-import org.apache.commons.complex.complex.ComplexFormat;
-import org.apache.commons.complex.distribution.RealDistribution;
-import org.apache.commons.complex.linear.FieldMatrix;
-import org.apache.commons.complex.linear.RealMatrix;
-import org.apache.commons.complex.linear.RealVector;
-import org.apache.commons.complex.stat.inference.ChiSquareTest;
-import org.apache.commons.complex.util.FastMath;
-import org.apache.commons.complex.util.Precision;
-import org.junit.Assert;
-
-/**
- */
-public class TestUtils {
- /**
- * Collection of static methods used in math unit tests.
- */
- private TestUtils() {
- super();
- }
-
- /**
- * Verifies that expected and actual are within delta, or are both NaN or
- * infinities of the same sign.
- */
- public static void assertEquals(double expected, double actual, double delta) {
- Assert.assertEquals(null, expected, actual, delta);
- }
-
- /**
- * Verifies that expected and actual are within delta, or are both NaN or
- * infinities of the same sign.
- */
- public static void assertEquals(String msg, double expected, double actual, double delta) {
- // check for NaN
- if(Double.isNaN(expected)){
- Assert.assertTrue("" + actual + " is not NaN.",
- Double.isNaN(actual));
- } else {
- Assert.assertEquals(msg, expected, actual, delta);
- }
- }
-
- /**
- * Verifies that the two arguments are exactly the same, either
- * both NaN or infinities of same sign, or identical floating point values.
- */
- public static void assertSame(double expected, double actual) {
- Assert.assertEquals(expected, actual, 0);
- }
-
- /**
- * Verifies that real and imaginary parts of the two complex arguments
- * are exactly the same. Also ensures that NaN / infinite components match.
- */
- public static void assertSame(Complex expected, Complex actual) {
- assertSame(expected.getReal(), actual.getReal());
- assertSame(expected.getImaginary(), actual.getImaginary());
- }
-
- /**
- * Verifies that real and imaginary parts of the two complex arguments
- * differ by at most delta. Also ensures that NaN / infinite components match.
- */
- public static void assertEquals(Complex expected, Complex actual, double delta) {
- Assert.assertEquals(expected.getReal(), actual.getReal(), delta);
- Assert.assertEquals(expected.getImaginary(), actual.getImaginary(), delta);
- }
-
- /**
- * Verifies that two double arrays have equal entries, up to tolerance
- */
- public static void assertEquals(double expected[], double observed[], double tolerance) {
- assertEquals("Array comparison failure", expected, observed, tolerance);
- }
-
- /**
- * Serializes an object to a bytes array and then recovers the object from the bytes array.
- * Returns the deserialized object.
- *
- * @param o object to serialize and recover
- * @return the recovered, deserialized object
- */
- public static Object serializeAndRecover(Object o) {
- try {
- // serialize the Object
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ObjectOutputStream so = new ObjectOutputStream(bos);
- so.writeObject(o);
-
- // deserialize the Object
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- ObjectInputStream si = new ObjectInputStream(bis);
- return si.readObject();
- } catch (IOException ioe) {
- return null;
- } catch (ClassNotFoundException cnfe) {
- return null;
- }
- }
-
- /**
- * Verifies that serialization preserves equals and hashCode.
- * Serializes the object, then recovers it and checks equals and hash code.
- *
- * @param object the object to serialize and recover
- */
- public static void checkSerializedEquality(Object object) {
- Object object2 = serializeAndRecover(object);
- Assert.assertEquals("Equals check", object, object2);
- Assert.assertEquals("HashCode check", object.hashCode(), object2.hashCode());
- }
-
- /**
- * Verifies that the relative error in actual vs. expected is less than or
- * equal to relativeError. If expected is infinite or NaN, actual must be
- * the same (NaN or infinity of the same sign).
- *
- * @param expected expected value
- * @param actual observed value
- * @param relativeError maximum allowable relative error
- */
- public static void assertRelativelyEquals(double expected, double actual,
- double relativeError) {
- assertRelativelyEquals(null, expected, actual, relativeError);
- }
-
- /**
- * Verifies that the relative error in actual vs. expected is less than or
- * equal to relativeError. If expected is infinite or NaN, actual must be
- * the same (NaN or infinity of the same sign).
- *
- * @param msg message to return with failure
- * @param expected expected value
- * @param actual observed value
- * @param relativeError maximum allowable relative error
- */
- public static void assertRelativelyEquals(String msg, double expected,
- double actual, double relativeError) {
- if (Double.isNaN(expected)) {
- Assert.assertTrue(msg, Double.isNaN(actual));
- } else if (Double.isNaN(actual)) {
- Assert.assertTrue(msg, Double.isNaN(expected));
- } else if (Double.isInfinite(actual) || Double.isInfinite(expected)) {
- Assert.assertEquals(expected, actual, relativeError);
- } else if (expected == 0.0) {
- Assert.assertEquals(msg, actual, expected, relativeError);
- } else {
- double absError = FastMath.abs(expected) * relativeError;
- Assert.assertEquals(msg, expected, actual, absError);
- }
- }
-
- /**
- * Fails iff values does not contain a number within epsilon of z.
- *
- * @param msg message to return with failure
- * @param values complex array to search
- * @param z value sought
- * @param epsilon tolerance
- */
- public static void assertContains(String msg, Complex[] values,
- Complex z, double epsilon) {
- for (Complex value : values) {
- if (Precision.equals(value.getReal(), z.getReal(), epsilon) &&
- Precision.equals(value.getImaginary(), z.getImaginary(), epsilon)) {
- return;
- }
- }
- Assert.fail(msg + " Unable to find " + (new ComplexFormat()).format(z));
- }
-
- /**
- * Fails iff values does not contain a number within epsilon of z.
- *
- * @param values complex array to search
- * @param z value sought
- * @param epsilon tolerance
- */
- public static void assertContains(Complex[] values,
- Complex z, double epsilon) {
- assertContains(null, values, z, epsilon);
- }
-
- /**
- * Fails iff values does not contain a number within epsilon of x.
- *
- * @param msg message to return with failure
- * @param values double array to search
- * @param x value sought
- * @param epsilon tolerance
- */
- public static void assertContains(String msg, double[] values,
- double x, double epsilon) {
- for (double value : values) {
- if (Precision.equals(value, x, epsilon)) {
- return;
- }
- }
- Assert.fail(msg + " Unable to find " + x);
- }
-
- /**
- * Fails iff values does not contain a number within epsilon of x.
- *
- * @param values double array to search
- * @param x value sought
- * @param epsilon tolerance
- */
- public static void assertContains(double[] values, double x,
- double epsilon) {
- assertContains(null, values, x, epsilon);
- }
-
- /**
- * Asserts that all entries of the specified vectors are equal to within a
- * positive {@code delta}.
- *
- * @param message the identifying message for the assertion error (can be
- * {@code null})
- * @param expected expected value
- * @param actual actual value
- * @param delta the maximum difference between the entries of the expected
- * and actual vectors for which both entries are still considered equal
- */
- public static void assertEquals(final String message,
- final double[] expected, final RealVector actual, final double delta) {
- final String msgAndSep = message.equals("") ? "" : message + ", ";
- Assert.assertEquals(msgAndSep + "dimension", expected.length,
- actual.getDimension());
- for (int i = 0; i < expected.length; i++) {
- Assert.assertEquals(msgAndSep + "entry #" + i, expected[i],
- actual.getEntry(i), delta);
- }
- }
-
- /**
- * Asserts that all entries of the specified vectors are equal to within a
- * positive {@code delta}.
- *
- * @param message the identifying message for the assertion error (can be
- * {@code null})
- * @param expected expected value
- * @param actual actual value
- * @param delta the maximum difference between the entries of the expected
- * and actual vectors for which both entries are still considered equal
- */
- public static void assertEquals(final String message,
- final RealVector expected, final RealVector actual, final double delta) {
- final String msgAndSep = message.equals("") ? "" : message + ", ";
- Assert.assertEquals(msgAndSep + "dimension", expected.getDimension(),
- actual.getDimension());
- final int dim = expected.getDimension();
- for (int i = 0; i < dim; i++) {
- Assert.assertEquals(msgAndSep + "entry #" + i,
- expected.getEntry(i), actual.getEntry(i), delta);
- }
- }
-
- /** verifies that two matrices are close (1-norm) */
- public static void assertEquals(String msg, RealMatrix expected, RealMatrix observed, double tolerance) {
-
- Assert.assertNotNull(msg + "\nObserved should not be null",observed);
-
- if (expected.getColumnDimension() != observed.getColumnDimension() ||
- expected.getRowDimension() != observed.getRowDimension()) {
- StringBuilder messageBuffer = new StringBuilder(msg);
- messageBuffer.append("\nObserved has incorrect dimensions.");
- messageBuffer.append("\nobserved is " + observed.getRowDimension() +
- " x " + observed.getColumnDimension());
- messageBuffer.append("\nexpected " + expected.getRowDimension() +
- " x " + expected.getColumnDimension());
- Assert.fail(messageBuffer.toString());
- }
-
- RealMatrix delta = expected.subtract(observed);
- if (delta.getNorm() >= tolerance) {
- StringBuilder messageBuffer = new StringBuilder(msg);
- messageBuffer.append("\nExpected: " + expected);
- messageBuffer.append("\nObserved: " + observed);
- messageBuffer.append("\nexpected - observed: " + delta);
- Assert.fail(messageBuffer.toString());
- }
- }
-
- /** verifies that two matrices are equal */
- public static void assertEquals(FieldMatrix<? extends FieldElement<?>> expected,
- FieldMatrix<? extends FieldElement<?>> observed) {
-
- Assert.assertNotNull("Observed should not be null",observed);
-
- if (expected.getColumnDimension() != observed.getColumnDimension() ||
- expected.getRowDimension() != observed.getRowDimension()) {
- StringBuilder messageBuffer = new StringBuilder();
- messageBuffer.append("Observed has incorrect dimensions.");
- messageBuffer.append("\nobserved is " + observed.getRowDimension() +
- " x " + observed.getColumnDimension());
- messageBuffer.append("\nexpected " + expected.getRowDimension() +
- " x " + expected.getColumnDimension());
- Assert.fail(messageBuffer.toString());
- }
-
- for (int i = 0; i < expected.getRowDimension(); ++i) {
- for (int j = 0; j < expected.getColumnDimension(); ++j) {
- FieldElement<?> eij = expected.getEntry(i, j);
- FieldElement<?> oij = observed.getEntry(i, j);
- Assert.assertEquals(eij, oij);
- }
- }
- }
-
- /** verifies that two arrays are close (sup norm) */
- public static void assertEquals(String msg, double[] expected, double[] observed, double tolerance) {
- StringBuilder out = new StringBuilder(msg);
- if (expected.length != observed.length) {
- out.append("\n Arrays not same length. \n");
- out.append("expected has length ");
- out.append(expected.length);
- out.append(" observed length = ");
- out.append(observed.length);
- Assert.fail(out.toString());
- }
- boolean failure = false;
- for (int i=0; i < expected.length; i++) {
- if (!Precision.equalsIncludingNaN(expected[i], observed[i], tolerance)) {
- failure = true;
- out.append("\n Elements at index ");
- out.append(i);
- out.append(" differ. ");
- out.append(" expected = ");
- out.append(expected[i]);
- out.append(" observed = ");
- out.append(observed[i]);
- }
- }
- if (failure) {
- Assert.fail(out.toString());
- }
- }
-
- /** verifies that two arrays are close (sup norm) */
- public static void assertEquals(String msg, float[] expected, float[] observed, float tolerance) {
- StringBuilder out = new StringBuilder(msg);
- if (expected.length != observed.length) {
- out.append("\n Arrays not same length. \n");
- out.append("expected has length ");
- out.append(expected.length);
- out.append(" observed length = ");
- out.append(observed.length);
- Assert.fail(out.toString());
- }
- boolean failure = false;
- for (int i=0; i < expected.length; i++) {
- if (!Precision.equalsIncludingNaN(expected[i], observed[i], tolerance)) {
- failure = true;
- out.append("\n Elements at index ");
- out.append(i);
- out.append(" differ. ");
- out.append(" expected = ");
- out.append(expected[i]);
- out.append(" observed = ");
- out.append(observed[i]);
- }
- }
- if (failure) {
- Assert.fail(out.toString());
- }
- }
-<<<<<<< HEAD
-
-=======
-
->>>>>>> 35ca5e10659d265613b4c3ed8a89f96ad6ce7ae7
- /** verifies that two arrays are close (sup norm) */
- public static void assertEquals(String msg, Complex[] expected, Complex[] observed, double tolerance) {
- StringBuilder out = new StringBuilder(msg);
- if (expected.length != observed.length) {
- out.append("\n Arrays not same length. \n");
- out.append("expected has length ");
- out.append(expected.length);
- out.append(" observed length = ");
- out.append(observed.length);
- Assert.fail(out.toString());
- }
- boolean failure = false;
- for (int i=0; i < expected.length; i++) {
- if (!Precision.equalsIncludingNaN(expected[i].getReal(), observed[i].getReal(), tolerance)) {
- failure = true;
- out.append("\n Real elements at index ");
- out.append(i);
- out.append(" differ. ");
- out.append(" expected = ");
- out.append(expected[i].getReal());
- out.append(" observed = ");
- out.append(observed[i].getReal());
- }
- if (!Precision.equalsIncludingNaN(expected[i].getImaginary(), observed[i].getImaginary(), tolerance)) {
- failure = true;
- out.append("\n Imaginary elements at index ");
- out.append(i);
- out.append(" differ. ");
- out.append(" expected = ");
- out.append(expected[i].getImaginary());
- out.append(" observed = ");
- out.append(observed[i].getImaginary());
- }
- }
- if (failure) {
- Assert.fail(out.toString());
- }
- }
-
- /** verifies that two arrays are close (sup norm) */
- public static void assertEquals(String msg, float[] expected, float[] observed, float tolerance) {
- StringBuilder out = new StringBuilder(msg);
- if (expected.length != observed.length) {
- out.append("\n Arrays not same length. \n");
- out.append("expected has length ");
- out.append(expected.length);
- out.append(" observed length = ");
- out.append(observed.length);
- Assert.fail(out.toString());
- }
- boolean failure = false;
- for (int i=0; i < expected.length; i++) {
- if (!Precision.equalsIncludingNaN(expected[i], observed[i], tolerance)) {
- failure = true;
- out.append("\n Elements at index ");
- out.append(i);
- out.append(" differ. ");
- out.append(" expected = ");
- out.append(expected[i]);
- out.append(" observed = ");
- out.append(observed[i]);
- }
- }
- if (failure) {
- Assert.fail(out.toString());
- }
- }
-
- /** verifies that two arrays are close (sup norm) */
- public static void assertEquals(String msg, Complex[] expected, Complex[] observed, double tolerance) {
- StringBuilder out = new StringBuilder(msg);
- if (expected.length != observed.length) {
- out.append("\n Arrays not same length. \n");
- out.append("expected has length ");
- out.append(expected.length);
- out.append(" observed length = ");
- out.append(observed.length);
- Assert.fail(out.toString());
- }
- boolean failure = false;
- for (int i=0; i < expected.length; i++) {
- if (!Precision.equalsIncludingNaN(expected[i].getReal(), observed[i].getReal(), tolerance)) {
- failure = true;
- out.append("\n Real elements at index ");
- out.append(i);
- out.append(" differ. ");
- out.append(" expected = ");
- out.append(expected[i].getReal());
- out.append(" observed = ");
- out.append(observed[i].getReal());
- }
- if (!Precision.equalsIncludingNaN(expected[i].getImaginary(), observed[i].getImaginary(), tolerance)) {
- failure = true;
- out.append("\n Imaginary elements at index ");
- out.append(i);
- out.append(" differ. ");
- out.append(" expected = ");
- out.append(expected[i].getImaginary());
- out.append(" observed = ");
- out.append(observed[i].getImaginary());
- }
- }
- if (failure) {
- Assert.fail(out.toString());
- }
- }
-
- /** verifies that two arrays are equal */
- public static <T extends FieldElement<T>> void assertEquals(T[] m, T[] n) {
- if (m.length != n.length) {
- Assert.fail("vectors not same length");
- }
- for (int i = 0; i < m.length; i++) {
- Assert.assertEquals(m[i],n[i]);
- }
- }
-
- /**
- * Computes the sum of squared deviations of <values> from <target>
- * @param values array of deviates
- * @param target value to compute deviations from
- *
- * @return sum of squared deviations
- */
- public static double sumSquareDev(double[] values, double target) {
- double sumsq = 0d;
- for (int i = 0; i < values.length; i++) {
- final double dev = values[i] - target;
- sumsq += (dev * dev);
- }
- return sumsq;
- }
-
- /**
- * Asserts the null hypothesis for a ChiSquare test. Fails and dumps arguments and test
- * statistics if the null hypothesis can be rejected with confidence 100 * (1 - alpha)%
- *
- * @param valueLabels labels for the values of the discrete distribution under test
- * @param expected expected counts
- * @param observed observed counts
- * @param alpha significance level of the test
- */
- public static void assertChiSquareAccept(String[] valueLabels, double[] expected, long[] observed, double alpha) {
- ChiSquareTest chiSquareTest = new ChiSquareTest();
-
- // Fail if we can reject null hypothesis that distributions are the same
- if (chiSquareTest.chiSquareTest(expected, observed, alpha)) {
- StringBuilder msgBuffer = new StringBuilder();
- DecimalFormat df = new DecimalFormat("#.##");
- msgBuffer.append("Chisquare test failed");
- msgBuffer.append(" p-value = ");
- msgBuffer.append(chiSquareTest.chiSquareTest(expected, observed));
- msgBuffer.append(" chisquare statistic = ");
- msgBuffer.append(chiSquareTest.chiSquare(expected, observed));
- msgBuffer.append(". \n");
- msgBuffer.append("value\texpected\tobserved\n");
- for (int i = 0; i < expected.length; i++) {
- msgBuffer.append(valueLabels[i]);
- msgBuffer.append("\t");
- msgBuffer.append(df.format(expected[i]));
- msgBuffer.append("\t\t");
- msgBuffer.append(observed[i]);
- msgBuffer.append("\n");
- }
- msgBuffer.append("This test can fail randomly due to sampling error with probability ");
- msgBuffer.append(alpha);
- msgBuffer.append(".");
- Assert.fail(msgBuffer.toString());
- }
- }
-
- /**
- * Asserts the null hypothesis for a ChiSquare test. Fails and dumps arguments and test
- * statistics if the null hypothesis can be rejected with confidence 100 * (1 - alpha)%
- *
- * @param values integer values whose observed and expected counts are being compared
- * @param expected expected counts
- * @param observed observed counts
- * @param alpha significance level of the test
- */
- public static void assertChiSquareAccept(int[] values, double[] expected, long[] observed, double alpha) {
- String[] labels = new String[values.length];
- for (int i = 0; i < values.length; i++) {
- labels[i] = Integer.toString(values[i]);
- }
- assertChiSquareAccept(labels, expected, observed, alpha);
- }
-
- /**
- * Asserts the null hypothesis for a ChiSquare test. Fails and dumps arguments and test
- * statistics if the null hypothesis can be rejected with confidence 100 * (1 - alpha)%
- *
- * @param expected expected counts
- * @param observed observed counts
- * @param alpha significance level of the test
- */
- public static void assertChiSquareAccept(double[] expected, long[] observed, double alpha) {
- String[] labels = new String[expected.length];
- for (int i = 0; i < labels.length; i++) {
- labels[i] = Integer.toString(i + 1);
- }
- assertChiSquareAccept(labels, expected, observed, alpha);
- }
-
- /**
- * Computes the 25th, 50th and 75th percentiles of the given distribution and returns
- * these values in an array.
- */
- public static double[] getDistributionQuartiles(RealDistribution distribution) {
- double[] quantiles = new double[3];
- quantiles[0] = distribution.inverseCumulativeProbability(0.25d);
- quantiles[1] = distribution.inverseCumulativeProbability(0.5d);
- quantiles[2] = distribution.inverseCumulativeProbability(0.75d);
- return quantiles;
- }
-
- /**
- * Updates observed counts of values in quartiles.
- * counts[0] <-> 1st quartile ... counts[3] <-> top quartile
- */
- public static void updateCounts(double value, long[] counts, double[] quartiles) {
- if (value < quartiles[0]) {
- counts[0]++;
- } else if (value > quartiles[2]) {
- counts[3]++;
- } else if (value > quartiles[1]) {
- counts[2]++;
- } else {
- counts[1]++;
- }
- }
-
- /**
- * Eliminates points with zero mass from densityPoints and densityValues parallel
- * arrays. Returns the number of positive mass points and collapses the arrays so
- * that the first <returned value> elements of the input arrays represent the positive
- * mass points.
- */
- public static int eliminateZeroMassPoints(int[] densityPoints, double[] densityValues) {
- int positiveMassCount = 0;
- for (int i = 0; i < densityValues.length; i++) {
- if (densityValues[i] > 0) {
- positiveMassCount++;
- }
- }
- if (positiveMassCount < densityValues.length) {
- int[] newPoints = new int[positiveMassCount];
- double[] newValues = new double[positiveMassCount];
- int j = 0;
- for (int i = 0; i < densityValues.length; i++) {
- if (densityValues[i] > 0) {
- newPoints[j] = densityPoints[i];
- newValues[j] = densityValues[i];
- j++;
- }
- }
- System.arraycopy(newPoints,0,densityPoints,0,positiveMassCount);
- System.arraycopy(newValues,0,densityValues,0,positiveMassCount);
- }
- return positiveMassCount;
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/test-jar.xml
----------------------------------------------------------------------
diff --git a/test-jar.xml b/test-jar.xml
deleted file mode 100644
index e5a20a5..0000000
--- a/test-jar.xml
+++ /dev/null
@@ -1,99 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
- 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.
--->
-
-<!--
- Compiles and runs unit tests against distribution jar(s). Use .antrc or the
- command line to control the jdk used to execute this build file.
-
- Assumes that the distribution jar to be tested is in the basedir/lib, along
- with any dependent jars (junit, hamcrest). Use the "libdir" property to specify
- the path to the directory containing these jars.
-
- The default target, "test," executes clean as a dependency.
--->
-
-<project default="test" name="commons-math" basedir=".">
- <property name="libdir" value="lib"/>
- <property name="testclassesdir" value="target/test-classes"/>
- <property name="testreportdir" value="target/test-reports"/>
- <property name="defaulttargetdir" value="target"/>
- <property name="test.resources" value="src/test/resources"/>
- <property name="build.home" value="target"/>
- <path id="build.classpath">
- <fileset dir="${libdir}">
- <include name="*.jar" />
- </fileset>
- </path>
- <target name="clean" description="o Clean up the generated directories">
- <delete dir="${defaulttargetdir}"/>
- </target>
- <target name="init" description="o Initializes some properties">
- <echo>
- JAVA ENVIRONMENT
- **************************Java runtime version*****************************
- ${java.runtime.version}
- **************************Java class path**********************************
- ${java.class.path}
- **************************Java home****************************************
- ${java.home}
- *************************Java library path*******************************
- Java library path: ${java.library.path}
- ===========================================================================
- </echo>
- </target>
- <target name="test" description="o Run the test cases" if="test.failure" depends="internal-test">
- <fail message="There were test failures.">
- </fail>
- </target>
- <target name="internal-test" depends="clean,compile-tests">
- <mkdir dir="${testreportdir}"/>
- <junit dir="./" failureproperty="test.failure" printSummary="yes"
- fork="true" haltonerror="true" showOutput="true">
- <sysproperty key="basedir" value="."/>
- <formatter type="brief"/>
- <classpath>
- <path refid="build.classpath"/>
- <pathelement path="${testclassesdir}"/>
- </classpath>
- <batchtest todir="${testreportdir}">
- <fileset dir="src/test/java">
- <include name="**/*Test.java"/>
- <exclude name="**/*AbstractTest.java"/>
- </fileset>
- </batchtest>
- </junit>
- </target>
- <target name="compile-tests" >
- <mkdir dir="${testclassesdir}"/>
- <javac destdir="${testclassesdir}" deprecation="true" debug="true"
- optimize="false" excludes="**/package.html">
- <src>
- <pathelement location="src/test"/>
- </src>
- <classpath>
- <path refid="build.classpath"/>
- </classpath>
- </javac>
- <copy todir="${build.home}/test-classes">
- <fileset dir="${test.resources}">
- </fileset>
- </copy>
- </target>
-</project>
-
[15/31] commons-numbers git commit: Updated development and release
howtos.
Posted by er...@apache.org.
Updated development and release howtos.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/b7dc0cf8
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/b7dc0cf8
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/b7dc0cf8
Branch: refs/heads/master
Commit: b7dc0cf862cada1be5cc772898f754cf11977b9a
Parents: c454132
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Wed Jan 18 14:40:51 2017 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Wed Jan 18 14:40:51 2017 +0100
----------------------------------------------------------------------
doc/development/development.howto.txt | 35 ++-
doc/release/release.howto.txt | 484 ++++++++++++++++++-----------
doc/release/settings.xml | 1 +
3 files changed, 332 insertions(+), 188 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/b7dc0cf8/doc/development/development.howto.txt
----------------------------------------------------------------------
diff --git a/doc/development/development.howto.txt b/doc/development/development.howto.txt
index 0e4512f..eecf2b4 100644
--- a/doc/development/development.howto.txt
+++ b/doc/development/development.howto.txt
@@ -1,23 +1,30 @@
-This document summarizes a discussion that took place on the "dev" ML:
- http://markmail.org/message/7lnus64entdwj4vo
+#
+# 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.
-The conclusions reported here are based on ideas presented in this blog post:
- http://nvie.com/posts/a-successful-git-branching-model/
+This document summarizes the development process of Commons Numbers:
-1. The "master" branch can only contain released code; i.e. the only
- accepted commits are the result of a merge from the "release" branch
- (from a release candidate that passed a vote).
-2. Contents that is candidate for being released must be merged into the
- "release" branch, from the "develop" branch.
-3. The "develop" branch collects all modifications that will be part
+1. The "master" branch collects all modifications that will be part
of the next release.
- Usually, changes should not be committed directly to the "develop"
+ Usually, non trivial changes should not be committed directly to the "master"
branch; they should be merged from a branch specifically created for
that purpose (see next point).
-4. Work on an identified issue (bug fix or new feature) must be done in a
+2. Work on an identified issue (bug fix or new feature) must be done in a
new branch named after its corresponding report in the bug-tracking
- system (JIRA), e.g. "feature-MATH-1319".
+ system (JIRA), e.g. "feature-NUMBERS-123".
After completion, and in the absence of technical objections, the feature
- branch is merged into the "develop" branch, using the "--no-ff" git
+ branch is merged into the "master" branch, using the "--no-ff" git
option.
That feature branch is then deleted.
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/b7dc0cf8/doc/release/release.howto.txt
----------------------------------------------------------------------
diff --git a/doc/release/release.howto.txt b/doc/release/release.howto.txt
index a667aa2..be4c09f 100644
--- a/doc/release/release.howto.txt
+++ b/doc/release/release.howto.txt
@@ -15,8 +15,8 @@
# limitations under the License.
This document is meant as a step-by-step recipe to achieve the release of
-the Commons Math component. Note that more general instructions valid
-for all components, including [math], are available on the Apache Commons
+the Commons Numbers component. Note that more general instructions valid
+for all components, including [rng], are available on the Apache Commons
main site: at "http://commons.apache.org/releases/prepare.html" and
"http://commons.apache.org/releases/release.html".
@@ -24,9 +24,9 @@ The files "settings-security.xml" and "settings.xml" are minimal examples
of files used by maven to pick up authentication credentials needed to
connect to remote servers and to cryptographically sign the artifacts.
-Since [math] has switched to git as its version control system, release preparation
-can be done easily on the release manager local host in a branch. As branches deletion
-is now forbidden at Apache, we will use a specific release branch for every version.
+Release preparation is done on the release manager local host in a branch.
+As branches deletion is now forbidden at Apache, we will use a specific
+release branch for every version.
The branch will be simply named X.Y-release, with X.Y being the version number.
The branch will be used to store the release specific parts (i.e. the pom changes with
the version number, the release date in the site and so on). Everything else and in
@@ -79,12 +79,31 @@ Preliminary checks:
(1)
-As a first optional step, you can test that everything works locally, i.e.
-that the build process can create all the necessary artifacts. The command
+As an optional step, you can test that everything works locally, i.e.
+that the build process can create all the necessary artifacts.
- $ mvn clean deploy -Prelease -Ptest-deploy
+ (1a)
+ The command
-should create the artifacts in the "target/deploy".
+ $ mvn clean deploy -Prelease -Ptest-deploy
+
+ should create the artifacts in the "target/deploy" directory.
+
+ At some point when processing the above command, the GPG passphrase will be
+ requested; to avoid problems, the "gpg2" executable should be specified in
+ the "settings.xml" file (see below).
+
+ (1b)
+ When the above works, you can test the creation of the full distribution
+ files with the following commands:
+
+ $ ( cd dist-archive && mvn assembly:single )
+
+ The "dist-archive/target" directory will then contain those files:
+ commons-numbers-1.0-SNAPSHOT-bin.tar.gz
+ commons-numbers-1.0-SNAPSHOT-bin.zip
+ commons-numbers-1.0-SNAPSHOT-src.tar.gz
+ commons-numbers-1.0-SNAPSHOT-src.zip
(2)
@@ -95,13 +114,14 @@ candidate, create it locally starting from the master branch or the version
branch and push it to Apache repository (assuming it is called origin),
remembering the binding between the local and remote origin branches:
- $ git branch X.Y-release
- $ git push -u origin X.Y-release
+ $ git branch 1.0-release
+ $ git push -u origin 1.0-release
+
(3)
Switch to the release branch:
- $ git checkout X.Y-release
+ $ git checkout 1.0-release
(4)
@@ -109,22 +129,25 @@ If there have been changes committed in the master branch or the version
branch since the creation of the release branch, there are two cases:
(4a)
- if all these changes must be included in the X.Y-release
- merge master branch or version branch into X.Y-release branch:
+ if all these changes must be included in version 1.0, merge "master"
+ or the version branch into "1.0-release":
- $ git merge master
- or, if the version branch is called MATH_3_X
- $ git merge MATH_3_X
+ $ git merge master
+
+ or, if the version branch is called "NUMBERS_1_X"
+
+ $ git merge NUMBERS_1_X
(4b)
- if only part of these changes must be included in the X.Y-release,
- cherry-pick the required commits into X.Y-release branch:
+ if only part of these changes must be included in version 1.0,
+ cherry-pick the required commits into the "1.0-release" branch:
+
+ $ git cherry-pick commit-SHA
- $ git cherry-pick commit-SHA
(5)
Update the release specific files, checking you are really working on the
-X.Y-release branch and *not* on the master branch.
+1.0-release branch and *not* on the master branch.
In particular:
* Update and commit the "src/site/site.xml" file to contain the information
@@ -132,10 +155,10 @@ In particular:
* Estimate a release date (taking into account the release vote delay) and
insert it in the "src/changes/changes.xml" file.
* Update the "pom.xml" to contain the final version number and not a SNAPSHOT:
- Assuming that the release version will be "3.4", modify the "<version>" tag to
+ Assuming that the release version will be "1.0", modify the "<version>" tag to
read:
- <version>3.4</version>
+ <version>1.0</version>
Modify the section of "<properties>" that also refers to version numbers.
You should uncomment the "<commons.rc.version>" line and indicate the
@@ -145,14 +168,14 @@ In particular:
<properties>
<!-- ... -->
- <commons.release.version>3.4</commons.release.version>
+ <commons.release.version>1.0</commons.release.version>
<commons.rc.version>RC1</commons.rc.version>
<!-- ... -->
</properties>
(6)
-The "download" page template is located at "src/site/xdoc/download_math.xml".
+The "download" page template is located at "src/site/xdoc/download_numbers.xml".
This file is updated automatically by running the command:
$ mvn commons:download-page
@@ -165,20 +188,21 @@ Create it by running:
$ mvn -Prelease-notes changes:announcement-generate
-Check the file for weird line breaks, and commit the updated file to git:
+Check the file for weird line breaks, and commit the updated files to git:
$ git add src/site/site.xml \
src/changes/changes.xml \
pom.xml \
- src/site/xdoc/download_math.xml \
+ src/site/xdoc/download_numbers.xml \
RELEASE-NOTES.txt
-Check you did not forget any file:
+Check you did not forget any files:
$ git status
Commit the changes:
- $ git commit -m "creating release candidate"
+
+ $ git commit -m "Release candidate."
(8)
@@ -188,10 +212,10 @@ First, make sure once again that the workspace is up-to-date:
$ git status
Then, assuming the first candidate, the suffix will be "RC1" (this should
-be the same as in the "<properties>" in the "pom.xml"), and the command
+be the same as in the "<properties>" in the "pom.xml"), and the command
will be:
- $ git tag -s -m "Creating Apache Commons Math v3.4 RC1 tag." MATH_3_4_RC1
+ $ git tag -u "__Your_key_id__" -s -m "RC1." NUMBERS_1_0_RC1
If you have several GPG keys, you may prefer to use "-u keyId" to select a specific
key for signing the tag instead of "-s" which select automatically one key
@@ -199,21 +223,18 @@ from the configured e-mail address.
Check the tag GPG signature:
- $ git tag -v MATH_3_4_RC1
+ $ git tag -v NUMBERS_1_0_RC1
You will get something like:
object cf4a9d70c9ac24dd7196995390171150e4e56451
type commit
- tag MATH_3_4_RC1
- tagger Luc Maisonobe <lu...@apache.org> 1418934614 +0100
+ tag NUMBERS_1_0_RC1
+ tagger YourName <YourApacheEmail> 1418934614 +0100
+
+ RC1.
- Creating Apache Commons Math v3.4 RC1 tag.
- gpg: Signature made Thu Dec 18 21:30:14 2014 CET using RSA key ID 02E9F65B
- gpg: Good signature from "Luc Maisonobe (CODE SIGNING KEY) <lu...@apache.org>"
- gpg: aka "Luc Maisonobe <Lu...@c-s.fr>"
- gpg: aka "Luc Maisonobe <Lu...@free.fr>"
- gpg: aka "Luc Maisonobe <lu...@orekit.org>"
+followed by GPG output lines.
Remember the commit ID listed in the object line (here cf4a9d70c9ac24dd7196995390171150e4e56451),
as it is the most stable reference for traceability.
@@ -222,22 +243,25 @@ Push everything (including the tag!) on the Apache repository:
$ git push --tags
+
(9)
Switch to a new directory out of your regular workspace, and retrieve
the official tag from the Apache repository:
$ cd /tmp
- $ git clone https://git-wip-us.apache.org/repos/asf/commons-math.git --branch MATH_3_4_RC1
+ $ git clone https://git-wip-us.apache.org/repos/asf/commons-numbers.git --branch NUMBERS_1_0_RC1
In the command above, the --branch option accepts both branch names and tags names,
so we specify directly the tag here. Git will warn that the resulting workspace
is in 'detached HEAD' state and 'git status' commands will warn that you are not
-currently on any branch. This is expected is this situation.
+currently on any branch. This is expected in this situation.
Check that the last commit has the id you noted in the previous step:
+ $ cd commons-numbers
$ git log -1
+
(10)
If this is your first release, you might need to add your GPG encryption
key to the KEYS file. [If you have already done so, skip this section.]
@@ -256,7 +280,9 @@ Create and transfer the artifacts to the Nexus server (a.k.a. "deploy").
Because the artifacts must be cryptographically signed, this step requires that
a profile named "release" exists in the maven "settings.xml" configuration file
which will contain the identifier of your GPG key (cf. sample "settings.xml"
-file).
+file). You will also have to follow the instructions at
+https://maven.apache.org/guides/mini/guide-encryption.html to set your password
+in the settings.xml file.
You can then run
@@ -267,107 +293,163 @@ which will transfer the artifacts to the Nexus repository located at
This process transfers more files than really needed in the the "staging" (i.e.
non official) maven repository. The files expected in the repository are
-commons-math3-3.4.pom, commons-math3-3.4.jar, commons-math3-3.4.javadoc,
-commons-math3-3.4.sources, commons-math3-3.4.test-sources commons-math3-3.4.tests,
-the associated fingerprints (<file-name>.md5 and <file-name>.sha1) and the signatures
-<file-name>.asc. Note that Nexus automatically adds "md5" and "sha1" checksums files
-to the "asc" files (cryptographic signature). These fingerprints on signatures are
-spurious and have to be manually removed from Nexus staging area. The process also
-transfers the complete source and binaries distributions files
-commons-math3-3.4.-bin.tar.gz, commons-math3-3.4.-bin.zip, commons-math3-3.4.-src.tar.gz,
-commons-math3-3.4.-src.zip as well as the associated .md5 and .sha1 fingerprints and the
-.asc signatures. These are not really maven artifacts but rather distribution archives,
-and they belong elsewhere, so they must also been removed from the Nexus staging
+ commons-numbers-1.0.pom
+ commons-numbers-1.0.jar
+ commons-numbers-1.0.javadoc
+ commons-numbers-1.0.sources
+ commons-numbers-1.0.test-sources
+ commons-numbers-1.0.tests
+and their associated fingerprints
+ <file-name>.md5
+ <file-name>.sha1
+and their signatures
+ <file-name>.asc
+
+Nexus used to add "md5" and "sha1" checksums files to the "asc" files
+(cryptographic signature). If these fingerprints on signatures are
+present, they must be manually removed from Nexus staging area.
+
+The process also transfers the complete source and binaries distributions files,
+(for each module):
+ commons-numbers-<ModuleArtefactId>-1.0-bin.tar.gz
+ commons-numbers-<ModuleArtefactId>-1.0-bin.zip
+ commons-numbers-<ModuleArtefactId>-1.0-src.tar.gz
+ commons-numbers-<ModuleArtefactId>-1.0-src.zip
+as well as their associated .md5 and .sha1 fingerprints and .asc signatures.
+All these files are not maven artifacts but rather distribution archives: They
+belong elsewhere; hence they must also been removed from the Nexus staging
repository.
-As a measure of sanity check, repository must be manually "closed" before other
-people review the deliverables just created.
+As a measure of sanity check, the Nexus repository must be manually "closed"
+before other people review the deliverables just created.
How to "close" the staging repository is explained at this page:
http://books.sonatype.com/nexus-book/reference/staging-repositories.html#staging-sect-closing
+
(12)
-Upload the other distribution files to the Apache servers.
+Create and upload the other distribution files to the Apache servers.
+
+ (12a)
+ Perform a server-side copy of the README.html from the "release" area of
+ the Apache dist server to the "dev" area:
+
+ $ svn cp https://dist.apache.org/repos/dist/release/commons/numbers/README.html \
+ https://dist.apache.org/repos/dist/dev/commons/numbers/README.html
+
+ (12b)
+ The modules "dist-archive" dedicated to creating the archive files.
+ Run the following command:
+
+ $ ( cd dist-archive && mvn assembly:single )
-The archive files have been created during the previous step. They have been put
-in the .m2 local repository. The RELEASE_NOTES.txt file hase been created earlier
-and is still in the checkout directory of the release candidate. The README.html
-file can be copied from the release area of the Apache dist server.
-All these files can be uploaded to the development area of the Apache dist server
-using the following commands:
+ (12c)
+ Go to a temporary directory and check out the "dev" area.
- $ cd /tmp
- $ svn cp https://dist.apache.org/repos/dist/release/commons/math/README.html \
- https://dist.apache.org/repos/dist/dev/commons/math/README.html
- $ svn checkout https://dist.apache.org/repos/dist/dev/commons/math
- $ cd math
+ $ cd /tmp
+ $ svn checkout https://dist.apache.org/repos/dist/dev/commons/numbers
+ $ cd numbers
-edit README.html with released version number
+ (12d)
+ Edit the "README.html" file to contain the released version number.
- $ cp ~/.m2/repository/org/apache/commons/commons-math3/3.4/*-bin.* binaries
- $ cp ~/.m2/repository/org/apache/commons/commons-math3/3.4/*-src.* source
- $ cp <path-to-the-RC-workspace>/RELEASE-NOTES.txt .
- $ svn add README.html RELEASE-NOTES.txt binaries/* source/*
- $ svn commit -m "Creating distribution files for 3.4 RC1"
+ (12e)
+ Copy other files from the RC workspace:
+
+ $ cp path-to-the-RC-workspace/RELEASE-NOTES.txt .
+ $ cp path-to-the-RC-workspace/CONTRIBUTING.md .
+ $ cp path-to-the-RC-workspace/README.md .
+ $ cp path-to-the-RC-workspace/dist-archive/target/*-bin.* binaries
+ $ cp path-to-the-RC-workspace/dist-archive/target/*-src.* source
+
+ Currently, the commons-parent build does not create the
+ * signatures (".asc"),
+ * checksums (".md5"),
+ * hashes (".sha1")
+ of the distribution files. Hence, you have to create them "manually"!
+ For the signature, the command would be
+ $ gpg -ab file-to-sign
+ For the hash and checksum, see e.g. the "Digest" Perl module.
+
+ (12f)
+ Commit to SVN:
+
+ $ svn add \
+ CONTRIBUTING.md \
+ README.md \
+ README.html \
+ RELEASE-NOTES.txt \
+ binaries/* \
+ source/*
+ $ svn commit -m "Distribution files for Commons Numbers v1.0 (RC1)."
(13)
As the web site staging area is shared among all commons components and therefore
-can be published before vote ends, it is not recommended to use the standard staging
-area for the release candidate. So you will just archive the transfer the site it on
-your apache personal area for review. Here is how to do this using lftp to initiate
-the sftp transfer (lftp supports a mirror command for recursive transfers, don't
-forget the -R flag for uploading instead of downloading the site):
-
- $ mvn site
+could be published before the vote ends, it is not recommended to use the standard
+staging area for the release candidate. So you will just archive the site and
+transfer it to your apache personal area for review.
+Here is how to do this using "lftp" to initiate the sftp transfer. "lftp" supports
+a mirror command for recursive transfers; don't forget the -R flag for uploading
+instead of downloading the site.
+If you haven't setup your login on home.apache.org you will need to go to
+ https://id.apache.org/
+login and copy the contents of your
+ ~/.ssh/id_rsa.pub
+file to "SSH Key (authorized_keys line)".
+Then run these commands:
+
+ $ mvn clean site site:stage
$ cd target
- $ mv site commons-math-3.4-RC1-site
- $ lftp sftp://__Your_apache_login__@home.apache.org/
+ $ mv staging commons-numbers-1.0-RC1-site
+ $ lftp sftp://__Your_apache_login__@home.apache.org
lftp you@home.apache.org:~> cd public_html
- lftp you@home.apache.org:~/public_html> mirror -R commons-math-3.4-RC1-site
+ lftp you@home.apache.org:~/public_html> mirror -R commons-numbers-1.0-RC1-site
lftp you@home.apache.org:~/public_html> bye
(14)
Call to vote by sending a message to the "dev" ML with subject
-"[VOTE][RC1] Release Commons Math 3.4". You can use the following example as
+"[VOTE][RC1] Release Commons Numbers 1.0". You can use the following example as
a starting point, replacing the URLs with the appropriate ones:
----------
-This is a [VOTE] for releasing Apache Commons Math 3.4 from release candidate 1.
+This is a [VOTE] for releasing Apache Commons Numbers 1.0 (from RC6).
+
Tag name:
- MATH_3_4_RC1 (signature can be checked from git using 'git tag -v')
+ NUMBERS_1_0_RC6 (signature can be checked from git using 'git tag -v')
Tag URL:
- <https://git-wip-us.apache.org/repos/asf?p=commons-math.git;a=commit;h=cf4a9d70c9ac24dd7196995390171150e4e56451>
+ https://git-wip-us.apache.org/repos/asf?p=commons-numbers.git;a=commit;h=4581a4520315657a4219b37c81f5db80e4a4e43c
Commit ID the tag points at:
- cf4a9d70c9ac24dd7196995390171150e4e56451
+ 4581a4520315657a4219b37c81f5db80e4a4e43c
Site:
- <http://home.apache.org/~__Your_apache_login__/commons-math-3.4-RC1-site>
+ http://home.apache.org/~erans/commons-numbers-1.0-RC6-site
-Distribution files:
- https://dist.apache.org/repos/dist/dev/commons/math/
+Distribution files (committed at revision 17284):
+ https://dist.apache.org/repos/dist/dev/commons/numbers/
Distribution files hashes (SHA1):
- e02c981d49c1f12b1fc237e69cb551a5620e57b4 commons-math3-3.4-bin.tar.gz
- 11965eb97033d4d6ef0aeb902f1450641f40d3c5 commons-math3-3.4-bin.zip
- ce3efda70ac8f850f15154b38438bc337adc027a commons-math3-3.4-src.tar.gz
- d343c885a9d6eea611403f7f92ff580911363681 commons-math3-3.4-src.zip
+ c5e70a523160ed848194eeba0efa2b14d23c7a61 commons-numbers-1.0-bin.tar.gz
+ 66d7701afc90aafa4c4b6e033b8df6cd84365161 commons-numbers-1.0-bin.zip
+ ef56543c8882a0e4771de83ecf8b3be190f122cf commons-numbers-1.0-src.tar.gz
+ 3dc56b0793d8bbd703a4efa68547eb58f6fb5b35 commons-numbers-1.0-src.zip
KEYS file to check signatures:
- http://www.apache.org/dist/commons/KEYS
+ https://www.apache.org/dist/commons/KEYS
Maven artifacts:
- https://repository.apache.org/content/repositories/orgapachecommons-051/org/apache/commons/commons-math3/3.4/
+ https://repository.apache.org/content/repositories/orgapachecommons-1229/
-[ ] +1 Release it.
-[ ] +0 Go ahead; I don't care.
-[ ] -0 There are a few minor glitches: ...
-[ ] -1 No, do not release it because ...
+Please select one of the following options:
+ [ ] +1 Release it.
+ [ ] +0 Go ahead; I don't care.
+ [ ] -0 There are a few minor glitches: ...
+ [ ] -1 No, do not release it because ...
-This vote will close in 72 hours, at YYYY-MM-DDThh:mm:ssZ (this is UTC
-time).
+This vote will be open for at least 72 hours, i.e. until 2016-12-10T00:00:00Z
+(this is UTC time).
----------
@@ -381,36 +463,36 @@ After correcting the problems, you'll likely have to start again from step 3,
(16)
After at least 72 hours have elapsed, send a "[VOTE][RESULT]" mail to
summarize the outcome of the vote. This should tally the votes cast,
-and state which are binding (PMC members).
+and state which are binding (PMC members). The vote needs at least three +1's
+from PMC members to pass.
(17)
The distribution files must be moved from the development area to the release
-area of the Apache dist server:
-
-$ svnmucc -U https://dist.apache.org/repos/dist \
- rm release/commons/math/README.html \
- mv dev/commons/math/README.html release/commons/math/README.html \
- rm release/commons/math/RELEASE-NOTES.txt \
- mv dev/commons/math/RELEASE-NOTES.txt release/commons/math/RELEASE-NOTES.txt \
- mv dev/commons/math/binaries/commons-math3-3.4-bin.tar.gz release/commons/math/binaries/commons-math3-3.4-bin.tar.gz \
- mv dev/commons/math/binaries/commons-math3-3.4-bin.tar.gz.asc release/commons/math/binaries/commons-math3-3.4-bin.tar.gz.asc \
- mv dev/commons/math/binaries/commons-math3-3.4-bin.tar.gz.md5 release/commons/math/binaries/commons-math3-3.4-bin.tar.gz.md5 \
- mv dev/commons/math/binaries/commons-math3-3.4-bin.tar.gz.sha1 release/commons/math/binaries/commons-math3-3.4-bin.tar.gz.sha1 \
- mv dev/commons/math/binaries/commons-math3-3.4-bin.zip release/commons/math/binaries/commons-math3-3.4-bin.zip \
- mv dev/commons/math/binaries/commons-math3-3.4-bin.zip.asc release/commons/math/binaries/commons-math3-3.4-bin.zip.asc \
- mv dev/commons/math/binaries/commons-math3-3.4-bin.zip.md5 release/commons/math/binaries/commons-math3-3.4-bin.zip.md5 \
- mv dev/commons/math/binaries/commons-math3-3.4-bin.zip.sha1 release/commons/math/binaries/commons-math3-3.4-bin.zip.sha1 \
- mv dev/commons/math/source/commons-math3-3.4-src.tar.gz release/commons/math/source/commons-math3-3.4-src.tar.gz \
- mv dev/commons/math/source/commons-math3-3.4-src.tar.gz.asc release/commons/math/source/commons-math3-3.4-src.tar.gz.asc \
- mv dev/commons/math/source/commons-math3-3.4-src.tar.gz.md5 release/commons/math/source/commons-math3-3.4-src.tar.gz.md5 \
- mv dev/commons/math/source/commons-math3-3.4-src.tar.gz.sha1 release/commons/math/source/commons-math3-3.4-src.tar.gz.sha1 \
- mv dev/commons/math/source/commons-math3-3.4-src.zip release/commons/math/source/commons-math3-3.4-src.zip \
- mv dev/commons/math/source/commons-math3-3.4-src.zip.asc release/commons/math/source/commons-math3-3.4-src.zip.asc \
- mv dev/commons/math/source/commons-math3-3.4-src.zip.md5 release/commons/math/source/commons-math3-3.4-src.zip.md5 \
- mv dev/commons/math/source/commons-math3-3.4-src.zip.sha1 release/commons/math/source/commons-math3-3.4-src.zip.sha1 \
- -m "Publish commons-math 3.4 Release"
+area of the Apache dist server.
+
+ (17a)
+ Checkout the official distribution repository:
+
+ $ svn co https://dist.apache.org/repos/dist/release/commons/numbers
+
+ (17b)
+ Copy the files from the checkout of the repository that was voted on:
+
+ $ cd numbers
+ $ rsync -Cavz path-to-RC-dev/numbers/ .
+
+ (17c)
+ Check (and possibly "svn add") files.
+ (17d)
+ Commit:
+
+ $ svn commit -m "Release Commons Numbers v1.0 (from RC6)."
+
+ (17e)
+ Register the release at
+ https://reporter.apache.org/addrelease.html?commons
(18)
Release (a.k.a. "promote") the artifacts on the Nexus server, as shown here:
@@ -418,85 +500,139 @@ Release (a.k.a. "promote") the artifacts on the Nexus server, as shown here:
(19)
-Publish the web site. This is done by first committing the web site to the staging area, and then
-by publishing the staging area (which is shared among all commons compoents.
+Publish the web site. This is done by first committing the web site to the
+staging area, and then by publishing the staging area (which is shared among
+all commons components).
-In order to commit the web site to the staging area, look at the subversion workspace that was
-automatically checked out during the 'mvn site' command in folder site-content. You can also check
-it out directly by yourself elsewhere:
+In order to commit the web site to the staging area, look at the subversion
+workspace that was automatically checked out during the 'mvn site' command in
+folder site-content. Note that svn commits in the site-content directory are
+immediately synced with the live site and so your changes should show up in a
+few minutes once you commit the new site. You can also check out the site
+directly by yourself elsewhere:
- svn checkout https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-math site-content
+ $ svn checkout https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-numbers site-content
Remove all files there (except .svn folder) and move all the files from the site.
-You may want to adjust manually some parts like fixing broken relative links or
-copying the content of the current apidocs to javadocs/api-3.4.
$ cd site-content
- $ rm -fr *
- $ cp -pR ../target/site/* .
+ $ rm -rf *
+ $ cp -pR ../target/commons-numbers-1.0-RC1-site/* .
-Check for possibly new files:
+Check for new or deleted files:
$ svn status
-and "svn add" them if necessary.
+and "svn add" or "svn del" them if necessary.
Commit the new contents of the web site:
- $ svn commit -m "updating site after official release of version 3.4"
+ $ svn commit -m "Commons Numbers v1.0 was released (from RC6). Web site update"
-Beware the commit command may be very long (several hours ...). The web site will be available
-for review at:
- http://commons.staging.apache.org/proper/commons-math/
-
-Publishing the staging web site is done directly from a browser at URL:
- https://cms.apache.org/commons/publish
(20)
-The javadocs for several version is kept available on the website under the javadocs directory.
-This corresponds to a huge number of files which never changes, so they are not retrieved by
-default in the working copy when running 'svn checkout'. These javadocs must therefore be
-copied manually using server side copy from the apidocs directory after release, in order for
-the links to former versions to work. This is done as follows:
+The Javadoc for several versions is kept available on the website, under the
+"javadocs" directory.
+There is a huge number of files that never change, so they are not retrieved by
+default in the working copy when running 'svn checkout'.
+The Javadoc must therefore be copied manually using server side copy from the
+"apidocs" directory after release, in order for the links to former versions
+to work. This is done as follows:
+
+ $ export NUMBERS_WEB_SITE_SVN_REVISION=1002658
+ $ export NUMBERS_RELEASE_VERSION=1.0
+ $ svnmucc -U https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-numbers \
+ cp $NUMBERS_WEB_SITE_SVN_REVISION commons-numbers-client-api/apidocs \
+ commons-numbers-client-api/javadocs/api-$NUMBERS_RELEASE_VERSION \
+ cp $NUMBERS_WEB_SITE_SVN_REVISION commons-numbers-core/apidocs \
+ commons-numbers-core/javadocs/api-$NUMBERS_RELEASE_VERSION \
+ cp $NUMBERS_WEB_SITE_SVN_REVISION commons-numbers-simple/apidocs \
+ commons-numbers-simple/javadocs/api-$NUMBERS_RELEASE_VERSION \
+ cp $NUMBERS_WEB_SITE_SVN_REVISION commons-numbers-sampling/apidocs \
+ commons-numbers-sampling/javadocs/api-$NUMBERS_RELEASE_VERSION \
+ cp $NUMBERS_WEB_SITE_SVN_REVISION commons-numbers-jmh/apidocs \
+ commons-numbers-jmh/javadocs/api-$NUMBERS_RELEASE_VERSION \
+ cp $NUMBERS_WEB_SITE_SVN_REVISION commons-numbers-examples/apidocs \
+ commons-numbers-examples/javadocs/api-$NUMBERS_RELEASE_VERSION \
+ -m "Commons NUMBERS: Copying $NUMBERS_RELEASE_VERSION apidocs to versioned directories for the long-term links."
+
+Now wait a few minutes for the live site to fully sync and then check
+ http://commons.apache.org/proper/commons-numbers/
+to make sure that everything looks correct.
- $ svn cp -m "copying 3.4 apidocs to versioned directory for the long-term links" \
- https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-math/apidocs \
- https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-math/javadocs/api-3.4
(21)
Put the official final tag to point at the same commit as the last release candidate tag:
- $ git tag -s -m "RC1 becomes the 3.4 official version." MATH_3_4 cf4a9d70c9ac24dd7196995390171150e4e56451
+ $ git tag -u "__Your_key_id__" -s -m "RC6 becomes v1.0 official release." NUMBERS_1_0 cf4a9d70c9ac24dd7196995390171150e4e56451
$ git push --tags
(22)
-Clean up files and prepare for next version (here we assume it will be 3.5):
+Switch back to the "master" branch.
+We now prepare for the next round of development (here we assume that the
+next version will be 1.1).
-edit "doap_math.rdf" to add the just released version date.
+ (22a)
+ Edit "doap_numbers.rdf" to add the just released version date.
+ It is located at
+ https://svn.apache.org/repos/asf/commons/cms-site/trunk/doap
+ in the SVN repository.
-edit "pom.xml" so it contains
-
- <version>3.5-SNAPSHOT</version>
+ (22b)
+ Retrieve files from the "1.0-release branch" (so that the web site will
+ contain up-to-date information):
-edit "src/changes/changes.xml" to add a new section for the next release, setting
-the release date to "TBD" and the description to the empty string.
+ $ git checkout 1.0-release src/site/xdoc/download_numbers.xml
+ $ git checkout 1.0-release src/changes/changes.xml
-Double-check "pom.xml" *really* has a -SNAPSHOT version and commit everything:
+ Edit "src/changes/changes.xml" to add a new section for the next release,
+ setting the release date and description to "TBD".
+ Then commit them.
- $ git add doap_math.rdf pom.xml src/changes/changes.xml
- $ git commit -m "preparing next version 3.5"
- $ git push
+ (22c)
+ Edit every "pom.xml" file (i.e. for each module) to contain
+ <version>1.1-SNAPSHOT</version>
-(23)
-Switch back to master and merge the X.Y-release branch
+ Double-check that the "pom.xml" files *really* have a "-SNAPSHOT" suffix
+ in the "<version>" property.
+ Then commit them.
- $ git checkout master
- $ get merge X.Y-release
- $ git push
+ Push everything to the Apache repository.
-(24)
+(23)
Allow for the web site mirrors to be updated (possibly several hours); then
send (from your apache account) a release announcement to the following ML:
announce@apache.org
dev@commons.apache.org
user@commons.apache.org
+
+If you don't have it setup already you can follow these instructions to send
+email from your apache account :
+
+https://reference.apache.org/committer/email#sendingemailfromyourapacheorgemailaddress
+
+You can use the following message as a template:
+
+----------
+The Apache Commons Team is pleased to announce the availability of
+version 1.0 of "Apache Commons Numbers".
+
+Apache Commons Numbers provides number types such as complex, quaternion
+fraction, and associated utilities.
+
+The release notes can be reviewed at
+ https://www.apache.org/dist/commons/numbers/RELEASE-NOTES.txt
+
+Distribution packages can be downloaded from
+ https://commons.apache.org/proper/commons-numbers/download_numbers.cgi
+
+When downloading, please verify signatures using the KEYS file
+available at
+ https://www.apache.org/dist/commons/KEYS
+
+Maven artifacts are also available in the central Maven repository:
+ https://repo1.maven.org/maven2/org/apache/commons/
+
+
+The Apache Commons Team
+----------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/b7dc0cf8/doc/release/settings.xml
----------------------------------------------------------------------
diff --git a/doc/release/settings.xml b/doc/release/settings.xml
index ff0adf6..3123dc0 100644
--- a/doc/release/settings.xml
+++ b/doc/release/settings.xml
@@ -55,6 +55,7 @@
<id>release</id>
<properties>
<gpg.keyname>__Your_key_identifier__</gpg.keyname>
+ <gpg.executable>gpg2</gpg.executable>
</properties>
</profile>
</profiles>
[21/31] commons-numbers git commit: Javadoc.
Posted by er...@apache.org.
Javadoc.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/d93af779
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/d93af779
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/d93af779
Branch: refs/heads/master
Commit: d93af7790f25beaf6fb6c81b2f1e95fc6711b525
Parents: 8dc0ad8
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Fri Jan 20 13:53:33 2017 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Fri Jan 20 13:53:33 2017 +0100
----------------------------------------------------------------------
.../java/org/apache/commons/numbers/complex/Complex.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/d93af779/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
----------------------------------------------------------------------
diff --git a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
index 9581f81..219681b 100644
--- a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
+++ b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
@@ -38,10 +38,10 @@ import java.util.List;
* Note that this contradicts the IEEE-754 standard for floating
* point numbers (according to which the test {@code x == x} must fail if
* {@code x} is {@code NaN}). The method
- * {@link org.apache.commons.numbers.complex.util.Precision#equals(double,double,int)
- * equals for primitive double} in {@link org.apache.commons.numbers.complex.util.Precision}
- * conforms with IEEE-754 while this class conforms with the standard behavior
- * for Java object types.</p>
+ * {@link org.apache.commons.numbers.core.Precision#equals(double,double,int)
+ * equals for primitive double} in class {@code Precision} conforms with
+ * IEEE-754 while this class conforms with the standard behavior for Java
+ * object types.</p>
*
*/
public class Complex implements Serializable {
[25/31] commons-numbers git commit: Correct project info.
Posted by er...@apache.org.
Correct project info.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/f3d40f85
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/f3d40f85
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/f3d40f85
Branch: refs/heads/master
Commit: f3d40f857b21005177eda7d794832fc119e46668
Parents: 3413c4a
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Fri Jan 20 14:43:00 2017 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Fri Jan 20 14:43:00 2017 +0100
----------------------------------------------------------------------
pom.xml | 2 +-
src/site/xdoc/issue-tracking.xml | 12 ++++++------
2 files changed, 7 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/f3d40f85/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index b1e4336..9d683ae 100644
--- a/pom.xml
+++ b/pom.xml
@@ -96,7 +96,7 @@
<commons.binary.suffix>-bin</commons.binary.suffix>
<commons.jira.id>NUMBERS</commons.jira.id>
- <commons.jira.pid>12310485</commons.jira.pid>
+ <commons.jira.pid>12320720</commons.jira.pid>
<commons.encoding>UTF-8</commons.encoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/f3d40f85/src/site/xdoc/issue-tracking.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/issue-tracking.xml b/src/site/xdoc/issue-tracking.xml
index 222833a..b3ecae0 100644
--- a/src/site/xdoc/issue-tracking.xml
+++ b/src/site/xdoc/issue-tracking.xml
@@ -65,13 +65,13 @@ limitations under the License.
If you would like to report a bug, or raise an enhancement request with
Apache Commons Numbers please do the following:
<ol>
- <li><a href="https://issues.apache.org/jira/secure/IssueNavigator.jspa?reset=true&pid=12310485&sorter/field=issuekey&sorter/order=DESC&status=1&status=3&status=4">Search existing open bugs</a>.
+ <li><a href="https://issues.apache.org/jira/secure/IssueNavigator.jspa?reset=true&pid=12320720&sorter/field=issuekey&sorter/order=DESC&status=1&status=3&status=4">Search existing open bugs</a>.
If you find your issue listed then please add a comment with your details.</li>
<li><a href="mail-lists.html">Search the mailing list archive(s)</a>.
You may find your issue or idea has already been discussed.</li>
<li>Decide if your issue is a bug or an enhancement.</li>
- <li>Submit either a <a href="https://issues.apache.org/jira/secure/CreateIssueDetails!init.jspa?pid=12310485&issuetype=1&priority=4&assignee=-1">bug report</a>
- or <a href="https://issues.apache.org/jira/secure/CreateIssueDetails!init.jspa?pid=12310485&issuetype=4&priority=4&assignee=-1">enhancement request</a>.</li>
+ <li>Submit either a <a href="https://issues.apache.org/jira/secure/CreateIssueDetails!init.jspa?pid=12320720&issuetype=1&priority=4&assignee=-1">bug report</a>
+ or <a href="https://issues.apache.org/jira/secure/CreateIssueDetails!init.jspa?pid=12320720&issuetype=4&priority=4&assignee=-1">enhancement request</a>.</li>
</ol>
</p>
@@ -92,9 +92,9 @@ limitations under the License.
<p>
You may also find these links useful:
<ul>
- <li><a href="https://issues.apache.org/jira/secure/IssueNavigator.jspa?reset=true&pid=12310485&sorter/field=issuekey&sorter/order=DESC&status=1&status=3&status=4">All Open Apache Commons Numbers bugs</a></li>
- <li><a href="https://issues.apache.org/jira/secure/IssueNavigator.jspa?reset=true&pid=12310485&sorter/field=issuekey&sorter/order=DESC&status=5&status=6">All Resolved Apache Commons Numbers bugs</a></li>
- <li><a href="https://issues.apache.org/jira/secure/IssueNavigator.jspa?reset=true&pid=12310485&sorter/field=issuekey&sorter/order=DESC">All Apache Commons Numbers bugs</a></li>
+ <li><a href="https://issues.apache.org/jira/secure/IssueNavigator.jspa?reset=true&pid=12320720&sorter/field=issuekey&sorter/order=DESC&status=1&status=3&status=4">All Open Apache Commons Numbers bugs</a></li>
+ <li><a href="https://issues.apache.org/jira/secure/IssueNavigator.jspa?reset=true&pid=12320720&sorter/field=issuekey&sorter/order=DESC&status=5&status=6">All Resolved Apache Commons Numbers bugs</a></li>
+ <li><a href="https://issues.apache.org/jira/secure/IssueNavigator.jspa?reset=true&pid=12320720&sorter/field=issuekey&sorter/order=DESC">All Apache Commons Numbers bugs</a></li>
</ul>
</p>
</section>
[02/31] commons-numbers git commit: Cleanup (massive delete).
Posted by er...@apache.org.
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/java/org/apache/commons/complex/ComplexUtilsTest.java.orig
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/complex/ComplexUtilsTest.java.orig b/src/test/java/org/apache/commons/complex/ComplexUtilsTest.java.orig
deleted file mode 100755
index 7ba7fa1..0000000
--- a/src/test/java/org/apache/commons/complex/ComplexUtilsTest.java.orig
+++ /dev/null
@@ -1,608 +0,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.
- */
-
-package org.apache.commons.complex.complex;
-
-import org.apache.commons.complex.TestUtils;
-import org.apache.commons.complex.complex.Complex;
-import org.apache.commons.complex.complex.ComplexUtils;
-import org.apache.commons.complex.exception.MathIllegalArgumentException;
-import org.apache.commons.complex.util.FastMath;
-import org.apache.commons.complex.util.IntegerSequence;
-import org.apache.commons.complex.util.IntegerSequence.Range;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.Assert;
-
-/**
- */
-public class ComplexUtilsTest {
-
- private final double inf = Double.POSITIVE_INFINITY;
- private final double negInf = Double.NEGATIVE_INFINITY;
- private final double nan = Double.NaN;
- private final double pi = FastMath.PI;
-
- private final Complex negInfInf = new Complex(negInf, inf);
- private final Complex infNegInf = new Complex(inf, negInf);
- private final Complex infInf = new Complex(inf, inf);
- private final Complex negInfNegInf = new Complex(negInf, negInf);
- private final Complex infNaN = new Complex(inf, nan);
-
- private static Complex c[]; // complex array with real values even and imag
- // values odd
- private static Complex cr[]; // complex array with real values consecutive
- private static Complex ci[]; // complex array with imag values consecutive
- private static double d[]; // real array with consecutive vals
- private static double di[]; // real array with consecutive vals,
- // 'interleaved' length
- private static float f[]; // real array with consecutive vals
- private static float fi[]; // real array with consec vals, interleaved
- // length
- private static double sr[]; // real component of split array, evens
- private static double si[]; // imag component of split array, odds
- private static float sfr[]; // real component of split array, float, evens
- private static float sfi[]; // imag component of split array, float, odds
- static Complex ans1, ans2; // answers to single value extraction methods
- static Range range1, range2; // ranges used to test with
- // IntegerRange
- static Complex[] ansArrayc1r, ansArrayc1i, ansArrayc2r, ansArrayc2i, ansArrayc3, ansArrayc4; // answers
- // to
- // range
- // extraction
- // methods
- static double[] ansArrayd1r, ansArrayd2r, ansArrayd1i, ansArrayd2i, ansArraydi1, ansArraydi2;
- static float[] ansArrayf1r, ansArrayf2r, ansArrayf1i, ansArrayf2i, ansArrayfi1, ansArrayfi2;
- static String msg; // error message for AssertEquals
- static Complex[][] c2d, cr2d, ci2d; // for 2d methods
- static Complex[][][] c3d, cr3d, ci3d; // for 3d methods
- static double[][] d2d, di2d, sr2d, si2d;
- static double[][][] d3d, di3d, sr3d, si3d;
- static float[][] f2d, fi2d, sfr2d, sfi2d;
- static float[][][] f3d, fi3d, sfr3d, sfi3d;
-
- private static void setArrays() { // initial setup method
- c = new Complex[10];
- cr = new Complex[10];
- ci = new Complex[10];
- d = new double[10];
- f = new float[10];
- di = new double[20];
- fi = new float[20];
- sr = new double[10];
- si = new double[10];
- sfr = new float[10];
- sfi = new float[10];
- c2d = new Complex[10][10];
- cr2d = new Complex[10][10];
- ci2d = new Complex[10][10];
- c3d = new Complex[10][10][10];
- cr3d = new Complex[10][10][10];
- ci3d = new Complex[10][10][10];
- d2d = new double[10][10];
- d3d = new double[10][10][10];
- f2d = new float[10][10];
- f3d = new float[10][10][10];
- sr2d = new double[10][10];
- sr3d = new double[10][10][10];
- si2d = new double[10][10];
- si3d = new double[10][10][10];
- sfr2d = new float[10][10];
- sfr3d = new float[10][10][10];
- sfi2d = new float[10][10];
- sfi3d = new float[10][10][10];
- di2d = new double[10][20];
- di3d = new double[10][10][20];
- fi2d = new float[10][20];
- fi3d = new float[10][10][20];
- range1 = IntegerSequence.range(3, 7);
- range2 = IntegerSequence.range(3, 7, 2);
- for (int i = 0; i < 20; i += 2) {
- d[i / 2] = i / 2;
- f[i / 2] = i / 2;
- di[i] = i;
- di[i + 1] = i + 1;
- fi[i] = i;
- fi[i + 1] = i + 1;
- c[i / 2] = new Complex(i, i + 1);
- cr[i / 2] = new Complex(i / 2);
- ci[i / 2] = new Complex(0, i / 2);
- sr[i / 2] = i;
- si[i / 2] = i + 1;
- sfr[i / 2] = i;
- sfi[i / 2] = i + 1;
- }
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 20; j += 2) {
- d2d[i][j / 2] = 10 * i + j / 2;
- f2d[i][j / 2] = 10 * i + j / 2;
- sr2d[i][j / 2] = 10 * i + j;
- si2d[i][j / 2] = 10 * i + j + 1;
- sfr2d[i][j / 2] = 10 * i + j;
- sfi2d[i][j / 2] = 10 * i + j + 1;
- di2d[i][j] = 10 * i + j;
- di2d[i][j + 1] = 10 * i + j + 1;
- fi2d[i][j] = 10 * i + j;
- fi2d[i][j + 1] = 10 * i + j + 1;
- c2d[i][j / 2] = new Complex(10 * i + j, 10 * i + j + 1);
- cr2d[i][j / 2] = new Complex(10 * i + j / 2);
- ci2d[i][j / 2] = new Complex(0, 10 * i + j / 2);
- }
- }
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- for (int k = 0; k < 20; k += 2) {
- d3d[i][j][k / 2] = 100 * i + 10 * j + k / 2;
- f3d[i][j][k / 2] = 100 * i + 10 * j + k / 2;
- sr3d[i][j][k / 2] = 100 * i + 10 * j + k;
- si3d[i][j][k / 2] = 100 * i + 10 * j + k + 1;
- sfr3d[i][j][k / 2] = 100 * i + 10 * j + k;
- sfi3d[i][j][k / 2] = 100 * i + 10 * j + k + 1;
- di3d[i][j][k] = 100 * i + 10 * j + k;
- di3d[i][j][k + 1] = 100 * i + 10 * j + k + 1;
- fi3d[i][j][k] = 100 * i + 10 * j + k;
- fi3d[i][j][k + 1] = 100 * i + 10 * j + k + 1;
- c3d[i][j][k / 2] = new Complex(100 * i + 10 * j + k, 100 * i + 10 * j + k + 1);
- cr3d[i][j][k / 2] = new Complex(100 * i + 10 * j + k / 2);
- ci3d[i][j][k / 2] = new Complex(0, 100 * i + 10 * j + k / 2);
- }
- }
- }
- ansArrayc1r = new Complex[] { new Complex(3), new Complex(4), new Complex(5), new Complex(6), new Complex(7) };
- ansArrayc2r = new Complex[] { new Complex(3), new Complex(5), new Complex(7) };
- ansArrayc1i = new Complex[] { new Complex(0, 3), new Complex(0, 4), new Complex(0, 5), new Complex(0, 6),
- new Complex(0, 7) };
- ansArrayc2i = new Complex[] { new Complex(0, 3), new Complex(0, 5), new Complex(0, 7) };
- ansArrayc3 = new Complex[] { new Complex(6, 7), new Complex(8, 9), new Complex(10, 11), new Complex(12, 13),
- new Complex(14, 15) };
- ansArrayc4 = new Complex[] { new Complex(6, 7), new Complex(10, 11), new Complex(14, 15) };
- ansArrayd1r = new double[] { 6, 8, 10, 12, 14 };
- ansArrayd1i = new double[] { 7, 9, 11, 13, 15 };
- ansArrayd2r = new double[] { 6, 10, 14 };
- ansArrayd2i = new double[] { 7, 11, 15 };
- ansArrayf1r = new float[] { 6, 8, 10, 12, 14 };
- ansArrayf1i = new float[] { 7, 9, 11, 13, 15 };
- ansArrayf2r = new float[] { 6, 10, 14 };
- ansArrayf2i = new float[] { 7, 11, 15 };
- ansArraydi1 = new double[] { 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
- ansArrayfi1 = new float[] { 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
- ansArraydi2 = new double[] { 6, 7, 10, 11, 14, 15 };
- ansArrayfi2 = new float[] { 6, 7, 10, 11, 14, 15 };
- msg = "";
- }
-
- @Test
- public void testPolar2Complex() {
- TestUtils.assertEquals(Complex.ONE, ComplexUtils.polar2Complex(1, 0), 10e-12);
- TestUtils.assertEquals(Complex.ZERO, ComplexUtils.polar2Complex(0, 1), 10e-12);
- TestUtils.assertEquals(Complex.ZERO, ComplexUtils.polar2Complex(0, -1), 10e-12);
- TestUtils.assertEquals(Complex.I, ComplexUtils.polar2Complex(1, pi / 2), 10e-12);
- TestUtils.assertEquals(Complex.I.negate(), ComplexUtils.polar2Complex(1, -pi / 2), 10e-12);
- double r = 0;
- for (int i = 0; i < 5; i++) {
- r += i;
- double theta = 0;
- for (int j = 0; j < 20; j++) {
- theta += pi / 6;
- TestUtils.assertEquals(altPolar(r, theta), ComplexUtils.polar2Complex(r, theta), 10e-12);
- }
- theta = -2 * pi;
- for (int j = 0; j < 20; j++) {
- theta -= pi / 6;
- TestUtils.assertEquals(altPolar(r, theta), ComplexUtils.polar2Complex(r, theta), 10e-12);
- }
- }
- }
-
- protected Complex altPolar(double r, double theta) {
- return Complex.I.multiply(new Complex(theta, 0)).exp().multiply(new Complex(r, 0));
- }
-
- @Test(expected = MathIllegalArgumentException.class)
- public void testPolar2ComplexIllegalModulus() {
- ComplexUtils.polar2Complex(-1, 0);
- }
-
- @Test
- public void testPolar2ComplexNaN() {
- TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(nan, 1));
- TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(1, nan));
- TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(nan, nan));
- }
-
- @Test
- public void testPolar2ComplexInf() {
- TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(1, inf));
- TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(1, negInf));
- TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(inf, inf));
- TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(inf, negInf));
- TestUtils.assertSame(infInf, ComplexUtils.polar2Complex(inf, pi / 4));
- TestUtils.assertSame(infNaN, ComplexUtils.polar2Complex(inf, 0));
- TestUtils.assertSame(infNegInf, ComplexUtils.polar2Complex(inf, -pi / 4));
- TestUtils.assertSame(negInfInf, ComplexUtils.polar2Complex(inf, 3 * pi / 4));
- TestUtils.assertSame(negInfNegInf, ComplexUtils.polar2Complex(inf, 5 * pi / 4));
- }
-
- @Test
- public void testCExtract() {
- final double[] real = new double[] { negInf, -123.45, 0, 1, 234.56, pi, inf };
- final Complex[] complex = ComplexUtils.real2Complex(real);
-
- for (int i = 0; i < real.length; i++) {
- Assert.assertEquals(real[i], complex[i].getReal(), 0d);
- }
- }
-
- // EXTRACTION METHODS
-
- @Test
- public void testExtractionMethods() {
- setArrays();
- // Extract complex from real double array, index 3
- TestUtils.assertSame(new Complex(3), ComplexUtils.extractComplexFromRealArray(d, 3));
- // Extract complex from real float array, index 3
- TestUtils.assertSame(new Complex(3), ComplexUtils.extractComplexFromRealArray(f, 3));
- // Extract real double from complex array, index 3
- TestUtils.assertSame(6, ComplexUtils.extractRealFromComplexArray(c, 3));
- // Extract real float from complex array, index 3
- TestUtils.assertSame(6, ComplexUtils.extractRealFloatFromComplexArray(c, 3));
- // Extract complex from interleaved double array, index 3
- TestUtils.assertSame(new Complex(6, 7), ComplexUtils.extractComplexFromInterleavedArray(d, 3));
- // Extract complex from interleaved float array, index 3
- TestUtils.assertSame(new Complex(6, 7), ComplexUtils.extractComplexFromInterleavedArray(f, 3));
- // Extract interleaved double from complex array, index 3
- TestUtils.assertEquals(msg, new double[] { 6, 7 }, ComplexUtils.extractInterleavedFromComplexArray(c, 3),
-<<<<<<< HEAD
- Math.ulp(1));
- // Extract interleaved float from complex array, index 3
- TestUtils.assertEquals(msg, new double[] { 6, 7 }, ComplexUtils.extractInterleavedFromComplexArray(c, 3),
- Math.ulp(1));
-=======
- Math.ulp(1.0));
- // Extract interleaved float from complex array, index 3
- TestUtils.assertEquals(msg, new double[] { 6, 7 }, ComplexUtils.extractInterleavedFromComplexArray(c, 3),
- Math.ulp(1.0));
->>>>>>> 35ca5e10659d265613b4c3ed8a89f96ad6ce7ae7
- if (!msg.equals("")) {
- throw new RuntimeException(msg);
- }
- }
- // REAL <-> COMPLEX
-
- @Test
- public void testRealToComplex() {
- setArrays();
- // Real double to complex, range 3-7, increment 1, entered as ints
- TestUtils.assertEquals(msg, ansArrayc1r, ComplexUtils.real2Complex(d, 3, 7),Math.ulp(1.0));
- // Real float to complex, range 3-7, increment 1, entered as ints
- TestUtils.assertEquals(msg, ansArrayc1r, ComplexUtils.real2Complex(f, 3, 7),Math.ulp(1.0));
- // Real double to complex, range 3-7, increment 2, entered as ints
- TestUtils.assertEquals(msg, ansArrayc2r, ComplexUtils.real2Complex(d, 3, 7, 2),Math.ulp(1.0));
- // Real float to complex, range 3-7, increment 2, entered as ints
- TestUtils.assertEquals(msg, ansArrayc2r, ComplexUtils.real2Complex(f, 3, 7, 2),Math.ulp(1.0));
- // Real double to complex, range 3-7, increment 1, using IntegerSequence
- TestUtils.assertEquals(msg, ansArrayc1r, ComplexUtils.real2Complex(d, range1),Math.ulp(1.0));
- // Real float to complex, range 3-7, increment 1, using IntegerSequence
- TestUtils.assertEquals(msg, ansArrayc1r, ComplexUtils.real2Complex(f, range1),Math.ulp(1.0));
- // Real double to complex, range 3-7, increment 2, using IntegerSequence
- TestUtils.assertEquals(msg, ansArrayc2r, ComplexUtils.real2Complex(d, 3, 7, 2),Math.ulp(1.0));
- // Real float to complex, range 3-7, increment 2, using IntegerSequence
- TestUtils.assertEquals(msg, ansArrayc2r, ComplexUtils.real2Complex(f, 3, 7, 2),Math.ulp(1.0));
- // Real double to complex, whole array
- TestUtils.assertEquals(msg, cr, ComplexUtils.real2Complex(d),Math.ulp(1.0));
- // Real float to complex, whole array
- TestUtils.assertEquals(msg, cr, ComplexUtils.real2Complex(f),Math.ulp(1.0));
- // 2d
- for (int i = 0; i < 10; i++) {
- // Real double to complex, 2d
- TestUtils.assertEquals(msg, cr2d[i], ComplexUtils.real2Complex(d2d[i]),Math.ulp(1.0));
- // Real float to complex, 2d
- TestUtils.assertEquals(msg, cr2d[i], ComplexUtils.real2Complex(f2d[i]),Math.ulp(1.0));
- }
- // 3d
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- // Real double to complex, 3d
- TestUtils.assertEquals(msg, cr3d[i][j], ComplexUtils.real2Complex(d3d[i][j]),Math.ulp(1.0));
- // Real float to complex, 3d
- TestUtils.assertEquals(msg, cr3d[i][j], ComplexUtils.real2Complex(f3d[i][j]),Math.ulp(1.0));
- }
- }
- if (!msg.equals("")) {
- throw new RuntimeException(msg);
- }
- }
-
- @Test
- public void testComplexToReal() {
- setArrays();
- // Real complex to double, range 3-7, increment 1, entered as ints
- TestUtils.assertEquals(msg, ansArrayd1r, ComplexUtils.complex2Real(c, 3, 7),Math.ulp(1.0));
- // Real complex to float, range 3-7, increment 1, entered as ints
- TestUtils.assertEquals(msg, ansArrayf1r, ComplexUtils.complex2RealFloat(c, 3, 7),Math.ulp(1.0f));
- // Real complex to double, range 3-7, increment 2, entered as ints
- TestUtils.assertEquals(msg, ansArrayd2r, ComplexUtils.complex2Real(c, 3, 7, 2),Math.ulp(1.0));
- // Real complex to float, range 3-7, increment 2, entered as ints
- TestUtils.assertEquals(msg, ansArrayf2r, ComplexUtils.complex2RealFloat(c, 3, 7, 2),Math.ulp(1.0f));
- // Real complex to double, range 3-7, increment 1, using IntegerSequence
- TestUtils.assertEquals(msg, ansArrayd1r, ComplexUtils.complex2Real(c, range1),Math.ulp(1.0));
- // Real complex to float, range 3-7, increment 1, using IntegerSequence
- TestUtils.assertEquals(msg, ansArrayf1r, ComplexUtils.complex2RealFloat(c, range1),Math.ulp(1.0f));
- // Real complex to double, range 3-7, increment 2, using IntegerSequence
- TestUtils.assertEquals(msg, ansArrayd2r, ComplexUtils.complex2Real(c, 3, 7, 2),Math.ulp(1.0));
- // Real complex to float, range 3-7, increment 2, using IntegerSequence
- TestUtils.assertEquals(msg, ansArrayf2r, ComplexUtils.complex2RealFloat(c, 3, 7, 2),Math.ulp(1.0f));
- // Real complex to double, whole array
- TestUtils.assertEquals(msg, sr, ComplexUtils.complex2Real(c),Math.ulp(1.0));
- // Real complex to float, whole array
- TestUtils.assertEquals(msg, sfr, ComplexUtils.complex2RealFloat(c),Math.ulp(1.0f));
- // 2d
- for (int i = 0; i < 10; i++) {
- // Real complex to double, 2d
- TestUtils.assertEquals(msg, sr2d[i], ComplexUtils.complex2Real(c2d[i]),Math.ulp(1.0));
- // Real complex to float, 2d
- TestUtils.assertEquals(msg, sfr2d[i], ComplexUtils.complex2RealFloat(c2d[i]),Math.ulp(1.0f));
- }
- // 3d
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- // Real complex to double, 3d
- TestUtils.assertEquals(msg, sr3d[i][j], ComplexUtils.complex2Real(c3d[i][j]),Math.ulp(1.0));
- // Real complex to float, 3d
- TestUtils.assertEquals(msg, sfr3d[i][j], ComplexUtils.complex2RealFloat(c3d[i][j]),Math.ulp(1.0f));
- }
- }
- if (!msg.equals("")) {
- throw new RuntimeException(msg);
- }
- }
-
- // IMAGINARY <-> COMPLEX
-
- @Test
- public void testImaginaryToComplex() {
- setArrays();
- // Imaginary double to complex, range 3-7, increment 1, entered as ints
- TestUtils.assertEquals(msg, ansArrayc1i, ComplexUtils.imaginary2Complex(d, 3, 7),Math.ulp(1.0));
- // Imaginary float to complex, range 3-7, increment 1, entered as ints
- TestUtils.assertEquals(msg, ansArrayc1i, ComplexUtils.imaginary2Complex(f, 3, 7),Math.ulp(1.0));
- // Imaginary double to complex, range 3-7, increment 2, entered as ints
- TestUtils.assertEquals(msg, ansArrayc2i, ComplexUtils.imaginary2Complex(d, 3, 7, 2),Math.ulp(1.0));
- // Imaginary float to complex, range 3-7, increment 2, entered as ints
- TestUtils.assertEquals(msg, ansArrayc2i, ComplexUtils.imaginary2Complex(f, 3, 7, 2),Math.ulp(1.0));
- // Imaginary double to complex, range 3-7, increment 1, using
- // IntegerSequence
- TestUtils.assertEquals(msg, ansArrayc1i, ComplexUtils.imaginary2Complex(d, range1),Math.ulp(1.0));
- // Imaginary float to complex, range 3-7, increment 1, using
- // IntegerSequence
- TestUtils.assertEquals(msg, ansArrayc1i, ComplexUtils.imaginary2Complex(f, range1),Math.ulp(1.0));
- // Imaginary double to complex, range 3-7, increment 2, using
- // IntegerSequence
- TestUtils.assertEquals(msg, ansArrayc2i, ComplexUtils.imaginary2Complex(d, 3, 7, 2),Math.ulp(1.0));
- // Imaginary float to complex, range 3-7, increment 2, using
- // IntegerSequence
- TestUtils.assertEquals(msg, ansArrayc2i, ComplexUtils.imaginary2Complex(f, 3, 7, 2),Math.ulp(1.0));
- // Imaginary double to complex, whole array
- TestUtils.assertEquals(msg, ci, ComplexUtils.imaginary2Complex(d),Math.ulp(1.0));
- // Imaginary float to complex, whole array
- TestUtils.assertEquals(msg, ci, ComplexUtils.imaginary2Complex(f),Math.ulp(1.0));
- // 2d
- for (int i = 0; i < 10; i++) {
- // Imaginary double to complex, 2d
- TestUtils.assertEquals(msg, ci2d[i], ComplexUtils.imaginary2Complex(d2d[i]),Math.ulp(1.0));
- // Imaginary float to complex, 2d
- TestUtils.assertEquals(msg, ci2d[i], ComplexUtils.imaginary2Complex(f2d[i]),Math.ulp(1.0));
- }
- // 3d
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- // Imaginary double to complex, 3d
- TestUtils.assertEquals(msg, ci3d[i][j], ComplexUtils.imaginary2Complex(d3d[i][j]),Math.ulp(1.0));
- // Imaginary float to complex, 3d
- TestUtils.assertEquals(msg, ci3d[i][j], ComplexUtils.imaginary2Complex(f3d[i][j]),Math.ulp(1.0));
- }
- }
- if (!msg.equals("")) {
- throw new RuntimeException(msg);
- }
- }
-
- @Test
- public void testComplexToImaginary() {
- setArrays();
- // Imaginary complex to double, range 3-7, increment 1, entered as ints
- TestUtils.assertEquals(msg, ansArrayd1i, ComplexUtils.complex2Imaginary(c, 3, 7),Math.ulp(1.0f));
- // Imaginary complex to float, range 3-7, increment 1, entered as ints
- TestUtils.assertEquals(msg, ansArrayf1i, ComplexUtils.complex2ImaginaryFloat(c, 3, 7),Math.ulp(1.0f));
- // Imaginary complex to double, range 3-7, increment 2, entered as ints
- TestUtils.assertEquals(msg, ansArrayd2i, ComplexUtils.complex2Imaginary(c, 3, 7, 2),Math.ulp(1.0));
- // Imaginary complex to float, range 3-7, increment 2, entered as ints
- TestUtils.assertEquals(msg, ansArrayf2i, ComplexUtils.complex2ImaginaryFloat(c, 3, 7, 2),Math.ulp(1.0f));
- // Imaginary complex to double, range 3-7, increment 1, using
- // IntegerSequence
- TestUtils.assertEquals(msg, ansArrayd1i, ComplexUtils.complex2Imaginary(c, range1),Math.ulp(1.0));
- // Imaginary complex to float, range 3-7, increment 1, using
- // IntegerSequence
- TestUtils.assertEquals(msg, ansArrayf1i, ComplexUtils.complex2ImaginaryFloat(c, range1),Math.ulp(1.0f));
- // Imaginary complex to double, range 3-7, increment 2, using
- // IntegerSequence
- TestUtils.assertEquals(msg, ansArrayd2i, ComplexUtils.complex2Imaginary(c, 3, 7, 2),Math.ulp(1.0));
- // Imaginary complex to float, range 3-7, increment 2, using
- // IntegerSequence
- TestUtils.assertEquals(msg, ansArrayf2i, ComplexUtils.complex2ImaginaryFloat(c, 3, 7, 2),Math.ulp(1.0f));
- // Imaginary complex to double, whole array
- TestUtils.assertEquals(msg, si, ComplexUtils.complex2Imaginary(c),Math.ulp(1.0));
- // Imaginary complex to float, whole array
- TestUtils.assertEquals(msg, sfi, ComplexUtils.complex2ImaginaryFloat(c),Math.ulp(1.0f));
- // 2d
- for (int i = 0; i < 10; i++) {
- // Imaginary complex to double, 2d
- TestUtils.assertEquals(msg, si2d[i], ComplexUtils.complex2Imaginary(c2d[i]),Math.ulp(1.0));
- // Imaginary complex to float, 2d
- TestUtils.assertEquals(msg, sfi2d[i], ComplexUtils.complex2ImaginaryFloat(c2d[i]),Math.ulp(1.0f));
- }
- // 3d
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- // Imaginary complex to double, 3d
- TestUtils.assertEquals(msg, si3d[i][j], ComplexUtils.complex2Imaginary(c3d[i][j]),Math.ulp(1.0));
- // Imaginary complex to float, 3d
- TestUtils.assertEquals(msg, sfi3d[i][j], ComplexUtils.complex2ImaginaryFloat(c3d[i][j]),Math.ulp(1.0f));
- }
- }
- if (!msg.equals("")) {
- throw new RuntimeException(msg);
- }
- }
-
- // INTERLEAVED <-> COMPLEX
-
- @Test
- public void testInterleavedToComplex() {
- setArrays();
- // Interleaved double to complex, range 3-7, increment 1, entered as
- // ints
- TestUtils.assertEquals(msg, ansArrayc3, ComplexUtils.interleaved2Complex(di, 3, 7),Math.ulp(1.0));
- // Interleaved float to complex, range 3-7, increment 1, entered as ints
- TestUtils.assertEquals(msg, ansArrayc3, ComplexUtils.interleaved2Complex(fi, 3, 7),Math.ulp(1.0));
- // Interleaved double to complex, range 3-7, increment 2, entered as
- // ints
- TestUtils.assertEquals(msg, ansArrayc4, ComplexUtils.interleaved2Complex(di, 3, 7, 2),Math.ulp(1.0));
- // Interleaved float to complex, range 3-7, increment 2, entered as ints
- TestUtils.assertEquals(msg, ansArrayc4, ComplexUtils.interleaved2Complex(fi, 3, 7, 2),Math.ulp(1.0));
- // Interleaved double to complex, range 3-7, increment 1, using
- // IntegerSequence
- TestUtils.assertEquals(msg, ansArrayc3, ComplexUtils.interleaved2Complex(di, range1),Math.ulp(1.0));
- // Interleaved float to complex, range 3-7, increment 1, using
- // IntegerSequence
- TestUtils.assertEquals(msg, ansArrayc3, ComplexUtils.interleaved2Complex(fi, range1),Math.ulp(1.0));
- // Interleaved double to complex, range 3-7, increment 2, using
- // IntegerSequence
- TestUtils.assertEquals(msg, ansArrayc4, ComplexUtils.interleaved2Complex(di, 3, 7, 2),Math.ulp(1.0));
- // Interleaved float to complex, range 3-7, increment 2, using
- // IntegerSequence
- TestUtils.assertEquals(msg, ansArrayc4, ComplexUtils.interleaved2Complex(fi, 3, 7, 2),Math.ulp(1.0));
- // Interleaved double to complex, whole array
- TestUtils.assertEquals(msg, c, ComplexUtils.interleaved2Complex(di),Math.ulp(1.0));
- // Interleaved float to complex, whole array
- TestUtils.assertEquals(msg, c, ComplexUtils.interleaved2Complex(fi),Math.ulp(1.0));
- // 2d
- for (int i = 0; i < 10; i++) {
- // Interleaved double to complex, 2d
- TestUtils.assertEquals(msg, c2d[i], ComplexUtils.interleaved2Complex(di2d[i]),Math.ulp(1.0));
- // Interleaved float to complex, 2d
- TestUtils.assertEquals(msg, c2d[i], ComplexUtils.interleaved2Complex(fi2d[i]),Math.ulp(1.0));
- }
- // 3d
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- // Interleaved double to complex, 3d
- TestUtils.assertEquals(msg, c3d[i][j], ComplexUtils.interleaved2Complex(di3d[i][j]),Math.ulp(1.0));
- // Interleaved float to complex, 3d
- TestUtils.assertEquals(msg, c3d[i][j], ComplexUtils.interleaved2Complex(fi3d[i][j]),Math.ulp(1.0));
- }
- }
- if (!msg.equals("")) {
- throw new RuntimeException(msg);
- }
- }
-
- @Test
- public void testComplexToInterleaved() {
- setArrays();
- // Interleaved complex to double, range 3-7, increment 1, entered as
- // ints
- TestUtils.assertEquals(msg, ansArraydi1, ComplexUtils.complex2Interleaved(c, 3, 7),Math.ulp(1.0));
- // Interleaved complex to float, range 3-7, increment 1, entered as ints
- TestUtils.assertEquals(msg, ansArrayfi1, ComplexUtils.complex2InterleavedFloat(c, 3, 7),Math.ulp(1.0f));
- // Interleaved complex to double, range 3-7, increment 2, entered as
- // ints
- TestUtils.assertEquals(msg, ansArraydi2, ComplexUtils.complex2Interleaved(c, 3, 7, 2),Math.ulp(1.0));
- // Interleaved complex to float, range 3-7, increment 2, entered as ints
- TestUtils.assertEquals(msg, ansArrayfi2, ComplexUtils.complex2InterleavedFloat(c, 3, 7, 2),Math.ulp(1.0f));
- // Interleaved complex to double, range 3-7, increment 1, using
- // IntegerSequence
- TestUtils.assertEquals(msg, ansArraydi1, ComplexUtils.complex2Interleaved(c, range1),Math.ulp(1.0));
- // Interleaved complex to float, range 3-7, increment 1, using
- // IntegerSequence
- TestUtils.assertEquals(msg, ansArrayfi1, ComplexUtils.complex2InterleavedFloat(c, range1),Math.ulp(1.0f));
- // Interleaved complex to double, range 3-7, increment 2, using
- // IntegerSequence
- TestUtils.assertEquals(msg, ansArraydi2, ComplexUtils.complex2Interleaved(c, 3, 7, 2),Math.ulp(1.0));
- // Interleaved complex to float, range 3-7, increment 2, using
- // IntegerSequence
- TestUtils.assertEquals(msg, ansArrayfi2, ComplexUtils.complex2InterleavedFloat(c, 3, 7, 2),Math.ulp(1.0f));
- // Interleaved complex to double, whole array
- TestUtils.assertEquals(msg, di, ComplexUtils.complex2Interleaved(c),Math.ulp(1.0));
- // Interleaved complex to float, whole array
- TestUtils.assertEquals(msg, fi, ComplexUtils.complex2InterleavedFloat(c),Math.ulp(1.0f));
- // 2d
- for (int i = 0; i < 10; i++) {
- // Interleaved complex to double, 2d
- TestUtils.assertEquals(msg, di2d[i], ComplexUtils.complex2Interleaved(c2d[i]),Math.ulp(1.0));
- // Interleaved complex to float, 2d
- TestUtils.assertEquals(msg, fi2d[i], ComplexUtils.complex2InterleavedFloat(c2d[i]),Math.ulp(1.0f));
- }
- // 3d
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- // Interleaved complex to double, 3d
- TestUtils.assertEquals(msg, di3d[i][j], ComplexUtils.complex2Interleaved(c3d[i][j]),Math.ulp(1.0));
- // Interleaved complex to float, 3d
- TestUtils.assertEquals(msg, fi3d[i][j], ComplexUtils.complex2InterleavedFloat(c3d[i][j]),Math.ulp(1.0f));
- }
- }
- if (!msg.equals("")) {
- throw new RuntimeException(msg);
- }
- }
-
- // SPLIT TO COMPLEX
- @Test
- public void testSplit2Complex() {
- setArrays();
- // Split double to complex, whole array
- TestUtils.assertEquals(msg, c, ComplexUtils.split2Complex(sr, si),Math.ulp(1.0));
-
- // 2d
- for (int i = 0; i < 10; i++) {
- // Split double to complex, 2d
- TestUtils.assertEquals(msg, c2d[i], ComplexUtils.split2Complex(sr2d[i], si2d[i]),Math.ulp(1.0));
- }
- // 3d
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- // Split double to complex, 3d
- TestUtils.assertEquals(msg, c3d[i][j], ComplexUtils.split2Complex(sr3d[i][j], si3d[i][j]),Math.ulp(1.0));
- }
- }
- if (!msg.equals("")) {
- throw new RuntimeException(msg);
- }
- }
-
- // INITIALIZATION METHODS
-
- @Test
- public void testInitialize() {
- Complex[] c = new Complex[10];
- ComplexUtils.initialize(c);
- for (Complex cc : c) {
- TestUtils.assertEquals(new Complex(0, 0), cc, Math.ulp(0));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/java/org/apache/commons/complex/FrenchComplexFormatTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/complex/FrenchComplexFormatTest.java b/src/test/java/org/apache/commons/complex/FrenchComplexFormatTest.java
deleted file mode 100644
index 5be32b8..0000000
--- a/src/test/java/org/apache/commons/complex/FrenchComplexFormatTest.java
+++ /dev/null
@@ -1,34 +0,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.
- */
-
-package org.apache.commons.complex;
-
-import java.util.Locale;
-
-
-public class FrenchComplexFormatTest extends ComplexFormatAbstractTest {
-
- @Override
- protected char getDecimalCharacter() {
- return ',';
- }
-
- @Override
- protected Locale getLocale() {
- return Locale.FRENCH;
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/java/org/apache/commons/complex/QuaternionTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/complex/QuaternionTest.java b/src/test/java/org/apache/commons/complex/QuaternionTest.java
deleted file mode 100644
index 07941f2..0000000
--- a/src/test/java/org/apache/commons/complex/QuaternionTest.java
+++ /dev/null
@@ -1,459 +0,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.
- */
-package org.apache.commons.complex;
-
-import java.util.Random;
-
-import org.apache.commons.complex.Quaternion;
-import org.junit.Test;
-import org.junit.Assert;
-
-public class QuaternionTest {
- /** Epsilon for double comparison. */
- private static final double EPS = Math.ulp(1d);
- /** Epsilon for double comparison. */
- private static final double COMPARISON_EPS = 1e-14;
-
- @Test
- public final void testAccessors1() {
- final double q0 = 2;
- final double q1 = 5.4;
- final double q2 = 17;
- final double q3 = 0.0005;
- final Quaternion q = new Quaternion(q0, q1, q2, q3);
-
- Assert.assertEquals(q0, q.getQ0(), 0);
- Assert.assertEquals(q1, q.getQ1(), 0);
- Assert.assertEquals(q2, q.getQ2(), 0);
- Assert.assertEquals(q3, q.getQ3(), 0);
- }
-
- @Test
- public final void testAccessors2() {
- final double q0 = 2;
- final double q1 = 5.4;
- final double q2 = 17;
- final double q3 = 0.0005;
- final Quaternion q = new Quaternion(q0, q1, q2, q3);
-
- final double sP = q.getScalarPart();
- final double[] vP = q.getVectorPart();
-
- Assert.assertEquals(q0, sP, 0);
- Assert.assertEquals(q1, vP[0], 0);
- Assert.assertEquals(q2, vP[1], 0);
- Assert.assertEquals(q3, vP[2], 0);
- }
-
- @Test
- public final void testAccessors3() {
- final double q0 = 2;
- final double q1 = 5.4;
- final double q2 = 17;
- final double q3 = 0.0005;
- final Quaternion q = new Quaternion(q0, new double[] { q1, q2, q3 });
-
- final double sP = q.getScalarPart();
- final double[] vP = q.getVectorPart();
-
- Assert.assertEquals(q0, sP, 0);
- Assert.assertEquals(q1, vP[0], 0);
- Assert.assertEquals(q2, vP[1], 0);
- Assert.assertEquals(q3, vP[2], 0);
- }
-
- @Test(expected=IllegalArgumentException.class)
- public void testWrongDimension() {
- new Quaternion(new double[] { 1, 2 });
- }
-
- @Test
- public final void testConjugate() {
- final double q0 = 2;
- final double q1 = 5.4;
- final double q2 = 17;
- final double q3 = 0.0005;
- final Quaternion q = new Quaternion(q0, q1, q2, q3);
-
- final Quaternion qConjugate = q.getConjugate();
-
- Assert.assertEquals(q0, qConjugate.getQ0(), 0);
- Assert.assertEquals(-q1, qConjugate.getQ1(), 0);
- Assert.assertEquals(-q2, qConjugate.getQ2(), 0);
- Assert.assertEquals(-q3, qConjugate.getQ3(), 0);
- }
-
- /* suppressed for initial compatibility in commons-complex
-
-
-
- @Test
- public final void testProductQuaternionQuaternion() {
-
- // Case : analytic test case
-
- final Quaternion qA = new Quaternion(1, 0.5, -3, 4);
- final Quaternion qB = new Quaternion(6, 2, 1, -9);
- final Quaternion qResult = Quaternion.multiply(qA, qB);
-
- Assert.assertEquals(44, qResult.getQ0(), EPS);
- Assert.assertEquals(28, qResult.getQ1(), EPS);
- Assert.assertEquals(-4.5, qResult.getQ2(), EPS);
- Assert.assertEquals(21.5, qResult.getQ3(), EPS);
-
- // comparison with the result given by the formula :
- // qResult = (scalarA * scalarB - vectorA . vectorB) + (scalarA * vectorB + scalarB * vectorA + vectorA ^
- // vectorB)
-
- final Vector3D vectorA = new Vector3D(qA.getVectorPart());
- final Vector3D vectorB = new Vector3D(qB.getVectorPart());
- final Vector3D vectorResult = new Vector3D(qResult.getVectorPart());
-
- final double scalarPartRef = qA.getScalarPart() * qB.getScalarPart() - Vector3D.dotProduct(vectorA, vectorB);
-
- Assert.assertEquals(scalarPartRef, qResult.getScalarPart(), EPS);
-
- final Vector3D vectorPartRef = ((vectorA.scalarMultiply(qB.getScalarPart())).add(vectorB.scalarMultiply(qA
- .getScalarPart()))).add(Vector3D.crossProduct(vectorA, vectorB));
- final double norm = (vectorResult.subtract(vectorPartRef)).getNorm();
-
- Assert.assertEquals(0, norm, EPS);
-
- // Conjugate of the product of two quaternions and product of their conjugates :
- // Conj(qA * qB) = Conj(qB) * Conj(qA)
-
- final Quaternion conjugateOfProduct = qB.getConjugate().multiply(qA.getConjugate());
- final Quaternion productOfConjugate = (qA.multiply(qB)).getConjugate();
-
- Assert.assertEquals(conjugateOfProduct.getQ0(), productOfConjugate.getQ0(), EPS);
- Assert.assertEquals(conjugateOfProduct.getQ1(), productOfConjugate.getQ1(), EPS);
- Assert.assertEquals(conjugateOfProduct.getQ2(), productOfConjugate.getQ2(), EPS);
- Assert.assertEquals(conjugateOfProduct.getQ3(), productOfConjugate.getQ3(), EPS);
- }
-*/
- /*
- @Test
- public final void testProductQuaternionVector() {
-
- // Case : Product between a vector and a quaternion : QxV
-
- final Quaternion quaternion = new Quaternion(4, 7, -1, 2);
- final double[] vector = {2.0, 1.0, 3.0};
- final Quaternion qResultQxV = Quaternion.multiply(quaternion, new Quaternion(vector));
-
- Assert.assertEquals(-19, qResultQxV.getQ0(), EPS);
- Assert.assertEquals(3, qResultQxV.getQ1(), EPS);
- Assert.assertEquals(-13, qResultQxV.getQ2(), EPS);
- Assert.assertEquals(21, qResultQxV.getQ3(), EPS);
-
- // comparison with the result given by the formula :
- // qResult = (- vectorQ . vector) + (scalarQ * vector + vectorQ ^ vector)
-
- final double[] vectorQ = quaternion.getVectorPart();
- final double[] vectorResultQxV = qResultQxV.getVectorPart();
-
- final double scalarPartRefQxV = -Vector3D.dotProduct(new Vector3D(vectorQ), new Vector3D(vector));
- Assert.assertEquals(scalarPartRefQxV, qResultQxV.getScalarPart(), EPS);
-
- final Vector3D vectorPartRefQxV = (new Vector3D(vector).scalarMultiply(quaternion.getScalarPart())).add(Vector3D
- .crossProduct(new Vector3D(vectorQ), new Vector3D(vector)));
- final double normQxV = (new Vector3D(vectorResultQxV).subtract(vectorPartRefQxV)).getNorm();
- Assert.assertEquals(0, normQxV, EPS);
-
- // Case : Product between a vector and a quaternion : VxQ
-
- final Quaternion qResultVxQ = Quaternion.multiply(new Quaternion(vector), quaternion);
-
- Assert.assertEquals(-19, qResultVxQ.getQ0(), EPS);
- Assert.assertEquals(13, qResultVxQ.getQ1(), EPS);
- Assert.assertEquals(21, qResultVxQ.getQ2(), EPS);
- Assert.assertEquals(3, qResultVxQ.getQ3(), EPS);
-
- final double[] vectorResultVxQ = qResultVxQ.getVectorPart();
-
- // comparison with the result given by the formula :
- // qResult = (- vector . vectorQ) + (scalarQ * vector + vector ^ vectorQ)
-
- final double scalarPartRefVxQ = -Vector3D.dotProduct(new Vector3D(vectorQ), new Vector3D(vector));
- Assert.assertEquals(scalarPartRefVxQ, qResultVxQ.getScalarPart(), EPS);
-
- final Vector3D vectorPartRefVxQ = (new Vector3D(vector).scalarMultiply(quaternion.getScalarPart())).add(Vector3D
- .crossProduct(new Vector3D(vector), new Vector3D(vectorQ)));
- final double normVxQ = (new Vector3D(vectorResultVxQ).subtract(vectorPartRefVxQ)).getNorm();
- Assert.assertEquals(0, normVxQ, EPS);
- }
-*/
- @Test
- public final void testDotProductQuaternionQuaternion() {
- // expected output
- final double expected = -6.;
- // inputs
- final Quaternion q1 = new Quaternion(1, 2, 2, 1);
- final Quaternion q2 = new Quaternion(3, -2, -1, -3);
-
- final double actual1 = Quaternion.dotProduct(q1, q2);
- final double actual2 = q1.dotProduct(q2);
-
- Assert.assertEquals(expected, actual1, EPS);
- Assert.assertEquals(expected, actual2, EPS);
- }
-
- @Test
- public final void testScalarMultiplyDouble() {
- // expected outputs
- final double w = 1.6;
- final double x = -4.8;
- final double y = 11.20;
- final double z = 2.56;
- // inputs
- final Quaternion q1 = new Quaternion(0.5, -1.5, 3.5, 0.8);
- final double a = 3.2;
-
- final Quaternion q = q1.multiply(a);
-
- Assert.assertEquals(w, q.getQ0(), COMPARISON_EPS);
- Assert.assertEquals(x, q.getQ1(), COMPARISON_EPS);
- Assert.assertEquals(y, q.getQ2(), COMPARISON_EPS);
- Assert.assertEquals(z, q.getQ3(), COMPARISON_EPS);
- }
-
- @Test
- public final void testAddQuaternionQuaternion() {
- // expected outputs
- final double w = 4;
- final double x = -1;
- final double y = 2;
- final double z = -4;
- // inputs
- final Quaternion q1 = new Quaternion(1., 2., -2., -1.);
- final Quaternion q2 = new Quaternion(3., -3., 4., -3.);
-
- final Quaternion qa = Quaternion.add(q1, q2);
- final Quaternion qb = q1.add(q2);
-
- Assert.assertEquals(w, qa.getQ0(), EPS);
- Assert.assertEquals(x, qa.getQ1(), EPS);
- Assert.assertEquals(y, qa.getQ2(), EPS);
- Assert.assertEquals(z, qa.getQ3(), EPS);
-
- Assert.assertEquals(w, qb.getQ0(), EPS);
- Assert.assertEquals(x, qb.getQ1(), EPS);
- Assert.assertEquals(y, qb.getQ2(), EPS);
- Assert.assertEquals(z, qb.getQ3(), EPS);
- }
-
- @Test
- public final void testSubtractQuaternionQuaternion() {
- // expected outputs
- final double w = -2.;
- final double x = 5.;
- final double y = -6.;
- final double z = 2.;
- // inputs
- final Quaternion q1 = new Quaternion(1., 2., -2., -1.);
- final Quaternion q2 = new Quaternion(3., -3., 4., -3.);
-
- final Quaternion qa = Quaternion.subtract(q1, q2);
- final Quaternion qb = q1.subtract(q2);
-
- Assert.assertEquals(w, qa.getQ0(), EPS);
- Assert.assertEquals(x, qa.getQ1(), EPS);
- Assert.assertEquals(y, qa.getQ2(), EPS);
- Assert.assertEquals(z, qa.getQ3(), EPS);
-
- Assert.assertEquals(w, qb.getQ0(), EPS);
- Assert.assertEquals(x, qb.getQ1(), EPS);
- Assert.assertEquals(y, qb.getQ2(), EPS);
- Assert.assertEquals(z, qb.getQ3(), EPS);
-}
-
- @Test
- public final void testNorm() {
-
- final double q0 = 2;
- final double q1 = 1;
- final double q2 = -4;
- final double q3 = 3;
- final Quaternion q = new Quaternion(q0, q1, q2, q3);
-
- final double norm = q.getNorm();
-
- Assert.assertEquals(Math.sqrt(30), norm, 0);
-
- final double normSquareRef = Quaternion.multiply(q, q.getConjugate()).getScalarPart();
- Assert.assertEquals(Math.sqrt(normSquareRef), norm, 0);
- }
-
- @Test
- public final void testNormalize() {
-
- final Quaternion q = new Quaternion(2, 1, -4, -2);
-
- final Quaternion versor = q.normalize();
-
- Assert.assertEquals(2.0 / 5.0, versor.getQ0(), 0);
- Assert.assertEquals(1.0 / 5.0, versor.getQ1(), 0);
- Assert.assertEquals(-4.0 / 5.0, versor.getQ2(), 0);
- Assert.assertEquals(-2.0 / 5.0, versor.getQ3(), 0);
-
- Assert.assertEquals(1, versor.getNorm(), 0);
- }
-
- @Test(expected=IllegalStateException.class)
- public final void testNormalizeFail() {
- final Quaternion zeroQ = new Quaternion(0, 0, 0, 0);
- zeroQ.normalize();
- }
-
- @Test
- public final void testObjectEquals() {
- final double one = 1;
- final Quaternion q1 = new Quaternion(one, one, one, one);
- Assert.assertTrue(q1.equals(q1));
-
- final Quaternion q2 = new Quaternion(one, one, one, one);
- Assert.assertTrue(q2.equals(q1));
-
- final Quaternion q3 = new Quaternion(one, Math.nextUp(one), one, one);
- Assert.assertFalse(q3.equals(q1));
- }
-
- @Test
- public final void testQuaternionEquals() {
- final double inc = 1e-5;
- final Quaternion q1 = new Quaternion(2, 1, -4, -2);
- final Quaternion q2 = new Quaternion(q1.getQ0() + inc, q1.getQ1(), q1.getQ2(), q1.getQ3());
- final Quaternion q3 = new Quaternion(q1.getQ0(), q1.getQ1() + inc, q1.getQ2(), q1.getQ3());
- final Quaternion q4 = new Quaternion(q1.getQ0(), q1.getQ1(), q1.getQ2() + inc, q1.getQ3());
- final Quaternion q5 = new Quaternion(q1.getQ0(), q1.getQ1(), q1.getQ2(), q1.getQ3() + inc);
-
- Assert.assertFalse(q1.equals(q2, 0.9 * inc));
- Assert.assertFalse(q1.equals(q3, 0.9 * inc));
- Assert.assertFalse(q1.equals(q4, 0.9 * inc));
- Assert.assertFalse(q1.equals(q5, 0.9 * inc));
-
- Assert.assertTrue(q1.equals(q2, 1.1 * inc));
- Assert.assertTrue(q1.equals(q3, 1.1 * inc));
- Assert.assertTrue(q1.equals(q4, 1.1 * inc));
- Assert.assertTrue(q1.equals(q5, 1.1 * inc));
- }
-
- @Test
- public final void testQuaternionEquals2() {
- final Quaternion q1 = new Quaternion(1, 4, 2, 3);
- final double gap = 1e-5;
- final Quaternion q2 = new Quaternion(1 + gap, 4 + gap, 2 + gap, 3 + gap);
-
- Assert.assertTrue(q1.equals(q2, 10 * gap));
- Assert.assertFalse(q1.equals(q2, gap));
- Assert.assertFalse(q1.equals(q2, gap / 10));
- }
-
- @Test
- public final void testIsUnitQuaternion() {
- final Random r = new Random(48);
- final int numberOfTrials = 1000;
- for (int i = 0; i < numberOfTrials; i++) {
- final Quaternion q1 = new Quaternion(r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble());
- final Quaternion q2 = q1.normalize();
- Assert.assertTrue(q2.isUnitQuaternion(COMPARISON_EPS));
- }
-
- final Quaternion q = new Quaternion(1, 1, 1, 1);
- Assert.assertFalse(q.isUnitQuaternion(COMPARISON_EPS));
- }
-
- @Test
- public final void testIsPureQuaternion() {
- final Quaternion q1 = new Quaternion(0, 5, 4, 8);
- Assert.assertTrue(q1.isPureQuaternion(EPS));
-
- final Quaternion q2 = new Quaternion(0 - EPS, 5, 4, 8);
- Assert.assertTrue(q2.isPureQuaternion(EPS));
-
- final Quaternion q3 = new Quaternion(0 - 1.1 * EPS, 5, 4, 8);
- Assert.assertFalse(q3.isPureQuaternion(EPS));
-
- final Random r = new Random(48);
- final double[] v = {r.nextDouble(), r.nextDouble(), r.nextDouble()};
- final Quaternion q4 = new Quaternion(v);
- Assert.assertTrue(q4.isPureQuaternion(0));
-
- final Quaternion q5 = new Quaternion(0, v);
- Assert.assertTrue(q5.isPureQuaternion(0));
- }
-
- /*
- @Test
- public final void testPolarForm() {
- final Random r = new Random(48);
- final int numberOfTrials = 1000;
- for (int i = 0; i < numberOfTrials; i++) {
- final Quaternion q = new Quaternion(2 * (r.nextDouble() - 0.5), 2 * (r.nextDouble() - 0.5),
- 2 * (r.nextDouble() - 0.5), 2 * (r.nextDouble() - 0.5));
- final Quaternion qP = q.getPositivePolarForm();
-
- Assert.assertTrue(qP.isUnitQuaternion(COMPARISON_EPS));
- Assert.assertTrue(qP.getQ0() >= 0);
-
- final Rotation rot = new Rotation(q.getQ0(), q.getQ1(), q.getQ2(), q.getQ3(), true);
- final Rotation rotP = new Rotation(qP.getQ0(), qP.getQ1(), qP.getQ2(), qP.getQ3(), true);
-
- Assert.assertEquals(rot.getAngle(), rotP.getAngle(), COMPARISON_EPS);
- Assert.assertEquals(rot.getAxis(RotationConvention.VECTOR_OPERATOR).getX(),
- rot.getAxis(RotationConvention.VECTOR_OPERATOR).getX(),
- COMPARISON_EPS);
- Assert.assertEquals(rot.getAxis(RotationConvention.VECTOR_OPERATOR).getY(),
- rot.getAxis(RotationConvention.VECTOR_OPERATOR).getY(),
- COMPARISON_EPS);
- Assert.assertEquals(rot.getAxis(RotationConvention.VECTOR_OPERATOR).getZ(),
- rot.getAxis(RotationConvention.VECTOR_OPERATOR).getZ(),
- COMPARISON_EPS);
- }
- }
-*/
- @Test
- public final void testGetInverse() {
- final Quaternion q = new Quaternion(1.5, 4, 2, -2.5);
-
- final Quaternion inverseQ = q.getInverse();
- Assert.assertEquals(1.5 / 28.5, inverseQ.getQ0(), 0);
- Assert.assertEquals(-4.0 / 28.5, inverseQ.getQ1(), 0);
- Assert.assertEquals(-2.0 / 28.5, inverseQ.getQ2(), 0);
- Assert.assertEquals(2.5 / 28.5, inverseQ.getQ3(), 0);
-
- final Quaternion product = Quaternion.multiply(inverseQ, q);
- Assert.assertEquals(1, product.getQ0(), EPS);
- Assert.assertEquals(0, product.getQ1(), EPS);
- Assert.assertEquals(0, product.getQ2(), EPS);
- Assert.assertEquals(0, product.getQ3(), EPS);
-
- final Quaternion qNul = new Quaternion(0, 0, 0, 0);
- try {
- final Quaternion inverseQNul = qNul.getInverse();
- Assert.fail("expecting ZeroException but got : " + inverseQNul);
- } catch (IllegalStateException ex) {
- // expected
- }
- }
-
- @Test
- public final void testToString() {
- final Quaternion q = new Quaternion(1, 2, 3, 4);
- Assert.assertTrue(q.toString().equals("[1.0 2.0 3.0 4.0]"));
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/java/org/apache/commons/complex/Retry.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/complex/Retry.java b/src/test/java/org/apache/commons/complex/Retry.java
deleted file mode 100644
index fd96a24..0000000
--- a/src/test/java/org/apache/commons/complex/Retry.java
+++ /dev/null
@@ -1,29 +0,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.
- */
-
-package org.apache.commons.complex;
-
-import java.lang.annotation.*;
-
-/**
- * Annotation that enables test retries.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface Retry {
- int value() default 2;
-}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/java/org/apache/commons/complex/RetryRunner.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/complex/RetryRunner.java b/src/test/java/org/apache/commons/complex/RetryRunner.java
deleted file mode 100644
index 54a523b..0000000
--- a/src/test/java/org/apache/commons/complex/RetryRunner.java
+++ /dev/null
@@ -1,81 +0,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.
- */
-
-package org.apache.commons.complex;
-
-import org.junit.runners.BlockJUnit4ClassRunner;
-import org.junit.runners.model.FrameworkMethod;
-import org.junit.runners.model.InitializationError;
-import org.junit.runners.model.Statement;
-
-
-/**
- * A test runner that retries tests when assertions fail.
- */
-public class RetryRunner extends BlockJUnit4ClassRunner {
- /**
- * Simple constructor.
- *
- * @param testClass Class to test.
- * @throws InitializationError if default runner cannot be built.
- */
- public RetryRunner(final Class<?> testClass)
- throws InitializationError {
- super(testClass);
- }
-
- @Override
- public Statement methodInvoker(final FrameworkMethod method,
- Object test) {
- final Statement singleTryStatement = super.methodInvoker(method, test);
- return new Statement() {
- /**
- * Evaluate the statement.
- * We attempt several runs for the test, at most MAX_ATTEMPTS.
- * if one attempt succeeds, we succeed, if all attempts fail, we
- * fail with the reason corresponding to the last attempt
- */
- @Override
- public void evaluate() throws Throwable {
- Throwable failureReason = null;
-
- final Retry retry = method.getAnnotation(Retry.class);
- if (retry == null) {
- // Do a single test run attempt.
- singleTryStatement.evaluate();
- } else {
- final int numRetries = retry.value();
-
- for (int i = 0; i < numRetries; ++i) {
- try {
- // Do a single test run attempt.
- singleTryStatement.evaluate();
- // Attempt succeeded, stop evaluation here.
- return;
- } catch (Throwable t) {
- // Attempt failed, store the reason.
- failureReason = t;
- }
- }
-
- // All attempts failed.
- throw failureReason;
- }
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/java/org/apache/commons/complex/RetryRunnerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/complex/RetryRunnerTest.java b/src/test/java/org/apache/commons/complex/RetryRunnerTest.java
deleted file mode 100644
index 87d76ad..0000000
--- a/src/test/java/org/apache/commons/complex/RetryRunnerTest.java
+++ /dev/null
@@ -1,53 +0,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.
- */
-
-package org.apache.commons.complex;
-
-import java.util.Random;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-/**
- * Test for the "Retry" functionality (retrying Junit test methods).
- */
-@RunWith(RetryRunner.class)
-public class RetryRunnerTest {
- final Random rng = new Random();
-
- /**
- * Shows that an always failing test will fail even if it is retried.
- */
- @Test(expected=IllegalStateException.class)
- @Retry
- public void testRetryFailAlways() {
- throw new IllegalStateException();
- }
-
- /**
- * Shows that a test that sometimes fail might succeed if it is retried.
- * In this case the high number of retries makes it quite unlikely that
- * the exception will be thrown by all of the calls.
- */
- @Test
- @Retry(100)
- public void testRetryFailSometimes() {
- if (rng.nextBoolean()) {
- throw new IllegalStateException();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/java/org/apache/commons/complex/RootsOfUnityTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/complex/RootsOfUnityTest.java b/src/test/java/org/apache/commons/complex/RootsOfUnityTest.java
deleted file mode 100644
index 642c87a..0000000
--- a/src/test/java/org/apache/commons/complex/RootsOfUnityTest.java
+++ /dev/null
@@ -1,84 +0,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.
- */
-package org.apache.commons.complex;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-
-/**
- * Unit tests for the {@link RootsOfUnity} class.
- *
- */
-public class RootsOfUnityTest {
- @Test(expected = IllegalArgumentException.class)
- public void testPrecondition() {
- new RootsOfUnity(0);
- }
- @Test(expected = IndexOutOfBoundsException.class)
- public void testGetRootPrecondition1() {
- final int n = 3;
- final RootsOfUnity roots = new RootsOfUnity(n);
- roots.getRoot(-1);
- }
- @Test(expected = IndexOutOfBoundsException.class)
- public void testGetRootPrecondition2() {
- final int n = -2;
- final RootsOfUnity roots = new RootsOfUnity(n);
- roots.getRoot(2);
- }
-
- @Test
- public void testGetNumberOfRoots1() {
- final int n = 5;
- final RootsOfUnity roots = new RootsOfUnity(n);
- Assert.assertEquals(n, roots.getNumberOfRoots());
- Assert.assertTrue(roots.isCounterClockwise());
- }
- @Test
- public void testGetNumberOfRoots2() {
- final int n = -4;
- final RootsOfUnity roots = new RootsOfUnity(n);
- Assert.assertEquals(Math.abs(n), roots.getNumberOfRoots());
- Assert.assertFalse(roots.isCounterClockwise());
- }
-
- @Test
- public void testComputeRoots() {
- final double tol = Math.ulp(1d);
- final org.apache.commons.math3.complex.RootsOfUnity cmRoots =
- new org.apache.commons.math3.complex.RootsOfUnity();
- for (int n = -10; n < 11; n++) {
- final int absN = Math.abs(n);
- if (n != 0) {
- cmRoots.computeRoots(n);
- final RootsOfUnity roots = new RootsOfUnity(n);
- for (int k = 0; k < absN; k++) {
- final Complex z = roots.getRoot(k);
- Assert.assertEquals("n=" + n + " k=" + k,
- cmRoots.getReal(k),
- z.getReal(),
- tol);
- Assert.assertEquals("n=" + n + " k=" + k,
- cmRoots.getImaginary(k),
- z.getImaginary(),
- tol);
- }
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/java/org/apache/commons/complex/TestUtils.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/complex/TestUtils.java b/src/test/java/org/apache/commons/complex/TestUtils.java
deleted file mode 100755
index 63a2e65..0000000
--- a/src/test/java/org/apache/commons/complex/TestUtils.java
+++ /dev/null
@@ -1,408 +0,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.
- */
-
-package org.apache.commons.complex;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
-import org.apache.commons.complex.Complex;
-import org.apache.commons.complex.ComplexFormat;
-
-import org.junit.Assert;
-
-/**
- */
-public class TestUtils {
- /**
- * Collection of static methods used in math unit tests.
- */
- private TestUtils() {
- super();
- }
-
- /**
- * Verifies that expected and actual are within delta, or are both NaN or
- * infinities of the same sign.
- */
- public static void assertEquals(double expected, double actual, double delta) {
- Assert.assertEquals(null, expected, actual, delta);
- }
-
- /**
- * Verifies that expected and actual are within delta, or are both NaN or
- * infinities of the same sign.
- */
- public static void assertEquals(String msg, double expected, double actual, double delta) {
- // check for NaN
- if(Double.isNaN(expected)){
- Assert.assertTrue("" + actual + " is not NaN.",
- Double.isNaN(actual));
- } else {
- Assert.assertEquals(msg, expected, actual, delta);
- }
- }
-
- /**
- * Verifies that the two arguments are exactly the same, either
- * both NaN or infinities of same sign, or identical floating point values.
- */
- public static void assertSame(double expected, double actual) {
- Assert.assertEquals(expected, actual, 0);
- }
-
- /**
- * Verifies that real and imaginary parts of the two complex arguments
- * are exactly the same. Also ensures that NaN / infinite components match.
- */
- public static void assertSame(Complex expected, Complex actual) {
- assertSame(expected.getReal(), actual.getReal());
- assertSame(expected.getImaginary(), actual.getImaginary());
- }
-
- /**
- * Verifies that real and imaginary parts of the two complex arguments
- * differ by at most delta. Also ensures that NaN / infinite components match.
- */
- public static void assertEquals(Complex expected, Complex actual, double delta) {
- Assert.assertEquals(expected.getReal(), actual.getReal(), delta);
- Assert.assertEquals(expected.getImaginary(), actual.getImaginary(), delta);
- }
-
- /**
- * Verifies that two double arrays have equal entries, up to tolerance
- */
- public static void assertEquals(double expected[], double observed[], double tolerance) {
- assertEquals("Array comparison failure", expected, observed, tolerance);
- }
-
- /**
- * Serializes an object to a bytes array and then recovers the object from the bytes array.
- * Returns the deserialized object.
- *
- * @param o object to serialize and recover
- * @return the recovered, deserialized object
- */
- public static Object serializeAndRecover(Object o) {
- try {
- // serialize the Object
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ObjectOutputStream so = new ObjectOutputStream(bos);
- so.writeObject(o);
-
- // deserialize the Object
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- ObjectInputStream si = new ObjectInputStream(bis);
- return si.readObject();
- } catch (IOException ioe) {
- return null;
- } catch (ClassNotFoundException cnfe) {
- return null;
- }
- }
-
- /**
- * Verifies that serialization preserves equals and hashCode.
- * Serializes the object, then recovers it and checks equals and hash code.
- *
- * @param object the object to serialize and recover
- */
- public static void checkSerializedEquality(Object object) {
- Object object2 = serializeAndRecover(object);
- Assert.assertEquals("Equals check", object, object2);
- Assert.assertEquals("HashCode check", object.hashCode(), object2.hashCode());
- }
-
- /**
- * Verifies that the relative error in actual vs. expected is less than or
- * equal to relativeError. If expected is infinite or NaN, actual must be
- * the same (NaN or infinity of the same sign).
- *
- * @param expected expected value
- * @param actual observed value
- * @param relativeError maximum allowable relative error
- */
- public static void assertRelativelyEquals(double expected, double actual,
- double relativeError) {
- assertRelativelyEquals(null, expected, actual, relativeError);
- }
-
- /**
- * Verifies that the relative error in actual vs. expected is less than or
- * equal to relativeError. If expected is infinite or NaN, actual must be
- * the same (NaN or infinity of the same sign).
- *
- * @param msg message to return with failure
- * @param expected expected value
- * @param actual observed value
- * @param relativeError maximum allowable relative error
- */
- public static void assertRelativelyEquals(String msg, double expected,
- double actual, double relativeError) {
- if (Double.isNaN(expected)) {
- Assert.assertTrue(msg, Double.isNaN(actual));
- } else if (Double.isNaN(actual)) {
- Assert.assertTrue(msg, Double.isNaN(expected));
- } else if (Double.isInfinite(actual) || Double.isInfinite(expected)) {
- Assert.assertEquals(expected, actual, relativeError);
- } else if (expected == 0.0) {
- Assert.assertEquals(msg, actual, expected, relativeError);
- } else {
- double absError = Math.abs(expected) * relativeError;
- Assert.assertEquals(msg, expected, actual, absError);
- }
- }
-
- /**
- * Fails iff values does not contain a number within epsilon of z.
- *
- * @param msg message to return with failure
- * @param values complex array to search
- * @param z value sought
- * @param epsilon tolerance
- */
- public static void assertContains(String msg, Complex[] values,
- Complex z, double epsilon) {
- for (Complex value : values) {
- if (Precision.equals(value.getReal(), z.getReal(), epsilon) &&
- Precision.equals(value.getImaginary(), z.getImaginary(), epsilon)) {
- return;
- }
- }
- Assert.fail(msg + " Unable to find " + (new ComplexFormat()).format(z));
- }
-
- /**
- * Fails iff values does not contain a number within epsilon of z.
- *
- * @param values complex array to search
- * @param z value sought
- * @param epsilon tolerance
- */
- public static void assertContains(Complex[] values,
- Complex z, double epsilon) {
- assertContains(null, values, z, epsilon);
- }
-
- /**
- * Fails iff values does not contain a number within epsilon of x.
- *
- * @param msg message to return with failure
- * @param values double array to search
- * @param x value sought
- * @param epsilon tolerance
- */
- public static void assertContains(String msg, double[] values,
- double x, double epsilon) {
- for (double value : values) {
- if (Precision.equals(value, x, epsilon)) {
- return;
- }
- }
- Assert.fail(msg + " Unable to find " + x);
- }
-
- /**
- * Fails iff values does not contain a number within epsilon of x.
- *
- * @param values double array to search
- * @param x value sought
- * @param epsilon tolerance
- */
- public static void assertContains(double[] values, double x,
- double epsilon) {
- assertContains(null, values, x, epsilon);
- }
-
- /** verifies that two arrays are close (sup norm) */
- public static void assertEquals(String msg, double[] expected, double[] observed, double tolerance) {
- StringBuilder out = new StringBuilder(msg);
- if (expected.length != observed.length) {
- out.append("\n Arrays not same length. \n");
- out.append("expected has length ");
- out.append(expected.length);
- out.append(" observed length = ");
- out.append(observed.length);
- Assert.fail(out.toString());
- }
- boolean failure = false;
- for (int i=0; i < expected.length; i++) {
- if (!equalsIncludingNaN(expected[i], observed[i], tolerance)) {
- failure = true;
- out.append("\n Elements at index ");
- out.append(i);
- out.append(" differ. ");
- out.append(" expected = ");
- out.append(expected[i]);
- out.append(" observed = ");
- out.append(observed[i]);
- }
- }
- if (failure) {
- Assert.fail(out.toString());
- }
- }
-
- /** verifies that two arrays are close (sup norm) */
- public static void assertEquals(String msg, float[] expected, float[] observed, float tolerance) {
- StringBuilder out = new StringBuilder(msg);
- if (expected.length != observed.length) {
- out.append("\n Arrays not same length. \n");
- out.append("expected has length ");
- out.append(expected.length);
- out.append(" observed length = ");
- out.append(observed.length);
- Assert.fail(out.toString());
- }
- boolean failure = false;
- for (int i=0; i < expected.length; i++) {
- if (!equalsIncludingNaN(expected[i], observed[i], tolerance)) {
- failure = true;
- out.append("\n Elements at index ");
- out.append(i);
- out.append(" differ. ");
- out.append(" expected = ");
- out.append(expected[i]);
- out.append(" observed = ");
- out.append(observed[i]);
- }
- }
- if (failure) {
- Assert.fail(out.toString());
- }
- }
-
- /** verifies that two arrays are close (sup norm) */
- public static void assertEquals(String msg, Complex[] expected, Complex[] observed, double tolerance) {
- StringBuilder out = new StringBuilder(msg);
- if (expected.length != observed.length) {
- out.append("\n Arrays not same length. \n");
- out.append("expected has length ");
- out.append(expected.length);
- out.append(" observed length = ");
- out.append(observed.length);
- Assert.fail(out.toString());
- }
- boolean failure = false;
- for (int i=0; i < expected.length; i++) {
- if (!equalsIncludingNaN(expected[i].getReal(), observed[i].getReal(), tolerance)) {
- failure = true;
- out.append("\n Real elements at index ");
- out.append(i);
- out.append(" differ. ");
- out.append(" expected = ");
- out.append(expected[i].getReal());
- out.append(" observed = ");
- out.append(observed[i].getReal());
- }
- if (!equalsIncludingNaN(expected[i].getImaginary(), observed[i].getImaginary(), tolerance)) {
- failure = true;
- out.append("\n Imaginary elements at index ");
- out.append(i);
- out.append(" differ. ");
- out.append(" expected = ");
- out.append(expected[i].getImaginary());
- out.append(" observed = ");
- out.append(observed[i].getImaginary());
- }
- }
- if (failure) {
- Assert.fail(out.toString());
- }
- }
-
- /**
- * Updates observed counts of values in quartiles.
- * counts[0] <-> 1st quartile ... counts[3] <-> top quartile
- */
- public static void updateCounts(double value, long[] counts, double[] quartiles) {
- if (value < quartiles[0]) {
- counts[0]++;
- } else if (value > quartiles[2]) {
- counts[3]++;
- } else if (value > quartiles[1]) {
- counts[2]++;
- } else {
- counts[1]++;
- }
- }
-
- /**
- * Eliminates points with zero mass from densityPoints and densityValues parallel
- * arrays. Returns the number of positive mass points and collapses the arrays so
- * that the first <returned value> elements of the input arrays represent the positive
- * mass points.
- */
- public static int eliminateZeroMassPoints(int[] densityPoints, double[] densityValues) {
- int positiveMassCount = 0;
- for (int i = 0; i < densityValues.length; i++) {
- if (densityValues[i] > 0) {
- positiveMassCount++;
- }
- }
- if (positiveMassCount < densityValues.length) {
- int[] newPoints = new int[positiveMassCount];
- double[] newValues = new double[positiveMassCount];
- int j = 0;
- for (int i = 0; i < densityValues.length; i++) {
- if (densityValues[i] > 0) {
- newPoints[j] = densityPoints[i];
- newValues[j] = densityValues[i];
- j++;
- }
- }
- System.arraycopy(newPoints,0,densityPoints,0,positiveMassCount);
- System.arraycopy(newValues,0,densityValues,0,positiveMassCount);
- }
- return positiveMassCount;
- }
-
- /**
- * Returns true if the arguments are both NaN, are equal or are within the range
- * of allowed error (inclusive).
- *
- * @param x first value
- * @param y second value
- * @param eps the amount of absolute error to allow.
- * @return {@code true} if the values are equal or within range of each other,
- * or both are NaN.
- * @since 2.2
- */
- private static boolean equalsIncludingNaN(double x, double y, double eps) {
- return equalsIncludingNaN(x, y) || (Math.abs(y - x) <= eps);
- }
-
- /**
- * Returns true if the arguments are both NaN or they are
- * equal as defined by {@link #equals(double,double) equals(x, y, 1)}.
- *
- * @param x first value
- * @param y second value
- * @return {@code true} if the values are equal or both are NaN.
- * @since 2.2
- */
- private static boolean equalsIncludingNaN(double x, double y) {
- return (x != x || y != y) ? !(x != x ^ y != y) : Precision.equals(x, y, 1);
- }
-
-
-}
-
-
[27/31] commons-numbers git commit: Removed methods that do not
belong in class "Complex".
Posted by er...@apache.org.
Removed methods that do not belong in class "Complex".
Similar methods are defined in class "Precision" (module "commons-numbers-core").
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/b797559e
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/b797559e
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/b797559e
Branch: refs/heads/master
Commit: b797559e4141da1f649f0594c28b06ce6b338bcb
Parents: 539279c
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Fri Jan 20 15:09:22 2017 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Fri Jan 20 15:09:22 2017 +0100
----------------------------------------------------------------------
.../apache/commons/numbers/complex/Complex.java | 41 --------------------
1 file changed, 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/b797559e/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
----------------------------------------------------------------------
diff --git a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
index 1d864e6..b130558 100644
--- a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
+++ b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
@@ -1314,47 +1314,6 @@ public class Complex implements Serializable {
return new Double(x).equals(new Double(y));
}
- /**
- * Returns {@code true} if there is no double value strictly between the
- * arguments or the difference between them is within the range of allowed
- * error (inclusive). Returns {@code false} if either of the arguments
- * is NaN.
- *
- * @param x First value.
- * @param y Second value.
- * @param eps Amount of allowed absolute error.
- * @return {@code true} if the values are two adjacent floating point
- * numbers or they are within range of each other.
- */
- public static boolean equals(double x, double y, double eps) {
- return equals(x, y, 1) || Math.abs(y - x) <= eps;
- }
-
-
- /**
- * Returns {@code true} if there is no double value strictly between the
- * arguments or the relative difference between them is less than or equal
- * to the given tolerance. Returns {@code false} if either of the arguments
- * is NaN.
- *
- * @param x First value.
- * @param y Second value.
- * @param eps Amount of allowed relative error.
- * @return {@code true} if the values are two adjacent floating point
- * numbers or they are within range of each other.
- * @since 3.1
- */
- public static boolean equalsWithRelativeTolerance(double x, double y, double eps) {
- if (equals(x, y, 1)) {
- return true;
- }
-
- final double absoluteMax = Math.max(Math.abs(x), Math.abs(y));
- final double relativeDifference = Math.abs((x - y) / absoluteMax);
-
- return relativeDifference <= eps;
- }
-
/**
* Returns an integer hash code representing the given double value.
*
[07/31] commons-numbers git commit: Cleanup (massive delete).
Posted by er...@apache.org.
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/main/java/org/apache/commons/complex/ComplexFormat.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/complex/ComplexFormat.java b/src/main/java/org/apache/commons/complex/ComplexFormat.java
deleted file mode 100644
index feed97d..0000000
--- a/src/main/java/org/apache/commons/complex/ComplexFormat.java
+++ /dev/null
@@ -1,595 +0,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.
- */
-
-package org.apache.commons.complex;
-
-import java.text.FieldPosition;
-import java.text.NumberFormat;
-import java.text.ParsePosition;
-import java.util.Locale;
-import org.apache.commons.complex.Complex;
-
-/**
- * Formats a Complex number in cartesian format "Re(c) + Im(c)i". 'i' can
- * be replaced with 'j' (or anything else), and the number format for both real
- * and imaginary parts can be configured.
- *
- */
-public class ComplexFormat {
-
- /** The default imaginary character. */
- private static final String DEFAULT_IMAGINARY_CHARACTER = "i";
- /** The notation used to signify the imaginary part of the complex number. */
- private final String imaginaryCharacter;
- /** The format used for the imaginary part. */
- private final NumberFormat imaginaryFormat;
- /** The format used for the real part. */
- private final NumberFormat realFormat;
-
- /**
- * Create an instance with the default imaginary character, 'i', and the
- * default number format for both real and imaginary parts.
- */
- public ComplexFormat() {
- this.imaginaryCharacter = DEFAULT_IMAGINARY_CHARACTER;
- this.imaginaryFormat = getDefaultNumberFormat();
- this.realFormat = imaginaryFormat;
- }
-
- /**
- * Create an instance with a custom number format for both real and
- * imaginary parts.
- * @param format the custom format for both real and imaginary parts.
- * @throws NullArgumentException if {@code realFormat} is {@code null}.
- */
- public ComplexFormat(NumberFormat format) {
- if (format == null) {
- throw new RuntimeException("Null argument to ComplexFormat");
- }
- this.imaginaryCharacter = DEFAULT_IMAGINARY_CHARACTER;
- this.imaginaryFormat = format;
- this.realFormat = format;
- }
-
- /**
- * Create an instance with a custom number format for the real part and a
- * custom number format for the imaginary part.
- * @param realFormat the custom format for the real part.
- * @param imaginaryFormat the custom format for the imaginary part.
- * @throws NullArgumentException if {@code imaginaryFormat} is {@code null}.
- * @throws NullArgumentException if {@code realFormat} is {@code null}.
- */
- public ComplexFormat(NumberFormat realFormat, NumberFormat imaginaryFormat) {
- if (imaginaryFormat == null || realFormat == null) {
- throw new RuntimeException("Null argument to ComplexFormat");
- }
- this.imaginaryCharacter = DEFAULT_IMAGINARY_CHARACTER;
- this.imaginaryFormat = imaginaryFormat;
- this.realFormat = realFormat;
- }
-
- /**
- * Create an instance with a custom imaginary character, and the default
- * number format for both real and imaginary parts.
- * @param imaginaryCharacter The custom imaginary character.
- * @throws NullArgumentException if {@code imaginaryCharacter} is
- * {@code null}.
- * @throws NoDataException if {@code imaginaryCharacter} is an
- * empty string.
- */
- public ComplexFormat(String imaginaryCharacter) {
- this(imaginaryCharacter, getDefaultNumberFormat());
- }
-
- /**
- * Create an instance with a custom imaginary character, and a custom number
- * format for both real and imaginary parts.
- * @param imaginaryCharacter The custom imaginary character.
- * @param format the custom format for both real and imaginary parts.
- * @throws NullArgumentException if {@code imaginaryCharacter} is
- * {@code null}.
- * @throws NoDataException if {@code imaginaryCharacter} is an
- * empty string.
- * @throws NullArgumentException if {@code format} is {@code null}.
- */
- public ComplexFormat(String imaginaryCharacter, NumberFormat format) {
- this(imaginaryCharacter, format, format);
- }
-
- /**
- * Create an instance with a custom imaginary character, a custom number
- * format for the real part, and a custom number format for the imaginary
- * part.
- *
- * @param imaginaryCharacter The custom imaginary character.
- * @param realFormat the custom format for the real part.
- * @param imaginaryFormat the custom format for the imaginary part.
- * @throws NullArgumentException if {@code imaginaryCharacter} is
- * {@code null}.
- * @throws NoDataException if {@code imaginaryCharacter} is an
- * empty string.
- * @throws NullArgumentException if {@code imaginaryFormat} is {@code null}.
- * @throws NullArgumentException if {@code realFormat} is {@code null}.
- */
- public ComplexFormat(String imaginaryCharacter,
- NumberFormat realFormat,
- NumberFormat imaginaryFormat) {
- if (imaginaryCharacter == null) {
- throw new RuntimeException("Null argument to ComplexFormat");
- }
- if (imaginaryCharacter.length() == 0) {
- throw new RuntimeException("Empty argument to ComplexFormat");
- }
- if (imaginaryFormat == null) {
- throw new RuntimeException("Null imaginary argument to ComplexFormat");
- }
- if (realFormat == null) {
- throw new RuntimeException("Null real argument to ComplexFormat");
- }
-
- this.imaginaryCharacter = imaginaryCharacter;
- this.imaginaryFormat = imaginaryFormat;
- this.realFormat = realFormat;
- }
-
- /**
- * Get the set of locales for which complex formats are available.
- * <p>This is the same set as the {@link NumberFormat} set.</p>
- * @return available complex format locales.
- */
- public static Locale[] getAvailableLocales() {
- return NumberFormat.getAvailableLocales();
- }
-
- /**
- * This method calls {@link #format(Object,StringBuffer,FieldPosition)}.
- *
- * @param c Complex object to format.
- * @return A formatted number in the form "Re(c) + Im(c)i".
- */
- public String format(Complex c) {
- return format(c, new StringBuffer(), new FieldPosition(0)).toString();
- }
-
- /**
- * This method calls {@link #format(Object,StringBuffer,FieldPosition)}.
- *
- * @param c Double object to format.
- * @return A formatted number.
- */
- public String format(Double c) {
- return format(new Complex(c, 0), new StringBuffer(), new FieldPosition(0)).toString();
- }
-
- /**
- * Formats a {@link Complex} object to produce a string.
- *
- * @param complex the object to format.
- * @param toAppendTo where the text is to be appended
- * @param pos On input: an alignment field, if desired. On output: the
- * offsets of the alignment field
- * @return the value passed in as toAppendTo.
- */
- public StringBuffer format(Complex complex, StringBuffer toAppendTo,
- FieldPosition pos) {
- pos.setBeginIndex(0);
- pos.setEndIndex(0);
-
- // format real
- double re = complex.getReal();
- formatDouble(re, getRealFormat(), toAppendTo, pos);
-
- // format sign and imaginary
- double im = complex.getImaginary();
- StringBuffer imAppendTo;
- if (im < 0.0) {
- toAppendTo.append(" - ");
- imAppendTo = formatImaginary(-im, new StringBuffer(), pos);
- toAppendTo.append(imAppendTo);
- toAppendTo.append(getImaginaryCharacter());
- } else if (im > 0.0 || Double.isNaN(im)) {
- toAppendTo.append(" + ");
- imAppendTo = formatImaginary(im, new StringBuffer(), pos);
- toAppendTo.append(imAppendTo);
- toAppendTo.append(getImaginaryCharacter());
- }
-
- return toAppendTo;
- }
-
- /**
- * Format the absolute value of the imaginary part.
- *
- * @param absIm Absolute value of the imaginary part of a complex number.
- * @param toAppendTo where the text is to be appended.
- * @param pos On input: an alignment field, if desired. On output: the
- * offsets of the alignment field.
- * @return the value passed in as toAppendTo.
- */
- private StringBuffer formatImaginary(double absIm,
- StringBuffer toAppendTo,
- FieldPosition pos) {
- pos.setBeginIndex(0);
- pos.setEndIndex(0);
-
- formatDouble(absIm, getImaginaryFormat(), toAppendTo, pos);
- if (toAppendTo.toString().equals("1")) {
- // Remove the character "1" if it is the only one.
- toAppendTo.setLength(0);
- }
-
- return toAppendTo;
- }
-
- /**
- * Formats a object to produce a string. {@code obj} must be either a
- * {@link Complex} object or a {@link Number} object. Any other type of
- * object will result in an {@link IllegalArgumentException} being thrown.
- *
- * @param obj the object to format.
- * @param toAppendTo where the text is to be appended
- * @param pos On input: an alignment field, if desired. On output: the
- * offsets of the alignment field
- * @return the value passed in as toAppendTo.
- * @see java.text.Format#format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)
- * @throws MathIllegalArgumentException is {@code obj} is not a valid type.
- */
- public StringBuffer format(Object obj, StringBuffer toAppendTo,
- FieldPosition pos) {
-
- StringBuffer ret = null;
-
- if (obj instanceof Complex) {
- ret = format( (Complex)obj, toAppendTo, pos);
- } else if (obj instanceof Number) {
- ret = format(new Complex(((Number)obj).doubleValue(), 0.0),
- toAppendTo, pos);
- } else {
- throw new RuntimeException("Cannot format instance as complex");
- }
-
- return ret;
- }
-
- /**
- * Access the imaginaryCharacter.
- * @return the imaginaryCharacter.
- */
- public String getImaginaryCharacter() {
- return imaginaryCharacter;
- }
-
- /**
- * Access the imaginaryFormat.
- * @return the imaginaryFormat.
- */
- public NumberFormat getImaginaryFormat() {
- return imaginaryFormat;
- }
-
- /**
- * Returns the default complex format for the current locale.
- * @return the default complex format.
- */
- public static ComplexFormat getInstance() {
- return getInstance(Locale.getDefault());
- }
-
- /**
- * Returns the default complex format for the given locale.
- * @param locale the specific locale used by the format.
- * @return the complex format specific to the given locale.
- */
- public static ComplexFormat getInstance(Locale locale) {
- NumberFormat f = getDefaultNumberFormat(locale);
- return new ComplexFormat(f);
- }
-
- /**
- * Returns the default complex format for the given locale.
- * @param locale the specific locale used by the format.
- * @param imaginaryCharacter Imaginary character.
- * @return the complex format specific to the given locale.
- * @throws NullArgumentException if {@code imaginaryCharacter} is
- * {@code null}.
- * @throws NoDataException if {@code imaginaryCharacter} is an
- * empty string.
- */
- public static ComplexFormat getInstance(String imaginaryCharacter, Locale locale) {
- NumberFormat f = getDefaultNumberFormat(locale);
- return new ComplexFormat(imaginaryCharacter, f);
- }
-
- /**
- * Access the realFormat.
- * @return the realFormat.
- */
- public NumberFormat getRealFormat() {
- return realFormat;
- }
-
- /**
- * Parses a string to produce a {@link Complex} object.
- *
- * @param source the string to parse.
- * @return the parsed {@link Complex} object.
- * @throws MathParseException if the beginning of the specified string
- * cannot be parsed.
- */
- public Complex parse(String source) {
- ParsePosition parsePosition = new ParsePosition(0);
- Complex result = parse(source, parsePosition);
- if (parsePosition.getIndex() == 0) {
- throw new RuntimeException("ComplexFormat parse error at index "+ parsePosition.getErrorIndex());
- }
- return result;
- }
-
- /**
- * Parses a string to produce a {@link Complex} object.
- *
- * @param source the string to parse
- * @param pos input/ouput parsing parameter.
- * @return the parsed {@link Complex} object.
- */
- public Complex parse(String source, ParsePosition pos) {
- int initialIndex = pos.getIndex();
-
- // parse whitespace
- parseAndIgnoreWhitespace(source, pos);
-
- // parse real
- Number re = parseNumber(source, getRealFormat(), pos);
- if (re == null) {
- // invalid real number
- // set index back to initial, error index should already be set
- pos.setIndex(initialIndex);
- return null;
- }
-
- // parse sign
- int startIndex = pos.getIndex();
- char c = parseNextCharacter(source, pos);
- int sign = 0;
- switch (c) {
- case 0 :
- // no sign
- // return real only complex number
- return new Complex(re.doubleValue(), 0.0);
- case '-' :
- sign = -1;
- break;
- case '+' :
- sign = 1;
- break;
- default :
- // invalid sign
- // set index back to initial, error index should be the last
- // character examined.
- pos.setIndex(initialIndex);
- pos.setErrorIndex(startIndex);
- return null;
- }
-
- // parse whitespace
- parseAndIgnoreWhitespace(source, pos);
-
- // parse imaginary
- Number im = parseNumber(source, getRealFormat(), pos);
- if (im == null) {
- // invalid imaginary number
- // set index back to initial, error index should already be set
- pos.setIndex(initialIndex);
- return null;
- }
-
- // parse imaginary character
- if (!parseFixedstring(source, getImaginaryCharacter(), pos)) {
- return null;
- }
-
- return new Complex(re.doubleValue(), im.doubleValue() * sign);
-
- }
-
-
- /**
- * Create a default number format. The default number format is based on
- * {@link NumberFormat#getInstance()} with the only customizing that the
- * maximum number of fraction digits is set to 10.
- * @return the default number format.
- */
- public static NumberFormat getDefaultNumberFormat() {
- return getDefaultNumberFormat(Locale.getDefault());
- }
-
- /**
- * Create a default number format. The default number format is based on
- * {@link NumberFormat#getInstance(java.util.Locale)} with the only
- * customizing that the maximum number of fraction digits is set to 10.
- * @param locale the specific locale used by the format.
- * @return the default number format specific to the given locale.
- */
- public static NumberFormat getDefaultNumberFormat(final Locale locale) {
- final NumberFormat nf = NumberFormat.getInstance(locale);
- nf.setMaximumFractionDigits(10);
- return nf;
- }
-
- /**
- * Parses <code>source</code> until a non-whitespace character is found.
- *
- * @param source the string to parse
- * @param pos input/output parsing parameter. On output, <code>pos</code>
- * holds the index of the next non-whitespace character.
- */
- public static void parseAndIgnoreWhitespace(final String source,
- final ParsePosition pos) {
- parseNextCharacter(source, pos);
- pos.setIndex(pos.getIndex() - 1);
- }
-
- /**
- * Parses <code>source</code> until a non-whitespace character is found.
- *
- * @param source the string to parse
- * @param pos input/output parsing parameter.
- * @return the first non-whitespace character.
- */
- public static char parseNextCharacter(final String source,
- final ParsePosition pos) {
- int index = pos.getIndex();
- final int n = source.length();
- char ret = 0;
-
- if (index < n) {
- char c;
- do {
- c = source.charAt(index++);
- } while (Character.isWhitespace(c) && index < n);
- pos.setIndex(index);
-
- if (index < n) {
- ret = c;
- }
- }
-
- return ret;
- }
-
- /**
- * Parses <code>source</code> for special double values. These values
- * include Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY.
- *
- * @param source the string to parse
- * @param value the special value to parse.
- * @param pos input/output parsing parameter.
- * @return the special number.
- */
- private static Number parseNumber(final String source, final double value,
- final ParsePosition pos) {
- Number ret = null;
-
- StringBuilder sb = new StringBuilder();
- sb.append('(');
- sb.append(value);
- sb.append(')');
-
- final int n = sb.length();
- final int startIndex = pos.getIndex();
- final int endIndex = startIndex + n;
- if (endIndex < source.length() &&
- source.substring(startIndex, endIndex).compareTo(sb.toString()) == 0) {
- ret = Double.valueOf(value);
- pos.setIndex(endIndex);
- }
-
- return ret;
- }
-
- /**
- * Parses <code>source</code> for a number. This method can parse normal,
- * numeric values as well as special values. These special values include
- * Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY.
- *
- * @param source the string to parse
- * @param format the number format used to parse normal, numeric values.
- * @param pos input/output parsing parameter.
- * @return the parsed number.
- */
- public static Number parseNumber(final String source, final NumberFormat format,
- final ParsePosition pos) {
- final int startIndex = pos.getIndex();
- Number number = format.parse(source, pos);
- final int endIndex = pos.getIndex();
-
- // check for error parsing number
- if (startIndex == endIndex) {
- // try parsing special numbers
- final double[] special = {
- Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY
- };
- for (int i = 0; i < special.length; ++i) {
- number = parseNumber(source, special[i], pos);
- if (number != null) {
- break;
- }
- }
- }
-
- return number;
- }
-
- /**
- * Parse <code>source</code> for an expected fixed string.
- * @param source the string to parse
- * @param expected expected string
- * @param pos input/output parsing parameter.
- * @return true if the expected string was there
- */
- public static boolean parseFixedstring(final String source,
- final String expected,
- final ParsePosition pos) {
-
- final int startIndex = pos.getIndex();
- final int endIndex = startIndex + expected.length();
- if ((startIndex >= source.length()) ||
- (endIndex > source.length()) ||
- (source.substring(startIndex, endIndex).compareTo(expected) != 0)) {
- // set index back to start, error index should be the start index
- pos.setIndex(startIndex);
- pos.setErrorIndex(startIndex);
- return false;
- }
-
- // the string was here
- pos.setIndex(endIndex);
- return true;
- }
-
- /**
- * Formats a double value to produce a string. In general, the value is
- * formatted using the formatting rules of <code>format</code>. There are
- * three exceptions to this:
- * <ol>
- * <li>NaN is formatted as '(NaN)'</li>
- * <li>Positive infinity is formatted as '(Infinity)'</li>
- * <li>Negative infinity is formatted as '(-Infinity)'</li>
- * </ol>
- *
- * @param value the double to format.
- * @param format the format used.
- * @param toAppendTo where the text is to be appended
- * @param pos On input: an alignment field, if desired. On output: the
- * offsets of the alignment field
- * @return the value passed in as toAppendTo.
- */
- public static StringBuffer formatDouble(final double value, final NumberFormat format,
- final StringBuffer toAppendTo,
- final FieldPosition pos) {
- if( Double.isNaN(value) || Double.isInfinite(value) ) {
- toAppendTo.append('(');
- toAppendTo.append(value);
- toAppendTo.append(')');
- } else {
- format.format(value, toAppendTo, pos);
- }
- return toAppendTo;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/main/java/org/apache/commons/complex/ComplexUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/complex/ComplexUtils.java b/src/main/java/org/apache/commons/complex/ComplexUtils.java
deleted file mode 100644
index 165d907..0000000
--- a/src/main/java/org/apache/commons/complex/ComplexUtils.java
+++ /dev/null
@@ -1,1430 +0,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.
- */
-
-package org.apache.commons.complex;
-
-/**
- * Static implementations of common {@link Complex} utilities functions.
- */
-public class ComplexUtils {
-
- /**
- * Utility class.
- */
- private ComplexUtils() {}
-
- /**
- * Creates a complex number from the given polar representation.
- * <p>
- * If either {@code r} or {@code theta} is NaN, or {@code theta} is
- * infinite, {@link Complex#NaN} is returned.
- * <p>
- * If {@code r} is infinite and {@code theta} is finite, infinite or NaN
- * values may be returned in parts of the result, following the rules for
- * double arithmetic.
- *
- * <pre>
- * Examples:
- * {@code
- * polar2Complex(INFINITY, \(\pi\)) = INFINITY + INFINITY i
- * polar2Complex(INFINITY, 0) = INFINITY + NaN i
- * polar2Complex(INFINITY, \(-\frac{\pi}{4}\)) = INFINITY - INFINITY i
- * polar2Complex(INFINITY, \(5\frac{\pi}{4}\)) = -INFINITY - INFINITY i }
- * </pre>
- *
- * @param r the modulus of the complex number to create
- * @param theta the argument of the complex number to create
- * @return {@code Complex}
- * @since 1.1
- */
- public static Complex polar2Complex(double r, double theta) {
- if (r < 0) {
- throw new NegativeModulusException(r);
- }
- return new Complex(r * Math.cos(theta), r * Math.sin(theta));
- }
-
- /**
- * Creates {@code Complex[]} array given {@code double[]} arrays of r and
- * theta.
- *
- * @param r {@code double[]} of moduli
- * @param theta {@code double[]} of arguments
- * @return {@code Complex[]}
- * @since 4.0
- */
- public static Complex[] polar2Complex(double[] r, double[] theta) {
- final int length = r.length;
- final Complex[] c = new Complex[length];
- for (int x = 0; x < length; x++) {
- if (r[x] < 0) {
- throw new NegativeModulusException(r[x]);
- }
- c[x] = new Complex(r[x] * Math.cos(theta[x]), r[x] * Math.sin(theta[x]));
- }
- return c;
- }
-
- /**
- * Creates {@code Complex[][]} array given {@code double[][]} arrays of r
- * and theta.
- *
- * @param r {@code double[]} of moduli
- * @param theta {@code double[]} of arguments
- * @return {@code Complex[][]}
- * @since 4.0
- */
- public static Complex[][] polar2Complex(double[][] r, double[][] theta) {
- final int length = r.length;
- final Complex[][] c = new Complex[length][];
- for (int x = 0; x < length; x++) {
- c[x] = polar2Complex(r[x], theta[x]);
- }
- return c;
- }
-
- /**
- * Creates {@code Complex[][][]} array given {@code double[][][]} arrays of
- * r and theta.
- *
- * @param r array of moduli
- * @param theta array of arguments
- * @return {@code Complex}
- * @since 4.0
- */
- public static Complex[][][] polar2Complex(double[][][] r, double[][][] theta) {
- final int length = r.length;
- final Complex[][][] c = new Complex[length][][];
- for (int x = 0; x < length; x++) {
- c[x] = polar2Complex(r[x], theta[x]);
- }
- return c;
- }
-
- /**
- * Returns double from array {@code real[]} at entry {@code index} as a
- * {@code Complex}.
- *
- * @param real array of real numbers
- * @param index location in the array
- * @return {@code Complex}.
- *
- * @since 4.0
- */
- public static Complex extractComplexFromRealArray(double[] real, int index) {
- return new Complex(real[index]);
- }
-
- /**
- * Returns float from array {@code real[]} at entry {@code index} as a
- * {@code Complex}.
- *
- * @param real array of real numbers
- * @param index location in the array
- * @return {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex extractComplexFromRealArray(float[] real, int index) {
- return new Complex(real[index]);
- }
-
- /**
- * Returns double from array {@code imaginary[]} at entry {@code index} as a
- * {@code Complex}.
- *
- * @param imaginary array of imaginary numbers
- * @param index location in the array
- * @return {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex extractComplexFromImaginaryArray(double[] imaginary, int index) {
- return new Complex(0, imaginary[index]);
- }
-
- /**
- * Returns float from array {@code imaginary[]} at entry {@code index} as a
- * {@code Complex}.
- *
- * @param imaginary array of imaginary numbers
- * @param index location in the array
- * @return {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex extractComplexFromImaginaryArray(float[] imaginary, int index) {
- return new Complex(0, imaginary[index]);
- }
-
- /**
- * Returns real component of Complex from array {@code Complex[]} at entry
- * {@code index} as a {@code double}.
- *
- * @param complex array of complex numbers
- * @param index location in the array
- * @return {@code double}.
- *
- * @since 4.0
- */
- public static double extractRealFromComplexArray(Complex[] complex, int index) {
- return complex[index].getReal();
- }
-
- /**
- * Returns real component of array {@code Complex[]} at entry {@code index}
- * as a {@code float}.
- *
- * @param complex array of complex numbers
- * @param index location in the array
- * @return {@code float}.
- *
- * @since 4.0
- */
- public static float extractRealFloatFromComplexArray(Complex[] complex, int index) {
- return (float) complex[index].getReal();
- }
-
- /**
- * Returns imaginary component of Complex from array {@code Complex[]} at
- * entry {@code index} as a {@code double}.
- *
- * @param complex array of complex numbers
- * @param index location in the array
- * @return {@code double}.
- *
- * @since 4.0
- */
- public static double extractImaginaryFromComplexArray(Complex[] complex, int index) {
- return complex[index].getImaginary();
- }
-
- /**
- * Returns imaginary component of array {@code Complex[]} at entry
- * {@code index} as a {@code float}.
- *
- * @param complex array of complex numbers
- * @param index location in the array
- * @return {@code float}.
- *
- * @since 4.0
- */
- public static float extractImaginaryFloatFromComplexArray(Complex[] complex, int index) {
- return (float) complex[index].getImaginary();
- }
-
- /**
- * Returns a Complex object from interleaved {@code double[]} array at entry
- * {@code index}.
- *
- * @param d array of interleaved complex numbers alternating real and imaginary values
- * @param index location in the array This is the location by complex number, e.g. index number 5 in the array will return {@code new Complex(d[10], d[11])}
- * @return {@code Complex}.
- *
- * @since 4.0
- */
- public static Complex extractComplexFromInterleavedArray(double[] d, int index) {
- return new Complex(d[index * 2], d[index * 2 + 1]);
- }
-
- /**
- * Returns a Complex object from interleaved {@code float[]} array at entry
- * {@code index}.
- *
- * @param f float array of interleaved complex numbers alternating real and imaginary values
- * @param index location in the array This is the location by complex number, e.g. index number 5 in the {@code float[]} array will return new {@code Complex(d[10], d[11])}
- * @return {@code Complex}.
- *
- * @since 4.0
- */
- public static Complex extractComplexFromInterleavedArray(float[] f, int index) {
- return new Complex(f[index * 2], f[index * 2 + 1]);
- }
-
- /**
- * Returns values of Complex object from array {@code Complex[]} at entry
- * {@code index} as a size 2 {@code double} of the form {real, imag}.
- *
- * @param complex array of complex numbers
- * @param index location in the array
- * @return size 2 array.
- *
- * @since 4.0
- */
- public static double[] extractInterleavedFromComplexArray(Complex[] complex, int index) {
- return new double[] { complex[index].getReal(), complex[index].getImaginary() };
- }
-
- /**
- * Returns Complex object from array {@code Complex[]} at entry
- * {@code index} as a size 2 {@code float} of the form {real, imag}.
- *
- * @param complex {@code Complex} array
- * @param index location in the array
- * @return size 2 {@code float[]}.
- *
- * @since 4.0
- */
- public static float[] extractInterleavedFloatFromComplexArray(Complex[] complex, int index) {
- return new float[] { (float) complex[index].getReal(), (float) complex[index].getImaginary() };
- }
-
- /**
- * Converts a {@code double[]} array to a {@code Complex[]} array.
- *
- * @param real array of numbers to be converted to their {@code Complex} equivalent
- * @return {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex[] real2Complex(double[] real) {
- int index = 0;
- final Complex c[] = new Complex[real.length];
- for (double d : real) {
- c[index] = new Complex(d);
- index++;
- }
- return c;
- }
-
- /**
- * Converts a {@code float[]} array to a {@code Complex[]} array.
- *
- * @param real array of numbers to be converted to their {@code Complex} equivalent
- * @return {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex[] real2Complex(float[] real) {
- int index = 0;
- final Complex c[] = new Complex[real.length];
- for (float d : real) {
- c[index] = new Complex(d);
- index++;
- }
- return c;
- }
-
- /**
- * Converts a 2D real {@code double[][]} array to a 2D {@code Complex[][]}
- * array.
- *
- * @param d 2D array
- * @return 2D {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex[][] real2Complex(double[][] d) {
- final int width = d.length;
- final Complex[][] c = new Complex[width][];
- for (int n = 0; n < width; n++) {
- c[n] = ComplexUtils.real2Complex(d[n]);
- }
- return c;
- }
-
- /**
- * Converts a 3D real {@code double[][][]} array to a {@code Complex [][][]}
- * array.
- *
- * @param d 3D complex interleaved array
- * @return 3D {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex[][][] real2Complex(double[][][] d) {
- final int width = d.length;
- final Complex[][][] c = new Complex[width][][];
- for (int x = 0; x < width; x++) {
- c[x] = ComplexUtils.real2Complex(d[x]);
- }
- return c;
- }
-
- /**
- * Converts real component of {@code Complex[]} array to a {@code double[]}
- * array.
- *
- * @param c {@code Complex} array
- * @return array of the real component
- *
- * @since 4.0
- */
- public static double[] complex2Real(Complex[] c) {
- int index = 0;
- final double d[] = new double[c.length];
- for (Complex cc : c) {
- d[index] = cc.getReal();
- index++;
- }
- return d;
- }
-
- /**
- * Converts real component of {@code Complex[]} array to a {@code float[]}
- * array.
- *
- * @param c {@code Complex} array
- * @return {@code float[]} array of the real component
- *
- * @since 4.0
- */
- public static float[] complex2RealFloat(Complex[] c) {
- int index = 0;
- final float f[] = new float[c.length];
- for (Complex cc : c) {
- f[index] = (float) cc.getReal();
- index++;
- }
- return f;
- }
-
- /**
- * Converts real component of a 2D {@code Complex[][]} array to a 2D
- * {@code double[][]} array.
- *
- * @param c 2D {@code Complex} array
- * @return {@code double[][]} of real component
- * @since 4.0
- */
- public static double[][] complex2Real(Complex[][] c) {
- final int length = c.length;
- double[][] d = new double[length][];
- for (int n = 0; n < length; n++) {
- d[n] = complex2Real(c[n]);
- }
- return d;
- }
-
- /**
- * Converts real component of a 2D {@code Complex[][]} array to a 2D
- * {@code float[][]} array.
- *
- * @param c 2D {@code Complex} array
- * @return {@code float[][]} of real component
- * @since 4.0
- */
- public static float[][] complex2RealFloat(Complex[][] c) {
- final int length = c.length;
- float[][] f = new float[length][];
- for (int n = 0; n < length; n++) {
- f[n] = complex2RealFloat(c[n]);
- }
- return f;
- }
-
- /**
- * Converts real component of a 3D {@code Complex[][][]} array to a 3D
- * {@code double[][][]} array.
- *
- * @param c 3D complex interleaved array
- * @return array of real component
- *
- * @since 4.0
- */
- public static double[][][] complex2Real(Complex[][][] c) {
- final int length = c.length;
- double[][][] d = new double[length][][];
- for (int n = 0; n < length; n++) {
- d[n] = complex2Real(c[n]);
- }
- return d;
- }
-
- /**
- * Converts real component of a 3D {@code Complex[][][]} array to a 3D
- * {@code float[][][]} array.
- *
- * @param c 3D {@code Complex} array
- * @return {@code float[][][]} of real component
- * @since 4.0
- */
- public static float[][][] complex2RealFloat(Complex[][][] c) {
- final int length = c.length;
- float[][][] f = new float[length][][];
- for (int n = 0; n < length; n++) {
- f[n] = complex2RealFloat(c[n]);
- }
- return f;
- }
-
- /**
- * Converts a {@code double[]} array to an imaginary {@code Complex[]}
- * array.
- *
- * @param imaginary array of numbers to be converted to their {@code Complex} equivalent
- * @return {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex[] imaginary2Complex(double[] imaginary) {
- int index = 0;
- final Complex c[] = new Complex[imaginary.length];
- for (double d : imaginary) {
- c[index] = new Complex(0, d);
- index++;
- }
- return c;
- }
-
- /**
- * Converts a {@code float[]} array to an imaginary {@code Complex[]} array.
- *
- * @param imaginary array of numbers to be converted to their {@code Complex} equivalent
- * @return {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex[] imaginary2Complex(float[] imaginary) {
- int index = 0;
- final Complex c[] = new Complex[imaginary.length];
- for (float d : imaginary) {
- c[index] = new Complex(0, d);
- index++;
- }
- return c;
- }
-
- /**
- * Converts a 2D imaginary array {@code double[][]} to a 2D
- * {@code Complex[][]} array.
- *
- * @param d 2D array
- * @return 2D {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex[][] imaginary2Complex(double[][] d) {
- int width = d.length;
- int height = d[0].length;
- Complex[][] c = new Complex[width][height];
- for (int n = 0; n < width; n++) {
- c[n] = ComplexUtils.imaginary2Complex(d[n]);
- }
- return c;
- }
-
- /**
- * Converts a 3D imaginary array {@code double[][][]} to a {@code Complex[]}
- * array.
- *
- * @param d 3D complex imaginary array
- * @return 3D {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex[][][] imaginary2Complex(double[][][] d) {
- int width = d.length;
- int height = d[0].length;
- int depth = d[0].length;
- Complex[][][] c = new Complex[width][height][depth];
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height; y++) {
- c[x][y] = ComplexUtils.imaginary2Complex(d[x][y]);
- }
- }
- return c;
- }
-
- /**
- * Converts imaginary part of a {@code Complex[]} array to a
- * {@code double[]} array.
- *
- * @param c {@code Complex} array.
- * @return array of the imaginary component
- *
- * @since 4.0
- */
- public static double[] complex2Imaginary(Complex[] c) {
- int index = 0;
- final double d[] = new double[c.length];
- for (Complex cc : c) {
- d[index] = cc.getImaginary();
- index++;
- }
- return d;
- }
-
- /**
- * Converts imaginary component of a {@code Complex[]} array to a
- * {@code float[]} array.
- *
- * @param c {@code Complex} array.
- * @return {@code float[]} array of the imaginary component
- *
- * @since 4.0
- */
- public static float[] complex2ImaginaryFloat(Complex[] c) {
- int index = 0;
- final float f[] = new float[c.length];
- for (Complex cc : c) {
- f[index] = (float) cc.getImaginary();
- index++;
- }
- return f;
- }
-
- /**
- * Converts imaginary component of a 2D {@code Complex[][]} array to a 2D
- * {@code double[][]} array.
- *
- * @param c 2D {@code Complex} array
- * @return {@code double[][]} of imaginary component
- * @since 4.0
- */
- public static double[][] complex2Imaginary(Complex[][] c) {
- final int length = c.length;
- double[][] d = new double[length][];
- for (int n = 0; n < length; n++) {
- d[n] = complex2Imaginary(c[n]);
- }
- return d;
- }
-
- /**
- * Converts imaginary component of a 2D {@code Complex[][]} array to a 2D
- * {@code float[][]} array.
- *
- * @param c 2D {@code Complex} array
- * @return {@code float[][]} of imaginary component
- * @since 4.0
- */
- public static float[][] complex2ImaginaryFloat(Complex[][] c) {
- final int length = c.length;
- float[][] f = new float[length][];
- for (int n = 0; n < length; n++) {
- f[n] = complex2ImaginaryFloat(c[n]);
- }
- return f;
- }
-
- /**
- * Converts imaginary component of a 3D {@code Complex[][][]} array to a 3D
- * {@code double[][][]} array.
- *
- * @param c 3D complex interleaved array
- * @return 3D {@code Complex} array
- *
- * @since 4.0
- */
- public static double[][][] complex2Imaginary(Complex[][][] c) {
- final int length = c.length;
- double[][][] d = new double[length][][];
- for (int n = 0; n < length; n++) {
- d[n] = complex2Imaginary(c[n]);
- }
- return d;
- }
-
- /**
- * Converts imaginary component of a 3D {@code Complex[][][]} array to a 3D
- * {@code float[][][]} array.
- *
- * @param c 3D {@code Complex} array
- * @return {@code float[][][]} of imaginary component
- * @since 4.0
- */
- public static float[][][] complex2ImaginaryFloat(Complex[][][] c) {
- final int length = c.length;
- float[][][] f = new float[length][][];
- for (int n = 0; n < length; n++) {
- f[n] = complex2ImaginaryFloat(c[n]);
- }
- return f;
- }
-
- // INTERLEAVED METHODS
-
- /**
- * Converts a complex interleaved {@code double[]} array to a
- * {@code Complex[]} array
- *
- * @param interleaved array of numbers to be converted to their {@code Complex} equivalent
- * @return {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex[] interleaved2Complex(double[] interleaved) {
- final int length = interleaved.length / 2;
- final Complex c[] = new Complex[length];
- for (int n = 0; n < length; n++) {
- c[n] = new Complex(interleaved[n * 2], interleaved[n * 2 + 1]);
- }
- return c;
- }
-
- /**
- * Converts a complex interleaved {@code float[]} array to a
- * {@code Complex[]} array
- *
- * @param interleaved float[] array of numbers to be converted to their {@code Complex} equivalent
- * @return {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex[] interleaved2Complex(float[] interleaved) {
- final int length = interleaved.length / 2;
- final Complex c[] = new Complex[length];
- for (int n = 0; n < length; n++) {
- c[n] = new Complex(interleaved[n * 2], interleaved[n * 2 + 1]);
- }
- return c;
- }
-
- /**
- * Converts a {@code Complex[]} array to an interleaved complex
- * {@code double[]} array
- *
- * @param c Complex array
- * @return complex interleaved array alternating real and
- * imaginary values
- *
- * @since 4.0
- */
- public static double[] complex2Interleaved(Complex[] c) {
- int index = 0;
- final double d[] = new double[c.length * 2];
- for (Complex cc : c) {
- int real = index * 2;
- int imag = index * 2 + 1;
- d[real] = cc.getReal();
- d[imag] = cc.getImaginary();
- index++;
- }
- return d;
- }
-
- /**
- * Converts a {@code Complex[]} array to an interleaved complex
- * {@code float[]} array
- *
- * @param c Complex array
- * @return complex interleaved {@code float[]} alternating real and
- * imaginary values
- *
- * @since 4.0
- */
- public static float[] complex2InterleavedFloat(Complex[] c) {
- int index = 0;
- final float f[] = new float[c.length * 2];
- for (Complex cc : c) {
- int real = index * 2;
- int imag = index * 2 + 1;
- f[real] = (float) cc.getReal();
- f[imag] = (float) cc.getImaginary();
- index++;
- }
- return f;
- }
-
- /**
- * Converts a 2D {@code Complex[][]} array to an interleaved complex
- * {@code double[][]} array.
- *
- * @param c 2D Complex array
- * @param interleavedDim Depth level of the array to interleave
- * @return complex interleaved array alternating real and
- * imaginary values
- *
- * @since 4.0
- */
- public static double[][] complex2Interleaved(Complex[][] c, int interleavedDim) {
- if (interleavedDim > 1 || interleavedDim < 0) {
- new IndexOutOfRangeException(interleavedDim);
- }
- final int width = c.length;
- final int height = c[0].length;
- double[][] d;
- if (interleavedDim == 0) {
- d = new double[2 * width][height];
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height; y++) {
- d[x * 2][y] = c[x][y].getReal();
- d[x * 2 + 1][y] = c[x][y].getImaginary();
- }
- }
- } else {
- d = new double[width][2 * height];
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height; y++) {
- d[x][y * 2] = c[x][y].getReal();
- d[x][y * 2 + 1] = c[x][y].getImaginary();
- }
- }
- }
- return d;
- }
-
- /**
- * Converts a 2D {@code Complex[][]} array to an interleaved complex
- * {@code double[][]} array. The second depth level of the array is assumed
- * to be interleaved.
- *
- * @param c 2D Complex array
- * @return complex interleaved array alternating real and
- * imaginary values
- *
- * @since 4.0
- */
- public static double[][] complex2Interleaved(Complex[][] c) {
- return complex2Interleaved(c, 1);
- }
-
- /**
- * Converts a 3D {@code Complex[][][]} array to an interleaved complex
- * {@code double[][][]} array.
- *
- * @param c 3D Complex array
- * @param interleavedDim Depth level of the array to interleave
- * @return complex interleaved array alternating real and
- * imaginary values
- *
- * @since 4.0
- */
- public static double[][][] complex2Interleaved(Complex[][][] c, int interleavedDim) {
- if (interleavedDim > 2 || interleavedDim < 0) {
- new IndexOutOfRangeException(interleavedDim);
- }
- int width = c.length;
- int height = c[0].length;
- int depth = c[0][0].length;
- double[][][] d;
- if (interleavedDim == 0) {
- d = new double[2 * width][height][depth];
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height; y++) {
- for (int z = 0; z < depth; z++) {
- d[x * 2][y][z] = c[x][y][z].getReal();
- d[x * 2 + 1][y][z] = c[x][y][z].getImaginary();
- }
- }
- }
- } else if (interleavedDim == 1) {
- d = new double[width][2 * height][depth];
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height; y++) {
- for (int z = 0; z < depth; z++) {
- d[x][y * 2][z] = c[x][y][z].getReal();
- d[x][y * 2 + 1][z] = c[x][y][z].getImaginary();
- }
- }
- }
- } else {
- d = new double[width][height][2 * depth];
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height; y++) {
- for (int z = 0; z < depth; z++) {
- d[x][y][z * 2] = c[x][y][z].getReal();
- d[x][y][z * 2 + 1] = c[x][y][z].getImaginary();
- }
- }
- }
- }
- return d;
- }
-
- /**
- * Converts a 3D {@code Complex[][][]} array to an interleaved complex
- * {@code double[][][]} array. The third depth level of the array is
- * interleaved.
- *
- * @param c 3D Complex array
- * @return complex interleaved array alternating real and
- * imaginary values
- *
- * @since 4.0
- */
- public static double[][][] complex2Interleaved(Complex[][][] c) {
- return complex2Interleaved(c, 2);
- }
-
- /**
- * Converts a 2D {@code Complex[][]} array to an interleaved complex
- * {@code float[][]} array.
- *
- * @param c 2D Complex array
- * @param interleavedDim Depth level of the array to interleave
- * @return complex interleaved {@code float[][]} alternating real and
- * imaginary values
- *
- * @since 4.0
- */
- public static float[][] complex2InterleavedFloat(Complex[][] c, int interleavedDim) {
- if (interleavedDim > 1 || interleavedDim < 0) {
- new IndexOutOfRangeException(interleavedDim);
- }
- final int width = c.length;
- final int height = c[0].length;
- float[][] d;
- if (interleavedDim == 0) {
- d = new float[2 * width][height];
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height; y++) {
- d[x * 2][y] = (float) c[x][y].getReal();
- d[x * 2 + 1][y] = (float) c[x][y].getImaginary();
- }
- }
- } else {
- d = new float[width][2 * height];
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height; y++) {
- d[x][y * 2] = (float) c[x][y].getReal();
- d[x][y * 2 + 1] = (float) c[x][y].getImaginary();
- }
- }
- }
- return d;
- }
-
- /**
- * Converts a 2D {@code Complex[][]} array to an interleaved complex
- * {@code float[][]} array. The second depth level of the array is assumed
- * to be interleaved.
- *
- * @param c 2D Complex array
- *
- * @return complex interleaved {@code float[][]} alternating real and
- * imaginary values
- *
- * @since 4.0
- */
- public static float[][] complex2InterleavedFloat(Complex[][] c) {
- return complex2InterleavedFloat(c, 1);
- }
-
- /**
- * Converts a 3D {@code Complex[][][]} array to an interleaved complex
- * {@code float[][][]} array.
- *
- * @param c 3D Complex array
- * @param interleavedDim Depth level of the array to interleave
- * @return complex interleaved {@code float[][][]} alternating real and
- * imaginary values
- *
- * @since 4.0
- */
- public static float[][][] complex2InterleavedFloat(Complex[][][] c, int interleavedDim) {
- if (interleavedDim > 2 || interleavedDim < 0) {
- new IndexOutOfRangeException(interleavedDim);
- }
- final int width = c.length;
- final int height = c[0].length;
- final int depth = c[0][0].length;
- float[][][] d;
- if (interleavedDim == 0) {
- d = new float[2 * width][height][depth];
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height; y++) {
- for (int z = 0; z < depth; z++) {
- d[x * 2][y][z] = (float) c[x][y][z].getReal();
- d[x * 2 + 1][y][z] = (float) c[x][y][z].getImaginary();
- }
- }
- }
- } else if (interleavedDim == 1) {
- d = new float[width][2 * height][depth];
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height; y++) {
- for (int z = 0; z < depth; z++) {
- d[x][y * 2][z] = (float) c[x][y][z].getReal();
- d[x][y * 2 + 1][z] = (float) c[x][y][z].getImaginary();
- }
- }
- }
- } else {
- d = new float[width][height][2 * depth];
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height; y++) {
- for (int z = 0; z < depth; z++) {
- d[x][y][z * 2] = (float) c[x][y][z].getReal();
- d[x][y][z * 2 + 1] = (float) c[x][y][z].getImaginary();
- }
- }
- }
- }
- return d;
- }
-
- /**
- * Converts a 3D {@code Complex[][][]} array to an interleaved complex
- * {@code float[][][]} array. The third depth level of the array is
- * interleaved.
- *
- * @param c 2D Complex array
- *
- * @return complex interleaved {@code float[][][]} alternating real and
- * imaginary values
- *
- * @since 4.0
- */
- public static float[][][] complex2InterleavedFloat(Complex[][][] c) {
- return complex2InterleavedFloat(c, 2);
- }
-
- /**
- * Converts a 2D interleaved complex {@code double[][]} array to a
- * {@code Complex[][]} array.
- *
- * @param d 2D complex interleaved array
- * @param interleavedDim Depth level of the array to interleave
- * @return 2D {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex[][] interleaved2Complex(double[][] d, int interleavedDim) {
- if (interleavedDim > 1 || interleavedDim < 0) {
- new IndexOutOfRangeException(interleavedDim);
- }
- final int width = d.length;
- final int height = d[0].length;
- Complex[][] c;
- if (interleavedDim == 0) {
- c = new Complex[width / 2][height];
- for (int x = 0; x < width / 2; x++) {
- for (int y = 0; y < height; y++) {
- c[x][y] = new Complex(d[x * 2][y], d[x * 2 + 1][y]);
- }
- }
- } else {
- c = new Complex[width][height / 2];
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height / 2; y++) {
- c[x][y] = new Complex(d[x][y * 2], d[x][y * 2 + 1]);
- }
- }
- }
- return c;
- }
-
- /**
- * Converts a 2D interleaved complex {@code double[][]} array to a
- * {@code Complex[][]} array. The second depth level of the array is assumed
- * to be interleaved.
- *
- * @param d 2D complex interleaved array
- * @return 2D {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex[][] interleaved2Complex(double[][] d) {
- return interleaved2Complex(d, 1);
- }
-
- /**
- * Converts a 3D interleaved complex {@code double[][][]} array to a
- * {@code Complex[][][]} array.
- *
- * @param d 3D complex interleaved array
- * @param interleavedDim Depth level of the array to interleave
- * @return 3D {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex[][][] interleaved2Complex(double[][][] d, int interleavedDim) {
- if (interleavedDim > 2 || interleavedDim < 0) {
- new IndexOutOfRangeException(interleavedDim);
- }
- final int width = d.length;
- final int height = d[0].length;
- final int depth = d[0][0].length;
- Complex[][][] c;
- if (interleavedDim == 0) {
- c = new Complex[width / 2][height][depth];
- for (int x = 0; x < width / 2; x++) {
- for (int y = 0; y < height; y++) {
- for (int z = 0; z < depth; z++) {
- c[x][y][z] = new Complex(d[x * 2][y][z], d[x * 2 + 1][y][z]);
- }
- }
- }
- } else if (interleavedDim == 1) {
- c = new Complex[width][height / 2][depth];
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height / 2; y++) {
- for (int z = 0; z < depth; z++) {
- c[x][y][z] = new Complex(d[x][y * 2][z], d[x][y * 2 + 1][z]);
- }
- }
- }
- } else {
- c = new Complex[width][height][depth / 2];
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height; y++) {
- for (int z = 0; z < depth / 2; z++) {
- c[x][y][z] = new Complex(d[x][y][z * 2], d[x][y][z * 2 + 1]);
- }
- }
- }
- }
- return c;
- }
-
- /**
- * Converts a 3D interleaved complex {@code double[][][]} array to a
- * {@code Complex[][][]} array. The third depth level is assumed to be
- * interleaved.
- *
- * @param d 3D complex interleaved array
- * @return 3D {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex[][][] interleaved2Complex(double[][][] d) {
- return interleaved2Complex(d, 2);
- }
-
- /**
- * Converts a 2D interleaved complex {@code float[][]} array to a
- * {@code Complex[][]} array.
- *
- * @param d 2D complex interleaved float array
- * @param interleavedDim Depth level of the array to interleave
- * @return 2D {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex[][] interleaved2Complex(float[][] d, int interleavedDim) {
- if (interleavedDim > 1 || interleavedDim < 0) {
- new IndexOutOfRangeException(interleavedDim);
- }
- final int width = d.length;
- final int height = d[0].length;
- Complex[][] c;
- if (interleavedDim == 0) {
- c = new Complex[width / 2][height];
- for (int x = 0; x < width / 2; x++) {
- for (int y = 0; y < height; y++) {
- c[x][y] = new Complex(d[x * 2][y], d[x * 2 + 1][y]);
- }
- }
- } else {
- c = new Complex[width][height / 2];
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height / 2; y++) {
- c[x][y] = new Complex(d[x][y * 2], d[x][y * 2 + 1]);
- }
- }
- }
- return c;
- }
-
- /**
- * Converts a 2D interleaved complex {@code float[][]} array to a
- * {@code Complex[][]} array. The second depth level of the array is assumed
- * to be interleaved.
- *
- * @param d 2D complex interleaved float array
- * @return 2D {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex[][] interleaved2Complex(float[][] d) {
- return interleaved2Complex(d, 1);
- }
-
- /**
- * Converts a 3D interleaved complex {@code float[][][]} array to a
- * {@code Complex[][][]} array.
- *
- * @param d 3D complex interleaved float array
- * @param interleavedDim Depth level of the array to interleave
- * @return 3D {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex[][][] interleaved2Complex(float[][][] d, int interleavedDim) {
- if (interleavedDim > 2 || interleavedDim < 0) {
- new IndexOutOfRangeException(interleavedDim);
- }
- final int width = d.length;
- final int height = d[0].length;
- final int depth = d[0][0].length;
- Complex[][][] c;
- if (interleavedDim == 0) {
- c = new Complex[width / 2][height][depth];
- for (int x = 0; x < width/2; x ++) {
- for (int y = 0; y < height; y++) {
- for (int z = 0; z < depth; z++) {
- c[x][y][z] = new Complex(d[x * 2][y][z], d[x * 2 + 1][y][z]);
- }
- }
- }
- } else if (interleavedDim == 1) {
- c = new Complex[width][height / 2][depth];
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height/2; y ++) {
- for (int z = 0; z < depth; z++) {
- c[x][y][z] = new Complex(d[x][y * 2][z], d[x][y * 2 + 1][z]);
- }
- }
- }
- } else {
- c = new Complex[width][height][depth / 2];
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height; y++) {
- for (int z = 0; z < depth/2; z++) {
- c[x][y][z] = new Complex(d[x][y][z * 2], d[x][y][z * 2 + 1]);
- }
- }
- }
- }
- return c;
- }
-
- /**
- * Converts a 3D interleaved complex {@code float[][][]} array to a
- * {@code Complex[]} array. The third depth level of the array is assumed to
- * be interleaved.
- *
- * @param d 3D complex interleaved float array
- * @return 3D {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex[][][] interleaved2Complex(float[][][] d) {
- return interleaved2Complex(d, 2);
- }
-
- // SPLIT METHODS
-
- /**
- * Converts a split complex array {@code double[] r, double[] i} to a
- * {@code Complex[]} array.
- *
- * @param real real component
- * @param imag imaginary component
- * @return {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex[] split2Complex(double[] real, double[] imag) {
- final int length = real.length;
- final Complex[] c = new Complex[length];
- for (int n = 0; n < length; n++) {
- c[n] = new Complex(real[n], imag[n]);
- }
- return c;
- }
-
- /**
- * Converts a 2D split complex array {@code double[][] r, double[][] i} to a
- * 2D {@code Complex[][]} array.
- *
- * @param real real component
- * @param imag imaginary component
- * @return 2D {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex[][] split2Complex(double[][] real, double[][] imag) {
- final int length = real.length;
- Complex[][] c = new Complex[length][];
- for (int x = 0; x < length; x++) {
- c[x] = split2Complex(real[x], imag[x]);
- }
- return c;
- }
-
- /**
- * Converts a 3D split complex array {@code double[][][] r, double[][][] i}
- * to a 3D {@code Complex[][][]} array.
- *
- * @param real real component
- * @param imag imaginary component
- * @return 3D {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex[][][] split2Complex(double[][][] real, double[][][] imag) {
- final int length = real.length;
- Complex[][][] c = new Complex[length][][];
- for (int x = 0; x < length; x++) {
- c[x] = split2Complex(real[x], imag[x]);
- }
- return c;
- }
-
- /**
- * Converts a split complex array {@code float[] r, float[] i} to a
- * {@code Complex[]} array.
- *
- * @param real real component
- * @param imag imaginary component
- * @return {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex[] split2Complex(float[] real, float[] imag) {
- final int length = real.length;
- final Complex[] c = new Complex[length];
- for (int n = 0; n < length; n++) {
- c[n] = new Complex(real[n], imag[n]);
- }
- return c;
- }
-
- /**
- * Converts a 2D split complex array {@code float[][] r, float[][] i} to a
- * 2D {@code Complex[][]} array.
- *
- * @param real real component
- * @param imag imaginary component
- * @return 2D {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex[][] split2Complex(float[][] real, float[][] imag) {
- final int length = real.length;
- Complex[][] c = new Complex[length][];
- for (int x = 0; x < length; x++) {
- c[x] = split2Complex(real[x], imag[x]);
- }
- return c;
- }
-
- /**
- * Converts a 3D split complex array {@code float[][][] r, float[][][] i} to
- * a 3D {@code Complex[][][]} array.
- *
- * @param real real component
- * @param imag imaginary component
- * @return 3D {@code Complex} array
- *
- * @since 4.0
- */
- public static Complex[][][] split2Complex(float[][][] real, float[][][] imag) {
- final int length = real.length;
- Complex[][][] c = new Complex[length][][];
- for (int x = 0; x < length; x++) {
- c[x] = split2Complex(real[x], imag[x]);
- }
- return c;
- }
-
- // MISC
-
- /**
- * Initializes a {@code Complex[]} array to zero, to avoid
- * NullPointerExceptions.
- *
- * @param c Complex array
- * @return c
- *
- * @since 4.0
- */
- public static Complex[] initialize(Complex[] c) {
- final int length = c.length;
- for (int x = 0; x < length; x++) {
- c[x] = Complex.ZERO;
- }
- return c;
- }
-
- /**
- * Initializes a {@code Complex[][]} array to zero, to avoid
- * NullPointerExceptions.
- *
- * @param c {@code Complex} array
- * @return c
- *
- * @since 4.0
- */
- public static Complex[][] initialize(Complex[][] c) {
- final int length = c.length;
- for (int x = 0; x < length; x++) {
- c[x] = initialize(c[x]);
- }
- return c;
- }
-
- /**
- * Initializes a {@code Complex[][][]} array to zero, to avoid
- * NullPointerExceptions.
- *
- * @param c {@code Complex} array
- * @return c
- *
- * @since 4.0
- */
- public static Complex[][][] initialize(Complex[][][] c) {
- final int length = c.length;
- for (int x = 0; x < length; x++) {
- c[x] = initialize(c[x]);
- }
- return c;
- }
-
- /**
- * Returns {@code double[]} containing absolute values (magnitudes) of a
- * {@code Complex[]} array.
- *
- * @param c {@code Complex} array
- * @return {@code double[]}
- *
- * @since 4.0
- */
- public static double[] abs(Complex[] c) {
- final int length = c.length;
- final double[] d = new double[length];
- for (int x = 0; x < length; x++) {
- d[x] = c[x].abs();
- }
- return d;
- }
-
- /**
- * Returns {@code double[]} containing arguments (phase angles) of a
- * {@code Complex[]} array.
- *
- * @param c {@code Complex} array
- * @return {@code double[]} array
- *
- * @since 4.0
- */
- public static double[] arg(Complex[] c) {
- final int length = c.length;
- final double[] d = new double[length];
- for (int x = 0; x < length; x++) {
- d[x] = c[x].getArgument();
- }
- return d;
- }
-
- /**
- * Exception to be throw when a negative value is passed as the modulus.
- */
- private static class NegativeModulusException extends IllegalArgumentException {
- /**
- * @param r Wrong modulus.
- */
- NegativeModulusException(double r) {
- super("Modulus is negative: " + r);
- }
- }
-
- /**
- * Exception to be throw when an out-of-range index value is passed.
- */
- private static class IndexOutOfRangeException extends IllegalArgumentException {
- /**
- * @param i Wrong index.
- */
- IndexOutOfRangeException(int i) {
- super("Out of range: " + i);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/main/java/org/apache/commons/complex/Precision.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/complex/Precision.java b/src/main/java/org/apache/commons/complex/Precision.java
deleted file mode 100644
index 77f5048..0000000
--- a/src/main/java/org/apache/commons/complex/Precision.java
+++ /dev/null
@@ -1,128 +0,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.
- */
-
-package org.apache.commons.complex;
-
-/**
- * Utilities for comparing numbers.
- */
-class Precision {
- /** Offset to order signed double numbers lexicographically. */
- private static final long SGN_MASK = 0x8000000000000000L;
- /** Positive zero bits. */
- private static final long POSITIVE_ZERO_DOUBLE_BITS = Double.doubleToRawLongBits(+0.0);
- /** Negative zero bits. */
- private static final long NEGATIVE_ZERO_DOUBLE_BITS = Double.doubleToRawLongBits(-0.0);
-
- /**
- * Private constructor.
- */
- private Precision() {}
-
- /**
- * Returns {@code true} if there is no double value strictly between the
- * arguments or the difference between them is within the range of allowed
- * error (inclusive). Returns {@code false} if either of the arguments
- * is NaN.
- *
- * @param x First value.
- * @param y Second value.
- * @param eps Amount of allowed absolute error.
- * @return {@code true} if the values are two adjacent floating point
- * numbers or they are within range of each other.
- */
- public static boolean equals(double x, double y, double eps) {
- return equals(x, y, 1) || Math.abs(y - x) <= eps;
- }
-
- /**
- * Returns {@code true} if there is no double value strictly between the
- * arguments or the relative difference between them is less than or equal
- * to the given tolerance. Returns {@code false} if either of the arguments
- * is NaN.
- *
- * @param x First value.
- * @param y Second value.
- * @param eps Amount of allowed relative error.
- * @return {@code true} if the values are two adjacent floating point
- * numbers or they are within range of each other.
- */
- public static boolean equalsWithRelativeTolerance(double x, double y, double eps) {
- if (equals(x, y, 1)) {
- return true;
- }
-
- final double absoluteMax = Math.max(Math.abs(x), Math.abs(y));
- final double relativeDifference = Math.abs((x - y) / absoluteMax);
-
- return relativeDifference <= eps;
- }
-
- /**
- * Returns true if the arguments are equal or within the range of allowed
- * error (inclusive).
- * <p>
- * Two float numbers are considered equal if there are {@code (maxUlps - 1)}
- * (or fewer) floating point numbers between them, i.e. two adjacent
- * floating point numbers are considered equal.
- * </p>
- * <p>
- * Adapted from <a
- * href="http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/">
- * Bruce Dawson</a>. Returns {@code false} if either of the arguments is NaN.
- * </p>
- *
- * @param x first value
- * @param y second value
- * @param maxUlps {@code (maxUlps - 1)} is the number of floating point
- * values between {@code x} and {@code y}.
- * @return {@code true} if there are fewer than {@code maxUlps} floating
- * point values between {@code x} and {@code y}.
- */
- public static boolean equals(final double x, final double y, final int maxUlps) {
-
- final long xInt = Double.doubleToRawLongBits(x);
- final long yInt = Double.doubleToRawLongBits(y);
-
- final boolean isEqual;
- if (((xInt ^ yInt) & SGN_MASK) == 0l) {
- // number have same sign, there is no risk of overflow
- isEqual = Math.abs(xInt - yInt) <= maxUlps;
- } else {
- // number have opposite signs, take care of overflow
- final long deltaPlus;
- final long deltaMinus;
- if (xInt < yInt) {
- deltaPlus = yInt - POSITIVE_ZERO_DOUBLE_BITS;
- deltaMinus = xInt - NEGATIVE_ZERO_DOUBLE_BITS;
- } else {
- deltaPlus = xInt - POSITIVE_ZERO_DOUBLE_BITS;
- deltaMinus = yInt - NEGATIVE_ZERO_DOUBLE_BITS;
- }
-
- if (deltaPlus > maxUlps) {
- isEqual = false;
- } else {
- isEqual = deltaMinus <= (maxUlps - deltaPlus);
- }
-
- }
-
- return isEqual && !Double.isNaN(x) && !Double.isNaN(y);
-
- }
-}
[22/31] commons-numbers git commit: Correct project info.
Posted by er...@apache.org.
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c7608e46/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 6bb0189..941d628 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -47,3614 +47,18 @@ If the output is not quite correct, check for invisible trailing spaces!
<document>
<properties>
- <title>Commons Math Release Notes</title>
+ <title>Apache Commons Numbers Release Notes</title>
</properties>
<body>
- <release version="TBD" date="TBD" description="TBD">
- </release>
-
- <release version="4.0" date="XXXX-XX-XX" description="">
- <action dev="erans" type="fix" issue="MATH-1301">
- "JDKRandomGenerator": Method "nextInt(int)" now throws a "NotStrictlyPositiveException".
- The class now delegates to (rather inherits from) "java.util.Random".
- </action>
- <action dev="erans" type="update" issue="MATH-1305" due-to="Rostislav Krasny">
- "AbstractRandomGenerator" and "BitsStreamGenerator": Slight performance
- improvement of the "nextBytes" method (particularly when the number of
- requested bytes is a multiple of 4).
- </action>
- <action dev="erans" type="fix" issue="MATH-1300" due-to="Rostislav Krasny">
- "AbstractRandomGenerator" and "BitsStreamGenerator": Remove a redundant call
- to the random data provider.
- </action>
- <action dev="erans" type="add" issue="MATH-1295" due-to="Aleksei Dievskii">
- "FactorialLog": Cache-based computation of the "log factorial" function (implemented
- as an inner class of "CombinatoricsUtils" in package "o.a.c.m.util").
- </action>
- <action dev="luc" type="add" issue="MATH-1271" due-to="Qualtagh">
- Added divideUnsigned and remainderUnsigned to ArithmeticUtils.
- </action>
- <action dev="erans" type="fix" issue="MATH-1231">
- Lifted unnecessary restriction on constructor's argument of
- "MicrosphereInterpolator" (package "o.a.c.m.analysis.interpolation").
- </action>
- <action dev="tn" type="fix" issue="MATH-1230">
- The "SimplexSolver" will now throw a "DimensionMismatchException"
- when calling "optimize(...)" with linear constraints whose dimension
- does not match the dimension of the objective function.
- </action>
- <action dev="luc" type="add" >
- Added a fast implementation of IEEEremainder in FastMath.
- </action>
- <action dev="luc" type="fix" issue="MATH-1222" due-to="Benedikt Ritter">
- Use Double.isNaN rather than x != x in FastMath.
- </action>
- <action dev="luc" type="fix" issue="MATH-1143">
- Added helper methods to FunctionUtils for univariate and multivariate differentiable functions conversion.
- </action>
- <action dev="tn" type="fix" issue="MATH-964">
- Removed unused package private class PollardRho in package primes.
- </action>
- <action dev="tn" type="fix" issue="MATH-1221">
- Improve performance of "ZipfDistribution" by caching the nth generalized harmonic.
- </action>
- <action dev="tn" type="update" issue="MATH-853">
- "MathRuntimeException" is now the base class for all commons-math
- exceptions (except for "NullArgumentException" which extends
- "NullPointerException").
- </action>
- <action dev="tn" type="remove" issue="MATH-1205">
- Removed methods "test(...)" from "AbstractUnivariateStatistic".
- The already existing methods "MathArrays#verifyValues(...)" shall
- be used instead.
- </action>
- <action dev="tn" type="update" issue="MATH-1205">
- The abstract class "AbstractStorelessUnivariateStatistic" does not
- extend anymore from "AbstractUnivariateStatistic".
- </action>
- <action dev="tn" type="update" issue="MATH-1205">
- Default implementation of
- "AbstractStorelessUnivariateStatistic#equals(Object)"
- will only return true if both instances have the same type. Previously
- different statistics were considered to be equal if their current state
- happened to be equal.
- </action>
- <action dev="tn" type="update" issue="MATH-1205">
- Default implementations of "AbstractStorelessUnivariateStatistic#evaluate(...)"
- do not alter the internal state anymore. Instead a temporary copy of
- the statistic is created for evaluation purposes.
- </action>
- <action dev="tn" type="fix" issue="MATH-1205">
- Methods "evaluate(...)" of class "Variance" changed the internal state
- although it was stated differently in the javadoc.
- </action>
- <action dev="luc" type="fix" issue="MATH-1191">
- Fixed ignored method parameters in QRDecomposition protected methods.
- </action>
- <action dev="luc" type="fix" issue="MATH-1212">
- Changed javadoc as the RandomDataGenerator class does not implement
- an interface anymore (the previous interface has been deprecated in
- 3.X and removed in 4.0).
- </action>
- <action dev="erans" type="update" issue="MATH-1206">
- Added new API methods in "LeastSquaresProblem.Evaluation" (package
- "o.a.c.m.fitting.leastsquares").
- </action>
- <action dev="erans" type="update" issue="MATH-1210">
- "QRDecomposition": include information about the condition that
- triggers a "SingularMatrixException".
- </action>
- <action dev="tn" type="update" issue="MATH-757">
- Removed broken synchronization support in "ResizableDoubleArray".
- </action>
- <action dev="tn" type="add" issue="MATH-945">
- Added method "T log10()" to interface "RealFieldElement".
- </action>
- <action dev="tn" type="update" issue="MATH-869">
- "SpearmansCorrelation" will now throw an "MathIllegalArgumentException"
- if provided with a "NaturalRanking" instance that uses "REMOVED" as "NaNStrategy".
- </action>
- <action dev="tn" type="update" issue="MATH-869">
- "NullArgumentException" extends now "java.lang.NullPointerException"
- instead of "MathIllegalArgumentException".
- </action>
- <action dev="tn" type="update" issue="MATH-839" due-to="Gilles Sadowski">
- Renamed "cumulativeProbability(double, double)" to "probability(double, double)"
- in "IntegerDistribution" and "RealDistribution".
- </action>
- <action dev="tn" type="add" issue="MATH-1039" due-to="Aleksei Dievskii">
- Added logDensity(double) to RealDistribution and logProbability(int)
- to IntegerDistribution interface. The implementations have already been
- updated in release 3.3.
- </action>
- <action dev="tn" type="update" issue="MATH-1155">
- WELL type pseudo-random number generators have been refactored:
- the cached indirection index tables per instance are now stored
- in a static instance. This reduces the initialization cost when
- creating a new instance.
- </action>
- <action dev="tn" type="remove" issue="MATH-1050">
- Removed "ArithmeticUtils#pow(int, long)" and "ArithmeticUtils#pow(long, long)".
- </action>
- <action dev="tn" type="update" issue="MATH-825" due-to="Gilles Sadowski">
- Method "LaguerreSolver#laguerre(...)" has been made private.
- </action>
- <action dev="tn" type="update" issue="MATH-760" due-to="sebb">
- Field "windowSize" in "DescriptiveStatistics" has been made private.
- </action>
- </release>
-
- <release version="3.6" date="2016-01-05" description="
-This is a minor release: It combines bug fixes and new features.
- Changes to existing features were made in a backwards-compatible
- way such as to allow drop-in replacement of the v3.x JAR file.
-
-Most notable among the new features are:
- field-based version of Ordinary Differential Equations framework,
- numerous improvements in distributions, statistics and neuralnet packages,
- refactored implementation of microsphere interpolation algorithm,
- explicit specification of rotation convention to use (both vector
- operator and frame transform conventions are now available).
-
-The minimum version of the Java platform required to compile and use
- Commons Math is Java 5.
-
-Users are encouraged to upgrade to this version as this release not
- only includes bug fixes but also deprecates numerous classes and
- methods that will be deleted from the next major release (4.0).
-
- Caveat:
- 1. The implementation of the BOBYQA optimization algorithm is in alpha
- state (cf. MATH-621): Many code paths are untested, and we are looking
- for volunteers to improve the code readability, robustness and performance
- and to extend the unit tests suite.
- 2. A few methods in the FastMath class are in fact slower that their
- counterpart in either Math or StrictMath (cf. MATH-740 and MATH-901).
-">
- <action dev="psteitz" type="fix" issue="MATH-1310">
- Improved performance and accuracy of 2-sample KolmogorovSmirnov tests.
- </action>
- <action dev="luc" type="fix" issue="MATH-1297">
- Detect start failures with multi-step ODE integrators.
- </action>
- <action dev="luc" type="add" issue="MATH-1302,MATH-1303">
- Added a RotationConvention enumerate to allow specifying the semantics
- or axis/angle for rotations. This enumerate has two values:
- VECTOR_OPERATOR and FRAME_TRANSFORM.
- </action>
- <action dev="luc" type="fix" due-to="Julien Queyrel">
- Fixed stability issues with Adams-Bashforth and Adams-Moulton ODE integrators.
- The integrators did not estimate the local error properly and were sometimes
- stuck attempting to reduce indefinitely the step size as they thought the
- error was too high.
- </action>
- <action dev="luc" type="add" issue="MATH-1288">
- Added a field-based version of Ordinary Differential Equations framework.
- This allows integrating ode that refer to RealField elements instead of
- primitive double, hence opening the way to use DerivativeStructure to
- compute partial differential without using variational equations, or to solve
- ode with extended precision using Dfp.
- </action>
- <action dev="erans" type="fix" issue="MATH-1295" due-to="Luke Lindsay">
- Increased default value for number of allowed evaluations in
- "o.a.c.m.optim.univariate.BracketFinder".
- </action>
- <action dev="psteitz" type="update" issue="MATH-1246">
- Modified 2-sample KolmogorovSmirnovTest to handle ties in sample data. By default,
- ties are broken by adding random jitter to input data. Also added bootstrap method
- analogous to ks.boot in R Matching package.
- </action>
- <action dev="tn" type="fix" issue="MATH-1294" due-to="Kamil W\u0142odarczyk">
- Fixed potential race condition in PolynomialUtils#buildPolynomial in
- case polynomials are generated from multiple threads. Furthermore, the
- synchronization is now performed on the coefficient list instead of the class.
- </action>
- <action dev="psteitz" type="update" issue="MATH-1246">
- Added bootstrap method to KolmogorovSmirnov test.
- </action>
- <action dev="psteitz" type="update" issue="MATH-1287">
- Added constructors taking sample data as arguments to enumerated real and integer distributions.
- </action>
- <action dev="oertl" type="fix" issue="MATH-1269">
- Fixed FastMath.exp that potentially returned NaN for non-NaN argument.
- </action>
- <action dev="luc" type="add">
- Added a nth order Brent solver for general real fields, replacing the former
- solver that was restricted to Dfp fields only.
- </action>
- <action dev="erans" type="add" issue="MATH-1286">
- New "Range" inner class of "o.a.c.m.util.IntegerSequence".
- </action>
- <action dev="oertl" type="fix" issue="MATH-1285" due-to="Pim van der Hoorn ">
- Updated reference in ZipfDistribution's javadoc.
- </action>
- <action dev="tn" type="fix" issue="MATH-1283" due-to="Jean Noel Delavalade">
- Fixed "Gamma#gamma(double)" for negative values smaller than -20.
- </action>
- <action dev="tn" type="fix" issue="MATH-1237" due-to="Ken Williams">
- Fixed javadoc of methods {floorDiv,floorMod} in class "FastMath".
- </action>
- <action dev="tn" type="add" issue="MATH-837">
- "AggregateSummaryStatistics" can now aggregate any kind of
- "StatisticalSummary".
- </action>
- <action dev="erans" type="fix" issue="MATH-1279">
- Check precondition (class "o.a.c.m.random.EmpiricalDistribution").
- </action>
- <action dev="erans" type="add" issue="MATH-1278">
- Deep copy of "Network" (package "o.a.c.m.ml.neuralnet") to allow evaluation of
- of intermediate states during training.
- </action>
- <action dev="oertl" type="update" issue="MATH-1276">
- Improved performance of sampling and inverse cumulative probability calculation
- for geometric distributions.
- </action>
- <action dev="oertl" type="fix" issue="MATH-1277" due-to="Marc Rosen">
- Fixed incorrect Kendall's tau coefficient calculation due to internal integer overflow.
- </action>
- <action dev="oertl" type="update" issue="MATH-1274">
- Representation of Kolmogorov-Smirnov statistic as integral value.
- </action>
- <action dev="luc" type="add" issue="MATH-1273" due-to="Qualtagh">
- Added negative zero support in FastMath.pow.
- </action>
- <action dev="erans" type="add" issue="MATH-1270">
- Various SOFM visualizations (in package "o.a.c.m.ml.neuralnet.twod.util"):
- Unified distance matrix, hit histogram, smoothed data histograms,
- topographic error, quantization error.
- </action>
- <action dev="erans" type="add" issue="MATH-1268">
- New interfaces to be implemented by algorithms that visualizes properties
- of a "NeuronSquareMesh2D" (package "o.a.c.m.ml.neuralnet.twod.util").
- </action>
- <action dev="luc" type="add" >
- Reimplemented pow(double, double) in FastMath, for better accuracy in
- integral power cases and trying to fix erroneous JIT optimization again.
- </action>
- <action dev="luc" type="add" >
- Added a pow(double, long) method in FastMath.
- </action>
- <action dev="luc" type="fix" issue="MATH-1266">
- Fixed split/side inconsistencies in BSP trees.
- </action>
- <action dev="erans" type="add" issue="MATH-1265">
- "NeuronSquareMesh2D" (package "o.a.c.m.ml.neuralnet.twod") implements "Iterable".
- </action>
- <action dev="erans" type="add" issue="MATH-1264">
- "MapUtils" (package "o.a.c.m.ml.neuralnet"): Method to sort units according to distance
- from a given vector.
- </action>
- <action dev="erans" type="add" issue="MATH-1263">
- Accessor (class "o.a.c.m.ml.neuralnet.twod.NeuronSquareMesh2D").
- </action>
- <action dev="erans" type="add" issue="MATH-1259">
- New "IntegerSequence" class (in package "o.a.c.m.util") with "Incrementor" inner class.
- </action>
- <action dev="oertl" type="update" issue="MATH-1220">
- Faster generation of Zipf distributed random numbers by using rejection-inversion sampling.
- </action>
- <action dev="oertl" type="update" issue="MATH-990">
- Improved performance of sort-in-place methods by avoiding boxing.
- </action>
- <action dev="erans" type="fix" issue="MATH-1261" due-to="Osamu Ikeuchi">
- Avoid overflow in "Fraction" (multiplication or division by an int).
- </action>
- <action dev="oertl" type="fix" issue="MATH-1258" due-to="Gunel Jahangirova">
- Added check for equal array lengths to distance measure functions.
- </action>
- <action dev="erans" type="fix" issue="MATH-1257" due-to="Bill Murphy">
- Better accuracy in computation of cumulative probability of "NormalDistribution"
- (package "o.a.c.m.distribution").
- </action>
- <action dev="erans" type="fix" issue="MATH-1256">
- Boundary check to construct an "Interval" (package "o.a.c.m.geometry.euclidean.oned").
- </action>
- <action dev="erans" type="fix" issue="MATH-1255">
- Wrong neighbourhood size in class "KohonenUpdateAction" (package "o.a.c.m.ml.neuralnet.sofm").
- </action>
- <action dev="psteitz" type="fix" issue="MATH-1252" due-to="John Bay">
- ResizableDoubleArray constructor does not work with double array of size 1.
- </action>
- <action dev="erans" type="fix" issue="MATH-1251">
- Fixed initial value of "number of calls" counter in class "KohonenUpdateAction"
- (package "o.a.c.m.ml.neuralnet.sofm").
- </action>
- <action dev="erans" type="add" issue="MATH-1250">
- "Neuron" class (package "o.a.c.m.ml.neuralnet"): added methods that can be used
- to assess concurrency performance.
- </action>
- <action dev="erans" type="fix" issue="MATH-1248" due-to="Chris Popp">
- Removed unnecessary allocations in "BigFraction" (package "o.a.c.m.fraction").
- </action>
- <action dev="psteitz" type="fix" issue="MATH-1245">
- Fixed error in computing discrete distribution of D statistics for small-sample
- 2-sample Kolmogorov-Smirnov tests. Error was causing incorrect p-values returned
- by exactP and monteCarloP methods (used by default for small, mid-size samples).
- </action>
- <action dev="erans" type="update" issue="MATH-1243">
- Refactored implementation of the "miscrosphere projection"
- interpolation algorithm.
- New classes: "MicrosphereProjectionInterpolator",
- "InterpolatingMicrosphere" and "InterpolatingMicrosphere2D"
- replace "MicrosphereInterpolator" and "MicrosphereInterpolatingFunction".
- (package "o.a.c.m.analysis.interpolation").
- </action>
- <action dev="erans" type="add" issue="MATH-1244">
- Method "cosAngle" in "o.a.c.m.util.MathArrays".
- </action>
- <action dev="tn" type="fix" issue="MATH-1240">
- "KolmogorovSmirnovTest#ksSum(...)" returned wrong result in case the provided
- t-parameters was zero. This affected the calculation of "approximateP(...)" for
- identical samples.
- </action>
- <action dev="tn" type="fix" issue="MATH-1242" due-to="Otmar Ertl">
- Improved performance to calculate the two-sample Kolmogorov-Smirnov test
- via monte carlo simulation ("KolmogorovSmirnovTets#monteCarloP(...)").
- </action>
- <action dev="tn" type="fix" issue="MATH-1241" due-to="Aleksei Dievskii">
- A "StackOverflowException" was thrown when passing Double.NaN or infinity
- to "Gamma#digamma(double)" or "Gamma#trigamma(double)". Now the input value
- is propagated to the output if it is not a real number.
- </action>
- <action dev="tn" type="fix" issue="MATH-1232" due-to="Otmar Ertl">
- Improved performance of calculating the two-sample Kolmogorov-Smirnov
- test statistic.
- </action>
- <action dev="luc" type="fix" issue="MATH-1232">
- Fixed error message for unknown parameter name in ODE.
- </action>
- <action dev="luc" type="fix" issue="MATH-1226">
- Fixed wrong event detection in case of close events pairs.
- </action>
- <action dev="tn" type="fix">
- Fix potential branching errors in "FastMath#pow(double, double)" when
- passing special values, i.e. infinity, due to erroneous JIT optimization.
- </action>
- <action dev="luc" type="fix" issue="MATH-1118" >
- Fixed equals/hashcode contract failure for Dfp.
- </action>
- <action dev="luc" type="fix" issue="MATH-1223" >
- Fixed wrong splitting of huge number in extended accuracy algorithms.
- </action>
- <action dev="tn" type="fix" issue="MATH-1153" due-to="Sergei Lebedev">
- Improve performance of "BetaDistribution#sample()" by using Cheng's algorithm.
- </action>
- <action dev="tn" type="fix" issue="MATH-1197">
- Computation of 2-sample Kolmogorov-Smirnov statistic in case of ties
- was not correct.
- </action>
- </release>
-
- <release version="3.5" date="2015-04-17" description="
-This is a minor release: It combines bug fixes and new features.
- Changes to existing features were made in a backwards-compatible
- way such as to allow drop-in replacement of the v3.4.1 JAR file.
-
-Most notable among the new features are:
- getQuadraticMean method added to DescriptiveStatistics SummaryStatistics
- which calculates the root mean square, and a way to build polyhedrons sets
- from list of vertices and the facets they belong too. There have been
- numerous bug fixes. See below for a full list.
-
-The minimum version of the Java platform required to compile and use
- Apache Commons Math is Java 5.
-
-Users are encouraged to upgrade to this version as this release not
- only includes bug fixes but also deprecates numerous classes and
- methods that will be deleted from the next major release (4.0).
-
- Caveat:
- 1. The implementation of the BOBYQA optimization algorithm is in alpha
- state (cf. MATH-621): Many code paths are untested, and we are looking
- for volunteers to improve the code readability, robustness and performance
- and to extend the unit tests suite.
- 2. A few methods in the FastMath class are in fact slower that their
- counterpart in either Math or StrictMath (cf. MATH-740 and MATH-901).
-">
- <action dev="luc" type="fix" issue="MATH-1195">
- Moved FastMathTestPerformance out of the main test tree, as is is
- a benchmark rather than a test.
- </action>
- <action dev="luc" type="add">
- Added a way to build polyhedrons sets from a list of vertices and
- facets specified using vertices indices.
- </action>
- <action dev="psteitz" type="update" issue="MATH-1213">
- Added Laguerre complex solve methods taking maxEval parameters.
- </action>
- <action dev="luc" type="fix" issue="MATH-1191">
- Fixed ignored method parameters in QRDecomposition protected methods.
- </action>
- <action dev="luc" type="fix" issue="MATH-1211" due-to="Mike Zimmerman">
- Fixed wrong selection of line/polyhedron intersection point.
- </action>
- <action dev="luc" type="fix" issue="MATH-1162">
- Improved fix for corner cases in BSP-tree merging, when cut sub-hyperplanes vanish.
- </action>
- <action dev="tn" type="fix" issue="MATH-1209" due-to="Jonathan Ogilvie">
- Fixed link to algorithm description in "PoissonDistribution#sample()".
- </action>
- <action dev="psteitz" type="fix" issue="MATH-1208">
- EmpiricalDistribution cumulativeProbability can return NaN when evaluated within a constant bin.
- </action>
- <action dev="psteitz" type="fix" issue="MATH-1203">
- EmpiricalDistribution getKernel fails for buckets with only multiple instances of the same value.
- </action>
- <action dev="evanward" type="fix" issue="MATH-1204">
- "UnivariateSolverUtils#bracket(...)" sometimes failed to bracket
- if a reached the lower bound.
- </action>
- <action dev="sebb" type="add" issue="MATH-1198">
- Simplified "FastMath#exp(double)" in order to avoid a potential
- Java 1.5 JIT bug when calling with negative infinity as argument.
- </action>
- <action dev="erans" type="add" issue="MATH-1199">
- Added method "getQuadraticMean()" to "DescriptiveStatistics"
- and "SummaryStatistics" which calculates the root mean square.
- </action>
- </release>
-
- <release version="3.4.1" date="2015-01-11" description="
-This is a maintenance release: It fixes issue MATH-1188.
-">
- <action dev="sebb" type="fix" issue="MATH-1188">
- Fixed non-Java1.5 code in BesselJ.
- </action>
- </release>
-
- <release version="3.4" date="2014-12-26" description="
-This is a minor release: It combines bug fixes and new features.
- Changes to existing features were made in a backwards-compatible
- way such as to allow drop-in replacement of the v3.3 JAR file.
-
-Most notable among the new features are:
- new distributions (Gumbel, Laplace, Logistic, Nakagami), and
- improvements on percentiles algorithms (better handling for NaNs
- in the regular algorithm, plus a new storeless implementation).
- Bicubic and tricubic interpolators have been fixed and new
- implementations added. There have been numerous bug fixes and
- several improvements on performances or robustness. See below
- for a full list.
-
-The minimum version of the Java platform required to compile and use
- Apache Commons Math is Java 5.
-
-Users are encouraged to upgrade to this version as this release not
- only includes bug fixes but also deprecates numerous classes and
- methods that will be deleted from the next major release (4.0).
-
- Caveat:
- 1. The implementation of the BOBYQA optimization algorithm is in alpha
- state (cf. MATH-621): Many code paths are untested, and we are looking
- for volunteers to improve the code readability, robustness and performance
- and to extend the unit tests suite.
- 2. A few methods in the FastMath class are in fact slower that their
- counterpart in either Math or StrictMath (cf. MATH-740 and MATH-901).
-">
- <action dev="psteitz" type="add" issue="MATH-1066" due-to="Brian Wignall">
- Added Bessel functions of the first kind, based on NetLib implementation.
- </action>
- <action dev="tn" type="fix" issue="MATH-1142" due-to="Arne Schwarz">
- Improve performance of kalman gain calculation in "KalmanFilter" by
- directly solving a linear system rather than computing the matrix
- inverse.
- </action>
- <action dev="psteitz" type="fix" issue="MATH-1181">
- Fixed integer overflow in KolmogorovSmirnovTest causing 2-sample test
- to use exact method when the product of the sample sizes exceeds
- Integer.MAX_VALUE, resulting in effectively hung execution.
- </action>
- <action dev="erans" type="add" issue="MATH-1180">
- Method to create a sequence of integers (in "o.a.c.m.util.MathArrays").
- </action>
- <action dev="erans" type="add" issue="MATH-1172">
- New class "SimpleCurveFitter": Boiler-plate code to allow fitting of
- a user-defined parametric function.
- </action>
- <action dev="erans" type="add" issue="MATH-1173">
- New classes "TricubicInterpolatingFunction" and "TricubicInterpolator" to
- replace "TricubicSplineInterpolatingFunction" and "TricubicSplineInterpolator".
- </action>
- <action dev="erans" type="fix" issue="MATH-1178" due-to="Dmitriy">
- Fixed example in userguide ("stat" section).
- </action>
- <action dev="erans" type="fix" issue="MATH-1175" due-to="Karsten Loesing">
- Fixed inverse cumulative probability of 0 in "LaplaceDistribution".
- </action>
- <action dev="erans" type="add" issue="MATH-1166">
- New classes "BicubicInterpolatingFunction" and "BicubicInterpolator" to
- replace "BicubicSplineInterpolatingFunction" and "BicubicSplineInterpolator".
- </action>
- <action dev="luc" type="update" >
- Spurious vertices in the middle of otherwise straight edges are now
- filtered out when rebuilding polygons boundaries from BSP trees.
- </action>
- <action dev="luc" type="fix" issue="MATH-1174" >
- Fixed a problem with too thin polygons considered to have infinite size.
- </action>
- <action dev="luc" type="add" >
- Boundary attributes in regions now provides the BSP tree nodes that
- were used to split the sub-hyperplane forming the boundary part of the facet.
- </action>
- <action dev="luc" type="fix" issue="MATH-1162" >
- Fixed a problem with vanishing cut sub-hyperplanes during BSP tree merging.
- </action>
- <action dev="erans" type="fix" issue="MATH-1167" due-to="Neil Ireson">
- "o.a.c.m.stat.regression.OLSMultipleLinearRegression": Use threshold
- when performing "QRDecomposition".
- </action>
- <action dev="tn" type="fix" issue="MATH-1165" due-to="Pashutan Modaresi">
- "FuzzyKMeansClusterer" has thrown an exception in case one of the data
- points was equal to a cluster center.
- </action>
- <action dev="erans" type="add" issue="MATH-1144">
- Interface to allow parameter validation in "o.a.c.m.fitting.leastsquares":
- the point computed by by the optimizer can be modified before evaluation.
- </action>
- <action dev="luc" type="fix" issue="MATH-1160" >
- Provide access to state derivatives in ContinuousOutputModel.
- </action>
- <action dev="luc" type="fix" issue="MATH-1138" due-to="Hank Grabowski">
- Fixed bicubic spline interpolator, using Akima splines.
- </action>
- <action dev="psteitz" type="add" issue="MATH-1154" >
- Changed classes in the inference package that instantiate distributions to
- pass null RandomGenerators to avoid initialization overhead for the default
- generator.
- </action>
- <action dev="luc" type="add" issue="MATH-1156" >
- Added all Java 8 StrictMath methods to FastMath, so FastMath remains compatible
- with newer Java versions.
- </action>
- <action dev="tn" type="add" issue="MATH-1139" due-to="Alexey Volkov">
- Added Gumbel, Laplace, Logistic and Nakagami distributions.
- </action>
- <action dev="psteitz" type="fix" issue="MATH-1147">
- Added statistics missing from toString method in SummaryStatistics.
- </action>
- <action dev="tn" type="fix" issue="MATH-1152" due-to="Andras Sereny">
- Improved performance of "EnumeratedDistribution#sample()" by caching
- the cumulative probabilities and using binary rather than a linear search.
- </action>
- <action dev="tn" type="fix" issue="MATH-1148" due-to="Guillaume Marceau">
- "MonotoneChain" did not take the tolerance factor into account when
- sorting the input points. In case of collinear points this could result
- in a "ConvergenceException" when computing the hull.
- </action>
- <action dev="erans" type="fix" issue="MATH-1151">
- Interface "ValueAndJacobianFunction" is a precondition for lazy
- evaluation (in "o.a.c.m.fitting.leastsquares").
- </action>
- <action dev="tn" type="fix" issue="MATH-1145" due-to="Anders Conbere">
- Fix potential integer overflows in "MannWhitneyUTest" when providing
- large sample arrays.
- </action>
- <action dev="tn" type="fix" issue="MATH-1149" due-to="M Kim">
- Fixed potential null pointer dereferencing in constructor of
- "DummyStepInterpolator(DummyStepInterpolator)".
- </action>
- <action dev="psteitz" type="fix" issue="MATH-1136" due-to="Aleksei Dievskii">
- Fixed BinomialDistribution to deal with degenerate cases correctly.
- </action>
- <action dev="tn" type="fix" issue="MATH-1135" due-to="Guillaume Marceau">
- "MonotoneChain" failed to generate a convex hull if only a minimal hull
- shall be created (includeCollinearPoints=false) and collinear hull points
- were present in the input.
- </action>
- <action dev="psteitz" type="fix" issue="MATH-1131" due-to="Schalk W. Cronj�">
- Improve performance of "KolmogorovSmirnovTest#kolmogorovSmirnovTest(...)" for
- large samples. Also changed implementation for large n to use Pelz-Good
- approximation.
- </action>
- <action dev="erans" type="fix" issue="MATH-1134">
- "BicubicSplineInterpolatingFunction": all fields made final and initialized in
- the constructor. Added flag to request initialization, or not, of the internal
- data needed for partial derivatives.
- </action>
- <action dev="psteitz" type="fix" issue="MATH-984">
- Constrained EmpiricalDistribution sample/getNextValue methods to return
- values within the range of the data; correctly linked RandomGenerator to
- superclass so that RealDistribution reseedRandomGenerator method works.
- </action>
- <action dev="luc" type="add" issue="MATH-1120" due-to="Venkatesha Murthy">
- Added several different estimation types and NaN handling strategies for Percentile.
- </action>
- <action dev="psteitz" type="add" issue="MATH-418" due-to="Venkatesha Murthy">
- Added implementation of PSquare algorithm to estimate percentiles without
- storing data in memory (i.e. as StorelessUnivariateStatistic).
- </action>
- <action dev="erans" type="fix" issue="MATH-1129">
- "Percentile": wrong sorting in the presence of NaN.
- </action>
- <action dev="erans" type="update" issue="MATH-1128">
- Added lazy evaluation to "LeastSquaresFactory" (in "o.a.c.m.fitting.leastsquares")
- to avoid evaluating the model when the optimization algorithm does not actually
- require it.
- </action>
- <action dev="luc" type="fix" issue="MATH-1127">
- Fixed overflow in Precision.equals with ulps (both double and float versions).
- </action>
- <action dev="tn" type="fix" issue="MATH-1125" due-to="Ajo Fod">
- Performance improvements for Student's t-distribution.
- </action>
- <action dev="luc" type="fix" issue="MATH-1123" due-to="Aur�lien Labrosse">
- Fixed NullPointerException when chopping-off a sub-hyperplane
- that is exactly at a region boundary.
- </action>
- <action dev="erans" type="fix" issue="MATH-1121" due-to="Ajo Fod">
- "BrentOptimizer": increment base class iteration counter.
- </action>
- </release>
-
- <release version="3.3" date="2014-05-05" description="
-This is a minor release: It combines bug fixes and new features.
- Changes to existing features were made in a backwards-compatible
- way such as to allow drop-in replacement of the v3.x JAR file.
-
-Most notable among the new features are:
- Framework for creating artificial neural nets, self organizing feature maps,
- computational geometry algorithms (convex hull, enclosing ball), performance
- improvements of the linear simplex solver, refactoring of curve fitters,
- low-discrepancy random generators (sobol, halton), least-squares fitting.
-
-The minimum version of the Java platform required to compile and use
- Commons Math is Java 5.
-
-Users are encouraged to upgrade to this version as this release not
- only includes bug fixes but also deprecates numerous classes and
- methods that will be deleted from the next major release (4.0).
-
- Caveat:
- 1. The implementation of the BOBYQA optimization algorithm is in alpha
- state (cf. MATH-621): Many code paths are untested, and we are looking
- for volunteers to improve the code readability, robustness and performance
- and to extend the unit tests suite.
- 2. A few methods in the FastMath class are in fact slower that their
- counterpart in either Math or StrictMath (cf. MATH-740 and MATH-901).
- 3. A few methods/constructors in the package o.a.c.m.geometry.partitioning
- have changed their signature in a non backwards-compatible way. The respective
- classes are intended to be package private only and are not supposed to be
- used for other purposes.
-">
- <action dev="tn" type="add" issue="MATH-1110" due-to="Edward Segall">
- Added new constructor to "OLSMultipleLinearRegression" to be able
- to specify a custom singularity threshold for QR decomposition.
- </action>
- <action dev="erans" type="fix" issue="MATH-1092">
- Extracted class "LineSearch" from "PowellOptimizer", to be used in
- "NonLinearConjugateGradientOptimizer" (in place of the implementation
- that triggered this issue).
- </action>
- <action dev="luc" type="fix" issue="MATH-1115">
- Build properly empty polyhedrons set when given equal min/max boundaries. Also explained
- better in the javadoc about some wrong usage of PolyhedronsSet constructor.
- </action>
- <action dev="luc" type="fix" issue="MATH-1117">
- Build properly empty polygons set when given equal min/max boundaries. Also explained
- better in the javadoc about some wrong usage of PolygonsSet constructor.
- </action>
- <action dev="luc" type="add" issue="MATH-1119">
- Added a fast single-step method for fixed-step Runge-Kutta integrators.
- </action>
- <action dev="erans" type="fix" issue="MATH-1118">
- "Complex": Fixed compatibility of "equals(Object)" with "hashCode()".
- Added new methods for testing floating-point equality between the real
- (resp. imaginary) parts of two complex numbers.
- </action>
- <action dev="luc" type="add" >
- Added an order 6 fixed-step ODE integrator designed by H. A. Luther in 1968.
- </action>
- <action dev="luc" type="update" >
- Bracketing utility for univariate root solvers returns a tighter interval than before.
- It also allows choosing the search interval expansion rate, supporting both linear
- and asymptotically exponential rates.
- </action>
- <action dev="luc" type="fix" issue="MATH-1107" due-to="Bruce A Johnson">
- Prevent penalties to grow multiplicatively in CMAES for out of bounds points.
- </action>
- <action dev="psteitz" type="update" issue="MATH-437">
- Added KolmogorovSmirnovTest class, deprecating KolmogorovSmirnovDistribution.
- </action>
- <action dev="luc" type="add" issue="MATH-1101">
- Improved documentation of QR decomposition handling of singular matrices.
- </action>
- <action dev="luc" type="add" issue="MATH-1053" due-to="Sean Owen">
- QR decomposition can compute pseudo-inverses for tall matrices.
- </action>
- <action dev="luc" type="add" issue="MATH-820">
- Field vectors now implement the visitor pattern just like real vectors.
- </action>
- <action dev="luc" type="fix" issue="MATH-875">
- Un-deprecated RealVector.sparseIterator, documenting explicitly that entries
- not iterated above are the zero ones.
- </action>
- <action dev="luc" type="fix" issue="MATH-821">
- Relaxed specification for function mapping on vectors, thus allowing straightforward
- implementation for sparse vectors.
- </action>
- <action dev="luc" type="update" issue="MATH-1099" due-to="Evan Ward">
- Make QR the default in GaussNewtonOptimizer.
- </action>
- <action dev="luc" type="update" issue="MATH-1099" due-to="Evan Ward">
- Add Cholesky option to GaussNewtonOptimizer.
- </action>
- <action dev="luc" type="update" issue="MATH-1099" due-to="Evan Ward">
- Make QR in GaussNewton faster and more accurate.
- </action>
- <action dev="luc" type="update" issue="MATH-870">
- The sparse vector and matrix classes have been un-deprecated. This is a reversal
- of a former decision, as we now think we should adopt a generally accepted
- behavior which is ... to ignore the problems of NaNs and infinities in
- sparse linear algebra entities.
- </action>
- <action dev="tn" type="add" issue="MATH-749">
- Added MonotoneChain algorithm to compute the convex hull of a collection of
- points in 2D. Additionally, the AklToussaintHeuristic can be used to speed up
- the generation.
- </action>
- <action dev="tn" type="fix" issue="MATH-1065" due-to="matteodg">
- Calculating the inverse cumulative probability of an "EnumeratedRealDistribution"
- will now return the correct result according to the selected enumerated probability
- mass function.
- </action>
- <action dev="erans" type="update" issue="MATH-1050">
- Deprecated "ArithmeticUtils#pow(int, long)" and "ArithmeticUtils#pow(long, long)"
- in favor of corresponding methods "ArithmeticUtils#pow(..., int)".
- </action>
- <action dev="erans" type="fix" issue="MATH-976">
- Create additional artifact "commons-math3-x.y.z-tools.jar" as part of the
- release process. This artifact contains useful tools, e.g. for performance testing.
- </action>
- <action dev="erans" type="fix" issue="MATH-990">
- Improved performance of "MathArrays#sortInPlace(...)".
- </action>
- <action dev="tn" type="fix" issue="MATH-1044" due-to="Sean Owen">
- Clarify javadoc of "DecompositionSolver#getInverse()" and corresponding implementations
- wrt the actually returned inverse. Several decomposition implementations are able
- to return a pseudo-inverse in case of a singular matrix.
- </action>
- <action dev="luc" type="add" issue="MATH-1095">
- Added Emo Welzl algorithm to find the smallest enclosing ball of a collection of points.
- </action>
- <action dev="erans" type="fix" issue="MATH-985" due-to="Johnathan Kool">
- Fixed an indexing problem in "BicubicSplineInterpolatingFunction" which
- resulted in wrong interpolations.
- </action>
- <action dev="tn" type="add" issue="MATH-1072">
- Added a constructor to "AbstractListChromosome" that does not copy the
- input argument.
- </action>
- <action dev="luc" type="add" issue="MATH-1091">
- BSP tree now provides an API to compute a global signed distance from
- a test point to the region. The distance is positive if the point is
- outside of the region, negative if the point is inside, and zero
- when the point is at the boundary. The distance is continuous
- everywhere, so it can be used with a root solver to identify accurately
- boundary crossings. This API is available for all BSP trees, in
- Euclidean and spherical geometries, and in all dimensions.
- </action>
- <action dev="luc" type="add">
- Added new geometry sub-packages: spherical.oned which deals with geometry
- on the 1-sphere (i.e. the circle) and spherical.twod which deals with the
- 2-sphere (i.e. the regular sphere). BSP trees can be used in these new
- spaces, so one can build arcs sets and spherical polygons sets with all
- the regular operations (inside/outside/boundary checks, union, intersection,
- symetric difference, complement ...).
- </action>
- <action dev="luc" type="add" issue="MATH-1090">
- IntervalsSet now implements Iterable<double[]>, so one can iterate
- over the sub-intervals without building a full list containing
- a copy of everything beforehand.
- </action>
- <action dev="tn" type="fix" issue="MATH-1089">
- "Precision#round(double, ...)" will now return negative zero for negative
- values rounded to zero, similar to the float variant.
- </action>
- <action dev="erans" type="fix" issue="MATH-1088">
- The iterator returned by "MultiDimensionalCounter#iterator()" will now
- correctly throw a "NoSuchElementException" when calling "next()" and the
- iterator is already exhausted.
- </action>
- <action dev="luc" type="fix" >
- Fixed an issue with noisy functions for ODE events detection.
- </action>
- <action dev="erans" type="add" issue="MATH-923">
- Utilities for creating artificial neural networks (package "o.a.c.m.ml.neuralnet").
- Implementation of Kohonen's Self-Organizing Feature Map (SOFM).
- </action>
- <action dev="tn" type="fix" issue="MATH-1082">
- The cutOff mechanism of the "SimplexSolver" in package o.a.c.math3.optim.linear
- could lead to invalid solutions. The mechanism has been improved in a way that
- the tableau does not need to be updated anymore. Additionally, a new check will
- prevent impossible solutions to be returned as valid.
- </action>
- <action dev="tn" type="fix" issue="MATH-1079">
- Improved performance of "SimplexSolver" in package o.a.c.math3.optim.linear by
- directly performing row operations and keeping track of the current basic variables.
- </action>
- <action dev="tn" type="update" issue="MATH-1080">
- The "LinearConstraintSet" will now return the enclosed collection of "LinearConstraint"
- objects in the same order as they have been added.
- </action>
- <action dev="tn" type="fix" issue="MATH-842">
- Added support for different pivot selection rules to the "SimplexSolver" by introducing
- the new "OptimizationData" class "PivotSelectionRule". Currently supported rules are:
- Dantzig (default) and Bland (avoids cycles).
- </action>
- <action dev="tn" type="fix" issue="MATH-1070" due-to="Oleksandr Muliarevych">
- Fix "Precision#round(float, int, int)" when using rounding mode "BigDecimal.ROUND_UP"
- and the discarded fraction is zero.
- </action>
- <action dev="tn" type="fix" issue="MATH-1059">
- Use "FastMath" instead of "Math" within Commons Math.
- </action>
- <action dev="tn" type="fix" issue="MATH-1068" due-to="Gal Lalouche">
- Avoid overflow when calculating Kendall's correlation for large arrays.
- </action>
- <action dev="erans" type="fix" issue="MATH-1067" due-to="Florian Erhard">
- Avoid infinite recursion in "Beta.regularizedBeta" (package "o.a.c.m.special");
- </action>
- <action dev="erans" type="add" issue="MATH-1014">
- Refactoring of curve fitters (package "o.a.c.m.fitting").
- </action>
- <action dev="tn" type="add" issue="MATH-970">
- Added possibility to retrieve the best found solution of the "SimplexSolver" in case
- the iteration limit has been reached. The "optimize(OptimizationData...)" method now
- supports a "SolutionCallback" which provides access to the best solution if
- a feasible solution could be found (phase 2 of the Two-Phase simplex method has been reached).
- </action>
- <action dev="tn" type="update" issue="MATH-1031" due-to="Thorsten Sch�fer">
- Added new class "ClusterEvaluator" to evaluate the result of a clustering algorithm
- and refactored existing evaluation code in "MultiKMeansPlusPlusClusterer"
- into separate class "SumOfClusterVariances".
- </action>
- <action dev="psteitz" type="add" issue="MATH-1061">
- Added InsufficientDataException.
- </action>
- <action dev="psteitz" type="fix" issue="MATH-1056" due-to="Sean Owen">
- Fixed unintended integer division error in PoissonDistribution sampling method.
- </action>
- <action dev="tn" type="fix" issue="MATH-1057">
- Fixed failing unit tests for "BOBYQAOptimizer" when executed with a Oracle/Sun JVM 1.5.
- </action>
- <action dev="tn" type="fix" issue="MATH-1062">
- A call to "KalmanFilter#correct(...)" may have resulted in "NonSymmetricMatrixException"
- as the internally used matrix inversion method was using a too strict symmetry check.
- </action>
- <action dev="erans" type="fix" issue="MATH-1058" due-to="Sean Owen">
- Precision improvements (for small values of the argument) in "Beta" function
- and in "LogNormalDistribution" and "WeibullDistribution".
- </action>
- <action dev="tn" type="fix" issue="MATH-1055" due-to="Sean Owen">
- Fixed some invalid links inside javadoc and added missing deprecated annotations.
- </action>
- <action dev="tn" type="add" issue="MATH-983">
- Added a graphical overview of available continuous distributions to the userguide.
- </action>
- <action dev="tn" type="add" issue="MATH-1051" due-to="Matt Adereth,devl">
- Added Kendall's tau correlation (KendallsCorrelation).
- </action>
- <action dev="tn" type="fix" issue="MATH-1051">
- "EigenDecomposition" may have failed to compute the decomposition for certain
- non-symmetric matrices. Port of the respective bugfix in Jama-1.0.3.
- </action>
- <action dev="erans" type="fix" issue="MATH-1047">
- Check for overflow in methods "pow" (class "o.a.c.m.util.ArithmeticUtils").
- </action>
- <action dev="erans" type="fix" issue="MATH-1045" due-to="Sean Owen">
- "EigenDecomposition": Using tolerance for detecting whether a matrix is singular.
- </action>
- <action dev="luc" type="add" issue="MATH-1036" due-to="Ajo Fod">
- Added SparseGradient to deal efficiently with first derivatives when the number
- of variables is very large but most computations depend only on a few of the
- variables.
- </action>
- <action dev="psteitz" type="update" issue="MATH-1039" due-to="Aleksei Dievskii">
- Added logDensity methods to AbstractReal/IntegerDistribution with naive default
- implementations and improved implementations for some current distributions.
- </action>
- <action dev="psteitz" type="add" issue="MATH-1038" due-to="Thorsten Sch�fer">
- Added ConfidenceInterval class and BinomialConfidenceInterval providing several
- estimators for confidence intervals for binomial probabilities.
- </action>
- <action dev="tn" type="fix" issue="MATH-1035" due-to="derphead">
- Simplified and improved performance of "ArithmeticUtils#addAndCheck(long, long)".
- </action>
- <action dev="tn" type="add" issue="MATH-1004" due-to="Ajo Fod">
- Added new methods to compute the inverse of a matrix to "DiagonalMatrix"
- and "MatrixUtils".
- </action>
- <action dev="tn" type="fix" issue="MATH-1029">
- The "BigFraction" constructor will throw a "FractionConversionException"
- also in case negative values are provided which exceed the allowed range
- (+/- Integer.MAX_VALUE).
- </action>
- <action dev="erans" type="add" issue="MATH-1041" due-to="Sean Owen">
- "Pair": added factory method and "toString" method.
- </action>
- <action dev="sebb" type="add" issue="MATH-1002">
- "AbstractUnivariateStatistic.test(...)" methods have uses outside subclasses;
- implementation moved to MathArrays.verifyValues(...).
- </action>
- <action dev="tn" type="fix" issue="MATH-1033" due-to="Yuan Qu">
- The "KalmanFilter" wrongly enforced a column dimension of 1 for
- the provided control and measurement noise matrix.
- </action>
- <action dev="tn" type="fix" issue="MATH-1037" due-to="Aleksei Dievskii">
- Fix a typo in the test class of "GeometricDistribution" and ensure that a meaningful
- tolerance value is used when comparing test results with expected values.
- </action>
- <action dev="psteitz" type="add" issue="MATH-1034" due-to="Thorsten Sch�fer">
- Added exact binomial test implementation.
- </action>
- <action dev="tn" type="add" issue="MATH-1018" due-to="Ajo Fod">
- Added overloaded constructors for subclasses of "RealDistribution" implementations
- which do not require an explicit "inverseCumulativeAccuracy". The default accuracy will
- be used instead.
- </action>
- <action dev="tn" type="add" issue="MATH-1001" due-to="sebb">
- Added overloaded methods for "Frequency#incrementValue(Comparable, long)" with
- int, long and char primitive arguments.
- </action>
- <action dev="tn" type="add" issue="MATH-1030" due-to="Thorsten Sch�fer">
- Added a section to the userguide for the new package o.a.c.m.ml with an
- overview of available clustering algorithms and a code example.
- </action>
- <action dev="tn" type="fix" issue="MATH-996" due-to="Tim Allison">
- Creating a "Fraction" or "BigFraction" object with a maxDenominator parameter
- does not throw a "FractionConversionException" anymore in case the value is
- very close to fraction.
- </action>
- <action dev="tn" type="add" issue="MATH-1028" due-to="Thorsten Sch�fer">
- Added new distance metric "EarthMoversDistance".
- </action>
- <action dev="tn" type="fix" issue="MATH-999" due-to="Ajo Fod">
- Improve performance of "DiagonalMatrix#preMultiply(RealVector)".
- </action>
- <action dev="psteitz" type="add" issue="MATH-1025">
- Added CombinatoricsUtils to the util package, moving binomial
- coefficients, factorials and Stirling numbers there and adding
- a combinations iterator.
- </action>
- <action dev="erans" type="add" issue="MATH-991">
- "PolynomialSplineFunction": added method "isValidPoint" that
- checks whether a point is within the interpolation range.
- </action>
- <action dev="erans" type="add" issue="MATH-989">
- "BicubicSplineInterpolatingFunction": added method "isValidPoint" that
- checks whether a point is within the interpolation range.
- </action>
- <action dev="erans" type="fix" issue="MATH-1021" due-to="Brian Bloniarz">
- Fixed overflow in "HypergeometricDistribution".
- </action>
- <action dev="erans" type="fix" issue="MATH-1020">
- Fixed "nextPermutation" method (in "o.a.c.m.random.RandomDataGenerator").
- This bug does not affect applications using a previous version of
- Commons Math.
- </action>
- <action dev="erans" type="fix" issue="MATH-1019">
- Buggy (private) method "shuffle" in "o.a.c.m.random.RandomDataGenerator"
- superseded by "MathArrays.shuffle" (cf. MATH-1010).
- </action>
- <action dev="erans" type="add" issue="MATH-1010">
- Utility to shuffle an array.
- </action>
- <action dev="erans" type="fix" issue="MATH-1012">
- Created "RandomGeneratorFactory" (package "o.a.c.m.random") to reduce
- code duplication in "RandomDataGenerator".
- </action>
- <action dev="erans" type="add" issue="MATH-1008">
- Created package ("o.a.c.m.fitting.leastsquares") for least-squares
- fitting, with implementations of "LevenbergMarquardtOptimizer" and
- "GaussNewtonOptimizer" adapted to a new ("fluent") API.
- </action>
- <action dev="erans" type="update" issue="MATH-1011">
- Improved implementation of "sample" method of "UniformIntegerDistribution".
- </action>
- <action dev="sebb" type="add" issue="MATH-1007">
- Add mode function to StatUtils class.
- </action>
- <action dev="psteitz" type="update" issue="MATH-1006">
- Enabled LaTeX expressions in javadoc and site docs via MathJax.
- </action>
- <action dev="sebb" type="add" issue="MATH-1000">
- Add mode function to Frequency class.
- </action>
- <action dev="erans" type="fix" issue="MATH-1005" due-to="Roman Werpachowski">
- Fixed "MathArrays.linearCombination" when array length is 1.
- </action>
- <action dev="erans" type="add" issue="MATH-997">
- Implemented Gauss-Hermite quadrature scheme (in package
- "o.a.c.m.analysis.integration.gauss").
- </action>
- <action dev="erans" type="update" issue="MATH-995">
- Documented limitation of "IterativeLegendreGaussIntegrator" (added
- warning about potential wrong usage).
- </action>
- <action dev="erans" type="fix" issue="MATH-993">
- In "GaussNewtonOptimizer", check for convergence before updating the
- parameters estimation for the next iteration.
- </action>
- <action dev="luc" type="add" issue="MATH-967" due-to="Oleksandr Kornieiev">
- Added midpoint integration method.
- </action>
- <action dev="luc" type="fix" issue="MATH-988" due-to="Andreas Huber">
- Fixed NullPointerException in 2D and 3D sub-line intersections.
- </action>
- <action dev="psteitz" type="update" issue="MATH-987" due-to="Ajo Fod">
- Added append method to SimpleRegression, making this class map/reducible.
- </action>
- <action dev="psteitz" type="update" issue="MATH-978" due-to="Ajo Fod">
- Added append method to StorelessCovariance, making this class map/reducible.
- </action>
- <action dev="tn" type="add" issue="MATH-851" due-to="Clemens Novak">
- Added method "MathArrays#convolve(double[], double[])" to compute the
- discrete, linear convolution of two sequences.
- </action>
- <action dev="tn" type="add" issue="MATH-977">
- Added low-discrepancy random generator "HaltonSequenceGenerator".
- </action>
- <action dev="tn" type="add" issue="MATH-826" due-to="Sam Halliday">
- Added low-discrepancy random generator "SobolSequenceGenerator".
- </action>
- <action dev="tn" type="add" issue="MATH-973" due-to="Mauro Tortonesi">
- Added "GeometricDistribution" to "o.a.c.m.distribution" package.
- </action>
- <action dev="tn" type="add" issue="MATH-968" due-to="Alex Gryzlov">
- Added "ParetoDistribution" to "o.a.c.m.distribution" package.
- </action>
- <action dev="tn" type="fix" issue="MATH-962">
- Added clarification to the javadoc of "VectorFormat" and derived classes
- in case "," is used as a separator.
- </action>
- <action dev="tn" type="add" issue="MATH-898">
- Added "FuzzyKMeansClusterer" to "o.a.c.m.ml.clustering" package.
- </action>
- <action dev="luc" type="fix" issue="MATH-965" >
- Fixed inconsistent dimensions preventing use of secondary states
- in ODE events.
- </action>
- </release>
- <release version="3.2" date="2013-04-06" description="
-This is a minor release: It combines bug fixes and new features.
- Changes to existing features were made in a backwards-compatible
- way such as to allow drop-in replacement of the v3.1[.1] JAR file.
-
-Most notable among the new features are: Framework for automatic
- differentiation, L�vy distribution, prime numbers, enumerated
- distributions, real field allowing to use several algorithms
- (solvers, linear algebra, 3D geometry) with different real-like
- classes (high accuracy or automatic differentiation), spherical
- coordinates with gradients and Hessians, reorganized clustering
- package with different distance implementations.
-
-The minimum version of the Java platform required to compile and use
- Commons Math is Java 5.
-
-Users are encouraged to upgrade to this version as this release not
- only includes bug fixes but also deprecates numerous classes and
- methods that will be deleted from the next major release (4.0).
-
- Caveat:
- 1. The implementation of the BOBYQA optimization algorithm is in alpha
- state (cf. MATH-621): Many code paths are untested, and we are looking
- for volunteers to improve the code readability, robustness and performance
- and to extend the unit tests suite.
- 2. A few methods in the FastMath class are in fact slower that their
- counterpart in either Math or StrictMath (cf. MATH-740 and MATH-901).
-">
- <action dev="luc" type="fix" issue="MATH-961" >
- Fixed wrong array dimensions in secondary equations handling in some cases.
- </action>
- <action dev="luc" type="fix" issue="MATH-960" >
- Fixed missing side effects of secondary equations on main state in
- Ordinary Differential Equations integration.
- </action>
- <action dev="luc" type="fix" issue="MATH-957" due-to="Evan Ward">
- Fixed inverse cumulative probability for uniform distribution.
- </action>
- <action dev="tn" type="add" issue="MATH-917,MATH-918,MATH-919,MATH-920" due-to="Reid Hochstedler">
- All contents of package "o.a.c.m.stat.clustering" refactored into
- new package "o.a.c.m.ml.clustering" and added support for additional
- distance measures in package "o.a.c.m.ml.distance": "CanberraDistance",
- "ChebyshevDistance", "EuclideanDistance" and "ManhattanDistance".
- </action>
- <action dev="tn" type="fix" issue="MATH-891">
- "SpearmansCorrelation" now works correctly in case of a provided
- "NaturalRanking" with a "NaNStrategy.REMOVED" strategy and the input
- data contains NaN values. From version 4.0 onwards this strategy will
- not be supported anymore.
- </action>
- <action dev="erans" type="update" issue="MATH-956">
- Replaced hard-coded numbers in "LevenbergMarquardtOptimizer".
- </action>
- <action dev="luc" type="update" issue="MATH-955" due-to="Evan Ward">
- Fixed loading of test file when path contains a space.
- </action>
- <action dev="luc" type="update" issue="MATH-954" due-to="Charles Cooper">
- Improved speed of FastMath.abs methods for all signatures, by removing branching.
- </action>
- <action dev="luc" type="update" issue="MATH-953" due-to="Charles Cooper">
- Improved speed of several FastMath methods.
- </action>
- <action dev="luc" type="fix" issue="MATH-934">
- Fixed Complex.reciprocal() for zero argument.
- </action>
- <action dev="luc" type="update" issue="MATH-951" due-to="Charles Cooper">
- Improved speed of FastMath copysign methods.
- </action>
- <action dev="erans" type="add" issue="MATH-817" due-to="Jared Becksfort">
- Added Multivariate Normal Mixture Model Fitting by Expectation Maximization.
- </action>
- <action dev="tn" type="fix" issue="MATH-862">
- AbstractRealMatrix will now check for rectangular input arrays in
- its copySubMatrix methods.
- </action>
- <action dev="erans" type="fix" issue="MATH-949">
- Increment iteration counter in optimization algorithms.
- </action>
- <action dev="luc" type="add" issue="MATH-811" >
- Added a way to trigger only increasing or decreasing events in ODE integration.
- </action>
- <action dev="luc" type="fix" issue="MATH-950" >
- Fixed missing update in ODE event handlers, when a RESET_STATE is triggered.
- </action>
- <action dev="psteitz" type="update" issue="MATH-671">
- Made EmpiricalDisribution smoothing kernel pluggable.
- </action>
- <action dev="psteitz" type="add" issue="MATH-946" due-to="Jared Becksfort">
- Added array-scaling methods to MathArrays.
- </action>
- <action dev="luc" type="update" issue="MATH-877" due-to="Peter Andrews">
- Allow direct use of SummaryStatistics in one-way ANOVA.
- </action>
- <action dev="luc" type="fix" issue="MATH-947" >
- Fixed infinite loop when NaN occurs in singular value decomposition.
- </action>
- <action dev="luc" type="add" issue="MATH-460" due-to="Andrew Waterman">
- Added the L�vy distribution.
- </action>
- <action dev="luc" type="update" >
- Normal distribution now uses a direct implementation of the
- inverse error function to compute inverse cumulative probability
- instead of relying on a numerical solver. This is much faster,
- more accurate and does not need convergence threshold.
- </action>
- <action dev="luc" type="add" issue="MATH-948" >
- Implementations for inverse error function and inverse complementary
- error functions have been added.
- </action>
- <action dev="luc" type="fix" issue="MATH-580" >
- Extended ranges for FastMath performance tests.
- </action>
- <action dev="luc" type="fix" issue="MATH-925" >
- Finalized implementation of diagonal matrix.
- </action>
- <action dev="luc" type="fix" issue="MATH-630" due-to="Christopher Nix" >
- Added rank revealing QR decomposition.
- </action>
- <action dev="luc" type="fix" issue="MATH-570" due-to="Arne Pl�se" >
- ArrayFieldVector can now be constructed from any FieldVector.
- </action>
- <action dev="luc" type="fix" issue="MATH-861" due-to="S�bastien Brisard" >
- Improved checking of null vector elements.
- </action>
- <action dev="luc" type="add" issue="MATH-845" due-to="S�bastien Riou" >
- Added utilities for prime numbers.
- </action>
- <action dev="luc" type="fix" issue="MATH-936" >
- Fixed generation of long random numbers between two bounds.
- </action>
- <action dev="luc" type="fix" issue="MATH-942" due-to="Piotr Wydrych" >
- Fixed creation of generic array.
- </action>
- <action dev="luc" type="add" issue="MATH-914" >
- Check bounds in multi-start vector optimizers.
- </action>
- <action dev="luc" type="add" issue="MATH-941" due-to="Piotr Wydrych" >
- Added discrete distributions.
- </action>
- <action dev="luc" type="fix" issue="MATH-940" due-to="Piotr Wydrych" >
- Fixed abstract test class naming that broke ant builds.
- </action>
- <action dev="luc" type="fix" issue="MATH-939" due-to="Piotr Wydrych" >
- Allow covariance to be computed for one-dimensional variables.
- </action>
- <action dev="luc" type="fix" issue="MATH-938" >
- Fixed accuracy of 3D Line.revert().
- </action>
- <action dev="luc" type="fix" issue="MATH-937" >
- Improved javadoc to explain how switching functions should
- behave across events in ODE events detection.
- </action>
- <action dev="luc" type="add" >
- Added Hermite interpolator for RealFieldElement instances.
- </action>
- <action dev="luc" type="add" >
- Added RealFieldElement interface to represent anything that is
- real number like, implemented by both Decimal64, Dfp and DerivativeStructure.
- </action>
- <action dev="luc" type="add" >
- Added partial derivatives computation for 3D vectors and rotations.
- </action>
- <action dev="luc" type="fix" issue="MATH-935" >
- Fixed DerivativeStructure.atan2 for special cases when both arguments are +/-0.
- </action>
- <action dev="luc" type="add" >
- Added accurate linear combination of DerivativeStructure instances,
- avoiding cancellation.
- </action>
- <action dev="erans" type="update" issue="MATH-933">
- Throw "MathUnsupportedOperationException" from optimizers that do
- not support constraints (previous behaviour was to silently ignore
- the "SimpleBounds" argument).
- </action>
- <action dev="luc" type="add" >
- Added conversion of gradients and Hessians from spherical to Cartesian
- coordinates in 3D.
- </action>
- <action dev="erans" type="update" issue="MATH-931" due-to="Sean Owen">
- Greater efficiency in "UnitSphereRandomVectorGenerator".
- </action>
- <action dev="tn" type="fix" issue="MATH-930">
- Improved class javadoc wrt convergence criteria and added
- additional constructors to override the default epsilon and cut-off
- values in class "SimplexSolver".
- </action>
- <action dev="erans" type="fix" issue="MATH-929" due-to="Piotr Wydrych">
- Fixed truncated value in "MultivariateNormalDistribution".
- </action>
- <action dev="erans" type="fix" issue="MATH-927" due-to="Dennis Hendriks">
- Made "BitStreamGenerator" implement the "Serializable" interface.
- </action>
- </release>
-
- <release version="3.1.1" date="2013-01-14" description="
-This is a point release: It fixes a bug that renders version 3.1 unusable
- in some situations (see details below).
-">
- <action dev="erans" type="fix" issue="MATH-924">
- Added a (minimal) "DiagonalMatrix" implementation, such that the
- case of a large number of uncorrelated observations is handled
- efficiently.
- </action>
- </release>
-
- <release version="3.1" date="2012-12-23" description="
-This is a minor release: It combines bug fixes and new features.
- Changes to existing features were made in a backwards-compatible
- way such as to allow drop-in replacement of the v3.0 JAR file.
-
- Most notable among the new features are: Framework for automatic
- differentiation, multivariate mixture model distribution, quaternions,
- Gauss integration framework, Hermite polynomial interpolation,
- eigenvalue decomposition of non-symmetric matrices, DBSCAN clustering.
- Most notable among the changes are: Greatly improved precision in
- the implementation of the Gamma and Beta special functions, optimizers
- API, deprecation of the sparse vector implementation.
-
- The minimal version of the Java platform required to compile and use
- Commons Math is Java 5.
- Users are encouraged to upgrade to this version as this release not
- only includes bug fixes but also deprecates numerous classes and
- methods that will be deleted from the next major release (4.0).
-
- Caveat:
- 1. The implementation of the BOBYQA optimization algorithm is in alpha
- state (cf. MATH-621): Many code paths are untested, and we are looking
- for volunteers to improve the code readability, robustness and performance
- and to extend the unit tests suite.
- 2. A few methods in the FastMath class are in fact slower that their
- counterpart in either Math or StrictMath (cf. MATH-740 and MATH-901).
-">
- <action dev="erans" type="add" issue="MATH-874">
- All contents of package "o.a.c.m.optimization" refactored into
- new packages "o.a.c.m.optimization" and "o.a.c.m.fitting".
- </action>
- <action dev="psteitz" type="update" issue="MATH-672">
- Added methods to EmpiricalDistribution to implement the RealDistribution
- interface.
- </action>
- <action dev="tn" type="add" issue="MATH-897" due-to="Reid Hochstedler">
- DBSCAN clustering algorithm (in package "o.a.c.m.stat.clustering").
- </action>
- <action dev="erans" type="add" issue="MATH-910">
- Added element-by-element addition, subtraction, multiplication and division
- (in class "o.a.c.m.util.MathArrays").
- </action>
- <action dev="erans" type="fix" issue="MATH-904" due-to="Jeff Hain">
- Fixed "pow" method in class "FastMath".
- </action>
- <action dev="erans" type="update" issue="MATH-902" due-to="Bruce A. Johnson">
- Created a "maximum number of iterations" stopping criterion in the
- convergence checkers (package "o.a.c.m.optimization") that allows the
- optimizers to return the "current best point" even if the convergence
- criteria are not met.
- </action>
- <action dev="erans" type="fix" issue="MATH-905" due-to="Jeff Hain">
- Fixed overflow in "sinh" and "cosh" methods in class "FastMath".
- </action>
- <action dev="celestin" type="update" issue="MATH-849">
- Accuracy improvements of Gamma.logGamma, and implementation of
- Gamma.gamma. Both new implementations are based on the NSWC
- Library of Mathematical Functions.
- </action>
- <action dev="erans" type="add" issue="MATH-902">
- New constructor in the custom checker classes (package
- "o.a.c.m.optimization") for passing the number of iterations
- after which the "convergence test" will return true.
- This allows an algorithm to return the best solution found (after
- the user-defined number of iterations) even if it does not meet the
- other convergence criteria.
- </action>
- <action dev="tn" type="update" issue="MATH-906" due-to="Patrick Meyer">
- Use "NaNStrategy#FAILED" as default strategy in "NaturalRanking".
- </action>
- <action dev="erans" type="add" issue="MATH-899">
- Added a new "SynchronizedRandomGenerator" that wraps another
- "RandomGenerator" with all methods being synchronized, thus
- rendering the code thread-safe (at some efficiency cost).
- </action>
- <action dev="tn" type="add" issue="MATH-893" due-to="Patrick Meyer">
- Add new "NaNStrategy": FAILED, used in "RankingAlgorithm" implementations.
- Any encountered input value that succeeds a "Double#isNaN" check, results in a
- "NotANumberException".
- </action>
- <action dev="tn" type="add" issue="MATH-892">
- Add new constructor to "SpearmansCorrelation" class which allows to specify the
- "RankingAlgorithm" to be used.
- </action>
- <action dev="luc" type="fix" issue="MATH-890">
- Fixed naming inconsistencies between Interval and IntervalsSet classes.
- </action>
- <action dev="luc" type="add" issue="MATH-889">
- Added a method to check points in the Interval class, with a tolerance for boundary.
- </action>
- <action dev="psteitz" type="add" issue="MATH-878" due-to="Radoslav Tsvetkov">
- Added G-test statistics.
- </action>
- <action dev="erans" type="add" issue="MATH-883">
- New "getSquareRoot" method in class "EigenDecomposition" (package
- "o.a.c.m.linear").
- </action>
- <action dev="erans" type="update" issue="MATH-884">
- Added "isSymmetric" and "checkSymmetric" in "MatrixUtils" (package
- "o.a.c.m.linear").
- </action>
- <action dev="psteitz" type="update" issue="MATH-885">
- Moved private array argument validation methods from ChiSquareTest to MathArrays.
- </action>
- <action dev="erans" type="add" issue="MATH-816" due-to="Jared Becksfort">
- New class for generic multivariate mixture model distributions.
- </action>
- <action dev="tn" type="fix" issue="MATH-759" due-to="sebb">
- Use getter/setter methods of super class for access to field "windowSize" in
- "ListUnivariateImpl".
- </action>
- <action dev="luc" type="fix" issue="MATH-880">
- Improved construction of polygons with an additional constructor, more robust numerically.
- </action>
- <action dev="tn" type="add" issue="MATH-474" due-to="Dan Checkoway">
- Added new methods "merge(Frequency)", "merge(Collection<Frequency>)",
- "incrementValue(Comparable<?>, long)" and "entrySetIterator()" to the "Frequency" class.
- </action>
- <action dev="tn" type="fix" issue="MATH-778" due-to="S�bastien Brisard">
- Allow unlimited input values for "Dfp#multiply(int)".
- </action>
- <action dev="luc" type="fix" issue="MATH-641" due-to="Curtis Jensen">
- Added distance to point to 2D Line and Segment.
- </action>
- <action dev="erans" type="fix" issue="MATH-783">
- "PowellOptimizer" (package "o.a.c.m.optimization.direct") uses
- "BrentOptimizer" as its internal line search optimizer. The fix
- forces the convergence criterion of "BrentOptimizer" to use
- function values (instead of domain values).
- </action>
- <action dev="erans" type="fix" issue="MATH-865,MATH-867,MATH-868" due-to="Nikolaus Hansen, Frank Hess">
- Numerical accuracy problems arose in "CMAESOptimizer" (in package
- "o.a.c.m.optimization.direct") when large finite boundaries were
- specified, because the interval of allowed values was mapped to
- [0, 1]. This mapping was not necessary and its removal allows
- finite and infinite boundaries to be used together.
- </action>
- <action dev="luc" type="fix" >
- Fixed some issues in nth root derivatives at 0.
- </action>
- <action dev="tn" type="fix" issue="MATH-848">
- Fixed transformation to a Schur matrix for certain input matrices.
- </action>
- <action dev="erans" type="add" issue="MATH-860">
- Added matrix "block inversion" (in "o.a.c.m.linear.MatrixUtils").
- </action>
- <action dev="erans" type="fix" issue="MATH-864" due-to="Frank Hess">
- "CMAESOptimizer": Solution was not constrained to lie within the
- provided boundaries.
- </action>
- <action dev="erans" type="add" issue="MATH-863" due-to="Julien Anxionnat">
- New "Quaternion" class (package "o.a.c.m.complex").
- </action>
- <action dev="erans" type="add" issue="MATH-866" due-to="Yannick Tanguy">
- Added method to test for floating-point numbers equality with a
- relative tolerance (class "o.a.c.m.util.Precision").
- </action>
- <action dev="tn" type="fix" issue="MATH-666">
- Deprecated "FieldVector#getData()" in favor of "toArray()".
- </action>
- <action dev="luc" type="fix" issue="MATH-789">
- Fixed an error in rectangular Cholesky decomposition.
- </action>
- <action dev="psteitz" type="update" issue="MATH-859">
- Clarified definition of isSupportXxxBoundInclusive in RealDistribution
- interface, made code consistent with the definition, and deprecated
- these methods, marking for removal in 4.0.
- </action>
- <action dev="erans" type="update" issue="MATH-841" due-to="Sebastien Riou">
- Performance improvement in computation of the greatest common divisor
- (in class "o.a.c.m.util.ArithmeticUtils").
- </action>
- <action dev="erans" type="fix" issue="MATH-855">
- Added a check so that the returned point will always be the best one.
- </action>
- <action dev="luc" type="add" >
- Added a NewtonRaphsonSolver that uses the new differentiation package
- to define the function to solve. This class is intended to replace the
- former NewtonSolver which is deprecated.
- </action>
- <action dev="psteitz" type="update" issue="MATH-850">
- Added RandomDataGenerator to replace RandomDataImpl and deprecated
- RandomData interface and RandomDataImpl class. Deprecated
- nextInversionDeviate methods from RandomDataImpl class. Ensured that
- all nextXxx methods in RandomDataImpl/RandomDataGenerator use the
- configured RandomGenerator.
- </action>
- <action dev="erans" type="fix" issue="MATH-844">
- Generate an exception for rare ill-conditioned cases in "HarmonicFitter"
- guessing procedure (package "o.a.c.m.optimization.fitting").
- </action>
- <action dev="erans" type="add" issue="MATH-815" due-to="Jared Becksfort">
- New interface for multivariate distributions.
- Added multivariate normal distribution.
- </action>
- <action dev="luc" type="add" >
- Added a utility method to compute Stirling numbers of the second kind.
- </action>
- <action dev="luc" type="add" >
- Added a new package dealing with differentials, for one or more free
- parameters and derivation order 1 or higher.
- </action>
- <action dev="tn" type="add" issue="MATH-777" due-to="Reid Hochstedler">
- Added additional crossover policies: "CycleCrossover", "NPointCrossover",
- "OrderedCrossover" and "UniformCrossover".
- </action>
- <action dev="tn" type="fix" issue="MATH-828">
- Improved numerical stability of "SimplexSolver" by introducing Bland's rule
- to prevent cycling and a cutoff threshold to zero out very small values.
- </action>
- <action dev="tn" type="fix" issue="MATH-836" due-to="Baste Nesse Buanes">
- Fixed overflow detection for negative values in constructor of class "Fraction".
- </action>
- <action dev="erans" type="fix" issue="MATH-835" due-to="Baste Nesse Buanes">
- Fixed overflow in method "percentageValue" in class "Fraction".
- </action>
- <action dev="erans" type="fix" issue="MATH-622">
- Raised (to 10) the default number of fractional digits to print out.
- </action>
- <action dev="erans" type="fix" issue="MATH-762">
- Removed duplicate code.
- </action>
- <action dev="tn" type="add" issue="MATH-831">
- Added a new "RealMatrixFormat" class for input/output of RealMatrix instances.
- Default formatter instances for commons-math and octave have been added to
- "MatrixUtils".
- </action>
- <action dev="erans" type="add" issue="MATH-827">
- New "IterativeLegendreGaussIntegrator" that performs the same automatic
- subdivision of the integration interval as "LegendreGaussIntegrator",
- but uses the classes from package "o.a.c.m.analysis.integration.gauss"
- to perform the Gauss integration on the sub-interval.
- Deprecated "LegendreGaussIntegrator".
- </action>
- <action dev="tn" type="fix" issue="MATH-578">
- Improve performance of quantile evaluation in "Percentile" class for cases
- with lots of equal values.
- </action>
- <action dev="erans" type="add" issue="MATH-797">
- New framework for Gauss integration schemes (in package
- "o.a.c.m.analysis.integration.gauss").
- Gauss-Legendre quadrature rules (of unlimited order) implemented in
- double precision, and high precision (using "BigDecimal").
- </action>
- <action dev="erans" type="add" issue="MATH-764,MATH-823">
- For all distribution classes (in package "o.a.c.m.distribution"), a new
- constructor takes a "RandomGenerator" parameter.
- The "RandomDataImpl" instance has been superseded by this RNG.
- All "sample()" methods have been modified to use this RNG instead of
- delegating to the methods in "RandomData".
- </action>
- <action dev="tn" type="add" issue="MATH-235">
- Added support for real asymmetric matrices to "EigenDecomposition".
- </action>
- <action dev="erans" type="add" issue="MATH-768">
- Re-instated methods to find all complex roots of a polynomial (class
- "LaguerreSolver" in package "o.a.c.m.analysis.solvers").
- </action>
- <action dev="erans" type="add" issue="MATH-810">
- Added accessors to the "Pair" class (package "o.a.c.m.util").
- </action>
- <action dev="tn" type="add" issue="MATH-822" due-to="Jared Becksfort">
- Added new constructors in "EigenDecomposition" and deprecated two constructors
- with unused parameters.
- </action>
- <action dev="erans" type="fix" issue="MATH-798">
- Added overridden method in "PolynomialFitter" (package
- "o.a.c.m.optimization.fitting") to limit the number of evaluations.
- </action>
- <action dev="celestin" type="add" issue="MATH-807">
- Added a new constructor to o.a.c.m.utils.IterationManager, allowing
- for the specification of a callback function in case the maximum
- number of iteration is reached.
- </action>
- <action dev="luc" type="add">
- A new HermiteInterpolator class allows interpolation of vector-valued
- functions using both values and derivatives of the function at sample
- points.
- </action>
- <action dev="erans" type="fix" issue="MATH-804">
- Parameterized "CurveFitter" class (package "o.a.c.m.optimization.fitting")
- with the type of the fitting function. Updated subclasses "PolynomialFitter",
- "HarmonicFitter", "GaussianFitter".
- </action>
- <action dev="luc" type="fix" issue="MATH-801">
- Fixed a problem when building rotations from two pairs of vectors. In very rare cases,
- due to numerical inaccuracies the computed quaternion was not normalized (some examples
- went as high as 1.0e8) and even after normalization, the quaternion was plain wrong.
- </action>
- <action dev="celestin" type="remove" issue="MATH-796">
- Removed unused fields LocalizedFormats.ALPHA and LocalizedFormats.BETA. This is
- an acceptable compatibility break, as these fields are only meant for internal use.
- </action>
- <action dev="tn" type="fix" issue="MATH-644" due-to="marzieh">
- Fix computation of upperCumulativeProbability in "HypergeometricDistribution" and
- cleanup of duplicate probability mass function.
- </action>
- <action dev="celestin" type="fix" issue="MATH-791">
- In GammaDistribution, deprecated getAlpha() and getBeta(). Replaced with
- getShape() and getScale(), respectively.
- </action>
- <action dev="luc" type="fix" issue="MATH-793" due-to="Sebb">
- Use inline computation for OrderedTuple hash code.
- </action>
- <action dev="tn" type="fix" issue="MATH-718" >
- Use modified Lentz-Thompson algorithm for continued fraction evaluation to avoid
- underflows.
- </action>
- <action dev="luc" type="fix" issue="MATH-780" >
- Fixed a wrong assumption on BSP tree attributes when boundary collapses to a too
- small polygon at a non-leaf node.
- </action>
- <action dev="luc" type="fix" issue="MATH-787" >
- Put serialization back for PointValuePair and PointVectorValuePair.
- </action>
- <action dev="tn" type="fix" issue="MATH-627" due-to="Arne Pl�se">
- Avoid superfluous null check when using iterators in RealVector and ArrayRealVector.
- </action>
- <action dev="tn" type="fix" issue="MATH-781" due-to="Scheiber Ern\u0151">
- Use epsilon instead of ulp in floating-point comparison when dropping columns after
- phase 1 in SimplexSolver.
- </action>
- <action dev="luc" type="fix" issue="MATH-721">
- Added a workaround for an OpenJDK issue on sparc solaris with too small constants.
- </action>
- <action dev="tn" type="fix" issue="MATH-779" due-to="Reid Hochstedler">
- Fixed ListPopulation#iterator to return an unmodifiable iterator.
- </action>
- <action dev="tn" type="fix" issue="MATH-775" due-to="Reid Hochstedler">
- Cleanup of ListPopulation to consistently enforce the population limit.
- </action>
- <action dev="tn" type="fix" issue="MATH-776" due-to="Reid Hochstedler">
- Use same range check in constructor for ElitisticListPopulation as in corresponding setter.
- </action>
- <action dev="tn" type="fix" issue="MATH-767" due-to="Dennis Hendriks">
- Fixed unbalanced use of code tags in javadoc of several classes.
- </action>
- <action dev="tn" type="add" issue="MATH-773" due-to="Reid Hochstedler">
- Added class FixedElapsedTime (new StoppingCondition for evolution of generations) to genetics package.
- </action>
- <action dev="celestin" type="add" issue="MATH-756">
- Added classes Decimal64 and Decimal64Field, which are wrapper classes around primitive doubles.
- These classes implement FieldElement and Field, respectively.
- </action>
- </release>
- <release version="3.0" date="2012-03-07" description="
-This is a major release: It combines bug fixes, new features and
-changes to existing features.
-
-Most notable among the new features are: Iterative solvers, Kalman filter,
-ISAAC RNG, Illinois and Pegasus root finders, enhanced ODE framework,
-refactored geometry package, Binary Space Partition trees.
-
-Most notable among the changes are: Exclusive use of unchecked exceptions,
-removal of interfaces for which a single implementation is assumed to exist,
-improved coding and API consistency across packages, performance (matrix
-product, FFT) and robustness (SVD).
+ <release version="1.0" date="TBD" description="
+This is the first release of Apache Commons Numbers.
-Because of the base package name change, this release can be used together
-with earlier versions of Commons Math.
-The minimal version of the Java platform required to compile and use
-Commons Math is Java 5.
-Users are encouraged to upgrade to this version as, in addition to new
-features, this release includes numerous bug fixes.
-Users of Commons Math 2.0-2 should recompile their code against the 3.0 JAR
-file and must adjust the import statements to use the appropriate
-org.apache.commons.math3 base package.
-Most of the compilation errors users will encounter after the switch will
-be due to moved or deleted classes/interfaces resulting from package
-reorganization.
-
-Caveat:
-1. The implementation of the BOBYQA optimization algorithm is in alpha state
-(cf. MATH-621): Many code paths are untested, and we are looking
-for volunteers to improve the code readability, robustness and performance
-and to extend the unit tests suite.
-2. A few methods in the FastMath class are in fact slower that their
-counterpart in either Math or StrictMath (cf. MATH-740).
+Apache Commons Numbers 1.0 contains
<TRUNCATED>
[24/31] commons-numbers git commit: Correct project info.
Posted by er...@apache.org.
Correct project info.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/3413c4a7
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/3413c4a7
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/3413c4a7
Branch: refs/heads/master
Commit: 3413c4a74169de85f7d5cc8fb23c8f70cb9c8db1
Parents: c7608e4
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Fri Jan 20 14:42:27 2017 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Fri Jan 20 14:42:27 2017 +0100
----------------------------------------------------------------------
src/site/xdoc/index.xml | 71 +++++++++++++-------------------------------
1 file changed, 21 insertions(+), 50 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/3413c4a7/src/site/xdoc/index.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/index.xml b/src/site/xdoc/index.xml
index 11c1a2b..4d48668 100644
--- a/src/site/xdoc/index.xml
+++ b/src/site/xdoc/index.xml
@@ -20,63 +20,34 @@
<document>
<properties>
- <title>Commons Math: The Apache Commons Mathematics Library</title>
+ <title>Apache Commons Numbers</title>
</properties>
<body>
- <section name="Commons Math: The Apache Commons Mathematics Library" href="summary">
+ <section name="Commons Numbers: Extended number types and utilities" href="summary">
<p>
- Commons Math is a library of lightweight, self-contained
- mathematics and statistics components addressing the most common
- problems not available in the Java programming language or Commons
- Lang.
- </p>
- <p>
- Guiding principles:
- <ol>
- <li>
- Real-world application use cases determine development
- priority.
- </li>
- <li>
- This package emphasizes small, easily integrated components
- rather than large libraries with complex dependencies and
- configurations.
- </li>
- <li>
- All algorithms are fully documented and follow generally
- accepted best practices.
- </li>
- <li>
- In situations where multiple standard algorithms exist, a
- Strategy pattern is used to support multiple
- implementations.
- </li>
- <li>
- Limited dependencies. No external dependencies beyond Commons
- components and the core Java platform (at least Java 1.3 up to
- version 1.2 of the library, at least Java 5 starting with version
- 2.0 of the library).
- </li>
- </ol>
+ Commons Numbers provides implementations of extended number types such as
+ <ul>
+ <li>complex</li>
+ <li>quaternion</li>
+ <li>fraction</li>
+ </ul>
</p>
</section>
- <section name="Download Math">
- <subsection name="Releases">
- <p>
- Download the
- <a href="http://commons.apache.org/math/download_math.cgi">
- Latest Release</a> of Commons Math.
- </p>
- </subsection>
- <!--
- <subsection name="No Nightly Builds">
- <p>
- There are no nightly builds for Apache Commons Math anymore.
- </p>
- </subsection>
- -->
+
+ <section name="Download Commons Numbers">
+ <subsection name="Releases">
+ <p>There is no offcial release yet. Come and join development work!</p>
+ <!--
+ <p>
+ Download the
+ <a href="http://commons.apache.org/numbers/download_numbers.cgi">
+ Latest Release</a> of Commons Numbers.
+ </p>
+ -->
+ </subsection>
+
</section>
</body>
</document>
[30/31] commons-numbers git commit: Module's custom description (to
be expanded).
Posted by er...@apache.org.
Module's custom description (to be expanded).
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/65a58afd
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/65a58afd
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/65a58afd
Branch: refs/heads/master
Commit: 65a58afd8e06d3193a2a03be6a64ec451418c54b
Parents: 0a3a673
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Fri Jan 20 15:38:01 2017 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Fri Jan 20 15:38:01 2017 +0100
----------------------------------------------------------------------
commons-numbers-core/src/site/site.xml | 35 ++++++++++++++++++++
commons-numbers-core/src/site/xdoc/index.xml | 40 +++++++++++++++++++++++
2 files changed, 75 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/65a58afd/commons-numbers-core/src/site/site.xml
----------------------------------------------------------------------
diff --git a/commons-numbers-core/src/site/site.xml b/commons-numbers-core/src/site/site.xml
new file mode 100644
index 0000000..7f34aa0
--- /dev/null
+++ b/commons-numbers-core/src/site/site.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project name="Numbers">
+ <bannerRight>
+ <name>Apache Commons Numbers</name>
+ <src>/images/commons_numbers.small.png</src>
+ <href>/index.html</href>
+ </bannerRight>
+
+ <body>
+ <menu name="Numbers Core">
+ <item name="Overview" href="index.html"/>
+ <item name="Latest API docs (development)"
+ href="apidocs/index.html"/>
+ <!--item name="Javadoc (1.0 release)"
+ href="http://commons.apache.org/rng/commons-numbers-core/javadocs/api-1.0/index.html"/-->
+ </menu>
+
+ </body>
+</project>
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/65a58afd/commons-numbers-core/src/site/xdoc/index.xml
----------------------------------------------------------------------
diff --git a/commons-numbers-core/src/site/xdoc/index.xml b/commons-numbers-core/src/site/xdoc/index.xml
new file mode 100644
index 0000000..99c1ea9
--- /dev/null
+++ b/commons-numbers-core/src/site/xdoc/index.xml
@@ -0,0 +1,40 @@
+<?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.
+ -->
+
+<document>
+
+ <properties>
+ <title>Commons Numbers Core</title>
+ </properties>
+
+ <body>
+
+ <section name="Apache Commons Numbers: Number types" href="summary">
+ <p>
+ Commons Numbers provides utilities such as complex numbers and fractions.
+ </p>
+
+ <p>
+ The "core" module contains basic utilities.
+ </p>
+ </section>
+
+ </body>
+
+</document>
[14/31] commons-numbers git commit: Multimodule project setup.
Posted by er...@apache.org.
Multimodule project setup.
Created "core", "complex" and "quaternion" modules.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/c4541327
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/c4541327
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/c4541327
Branch: refs/heads/master
Commit: c45413279a7e1eec230516ec1f8efd5456c6215e
Parents: a752ab8
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Wed Jan 18 14:22:45 2017 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Wed Jan 18 14:22:45 2017 +0100
----------------------------------------------------------------------
NOTICE.txt | 2 +-
README.md | 23 +-
commons-numbers-complex/LICENSE.txt | 201 +++
commons-numbers-complex/NOTICE.txt | 6 +
commons-numbers-complex/README.md | 98 ++
commons-numbers-complex/pom.xml | 61 +
.../apache/commons/numbers/complex/Complex.java | 1369 ++++++++++++++++
.../commons/numbers/complex/ComplexUtils.java | 1430 +++++++++++++++++
.../commons/numbers/complex/Precision.java | 128 ++
.../commons/numbers/complex/RootsOfUnity.java | 116 ++
.../commons/numbers/complex/package-info.java | 20 +
.../commons/numbers/complex/ComplexTest.java | 1477 ++++++++++++++++++
.../numbers/complex/ComplexUtilsTest.java | 475 ++++++
.../numbers/complex/RootsOfUnityTest.java | 84 +
.../commons/numbers/complex/TestUtils.java | 409 +++++
commons-numbers-core/LICENSE.txt | 201 +++
commons-numbers-core/NOTICE.txt | 6 +
commons-numbers-core/README.md | 98 ++
commons-numbers-core/pom.xml | 46 +
.../apache/commons/numbers/core/Precision.java | 598 +++++++
.../commons/numbers/core/PrecisionTest.java | 547 +++++++
.../apache/commons/numbers/core/TestUtils.java | 320 ++++
commons-numbers-quaternion/LICENSE.txt | 201 +++
commons-numbers-quaternion/NOTICE.txt | 6 +
commons-numbers-quaternion/README.md | 98 ++
commons-numbers-quaternion/pom.xml | 53 +
.../commons/numbers/quaternion/Quaternion.java | 455 ++++++
.../numbers/quaternion/package-info.java | 20 +
.../numbers/quaternion/QuaternionTest.java | 456 ++++++
pom.xml | 408 ++---
src/main/resources/checkstyle/checkstyle.xml | 202 +++
.../resources/checkstyle/license-header.txt | 16 +
src/main/resources/clirr/clirr-ignored.xml | 21 +
.../findbugs/findbugs-exclude-filter.xml | 28 +
src/main/resources/pmd/pmd-ruleset.xml | 57 +
35 files changed, 9530 insertions(+), 206 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/NOTICE.txt
----------------------------------------------------------------------
diff --git a/NOTICE.txt b/NOTICE.txt
index d22df2a..ea6ae07 100644
--- a/NOTICE.txt
+++ b/NOTICE.txt
@@ -1,4 +1,4 @@
-Apache Commons Math
+Apache Commons Numbers
Copyright 2001-2016 The Apache Software Foundation
This product includes software developed at
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 905ee17..e0754e0 100644
--- a/README.md
+++ b/README.md
@@ -40,33 +40,28 @@
| |
+======================================================================+
--->
-Apache Commons Complex
-======================
+Apache Commons Numbers
+===================
-[](https://travis-ci.org/apache/commons-complex)
-[](https://coveralls.io/github/apache/commons-complex?branch=master)
-[](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-complex/)
-[](http://www.apache.org/licenses/LICENSE-2.0.html)
-
-The Apache Commons Complex project provides self-contained components addressing the most common practical problems involving Java computing with complex numbers.
+The Apache Commons Numbers project provides number types and utilities.
Documentation
-------------
-More information can be found on the [homepage](https://commons.apache.org/proper/commons-complex).
-The [JavaDoc](https://commons.apache.org/proper/commons-complex/apidocs) can be browsed.
-Questions related to the usage of Apache Commons Math should be posted to the [user mailing list][ml].
+More information can be found on the [homepage](https://commons.apache.org/proper/commons-numbers).
+The [JavaDoc](https://commons.apache.org/proper/commons-numbers/javadocs/api-release) can be browsed.
+Questions related to the usage of Apache Commons Numbers should be posted to the [user mailing list][ml].
Where can I get the latest release?
-----------------------------------
-You can download source and binaries from our [download page](https://commons.apache.org/proper/commons-complex/download_complex.cgi).
+You can download source and binaries from our [download page](https://commons.apache.org/proper/commons-numbers/download_numbers.cgi).
Alternatively you can pull it from the central Maven repositories:
```xml
<dependency>
<groupId>org.apache.commons</groupId>
- <artifactId>commons-complex</artifactId>
+ <artifactId>commons-numbers-parent</artifactId>
<version>1.0</version>
</dependency>
```
@@ -90,7 +85,7 @@ Code is under the [Apache Licence v2](https://www.apache.org/licenses/LICENSE-2.
Donations
---------
-You like Apache Commons Math? Then [donate back to the ASF](https://www.apache.org/foundation/contributing.html) to support the development.
+You like Apache Commons Numbers? Then [donate back to the ASF](https://www.apache.org/foundation/contributing.html) to support the development.
Additional Resources
--------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-complex/LICENSE.txt
----------------------------------------------------------------------
diff --git a/commons-numbers-complex/LICENSE.txt b/commons-numbers-complex/LICENSE.txt
new file mode 100644
index 0000000..261eeb9
--- /dev/null
+++ b/commons-numbers-complex/LICENSE.txt
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-complex/NOTICE.txt
----------------------------------------------------------------------
diff --git a/commons-numbers-complex/NOTICE.txt b/commons-numbers-complex/NOTICE.txt
new file mode 100644
index 0000000..ea6ae07
--- /dev/null
+++ b/commons-numbers-complex/NOTICE.txt
@@ -0,0 +1,6 @@
+Apache Commons Numbers
+Copyright 2001-2016 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-complex/README.md
----------------------------------------------------------------------
diff --git a/commons-numbers-complex/README.md b/commons-numbers-complex/README.md
new file mode 100644
index 0000000..582b7ce
--- /dev/null
+++ b/commons-numbers-complex/README.md
@@ -0,0 +1,98 @@
+<!---
+ 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.
+-->
+<!---
+ +======================================================================+
+ |**** ****|
+ |**** THIS FILE IS GENERATED BY THE COMMONS BUILD PLUGIN ****|
+ |**** DO NOT EDIT DIRECTLY ****|
+ |**** ****|
+ +======================================================================+
+ | TEMPLATE FILE: readme-md-template.md |
+ | commons-build-plugin/trunk/src/main/resources/commons-xdoc-templates |
+ +======================================================================+
+ | |
+ | 1) Re-generate using: mvn commons:readme-md |
+ | |
+ | 2) Set the following properties in the component's pom: |
+ | - commons.componentid (required, alphabetic, lower case) |
+ | - commons.release.version (required) |
+ | |
+ | 3) Example Properties |
+ | |
+ | <properties> |
+ | <commons.componentid>math</commons.componentid> |
+ | <commons.release.version>1.2</commons.release.version> |
+ | </properties> |
+ | |
+ +======================================================================+
+--->
+Apache Commons Numbers Complex
+===================
+
+Complex numbers.
+
+Documentation
+-------------
+
+More information can be found on the [homepage](https://commons.apache.org/proper/commons-numbers).
+The [JavaDoc](https://commons.apache.org/proper/commons-numbers/javadocs/api-release) can be browsed.
+Questions related to the usage of Apache Commons Numbers Complex should be posted to the [user mailing list][ml].
+
+Where can I get the latest release?
+-----------------------------------
+You can download source and binaries from our [download page](https://commons.apache.org/proper/commons-numbers/download_numbers.cgi).
+
+Alternatively you can pull it from the central Maven repositories:
+
+```xml
+<dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-complex</artifactId>
+ <version>1.0</version>
+</dependency>
+```
+
+Contributing
+------------
+
+We accept PRs via github. The [developer mailing list][ml] is the main channel of communication for contributors.
+There are some guidelines which will make applying PRs easier for us:
++ No tabs! Please use spaces for indentation.
++ Respect the code style.
++ Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change.
++ Provide JUnit tests for your changes and make sure your changes don't break any existing tests by running ```mvn clean test```.
+
+If you plan to contribute on a regular basis, please consider filing a [contributor license agreement](https://www.apache.org/licenses/#clas).
+You can learn more about contributing via GitHub in our [contribution guidelines](CONTRIBUTING.md).
+
+License
+-------
+Code is under the [Apache Licence v2](https://www.apache.org/licenses/LICENSE-2.0.txt).
+
+Donations
+---------
+You like Apache Commons Numbers Complex? Then [donate back to the ASF](https://www.apache.org/foundation/contributing.html) to support the development.
+
+Additional Resources
+--------------------
+
++ [Apache Commons Homepage](https://commons.apache.org/)
++ [Apache Bugtracker (JIRA)](https://issues.apache.org/jira/)
++ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons)
++ #apachecommons IRC channel on freenode.org
+
+[ml]:https://commons.apache.org/mail-lists.html
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-complex/pom.xml
----------------------------------------------------------------------
diff --git a/commons-numbers-complex/pom.xml b/commons-numbers-complex/pom.xml
new file mode 100644
index 0000000..735348f
--- /dev/null
+++ b/commons-numbers-complex/pom.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-parent</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-complex</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <name>Apache Commons Numbers Complex</name>
+
+ <description>Complex numbers.</description>
+
+ <properties>
+ <!-- This value must reflect the current name of the base package. -->
+ <commons.osgi.symbolicName>org.apache.commons.numbers.complex</commons.osgi.symbolicName>
+ <!-- OSGi -->
+ <commons.osgi.export>org.apache.commons.numbers.complex</commons.osgi.export>
+ <!-- Workaround to avoid duplicating config files. -->
+ <numbers.parent.dir>${basedir}/..</numbers.parent.dir>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-core</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-math3</artifactId>
+ <version>3.6.1</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
----------------------------------------------------------------------
diff --git a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
new file mode 100644
index 0000000..9581f81
--- /dev/null
+++ b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
@@ -0,0 +1,1369 @@
+/*
+ * 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.
+ */
+
+package org.apache.commons.numbers.complex;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Representation of a Complex number, i.e. a number which has both a
+ * real and imaginary part.
+ * <p>
+ * Implementations of arithmetic operations handle {@code NaN} and
+ * infinite values according to the rules for {@link java.lang.Double}, i.e.
+ * {@link #equals} is an equivalence relation for all instances that have
+ * a {@code NaN} in either real or imaginary part, e.g. the following are
+ * considered equal:
+ * <ul>
+ * <li>{@code 1 + NaNi}</li>
+ * <li>{@code NaN + i}</li>
+ * <li>{@code NaN + NaNi}</li>
+ * </ul><p>
+ * Note that this contradicts the IEEE-754 standard for floating
+ * point numbers (according to which the test {@code x == x} must fail if
+ * {@code x} is {@code NaN}). The method
+ * {@link org.apache.commons.numbers.complex.util.Precision#equals(double,double,int)
+ * equals for primitive double} in {@link org.apache.commons.numbers.complex.util.Precision}
+ * conforms with IEEE-754 while this class conforms with the standard behavior
+ * for Java object types.</p>
+ *
+ */
+public class Complex implements Serializable {
+ /** The square root of -1. A number representing "0.0 + 1.0i" */
+ public static final Complex I = new Complex(0.0, 1.0);
+ // CHECKSTYLE: stop ConstantName
+ /** A complex number representing "NaN + NaNi" */
+ public static final Complex NaN = new Complex(Double.NaN, Double.NaN);
+ // CHECKSTYLE: resume ConstantName
+ /** A complex number representing "+INF + INFi" */
+ public static final Complex INF = new Complex(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
+ /** A complex number representing "1.0 + 0.0i" */
+ public static final Complex ONE = new Complex(1.0, 0.0);
+ /** A complex number representing "0.0 + 0.0i" */
+ public static final Complex ZERO = new Complex(0.0, 0.0);
+
+ /** Serializable version identifier */
+ private static final long serialVersionUID = -6195664516687396620L;
+
+ /** The imaginary part. */
+ private final double imaginary;
+ /** The real part. */
+ private final double real;
+ /** Record whether this complex number is equal to NaN. */
+ private final transient boolean isNaN;
+ /** Record whether this complex number is infinite. */
+ private final transient boolean isInfinite;
+
+ /**
+ * Create a complex number given only the real part.
+ *
+ * @param real Real part.
+ */
+ public Complex(double real) {
+ this(real, 0.0);
+ }
+
+ /**
+ * Create a complex number given the real and imaginary parts.
+ *
+ * @param real Real part.
+ * @param imaginary Imaginary part.
+ */
+ public Complex(double real, double imaginary) {
+ this.real = real;
+ this.imaginary = imaginary;
+
+ isNaN = Double.isNaN(real) || Double.isNaN(imaginary);
+ isInfinite = !isNaN &&
+ (Double.isInfinite(real) || Double.isInfinite(imaginary));
+ }
+
+ /**
+ * Return the absolute value of this complex number.
+ * Returns {@code NaN} if either real or imaginary part is {@code NaN}
+ * and {@code Double.POSITIVE_INFINITY} if neither part is {@code NaN},
+ * but at least one part is infinite.
+ *
+ * @return the absolute value.
+ */
+ public double abs() {
+ if (isNaN) {
+ return Double.NaN;
+ }
+ if (isInfinite()) {
+ return Double.POSITIVE_INFINITY;
+ }
+ if (Math.abs(real) < Math.abs(imaginary)) {
+ if (imaginary == 0.0) {
+ return Math.abs(real);
+ }
+ double q = real / imaginary;
+ return Math.abs(imaginary) * Math.sqrt(1 + q * q);
+ } else {
+ if (real == 0.0) {
+ return Math.abs(imaginary);
+ }
+ double q = imaginary / real;
+ return Math.abs(real) * Math.sqrt(1 + q * q);
+ }
+ }
+
+ /**
+ * Returns a {@code Complex} whose value is
+ * {@code (this + addend)}.
+ * Uses the definitional formula
+ * <p>
+ * {@code (a + bi) + (c + di) = (a+c) + (b+d)i}
+ * </p>
+ * If either {@code this} or {@code addend} has a {@code NaN} value in
+ * either part, {@link #NaN} is returned; otherwise {@code Infinite}
+ * and {@code NaN} values are returned in the parts of the result
+ * according to the rules for {@link java.lang.Double} arithmetic.
+ *
+ * @param addend Value to be added to this {@code Complex}.
+ * @return {@code this + addend}.
+ */
+ public Complex add(Complex addend) {
+ checkNotNull(addend);
+ if (isNaN || addend.isNaN) {
+ return NaN;
+ }
+
+ return createComplex(real + addend.getReal(),
+ imaginary + addend.getImaginary());
+ }
+
+ /**
+ * Returns a {@code Complex} whose value is {@code (this + addend)},
+ * with {@code addend} interpreted as a real number.
+ *
+ * @param addend Value to be added to this {@code Complex}.
+ * @return {@code this + addend}.
+ * @see #add(Complex)
+ */
+ public Complex add(double addend) {
+ if (isNaN || Double.isNaN(addend)) {
+ return NaN;
+ }
+
+ return createComplex(real + addend, imaginary);
+ }
+
+ /**
+ * Returns the conjugate of this complex number.
+ * The conjugate of {@code a + bi} is {@code a - bi}.
+ * <p>
+ * {@link #NaN} is returned if either the real or imaginary
+ * part of this Complex number equals {@code Double.NaN}.
+ * </p><p>
+ * If the imaginary part is infinite, and the real part is not
+ * {@code NaN}, the returned value has infinite imaginary part
+ * of the opposite sign, e.g. the conjugate of
+ * {@code 1 + POSITIVE_INFINITY i} is {@code 1 - NEGATIVE_INFINITY i}.
+ * </p>
+ * @return the conjugate of this Complex object.
+ */
+ public Complex conjugate() {
+ if (isNaN) {
+ return NaN;
+ }
+
+ return createComplex(real, -imaginary);
+ }
+
+ /**
+ * Returns a {@code Complex} whose value is
+ * {@code (this / divisor)}.
+ * Implements the definitional formula
+ * <pre>
+ * <code>
+ * a + bi ac + bd + (bc - ad)i
+ * ----------- = -------------------------
+ * c + di c<sup>2</sup> + d<sup>2</sup>
+ * </code>
+ * </pre>
+ * but uses
+ * <a href="http://doi.acm.org/10.1145/1039813.1039814">
+ * prescaling of operands</a> to limit the effects of overflows and
+ * underflows in the computation.
+ * <p>
+ * {@code Infinite} and {@code NaN} values are handled according to the
+ * following rules, applied in the order presented:
+ * <ul>
+ * <li>If either {@code this} or {@code divisor} has a {@code NaN} value
+ * in either part, {@link #NaN} is returned.
+ * </li>
+ * <li>If {@code divisor} equals {@link #ZERO}, {@link #NaN} is returned.
+ * </li>
+ * <li>If {@code this} and {@code divisor} are both infinite,
+ * {@link #NaN} is returned.
+ * </li>
+ * <li>If {@code this} is finite (i.e., has no {@code Infinite} or
+ * {@code NaN} parts) and {@code divisor} is infinite (one or both parts
+ * infinite), {@link #ZERO} is returned.
+ * </li>
+ * <li>If {@code this} is infinite and {@code divisor} is finite,
+ * {@code NaN} values are returned in the parts of the result if the
+ * {@link java.lang.Double} rules applied to the definitional formula
+ * force {@code NaN} results.
+ * </li>
+ * </ul>
+ *
+ * @param divisor Value by which this {@code Complex} is to be divided.
+ * @return {@code this / divisor}.
+ */
+ public Complex divide(Complex divisor) {
+ checkNotNull(divisor);
+ if (isNaN || divisor.isNaN) {
+ return NaN;
+ }
+
+ final double c = divisor.getReal();
+ final double d = divisor.getImaginary();
+ if (c == 0.0 && d == 0.0) {
+ return NaN;
+ }
+
+ if (divisor.isInfinite() && !isInfinite()) {
+ return ZERO;
+ }
+
+ if (Math.abs(c) < Math.abs(d)) {
+ double q = c / d;
+ double denominator = c * q + d;
+ return createComplex((real * q + imaginary) / denominator,
+ (imaginary * q - real) / denominator);
+ } else {
+ double q = d / c;
+ double denominator = d * q + c;
+ return createComplex((imaginary * q + real) / denominator,
+ (imaginary - real * q) / denominator);
+ }
+ }
+
+ /**
+ * Returns a {@code Complex} whose value is {@code (this / divisor)},
+ * with {@code divisor} interpreted as a real number.
+ *
+ * @param divisor Value by which this {@code Complex} is to be divided.
+ * @return {@code this / divisor}.
+ * @see #divide(Complex)
+ */
+ public Complex divide(double divisor) {
+ if (isNaN || Double.isNaN(divisor)) {
+ return NaN;
+ }
+ if (divisor == 0d) {
+ return NaN;
+ }
+ if (Double.isInfinite(divisor)) {
+ return !isInfinite() ? ZERO : NaN;
+ }
+ return createComplex(real / divisor,
+ imaginary / divisor);
+ }
+
+ /** {@inheritDoc} */
+ public Complex reciprocal() {
+ if (isNaN) {
+ return NaN;
+ }
+
+ if (real == 0.0 && imaginary == 0.0) {
+ return INF;
+ }
+
+ if (isInfinite) {
+ return ZERO;
+ }
+
+ if (Math.abs(real) < Math.abs(imaginary)) {
+ double q = real / imaginary;
+ double scale = 1. / (real * q + imaginary);
+ return createComplex(scale * q, -scale);
+ } else {
+ double q = imaginary / real;
+ double scale = 1. / (imaginary * q + real);
+ return createComplex(scale, -scale * q);
+ }
+ }
+
+ /**
+ * Test for equality with another object.
+ * If both the real and imaginary parts of two complex numbers
+ * are exactly the same, and neither is {@code Double.NaN}, the two
+ * Complex objects are considered to be equal.
+ * The behavior is the same as for JDK's {@link Double#equals(Object)
+ * Double}:
+ * <ul>
+ * <li>All {@code NaN} values are considered to be equal,
+ * i.e, if either (or both) real and imaginary parts of the complex
+ * number are equal to {@code Double.NaN}, the complex number is equal
+ * to {@code NaN}.
+ * </li>
+ * <li>
+ * Instances constructed with different representations of zero (i.e.
+ * either "0" or "-0") are <em>not</em> considered to be equal.
+ * </li>
+ * </ul>
+ *
+ * @param other Object to test for equality with this instance.
+ * @return {@code true} if the objects are equal, {@code false} if object
+ * is {@code null}, not an instance of {@code Complex}, or not equal to
+ * this instance.
+ */
+ @Override
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (other instanceof Complex){
+ Complex c = (Complex) other;
+ if (c.isNaN) {
+ return isNaN;
+ } else {
+ return equals(real, c.real) &&
+ equals(imaginary, c.imaginary);
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Test for the floating-point equality between Complex objects.
+ * It returns {@code true} if both arguments are equal or within the
+ * range of allowed error (inclusive).
+ *
+ * @param x First value (cannot be {@code null}).
+ * @param y Second value (cannot be {@code null}).
+ * @param maxUlps {@code (maxUlps - 1)} is the number of floating point
+ * values between the real (resp. imaginary) parts of {@code x} and
+ * {@code y}.
+ * @return {@code true} if there are fewer than {@code maxUlps} floating
+ * point values between the real (resp. imaginary) parts of {@code x}
+ * and {@code y}.
+ *
+ * @see Precision#equals(double,double,int)
+ * @since 3.3
+ */
+ public static boolean equals(Complex x, Complex y, int maxUlps) {
+ return Precision.equals(x.real, y.real, maxUlps) &&
+ Precision.equals(x.imaginary, y.imaginary, maxUlps);
+ }
+
+ /**
+ * Returns {@code true} iff the values are equal as defined by
+ * {@link #equals(Complex,Complex,int) equals(x, y, 1)}.
+ *
+ * @param x First value (cannot be {@code null}).
+ * @param y Second value (cannot be {@code null}).
+ * @return {@code true} if the values are equal.
+ *
+ * @since 3.3
+ */
+ public static boolean equals(Complex x, Complex y) {
+ return equals(x, y, 1);
+ }
+
+ /**
+ * Returns {@code true} if, both for the real part and for the imaginary
+ * part, there is no double value strictly between the arguments or the
+ * difference between them is within the range of allowed error
+ * (inclusive). Returns {@code false} if either of the arguments is NaN.
+ *
+ * @param x First value (cannot be {@code null}).
+ * @param y Second value (cannot be {@code null}).
+ * @param eps Amount of allowed absolute error.
+ * @return {@code true} if the values are two adjacent floating point
+ * numbers or they are within range of each other.
+ *
+ * @see Precision#equals(double,double,double)
+ * @since 3.3
+ */
+ public static boolean equals(Complex x, Complex y, double eps) {
+ return Precision.equals(x.real, y.real, eps) &&
+ Precision.equals(x.imaginary, y.imaginary, eps);
+ }
+
+ /**
+ * Returns {@code true} if, both for the real part and for the imaginary
+ * part, there is no double value strictly between the arguments or the
+ * relative difference between them is smaller or equal to the given
+ * tolerance. Returns {@code false} if either of the arguments is NaN.
+ *
+ * @param x First value (cannot be {@code null}).
+ * @param y Second value (cannot be {@code null}).
+ * @param eps Amount of allowed relative error.
+ * @return {@code true} if the values are two adjacent floating point
+ * numbers or they are within range of each other.
+ *
+ * @see Precision#equalsWithRelativeTolerance(double,double,double)
+ * @since 3.3
+ */
+ public static boolean equalsWithRelativeTolerance(Complex x, Complex y,
+ double eps) {
+ return Precision.equalsWithRelativeTolerance(x.real, y.real, eps) &&
+ Precision.equalsWithRelativeTolerance(x.imaginary, y.imaginary, eps);
+ }
+
+ /**
+ * Get a hashCode for the complex number.
+ * Any {@code Double.NaN} value in real or imaginary part produces
+ * the same hash code {@code 7}.
+ *
+ * @return a hash code value for this object.
+ */
+ @Override
+ public int hashCode() {
+ if (isNaN) {
+ return 7;
+ }
+ return 37 * (17 * hash(imaginary) +
+ hash(real));
+ }
+
+ /**
+ * Access the imaginary part.
+ *
+ * @return the imaginary part.
+ */
+ public double getImaginary() {
+ return imaginary;
+ }
+
+ /**
+ * Access the real part.
+ *
+ * @return the real part.
+ */
+ public double getReal() {
+ return real;
+ }
+
+ /**
+ * Checks whether either or both parts of this complex number is
+ * {@code NaN}.
+ *
+ * @return true if either or both parts of this complex number is
+ * {@code NaN}; false otherwise.
+ */
+ public boolean isNaN() {
+ return isNaN;
+ }
+
+ /**
+ * Checks whether either the real or imaginary part of this complex number
+ * takes an infinite value (either {@code Double.POSITIVE_INFINITY} or
+ * {@code Double.NEGATIVE_INFINITY}) and neither part
+ * is {@code NaN}.
+ *
+ * @return true if one or both parts of this complex number are infinite
+ * and neither part is {@code NaN}.
+ */
+ public boolean isInfinite() {
+ return isInfinite;
+ }
+
+ /**
+ * Returns a {@code Complex} whose value is {@code this * factor}.
+ * Implements preliminary checks for {@code NaN} and infinity followed by
+ * the definitional formula:
+ * <p>
+ * {@code (a + bi)(c + di) = (ac - bd) + (ad + bc)i}
+ * </p>
+ * Returns {@link #NaN} if either {@code this} or {@code factor} has one or
+ * more {@code NaN} parts.
+ * <p>
+ * Returns {@link #INF} if neither {@code this} nor {@code factor} has one
+ * or more {@code NaN} parts and if either {@code this} or {@code factor}
+ * has one or more infinite parts (same result is returned regardless of
+ * the sign of the components).
+ * </p><p>
+ * Returns finite values in components of the result per the definitional
+ * formula in all remaining cases.</p>
+ *
+ * @param factor value to be multiplied by this {@code Complex}.
+ * @return {@code this * factor}.
+ */
+ public Complex multiply(Complex factor) {
+ checkNotNull(factor);
+ if (isNaN || factor.isNaN) {
+ return NaN;
+ }
+ if (Double.isInfinite(real) ||
+ Double.isInfinite(imaginary) ||
+ Double.isInfinite(factor.real) ||
+ Double.isInfinite(factor.imaginary)) {
+ // we don't use isInfinite() to avoid testing for NaN again
+ return INF;
+ }
+ return createComplex(real * factor.real - imaginary * factor.imaginary,
+ real * factor.imaginary + imaginary * factor.real);
+ }
+
+ /**
+ * Returns a {@code Complex} whose value is {@code this * factor}, with {@code factor}
+ * interpreted as a integer number.
+ *
+ * @param factor value to be multiplied by this {@code Complex}.
+ * @return {@code this * factor}.
+ * @see #multiply(Complex)
+ */
+ public Complex multiply(final int factor) {
+ if (isNaN) {
+ return NaN;
+ }
+ if (Double.isInfinite(real) ||
+ Double.isInfinite(imaginary)) {
+ return INF;
+ }
+ return createComplex(real * factor, imaginary * factor);
+ }
+
+ /**
+ * Returns a {@code Complex} whose value is {@code this * factor}, with {@code factor}
+ * interpreted as a real number.
+ *
+ * @param factor value to be multiplied by this {@code Complex}.
+ * @return {@code this * factor}.
+ * @see #multiply(Complex)
+ */
+ public Complex multiply(double factor) {
+ if (isNaN || Double.isNaN(factor)) {
+ return NaN;
+ }
+ if (Double.isInfinite(real) ||
+ Double.isInfinite(imaginary) ||
+ Double.isInfinite(factor)) {
+ // we don't use isInfinite() to avoid testing for NaN again
+ return INF;
+ }
+ return createComplex(real * factor, imaginary * factor);
+ }
+
+ /**
+ * Returns a {@code Complex} whose value is {@code (-this)}.
+ * Returns {@code NaN} if either real or imaginary
+ * part of this Complex number is {@code Double.NaN}.
+ *
+ * @return {@code -this}.
+ */
+ public Complex negate() {
+ if (isNaN) {
+ return NaN;
+ }
+
+ return createComplex(-real, -imaginary);
+ }
+
+ /**
+ * Returns a {@code Complex} whose value is
+ * {@code (this - subtrahend)}.
+ * Uses the definitional formula
+ * <p>
+ * {@code (a + bi) - (c + di) = (a-c) + (b-d)i}
+ * </p>
+ * If either {@code this} or {@code subtrahend} has a {@code NaN]} value in either part,
+ * {@link #NaN} is returned; otherwise infinite and {@code NaN} values are
+ * returned in the parts of the result according to the rules for
+ * {@link java.lang.Double} arithmetic.
+ *
+ * @param subtrahend value to be subtracted from this {@code Complex}.
+ * @return {@code this - subtrahend}.
+ */
+ public Complex subtract(Complex subtrahend) {
+ checkNotNull(subtrahend);
+ if (isNaN || subtrahend.isNaN) {
+ return NaN;
+ }
+
+ return createComplex(real - subtrahend.getReal(),
+ imaginary - subtrahend.getImaginary());
+ }
+
+ /**
+ * Returns a {@code Complex} whose value is
+ * {@code (this - subtrahend)}.
+ *
+ * @param subtrahend value to be subtracted from this {@code Complex}.
+ * @return {@code this - subtrahend}.
+ * @see #subtract(Complex)
+ */
+ public Complex subtract(double subtrahend) {
+ if (isNaN || Double.isNaN(subtrahend)) {
+ return NaN;
+ }
+ return createComplex(real - subtrahend, imaginary);
+ }
+
+ /**
+ * Compute the
+ * <a href="http://mathworld.wolfram.com/InverseCosine.html" TARGET="_top">
+ * inverse cosine</a> of this complex number.
+ * Implements the formula:
+ * <p>
+ * {@code acos(z) = -i (log(z + i (sqrt(1 - z<sup>2</sup>))))}
+ * </p>
+ * Returns {@link Complex#NaN} if either real or imaginary part of the
+ * input argument is {@code NaN} or infinite.
+ *
+ * @return the inverse cosine of this complex number.
+ * @since 1.2
+ */
+ public Complex acos() {
+ if (isNaN) {
+ return NaN;
+ }
+
+ return this.add(this.sqrt1z().multiply(I)).log().multiply(I.negate());
+ }
+
+ /**
+ * Compute the
+ * <a href="http://mathworld.wolfram.com/InverseSine.html" TARGET="_top">
+ * inverse sine</a> of this complex number.
+ * Implements the formula:
+ * <p>
+ * {@code asin(z) = -i (log(sqrt(1 - z<sup>2</sup>) + iz))}
+ * </p><p>
+ * Returns {@link Complex#NaN} if either real or imaginary part of the
+ * input argument is {@code NaN} or infinite.</p>
+ *
+ * @return the inverse sine of this complex number.
+ * @since 1.2
+ */
+ public Complex asin() {
+ if (isNaN) {
+ return NaN;
+ }
+
+ return sqrt1z().add(this.multiply(I)).log().multiply(I.negate());
+ }
+
+ /**
+ * Compute the
+ * <a href="http://mathworld.wolfram.com/InverseTangent.html" TARGET="_top">
+ * inverse tangent</a> of this complex number.
+ * Implements the formula:
+ * <p>
+ * {@code atan(z) = (i/2) log((i + z)/(i - z))}
+ * </p><p>
+ * Returns {@link Complex#NaN} if either real or imaginary part of the
+ * input argument is {@code NaN} or infinite.</p>
+ *
+ * @return the inverse tangent of this complex number
+ * @since 1.2
+ */
+ public Complex atan() {
+ if (isNaN) {
+ return NaN;
+ }
+
+ return this.add(I).divide(I.subtract(this)).log()
+ .multiply(I.divide(createComplex(2.0, 0.0)));
+ }
+
+ /**
+ * Compute the
+ * <a href="http://mathworld.wolfram.com/Cosine.html" TARGET="_top">
+ * cosine</a> of this complex number.
+ * Implements the formula:
+ * <p>
+ * {@code cos(a + bi) = cos(a)cosh(b) - sin(a)sinh(b)i}
+ * </p><p>
+ * where the (real) functions on the right-hand side are
+ * {@link Math#sin}, {@link Math#cos},
+ * {@link Math#cosh} and {@link Math#sinh}.
+ * </p><p>
+ * Returns {@link Complex#NaN} if either real or imaginary part of the
+ * input argument is {@code NaN}.
+ * </p><p>
+ * Infinite values in real or imaginary parts of the input may result in
+ * infinite or NaN values returned in parts of the result.</p>
+ * <pre>
+ * Examples:
+ * <code>
+ * cos(1 ± INFINITY i) = 1 \u2213 INFINITY i
+ * cos(±INFINITY + i) = NaN + NaN i
+ * cos(±INFINITY ± INFINITY i) = NaN + NaN i
+ * </code>
+ * </pre>
+ *
+ * @return the cosine of this complex number.
+ * @since 1.2
+ */
+ public Complex cos() {
+ if (isNaN) {
+ return NaN;
+ }
+
+ return createComplex(Math.cos(real) * Math.cosh(imaginary),
+ -Math.sin(real) * Math.sinh(imaginary));
+ }
+
+ /**
+ * Compute the
+ * <a href="http://mathworld.wolfram.com/HyperbolicCosine.html" TARGET="_top">
+ * hyperbolic cosine</a> of this complex number.
+ * Implements the formula:
+ * <pre>
+ * <code>
+ * cosh(a + bi) = cosh(a)cos(b) + sinh(a)sin(b)i
+ * </code>
+ * </pre>
+ * where the (real) functions on the right-hand side are
+ * {@link Math#sin}, {@link Math#cos},
+ * {@link Math#cosh} and {@link Math#sinh}.
+ * <p>
+ * Returns {@link Complex#NaN} if either real or imaginary part of the
+ * input argument is {@code NaN}.
+ * </p>
+ * Infinite values in real or imaginary parts of the input may result in
+ * infinite or NaN values returned in parts of the result.
+ * <pre>
+ * Examples:
+ * <code>
+ * cosh(1 ± INFINITY i) = NaN + NaN i
+ * cosh(±INFINITY + i) = INFINITY ± INFINITY i
+ * cosh(±INFINITY ± INFINITY i) = NaN + NaN i
+ * </code>
+ * </pre>
+ *
+ * @return the hyperbolic cosine of this complex number.
+ * @since 1.2
+ */
+ public Complex cosh() {
+ if (isNaN) {
+ return NaN;
+ }
+
+ return createComplex(Math.cosh(real) * Math.cos(imaginary),
+ Math.sinh(real) * Math.sin(imaginary));
+ }
+
+ /**
+ * Compute the
+ * <a href="http://mathworld.wolfram.com/ExponentialFunction.html" TARGET="_top">
+ * exponential function</a> of this complex number.
+ * Implements the formula:
+ * <pre>
+ * <code>
+ * exp(a + bi) = exp(a)cos(b) + exp(a)sin(b)i
+ * </code>
+ * </pre>
+ * where the (real) functions on the right-hand side are
+ * {@link Math#exp}, {@link Math#cos}, and
+ * {@link Math#sin}.
+ * <p>
+ * Returns {@link Complex#NaN} if either real or imaginary part of the
+ * input argument is {@code NaN}.
+ * </p>
+ * Infinite values in real or imaginary parts of the input may result in
+ * infinite or NaN values returned in parts of the result.
+ * <pre>
+ * Examples:
+ * <code>
+ * exp(1 ± INFINITY i) = NaN + NaN i
+ * exp(INFINITY + i) = INFINITY + INFINITY i
+ * exp(-INFINITY + i) = 0 + 0i
+ * exp(±INFINITY ± INFINITY i) = NaN + NaN i
+ * </code>
+ * </pre>
+ *
+ * @return <code><i>e</i><sup>this</sup></code>.
+ * @since 1.2
+ */
+ public Complex exp() {
+ if (isNaN) {
+ return NaN;
+ }
+
+ double expReal = Math.exp(real);
+ return createComplex(expReal * Math.cos(imaginary),
+ expReal * Math.sin(imaginary));
+ }
+
+ /**
+ * Compute the
+ * <a href="http://mathworld.wolfram.com/NaturalLogarithm.html" TARGET="_top">
+ * natural logarithm</a> of this complex number.
+ * Implements the formula:
+ * <pre>
+ * <code>
+ * log(a + bi) = ln(|a + bi|) + arg(a + bi)i
+ * </code>
+ * </pre>
+ * where ln on the right hand side is {@link Math#log},
+ * {@code |a + bi|} is the modulus, {@link Complex#abs}, and
+ * {@code arg(a + bi) = }{@link Math#atan2}(b, a).
+ * <p>
+ * Returns {@link Complex#NaN} if either real or imaginary part of the
+ * input argument is {@code NaN}.
+ * </p>
+ * Infinite (or critical) values in real or imaginary parts of the input may
+ * result in infinite or NaN values returned in parts of the result.
+ * <pre>
+ * Examples:
+ * <code>
+ * log(1 ± INFINITY i) = INFINITY ± (π/2)i
+ * log(INFINITY + i) = INFINITY + 0i
+ * log(-INFINITY + i) = INFINITY + πi
+ * log(INFINITY ± INFINITY i) = INFINITY ± (π/4)i
+ * log(-INFINITY ± INFINITY i) = INFINITY ± (3π/4)i
+ * log(0 + 0i) = -INFINITY + 0i
+ * </code>
+ * </pre>
+ *
+ * @return the value <code>ln this</code>, the natural logarithm
+ * of {@code this}.
+ * @since 1.2
+ */
+ public Complex log() {
+ if (isNaN) {
+ return NaN;
+ }
+
+ return createComplex(Math.log(abs()),
+ Math.atan2(imaginary, real));
+ }
+
+ /**
+ * Returns of value of this complex number raised to the power of {@code x}.
+ * Implements the formula:
+ * <pre>
+ * <code>
+ * y<sup>x</sup> = exp(x·log(y))
+ * </code>
+ * </pre>
+ * where {@code exp} and {@code log} are {@link #exp} and
+ * {@link #log}, respectively.
+ * <p>
+ * Returns {@link Complex#NaN} if either real or imaginary part of the
+ * input argument is {@code NaN} or infinite, or if {@code y}
+ * equals {@link Complex#ZERO}.</p>
+ *
+ * @param x exponent to which this {@code Complex} is to be raised.
+ * @return <code> this<sup>x</sup></code>.
+ * @since 1.2
+ */
+ public Complex pow(Complex x) {
+ checkNotNull(x);
+ if (real == 0 && imaginary == 0) {
+ if (x.real > 0 && x.imaginary == 0) {
+ // 0 raised to positive number is 0
+ return ZERO;
+ } else {
+ // 0 raised to anything else is NaN
+ return NaN;
+ }
+ }
+ return this.log().multiply(x).exp();
+ }
+
+ /**
+ * Returns of value of this complex number raised to the power of {@code x}.
+ *
+ * @param x exponent to which this {@code Complex} is to be raised.
+ * @return <code>this<sup>x</sup></code>.
+ * @see #pow(Complex)
+ */
+ public Complex pow(double x) {
+ if (real == 0 && imaginary == 0) {
+ if (x > 0) {
+ // 0 raised to positive number is 0
+ return ZERO;
+ } else {
+ // 0 raised to anything else is NaN
+ return NaN;
+ }
+ }
+ return this.log().multiply(x).exp();
+ }
+
+ /**
+ * Compute the
+ * <a href="http://mathworld.wolfram.com/Sine.html" TARGET="_top">
+ * sine</a>
+ * of this complex number.
+ * Implements the formula:
+ * <pre>
+ * <code>
+ * sin(a + bi) = sin(a)cosh(b) - cos(a)sinh(b)i
+ * </code>
+ * </pre>
+ * where the (real) functions on the right-hand side are
+ * {@link Math#sin}, {@link Math#cos},
+ * {@link Math#cosh} and {@link Math#sinh}.
+ * <p>
+ * Returns {@link Complex#NaN} if either real or imaginary part of the
+ * input argument is {@code NaN}.
+ * </p><p>
+ * Infinite values in real or imaginary parts of the input may result in
+ * infinite or {@code NaN} values returned in parts of the result.
+ * <pre>
+ * Examples:
+ * <code>
+ * sin(1 ± INFINITY i) = 1 ± INFINITY i
+ * sin(±INFINITY + i) = NaN + NaN i
+ * sin(±INFINITY ± INFINITY i) = NaN + NaN i
+ * </code>
+ * </pre>
+ *
+ * @return the sine of this complex number.
+ * @since 1.2
+ */
+ public Complex sin() {
+ if (isNaN) {
+ return NaN;
+ }
+
+ return createComplex(Math.sin(real) * Math.cosh(imaginary),
+ Math.cos(real) * Math.sinh(imaginary));
+ }
+
+ /**
+ * Compute the
+ * <a href="http://mathworld.wolfram.com/HyperbolicSine.html" TARGET="_top">
+ * hyperbolic sine</a> of this complex number.
+ * Implements the formula:
+ * <pre>
+ * <code>
+ * sinh(a + bi) = sinh(a)cos(b)) + cosh(a)sin(b)i
+ * </code>
+ * </pre>
+ * where the (real) functions on the right-hand side are
+ * {@link Math#sin}, {@link Math#cos},
+ * {@link Math#cosh} and {@link Math#sinh}.
+ * <p>
+ * Returns {@link Complex#NaN} if either real or imaginary part of the
+ * input argument is {@code NaN}.
+ * </p><p>
+ * Infinite values in real or imaginary parts of the input may result in
+ * infinite or NaN values returned in parts of the result.
+ * <pre>
+ * Examples:
+ * <code>
+ * sinh(1 ± INFINITY i) = NaN + NaN i
+ * sinh(±INFINITY + i) = ± INFINITY + INFINITY i
+ * sinh(±INFINITY ± INFINITY i) = NaN + NaN i
+ * </code>
+ * </pre>
+ *
+ * @return the hyperbolic sine of {@code this}.
+ * @since 1.2
+ */
+ public Complex sinh() {
+ if (isNaN) {
+ return NaN;
+ }
+
+ return createComplex(Math.sinh(real) * Math.cos(imaginary),
+ Math.cosh(real) * Math.sin(imaginary));
+ }
+
+ /**
+ * Compute the
+ * <a href="http://mathworld.wolfram.com/SquareRoot.html" TARGET="_top">
+ * square root</a> of this complex number.
+ * Implements the following algorithm to compute {@code sqrt(a + bi)}:
+ * <ol><li>Let {@code t = sqrt((|a| + |a + bi|) / 2)}</li>
+ * <li><pre>if {@code a ≥ 0} return {@code t + (b/2t)i}
+ * else return {@code |b|/2t + sign(b)t i }</pre></li>
+ * </ol>
+ * where <ul>
+ * <li>{@code |a| = }{@link Math#abs}(a)</li>
+ * <li>{@code |a + bi| = }{@link Complex#abs}(a + bi)</li>
+ * <li>{@code sign(b) = }{@link Math#copySign(double,double) copySign(1d, b)}
+ * </ul>
+ * <p>
+ * Returns {@link Complex#NaN} if either real or imaginary part of the
+ * input argument is {@code NaN}.
+ * </p>
+ * Infinite values in real or imaginary parts of the input may result in
+ * infinite or NaN values returned in parts of the result.
+ * <pre>
+ * Examples:
+ * <code>
+ * sqrt(1 ± INFINITY i) = INFINITY + NaN i
+ * sqrt(INFINITY + i) = INFINITY + 0i
+ * sqrt(-INFINITY + i) = 0 + INFINITY i
+ * sqrt(INFINITY ± INFINITY i) = INFINITY + NaN i
+ * sqrt(-INFINITY ± INFINITY i) = NaN ± INFINITY i
+ * </code>
+ * </pre>
+ *
+ * @return the square root of {@code this}.
+ * @since 1.2
+ */
+ public Complex sqrt() {
+ if (isNaN) {
+ return NaN;
+ }
+
+ if (real == 0.0 && imaginary == 0.0) {
+ return createComplex(0.0, 0.0);
+ }
+
+ double t = Math.sqrt((Math.abs(real) + abs()) / 2.0);
+ if (real >= 0.0) {
+ return createComplex(t, imaginary / (2.0 * t));
+ } else {
+ return createComplex(Math.abs(imaginary) / (2.0 * t),
+ Math.copySign(1d, imaginary) * t);
+ }
+ }
+
+ /**
+ * Compute the
+ * <a href="http://mathworld.wolfram.com/SquareRoot.html" TARGET="_top">
+ * square root</a> of <code>1 - this<sup>2</sup></code> for this complex
+ * number.
+ * Computes the result directly as
+ * {@code sqrt(ONE.subtract(z.multiply(z)))}.
+ * <p>
+ * Returns {@link Complex#NaN} if either real or imaginary part of the
+ * input argument is {@code NaN}.
+ * </p>
+ * Infinite values in real or imaginary parts of the input may result in
+ * infinite or NaN values returned in parts of the result.
+ *
+ * @return the square root of <code>1 - this<sup>2</sup></code>.
+ * @since 1.2
+ */
+ public Complex sqrt1z() {
+ return createComplex(1.0, 0.0).subtract(this.multiply(this)).sqrt();
+ }
+
+ /**
+ * Compute the
+ * <a href="http://mathworld.wolfram.com/Tangent.html" TARGET="_top">
+ * tangent</a> of this complex number.
+ * Implements the formula:
+ * <pre>
+ * <code>
+ * tan(a + bi) = sin(2a)/(cos(2a)+cosh(2b)) + [sinh(2b)/(cos(2a)+cosh(2b))]i
+ * </code>
+ * </pre>
+ * where the (real) functions on the right-hand side are
+ * {@link Math#sin}, {@link Math#cos}, {@link Math#cosh} and
+ * {@link Math#sinh}.
+ * <p>
+ * Returns {@link Complex#NaN} if either real or imaginary part of the
+ * input argument is {@code NaN}.
+ * </p>
+ * Infinite (or critical) values in real or imaginary parts of the input may
+ * result in infinite or NaN values returned in parts of the result.
+ * <pre>
+ * Examples:
+ * <code>
+ * tan(a ± INFINITY i) = 0 ± i
+ * tan(±INFINITY + bi) = NaN + NaN i
+ * tan(±INFINITY ± INFINITY i) = NaN + NaN i
+ * tan(±π/2 + 0 i) = ±INFINITY + NaN i
+ * </code>
+ * </pre>
+ *
+ * @return the tangent of {@code this}.
+ * @since 1.2
+ */
+ public Complex tan() {
+ if (isNaN || Double.isInfinite(real)) {
+ return NaN;
+ }
+ if (imaginary > 20.0) {
+ return createComplex(0.0, 1.0);
+ }
+ if (imaginary < -20.0) {
+ return createComplex(0.0, -1.0);
+ }
+
+ double real2 = 2.0 * real;
+ double imaginary2 = 2.0 * imaginary;
+ double d = Math.cos(real2) + Math.cosh(imaginary2);
+
+ return createComplex(Math.sin(real2) / d,
+ Math.sinh(imaginary2) / d);
+ }
+
+ /**
+ * Compute the
+ * <a href="http://mathworld.wolfram.com/HyperbolicTangent.html" TARGET="_top">
+ * hyperbolic tangent</a> of this complex number.
+ * Implements the formula:
+ * <pre>
+ * <code>
+ * tan(a + bi) = sinh(2a)/(cosh(2a)+cos(2b)) + [sin(2b)/(cosh(2a)+cos(2b))]i
+ * </code>
+ * </pre>
+ * where the (real) functions on the right-hand side are
+ * {@link Math#sin}, {@link Math#cos}, {@link Math#cosh} and
+ * {@link Math#sinh}.
+ * <p>
+ * Returns {@link Complex#NaN} if either real or imaginary part of the
+ * input argument is {@code NaN}.
+ * </p>
+ * Infinite values in real or imaginary parts of the input may result in
+ * infinite or NaN values returned in parts of the result.
+ * <pre>
+ * Examples:
+ * <code>
+ * tanh(a ± INFINITY i) = NaN + NaN i
+ * tanh(±INFINITY + bi) = ±1 + 0 i
+ * tanh(±INFINITY ± INFINITY i) = NaN + NaN i
+ * tanh(0 + (π/2)i) = NaN + INFINITY i
+ * </code>
+ * </pre>
+ *
+ * @return the hyperbolic tangent of {@code this}.
+ * @since 1.2
+ */
+ public Complex tanh() {
+ if (isNaN || Double.isInfinite(imaginary)) {
+ return NaN;
+ }
+ if (real > 20.0) {
+ return createComplex(1.0, 0.0);
+ }
+ if (real < -20.0) {
+ return createComplex(-1.0, 0.0);
+ }
+ double real2 = 2.0 * real;
+ double imaginary2 = 2.0 * imaginary;
+ double d = Math.cosh(real2) + Math.cos(imaginary2);
+
+ return createComplex(Math.sinh(real2) / d,
+ Math.sin(imaginary2) / d);
+ }
+
+
+
+ /**
+ * Compute the argument of this complex number.
+ * The argument is the angle phi between the positive real axis and
+ * the point representing this number in the complex plane.
+ * The value returned is between -PI (not inclusive)
+ * and PI (inclusive), with negative values returned for numbers with
+ * negative imaginary parts.
+ * <p>
+ * If either real or imaginary part (or both) is NaN, NaN is returned.
+ * Infinite parts are handled as {@code Math.atan2} handles them,
+ * essentially treating finite parts as zero in the presence of an
+ * infinite coordinate and returning a multiple of pi/4 depending on
+ * the signs of the infinite parts.
+ * See the javadoc for {@code Math.atan2} for full details.
+ *
+ * @return the argument of {@code this}.
+ */
+ public double getArgument() {
+ return Math.atan2(getImaginary(), getReal());
+ }
+
+ /**
+ * Computes the n-th roots of this complex number.
+ * The nth roots are defined by the formula:
+ * <pre>
+ * <code>
+ * z<sub>k</sub> = abs<sup>1/n</sup> (cos(phi + 2πk/n) + i (sin(phi + 2πk/n))
+ * </code>
+ * </pre>
+ * for <i>{@code k=0, 1, ..., n-1}</i>, where {@code abs} and {@code phi}
+ * are respectively the {@link #abs() modulus} and
+ * {@link #getArgument() argument} of this complex number.
+ * <p>
+ * If one or both parts of this complex number is NaN, a list with just
+ * one element, {@link #NaN} is returned.
+ * if neither part is NaN, but at least one part is infinite, the result
+ * is a one-element list containing {@link #INF}.
+ *
+ * @param n Degree of root.
+ * @return a List of all {@code n}-th roots of {@code this}.
+ * @since 2.0
+ */
+ public List<Complex> nthRoot(int n) {
+
+ if (n <= 0) {
+ throw new RuntimeException("cannot compute nth root for null or negative n: {0}");
+ }
+
+ final List<Complex> result = new ArrayList<Complex>();
+
+ if (isNaN) {
+ result.add(NaN);
+ return result;
+ }
+ if (isInfinite()) {
+ result.add(INF);
+ return result;
+ }
+
+ // nth root of abs -- faster / more accurate to use a solver here?
+ final double nthRootOfAbs = Math.pow(abs(), 1.0 / n);
+
+ // Compute nth roots of complex number with k = 0, 1, ... n-1
+ final double nthPhi = getArgument() / n;
+ final double slice = 2 * Math.PI / n;
+ double innerPart = nthPhi;
+ for (int k = 0; k < n ; k++) {
+ // inner part
+ final double realPart = nthRootOfAbs * Math.cos(innerPart);
+ final double imaginaryPart = nthRootOfAbs * Math.sin(innerPart);
+ result.add(createComplex(realPart, imaginaryPart));
+ innerPart += slice;
+ }
+
+ return result;
+ }
+
+ /**
+ * Create a complex number given the real and imaginary parts.
+ *
+ * @param realPart Real part.
+ * @param imaginaryPart Imaginary part.
+ * @return a new complex number instance.
+ * @since 1.2
+ * @see #valueOf(double, double)
+ */
+ protected Complex createComplex(double realPart,
+ double imaginaryPart) {
+ return new Complex(realPart, imaginaryPart);
+ }
+
+ /**
+ * Create a complex number given the real and imaginary parts.
+ *
+ * @param realPart Real part.
+ * @param imaginaryPart Imaginary part.
+ * @return a Complex instance.
+ */
+ public static Complex valueOf(double realPart,
+ double imaginaryPart) {
+ if (Double.isNaN(realPart) ||
+ Double.isNaN(imaginaryPart)) {
+ return NaN;
+ }
+ return new Complex(realPart, imaginaryPart);
+ }
+
+ /**
+ * Create a complex number given only the real part.
+ *
+ * @param realPart Real part.
+ * @return a Complex instance.
+ */
+ public static Complex valueOf(double realPart) {
+ if (Double.isNaN(realPart)) {
+ return NaN;
+ }
+ return new Complex(realPart);
+ }
+
+ /**
+ * Resolve the transient fields in a deserialized Complex Object.
+ * Subclasses will need to override {@link #createComplex} to
+ * deserialize properly.
+ *
+ * @return A Complex instance with all fields resolved.
+ * @since 2.0
+ */
+ protected final Object readResolve() {
+ return createComplex(real, imaginary);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public String toString() {
+ return "(" + real + ", " + imaginary + ")";
+ }
+
+ /**
+ * Checks that an object is not null.
+ *
+ * @param o Object to be checked.
+ */
+ private static void checkNotNull(Object o) {
+ if (o == null) {
+ throw new RuntimeException("Null Argument to Complex Method");
+ }
+ }
+
+ /**
+ * Returns {@code true} if the values are equal according to semantics of
+ * {@link Double#equals(Object)}.
+ *
+ * @param x Value
+ * @param y Value
+ * @return {@code new Double(x).equals(new Double(y))}
+ */
+ private static boolean equals(double x, double y) {
+ return new Double(x).equals(new Double(y));
+ }
+
+ /**
+ * Returns {@code true} if there is no double value strictly between the
+ * arguments or the difference between them is within the range of allowed
+ * error (inclusive). Returns {@code false} if either of the arguments
+ * is NaN.
+ *
+ * @param x First value.
+ * @param y Second value.
+ * @param eps Amount of allowed absolute error.
+ * @return {@code true} if the values are two adjacent floating point
+ * numbers or they are within range of each other.
+ */
+ public static boolean equals(double x, double y, double eps) {
+ return equals(x, y, 1) || Math.abs(y - x) <= eps;
+ }
+
+
+ /**
+ * Returns {@code true} if there is no double value strictly between the
+ * arguments or the relative difference between them is less than or equal
+ * to the given tolerance. Returns {@code false} if either of the arguments
+ * is NaN.
+ *
+ * @param x First value.
+ * @param y Second value.
+ * @param eps Amount of allowed relative error.
+ * @return {@code true} if the values are two adjacent floating point
+ * numbers or they are within range of each other.
+ * @since 3.1
+ */
+ public static boolean equalsWithRelativeTolerance(double x, double y, double eps) {
+ if (equals(x, y, 1)) {
+ return true;
+ }
+
+ final double absoluteMax = Math.max(Math.abs(x), Math.abs(y));
+ final double relativeDifference = Math.abs((x - y) / absoluteMax);
+
+ return relativeDifference <= eps;
+ }
+
+ /**
+ * Returns an integer hash code representing the given double value.
+ *
+ * @param value the value to be hashed
+ * @return the hash code
+ */
+ public static int hash(double value) {
+ return new Double(value).hashCode();
+ }
+
+}
+
[06/31] commons-numbers git commit: Cleanup (massive delete).
Posted by er...@apache.org.
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/main/java/org/apache/commons/complex/Quaternion.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/complex/Quaternion.java b/src/main/java/org/apache/commons/complex/Quaternion.java
deleted file mode 100644
index 6fc29a3..0000000
--- a/src/main/java/org/apache/commons/complex/Quaternion.java
+++ /dev/null
@@ -1,467 +0,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.
- */
-
-package org.apache.commons.complex;
-
-import java.io.Serializable;
-
-/**
- * This class implements <a href="http://mathworld.wolfram.com/Quaternion.html">
- * quaternions</a> (Hamilton's hypercomplex numbers).
- * <br/>
- * Instance of this class are guaranteed to be immutable.
- *
- * @since 3.1
- */
-public final class Quaternion implements Serializable {
- /** Identity quaternion. */
- public static final Quaternion IDENTITY = new Quaternion(1, 0, 0, 0);
- /** Zero quaternion. */
- public static final Quaternion ZERO = new Quaternion(0, 0, 0, 0);
- /** i */
- public static final Quaternion I = new Quaternion(0, 1, 0, 0);
- /** j */
- public static final Quaternion J = new Quaternion(0, 0, 1, 0);
- /** k */
- public static final Quaternion K = new Quaternion(0, 0, 0, 1);
-
- /** Serializable version identifier. */
- private static final long serialVersionUID = 20092012L;
-
- /** First component (scalar part). */
- private final double q0;
- /** Second component (first vector part). */
- private final double q1;
- /** Third component (second vector part). */
- private final double q2;
- /** Fourth component (third vector part). */
- private final double q3;
-
- /** Exception message strings */
- private static final String zeroNormException = "Norm is zero";
-
- /** Exponent offset in IEEE754 representation. */
- private static final long EXPONENT_OFFSET = 1023l;
- /** Safe minimums such that 1/N does not overflow */
- private static final double SAFE_MIN = Double.longBitsToDouble((EXPONENT_OFFSET - 1022l) << 52);
-
- /**
- * Builds a quaternion from its components.
- *
- * @param a Scalar component.
- * @param b First vector component.
- * @param c Second vector component.
- * @param d Third vector component.
- */
- public Quaternion(final double a,
- final double b,
- final double c,
- final double d) {
- this.q0 = a;
- this.q1 = b;
- this.q2 = c;
- this.q3 = d;
- }
-
- /**
- * Builds a quaternion from scalar and vector parts.
- *
- * @param scalar Scalar part of the quaternion.
- * @param v Components of the vector part of the quaternion.
- *
- * @throws IllegalArgumentException if the array length is not 3.
- */
- public Quaternion(final double scalar,
- final double[] v) {
- try {
- this.q0 = scalar;
- this.q1 = v[0];
- this.q2 = v[1];
- this.q3 = v[2];
- } catch (Exception e) {
- throw new IllegalArgumentException(zeroNormException);
- }
- }
-
- /**
- * Builds a pure quaternion from a vector (assuming that the scalar
- * part is zero).
- *
- * @param v Components of the vector part of the pure quaternion.
- */
- public Quaternion(final double[] v) {
- this(0, v);
- }
-
- /**
- * Returns the conjugate quaternion of the instance.
- *
- * @return the conjugate quaternion
- */
- public Quaternion getConjugate() {
- return new Quaternion(q0, -q1, -q2, -q3);
- }
-
- /**
- * Returns the Hamilton product of two quaternions.
- *
- * @param q1 First quaternion.
- * @param q2 Second quaternion.
- * @return the product {@code q1} and {@code q2}, in that order.
- */
- public static Quaternion multiply(final Quaternion q1, final Quaternion q2) {
- // Components of the first quaternion.
- final double q1a = q1.getQ0();
- final double q1b = q1.getQ1();
- final double q1c = q1.getQ2();
- final double q1d = q1.getQ3();
-
- // Components of the second quaternion.
- final double q2a = q2.getQ0();
- final double q2b = q2.getQ1();
- final double q2c = q2.getQ2();
- final double q2d = q2.getQ3();
-
- // Components of the product.
- final double w = q1a * q2a - q1b * q2b - q1c * q2c - q1d * q2d;
- final double x = q1a * q2b + q1b * q2a + q1c * q2d - q1d * q2c;
- final double y = q1a * q2c - q1b * q2d + q1c * q2a + q1d * q2b;
- final double z = q1a * q2d + q1b * q2c - q1c * q2b + q1d * q2a;
-
- return new Quaternion(w, x, y, z);
- }
-
- /**
- * Returns the Hamilton product of the instance by a quaternion.
- *
- * @param q Quaternion.
- * @return the product of this instance with {@code q}, in that order.
- */
- public Quaternion multiply(final Quaternion q) {
- return multiply(this, q);
- }
-
- /**
- * Computes the sum of two quaternions.
- *
- * @param q1 Quaternion.
- * @param q2 Quaternion.
- * @return the sum of {@code q1} and {@code q2}.
- */
- public static Quaternion add(final Quaternion q1,
- final Quaternion q2) {
- return new Quaternion(q1.getQ0() + q2.getQ0(),
- q1.getQ1() + q2.getQ1(),
- q1.getQ2() + q2.getQ2(),
- q1.getQ3() + q2.getQ3());
- }
-
- /**
- * Computes the sum of the instance and another quaternion.
- *
- * @param q Quaternion.
- * @return the sum of this instance and {@code q}
- */
- public Quaternion add(final Quaternion q) {
- return add(this, q);
- }
-
- /**
- * Subtracts two quaternions.
- *
- * @param q1 First Quaternion.
- * @param q2 Second quaternion.
- * @return the difference between {@code q1} and {@code q2}.
- */
- public static Quaternion subtract(final Quaternion q1,
- final Quaternion q2) {
- return new Quaternion(q1.getQ0() - q2.getQ0(),
- q1.getQ1() - q2.getQ1(),
- q1.getQ2() - q2.getQ2(),
- q1.getQ3() - q2.getQ3());
- }
-
- /**
- * Subtracts a quaternion from the instance.
- *
- * @param q Quaternion.
- * @return the difference between this instance and {@code q}.
- */
- public Quaternion subtract(final Quaternion q) {
- return subtract(this, q);
- }
-
- /**
- * Computes the dot-product of two quaternions.
- *
- * @param q1 Quaternion.
- * @param q2 Quaternion.
- * @return the dot product of {@code q1} and {@code q2}.
- */
- public static double dotProduct(final Quaternion q1,
- final Quaternion q2) {
- return q1.getQ0() * q2.getQ0() +
- q1.getQ1() * q2.getQ1() +
- q1.getQ2() * q2.getQ2() +
- q1.getQ3() * q2.getQ3();
- }
-
- /**
- * Computes the dot-product of the instance by a quaternion.
- *
- * @param q Quaternion.
- * @return the dot product of this instance and {@code q}.
- */
- public double dotProduct(final Quaternion q) {
- return dotProduct(this, q);
- }
-
- /**
- * Computes the norm of the quaternion.
- *
- * @return the norm.
- */
- public double getNorm() {
- return Math.sqrt(q0 * q0 +
- q1 * q1 +
- q2 * q2 +
- q3 * q3);
- }
-
- /**
- * Computes the normalized quaternion (the versor of the instance).
- * The norm of the quaternion must not be zero.
- *
- * @return a normalized quaternion.
- * @throws IllegalArgumentException if the norm of the quaternion is zero.
- */
- public Quaternion normalize() {
- final double norm = getNorm();
-
- if (norm < SAFE_MIN) {
- throw new IllegalStateException(zeroNormException);
- }
-
- return new Quaternion(q0 / norm,
- q1 / norm,
- q2 / norm,
- q3 / norm);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object other) {
- if (this == other) {
- return true;
- }
- if (other instanceof Quaternion) {
- final Quaternion q = (Quaternion) other;
- return q0 == q.getQ0() &&
- q1 == q.getQ1() &&
- q2 == q.getQ2() &&
- q3 == q.getQ3();
- }
-
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- // "Effective Java" (second edition, p. 47).
- int result = 17;
- for (double comp : new double[] { q0, q1, q2, q3 }) {
- final int c = new Double(comp).hashCode();
- result = 31 * result + c;
- }
- return result;
- }
-
- /**
- * Checks whether this instance is equal to another quaternion
- * within a given tolerance.
- *
- * @param q Quaternion with which to compare the current quaternion.
- * @param eps Tolerance.
- * @return {@code true} if the each of the components are equal
- * within the allowed absolute error.
- */
- public boolean equals(final Quaternion q,
- final double eps) {
- return Precision.equals(q0, q.getQ0(), eps) &&
- Precision.equals(q1, q.getQ1(), eps) &&
- Precision.equals(q2, q.getQ2(), eps) &&
- Precision.equals(q3, q.getQ3(), eps);
- }
-
- /**
- * Checks whether the instance is a unit quaternion within a given
- * tolerance.
- *
- * @param eps Tolerance (absolute error).
- * @return {@code true} if the norm is 1 within the given tolerance,
- * {@code false} otherwise
- */
- public boolean isUnitQuaternion(double eps) {
- return Precision.equals(getNorm(), 1d, eps);
- }
-
- /**
- * Checks whether the instance is a pure quaternion within a given
- * tolerance.
- *
- * @param eps Tolerance (absolute error).
- * @return {@code true} if the scalar part of the quaternion is zero.
- */
- public boolean isPureQuaternion(double eps) {
- return Math.abs(getQ0()) <= eps;
- }
-
- /**
- * Returns the polar form of the quaternion.
- *
- * @return the unit quaternion with positive scalar part.
- */
- public Quaternion getPositivePolarForm() {
- if (getQ0() < 0) {
- final Quaternion unitQ = normalize();
- // The quaternion of rotation (normalized quaternion) q and -q
- // are equivalent (i.e. represent the same rotation).
- return new Quaternion(-unitQ.getQ0(),
- -unitQ.getQ1(),
- -unitQ.getQ2(),
- -unitQ.getQ3());
- } else {
- return this.normalize();
- }
- }
-
- /**
- * Returns the inverse of this instance.
- * The norm of the quaternion must not be zero.
- *
- * @return the inverse.
- * @throws IllegalArgumentException if the norm (squared) of the quaternion is zero.
- */
- public Quaternion getInverse() {
- final double squareNorm = q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3;
- if (squareNorm < SAFE_MIN) {
- throw new IllegalStateException("Norm of the Quarterion is zero");
- }
-
- return new Quaternion(q0 / squareNorm,
- -q1 / squareNorm,
- -q2 / squareNorm,
- -q3 / squareNorm);
- }
-
- /**
- * Gets the first component of the quaternion (scalar part).
- *
- * @return the scalar part.
- */
- public double getQ0() {
- return q0;
- }
-
- /**
- * Gets the second component of the quaternion (first component
- * of the vector part).
- *
- * @return the first component of the vector part.
- */
- public double getQ1() {
- return q1;
- }
-
- /**
- * Gets the third component of the quaternion (second component
- * of the vector part).
- *
- * @return the second component of the vector part.
- */
- public double getQ2() {
- return q2;
- }
-
- /**
- * Gets the fourth component of the quaternion (third component
- * of the vector part).
- *
- * @return the third component of the vector part.
- */
- public double getQ3() {
- return q3;
- }
-
- /**
- * Gets the scalar part of the quaternion.
- *
- * @return the scalar part.
- * @see #getQ0()
- */
- public double getScalarPart() {
- return getQ0();
- }
-
- /**
- * Gets the three components of the vector part of the quaternion.
- *
- * @return the vector part.
- * @see #getQ1()
- * @see #getQ2()
- * @see #getQ3()
- */
- public double[] getVectorPart() {
- return new double[] { getQ1(), getQ2(), getQ3() };
- }
-
- /**
- * Multiplies the instance by a scalar.
- *
- * @param alpha Scalar factor.
- * @return a scaled quaternion.
- */
- public Quaternion multiply(final double alpha) {
- return new Quaternion(alpha * q0,
- alpha * q1,
- alpha * q2,
- alpha * q3);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- final String sp = " ";
- final StringBuilder s = new StringBuilder();
- s.append("[")
- .append(q0).append(sp)
- .append(q1).append(sp)
- .append(q2).append(sp)
- .append(q3)
- .append("]");
-
- return s.toString();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/main/java/org/apache/commons/complex/RootsOfUnity.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/complex/RootsOfUnity.java b/src/main/java/org/apache/commons/complex/RootsOfUnity.java
deleted file mode 100644
index 7a06a69..0000000
--- a/src/main/java/org/apache/commons/complex/RootsOfUnity.java
+++ /dev/null
@@ -1,116 +0,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.
- */
-package org.apache.commons.complex;
-
-/**
- * Computation of the {@code n}-th roots of unity.
- */
-public class RootsOfUnity {
- /** 2 * π */
- private static final double TWO_PI = 2 * Math.PI;
- /** Number of roots of unity. */
- private final int omegaCount;
- /** The roots. */
- private final Complex[] omega;
- /**
- * {@code true} if the constructor was called with a positive
- * value of its argument {@code n}.
- */
- private final boolean isCounterClockwise;
-
- /**
- * Computes the {@code n}-th roots of unity.
- *
- * The roots are stored in an array
- * {@code omega[]}, such that {@code omega[k] = w ^ k}, where
- * {@code k = 0, ..., n - 1}, {@code w = exp(2 * pi * i / n)} and
- * {@code i = sqrt(-1)}.
- *
- * <p>{@code n} can be positive of negative ({@code abs(n)} is always
- * the number of roots of unity):</p>
- * <ul>
- * <li>If {@code n > 0}, then the roots are stored in counter-clockwise order.</li>
- * <li>If {@code n < 0}, then the roots are stored in clockwise order.</li>
- * </ul>
- *
- * @param n The (signed) number of roots of unity to be computed.
- * @throws IllegalArgumentException if {@code n == 0}?
- */
- public RootsOfUnity(int n) {
- if (n == 0) {
- throw new IllegalArgumentException("Zero-th root");
- }
-
- omegaCount = Math.abs(n);
- isCounterClockwise = n > 0;
-
- omega = new Complex[omegaCount];
- final double t = TWO_PI / omegaCount;
- final double cosT = Math.cos(t);
- final double sinT = Math.sin(t);
-
- double previousReal = 1;
- double previousImag = 0;
- omega[0] = new Complex(previousReal, previousImag);
- for (int i = 1; i < omegaCount; i++) {
- final double real = previousReal * cosT - previousImag * sinT;
- final double imag = previousReal * sinT + previousImag * cosT;
-
- omega[i] = isCounterClockwise ?
- new Complex(real, imag) :
- new Complex(real, -imag);
-
- previousReal = real;
- previousImag = imag;
- }
- }
-
- /**
- * Returns {@code true} if {@link #RootsOfUnity(int)} was called with a
- * positive value of its argument {@code n}.
- * If {@code true}, then the imaginary parts of the successive roots are
- * {@link #getRoot(int) returned} in counter-clockwise order.
- *
- * @return {@code true} if the roots of unity are stored in
- * counter-clockwise order.
- */
- public boolean isCounterClockwise() {
- return isCounterClockwise;
- }
-
- /**
- * Gets the {@code k}-th among the computed roots of unity.
- *
- * @param k Index of the requested value.
- * @return the {@code k}-th among the {@code N}-th root of unity
- * where {@code N} is the absolute value of the argument passed
- * to the constructor.
- * @throws IndexOutOfBoundsException if {@code k} is out of range.
- */
- public Complex getRoot(int k) {
- return omega[k];
- }
-
- /**
- * Gets the number of roots of unity.
- *
- * @return the number of roots of unity.
- */
- public int getNumberOfRoots() {
- return omegaCount;
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/main/java/org/apache/commons/complex/package-info.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/complex/package-info.java b/src/main/java/org/apache/commons/complex/package-info.java
deleted file mode 100644
index 88a0f54..0000000
--- a/src/main/java/org/apache/commons/complex/package-info.java
+++ /dev/null
@@ -1,23 +0,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.
- */
-/**
- *
- * Complex number type and implementations of complex transcendental
- * functions.
- *
- */
-package org.apache.commons.complex;
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/ChiSquareDistributionTestCases.R
----------------------------------------------------------------------
diff --git a/src/test/R/ChiSquareDistributionTestCases.R b/src/test/R/ChiSquareDistributionTestCases.R
deleted file mode 100644
index 3df58ba..0000000
--- a/src/test/R/ChiSquareDistributionTestCases.R
+++ /dev/null
@@ -1,97 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate ChiSquare distribution tests in
-# org.apache.commons.math.distribution.ChiSquareDistributionTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-#-----------------------------------------------------------------------------
-tol <- 1E-9
-
-# Function definitions
-source("testFunctions") # utility test functions
-
-# function to verify distribution computations
-verifyDistribution <- function(points, expected, df, tol) {
- rDistValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDistValues[i] <- pchisq(point, df, log = FALSE)
- }
- output <- c("Distribution test df = ", df)
- if (assertEquals(expected, rDistValues, tol, "Distribution Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify density computations
-verifyDensity <- function(points, expected, df, tol) {
- rDensityValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDensityValues[i] <- dchisq(point, df, log = FALSE)
- }
- output <- c("Density test df = ", df)
- if (assertEquals(expected, rDensityValues, tol, "Density Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify quantiles
-verifyQuantiles <- function(points, expected, df, tol) {
- rQuantileValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rQuantileValues[i] <- qchisq(point, df, log = FALSE)
- }
- output <- c("Quantile test df = ", df)
- if (assertEquals(expected, rQuantileValues, tol, "Quantile Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-#--------------------------------------------------------------------------
-cat("ChiSquare Distribution test cases\n")
-
-df <- 5
-distributionValues <- c(0.001, 0.01, 0.025, 0.05, 0.1, 0.999, 0.990, 0.975, 0.950, 0.900)
-densityValues <- c(0.0115379817652, 0.0415948507811, 0.0665060119842, 0.0919455953114, 0.121472591024,
- 0.000433630076361, 0.00412780610309, 0.00999340341045, 0.0193246438937, 0.0368460089216)
-distributionPoints <- c(0.210212602629, 0.554298076728, 0.831211613487, 1.14547622606, 1.61030798696,
- 20.5150056524, 15.0862724694, 12.8325019940, 11.0704976935, 9.23635689978)
-verifyQuantiles(distributionValues, distributionPoints, df, tol)
-verifyDistribution(distributionPoints, distributionValues, df, tol)
-verifyDensity(distributionPoints, densityValues, df, tol)
-
-df <- .1
-distributionPoints <- c(1.16892641146e-60, 1.16892641146e-40, 1.06313237798e-32, 1.11477509638e-26, 1.16892641146e-20,
- 5.47291719746, 2.17525480018, 1.13434752351, 0.531864604852, 0.152634227818)
-verifyQuantiles(distributionValues, distributionPoints, df, tol)
-verifyDistribution(distributionPoints, distributionValues, df, tol)
-
-displayDashes(WIDTH)
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/FDistributionTestCases.R
----------------------------------------------------------------------
diff --git a/src/test/R/FDistributionTestCases.R b/src/test/R/FDistributionTestCases.R
deleted file mode 100644
index ee7c199..0000000
--- a/src/test/R/FDistributionTestCases.R
+++ /dev/null
@@ -1,92 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate F distribution tests in
-# org.apache.commons.math.distribution.TDistributionTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-#-----------------------------------------------------------------------------
-tol <- 1E-9
-
-# Function definitions
-source("testFunctions") # utility test functions
-
-# function to verify distribution computations
-verifyDistribution <- function(points, expected, numeratorDf, denominatorDf, tol) {
- rDistValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDistValues[i] <- pf(point, numeratorDf, denominatorDf, log = FALSE)
- }
- output <- c("Distribution test numerator df = ", numeratorDf, " denominator df = ", denominatorDf)
- if (assertEquals(expected, rDistValues, tol, "Distribution Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify density computations
-verifyDensity <- function(points, expected, numeratorDf, denominatorDf, tol) {
- rDensityValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDensityValues[i] <- df(point, numeratorDf, denominatorDf, log = FALSE)
- }
- output <- c("Density test numerator df = ", numeratorDf, " denominator df = ", denominatorDf)
- if (assertEquals(expected, rDensityValues, tol, "Density Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify quantiles
-verifyQuantiles <- function(points, expected, numeratorDf, denominatorDf, tol) {
- rQuantileValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rQuantileValues[i] <- qf(point, numeratorDf, denominatorDf, log = FALSE)
- }
- output <- c("Quantile test numerator df = ", numeratorDf, " denominator df = ", denominatorDf)
- if (assertEquals(expected, rQuantileValues, tol, "Quantile Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-#--------------------------------------------------------------------------
-cat("F Distribution test cases\n")
-
-numeratorDf <- 5
-denominatorDf <- 6
-distributionValues <- c(0.001, 0.01, 0.025, 0.05, 0.1, 0.999, 0.990, 0.975, 0.950, 0.900)
-densityValues <- c(0.0689156576706, 0.236735653193, 0.364074131941, 0.481570789649, 0.595880479994,
- 0.000133443915657, 0.00286681303403, 0.00969192007502, 0.0242883861471, 0.0605491314658)
-distributionPoints <- c(0.0346808448626, 0.0937009113303, 0.143313661184, 0.202008445998, 0.293728320107,
- 20.8026639595, 8.74589525602, 5.98756512605, 4.38737418741, 3.10751166664)
-verifyQuantiles(distributionValues, distributionPoints, numeratorDf, denominatorDf, tol)
-verifyDistribution(distributionPoints, distributionValues, numeratorDf, denominatorDf, tol)
-verifyDensity(distributionPoints, densityValues, numeratorDf, denominatorDf, tol)
-
-displayDashes(WIDTH)
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/GammaDistributionTestCases.R
----------------------------------------------------------------------
diff --git a/src/test/R/GammaDistributionTestCases.R b/src/test/R/GammaDistributionTestCases.R
deleted file mode 100644
index 2ed7c95..0000000
--- a/src/test/R/GammaDistributionTestCases.R
+++ /dev/null
@@ -1,92 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate Gamma distribution tests in
-# org.apache.commons.math.distribution.GammaDistributionTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-#-----------------------------------------------------------------------------
-tol <- 1E-9
-
-# Function definitions
-source("testFunctions") # utility test functions
-
-# function to verify distribution computations
-verifyDistribution <- function(points, expected, alpha, beta, tol) {
- rDistValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDistValues[i] <- pgamma(point, shape=alpha, scale=beta, log = FALSE)
- }
- output <- c("Distribution test shape = ", shape, " scale = ", scale)
- if (assertEquals(expected, rDistValues, tol, "Distribution Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify density computations
-verifyDensity <- function(points, expected, alpha, beta, tol) {
- rDensityValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDensityValues[i] <- dgamma(point, shape=alpha, scale=beta, log = FALSE)
- }
- output <- c("Density test shape = ", shape, " scale = ", scale)
- if (assertEquals(expected, rDensityValues, tol, "Density Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify quantiles
-verifyQuantiles <- function(points, expected, alpha, beta, tol) {
- rQuantileValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rQuantileValues[i] <- qgamma(point, shape=alpha, scale=beta, log = FALSE)
- }
- output <- c("Quantile test shape = ", shape, " scale = ", scale)
- if (assertEquals(expected, rQuantileValues, tol, "Quantile Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-#--------------------------------------------------------------------------
-cat("Gamma Distribution test cases\n")
-
-shape <- 4
-scale <- 2
-distributionValues <- c(0.001, 0.01, 0.025, 0.05, 0.1, 0.999, 0.990, 0.975, 0.950, 0.900)
-densityValues <- c(0.00427280075546, 0.0204117166709, 0.0362756163658, 0.0542113174239, 0.0773195272491,
- 0.000394468852816, 0.00366559696761, 0.00874649473311, 0.0166712508128, 0.0311798227954)
-distributionPoints <- c(0.857104827257, 1.64649737269, 2.17973074725, 2.7326367935, 3.48953912565,
- 26.1244815584, 20.0902350297, 17.5345461395, 15.5073130559, 13.3615661365)
-verifyQuantiles(distributionValues, distributionPoints, shape, scale, tol)
-verifyDistribution(distributionPoints, distributionValues, shape, scale, tol)
-verifyDensity(distributionPoints, densityValues, shape, scale, tol)
-
-displayDashes(WIDTH)
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/KolmogorovSmirnovDistributionTestCases.R
----------------------------------------------------------------------
diff --git a/src/test/R/KolmogorovSmirnovDistributionTestCases.R b/src/test/R/KolmogorovSmirnovDistributionTestCases.R
deleted file mode 100644
index 19f74b7..0000000
--- a/src/test/R/KolmogorovSmirnovDistributionTestCases.R
+++ /dev/null
@@ -1,37 +0,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.
-#
-cat("/* ", version$version.string, " */\n\n\n", sep = "")
-
-ns <- c(200, 341, 389)
-ps <- c(0.005, 0.02, 0.031111, 0.04)
-
-for (n in ns) {
- for (p in ps) {
- res <- .C("pkolmogorov2x", p = as.double(p), n = as.integer(n), PACKAGE = "stats")$p
-
- cat("/* formatC(.C(\"pkolmogorov2x\", p = as.double(", p, "), n = as.integer(", n, "), PACKAGE = \"stats\")$p, 40) gives\n", sep = "")
- cat(" * ", formatC(res, digits = 40), "\n", sep = "")
- cat(" */\n")
-
- cat("dist = new KolmogorovSmirnovDistributionImpl(", n, ");\n", sep = "")
- #cat("Assert.assertEquals(", formatC(res, digits = 40), ", dist.cdf(", p, ", true), TOLERANCE);\n", sep = "")
- cat("Assert.assertEquals(", formatC(res, digits = 40), ", dist.cdf(", p, ", false), TOLERANCE);\n", sep = "")
- cat("\n")
-
- #cat("System.out.println(\"", formatC(res, digits = 20), " - \" + dist.cdf(", p, ", false) + \" = \" + (", res, " - dist.cdf(", p, ", false)));\n", sep = "")
- }
-}
-
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/KolmogorovSmirnovTestCases.R
----------------------------------------------------------------------
diff --git a/src/test/R/KolmogorovSmirnovTestCases.R b/src/test/R/KolmogorovSmirnovTestCases.R
deleted file mode 100644
index 19b3c13..0000000
--- a/src/test/R/KolmogorovSmirnovTestCases.R
+++ /dev/null
@@ -1,208 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate KolmogorovSmirnov tests in
-# org.apache.commons.complex.stat.inference.KolmogorovSmirnovTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-# NOTE: the 2-sample bootstrap test requires the "Matching" library
-## https://cran.r-project.org/web/packages/Matching/index.html
-## See http://sekhon.berkeley.edu/matching for additional documentation.
-## Jasjeet S. Sekhon. 2011. ``Multivariate and Propensity Score Matching
-## Software with Automated Balance Optimization: The Matching package for R.''
-## Journal of Statistical Software, 42(7): 1-52.
-#
-#------------------------------------------------------------------------------
-tol <- 1E-14 # error tolerance for tests
-#------------------------------------------------------------------------------
-# Function definitions
-
-source("testFunctions") # utility test functions
-require("Matching") # for ks.boot
-
-verifyOneSampleGaussian <- function(data, expectedP, expectedD, mean, sigma, exact, tol, desc) {
- results <- ks.test(data, "pnorm", mean, sigma, exact = exact)
- if (assertEquals(expectedP, results$p.value, tol, "p-value")) {
- displayPadded(c(desc," p-value test"), SUCCEEDED, WIDTH)
- } else {
- displayPadded(c(desc, " p-value test"), FAILED, WIDTH)
- }
- if (assertEquals(expectedD, results$statistic, tol, "D statistic value")) {
- displayPadded(c(desc," D statistic test"), SUCCEEDED, WIDTH)
- } else {
- displayPadded(c(desc, " D statistic test"), FAILED, WIDTH)
- }
-}
-
-verifyOneSampleUniform <- function(data, expectedP, expectedD, min, max, exact, tol, desc) {
- results <- ks.test(data, "punif", min, max, exact = exact)
- if (assertEquals(expectedP, results$p.value, tol, "p-value")) {
- displayPadded(c(desc," p-value test"), SUCCEEDED, WIDTH)
- } else {
- displayPadded(c(desc, " p-value test"), FAILED, WIDTH)
- }
- if (assertEquals(expectedD, results$statistic, tol, "D statistic value")) {
- displayPadded(c(desc," D statistic test"), SUCCEEDED, WIDTH)
- } else {
- displayPadded(c(desc, " D statistic test"), FAILED, WIDTH)
- }
-}
-
-verifyTwoSampleLargeSamples <- function(sample1, sample2, expectedP, expectedD, tol, desc) {
- results <- ks.test(sample1, sample2)
- if (assertEquals(expectedP, results$p.value, tol, "p-value")) {
- displayPadded(c(desc," p-value test"), SUCCEEDED, WIDTH)
- } else {
- displayPadded(c(desc, " p-value test"), FAILED, WIDTH)
- }
- if (assertEquals(expectedD, results$statistic, tol, "D statistic value")) {
- displayPadded(c(desc," D statistic test"), SUCCEEDED, WIDTH)
- } else {
- displayPadded(c(desc, " D statistic test"), FAILED, WIDTH)
- }
-}
-
-verifyTwoSampleSmallSamplesExact <- function(sample1, sample2, expectedP, expectedD, tol, desc) {
- results <- ks.test(sample1, sample2, exact = TRUE)
- if (assertEquals(expectedP, results$p.value, tol, "p-value")) {
- displayPadded(c(desc," p-value test"), SUCCEEDED, WIDTH)
- } else {
- displayPadded(c(desc, " p-value test"), FAILED, WIDTH)
- }
- if (assertEquals(expectedD, results$statistic, tol, "D statistic value")) {
- displayPadded(c(desc," D statistic test"), SUCCEEDED, WIDTH)
- } else {
- displayPadded(c(desc, " D statistic test"), FAILED, WIDTH)
- }
-}
-
-verifyTwoSampleBootstrap <- function(sample1, sample2, expectedP, tol, desc) {
- results <- ks.boot(sample1, sample2,nboots=10000 )
- if (assertEquals(expectedP, results$ks.boot.pvalue, tol, "p-value")) {
- displayPadded(c(desc, " p-value test"), SUCCEEDED, WIDTH)
- } else {
- displayPadded(c(desc, " p-value test"), FAILED, WIDTH)
- }
-}
-
-cat("KolmogorovSmirnovTest test cases\n")
-
-gaussian <- c(0.26055895, -0.63665233, 1.51221323, 0.61246988, -0.03013003, -1.73025682,
- -0.51435805, 0.70494168, 0.18242945, 0.94734336, -0.04286604, -0.37931719, -1.07026403, -2.05861425,
- 0.11201862, 0.71400136, -0.52122185, -0.02478725, -1.86811649, -1.79907688, 0.15046279, 1.32390193,
- 1.55889719, 1.83149171, -0.03948003, -0.98579207, -0.76790540, 0.89080682, 0.19532153, 0.40692841,
- 0.15047336, -0.58546562, -0.39865469, 0.77604271, -0.65188221, -1.80368554, 0.65273365, -0.75283102,
- -1.91022150, -0.07640869, -1.08681188, -0.89270600, 2.09017508, 0.43907981, 0.10744033, -0.70961218,
- 1.15707300, 0.44560525, -2.04593349, 0.53816843, -0.08366640, 0.24652218, 1.80549401, -0.99220707,
- -1.14589408, -0.27170290, -0.49696855, 0.00968353, -1.87113545, -1.91116529, 0.97151891, -0.73576115,
- -0.59437029, 0.72148436, 0.01747695, -0.62601157, -1.00971538, -1.42691397, 1.03250131, -0.30672627,
- -0.15353992, -1.19976069, -0.68364218, 0.37525652, -0.46592881, -0.52116168, -0.17162202, 1.04679215,
- 0.25165971, -0.04125231, -0.23756244, -0.93389975, 0.75551407, 0.08347445, -0.27482228, -0.4717632,
- -0.1867746, -0.1166976, 0.5763333, 0.1307952, 0.7630584, -0.3616248, 2.1383790,-0.7946630,
- 0.0231885, 0.7919195, 1.6057144, -0.3802508, 0.1229078, 1.5252901, -0.8543149, 0.3025040)
-
-shortGaussian <- gaussian[1:50]
-
-gaussian2 <- c(2.88041498038308, -0.632349445671017, 0.402121295225571, 0.692626364613243, 1.30693446815426,
- -0.714176317131286, -0.233169206599583, 1.09113298322107, -1.53149079994305, 1.23259966205809,
- 1.01389927412503, 0.0143898711497477, -0.512813545447559, 2.79364360835469, 0.662008875538092,
- 1.04861546834788, -0.321280099931466, 0.250296656278743, 1.75820367603736, -2.31433523590905,
- -0.462694696086403, 0.187725700950191, -2.24410950019152, 2.83473751105445, 0.252460174391016,
- 1.39051945380281, -1.56270144203134, 0.998522814471644, -1.50147469080896, 0.145307533554146,
- 0.469089457043406, -0.0914780723809334, -0.123446939266548, -0.610513388160565, -3.71548343891957,
- -0.329577317349478, -0.312973794075871, 2.02051909758923, 2.85214308266271, 0.0193222002327237,
- -0.0322422268266562, 0.514736012106768, 0.231484953375887, -2.22468798953629, 1.42197716075595,
- 2.69988043856357, 0.0443757119128293, 0.721536984407798, -0.0445688839903234, -0.294372724550705,
- 0.234041580912698, -0.868973119365727, 1.3524893453845, -0.931054600134503, -0.263514296006792,
- 0.540949457402918, -0.882544288773685, -0.34148675747989, 1.56664494810034, 2.19850536566584,
- -0.667972122928022, -0.70889669526203, -0.00251758193079668, 2.39527162977682, -2.7559594317269,
- -0.547393502656671, -2.62144031572617, 2.81504147017922, -1.02036850201042, -1.00713927602786,
- -0.520197775122254, 1.00625480138649, 2.46756916531313, 1.64364743727799, 0.704545210648595,
- -0.425885789416992, -1.78387854908546, -0.286783886710481, 0.404183648369076, -0.369324280845769,
- -0.0391185138840443, 2.41257787857293, 2.49744281317859, -0.826964496939021, -0.792555379958975,
- 1.81097685787403, -0.475014580016638, 1.23387615291805, 0.646615294802053, 1.88496377454523, 1.20390698380814,
- -0.27812153371728, 2.50149494533101, 0.406964323253817, -1.72253451309982, 1.98432494184332, 2.2223658560333,
- 0.393086362404685, -0.504073151377089, -0.0484610869883821)
-
-uniform <- c(0.7930305, 0.6424382, 0.8747699, 0.7156518, 0.1845909, 0.2022326,
- 0.4877206, 0.8928752, 0.2293062, 0.4222006, 0.1610459, 0.2830535, 0.9946345, 0.7329499,
- 0.26411126, 0.87958133, 0.29827437, 0.39185988, 0.38351185, 0.36359611, 0.48646472, 0.05577866,
- 0.56152250, 0.52672013, 0.13171783, 0.95864085, 0.03060207, 0.33514887, 0.72508148, 0.38901437,
- 0.9978665, 0.5981300, 0.1065388, 0.7036991, 0.1071584, 0.4423963, 0.1107071, 0.6437221,
- 0.58523872, 0.05044634, 0.65999539, 0.37367260, 0.73270024, 0.47473755, 0.74661163, 0.50765549,
- 0.05377347, 0.40998009, 0.55235182, 0.21361998, 0.63117971, 0.18109222, 0.89153510, 0.23203248,
- 0.6177106, 0.6856418, 0.2158557, 0.9870501, 0.2036914, 0.2100311, 0.9065020, 0.7459159,
- 0.56631790, 0.06753629, 0.39684629, 0.52504615, 0.14199103, 0.78551120, 0.90503321, 0.80452362,
- 0.9960115, 0.8172592, 0.5831134, 0.8794187, 0.2021501, 0.2923505, 0.9561824, 0.8792248,
- 0.85201008, 0.02945562, 0.26200374, 0.11382818, 0.17238856, 0.36449473, 0.69688273, 0.96216330,
- 0.4859432,0.4503438, 0.1917656, 0.8357845, 0.9957812, 0.4633570, 0.8654599, 0.4597996,
- 0.68190289, 0.58887855, 0.09359396, 0.98081979, 0.73659533, 0.89344777, 0.18903099, 0.97660425)
-
-smallSample1 <- c(6, 7, 9, 13, 19, 21, 22, 23, 24)
-smallSample2 <- c(10, 11, 12, 16, 20, 27, 28, 32, 44, 54)
-smallSample3 <- c(6, 7, 9, 13, 19, 21, 22, 23, 24, 29, 30, 34, 36, 41, 45, 47, 51, 63, 33, 91)
-smallSample4 <- c(10, 11, 12, 16, 20, 27, 28, 32, 44, 54, 56, 57, 64, 69, 71, 80, 81, 88, 90)
-smallSample5 <- c(-10, -5, 17, 21, 22, 23, 24, 30, 44, 50, 56, 57, 59, 67, 73, 75, 77, 78, 79, 80, 81, 83, 84, 85, 88, 90,
- 92, 93, 94, 95, 98, 100, 101, 103, 105, 110)
-smallSample6 <- c(-2, -1, 0, 10, 14, 15, 16, 20, 25, 26, 27, 31, 32, 33, 34, 45, 47, 48, 51, 52, 53, 54, 60, 61, 62, 63,
- 74, 82, 106, 107, 109, 11, 112, 113, 114)
-bootSample1 <- c(0, 2, 4, 6, 8, 8, 10, 15, 22, 30, 33, 36, 38)
-bootSample2 <- c(9, 17, 20, 33, 40, 51, 60, 60, 72, 90, 101)
-roundingSample1 <- c(2,4,6,8,9,10,11,12,13)
-roundingSample2 <- c(0,1,3,5,7)
-
-shortUniform <- uniform[1:20]
-
-verifyOneSampleGaussian(gaussian, 0.3172069207622391, 0.0932947561266756, 0, 1,
-TRUE, tol, "One sample gaussian - gaussian values")
-
-verifyOneSampleGaussian(shortGaussian, 0.683736463728347, 0.09820779969463278, 0, 1,
-TRUE, tol, "One sample gaussian - gaussian values - small sample")
-
-verifyOneSampleGaussian(uniform, 8.881784197001252E-16, 0.5117493931609258, 0, 1,
-TRUE, tol, "One sample gaussian - uniform values")
-
-verifyOneSampleUniform(uniform, 8.881784197001252E-16, 0.5400666982352942, -0.5, 0.5,
-TRUE, tol, "One sample uniform - uniform values")
-
-verifyOneSampleUniform(shortUniform, 4.117594598618268E-9, 0.6610459, -0.5, 0.5,
-TRUE, tol, "One sample uniform - uniform values - small sample")
-
-verifyOneSampleUniform(gaussian, 4.9405812774239166E-11, 0.3401058049019608, -0.5, 0.5,
-TRUE, tol, "One sample uniform - unit normal values")
-
-verifyTwoSampleLargeSamples(gaussian, gaussian2, 0.0319983962391632, 0.202352941176471, tol,
-"Two sample N(0, 1) vs N(0, 1.6)")
-
-verifyTwoSampleSmallSamplesExact(smallSample1, smallSample2, 0.105577085453247, .5, tol,
-"Two sample small samples exact 1")
-
-verifyTwoSampleSmallSamplesExact(smallSample3, smallSample4, 0.046298660942952, 0.426315789473684, tol,
-"Two sample small samples exact 2")
-
-verifyTwoSampleSmallSamplesExact(smallSample5, smallSample6, 0.00300743602233366, 0.41031746031746, tol,
-"Two sample small samples exact 3")
-
-verifyTwoSampleBootstrap(bootSample1, bootSample2, 0.0059, 1E-3, "Two sample bootstrap - isolated failures possible")
-verifyTwoSampleBootstrap(gaussian, gaussian2, 0.0237, 1E-2, "Two sample bootstrap - isolated failures possible")
-verifyTwoSampleBootstrap(roundingSample1, roundingSample2, 0.06303, 1E-2, "Two sample bootstrap - isolated failures possible")
-
-displayDashes(WIDTH)
-
-
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/LevyDistributionTestCases.R
----------------------------------------------------------------------
diff --git a/src/test/R/LevyDistributionTestCases.R b/src/test/R/LevyDistributionTestCases.R
deleted file mode 100644
index e1300a7..0000000
--- a/src/test/R/LevyDistributionTestCases.R
+++ /dev/null
@@ -1,88 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate L�vy distribution tests in
-# org.apache.commons.complex.distribution.LevyDistributionTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-# R functions used
-# dlevy(q, m=0, s=1, log=FALSE)
-# plevy(q, m=0, s=1)
-# qlevy(p, m=0, s=1)
-#-----------------------------------------------------------------------------
-tol <- 1E-9
-
-# Function definitions
-
-source("testFunctions") # utility test functions
-
-# function to verify distribution computations
-
-verifyDistribution <- function(points, expected, m, s, tol) {
- rDistValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDistValues[i] <- plevy(point, m, s)
- }
- output <- c("Distribution test m = ",m,", s = ", s)
- if (assertEquals(expected, rDistValues, tol, "Distribution Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify density computations
-
-verifyDensity <- function(points, expected, m, s, tol) {
- rDensityValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDensityValues[i] <- dlevy(point, m, s, log=FALSE)
- }
- output <- c("Density test m = ",m,", s = ", s)
- if (assertEquals(expected, rDensityValues, tol, "Density Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-#--------------------------------------------------------------------------
-cat("Levy test cases\n")
-
-m <- 1.2
-s <- 0.4
-distributionPoints <- c(1.2001, 1.21, 1.225, 1.25, 1.3, 1.9, 3.4, 5.6)
-densityValues <- c(0.0, 5.200563737654472E-7, 0.021412836122382383, 0.4133397070818418, 1.0798193302637613, 0.3237493191610873, 0.07060325500936372, 0.026122839883975738)
-distributionValues <- c(0.0, 2.539628589470901E-10, 6.334248366624259E-5, 0.004677734981047284, 0.04550026389635843, 0.4496917979688907, 0.6698153575994166, 0.763024600552995)
-verifyDistribution(distributionPoints, distributionValues, m, s, tol)
-verifyDensity(distributionPoints, densityValues, m, s, tol)
-
-m <- 5
-s <- 1.3
-distributionPoints <- c(5.0001, 6, 7, 8, 9, 10, 11, 12, 13, 14)
-densityValues <- c(0.0, 0.23745992633364185, 0.1161959636020616, 0.07048597672583455, 0.04833023442399538, 0.03572468867742048, 0.02777194506550441, 0.022382435270909086, 0.018533623436073274, 0.0156730047506865)
-distributionValues <- c(0.0, 0.25421322360396437, 0.42011267955064, 0.5103578488686935, 0.5686182086635944, 0.6101201547975077, 0.6415915735304425, 0.6665077778509312, 0.6868651803414656, 0.7039020091632311)
-verifyDistribution(distributionPoints, distributionValues, m, s, tol)
-verifyDensity(distributionPoints, densityValues, m, s, tol)
-
-displayDashes(WIDTH)
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/README.txt
----------------------------------------------------------------------
diff --git a/src/test/R/README.txt b/src/test/R/README.txt
deleted file mode 100644
index eb83ecc..0000000
--- a/src/test/R/README.txt
+++ /dev/null
@@ -1,168 +0,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.
-#
-#------------------------------------------------------------------------------
-
-INTRODUCTION
-
-The purpose of the R programs included in this directory is to validate
-the target values used in Apache commons math unit tests. Success running the
-R and commons-math tests on a platform (OS and R version) means that R and
-commons-math give results for the test cases that are close in value. The
-tests include configurable tolerance levels; but care must be taken in changing
-these, since in most cases the pre-set tolerance is close to the number of
-decimal digits used in expressing the expected values (both here and in the
-corresponding commons-math unit tests).
-
-Of course it is always possible that both R and commons-math give incorrect
-values for test cases, so these tests should not be interpreted as definitive
-in any absolute sense. The value of developing and running the tests is really
-to generate questions (and answers!) when the two systems give different
-results.
-
-Contributions of additional test cases (both R and Junit code) or just
-R programs to validate commons-math tests that are not covered here would be
-greatly appreciated.
-
-SETUP
-
-0) Download and install R. You can get R here
-http://www.r-project.org/
-Follow the install instructions and make sure that you can launch R from this
-(i.e., either explitly add R to your OS path or let the install package do it
-for you).
-
-1) Launch R from this directory and type
-> source("testAll")
-to an R prompt. This should produce output to the console similar to this:
-
-Binomial test cases
-Density test n = 10, p = 0.7...........................................SUCCEEDED
-Distribution test n = 10, p = 0.7......................................SUCCEEDED
-Inverse Distribution test n = 10, p = 0.7..............................SUCCEEDED
-Density test n = 5, p = 0..............................................SUCCEEDED
-Distribution test n = 5, p = 0.........................................SUCCEEDED
-Density test n = 5, p = 1..............................................SUCCEEDED
-Distribution test n = 5, p = 1.........................................SUCCEEDED
---------------------------------------------------------------------------------
-Normal test cases
-Distribution test mu = 2.1, sigma = 1.4................................SUCCEEDED
-Distribution test mu = 2.1, sigma = 1.4................................SUCCEEDED
-Distribution test mu = 0, sigma = 1....................................SUCCEEDED
-Distribution test mu = 0, sigma = 0.1..................................SUCCEEDED
---------------------------------------------------------------------------------
-...
-<more test reports>
-
-
-WORKING WITH THE TESTS
-
-The R distribution comes with online manuals that you can view by launching
-a browser instance and then entering
-
-> help.start()
-
-at an R prompt. Poking about in the test case files and the online docs should
-bring you up to speed fairly quickly. Here are some basic things to get
-you started. I should note at this point that I am by no means an expert R
-programmer, so some things may not be implemented in the the nicest way.
-Comments / suggestions for improvement are welcome!
-
-All of the test cases use some basic functions and global constants (screen
-width and success / failure strings) defined in "testFunctions." The
-R "source" function is used to "import" these functions into each of the test
-programs. The "testAll" program pulls together and executes all of the
-individual test programs. You can execute any one of them by just entering
-
-> source(<program-name>).
-
-The "assertEquals" function in the testFunctions file mimics the similarly
-named function used by Junit:
-
-assertEquals <- function(expected, observed, tol, message) {
- if(any(abs(expected - observed) > tol)) {
- cat("FAILURE: ",message,"\n")
- cat("EXPECTED: ",expected,"\n")
- cat("OBSERVED: ",observed,"\n")
- return(0)
- } else {
- return(1)
- }
-}
-
-The <expected> and <observed> arguments can be scalar values, vectors or
-matrices. If the arguments are vectors or matrices, corresponding entries
-are compared.
-
-The standard pattern used throughout the tests looks like this (from
-binomialTestCases):
-
-Start by defining a "verification function" -- in this example a function to
-verify computation of binomial probabilities. The <points> argument is a vector
-of integer values to feed into the density function, <expected> is a vector of
-the computed probabilies from the commons-math Junit tests, <n> and <p> are
-parameters of the distribution and <tol> is the error tolerance of the test.
-The function computes the probabilities using R and compares the values that
-R produces with those in the <expected> vector.
-
-verifyDensity <- function(points, expected, n, p, tol) {
- rDensityValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDensityValues[i] <- dbinom(point, n, p, log = FALSE)
- }
- output <- c("Density test n = ", n, ", p = ", p)
- if (assertEquals(expected,rDensityValues,tol,"Density Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-The displayPadded function just displays its first and second arguments with
-enough dots in between to make the whole string WIDTH characters long. It is
-defined in testFunctions.
-
-Then call this function with different parameters corresponding to the different
-Junit test cases:
-
-size <- 10.0
-probability <- 0.70
-
-densityPoints <- c(-1,0,1,2,3,4,5,6,7,8,9,10,11)
-densityValues <- c(0, 0.0000, 0.0001, 0.0014, 0.0090, 0.0368, 0.1029,
- 0.2001, 0.2668, 0.2335, 0.1211, 0.0282, 0)
-...
-verifyDensity(densityPoints, densityValues, size, probability, tol)
-
-If the values computed by R match the target values in densityValues, this will
-produce one line of output to the console:
-
-Density test n = 10, p = 0.7...........................................SUCCEEDED
-
-If you modify the value of tol set at the top of binomialTestCases to make the
-test more sensitive than the number of digits specified in the densityValues
-vector, it will fail, producing the following output, showing the failure and
-the expected and observed values:
-
-FAILURE: Density Values
-EXPECTED: 0 0 1e-04 0.0014 0.009 0.0368 0.1029 0.2001 0.2668 0.2335 0.1211 /
- 0.0282 0
-OBSERVED: 0 5.9049e-06 0.000137781 0.0014467005 0.009001692 0.036756909 /
-0.1029193452 0.200120949 0.266827932 0.2334744405 0.121060821 0.0282475249 0
-Density test n = 10, p = 0.7..............................................FAILED
-
-
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/TDistributionTestCases.R
----------------------------------------------------------------------
diff --git a/src/test/R/TDistributionTestCases.R b/src/test/R/TDistributionTestCases.R
deleted file mode 100644
index 6f91269..0000000
--- a/src/test/R/TDistributionTestCases.R
+++ /dev/null
@@ -1,100 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate T distribution tests in
-# org.apache.commons.math.distribution.TDistributionTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-#-----------------------------------------------------------------------------
-tol <- 1E-9
-
-# Function definitions
-source("testFunctions") # utility test functions
-
-# function to verify distribution computations
-verifyDistribution <- function(points, expected, df, tol) {
- rDistValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDistValues[i] <- pt(point, df, log = FALSE)
- }
- output <- c("Distribution test df = ", df)
- if (assertEquals(expected, rDistValues, tol, "Distribution Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify density computations
-verifyDensity <- function(points, expected, df, tol) {
- rDensityValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDensityValues[i] <- dt(point, df, log = FALSE)
- }
- output <- c("Density test df = ", df)
- if (assertEquals(expected, rDensityValues, tol, "Density Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify quantiles
-verifyQuantiles <- function(points, expected, df, tol) {
- rQuantileValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rQuantileValues[i] <- qt(point, df, log = FALSE)
- }
- output <- c("Quantile test df = ", df)
- if (assertEquals(expected, rQuantileValues, tol, "Quantile Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-#--------------------------------------------------------------------------
-cat("T Distribution test cases\n")
-
-df <- 5
-distributionValues <- c(0.001, 0.01, 0.025, 0.05, 0.1, 0.999, 0.990, 0.975, 0.950, 0.900)
-densityValues <- c(0.000756494565517, 0.0109109752919, 0.0303377878006, 0.0637967988952, 0.128289492005,
- 0.000756494565517, 0.0109109752919, 0.0303377878006, 0.0637967988952, 0.128289492005)
-distributionPoints <- c(-5.89342953136, -3.36492999891, -2.57058183564, -2.01504837333, -1.47588404882,
- 5.89342953136, 3.36492999891, 2.57058183564, 2.01504837333, 1.47588404882)
-verifyQuantiles(distributionValues, distributionPoints, df, tol)
-verifyDistribution(distributionPoints, distributionValues, df, tol)
-verifyDensity(distributionPoints, densityValues, df, tol)
-
-df <- 1
-densityValues <- c(3.14158231817e-06, 0.000314055924703, 0.00195946145194, 0.00778959736375, 0.0303958893917,
- 3.14158231817e-06, 0.000314055924703, 0.00195946145194, 0.00778959736375, 0.0303958893917)
-distributionPoints <- c(-318.308838986, -31.8205159538, -12.7062047362, -6.31375151468, -3.07768353718,
- 318.308838986, 31.8205159538, 12.7062047362, 6.31375151468, 3.07768353718)
-verifyQuantiles(distributionValues, distributionPoints, df, tol)
-verifyDistribution(distributionPoints, distributionValues, df, tol)
-verifyDensity(distributionPoints, densityValues, df, tol)
-
-displayDashes(WIDTH)
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/TTestCases
----------------------------------------------------------------------
diff --git a/src/test/R/TTestCases b/src/test/R/TTestCases
deleted file mode 100644
index 38adf7b..0000000
--- a/src/test/R/TTestCases
+++ /dev/null
@@ -1,106 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate TTest tests in
-# org.apache.commons.math.inference.TTestImpl
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-# R functions used
-# t.test(x, y = NULL, alternative = c("two.sided", "less", "greater"),
-# mu = 0, paired = FALSE, var.equal = FALSE, ... )
-# Arguments
-# x a numeric vector of data values.
-# y an optional numeric vector data values.
-# alternative a character string specifying the alternative hypothesis,
-# must be one of "two.sided" (default), "greater" or "less". You can specify
-# just the initial letter.
-# mu a number indicating the true value of the mean (or difference in means
-# if you are performing a two sample test).
-# paired a logical indicating whether you want a paired t-test.
-# var.equal a logical variable indicating whether to treat the two
-# variances as being equal.
-# If TRUE then the pooled variance is used to estimate the variance,
-# otherwise the Welch (or Satterthwaite) approximation to the degrees
-# of freedom is used.
-#------------------------------------------------------------------------------
-tol <- 1E-10 # error tolerance for tests
-#------------------------------------------------------------------------------
-# Function definitions
-#------------------------------------------------------------------------------
-source("testFunctions") # utility test functions
-#------------------------------------------------------------------------------
-# Verification function
-#
-verifyTest <- function(out,expectedP, expectedT,
- tol) {
- if (assertEquals(expectedP, out$p.value, tol,
- "Ttest p value")) {
- displayPadded(output, SUCCEEDED, 80)
- } else {
- displayPadded(output, FAILED, 80)
- }
- output <- c("t test test statistic")
- if (assertEquals(expectedT, out$statistic, tol,
- "Ttest t statistic")) {
- displayPadded(output, SUCCEEDED, 80)
- } else {
- displayPadded(output, FAILED, 80)
- }
- displayDashes(WIDTH)
-}
-
-cat("One-sample, two-sided TTest test cases \n")
-sample1 <- c(93.0, 103.0, 95.0, 101.0, 91.0, 105.0, 96.0, 94.0, 101.0, 88.0,
- 98.0, 94.0, 101.0, 92.0, 95.0)
-out <- t.test(sample1, mu=100.0)
-expectedP <- 0.0136390585873
-expectedT<- -2.81976445346
-verifyTest(out,expectedP, expectedT, tol)
-
-cat("One-sample, one-sided TTest test cases \n")
-sample1 <- c(2, 0, 6, 6, 3, 3, 2, 3, -6, 6, 6, 6, 3, 0, 1, 1, 0, 2, 3, 3)
-out <- t.test(sample1, mu=0.0, alternative="g")
-expectedP <- 0.000521637019637
-expectedT<- 3.86485535541
-verifyTest(out,expectedP, expectedT, tol)
-
-cat("Homoscedastic TTest test cases \n")
-sample1 <- c(2, 4, 6, 8, 10, 97)
-sample2 <- c(4, 6, 8, 10, 16)
-out <- t.test(sample1,sample2,var.equal = TRUE)
-expectedP <- 0.4833963785
-expectedT<- 0.73096310086
-verifyTest(out,expectedP, expectedT, tol)
-
-cat("Heteroscedastic TTest test cases \n")
-sample1 <- c(7, -4, 18, 17, -3, -5, 1, 10, 11, -2)
-sample2 <- c(-1, 12, -1, -3, 3, -5, 5, 2, -11, -1, -3)
-out <- t.test(sample1,sample2,var.equal = FALSE)
-expectedP <- 0.128839369622
-expectedT<- 1.60371728768
-verifyTest(out,expectedP, expectedT, tol)
-
-cat("Small sample, heteroscedastic test cases \n")
-sample1 <- c(1,3)
-sample2 <- c(4,5)
-out <- t.test(sample1,sample2,var.equal = FALSE)
-expectedP <- 0.198727388935
-expectedT<- -2.2360679775
-verifyTest(out,expectedP, expectedT, tol)
-
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/WeibullDistributionTestCases.R
----------------------------------------------------------------------
diff --git a/src/test/R/WeibullDistributionTestCases.R b/src/test/R/WeibullDistributionTestCases.R
deleted file mode 100644
index 7228641..0000000
--- a/src/test/R/WeibullDistributionTestCases.R
+++ /dev/null
@@ -1,92 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate Weibull distribution tests in
-# org.apache.commons.math.distribution.GammaDistributionTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-#-----------------------------------------------------------------------------
-tol <- 1E-9
-
-# Function definitions
-source("testFunctions") # utility test functions
-
-# function to verify distribution computations
-verifyDistribution <- function(points, expected, alpha, beta, tol) {
- rDistValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDistValues[i] <- pweibull(point, shape=alpha, scale=beta, log = FALSE)
- }
- output <- c("Distribution test shape = ", shape, " scale = ", scale)
- if (assertEquals(expected, rDistValues, tol, "Distribution Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify density computations
-verifyDensity <- function(points, expected, alpha, beta, tol) {
- rDensityValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDensityValues[i] <- dweibull(point, shape=alpha, scale=beta, log = FALSE)
- }
- output <- c("Density test shape = ", shape, " scale = ", scale)
- if (assertEquals(expected, rDensityValues, tol, "Density Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify quantiles
-verifyQuantiles <- function(points, expected, alpha, beta, tol) {
- rQuantileValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rQuantileValues[i] <- qweibull(point, shape=alpha, scale=beta, log = FALSE)
- }
- output <- c("Quantile test shape = ", shape, " scale = ", scale)
- if (assertEquals(expected, rQuantileValues, tol, "Quantile Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-#--------------------------------------------------------------------------
-cat("Weibull Distribution test cases\n")
-
-shape <- 1.2
-scale <- 2.1
-distributionValues <- c(0.001, 0.01, 0.025, 0.05, 0.1, 0.999, 0.990, 0.975, 0.950, 0.900)
-densityValues <- c(0.180535929306, 0.262801138133, 0.301905425199, 0.330899152971, 0.353441418887, 0.000788590320203,
- 0.00737060094841, 0.0177576041516, 0.0343043442574, 0.065664589369)
-distributionPoints <- c(0.00664355180993, 0.0454328283309, 0.0981162737374, 0.176713524579, 0.321946865392,
- 10.5115496887, 7.4976304671, 6.23205600701, 5.23968436955, 4.20790282578)
-verifyQuantiles(distributionValues, distributionPoints, shape, scale, tol)
-verifyDistribution(distributionPoints, distributionValues, shape, scale, tol)
-verifyDensity(distributionPoints, densityValues, shape, scale, tol)
-
-displayDashes(WIDTH)
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/anovaTestCases
----------------------------------------------------------------------
diff --git a/src/test/R/anovaTestCases b/src/test/R/anovaTestCases
deleted file mode 100644
index 1c1dd7c..0000000
--- a/src/test/R/anovaTestCases
+++ /dev/null
@@ -1,72 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate Binomial distribution tests in
-# org.apache.commons.math.distribution.BinomialDistributionTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-# R functions used
-# anova(model) <- anova
-# lm(frame) <- linear model
-#------------------------------------------------------------------------------
-tol <- 1E-12 # error tolerance for tests
-#------------------------------------------------------------------------------
-# Function definitions
-
-source("testFunctions") # utility test functions
-options(digits=16) # override number of digits displayed
-
-# function to verify anova computations
-
-verifyAnova <- function(frame, expectedP, expectedF, frameName) {
- a <- anova(lm(frame))
- p <- a$"Pr(>F)"[1]
- f <- a$"F value"[1]
- output <- c("P-value test frame = ", frameName)
- if (assertEquals(expectedP,p,tol,"P value")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
- output <- c("F-value test frame = ", frameName)
- if (assertEquals(expectedF,f,tol,"F value")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-#--------------------------------------------------------------------------
-cat("Anova test cases\n")
-classA <- c(93.0, 103.0, 95.0, 101.0, 91.0, 105.0, 96.0, 94.0, 101.0)
-classB <- c(99.0, 92.0, 102.0, 100.0, 102.0, 89.0)
-classC <- c(110.0, 115.0, 111.0, 117.0, 128.0, 117.0)
-
-threeClasses = data.frame(val = c(classA, classB, classC),
-class=c(rep("classA", length(classA)),
- rep("classB", length(classB)),
- rep("classC", length(classC))))
-
-verifyAnova(threeClasses,6.959446e-06, 24.67361709460624, "Three classes")
-
-twoClasses = data.frame(val = c(classA, classB),
-class=c(rep("classA", length(classA)), rep("classB", length(classB))))
-verifyAnova(twoClasses, 0.904212960464, 0.0150579150579, "Two classes")
-
-displayDashes(WIDTH)
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/binomialTestCases
----------------------------------------------------------------------
diff --git a/src/test/R/binomialTestCases b/src/test/R/binomialTestCases
deleted file mode 100644
index 144a221..0000000
--- a/src/test/R/binomialTestCases
+++ /dev/null
@@ -1,127 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate Binomial distribution tests in
-# org.apache.commons.math.distribution.BinomialDistributionTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-# R functions used
-# dbinom(x, size, prob, log = FALSE) <- density
-# pbinom(q, size, prob, lower.tail = TRUE, log.p = FALSE) <- distribution
-# qbinom(p, size, prob, lower.tail = TRUE, log.p = FALSE) <- quantiles
-#------------------------------------------------------------------------------
-tol <- 1E-4 # error tolerance for tests
-#------------------------------------------------------------------------------
-# Function definitions
-
-source("testFunctions") # utility test functions
-
-# function to verify density computations
-
-verifyDensity <- function(points, expected, n, p, tol) {
- rDensityValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDensityValues[i] <- dbinom(point, n, p, log = FALSE)
- }
- output <- c("Density test n = ", n, ", p = ", p)
- if (assertEquals(expected,rDensityValues,tol,"Density Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify distribution computations
-
-verifyDistribution <- function(points, expected, n, p, tol) {
- rDistValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDistValues[i] <- pbinom(point, n, p, log = FALSE)
- }
- output <- c("Distribution test n = ", n, ", p = ", p)
- if (assertEquals(expected,rDistValues,tol,"Distribution Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-#--------------------------------------------------------------------------
-cat("Binomial test cases\n")
-
-size <- 10.0
-probability <- 0.70
-
-densityPoints <- c(-1,0,1,2,3,4,5,6,7,8,9,10,11)
-densityValues <- c(0, 0.0000, 0.0001, 0.0014, 0.0090, 0.0368, 0.1029,
- 0.2001, 0.2668, 0.2335, 0.1211, 0.0282, 0)
-distributionValues <- c(0, 0.0000, 0.0001, 0.0016, 0.0106, 0.0473,
- 0.1503, 0.3504, 0.6172, 0.8507, 0.9718, 1, 1)
-inverseCumPoints <- c( 0.001, 0.010, 0.025, 0.050, 0.100, 0.999,
- 0.990, 0.975, 0.950, 0.900)
-inverseCumValues <- c(1, 2, 3, 4, 4, 9, 9, 9, 8, 8)
-
-verifyDensity(densityPoints,densityValues,size,probability,tol)
-verifyDistribution(densityPoints, distributionValues, size, probability, tol)
-
-i <- 0
-rInverseCumValues <- rep(0,length(inverseCumPoints))
-for (point in inverseCumPoints) {
- i <- i + 1
- rInverseCumValues[i] <- qbinom(point, size, probability, log = FALSE)
-}
-
-output <- c("Inverse Distribution test n = ", size, ", p = ", probability)
-# R defines quantiles from the right, need to subtract one
-if (assertEquals(inverseCumValues, rInverseCumValues-1, tol,
- "Inverse Dist Values")) {
- displayPadded(output, SUCCEEDED, 80)
-} else {
- displayPadded(output, FAILED, 80)
-}
-
-# Degenerate cases
-
-size <- 5
-probability <- 0.0
-
-densityPoints <- c(-1, 0, 1, 10, 11)
-densityValues <- c(0, 1, 0, 0, 0)
-distributionPoints <- c(-1, 0, 1, 5, 10)
-distributionValues <- c(0, 1, 1, 1, 1)
-
-verifyDensity(densityPoints,densityValues,size,probability,tol)
-verifyDistribution(distributionPoints,distributionValues,size,probability,tol)
-
-size <- 5
-probability <- 1.0
-
-densityPoints <- c(-1, 0, 1, 2, 5, 10)
-densityValues <- c(0, 0, 0, 0, 1, 0)
-distributionPoints <- c(-1, 0, 1, 2, 5, 10)
-distributionValues <- c(0, 0, 0, 0, 1, 1)
-
-verifyDensity(densityPoints,densityValues,size,probability,tol)
-verifyDistribution(distributionPoints,distributionValues,size,probability,tol)
-
-displayDashes(WIDTH)
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/cauchyTestCases.R
----------------------------------------------------------------------
diff --git a/src/test/R/cauchyTestCases.R b/src/test/R/cauchyTestCases.R
deleted file mode 100644
index d0fe442..0000000
--- a/src/test/R/cauchyTestCases.R
+++ /dev/null
@@ -1,97 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate Cauchy distribution tests in
-# org.apache.commons.math.distribution.CauchyDistributionTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-#-----------------------------------------------------------------------------
-tol <- 1E-9
-
-# Function definitions
-
-source("testFunctions") # utility test functions
-
-# function to verify distribution computations
-
-verifyDistribution <- function(points, expected, median, scale, tol) {
- rDistValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDistValues[i] <- pcauchy(point, median, scale, log = FALSE)
- }
- output <- c("Distribution test median = ",median,", scale = ", scale)
- if (assertEquals(expected, rDistValues, tol, "Distribution Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify density computations
-
-verifyDensity <- function(points, expected, median, scale, tol) {
- rDensityValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDensityValues[i] <- dcauchy(point, median, scale, log = FALSE)
- }
- output <- c("Density test median = ",median,", scale = ", scale)
- if (assertEquals(expected, rDensityValues, tol, "Density Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify quantiles
-
-verifyQuantiles <- function(points, expected, median, scale, tol) {
- rQuantileValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rQuantileValues[i] <- qcauchy(point, median, scale, log = FALSE)
- }
- output <- c("Quantile test median = ",median,", scale = ", scale)
- if (assertEquals(expected, rQuantileValues, tol, "Quantile Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-#--------------------------------------------------------------------------
-cat("Cauchy test cases\n")
-
-median <- 1.2
-scale <- 2.1
-distributionValues <- c(0.001, 0.01, 0.025, 0.05, 0.1, 0.999,
- 0.990, 0.975, 0.950, 0.900)
-densityValues <- c(1.49599158008e-06, 0.000149550440335, 0.000933076881878, 0.00370933207799, 0.0144742330437,
- 1.49599158008e-06, 0.000149550440335, 0.000933076881878, 0.00370933207799, 0.0144742330437)
-distributionPoints <- c(-667.24856187, -65.6230835029, -25.4830299460, -12.0588781808, -5.26313542807,
- 669.64856187, 68.0230835029, 27.8830299460, 14.4588781808, 7.66313542807)
-verifyDistribution(distributionPoints, distributionValues, median, scale, tol)
-verifyDensity(distributionPoints, densityValues, median, scale, tol)
-verifyQuantiles(distributionValues, distributionPoints, median, scale, tol)
-
-displayDashes(WIDTH)
[12/31] commons-numbers git commit: Multimodule project setup.
Posted by er...@apache.org.
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexTest.java
----------------------------------------------------------------------
diff --git a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexTest.java b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexTest.java
new file mode 100644
index 0000000..1dbcce1
--- /dev/null
+++ b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexTest.java
@@ -0,0 +1,1477 @@
+/*
+ * 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.
+ */
+
+package org.apache.commons.numbers.complex;
+
+import java.util.List;
+
+import org.apache.commons.numbers.complex.Complex;
+import org.apache.commons.numbers.complex.ComplexUtils;
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+
+
+/**
+ */
+public class ComplexTest {
+
+
+ private double inf = Double.POSITIVE_INFINITY;
+ private double neginf = Double.NEGATIVE_INFINITY;
+ private double nan = Double.NaN;
+ private double pi = Math.PI;
+ private Complex oneInf = new Complex(1, inf);
+ private Complex oneNegInf = new Complex(1, neginf);
+ private Complex infOne = new Complex(inf, 1);
+ private Complex infZero = new Complex(inf, 0);
+ private Complex infNaN = new Complex(inf, nan);
+ private Complex infNegInf = new Complex(inf, neginf);
+ private Complex infInf = new Complex(inf, inf);
+ private Complex negInfInf = new Complex(neginf, inf);
+ private Complex negInfZero = new Complex(neginf, 0);
+ private Complex negInfOne = new Complex(neginf, 1);
+ private Complex negInfNaN = new Complex(neginf, nan);
+ private Complex negInfNegInf = new Complex(neginf, neginf);
+ private Complex oneNaN = new Complex(1, nan);
+ private Complex zeroInf = new Complex(0, inf);
+ private Complex zeroNaN = new Complex(0, nan);
+ private Complex nanInf = new Complex(nan, inf);
+ private Complex nanNegInf = new Complex(nan, neginf);
+ private Complex nanZero = new Complex(nan, 0);
+
+ @Test
+ public void testConstructor() {
+ Complex z = new Complex(3.0, 4.0);
+ Assert.assertEquals(3.0, z.getReal(), 1.0e-5);
+ Assert.assertEquals(4.0, z.getImaginary(), 1.0e-5);
+ }
+
+ @Test
+ public void testConstructorNaN() {
+ Complex z = new Complex(3.0, Double.NaN);
+ Assert.assertTrue(z.isNaN());
+
+ z = new Complex(nan, 4.0);
+ Assert.assertTrue(z.isNaN());
+
+ z = new Complex(3.0, 4.0);
+ Assert.assertFalse(z.isNaN());
+ }
+
+ @Test
+ public void testAbs() {
+ Complex z = new Complex(3.0, 4.0);
+ Assert.assertEquals(5.0, z.abs(), 1.0e-5);
+ }
+
+ @Test
+ public void testAbsNaN() {
+ Assert.assertTrue(Double.isNaN(Complex.NaN.abs()));
+ Complex z = new Complex(inf, nan);
+ Assert.assertTrue(Double.isNaN(z.abs()));
+ }
+
+ @Test
+ public void testAbsInfinite() {
+ Complex z = new Complex(inf, 0);
+ Assert.assertEquals(inf, z.abs(), 0);
+ z = new Complex(0, neginf);
+ Assert.assertEquals(inf, z.abs(), 0);
+ z = new Complex(inf, neginf);
+ Assert.assertEquals(inf, z.abs(), 0);
+ }
+
+ @Test
+ public void testAdd() {
+ Complex x = new Complex(3.0, 4.0);
+ Complex y = new Complex(5.0, 6.0);
+ Complex z = x.add(y);
+ Assert.assertEquals(8.0, z.getReal(), 1.0e-5);
+ Assert.assertEquals(10.0, z.getImaginary(), 1.0e-5);
+ }
+
+ @Test
+ public void testAddNaN() {
+ Complex x = new Complex(3.0, 4.0);
+ Complex z = x.add(Complex.NaN);
+ Assert.assertSame(Complex.NaN, z);
+ z = new Complex(1, nan);
+ Complex w = x.add(z);
+ Assert.assertSame(Complex.NaN, w);
+ }
+
+ @Test
+ public void testAddInf() {
+ Complex x = new Complex(1, 1);
+ Complex z = new Complex(inf, 0);
+ Complex w = x.add(z);
+ Assert.assertEquals(w.getImaginary(), 1, 0);
+ Assert.assertEquals(inf, w.getReal(), 0);
+
+ x = new Complex(neginf, 0);
+ Assert.assertTrue(Double.isNaN(x.add(z).getReal()));
+ }
+
+
+ @Test
+ public void testScalarAdd() {
+ Complex x = new Complex(3.0, 4.0);
+ double yDouble = 2.0;
+ Complex yComplex = new Complex(yDouble);
+ Assert.assertEquals(x.add(yComplex), x.add(yDouble));
+ }
+
+ @Test
+ public void testScalarAddNaN() {
+ Complex x = new Complex(3.0, 4.0);
+ double yDouble = Double.NaN;
+ Complex yComplex = new Complex(yDouble);
+ Assert.assertEquals(x.add(yComplex), x.add(yDouble));
+ }
+
+ @Test
+ public void testScalarAddInf() {
+ Complex x = new Complex(1, 1);
+ double yDouble = Double.POSITIVE_INFINITY;
+
+ Complex yComplex = new Complex(yDouble);
+ Assert.assertEquals(x.add(yComplex), x.add(yDouble));
+
+ x = new Complex(neginf, 0);
+ Assert.assertEquals(x.add(yComplex), x.add(yDouble));
+ }
+
+ @Test
+ public void testConjugate() {
+ Complex x = new Complex(3.0, 4.0);
+ Complex z = x.conjugate();
+ Assert.assertEquals(3.0, z.getReal(), 1.0e-5);
+ Assert.assertEquals(-4.0, z.getImaginary(), 1.0e-5);
+ }
+
+ @Test
+ public void testConjugateNaN() {
+ Complex z = Complex.NaN.conjugate();
+ Assert.assertTrue(z.isNaN());
+ }
+
+ @Test
+ public void testConjugateInfiinite() {
+ Complex z = new Complex(0, inf);
+ Assert.assertEquals(neginf, z.conjugate().getImaginary(), 0);
+ z = new Complex(0, neginf);
+ Assert.assertEquals(inf, z.conjugate().getImaginary(), 0);
+ }
+
+ @Test
+ public void testDivide() {
+ Complex x = new Complex(3.0, 4.0);
+ Complex y = new Complex(5.0, 6.0);
+ Complex z = x.divide(y);
+ Assert.assertEquals(39.0 / 61.0, z.getReal(), 1.0e-5);
+ Assert.assertEquals(2.0 / 61.0, z.getImaginary(), 1.0e-5);
+ }
+
+ @Test
+ public void testDivideReal() {
+ Complex x = new Complex(2d, 3d);
+ Complex y = new Complex(2d, 0d);
+ Assert.assertEquals(new Complex(1d, 1.5), x.divide(y));
+
+ }
+
+ @Test
+ public void testDivideImaginary() {
+ Complex x = new Complex(2d, 3d);
+ Complex y = new Complex(0d, 2d);
+ Assert.assertEquals(new Complex(1.5d, -1d), x.divide(y));
+ }
+
+ @Test
+ public void testDivideInf() {
+ Complex x = new Complex(3, 4);
+ Complex w = new Complex(neginf, inf);
+ Assert.assertTrue(x.divide(w).equals(Complex.ZERO));
+
+ Complex z = w.divide(x);
+ Assert.assertTrue(Double.isNaN(z.getReal()));
+ Assert.assertEquals(inf, z.getImaginary(), 0);
+
+ w = new Complex(inf, inf);
+ z = w.divide(x);
+ Assert.assertTrue(Double.isNaN(z.getImaginary()));
+ Assert.assertEquals(inf, z.getReal(), 0);
+
+ w = new Complex(1, inf);
+ z = w.divide(w);
+ Assert.assertTrue(Double.isNaN(z.getReal()));
+ Assert.assertTrue(Double.isNaN(z.getImaginary()));
+ }
+
+ @Test
+ public void testDivideZero() {
+ Complex x = new Complex(3.0, 4.0);
+ Complex z = x.divide(Complex.ZERO);
+ // Assert.assertEquals(z, Complex.INF); // See MATH-657
+ Assert.assertEquals(z, Complex.NaN);
+ }
+
+ @Test
+ public void testDivideZeroZero() {
+ Complex x = new Complex(0.0, 0.0);
+ Complex z = x.divide(Complex.ZERO);
+ Assert.assertEquals(z, Complex.NaN);
+ }
+
+ @Test
+ public void testDivideNaN() {
+ Complex x = new Complex(3.0, 4.0);
+ Complex z = x.divide(Complex.NaN);
+ Assert.assertTrue(z.isNaN());
+ }
+
+ @Test
+ public void testDivideNaNInf() {
+ Complex z = oneInf.divide(Complex.ONE);
+ Assert.assertTrue(Double.isNaN(z.getReal()));
+ Assert.assertEquals(inf, z.getImaginary(), 0);
+
+ z = negInfNegInf.divide(oneNaN);
+ Assert.assertTrue(Double.isNaN(z.getReal()));
+ Assert.assertTrue(Double.isNaN(z.getImaginary()));
+
+ z = negInfInf.divide(Complex.ONE);
+ Assert.assertTrue(Double.isNaN(z.getReal()));
+ Assert.assertTrue(Double.isNaN(z.getImaginary()));
+ }
+
+ @Test
+ public void testScalarDivide() {
+ Complex x = new Complex(3.0, 4.0);
+ double yDouble = 2.0;
+ Complex yComplex = new Complex(yDouble);
+ Assert.assertEquals(x.divide(yComplex), x.divide(yDouble));
+ }
+
+ @Test
+ public void testScalarDivideNaN() {
+ Complex x = new Complex(3.0, 4.0);
+ double yDouble = Double.NaN;
+ Complex yComplex = new Complex(yDouble);
+ Assert.assertEquals(x.divide(yComplex), x.divide(yDouble));
+ }
+
+ @Test
+ public void testScalarDivideZero() {
+ Complex x = new Complex(1,1);
+ TestUtils.assertEquals(x.divide(Complex.ZERO), x.divide(0), 0);
+ }
+
+ @Test
+ public void testReciprocal() {
+ Complex z = new Complex(5.0, 6.0);
+ Complex act = z.reciprocal();
+ double expRe = 5.0 / 61.0;
+ double expIm = -6.0 / 61.0;
+ Assert.assertEquals(expRe, act.getReal(), Math.ulp(expRe));
+ Assert.assertEquals(expIm, act.getImaginary(), Math.ulp(expIm));
+ }
+
+ @Test
+ public void testReciprocalReal() {
+ Complex z = new Complex(-2.0, 0.0);
+ Assert.assertTrue(Complex.equals(new Complex(-0.5, 0.0), z.reciprocal()));
+ }
+
+ @Test
+ public void testReciprocalImaginary() {
+ Complex z = new Complex(0.0, -2.0);
+ Assert.assertEquals(new Complex(0.0, 0.5), z.reciprocal());
+ }
+
+ @Test
+ public void testReciprocalInf() {
+ Complex z = new Complex(neginf, inf);
+ Assert.assertTrue(z.reciprocal().equals(Complex.ZERO));
+
+ z = new Complex(1, inf).reciprocal();
+ Assert.assertEquals(z, Complex.ZERO);
+ }
+
+ @Test
+ public void testReciprocalZero() {
+ Assert.assertEquals(Complex.ZERO.reciprocal(), Complex.INF);
+ }
+
+ @Test
+ public void testReciprocalNaN() {
+ Assert.assertTrue(Complex.NaN.reciprocal().isNaN());
+ }
+
+ @Test
+ public void testMultiply() {
+ Complex x = new Complex(3.0, 4.0);
+ Complex y = new Complex(5.0, 6.0);
+ Complex z = x.multiply(y);
+ Assert.assertEquals(-9.0, z.getReal(), 1.0e-5);
+ Assert.assertEquals(38.0, z.getImaginary(), 1.0e-5);
+ }
+
+ @Test
+ public void testMultiplyNaN() {
+ Complex x = new Complex(3.0, 4.0);
+ Complex z = x.multiply(Complex.NaN);
+ Assert.assertSame(Complex.NaN, z);
+ z = Complex.NaN.multiply(5);
+ Assert.assertSame(Complex.NaN, z);
+ }
+
+ @Test
+ public void testMultiplyInfInf() {
+ // Assert.assertTrue(infInf.multiply(infInf).isNaN()); // MATH-620
+ Assert.assertTrue(infInf.multiply(infInf).isInfinite());
+ }
+
+ @Test
+ public void testMultiplyNaNInf() {
+ Complex z = new Complex(1,1);
+ Complex w = z.multiply(infOne);
+ Assert.assertEquals(w.getReal(), inf, 0);
+ Assert.assertEquals(w.getImaginary(), inf, 0);
+
+ // [MATH-164]
+ Assert.assertTrue(new Complex( 1,0).multiply(infInf).equals(Complex.INF));
+ Assert.assertTrue(new Complex(-1,0).multiply(infInf).equals(Complex.INF));
+ Assert.assertTrue(new Complex( 1,0).multiply(negInfZero).equals(Complex.INF));
+
+ w = oneInf.multiply(oneNegInf);
+ Assert.assertEquals(w.getReal(), inf, 0);
+ Assert.assertEquals(w.getImaginary(), inf, 0);
+
+ w = negInfNegInf.multiply(oneNaN);
+ Assert.assertTrue(Double.isNaN(w.getReal()));
+ Assert.assertTrue(Double.isNaN(w.getImaginary()));
+
+ z = new Complex(1, neginf);
+ Assert.assertSame(Complex.INF, z.multiply(z));
+ }
+
+ @Test
+ public void testScalarMultiply() {
+ Complex x = new Complex(3.0, 4.0);
+ double yDouble = 2.0;
+ Complex yComplex = new Complex(yDouble);
+ Assert.assertEquals(x.multiply(yComplex), x.multiply(yDouble));
+ int zInt = -5;
+ Complex zComplex = new Complex(zInt);
+ Assert.assertEquals(x.multiply(zComplex), x.multiply(zInt));
+ }
+
+ @Test
+ public void testScalarMultiplyNaN() {
+ Complex x = new Complex(3.0, 4.0);
+ double yDouble = Double.NaN;
+ Complex yComplex = new Complex(yDouble);
+ Assert.assertEquals(x.multiply(yComplex), x.multiply(yDouble));
+ }
+
+ @Test
+ public void testScalarMultiplyInf() {
+ Complex x = new Complex(1, 1);
+ double yDouble = Double.POSITIVE_INFINITY;
+ Complex yComplex = new Complex(yDouble);
+ Assert.assertEquals(x.multiply(yComplex), x.multiply(yDouble));
+
+ yDouble = Double.NEGATIVE_INFINITY;
+ yComplex = new Complex(yDouble);
+ Assert.assertEquals(x.multiply(yComplex), x.multiply(yDouble));
+ }
+
+ @Test
+ public void testNegate() {
+ Complex x = new Complex(3.0, 4.0);
+ Complex z = x.negate();
+ Assert.assertEquals(-3.0, z.getReal(), 1.0e-5);
+ Assert.assertEquals(-4.0, z.getImaginary(), 1.0e-5);
+ }
+
+ @Test
+ public void testNegateNaN() {
+ Complex z = Complex.NaN.negate();
+ Assert.assertTrue(z.isNaN());
+ }
+
+ @Test
+ public void testSubtract() {
+ Complex x = new Complex(3.0, 4.0);
+ Complex y = new Complex(5.0, 6.0);
+ Complex z = x.subtract(y);
+ Assert.assertEquals(-2.0, z.getReal(), 1.0e-5);
+ Assert.assertEquals(-2.0, z.getImaginary(), 1.0e-5);
+ }
+
+ @Test
+ public void testSubtractNaN() {
+ Complex x = new Complex(3.0, 4.0);
+ Complex z = x.subtract(Complex.NaN);
+ Assert.assertSame(Complex.NaN, z);
+ z = new Complex(1, nan);
+ Complex w = x.subtract(z);
+ Assert.assertSame(Complex.NaN, w);
+ }
+
+ @Test
+ public void testSubtractInf() {
+ Complex x = new Complex(1, 1);
+ Complex z = new Complex(neginf, 0);
+ Complex w = x.subtract(z);
+ Assert.assertEquals(w.getImaginary(), 1, 0);
+ Assert.assertEquals(inf, w.getReal(), 0);
+
+ x = new Complex(neginf, 0);
+ Assert.assertTrue(Double.isNaN(x.subtract(z).getReal()));
+ }
+
+ @Test
+ public void testScalarSubtract() {
+ Complex x = new Complex(3.0, 4.0);
+ double yDouble = 2.0;
+ Complex yComplex = new Complex(yDouble);
+ Assert.assertEquals(x.subtract(yComplex), x.subtract(yDouble));
+ }
+
+ @Test
+ public void testScalarSubtractNaN() {
+ Complex x = new Complex(3.0, 4.0);
+ double yDouble = Double.NaN;
+ Complex yComplex = new Complex(yDouble);
+ Assert.assertEquals(x.subtract(yComplex), x.subtract(yDouble));
+ }
+
+ @Test
+ public void testScalarSubtractInf() {
+ Complex x = new Complex(1, 1);
+ double yDouble = Double.POSITIVE_INFINITY;
+ Complex yComplex = new Complex(yDouble);
+ Assert.assertEquals(x.subtract(yComplex), x.subtract(yDouble));
+
+ x = new Complex(neginf, 0);
+ Assert.assertEquals(x.subtract(yComplex), x.subtract(yDouble));
+ }
+
+
+ @Test
+ public void testEqualsNull() {
+ Complex x = new Complex(3.0, 4.0);
+ Assert.assertFalse(x.equals(null));
+ }
+
+ @Test(expected=NullPointerException.class)
+ public void testFloatingPointEqualsPrecondition1() {
+ Complex.equals(new Complex(3.0, 4.0), null, 3);
+ }
+ @Test(expected=NullPointerException.class)
+ public void testFloatingPointEqualsPrecondition2() {
+ Complex.equals(null, new Complex(3.0, 4.0), 3);
+ }
+
+ @Test
+ public void testEqualsClass() {
+ Complex x = new Complex(3.0, 4.0);
+ Assert.assertFalse(x.equals(this));
+ }
+
+ @Test
+ public void testEqualsSame() {
+ Complex x = new Complex(3.0, 4.0);
+ Assert.assertTrue(x.equals(x));
+ }
+
+ @Test
+ public void testFloatingPointEquals() {
+ double re = -3.21;
+ double im = 456789e10;
+
+ final Complex x = new Complex(re, im);
+ Complex y = new Complex(re, im);
+
+ Assert.assertTrue(x.equals(y));
+ Assert.assertTrue(Complex.equals(x, y));
+
+ final int maxUlps = 5;
+ for (int i = 0; i < maxUlps; i++) {
+ re = Math.nextUp(re);
+ im = Math.nextUp(im);
+ }
+ y = new Complex(re, im);
+ Assert.assertTrue(Complex.equals(x, y, maxUlps));
+
+ re = Math.nextUp(re);
+ im = Math.nextUp(im);
+ y = new Complex(re, im);
+ Assert.assertFalse(Complex.equals(x, y, maxUlps));
+ }
+
+ @Test
+ public void testFloatingPointEqualsNaN() {
+ Complex c = new Complex(Double.NaN, 1);
+ Assert.assertFalse(Complex.equals(c, c));
+
+ c = new Complex(1, Double.NaN);
+ Assert.assertFalse(Complex.equals(c, c));
+ }
+
+ @Test
+ public void testFloatingPointEqualsWithAllowedDelta() {
+ final double re = 153.0000;
+ final double im = 152.9375;
+ final double tol1 = 0.0625;
+ final Complex x = new Complex(re, im);
+ final Complex y = new Complex(re + tol1, im + tol1);
+ Assert.assertTrue(Complex.equals(x, y, tol1));
+
+ final double tol2 = 0.0624;
+ Assert.assertFalse(Complex.equals(x, y, tol2));
+ }
+
+ @Test
+ public void testFloatingPointEqualsWithAllowedDeltaNaN() {
+ final Complex x = new Complex(0, Double.NaN);
+ final Complex y = new Complex(Double.NaN, 0);
+ Assert.assertFalse(Complex.equals(x, Complex.ZERO, 0.1));
+ Assert.assertFalse(Complex.equals(x, x, 0.1));
+ Assert.assertFalse(Complex.equals(x, y, 0.1));
+ }
+
+ @Test
+ public void testFloatingPointEqualsWithRelativeTolerance() {
+ final double tol = 1e-4;
+ final double re = 1;
+ final double im = 1e10;
+
+ final double f = 1 + tol;
+ final Complex x = new Complex(re, im);
+ final Complex y = new Complex(re * f, im * f);
+ Assert.assertTrue(Complex.equalsWithRelativeTolerance(x, y, tol));
+ }
+
+ @Test
+ public void testFloatingPointEqualsWithRelativeToleranceNaN() {
+ final Complex x = new Complex(0, Double.NaN);
+ final Complex y = new Complex(Double.NaN, 0);
+ Assert.assertFalse(Complex.equalsWithRelativeTolerance(x, Complex.ZERO, 0.1));
+ Assert.assertFalse(Complex.equalsWithRelativeTolerance(x, x, 0.1));
+ Assert.assertFalse(Complex.equalsWithRelativeTolerance(x, y, 0.1));
+ }
+
+ @Test
+ public void testEqualsTrue() {
+ Complex x = new Complex(3.0, 4.0);
+ Complex y = new Complex(3.0, 4.0);
+ Assert.assertTrue(x.equals(y));
+ }
+
+ @Test
+ public void testEqualsRealDifference() {
+ Complex x = new Complex(0.0, 0.0);
+ Complex y = new Complex(0.0 + Double.MIN_VALUE, 0.0);
+ Assert.assertFalse(x.equals(y));
+ }
+
+ @Test
+ public void testEqualsImaginaryDifference() {
+ Complex x = new Complex(0.0, 0.0);
+ Complex y = new Complex(0.0, 0.0 + Double.MIN_VALUE);
+ Assert.assertFalse(x.equals(y));
+ }
+
+ @Test
+ public void testEqualsNaN() {
+ Complex realNaN = new Complex(Double.NaN, 0.0);
+ Complex imaginaryNaN = new Complex(0.0, Double.NaN);
+ Complex complexNaN = Complex.NaN;
+ Assert.assertTrue(realNaN.equals(imaginaryNaN));
+ Assert.assertTrue(imaginaryNaN.equals(complexNaN));
+ Assert.assertTrue(realNaN.equals(complexNaN));
+ }
+
+ @Test
+ public void testHashCode() {
+ Complex x = new Complex(0.0, 0.0);
+ Complex y = new Complex(0.0, 0.0 + Double.MIN_VALUE);
+ Assert.assertFalse(x.hashCode()==y.hashCode());
+ y = new Complex(0.0 + Double.MIN_VALUE, 0.0);
+ Assert.assertFalse(x.hashCode()==y.hashCode());
+ Complex realNaN = new Complex(Double.NaN, 0.0);
+ Complex imaginaryNaN = new Complex(0.0, Double.NaN);
+ Assert.assertEquals(realNaN.hashCode(), imaginaryNaN.hashCode());
+ Assert.assertEquals(imaginaryNaN.hashCode(), Complex.NaN.hashCode());
+
+ // MATH-1118
+ // "equals" and "hashCode" must be compatible: if two objects have
+ // different hash codes, "equals" must return false.
+ final String msg = "'equals' not compatible with 'hashCode'";
+
+ x = new Complex(0.0, 0.0);
+ y = new Complex(0.0, -0.0);
+ Assert.assertTrue(x.hashCode() != y.hashCode());
+ Assert.assertFalse(msg, x.equals(y));
+
+ x = new Complex(0.0, 0.0);
+ y = new Complex(-0.0, 0.0);
+ Assert.assertTrue(x.hashCode() != y.hashCode());
+ Assert.assertFalse(msg, x.equals(y));
+ }
+
+ @Test
+ public void testAcos() {
+ Complex z = new Complex(3, 4);
+ Complex expected = new Complex(0.936812, -2.30551);
+ TestUtils.assertEquals(expected, z.acos(), 1.0e-5);
+ TestUtils.assertEquals(new Complex(Math.acos(0), 0),
+ Complex.ZERO.acos(), 1.0e-12);
+ }
+
+ @Test
+ public void testAcosInf() {
+ TestUtils.assertSame(Complex.NaN, oneInf.acos());
+ TestUtils.assertSame(Complex.NaN, oneNegInf.acos());
+ TestUtils.assertSame(Complex.NaN, infOne.acos());
+ TestUtils.assertSame(Complex.NaN, negInfOne.acos());
+ TestUtils.assertSame(Complex.NaN, infInf.acos());
+ TestUtils.assertSame(Complex.NaN, infNegInf.acos());
+ TestUtils.assertSame(Complex.NaN, negInfInf.acos());
+ TestUtils.assertSame(Complex.NaN, negInfNegInf.acos());
+ }
+
+ @Test
+ public void testAcosNaN() {
+ Assert.assertTrue(Complex.NaN.acos().isNaN());
+ }
+
+ @Test
+ public void testAsin() {
+ Complex z = new Complex(3, 4);
+ Complex expected = new Complex(0.633984, 2.30551);
+ TestUtils.assertEquals(expected, z.asin(), 1.0e-5);
+ }
+
+ @Test
+ public void testAsinNaN() {
+ Assert.assertTrue(Complex.NaN.asin().isNaN());
+ }
+
+ @Test
+ public void testAsinInf() {
+ TestUtils.assertSame(Complex.NaN, oneInf.asin());
+ TestUtils.assertSame(Complex.NaN, oneNegInf.asin());
+ TestUtils.assertSame(Complex.NaN, infOne.asin());
+ TestUtils.assertSame(Complex.NaN, negInfOne.asin());
+ TestUtils.assertSame(Complex.NaN, infInf.asin());
+ TestUtils.assertSame(Complex.NaN, infNegInf.asin());
+ TestUtils.assertSame(Complex.NaN, negInfInf.asin());
+ TestUtils.assertSame(Complex.NaN, negInfNegInf.asin());
+ }
+
+
+ @Test
+ public void testAtan() {
+ Complex z = new Complex(3, 4);
+ Complex expected = new Complex(1.44831, 0.158997);
+ TestUtils.assertEquals(expected, z.atan(), 1.0e-5);
+ }
+
+ @Test
+ public void testAtanInf() {
+ TestUtils.assertSame(Complex.NaN, oneInf.atan());
+ TestUtils.assertSame(Complex.NaN, oneNegInf.atan());
+ TestUtils.assertSame(Complex.NaN, infOne.atan());
+ TestUtils.assertSame(Complex.NaN, negInfOne.atan());
+ TestUtils.assertSame(Complex.NaN, infInf.atan());
+ TestUtils.assertSame(Complex.NaN, infNegInf.atan());
+ TestUtils.assertSame(Complex.NaN, negInfInf.atan());
+ TestUtils.assertSame(Complex.NaN, negInfNegInf.atan());
+ }
+
+ @Test
+ public void testAtanI() {
+ Assert.assertTrue(Complex.I.atan().isNaN());
+ }
+
+ @Test
+ public void testAtanNaN() {
+ Assert.assertTrue(Complex.NaN.atan().isNaN());
+ }
+
+ @Test
+ public void testCos() {
+ Complex z = new Complex(3, 4);
+ Complex expected = new Complex(-27.03495, -3.851153);
+ TestUtils.assertEquals(expected, z.cos(), 1.0e-5);
+ }
+
+ @Test
+ public void testCosNaN() {
+ Assert.assertTrue(Complex.NaN.cos().isNaN());
+ }
+
+ @Test
+ public void testCosInf() {
+ TestUtils.assertSame(infNegInf, oneInf.cos());
+ TestUtils.assertSame(infInf, oneNegInf.cos());
+ TestUtils.assertSame(Complex.NaN, infOne.cos());
+ TestUtils.assertSame(Complex.NaN, negInfOne.cos());
+ TestUtils.assertSame(Complex.NaN, infInf.cos());
+ TestUtils.assertSame(Complex.NaN, infNegInf.cos());
+ TestUtils.assertSame(Complex.NaN, negInfInf.cos());
+ TestUtils.assertSame(Complex.NaN, negInfNegInf.cos());
+ }
+
+ @Test
+ public void testCosh() {
+ Complex z = new Complex(3, 4);
+ Complex expected = new Complex(-6.58066, -7.58155);
+ TestUtils.assertEquals(expected, z.cosh(), 1.0e-5);
+ }
+
+ @Test
+ public void testCoshNaN() {
+ Assert.assertTrue(Complex.NaN.cosh().isNaN());
+ }
+
+ @Test
+ public void testCoshInf() {
+ TestUtils.assertSame(Complex.NaN, oneInf.cosh());
+ TestUtils.assertSame(Complex.NaN, oneNegInf.cosh());
+ TestUtils.assertSame(infInf, infOne.cosh());
+ TestUtils.assertSame(infNegInf, negInfOne.cosh());
+ TestUtils.assertSame(Complex.NaN, infInf.cosh());
+ TestUtils.assertSame(Complex.NaN, infNegInf.cosh());
+ TestUtils.assertSame(Complex.NaN, negInfInf.cosh());
+ TestUtils.assertSame(Complex.NaN, negInfNegInf.cosh());
+ }
+
+ @Test
+ public void testExp() {
+ final double tol = Math.ulp(1d);
+ Complex z = new Complex(3, 4);
+ Complex expected = new Complex(-13.12878, -15.20078);
+ TestUtils.assertEquals(expected, z.exp(), 1.0e-5);
+ TestUtils.assertEquals(Complex.ONE,
+ Complex.ZERO.exp(), tol);
+ Complex iPi = Complex.I.multiply(new Complex(pi,0));
+ TestUtils.assertEquals(Complex.ONE.negate(),
+ iPi.exp(), tol);
+ }
+
+ @Test
+ public void testExpNaN() {
+ Assert.assertTrue(Complex.NaN.exp().isNaN());
+ }
+
+ @Test
+ public void testExpInf1() {
+ TestUtils.assertSame(Complex.NaN, oneInf.exp());
+ }
+
+ @Test
+ public void testExpInf2() {
+ TestUtils.assertSame(Complex.NaN, oneNegInf.exp());
+ }
+
+ @Test
+ public void testExpInf3() {
+ TestUtils.assertSame(infInf, infOne.exp());
+ }
+
+ @Test
+ @Ignore
+ public void testJava() {// TODO more debug
+ System.out.println(">>testJava()");
+ // MathTest#testExpSpecialCases() checks the following:
+ // Assert.assertEquals("exp of -infinity should be 0.0", 0.0, Math.exp(Double.NEGATIVE_INFINITY), Precision.EPSILON);
+ // Let's check how well Math works:
+ System.out.println("Math.exp="+Math.exp(Double.NEGATIVE_INFINITY));
+ String props[] = {
+ "java.version", // Java Runtime Environment version
+ "java.vendor", // Java Runtime Environment vendor
+ "java.vm.specification.version", // Java Virtual Machine specification version
+ "java.vm.specification.vendor", // Java Virtual Machine specification vendor
+ "java.vm.specification.name", // Java Virtual Machine specification name
+ "java.vm.version", // Java Virtual Machine implementation version
+ "java.vm.vendor", // Java Virtual Machine implementation vendor
+ "java.vm.name", // Java Virtual Machine implementation name
+ "java.specification.version", // Java Runtime Environment specification version
+ "java.specification.vendor", // Java Runtime Environment specification vendor
+ "java.specification.name", // Java Runtime Environment specification name
+ "java.class.version", // Java class format version number
+ };
+ for(String t : props) {
+ System.out.println(t + "=" + System.getProperty(t));
+ }
+ System.out.println("<<testJava()");
+ }
+
+ @Test
+ public void testExpInf4() {
+ final Complex exp = negInfOne.exp();
+ TestUtils.assertSame(Complex.ZERO, exp);
+ }
+
+ @Test
+ public void testExpInf5() {
+ TestUtils.assertSame(Complex.NaN, infInf.exp());
+ }
+
+ @Test
+ public void testExpInf6() {
+ TestUtils.assertSame(Complex.NaN, infNegInf.exp());
+ }
+
+ @Test
+ public void testExpInf7() {
+ TestUtils.assertSame(Complex.NaN, negInfInf.exp());
+ }
+
+ @Test
+ public void testExpInf8() {
+ TestUtils.assertSame(Complex.NaN, negInfNegInf.exp());
+ }
+
+ @Test
+ public void testLog() {
+ Complex z = new Complex(3, 4);
+ Complex expected = new Complex(1.60944, 0.927295);
+ TestUtils.assertEquals(expected, z.log(), 1.0e-5);
+ }
+
+ @Test
+ public void testLogNaN() {
+ Assert.assertTrue(Complex.NaN.log().isNaN());
+ }
+
+ @Test
+ public void testLogInf() {
+ final double tol = Math.ulp(1d);
+ TestUtils.assertEquals(new Complex(inf, pi / 2),
+ oneInf.log(), tol);
+ TestUtils.assertEquals(new Complex(inf, -pi / 2),
+ oneNegInf.log(), tol);
+ TestUtils.assertEquals(infZero, infOne.log(), tol);
+ TestUtils.assertEquals(new Complex(inf, pi),
+ negInfOne.log(), tol);
+ TestUtils.assertEquals(new Complex(inf, pi / 4),
+ infInf.log(), tol);
+ TestUtils.assertEquals(new Complex(inf, -pi / 4),
+ infNegInf.log(), tol);
+ TestUtils.assertEquals(new Complex(inf, 3d * pi / 4),
+ negInfInf.log(), tol);
+ TestUtils.assertEquals(new Complex(inf, - 3d * pi / 4),
+ negInfNegInf.log(), tol);
+ }
+
+ @Test
+ public void testLogZero() {
+ TestUtils.assertSame(negInfZero, Complex.ZERO.log());
+ }
+
+ @Test
+ public void testPow() {
+ Complex x = new Complex(3, 4);
+ Complex y = new Complex(5, 6);
+ Complex expected = new Complex(-1.860893, 11.83677);
+ TestUtils.assertEquals(expected, x.pow(y), 1.0e-5);
+ }
+
+ @Test
+ public void testPowNaNBase() {
+ Complex x = new Complex(3, 4);
+ Assert.assertTrue(Complex.NaN.pow(x).isNaN());
+ }
+
+ @Test
+ public void testPowNaNExponent() {
+ Complex x = new Complex(3, 4);
+ Assert.assertTrue(x.pow(Complex.NaN).isNaN());
+ }
+
+ @Test
+ public void testPowInf() {
+ TestUtils.assertSame(Complex.NaN,Complex.ONE.pow(oneInf));
+ TestUtils.assertSame(Complex.NaN,Complex.ONE.pow(oneNegInf));
+ TestUtils.assertSame(Complex.NaN,Complex.ONE.pow(infOne));
+ TestUtils.assertSame(Complex.NaN,Complex.ONE.pow(infInf));
+ TestUtils.assertSame(Complex.NaN,Complex.ONE.pow(infNegInf));
+ TestUtils.assertSame(Complex.NaN,Complex.ONE.pow(negInfInf));
+ TestUtils.assertSame(Complex.NaN,Complex.ONE.pow(negInfNegInf));
+ TestUtils.assertSame(Complex.NaN,infOne.pow(Complex.ONE));
+ TestUtils.assertSame(Complex.NaN,negInfOne.pow(Complex.ONE));
+ TestUtils.assertSame(Complex.NaN,infInf.pow(Complex.ONE));
+ TestUtils.assertSame(Complex.NaN,infNegInf.pow(Complex.ONE));
+ TestUtils.assertSame(Complex.NaN,negInfInf.pow(Complex.ONE));
+ TestUtils.assertSame(Complex.NaN,negInfNegInf.pow(Complex.ONE));
+ TestUtils.assertSame(Complex.NaN,negInfNegInf.pow(infNegInf));
+ TestUtils.assertSame(Complex.NaN,negInfNegInf.pow(negInfNegInf));
+ TestUtils.assertSame(Complex.NaN,negInfNegInf.pow(infInf));
+ TestUtils.assertSame(Complex.NaN,infInf.pow(infNegInf));
+ TestUtils.assertSame(Complex.NaN,infInf.pow(negInfNegInf));
+ TestUtils.assertSame(Complex.NaN,infInf.pow(infInf));
+ TestUtils.assertSame(Complex.NaN,infNegInf.pow(infNegInf));
+ TestUtils.assertSame(Complex.NaN,infNegInf.pow(negInfNegInf));
+ TestUtils.assertSame(Complex.NaN,infNegInf.pow(infInf));
+ }
+
+ @Test
+ public void testPowZero() {
+ final double tol = Math.ulp(1d);
+ TestUtils.assertEquals(Complex.ZERO,
+ Complex.ZERO.pow(Complex.ONE), tol);
+ TestUtils.assertEquals(Complex.ZERO,
+ Complex.ZERO.pow(new Complex(2, 0)), tol);
+ TestUtils.assertSame(Complex.NaN,
+ Complex.ZERO.pow(Complex.ZERO));
+ TestUtils.assertSame(Complex.NaN,
+ Complex.ZERO.pow(Complex.I));
+ TestUtils.assertEquals(Complex.ONE,
+ Complex.ONE.pow(Complex.ZERO), tol);
+ TestUtils.assertEquals(Complex.ONE,
+ Complex.I.pow(Complex.ZERO), tol);
+ TestUtils.assertEquals(Complex.ONE,
+ new Complex(-1, 3).pow(Complex.ZERO), tol);
+ }
+
+ @Test
+ public void testScalarPow() {
+ Complex x = new Complex(3, 4);
+ double yDouble = 5.0;
+ Complex yComplex = new Complex(yDouble);
+ Assert.assertEquals(x.pow(yComplex), x.pow(yDouble));
+ }
+
+ @Test
+ public void testScalarPowNaNBase() {
+ Complex x = Complex.NaN;
+ double yDouble = 5.0;
+ Complex yComplex = new Complex(yDouble);
+ Assert.assertEquals(x.pow(yComplex), x.pow(yDouble));
+ }
+
+ @Test
+ public void testScalarPowNaNExponent() {
+ Complex x = new Complex(3, 4);
+ double yDouble = Double.NaN;
+ Complex yComplex = new Complex(yDouble);
+ Assert.assertEquals(x.pow(yComplex), x.pow(yDouble));
+ }
+
+ @Test
+ public void testScalarPowInf() {
+ TestUtils.assertSame(Complex.NaN,Complex.ONE.pow(Double.POSITIVE_INFINITY));
+ TestUtils.assertSame(Complex.NaN,Complex.ONE.pow(Double.NEGATIVE_INFINITY));
+ TestUtils.assertSame(Complex.NaN,infOne.pow(1.0));
+ TestUtils.assertSame(Complex.NaN,negInfOne.pow(1.0));
+ TestUtils.assertSame(Complex.NaN,infInf.pow(1.0));
+ TestUtils.assertSame(Complex.NaN,infNegInf.pow(1.0));
+ TestUtils.assertSame(Complex.NaN,negInfInf.pow(10));
+ TestUtils.assertSame(Complex.NaN,negInfNegInf.pow(1.0));
+ TestUtils.assertSame(Complex.NaN,negInfNegInf.pow(Double.POSITIVE_INFINITY));
+ TestUtils.assertSame(Complex.NaN,negInfNegInf.pow(Double.POSITIVE_INFINITY));
+ TestUtils.assertSame(Complex.NaN,infInf.pow(Double.POSITIVE_INFINITY));
+ TestUtils.assertSame(Complex.NaN,infInf.pow(Double.NEGATIVE_INFINITY));
+ TestUtils.assertSame(Complex.NaN,infNegInf.pow(Double.NEGATIVE_INFINITY));
+ TestUtils.assertSame(Complex.NaN,infNegInf.pow(Double.POSITIVE_INFINITY));
+ }
+
+ @Test
+ public void testScalarPowZero() {
+ final double tol = Math.ulp(1d);
+ TestUtils.assertEquals(Complex.ZERO, Complex.ZERO.pow(1.0), tol);
+ TestUtils.assertEquals(Complex.ZERO, Complex.ZERO.pow(2.0), tol);
+ TestUtils.assertSame(Complex.NaN, Complex.ZERO.pow(0.0));
+ TestUtils.assertSame(Complex.NaN, Complex.ZERO.pow(-1.0));
+ TestUtils.assertEquals(Complex.ONE, Complex.ONE.pow(0.0), tol);
+ TestUtils.assertEquals(Complex.ONE, Complex.I.pow(0.0), tol);
+ TestUtils.assertEquals(Complex.ONE, new Complex(-1, 3).pow(0.0), tol);
+ }
+
+ @Test
+ public void testSin() {
+ Complex z = new Complex(3, 4);
+ Complex expected = new Complex(3.853738, -27.01681);
+ TestUtils.assertEquals(expected, z.sin(), 1.0e-5);
+ }
+
+ @Test
+ public void testSinInf() {
+ TestUtils.assertSame(infInf, oneInf.sin());
+ TestUtils.assertSame(infNegInf, oneNegInf.sin());
+ TestUtils.assertSame(Complex.NaN, infOne.sin());
+ TestUtils.assertSame(Complex.NaN, negInfOne.sin());
+ TestUtils.assertSame(Complex.NaN, infInf.sin());
+ TestUtils.assertSame(Complex.NaN, infNegInf.sin());
+ TestUtils.assertSame(Complex.NaN, negInfInf.sin());
+ TestUtils.assertSame(Complex.NaN, negInfNegInf.sin());
+ }
+
+ @Test
+ public void testSinNaN() {
+ Assert.assertTrue(Complex.NaN.sin().isNaN());
+ }
+
+ @Test
+ public void testSinh() {
+ Complex z = new Complex(3, 4);
+ Complex expected = new Complex(-6.54812, -7.61923);
+ TestUtils.assertEquals(expected, z.sinh(), 1.0e-5);
+ }
+
+ @Test
+ public void testSinhNaN() {
+ Assert.assertTrue(Complex.NaN.sinh().isNaN());
+ }
+
+ @Test
+ public void testSinhInf() {
+ TestUtils.assertSame(Complex.NaN, oneInf.sinh());
+ TestUtils.assertSame(Complex.NaN, oneNegInf.sinh());
+ TestUtils.assertSame(infInf, infOne.sinh());
+ TestUtils.assertSame(negInfInf, negInfOne.sinh());
+ TestUtils.assertSame(Complex.NaN, infInf.sinh());
+ TestUtils.assertSame(Complex.NaN, infNegInf.sinh());
+ TestUtils.assertSame(Complex.NaN, negInfInf.sinh());
+ TestUtils.assertSame(Complex.NaN, negInfNegInf.sinh());
+ }
+
+ @Test
+ public void testSqrtRealPositive() {
+ Complex z = new Complex(3, 4);
+ Complex expected = new Complex(2, 1);
+ TestUtils.assertEquals(expected, z.sqrt(), 1.0e-5);
+ }
+
+ @Test
+ public void testSqrtRealZero() {
+ Complex z = new Complex(0.0, 4);
+ Complex expected = new Complex(1.41421, 1.41421);
+ TestUtils.assertEquals(expected, z.sqrt(), 1.0e-5);
+ }
+
+ @Test
+ public void testSqrtRealNegative() {
+ Complex z = new Complex(-3.0, 4);
+ Complex expected = new Complex(1, 2);
+ TestUtils.assertEquals(expected, z.sqrt(), 1.0e-5);
+ }
+
+ @Test
+ public void testSqrtImaginaryZero() {
+ Complex z = new Complex(-3.0, 0.0);
+ Complex expected = new Complex(0.0, 1.73205);
+ TestUtils.assertEquals(expected, z.sqrt(), 1.0e-5);
+ }
+
+ @Test
+ public void testSqrtImaginaryNegative() {
+ Complex z = new Complex(-3.0, -4.0);
+ Complex expected = new Complex(1.0, -2.0);
+ TestUtils.assertEquals(expected, z.sqrt(), 1.0e-5);
+ }
+
+ @Test
+ public void testSqrtPolar() {
+ final double tol = 1e-12;
+ double r = 1;
+ for (int i = 0; i < 5; i++) {
+ r += i;
+ double theta = 0;
+ for (int j = 0; j < 11; j++) {
+ theta += pi / 12;
+ Complex z = ComplexUtils.polar2Complex(r, theta);
+ Complex sqrtz = ComplexUtils.polar2Complex(Math.sqrt(r), theta / 2);
+ TestUtils.assertEquals(sqrtz, z.sqrt(), tol);
+ }
+ }
+ }
+
+ @Test
+ public void testSqrtNaN() {
+ Assert.assertTrue(Complex.NaN.sqrt().isNaN());
+ }
+
+ @Test
+ public void testSqrtInf() {
+ TestUtils.assertSame(infNaN, oneInf.sqrt());
+ TestUtils.assertSame(infNaN, oneNegInf.sqrt());
+ TestUtils.assertSame(infZero, infOne.sqrt());
+ TestUtils.assertSame(zeroInf, negInfOne.sqrt());
+ TestUtils.assertSame(infNaN, infInf.sqrt());
+ TestUtils.assertSame(infNaN, infNegInf.sqrt());
+ TestUtils.assertSame(nanInf, negInfInf.sqrt());
+ TestUtils.assertSame(nanNegInf, negInfNegInf.sqrt());
+ }
+
+ @Test
+ public void testSqrt1z() {
+ Complex z = new Complex(3, 4);
+ Complex expected = new Complex(4.08033, -2.94094);
+ TestUtils.assertEquals(expected, z.sqrt1z(), 1.0e-5);
+ }
+
+ @Test
+ public void testSqrt1zNaN() {
+ Assert.assertTrue(Complex.NaN.sqrt1z().isNaN());
+ }
+
+ @Test
+ public void testTan() {
+ Complex z = new Complex(3, 4);
+ Complex expected = new Complex(-0.000187346, 0.999356);
+ TestUtils.assertEquals(expected, z.tan(), 1.0e-5);
+ /* Check that no overflow occurs (MATH-722) */
+ Complex actual = new Complex(3.0, 1E10).tan();
+ expected = new Complex(0, 1);
+ TestUtils.assertEquals(expected, actual, 1.0e-5);
+ actual = new Complex(3.0, -1E10).tan();
+ expected = new Complex(0, -1);
+ TestUtils.assertEquals(expected, actual, 1.0e-5);
+ }
+
+ @Test
+ public void testTanNaN() {
+ Assert.assertTrue(Complex.NaN.tan().isNaN());
+ }
+
+ @Test
+ public void testTanInf() {
+ TestUtils.assertSame(Complex.valueOf(0.0, 1.0), oneInf.tan());
+ TestUtils.assertSame(Complex.valueOf(0.0, -1.0), oneNegInf.tan());
+ TestUtils.assertSame(Complex.NaN, infOne.tan());
+ TestUtils.assertSame(Complex.NaN, negInfOne.tan());
+ TestUtils.assertSame(Complex.NaN, infInf.tan());
+ TestUtils.assertSame(Complex.NaN, infNegInf.tan());
+ TestUtils.assertSame(Complex.NaN, negInfInf.tan());
+ TestUtils.assertSame(Complex.NaN, negInfNegInf.tan());
+ }
+
+ @Test
+ public void testTanCritical() {
+ TestUtils.assertSame(infNaN, new Complex(pi/2, 0).tan());
+ TestUtils.assertSame(negInfNaN, new Complex(-pi/2, 0).tan());
+ }
+
+ @Test
+ public void testTanh() {
+ Complex z = new Complex(3, 4);
+ Complex expected = new Complex(1.00071, 0.00490826);
+ TestUtils.assertEquals(expected, z.tanh(), 1.0e-5);
+ /* Check that no overflow occurs (MATH-722) */
+ Complex actual = new Complex(1E10, 3.0).tanh();
+ expected = new Complex(1, 0);
+ TestUtils.assertEquals(expected, actual, 1.0e-5);
+ actual = new Complex(-1E10, 3.0).tanh();
+ expected = new Complex(-1, 0);
+ TestUtils.assertEquals(expected, actual, 1.0e-5);
+ }
+
+ @Test
+ public void testTanhNaN() {
+ Assert.assertTrue(Complex.NaN.tanh().isNaN());
+ }
+
+ @Test
+ public void testTanhInf() {
+ TestUtils.assertSame(Complex.NaN, oneInf.tanh());
+ TestUtils.assertSame(Complex.NaN, oneNegInf.tanh());
+ TestUtils.assertSame(Complex.valueOf(1.0, 0.0), infOne.tanh());
+ TestUtils.assertSame(Complex.valueOf(-1.0, 0.0), negInfOne.tanh());
+ TestUtils.assertSame(Complex.NaN, infInf.tanh());
+ TestUtils.assertSame(Complex.NaN, infNegInf.tanh());
+ TestUtils.assertSame(Complex.NaN, negInfInf.tanh());
+ TestUtils.assertSame(Complex.NaN, negInfNegInf.tanh());
+ }
+
+ @Test
+ public void testTanhCritical() {
+ TestUtils.assertSame(nanInf, new Complex(0, pi/2).tanh());
+ }
+
+ /** test issue MATH-221 */
+ @Test
+ public void testMath221() {
+ Assert.assertTrue(Complex.equals(new Complex(0,-1),
+ new Complex(0,1).multiply(new Complex(-1,0))));
+ }
+
+ /**
+ * Test: computing <b>third roots</b> of z.
+ * <pre>
+ * <code>
+ * <b>z = -2 + 2 * i</b>
+ * => z_0 = 1 + i
+ * => z_1 = -1.3660 + 0.3660 * i
+ * => z_2 = 0.3660 - 1.3660 * i
+ * </code>
+ * </pre>
+ */
+ @Test
+ public void testNthRoot_normal_thirdRoot() {
+ // The complex number we want to compute all third-roots for.
+ Complex z = new Complex(-2,2);
+ // The List holding all third roots
+ Complex[] thirdRootsOfZ = z.nthRoot(3).toArray(new Complex[0]);
+ // Returned Collection must not be empty!
+ Assert.assertEquals(3, thirdRootsOfZ.length);
+ // test z_0
+ Assert.assertEquals(1.0, thirdRootsOfZ[0].getReal(), 1.0e-5);
+ Assert.assertEquals(1.0, thirdRootsOfZ[0].getImaginary(), 1.0e-5);
+ // test z_1
+ Assert.assertEquals(-1.3660254037844386, thirdRootsOfZ[1].getReal(), 1.0e-5);
+ Assert.assertEquals(0.36602540378443843, thirdRootsOfZ[1].getImaginary(), 1.0e-5);
+ // test z_2
+ Assert.assertEquals(0.366025403784439, thirdRootsOfZ[2].getReal(), 1.0e-5);
+ Assert.assertEquals(-1.3660254037844384, thirdRootsOfZ[2].getImaginary(), 1.0e-5);
+ }
+
+
+ /**
+ * Test: computing <b>fourth roots</b> of z.
+ * <pre>
+ * <code>
+ * <b>z = 5 - 2 * i</b>
+ * => z_0 = 1.5164 - 0.1446 * i
+ * => z_1 = 0.1446 + 1.5164 * i
+ * => z_2 = -1.5164 + 0.1446 * i
+ * => z_3 = -1.5164 - 0.1446 * i
+ * </code>
+ * </pre>
+ */
+ @Test
+ public void testNthRoot_normal_fourthRoot() {
+ // The complex number we want to compute all third-roots for.
+ Complex z = new Complex(5,-2);
+ // The List holding all fourth roots
+ Complex[] fourthRootsOfZ = z.nthRoot(4).toArray(new Complex[0]);
+ // Returned Collection must not be empty!
+ Assert.assertEquals(4, fourthRootsOfZ.length);
+ // test z_0
+ Assert.assertEquals(1.5164629308487783, fourthRootsOfZ[0].getReal(), 1.0e-5);
+ Assert.assertEquals(-0.14469266210702247, fourthRootsOfZ[0].getImaginary(), 1.0e-5);
+ // test z_1
+ Assert.assertEquals(0.14469266210702256, fourthRootsOfZ[1].getReal(), 1.0e-5);
+ Assert.assertEquals(1.5164629308487783, fourthRootsOfZ[1].getImaginary(), 1.0e-5);
+ // test z_2
+ Assert.assertEquals(-1.5164629308487783, fourthRootsOfZ[2].getReal(), 1.0e-5);
+ Assert.assertEquals(0.14469266210702267, fourthRootsOfZ[2].getImaginary(), 1.0e-5);
+ // test z_3
+ Assert.assertEquals(-0.14469266210702275, fourthRootsOfZ[3].getReal(), 1.0e-5);
+ Assert.assertEquals(-1.5164629308487783, fourthRootsOfZ[3].getImaginary(), 1.0e-5);
+ }
+
+ /**
+ * Test: computing <b>third roots</b> of z.
+ * <pre>
+ * <code>
+ * <b>z = 8</b>
+ * => z_0 = 2
+ * => z_1 = -1 + 1.73205 * i
+ * => z_2 = -1 - 1.73205 * i
+ * </code>
+ * </pre>
+ */
+ @Test
+ public void testNthRoot_cornercase_thirdRoot_imaginaryPartEmpty() {
+ // The number 8 has three third roots. One we all already know is the number 2.
+ // But there are two more complex roots.
+ Complex z = new Complex(8,0);
+ // The List holding all third roots
+ Complex[] thirdRootsOfZ = z.nthRoot(3).toArray(new Complex[0]);
+ // Returned Collection must not be empty!
+ Assert.assertEquals(3, thirdRootsOfZ.length);
+ // test z_0
+ Assert.assertEquals(2.0, thirdRootsOfZ[0].getReal(), 1.0e-5);
+ Assert.assertEquals(0.0, thirdRootsOfZ[0].getImaginary(), 1.0e-5);
+ // test z_1
+ Assert.assertEquals(-1.0, thirdRootsOfZ[1].getReal(), 1.0e-5);
+ Assert.assertEquals(1.7320508075688774, thirdRootsOfZ[1].getImaginary(), 1.0e-5);
+ // test z_2
+ Assert.assertEquals(-1.0, thirdRootsOfZ[2].getReal(), 1.0e-5);
+ Assert.assertEquals(-1.732050807568877, thirdRootsOfZ[2].getImaginary(), 1.0e-5);
+ }
+
+
+ /**
+ * Test: computing <b>third roots</b> of z with real part 0.
+ * <pre>
+ * <code>
+ * <b>z = 2 * i</b>
+ * => z_0 = 1.0911 + 0.6299 * i
+ * => z_1 = -1.0911 + 0.6299 * i
+ * => z_2 = -2.3144 - 1.2599 * i
+ * </code>
+ * </pre>
+ */
+ @Test
+ public void testNthRoot_cornercase_thirdRoot_realPartZero() {
+ // complex number with only imaginary part
+ Complex z = new Complex(0,2);
+ // The List holding all third roots
+ Complex[] thirdRootsOfZ = z.nthRoot(3).toArray(new Complex[0]);
+ // Returned Collection must not be empty!
+ Assert.assertEquals(3, thirdRootsOfZ.length);
+ // test z_0
+ Assert.assertEquals(1.0911236359717216, thirdRootsOfZ[0].getReal(), 1.0e-5);
+ Assert.assertEquals(0.6299605249474365, thirdRootsOfZ[0].getImaginary(), 1.0e-5);
+ // test z_1
+ Assert.assertEquals(-1.0911236359717216, thirdRootsOfZ[1].getReal(), 1.0e-5);
+ Assert.assertEquals(0.6299605249474365, thirdRootsOfZ[1].getImaginary(), 1.0e-5);
+ // test z_2
+ Assert.assertEquals(-2.3144374213981936E-16, thirdRootsOfZ[2].getReal(), 1.0e-5);
+ Assert.assertEquals(-1.2599210498948732, thirdRootsOfZ[2].getImaginary(), 1.0e-5);
+ }
+
+ /**
+ * Test cornercases with NaN and Infinity.
+ */
+ @Test
+ public void testNthRoot_cornercase_NAN_Inf() {
+ // NaN + finite -> NaN
+ List<Complex> roots = oneNaN.nthRoot(3);
+ Assert.assertEquals(1,roots.size());
+ Assert.assertEquals(Complex.NaN, roots.get(0));
+
+ roots = nanZero.nthRoot(3);
+ Assert.assertEquals(1,roots.size());
+ Assert.assertEquals(Complex.NaN, roots.get(0));
+
+ // NaN + infinite -> NaN
+ roots = nanInf.nthRoot(3);
+ Assert.assertEquals(1,roots.size());
+ Assert.assertEquals(Complex.NaN, roots.get(0));
+
+ // finite + infinite -> Inf
+ roots = oneInf.nthRoot(3);
+ Assert.assertEquals(1,roots.size());
+ Assert.assertEquals(Complex.INF, roots.get(0));
+
+ // infinite + infinite -> Inf
+ roots = negInfInf.nthRoot(3);
+ Assert.assertEquals(1,roots.size());
+ Assert.assertEquals(Complex.INF, roots.get(0));
+ }
+
+ /**
+ * Test standard values
+ */
+ @Test
+ public void testGetArgument() {
+ Complex z = new Complex(1, 0);
+ Assert.assertEquals(0.0, z.getArgument(), 1.0e-12);
+
+ z = new Complex(1, 1);
+ Assert.assertEquals(Math.PI/4, z.getArgument(), 1.0e-12);
+
+ z = new Complex(0, 1);
+ Assert.assertEquals(Math.PI/2, z.getArgument(), 1.0e-12);
+
+ z = new Complex(-1, 1);
+ Assert.assertEquals(3 * Math.PI/4, z.getArgument(), 1.0e-12);
+
+ z = new Complex(-1, 0);
+ Assert.assertEquals(Math.PI, z.getArgument(), 1.0e-12);
+
+ z = new Complex(-1, -1);
+ Assert.assertEquals(-3 * Math.PI/4, z.getArgument(), 1.0e-12);
+
+ z = new Complex(0, -1);
+ Assert.assertEquals(-Math.PI/2, z.getArgument(), 1.0e-12);
+
+ z = new Complex(1, -1);
+ Assert.assertEquals(-Math.PI/4, z.getArgument(), 1.0e-12);
+
+ }
+
+ /**
+ * Verify atan2-style handling of infinite parts
+ */
+ @Test
+ public void testGetArgumentInf() {
+ Assert.assertEquals(Math.PI/4, infInf.getArgument(), 1.0e-12);
+ Assert.assertEquals(Math.PI/2, oneInf.getArgument(), 1.0e-12);
+ Assert.assertEquals(0.0, infOne.getArgument(), 1.0e-12);
+ Assert.assertEquals(Math.PI/2, zeroInf.getArgument(), 1.0e-12);
+ Assert.assertEquals(0.0, infZero.getArgument(), 1.0e-12);
+ Assert.assertEquals(Math.PI, negInfOne.getArgument(), 1.0e-12);
+ Assert.assertEquals(-3.0*Math.PI/4, negInfNegInf.getArgument(), 1.0e-12);
+ Assert.assertEquals(-Math.PI/2, oneNegInf.getArgument(), 1.0e-12);
+ }
+
+ /**
+ * Verify that either part NaN results in NaN
+ */
+ @Test
+ public void testGetArgumentNaN() {
+ Assert.assertTrue(Double.isNaN(nanZero.getArgument()));
+ Assert.assertTrue(Double.isNaN(zeroNaN.getArgument()));
+ Assert.assertTrue(Double.isNaN(Complex.NaN.getArgument()));
+ }
+
+ @Test
+ public void testSerial() {
+ Complex z = new Complex(3.0, 4.0);
+ Assert.assertEquals(z, TestUtils.serializeAndRecover(z));
+ Complex ncmplx = (Complex)TestUtils.serializeAndRecover(oneNaN);
+ Assert.assertEquals(nanZero, ncmplx);
+ Assert.assertTrue(ncmplx.isNaN());
+ Complex infcmplx = (Complex)TestUtils.serializeAndRecover(infInf);
+ Assert.assertEquals(infInf, infcmplx);
+ Assert.assertTrue(infcmplx.isInfinite());
+ TestComplex tz = new TestComplex(3.0, 4.0);
+ Assert.assertEquals(tz, TestUtils.serializeAndRecover(tz));
+ TestComplex ntcmplx = (TestComplex)TestUtils.serializeAndRecover(new TestComplex(oneNaN));
+ Assert.assertEquals(nanZero, ntcmplx);
+ Assert.assertTrue(ntcmplx.isNaN());
+ TestComplex inftcmplx = (TestComplex)TestUtils.serializeAndRecover(new TestComplex(infInf));
+ Assert.assertEquals(infInf, inftcmplx);
+ Assert.assertTrue(inftcmplx.isInfinite());
+ }
+
+ /**
+ * Class to test extending Complex
+ */
+ public static class TestComplex extends Complex {
+
+ /**
+ * Serialization identifier.
+ */
+ private static final long serialVersionUID = 3268726724160389237L;
+
+ public TestComplex(double real, double imaginary) {
+ super(real, imaginary);
+ }
+
+ public TestComplex(Complex other){
+ this(other.getReal(), other.getImaginary());
+ }
+
+ @Override
+ protected TestComplex createComplex(double real, double imaginary){
+ return new TestComplex(real, imaginary);
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexUtilsTest.java
----------------------------------------------------------------------
diff --git a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexUtilsTest.java b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexUtilsTest.java
new file mode 100644
index 0000000..9a7a29d
--- /dev/null
+++ b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexUtilsTest.java
@@ -0,0 +1,475 @@
+/*
+ * 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.
+ */
+
+package org.apache.commons.numbers.complex;
+
+import org.apache.commons.numbers.complex.Complex;
+import org.apache.commons.numbers.complex.ComplexUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ */
+public class ComplexUtilsTest {
+
+ private final double inf = Double.POSITIVE_INFINITY;
+ private final double negInf = Double.NEGATIVE_INFINITY;
+ private final double nan = Double.NaN;
+ private final double pi = Math.PI;
+
+ private final Complex negInfInf = new Complex(negInf, inf);
+ private final Complex infNegInf = new Complex(inf, negInf);
+ private final Complex infInf = new Complex(inf, inf);
+ private final Complex negInfNegInf = new Complex(negInf, negInf);
+ private final Complex infNaN = new Complex(inf, nan);
+
+ private static Complex c[]; // complex array with real values even and imag
+ // values odd
+ private static Complex cr[]; // complex array with real values consecutive
+ private static Complex ci[]; // complex array with imag values consecutive
+ private static double d[]; // real array with consecutive vals
+ private static double di[]; // real array with consecutive vals,
+ // 'interleaved' length
+ private static float f[]; // real array with consecutive vals
+ private static float fi[]; // real array with consec vals, interleaved
+ // length
+ private static double sr[]; // real component of split array, evens
+ private static double si[]; // imag component of split array, odds
+ private static float sfr[]; // real component of split array, float, evens
+ private static float sfi[]; // imag component of split array, float, odds
+ static Complex ans1, ans2; // answers to single value extraction methods
+ static Complex[] ansArrayc1r, ansArrayc1i, ansArrayc2r, ansArrayc2i, ansArrayc3, ansArrayc4; // answers
+ // to
+ // range
+ // extraction
+ // methods
+ static double[] ansArrayd1r, ansArrayd2r, ansArrayd1i, ansArrayd2i, ansArraydi1, ansArraydi2;
+ static float[] ansArrayf1r, ansArrayf2r, ansArrayf1i, ansArrayf2i, ansArrayfi1, ansArrayfi2;
+ static String msg; // error message for AssertEquals
+ static Complex[][] c2d, cr2d, ci2d; // for 2d methods
+ static Complex[][][] c3d, cr3d, ci3d; // for 3d methods
+ static double[][] d2d, di2d, sr2d, si2d;
+ static double[][][] d3d, di3d, sr3d, si3d;
+ static float[][] f2d, fi2d, sfr2d, sfi2d;
+ static float[][][] f3d, fi3d, sfr3d, sfi3d;
+
+ private static void setArrays() { // initial setup method
+ c = new Complex[10];
+ cr = new Complex[10];
+ ci = new Complex[10];
+ d = new double[10];
+ f = new float[10];
+ di = new double[20];
+ fi = new float[20];
+ sr = new double[10];
+ si = new double[10];
+ sfr = new float[10];
+ sfi = new float[10];
+ c2d = new Complex[10][10];
+ cr2d = new Complex[10][10];
+ ci2d = new Complex[10][10];
+ c3d = new Complex[10][10][10];
+ cr3d = new Complex[10][10][10];
+ ci3d = new Complex[10][10][10];
+ d2d = new double[10][10];
+ d3d = new double[10][10][10];
+ f2d = new float[10][10];
+ f3d = new float[10][10][10];
+ sr2d = new double[10][10];
+ sr3d = new double[10][10][10];
+ si2d = new double[10][10];
+ si3d = new double[10][10][10];
+ sfr2d = new float[10][10];
+ sfr3d = new float[10][10][10];
+ sfi2d = new float[10][10];
+ sfi3d = new float[10][10][10];
+ di2d = new double[10][20];
+ di3d = new double[10][10][20];
+ fi2d = new float[10][20];
+ fi3d = new float[10][10][20];
+ for (int i = 0; i < 20; i += 2) {
+ d[i / 2] = i / 2;
+ f[i / 2] = i / 2;
+ di[i] = i;
+ di[i + 1] = i + 1;
+ fi[i] = i;
+ fi[i + 1] = i + 1;
+ c[i / 2] = new Complex(i, i + 1);
+ cr[i / 2] = new Complex(i / 2);
+ ci[i / 2] = new Complex(0, i / 2);
+ sr[i / 2] = i;
+ si[i / 2] = i + 1;
+ sfr[i / 2] = i;
+ sfi[i / 2] = i + 1;
+ }
+ for (int i = 0; i < 10; i++) {
+ for (int j = 0; j < 20; j += 2) {
+ d2d[i][j / 2] = 10 * i + j / 2;
+ f2d[i][j / 2] = 10 * i + j / 2;
+ sr2d[i][j / 2] = 10 * i + j;
+ si2d[i][j / 2] = 10 * i + j + 1;
+ sfr2d[i][j / 2] = 10 * i + j;
+ sfi2d[i][j / 2] = 10 * i + j + 1;
+ di2d[i][j] = 10 * i + j;
+ di2d[i][j + 1] = 10 * i + j + 1;
+ fi2d[i][j] = 10 * i + j;
+ fi2d[i][j + 1] = 10 * i + j + 1;
+ c2d[i][j / 2] = new Complex(10 * i + j, 10 * i + j + 1);
+ cr2d[i][j / 2] = new Complex(10 * i + j / 2);
+ ci2d[i][j / 2] = new Complex(0, 10 * i + j / 2);
+ }
+ }
+ for (int i = 0; i < 10; i++) {
+ for (int j = 0; j < 10; j++) {
+ for (int k = 0; k < 20; k += 2) {
+ d3d[i][j][k / 2] = 100 * i + 10 * j + k / 2;
+ f3d[i][j][k / 2] = 100 * i + 10 * j + k / 2;
+ sr3d[i][j][k / 2] = 100 * i + 10 * j + k;
+ si3d[i][j][k / 2] = 100 * i + 10 * j + k + 1;
+ sfr3d[i][j][k / 2] = 100 * i + 10 * j + k;
+ sfi3d[i][j][k / 2] = 100 * i + 10 * j + k + 1;
+ di3d[i][j][k] = 100 * i + 10 * j + k;
+ di3d[i][j][k + 1] = 100 * i + 10 * j + k + 1;
+ fi3d[i][j][k] = 100 * i + 10 * j + k;
+ fi3d[i][j][k + 1] = 100 * i + 10 * j + k + 1;
+ c3d[i][j][k / 2] = new Complex(100 * i + 10 * j + k, 100 * i + 10 * j + k + 1);
+ cr3d[i][j][k / 2] = new Complex(100 * i + 10 * j + k / 2);
+ ci3d[i][j][k / 2] = new Complex(0, 100 * i + 10 * j + k / 2);
+ }
+ }
+ }
+ ansArrayc1r = new Complex[] { new Complex(3), new Complex(4), new Complex(5), new Complex(6), new Complex(7) };
+ ansArrayc2r = new Complex[] { new Complex(3), new Complex(5), new Complex(7) };
+ ansArrayc1i = new Complex[] { new Complex(0, 3), new Complex(0, 4), new Complex(0, 5), new Complex(0, 6),
+ new Complex(0, 7) };
+ ansArrayc2i = new Complex[] { new Complex(0, 3), new Complex(0, 5), new Complex(0, 7) };
+ ansArrayc3 = new Complex[] { new Complex(6, 7), new Complex(8, 9), new Complex(10, 11), new Complex(12, 13),
+ new Complex(14, 15) };
+ ansArrayc4 = new Complex[] { new Complex(6, 7), new Complex(10, 11), new Complex(14, 15) };
+ ansArrayd1r = new double[] { 6, 8, 10, 12, 14 };
+ ansArrayd1i = new double[] { 7, 9, 11, 13, 15 };
+ ansArrayd2r = new double[] { 6, 10, 14 };
+ ansArrayd2i = new double[] { 7, 11, 15 };
+ ansArrayf1r = new float[] { 6, 8, 10, 12, 14 };
+ ansArrayf1i = new float[] { 7, 9, 11, 13, 15 };
+ ansArrayf2r = new float[] { 6, 10, 14 };
+ ansArrayf2i = new float[] { 7, 11, 15 };
+ ansArraydi1 = new double[] { 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
+ ansArrayfi1 = new float[] { 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
+ ansArraydi2 = new double[] { 6, 7, 10, 11, 14, 15 };
+ ansArrayfi2 = new float[] { 6, 7, 10, 11, 14, 15 };
+ msg = "";
+ }
+
+ @Test
+ public void testPolar2Complex() {
+ TestUtils.assertEquals(Complex.ONE, ComplexUtils.polar2Complex(1, 0), 10e-12);
+ TestUtils.assertEquals(Complex.ZERO, ComplexUtils.polar2Complex(0, 1), 10e-12);
+ TestUtils.assertEquals(Complex.ZERO, ComplexUtils.polar2Complex(0, -1), 10e-12);
+ TestUtils.assertEquals(Complex.I, ComplexUtils.polar2Complex(1, pi / 2), 10e-12);
+ TestUtils.assertEquals(Complex.I.negate(), ComplexUtils.polar2Complex(1, -pi / 2), 10e-12);
+ double r = 0;
+ for (int i = 0; i < 5; i++) {
+ r += i;
+ double theta = 0;
+ for (int j = 0; j < 20; j++) {
+ theta += pi / 6;
+ TestUtils.assertEquals(altPolar(r, theta), ComplexUtils.polar2Complex(r, theta), 10e-12);
+ }
+ theta = -2 * pi;
+ for (int j = 0; j < 20; j++) {
+ theta -= pi / 6;
+ TestUtils.assertEquals(altPolar(r, theta), ComplexUtils.polar2Complex(r, theta), 10e-12);
+ }
+ }
+ }
+
+ protected Complex altPolar(double r, double theta) {
+ return Complex.I.multiply(new Complex(theta, 0)).exp().multiply(new Complex(r, 0));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testPolar2ComplexIllegalModulus() {
+ ComplexUtils.polar2Complex(-1, 0);
+ }
+
+ @Test
+ public void testPolar2ComplexNaN() {
+ TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(nan, 1));
+ TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(1, nan));
+ TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(nan, nan));
+ }
+
+ @Test
+ public void testPolar2ComplexInf() {
+ TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(1, inf));
+ TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(1, negInf));
+ TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(inf, inf));
+ TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(inf, negInf));
+ TestUtils.assertSame(infInf, ComplexUtils.polar2Complex(inf, pi / 4));
+ TestUtils.assertSame(infNaN, ComplexUtils.polar2Complex(inf, 0));
+ TestUtils.assertSame(infNegInf, ComplexUtils.polar2Complex(inf, -pi / 4));
+ TestUtils.assertSame(negInfInf, ComplexUtils.polar2Complex(inf, 3 * pi / 4));
+ TestUtils.assertSame(negInfNegInf, ComplexUtils.polar2Complex(inf, 5 * pi / 4));
+ }
+
+ @Test
+ public void testCExtract() {
+ final double[] real = new double[] { negInf, -123.45, 0, 1, 234.56, pi, inf };
+ final Complex[] complex = ComplexUtils.real2Complex(real);
+
+ for (int i = 0; i < real.length; i++) {
+ Assert.assertEquals(real[i], complex[i].getReal(), 0d);
+ }
+ }
+
+ // EXTRACTION METHODS
+
+ @Test
+ public void testExtractionMethods() {
+ setArrays();
+ // Extract complex from real double array, index 3
+ TestUtils.assertSame(new Complex(3), ComplexUtils.extractComplexFromRealArray(d, 3));
+ // Extract complex from real float array, index 3
+ TestUtils.assertSame(new Complex(3), ComplexUtils.extractComplexFromRealArray(f, 3));
+ // Extract real double from complex array, index 3
+ TestUtils.assertSame(6, ComplexUtils.extractRealFromComplexArray(c, 3));
+ // Extract real float from complex array, index 3
+ TestUtils.assertSame(6, ComplexUtils.extractRealFloatFromComplexArray(c, 3));
+ // Extract complex from interleaved double array, index 3
+ TestUtils.assertSame(new Complex(6, 7), ComplexUtils.extractComplexFromInterleavedArray(d, 3));
+ // Extract complex from interleaved float array, index 3
+ TestUtils.assertSame(new Complex(6, 7), ComplexUtils.extractComplexFromInterleavedArray(f, 3));
+ // Extract interleaved double from complex array, index 3
+ TestUtils.assertEquals(msg, new double[] { 6, 7 }, ComplexUtils.extractInterleavedFromComplexArray(c, 3),
+ Math.ulp(1));
+ // Extract interleaved float from complex array, index 3
+ TestUtils.assertEquals(msg, new double[] { 6, 7 }, ComplexUtils.extractInterleavedFromComplexArray(c, 3),
+ Math.ulp(1));
+ if (!msg.equals("")) {
+ throw new RuntimeException(msg);
+ }
+ }
+ // REAL <-> COMPLEX
+
+ @Test
+ public void testRealToComplex() {
+ setArrays();
+ // Real double to complex, range 3-7, increment 1, entered as ints
+ // Real double to complex, whole array
+ TestUtils.assertEquals(msg, cr, ComplexUtils.real2Complex(d),Math.ulp(1.0));
+ // Real float to complex, whole array
+ TestUtils.assertEquals(msg, cr, ComplexUtils.real2Complex(f),Math.ulp(1.0));
+ // 2d
+ for (int i = 0; i < 10; i++) {
+ // Real double to complex, 2d
+ TestUtils.assertEquals(msg, cr2d[i], ComplexUtils.real2Complex(d2d[i]),Math.ulp(1.0));
+ // Real float to complex, 2d
+ TestUtils.assertEquals(msg, cr2d[i], ComplexUtils.real2Complex(f2d[i]),Math.ulp(1.0));
+ }
+ // 3d
+ for (int i = 0; i < 10; i++) {
+ for (int j = 0; j < 10; j++) {
+ // Real double to complex, 3d
+ TestUtils.assertEquals(msg, cr3d[i][j], ComplexUtils.real2Complex(d3d[i][j]),Math.ulp(1.0));
+ // Real float to complex, 3d
+ TestUtils.assertEquals(msg, cr3d[i][j], ComplexUtils.real2Complex(f3d[i][j]),Math.ulp(1.0));
+ }
+ }
+ if (!msg.equals("")) {
+ throw new RuntimeException(msg);
+ }
+ }
+
+ @Test
+ public void testComplexToReal() {
+ setArrays();
+ // Real complex to double, whole array
+ TestUtils.assertEquals(msg, sr, ComplexUtils.complex2Real(c),Math.ulp(1.0));
+ // Real complex to float, whole array
+ TestUtils.assertEquals(msg, sfr, ComplexUtils.complex2RealFloat(c),Math.ulp(1.0f));
+ // 2d
+ for (int i = 0; i < 10; i++) {
+ // Real complex to double, 2d
+ TestUtils.assertEquals(msg, sr2d[i], ComplexUtils.complex2Real(c2d[i]),Math.ulp(1.0));
+ // Real complex to float, 2d
+ TestUtils.assertEquals(msg, sfr2d[i], ComplexUtils.complex2RealFloat(c2d[i]),Math.ulp(1.0f));
+ }
+ // 3d
+ for (int i = 0; i < 10; i++) {
+ for (int j = 0; j < 10; j++) {
+ // Real complex to double, 3d
+ TestUtils.assertEquals(msg, sr3d[i][j], ComplexUtils.complex2Real(c3d[i][j]),Math.ulp(1.0));
+ // Real complex to float, 3d
+ TestUtils.assertEquals(msg, sfr3d[i][j], ComplexUtils.complex2RealFloat(c3d[i][j]),Math.ulp(1.0f));
+ }
+ }
+ if (!msg.equals("")) {
+ throw new RuntimeException(msg);
+ }
+ }
+
+ // IMAGINARY <-> COMPLEX
+
+ @Test
+ public void testImaginaryToComplex() {
+ setArrays();
+ // Imaginary double to complex, whole array
+ TestUtils.assertEquals(msg, ci, ComplexUtils.imaginary2Complex(d),Math.ulp(1.0));
+ // Imaginary float to complex, whole array
+ TestUtils.assertEquals(msg, ci, ComplexUtils.imaginary2Complex(f),Math.ulp(1.0));
+ // 2d
+ for (int i = 0; i < 10; i++) {
+ // Imaginary double to complex, 2d
+ TestUtils.assertEquals(msg, ci2d[i], ComplexUtils.imaginary2Complex(d2d[i]),Math.ulp(1.0));
+ // Imaginary float to complex, 2d
+ TestUtils.assertEquals(msg, ci2d[i], ComplexUtils.imaginary2Complex(f2d[i]),Math.ulp(1.0));
+ }
+ // 3d
+ for (int i = 0; i < 10; i++) {
+ for (int j = 0; j < 10; j++) {
+ // Imaginary double to complex, 3d
+ TestUtils.assertEquals(msg, ci3d[i][j], ComplexUtils.imaginary2Complex(d3d[i][j]),Math.ulp(1.0));
+ // Imaginary float to complex, 3d
+ TestUtils.assertEquals(msg, ci3d[i][j], ComplexUtils.imaginary2Complex(f3d[i][j]),Math.ulp(1.0));
+ }
+ }
+ if (!msg.equals("")) {
+ throw new RuntimeException(msg);
+ }
+ }
+
+ @Test
+ public void testComplexToImaginary() {
+ setArrays();
+ // Imaginary complex to double, whole array
+ TestUtils.assertEquals(msg, si, ComplexUtils.complex2Imaginary(c),Math.ulp(1.0));
+ // Imaginary complex to float, whole array
+ TestUtils.assertEquals(msg, sfi, ComplexUtils.complex2ImaginaryFloat(c),Math.ulp(1.0f));
+ // 2d
+ for (int i = 0; i < 10; i++) {
+ // Imaginary complex to double, 2d
+ TestUtils.assertEquals(msg, si2d[i], ComplexUtils.complex2Imaginary(c2d[i]),Math.ulp(1.0));
+ // Imaginary complex to float, 2d
+ TestUtils.assertEquals(msg, sfi2d[i], ComplexUtils.complex2ImaginaryFloat(c2d[i]),Math.ulp(1.0f));
+ }
+ // 3d
+ for (int i = 0; i < 10; i++) {
+ for (int j = 0; j < 10; j++) {
+ // Imaginary complex to double, 3d
+ TestUtils.assertEquals(msg, si3d[i][j], ComplexUtils.complex2Imaginary(c3d[i][j]),Math.ulp(1.0));
+ // Imaginary complex to float, 3d
+ TestUtils.assertEquals(msg, sfi3d[i][j], ComplexUtils.complex2ImaginaryFloat(c3d[i][j]),Math.ulp(1.0f));
+ }
+ }
+ if (!msg.equals("")) {
+ throw new RuntimeException(msg);
+ }
+ }
+
+ // INTERLEAVED <-> COMPLEX
+
+ @Test
+ public void testInterleavedToComplex() {
+ setArrays();
+ // Interleaved double to complex, whole array
+ TestUtils.assertEquals(msg, c, ComplexUtils.interleaved2Complex(di),Math.ulp(1.0));
+ // Interleaved float to complex, whole array
+ TestUtils.assertEquals(msg, c, ComplexUtils.interleaved2Complex(fi),Math.ulp(1.0));
+ // 2d
+ for (int i = 0; i < 10; i++) {
+ // Interleaved double to complex, 2d
+ TestUtils.assertEquals(msg, c2d[i], ComplexUtils.interleaved2Complex(di2d[i]),Math.ulp(1.0));
+ // Interleaved float to complex, 2d
+ TestUtils.assertEquals(msg, c2d[i], ComplexUtils.interleaved2Complex(fi2d[i]),Math.ulp(1.0));
+ }
+ // 3d
+ for (int i = 0; i < 10; i++) {
+ for (int j = 0; j < 10; j++) {
+ // Interleaved double to complex, 3d
+ TestUtils.assertEquals(msg, c3d[i][j], ComplexUtils.interleaved2Complex(di3d[i][j]),Math.ulp(1.0));
+ // Interleaved float to complex, 3d
+ TestUtils.assertEquals(msg, c3d[i][j], ComplexUtils.interleaved2Complex(fi3d[i][j]),Math.ulp(1.0));
+ }
+ }
+ if (!msg.equals("")) {
+ throw new RuntimeException(msg);
+ }
+ }
+
+ @Test
+ public void testComplexToInterleaved() {
+ setArrays();
+ TestUtils.assertEquals(msg, di, ComplexUtils.complex2Interleaved(c),Math.ulp(1.0));
+ // Interleaved complex to float, whole array
+ TestUtils.assertEquals(msg, fi, ComplexUtils.complex2InterleavedFloat(c),Math.ulp(1.0f));
+ // 2d
+ for (int i = 0; i < 10; i++) {
+ // Interleaved complex to double, 2d
+ TestUtils.assertEquals(msg, di2d[i], ComplexUtils.complex2Interleaved(c2d[i]),Math.ulp(1.0));
+ // Interleaved complex to float, 2d
+ TestUtils.assertEquals(msg, fi2d[i], ComplexUtils.complex2InterleavedFloat(c2d[i]),Math.ulp(1.0f));
+ }
+ // 3d
+ for (int i = 0; i < 10; i++) {
+ for (int j = 0; j < 10; j++) {
+ // Interleaved complex to double, 3d
+ TestUtils.assertEquals(msg, di3d[i][j], ComplexUtils.complex2Interleaved(c3d[i][j]),Math.ulp(1.0));
+ // Interleaved complex to float, 3d
+ TestUtils.assertEquals(msg, fi3d[i][j], ComplexUtils.complex2InterleavedFloat(c3d[i][j]),Math.ulp(1.0f));
+ }
+ }
+ if (!msg.equals("")) {
+ throw new RuntimeException(msg);
+ }
+ }
+
+ // SPLIT TO COMPLEX
+ @Test
+ public void testSplit2Complex() {
+ setArrays();
+ // Split double to complex, whole array
+ TestUtils.assertEquals(msg, c, ComplexUtils.split2Complex(sr, si),Math.ulp(1.0));
+
+ // 2d
+ for (int i = 0; i < 10; i++) {
+ // Split double to complex, 2d
+ TestUtils.assertEquals(msg, c2d[i], ComplexUtils.split2Complex(sr2d[i], si2d[i]),Math.ulp(1.0));
+ }
+ // 3d
+ for (int i = 0; i < 10; i++) {
+ for (int j = 0; j < 10; j++) {
+ // Split double to complex, 3d
+ TestUtils.assertEquals(msg, c3d[i][j], ComplexUtils.split2Complex(sr3d[i][j], si3d[i][j]),Math.ulp(1.0));
+ }
+ }
+ if (!msg.equals("")) {
+ throw new RuntimeException(msg);
+ }
+ }
+
+ // INITIALIZATION METHODS
+
+ @Test
+ public void testInitialize() {
+ Complex[] c = new Complex[10];
+ ComplexUtils.initialize(c);
+ for (Complex cc : c) {
+ TestUtils.assertEquals(new Complex(0, 0), cc, Math.ulp(0));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/RootsOfUnityTest.java
----------------------------------------------------------------------
diff --git a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/RootsOfUnityTest.java b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/RootsOfUnityTest.java
new file mode 100644
index 0000000..df40f99
--- /dev/null
+++ b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/RootsOfUnityTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.
+ */
+package org.apache.commons.numbers.complex;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+
+/**
+ * Unit tests for the {@link RootsOfUnity} class.
+ *
+ */
+public class RootsOfUnityTest {
+ @Test(expected = IllegalArgumentException.class)
+ public void testPrecondition() {
+ new RootsOfUnity(0);
+ }
+ @Test(expected = IndexOutOfBoundsException.class)
+ public void testGetRootPrecondition1() {
+ final int n = 3;
+ final RootsOfUnity roots = new RootsOfUnity(n);
+ roots.getRoot(-1);
+ }
+ @Test(expected = IndexOutOfBoundsException.class)
+ public void testGetRootPrecondition2() {
+ final int n = -2;
+ final RootsOfUnity roots = new RootsOfUnity(n);
+ roots.getRoot(2);
+ }
+
+ @Test
+ public void testGetNumberOfRoots1() {
+ final int n = 5;
+ final RootsOfUnity roots = new RootsOfUnity(n);
+ Assert.assertEquals(n, roots.getNumberOfRoots());
+ Assert.assertTrue(roots.isCounterClockwise());
+ }
+ @Test
+ public void testGetNumberOfRoots2() {
+ final int n = -4;
+ final RootsOfUnity roots = new RootsOfUnity(n);
+ Assert.assertEquals(Math.abs(n), roots.getNumberOfRoots());
+ Assert.assertFalse(roots.isCounterClockwise());
+ }
+
+ @Test
+ public void testComputeRoots() {
+ final double tol = Math.ulp(1d);
+ final org.apache.commons.math3.complex.RootsOfUnity cmRoots =
+ new org.apache.commons.math3.complex.RootsOfUnity();
+ for (int n = -10; n < 11; n++) {
+ final int absN = Math.abs(n);
+ if (n != 0) {
+ cmRoots.computeRoots(n);
+ final RootsOfUnity roots = new RootsOfUnity(n);
+ for (int k = 0; k < absN; k++) {
+ final Complex z = roots.getRoot(k);
+ Assert.assertEquals("n=" + n + " k=" + k,
+ cmRoots.getReal(k),
+ z.getReal(),
+ tol);
+ Assert.assertEquals("n=" + n + " k=" + k,
+ cmRoots.getImaginary(k),
+ z.getImaginary(),
+ tol);
+ }
+ }
+ }
+ }
+}
[20/31] commons-numbers git commit: Correct project info.
Posted by er...@apache.org.
Correct project info.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/8dc0ad8c
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/8dc0ad8c
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/8dc0ad8c
Branch: refs/heads/master
Commit: 8dc0ad8c189688731f2a5635187135b71df3c79d
Parents: 81911e4
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Fri Jan 20 13:45:58 2017 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Fri Jan 20 13:45:58 2017 +0100
----------------------------------------------------------------------
src/site/site.xml | 64 ++++++++++----------------------------------------
1 file changed, 12 insertions(+), 52 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/8dc0ad8c/src/site/site.xml
----------------------------------------------------------------------
diff --git a/src/site/site.xml b/src/site/site.xml
index b6e0f7a..c939d2c 100644
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -15,68 +15,28 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<project name="Math">
+<project name="Numbers">
<bannerRight>
- <name>Commons Math</name>
- <src>/images/math.gif</src>
+ <name>Apache Commons Numbers</name>
+ <src>/images/commons_numbers.small.png</src>
<href>/index.html</href>
</bannerRight>
<body>
- <menu name="Math">
+ <menu name="Numbers">
<item name="Overview" href="/index.html"/>
- <item name="Downloads" href="http://commons.apache.org/math/download_math.cgi"/>
- <item name="Latest API docs (development)" href="apidocs/index.html"/>
- <item name="Javadoc (3.5 release)"
- href="http://commons.apache.org/math/javadocs/api-3.5/index.html"/>
- <item name="Javadoc (3.4.1 release)"
- href="http://commons.apache.org/math/javadocs/api-3.4.1/index.html"/>
- <item name="Javadoc (3.4 release)"
- href="http://commons.apache.org/math/javadocs/api-3.4/index.html"/>
- <item name="Javadoc (3.3 release)"
- href="http://commons.apache.org/math/javadocs/api-3.3/index.html"/>
- <item name="Javadoc (3.2 release)"
- href="http://commons.apache.org/math/javadocs/api-3.2/index.html"/>
- <item name="Javadoc (3.1.1 release)"
- href="http://commons.apache.org/math/javadocs/api-3.1.1/index.html"/>
- <item name="Javadoc (3.1 release)"
- href="http://commons.apache.org/math/javadocs/api-3.1/index.html"/>
- <item name="Javadoc (3.0 release)"
- href="http://commons.apache.org/math/javadocs/api-3.0/index.html"/>
- <item name="Javadoc (2.2 release)"
- href="http://commons.apache.org/math/javadocs/api-2.2/index.html"/>
+ <item name="Downloads" href="http://commons.apache.org/rng/download_rng.cgi"/>
<item name="Issue Tracking" href="/issue-tracking.html"/>
<item name="Source Repository (current)"
- href="http://git-wip-us.apache.org/repos/asf/commons-math.git"/>
- <item name="Wiki"
- href="http://wiki.apache.org/commons/Math"/>
+ href="http://git-wip-us.apache.org/repos/asf/commons-rng.git"/>
+ <!-- <item name="Wiki" -->
+ <!-- href="http://wiki.apache.org/commons/Numbers"/> -->
<item name="Developers Guide" href="/developers.html"/>
- <item name="Proposal" href="/proposal.html"/>
- </menu>
-
- <menu name="User Guide">
- <item name="Contents" href="/userguide/index.html"/>
- <item name="Overview" href="/userguide/overview.html"/>
- <item name="Statistics" href="/userguide/stat.html"/>
- <item name="Data Generation" href="/userguide/random.html"/>
- <item name="Linear Algebra" href="/userguide/linear.html"/>
- <item name="Numerical Analysis" href="/userguide/analysis.html"/>
- <item name="Special Functions" href="/userguide/special.html"/>
- <item name="Utilities" href="/userguide/utilities.html"/>
- <item name="Complex Numbers" href="/userguide/complex.html"/>
- <item name="Distributions" href="/userguide/distribution.html"/>
- <item name="Fractions" href="/userguide/fraction.html"/>
- <item name="Transform Methods" href="/userguide/transform.html"/>
- <item name="Geometry" href="/userguide/geometry.html"/>
- <item name="Optimization" href="/userguide/optimization.html"/>
- <item name="Curve Fitting" href="/userguide/fitting.html"/>
- <item name="Least Squares" href="/userguide/leastsquares.html"/>
- <item name="Ordinary Differential Equations" href="/userguide/ode.html"/>
- <item name="Genetic Algorithms" href="/userguide/genetics.html"/>
- <item name="Filters" href="/userguide/filter.html"/>
- <item name="Machine Learning" href="/userguide/ml.html"/>
- <item name="Exceptions" href="/userguide/exceptions.html"/>
</menu>
+
+ <!-- <menu name="User Guide">
+ <item name="Contents" href="/userguide/index.html"/>
+ </menu> -->
<head>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
[26/31] commons-numbers git commit: Use "date" convention for
assigning serial version identifier.
Posted by er...@apache.org.
Use "date" convention for assigning serial version identifier.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/539279ce
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/539279ce
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/539279ce
Branch: refs/heads/master
Commit: 539279ce0e9de7c68b149afa0a908b72225fd8d8
Parents: f3d40f8
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Fri Jan 20 15:02:31 2017 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Fri Jan 20 15:02:31 2017 +0100
----------------------------------------------------------------------
.../main/java/org/apache/commons/numbers/complex/Complex.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/539279ce/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
----------------------------------------------------------------------
diff --git a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
index 219681b..1d864e6 100644
--- a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
+++ b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
@@ -45,6 +45,9 @@ import java.util.List;
*
*/
public class Complex implements Serializable {
+ /** Serializable version identifier */
+ private static final long serialVersionUID = 201701120L;
+
/** The square root of -1. A number representing "0.0 + 1.0i" */
public static final Complex I = new Complex(0.0, 1.0);
// CHECKSTYLE: stop ConstantName
@@ -58,9 +61,6 @@ public class Complex implements Serializable {
/** A complex number representing "0.0 + 0.0i" */
public static final Complex ZERO = new Complex(0.0, 0.0);
- /** Serializable version identifier */
- private static final long serialVersionUID = -6195664516687396620L;
-
/** The imaginary part. */
private final double imaginary;
/** The real part. */
[29/31] commons-numbers git commit: Removed "@since" tags.
Posted by er...@apache.org.
Removed "@since" tags.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/0a3a6732
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/0a3a6732
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/0a3a6732
Branch: refs/heads/master
Commit: 0a3a6732931a5582d0d9f0a2a1ab8f76efe92623
Parents: b4907a3
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Fri Jan 20 15:26:17 2017 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Fri Jan 20 15:26:17 2017 +0100
----------------------------------------------------------------------
.../apache/commons/numbers/complex/Complex.java | 22 --------------------
1 file changed, 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/0a3a6732/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
----------------------------------------------------------------------
diff --git a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
index 2cfebd6..4d20226 100644
--- a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
+++ b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
@@ -360,7 +360,6 @@ public class Complex implements Serializable {
* and {@code y}.
*
* @see Precision#equals(double,double,int)
- * @since 3.3
*/
public static boolean equals(Complex x, Complex y, int maxUlps) {
return Precision.equals(x.real, y.real, maxUlps) &&
@@ -374,8 +373,6 @@ public class Complex implements Serializable {
* @param x First value (cannot be {@code null}).
* @param y Second value (cannot be {@code null}).
* @return {@code true} if the values are equal.
- *
- * @since 3.3
*/
public static boolean equals(Complex x, Complex y) {
return equals(x, y, 1);
@@ -394,7 +391,6 @@ public class Complex implements Serializable {
* numbers or they are within range of each other.
*
* @see Precision#equals(double,double,double)
- * @since 3.3
*/
public static boolean equals(Complex x, Complex y, double eps) {
return Precision.equals(x.real, y.real, eps) &&
@@ -414,7 +410,6 @@ public class Complex implements Serializable {
* numbers or they are within range of each other.
*
* @see Precision#equalsWithRelativeTolerance(double,double,double)
- * @since 3.3
*/
public static boolean equalsWithRelativeTolerance(Complex x, Complex y,
double eps) {
@@ -624,7 +619,6 @@ public class Complex implements Serializable {
* input argument is {@code NaN} or infinite.
*
* @return the inverse cosine of this complex number.
- * @since 1.2
*/
public Complex acos() {
if (isNaN) {
@@ -646,7 +640,6 @@ public class Complex implements Serializable {
* input argument is {@code NaN} or infinite.</p>
*
* @return the inverse sine of this complex number.
- * @since 1.2
*/
public Complex asin() {
if (isNaN) {
@@ -668,7 +661,6 @@ public class Complex implements Serializable {
* input argument is {@code NaN} or infinite.</p>
*
* @return the inverse tangent of this complex number
- * @since 1.2
*/
public Complex atan() {
if (isNaN) {
@@ -706,7 +698,6 @@ public class Complex implements Serializable {
* </pre>
*
* @return the cosine of this complex number.
- * @since 1.2
*/
public Complex cos() {
if (isNaN) {
@@ -746,7 +737,6 @@ public class Complex implements Serializable {
* </pre>
*
* @return the hyperbolic cosine of this complex number.
- * @since 1.2
*/
public Complex cosh() {
if (isNaN) {
@@ -787,7 +777,6 @@ public class Complex implements Serializable {
* </pre>
*
* @return <code><i>e</i><sup>this</sup></code>.
- * @since 1.2
*/
public Complex exp() {
if (isNaN) {
@@ -832,7 +821,6 @@ public class Complex implements Serializable {
*
* @return the value <code>ln this</code>, the natural logarithm
* of {@code this}.
- * @since 1.2
*/
public Complex log() {
if (isNaN) {
@@ -860,7 +848,6 @@ public class Complex implements Serializable {
*
* @param x exponent to which this {@code Complex} is to be raised.
* @return <code> this<sup>x</sup></code>.
- * @since 1.2
*/
public Complex pow(Complex x) {
checkNotNull(x);
@@ -926,7 +913,6 @@ public class Complex implements Serializable {
* </pre>
*
* @return the sine of this complex number.
- * @since 1.2
*/
public Complex sin() {
if (isNaN) {
@@ -966,7 +952,6 @@ public class Complex implements Serializable {
* </pre>
*
* @return the hyperbolic sine of {@code this}.
- * @since 1.2
*/
public Complex sinh() {
if (isNaN) {
@@ -1009,7 +994,6 @@ public class Complex implements Serializable {
* </pre>
*
* @return the square root of {@code this}.
- * @since 1.2
*/
public Complex sqrt() {
if (isNaN) {
@@ -1044,7 +1028,6 @@ public class Complex implements Serializable {
* infinite or NaN values returned in parts of the result.
*
* @return the square root of <code>1 - this<sup>2</sup></code>.
- * @since 1.2
*/
public Complex sqrt1z() {
return createComplex(1.0, 0.0).subtract(this.multiply(this)).sqrt();
@@ -1080,7 +1063,6 @@ public class Complex implements Serializable {
* </pre>
*
* @return the tangent of {@code this}.
- * @since 1.2
*/
public Complex tan() {
if (isNaN || Double.isInfinite(real)) {
@@ -1131,7 +1113,6 @@ public class Complex implements Serializable {
* </pre>
*
* @return the hyperbolic tangent of {@code this}.
- * @since 1.2
*/
public Complex tanh() {
if (isNaN || Double.isInfinite(imaginary)) {
@@ -1193,7 +1174,6 @@ public class Complex implements Serializable {
*
* @param n Degree of root.
* @return a List of all {@code n}-th roots of {@code this}.
- * @since 2.0
*/
public List<Complex> nthRoot(int n) {
@@ -1236,7 +1216,6 @@ public class Complex implements Serializable {
* @param realPart Real part.
* @param imaginaryPart Imaginary part.
* @return a new complex number instance.
- * @since 1.2
* @see #valueOf(double, double)
*/
protected Complex createComplex(double realPart,
@@ -1279,7 +1258,6 @@ public class Complex implements Serializable {
* deserialize properly.
*
* @return A Complex instance with all fields resolved.
- * @since 2.0
*/
protected final Object readResolve() {
return createComplex(real, imaginary);
[10/31] commons-numbers git commit: Multimodule project setup.
Posted by er...@apache.org.
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/PrecisionTest.java
----------------------------------------------------------------------
diff --git a/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/PrecisionTest.java b/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/PrecisionTest.java
new file mode 100644
index 0000000..188c949
--- /dev/null
+++ b/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/PrecisionTest.java
@@ -0,0 +1,547 @@
+/*
+ * 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.
+ */
+package org.apache.commons.numbers.core;
+
+import java.math.BigDecimal;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test cases for the {@link Precision} class.
+ *
+ */
+public class PrecisionTest {
+ @Test
+ public void testEqualsWithRelativeTolerance() {
+ Assert.assertTrue(Precision.equalsWithRelativeTolerance(0d, 0d, 0d));
+ Assert.assertTrue(Precision.equalsWithRelativeTolerance(0d, 1 / Double.NEGATIVE_INFINITY, 0d));
+
+ final double eps = 1e-14;
+ Assert.assertFalse(Precision.equalsWithRelativeTolerance(1.987654687654968, 1.987654687654988, eps));
+ Assert.assertTrue(Precision.equalsWithRelativeTolerance(1.987654687654968, 1.987654687654987, eps));
+ Assert.assertFalse(Precision.equalsWithRelativeTolerance(1.987654687654968, 1.987654687654948, eps));
+ Assert.assertTrue(Precision.equalsWithRelativeTolerance(1.987654687654968, 1.987654687654949, eps));
+
+ Assert.assertFalse(Precision.equalsWithRelativeTolerance(Precision.SAFE_MIN, 0.0, eps));
+
+ Assert.assertFalse(Precision.equalsWithRelativeTolerance(1.0000000000001e-300, 1e-300, eps));
+ Assert.assertTrue(Precision.equalsWithRelativeTolerance(1.00000000000001e-300, 1e-300, eps));
+
+ Assert.assertFalse(Precision.equalsWithRelativeTolerance(Double.NEGATIVE_INFINITY, 1.23, eps));
+ Assert.assertFalse(Precision.equalsWithRelativeTolerance(Double.POSITIVE_INFINITY, 1.23, eps));
+
+ Assert.assertTrue(Precision.equalsWithRelativeTolerance(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, eps));
+ Assert.assertTrue(Precision.equalsWithRelativeTolerance(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, eps));
+ Assert.assertFalse(Precision.equalsWithRelativeTolerance(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, eps));
+
+ Assert.assertFalse(Precision.equalsWithRelativeTolerance(Double.NaN, 1.23, eps));
+ Assert.assertFalse(Precision.equalsWithRelativeTolerance(Double.NaN, Double.NaN, eps));
+ }
+
+ @Test
+ public void testEqualsIncludingNaN() {
+ double[] testArray = {
+ Double.NaN,
+ Double.POSITIVE_INFINITY,
+ Double.NEGATIVE_INFINITY,
+ 1d,
+ 0d };
+ for (int i = 0; i < testArray.length; i++) {
+ for (int j = 0; j < testArray.length; j++) {
+ if (i == j) {
+ Assert.assertTrue(Precision.equalsIncludingNaN(testArray[i], testArray[j]));
+ Assert.assertTrue(Precision.equalsIncludingNaN(testArray[j], testArray[i]));
+ } else {
+ Assert.assertTrue(!Precision.equalsIncludingNaN(testArray[i], testArray[j]));
+ Assert.assertTrue(!Precision.equalsIncludingNaN(testArray[j], testArray[i]));
+ }
+ }
+ }
+ }
+
+ @Test
+ public void testEqualsWithAllowedDelta() {
+ Assert.assertTrue(Precision.equals(153.0000, 153.0000, .0625));
+ Assert.assertTrue(Precision.equals(153.0000, 153.0625, .0625));
+ Assert.assertTrue(Precision.equals(152.9375, 153.0000, .0625));
+ Assert.assertFalse(Precision.equals(153.0000, 153.0625, .0624));
+ Assert.assertFalse(Precision.equals(152.9374, 153.0000, .0625));
+ Assert.assertFalse(Precision.equals(Double.NaN, Double.NaN, 1.0));
+ Assert.assertTrue(Precision.equals(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, 1.0));
+ Assert.assertTrue(Precision.equals(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, 1.0));
+ Assert.assertFalse(Precision.equals(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 1.0));
+ }
+
+ @Test
+ public void testMath475() {
+ final double a = 1.7976931348623182E16;
+ final double b = Math.nextUp(a);
+
+ double diff = Math.abs(a - b);
+ // Because they are adjacent floating point numbers, "a" and "b" are
+ // considered equal even though the allowed error is smaller than
+ // their difference.
+ Assert.assertTrue(Precision.equals(a, b, 0.5 * diff));
+
+ final double c = Math.nextUp(b);
+ diff = Math.abs(a - c);
+ // Because "a" and "c" are not adjacent, the tolerance is taken into
+ // account for assessing equality.
+ Assert.assertTrue(Precision.equals(a, c, diff));
+ Assert.assertFalse(Precision.equals(a, c, (1 - 1e-16) * diff));
+ }
+
+ @Test
+ public void testEqualsIncludingNaNWithAllowedDelta() {
+ Assert.assertTrue(Precision.equalsIncludingNaN(153.0000, 153.0000, .0625));
+ Assert.assertTrue(Precision.equalsIncludingNaN(153.0000, 153.0625, .0625));
+ Assert.assertTrue(Precision.equalsIncludingNaN(152.9375, 153.0000, .0625));
+ Assert.assertTrue(Precision.equalsIncludingNaN(Double.NaN, Double.NaN, 1.0));
+ Assert.assertTrue(Precision.equalsIncludingNaN(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, 1.0));
+ Assert.assertTrue(Precision.equalsIncludingNaN(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, 1.0));
+ Assert.assertFalse(Precision.equalsIncludingNaN(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 1.0));
+ Assert.assertFalse(Precision.equalsIncludingNaN(153.0000, 153.0625, .0624));
+ Assert.assertFalse(Precision.equalsIncludingNaN(152.9374, 153.0000, .0625));
+ }
+
+ // Tests for floating point equality
+ @Test
+ public void testFloatEqualsWithAllowedUlps() {
+ Assert.assertTrue("+0.0f == -0.0f",Precision.equals(0.0f, -0.0f));
+ Assert.assertTrue("+0.0f == -0.0f (1 ulp)",Precision.equals(0.0f, -0.0f, 1));
+ float oneFloat = 1.0f;
+ Assert.assertTrue("1.0f == 1.0f + 1 ulp",Precision.equals(oneFloat, Float.intBitsToFloat(1 + Float.floatToIntBits(oneFloat))));
+ Assert.assertTrue("1.0f == 1.0f + 1 ulp (1 ulp)",Precision.equals(oneFloat, Float.intBitsToFloat(1 + Float.floatToIntBits(oneFloat)), 1));
+ Assert.assertFalse("1.0f != 1.0f + 2 ulp (1 ulp)",Precision.equals(oneFloat, Float.intBitsToFloat(2 + Float.floatToIntBits(oneFloat)), 1));
+
+ Assert.assertTrue(Precision.equals(153.0f, 153.0f, 1));
+
+ // These tests need adjusting for floating point precision
+// Assert.assertTrue(Precision.equals(153.0f, 153.00000000000003f, 1));
+// Assert.assertFalse(Precision.equals(153.0f, 153.00000000000006f, 1));
+// Assert.assertTrue(Precision.equals(153.0f, 152.99999999999997f, 1));
+// Assert.assertFalse(Precision.equals(153f, 152.99999999999994f, 1));
+//
+// Assert.assertTrue(Precision.equals(-128.0f, -127.99999999999999f, 1));
+// Assert.assertFalse(Precision.equals(-128.0f, -127.99999999999997f, 1));
+// Assert.assertTrue(Precision.equals(-128.0f, -128.00000000000003f, 1));
+// Assert.assertFalse(Precision.equals(-128.0f, -128.00000000000006f, 1));
+
+ Assert.assertTrue(Precision.equals(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, 1));
+ Assert.assertTrue(Precision.equals(Double.MAX_VALUE, Float.POSITIVE_INFINITY, 1));
+
+ Assert.assertTrue(Precision.equals(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, 1));
+ Assert.assertTrue(Precision.equals(-Float.MAX_VALUE, Float.NEGATIVE_INFINITY, 1));
+
+ Assert.assertFalse(Precision.equals(Float.NaN, Float.NaN, 1));
+ Assert.assertFalse(Precision.equals(Float.NaN, Float.NaN, 0));
+ Assert.assertFalse(Precision.equals(Float.NaN, 0, 0));
+ Assert.assertFalse(Precision.equals(Float.NaN, Float.POSITIVE_INFINITY, 0));
+ Assert.assertFalse(Precision.equals(Float.NaN, Float.NEGATIVE_INFINITY, 0));
+
+ Assert.assertFalse(Precision.equals(Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 100000));
+ }
+
+ @Test
+ public void testEqualsWithAllowedUlps() {
+ Assert.assertTrue(Precision.equals(0.0, -0.0, 1));
+
+ Assert.assertTrue(Precision.equals(1.0, 1 + Math.ulp(1d), 1));
+ Assert.assertFalse(Precision.equals(1.0, 1 + 2 * Math.ulp(1d), 1));
+
+ final double nUp1 = Math.nextAfter(1d, Double.POSITIVE_INFINITY);
+ final double nnUp1 = Math.nextAfter(nUp1, Double.POSITIVE_INFINITY);
+ Assert.assertTrue(Precision.equals(1.0, nUp1, 1));
+ Assert.assertTrue(Precision.equals(nUp1, nnUp1, 1));
+ Assert.assertFalse(Precision.equals(1.0, nnUp1, 1));
+
+ Assert.assertTrue(Precision.equals(0.0, Math.ulp(0d), 1));
+ Assert.assertTrue(Precision.equals(0.0, -Math.ulp(0d), 1));
+
+ Assert.assertTrue(Precision.equals(153.0, 153.0, 1));
+
+ Assert.assertTrue(Precision.equals(153.0, 153.00000000000003, 1));
+ Assert.assertFalse(Precision.equals(153.0, 153.00000000000006, 1));
+ Assert.assertTrue(Precision.equals(153.0, 152.99999999999997, 1));
+ Assert.assertFalse(Precision.equals(153, 152.99999999999994, 1));
+
+ Assert.assertTrue(Precision.equals(-128.0, -127.99999999999999, 1));
+ Assert.assertFalse(Precision.equals(-128.0, -127.99999999999997, 1));
+ Assert.assertTrue(Precision.equals(-128.0, -128.00000000000003, 1));
+ Assert.assertFalse(Precision.equals(-128.0, -128.00000000000006, 1));
+
+ Assert.assertTrue(Precision.equals(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, 1));
+ Assert.assertTrue(Precision.equals(Double.MAX_VALUE, Double.POSITIVE_INFINITY, 1));
+
+ Assert.assertTrue(Precision.equals(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, 1));
+ Assert.assertTrue(Precision.equals(-Double.MAX_VALUE, Double.NEGATIVE_INFINITY, 1));
+
+ Assert.assertFalse(Precision.equals(Double.NaN, Double.NaN, 1));
+ Assert.assertFalse(Precision.equals(Double.NaN, Double.NaN, 0));
+ Assert.assertFalse(Precision.equals(Double.NaN, 0, 0));
+ Assert.assertFalse(Precision.equals(Double.NaN, Double.POSITIVE_INFINITY, 0));
+ Assert.assertFalse(Precision.equals(Double.NaN, Double.NEGATIVE_INFINITY, 0));
+
+ Assert.assertFalse(Precision.equals(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 100000));
+ }
+
+ @Test
+ public void testEqualsIncludingNaNWithAllowedUlps() {
+ Assert.assertTrue(Precision.equalsIncludingNaN(0.0, -0.0, 1));
+
+ Assert.assertTrue(Precision.equalsIncludingNaN(1.0, 1 + Math.ulp(1d), 1));
+ Assert.assertFalse(Precision.equalsIncludingNaN(1.0, 1 + 2 * Math.ulp(1d), 1));
+
+ final double nUp1 = Math.nextAfter(1d, Double.POSITIVE_INFINITY);
+ final double nnUp1 = Math.nextAfter(nUp1, Double.POSITIVE_INFINITY);
+ Assert.assertTrue(Precision.equalsIncludingNaN(1.0, nUp1, 1));
+ Assert.assertTrue(Precision.equalsIncludingNaN(nUp1, nnUp1, 1));
+ Assert.assertFalse(Precision.equalsIncludingNaN(1.0, nnUp1, 1));
+
+ Assert.assertTrue(Precision.equalsIncludingNaN(0.0, Math.ulp(0d), 1));
+ Assert.assertTrue(Precision.equalsIncludingNaN(0.0, -Math.ulp(0d), 1));
+
+ Assert.assertTrue(Precision.equalsIncludingNaN(153.0, 153.0, 1));
+
+ Assert.assertTrue(Precision.equalsIncludingNaN(153.0, 153.00000000000003, 1));
+ Assert.assertFalse(Precision.equalsIncludingNaN(153.0, 153.00000000000006, 1));
+ Assert.assertTrue(Precision.equalsIncludingNaN(153.0, 152.99999999999997, 1));
+ Assert.assertFalse(Precision.equalsIncludingNaN(153, 152.99999999999994, 1));
+
+ Assert.assertTrue(Precision.equalsIncludingNaN(-128.0, -127.99999999999999, 1));
+ Assert.assertFalse(Precision.equalsIncludingNaN(-128.0, -127.99999999999997, 1));
+ Assert.assertTrue(Precision.equalsIncludingNaN(-128.0, -128.00000000000003, 1));
+ Assert.assertFalse(Precision.equalsIncludingNaN(-128.0, -128.00000000000006, 1));
+
+ Assert.assertTrue(Precision.equalsIncludingNaN(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, 1));
+ Assert.assertTrue(Precision.equalsIncludingNaN(Double.MAX_VALUE, Double.POSITIVE_INFINITY, 1));
+
+ Assert.assertTrue(Precision.equalsIncludingNaN(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, 1));
+ Assert.assertTrue(Precision.equalsIncludingNaN(-Double.MAX_VALUE, Double.NEGATIVE_INFINITY, 1));
+
+ Assert.assertTrue(Precision.equalsIncludingNaN(Double.NaN, Double.NaN, 1));
+
+ Assert.assertFalse(Precision.equalsIncludingNaN(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 100000));
+ }
+
+ @Test
+ public void testCompareToEpsilon() {
+ Assert.assertEquals(0, Precision.compareTo(152.33, 152.32, .011));
+ Assert.assertTrue(Precision.compareTo(152.308, 152.32, .011) < 0);
+ Assert.assertTrue(Precision.compareTo(152.33, 152.318, .011) > 0);
+ Assert.assertEquals(0, Precision.compareTo(Double.MIN_VALUE, +0.0, Double.MIN_VALUE));
+ Assert.assertEquals(0, Precision.compareTo(Double.MIN_VALUE, -0.0, Double.MIN_VALUE));
+ }
+
+ @Test
+ public void testCompareToMaxUlps() {
+ double a = 152.32;
+ double delta = Math.ulp(a);
+ for (int i = 0; i <= 10; ++i) {
+ if (i <= 5) {
+ Assert.assertEquals( 0, Precision.compareTo(a, a + i * delta, 5));
+ Assert.assertEquals( 0, Precision.compareTo(a, a - i * delta, 5));
+ } else {
+ Assert.assertEquals(-1, Precision.compareTo(a, a + i * delta, 5));
+ Assert.assertEquals(+1, Precision.compareTo(a, a - i * delta, 5));
+ }
+ }
+
+ Assert.assertEquals( 0, Precision.compareTo(-0.0, 0.0, 0));
+
+ Assert.assertEquals(-1, Precision.compareTo(-Double.MIN_VALUE, -0.0, 0));
+ Assert.assertEquals( 0, Precision.compareTo(-Double.MIN_VALUE, -0.0, 1));
+ Assert.assertEquals(-1, Precision.compareTo(-Double.MIN_VALUE, +0.0, 0));
+ Assert.assertEquals( 0, Precision.compareTo(-Double.MIN_VALUE, +0.0, 1));
+
+ Assert.assertEquals(+1, Precision.compareTo( Double.MIN_VALUE, -0.0, 0));
+ Assert.assertEquals( 0, Precision.compareTo( Double.MIN_VALUE, -0.0, 1));
+ Assert.assertEquals(+1, Precision.compareTo( Double.MIN_VALUE, +0.0, 0));
+ Assert.assertEquals( 0, Precision.compareTo( Double.MIN_VALUE, +0.0, 1));
+
+ Assert.assertEquals(-1, Precision.compareTo(-Double.MIN_VALUE, Double.MIN_VALUE, 0));
+ Assert.assertEquals(-1, Precision.compareTo(-Double.MIN_VALUE, Double.MIN_VALUE, 1));
+ Assert.assertEquals( 0, Precision.compareTo(-Double.MIN_VALUE, Double.MIN_VALUE, 2));
+
+ Assert.assertEquals( 0, Precision.compareTo(Double.MAX_VALUE, Double.POSITIVE_INFINITY, 1));
+ Assert.assertEquals(-1, Precision.compareTo(Double.MAX_VALUE, Double.POSITIVE_INFINITY, 0));
+
+ Assert.assertEquals(+1, Precision.compareTo(Double.MAX_VALUE, Double.NaN, Integer.MAX_VALUE));
+ Assert.assertEquals(+1, Precision.compareTo(Double.NaN, Double.MAX_VALUE, Integer.MAX_VALUE));
+ }
+
+ @Test
+ public void testRoundDouble() {
+ double x = 1.234567890;
+ Assert.assertEquals(1.23, Precision.round(x, 2), 0.0);
+ Assert.assertEquals(1.235, Precision.round(x, 3), 0.0);
+ Assert.assertEquals(1.2346, Precision.round(x, 4), 0.0);
+
+ // JIRA MATH-151
+ Assert.assertEquals(39.25, Precision.round(39.245, 2), 0.0);
+ Assert.assertEquals(39.24, Precision.round(39.245, 2, BigDecimal.ROUND_DOWN), 0.0);
+ double xx = 39.0;
+ xx += 245d / 1000d;
+ Assert.assertEquals(39.25, Precision.round(xx, 2), 0.0);
+
+ // BZ 35904
+ Assert.assertEquals(30.1d, Precision.round(30.095d, 2), 0.0d);
+ Assert.assertEquals(30.1d, Precision.round(30.095d, 1), 0.0d);
+ Assert.assertEquals(33.1d, Precision.round(33.095d, 1), 0.0d);
+ Assert.assertEquals(33.1d, Precision.round(33.095d, 2), 0.0d);
+ Assert.assertEquals(50.09d, Precision.round(50.085d, 2), 0.0d);
+ Assert.assertEquals(50.19d, Precision.round(50.185d, 2), 0.0d);
+ Assert.assertEquals(50.01d, Precision.round(50.005d, 2), 0.0d);
+ Assert.assertEquals(30.01d, Precision.round(30.005d, 2), 0.0d);
+ Assert.assertEquals(30.65d, Precision.round(30.645d, 2), 0.0d);
+
+ Assert.assertEquals(1.24, Precision.round(x, 2, BigDecimal.ROUND_CEILING), 0.0);
+ Assert.assertEquals(1.235, Precision.round(x, 3, BigDecimal.ROUND_CEILING), 0.0);
+ Assert.assertEquals(1.2346, Precision.round(x, 4, BigDecimal.ROUND_CEILING), 0.0);
+ Assert.assertEquals(-1.23, Precision.round(-x, 2, BigDecimal.ROUND_CEILING), 0.0);
+ Assert.assertEquals(-1.234, Precision.round(-x, 3, BigDecimal.ROUND_CEILING), 0.0);
+ Assert.assertEquals(-1.2345, Precision.round(-x, 4, BigDecimal.ROUND_CEILING), 0.0);
+
+ Assert.assertEquals(1.23, Precision.round(x, 2, BigDecimal.ROUND_DOWN), 0.0);
+ Assert.assertEquals(1.234, Precision.round(x, 3, BigDecimal.ROUND_DOWN), 0.0);
+ Assert.assertEquals(1.2345, Precision.round(x, 4, BigDecimal.ROUND_DOWN), 0.0);
+ Assert.assertEquals(-1.23, Precision.round(-x, 2, BigDecimal.ROUND_DOWN), 0.0);
+ Assert.assertEquals(-1.234, Precision.round(-x, 3, BigDecimal.ROUND_DOWN), 0.0);
+ Assert.assertEquals(-1.2345, Precision.round(-x, 4, BigDecimal.ROUND_DOWN), 0.0);
+
+ Assert.assertEquals(1.23, Precision.round(x, 2, BigDecimal.ROUND_FLOOR), 0.0);
+ Assert.assertEquals(1.234, Precision.round(x, 3, BigDecimal.ROUND_FLOOR), 0.0);
+ Assert.assertEquals(1.2345, Precision.round(x, 4, BigDecimal.ROUND_FLOOR), 0.0);
+ Assert.assertEquals(-1.24, Precision.round(-x, 2, BigDecimal.ROUND_FLOOR), 0.0);
+ Assert.assertEquals(-1.235, Precision.round(-x, 3, BigDecimal.ROUND_FLOOR), 0.0);
+ Assert.assertEquals(-1.2346, Precision.round(-x, 4, BigDecimal.ROUND_FLOOR), 0.0);
+
+ Assert.assertEquals(1.23, Precision.round(x, 2, BigDecimal.ROUND_HALF_DOWN), 0.0);
+ Assert.assertEquals(1.235, Precision.round(x, 3, BigDecimal.ROUND_HALF_DOWN), 0.0);
+ Assert.assertEquals(1.2346, Precision.round(x, 4, BigDecimal.ROUND_HALF_DOWN), 0.0);
+ Assert.assertEquals(-1.23, Precision.round(-x, 2, BigDecimal.ROUND_HALF_DOWN), 0.0);
+ Assert.assertEquals(-1.235, Precision.round(-x, 3, BigDecimal.ROUND_HALF_DOWN), 0.0);
+ Assert.assertEquals(-1.2346, Precision.round(-x, 4, BigDecimal.ROUND_HALF_DOWN), 0.0);
+ Assert.assertEquals(1.234, Precision.round(1.2345, 3, BigDecimal.ROUND_HALF_DOWN), 0.0);
+ Assert.assertEquals(-1.234, Precision.round(-1.2345, 3, BigDecimal.ROUND_HALF_DOWN), 0.0);
+
+ Assert.assertEquals(1.23, Precision.round(x, 2, BigDecimal.ROUND_HALF_EVEN), 0.0);
+ Assert.assertEquals(1.235, Precision.round(x, 3, BigDecimal.ROUND_HALF_EVEN), 0.0);
+ Assert.assertEquals(1.2346, Precision.round(x, 4, BigDecimal.ROUND_HALF_EVEN), 0.0);
+ Assert.assertEquals(-1.23, Precision.round(-x, 2, BigDecimal.ROUND_HALF_EVEN), 0.0);
+ Assert.assertEquals(-1.235, Precision.round(-x, 3, BigDecimal.ROUND_HALF_EVEN), 0.0);
+ Assert.assertEquals(-1.2346, Precision.round(-x, 4, BigDecimal.ROUND_HALF_EVEN), 0.0);
+ Assert.assertEquals(1.234, Precision.round(1.2345, 3, BigDecimal.ROUND_HALF_EVEN), 0.0);
+ Assert.assertEquals(-1.234, Precision.round(-1.2345, 3, BigDecimal.ROUND_HALF_EVEN), 0.0);
+ Assert.assertEquals(1.236, Precision.round(1.2355, 3, BigDecimal.ROUND_HALF_EVEN), 0.0);
+ Assert.assertEquals(-1.236, Precision.round(-1.2355, 3, BigDecimal.ROUND_HALF_EVEN), 0.0);
+
+ Assert.assertEquals(1.23, Precision.round(x, 2, BigDecimal.ROUND_HALF_UP), 0.0);
+ Assert.assertEquals(1.235, Precision.round(x, 3, BigDecimal.ROUND_HALF_UP), 0.0);
+ Assert.assertEquals(1.2346, Precision.round(x, 4, BigDecimal.ROUND_HALF_UP), 0.0);
+ Assert.assertEquals(-1.23, Precision.round(-x, 2, BigDecimal.ROUND_HALF_UP), 0.0);
+ Assert.assertEquals(-1.235, Precision.round(-x, 3, BigDecimal.ROUND_HALF_UP), 0.0);
+ Assert.assertEquals(-1.2346, Precision.round(-x, 4, BigDecimal.ROUND_HALF_UP), 0.0);
+ Assert.assertEquals(1.235, Precision.round(1.2345, 3, BigDecimal.ROUND_HALF_UP), 0.0);
+ Assert.assertEquals(-1.235, Precision.round(-1.2345, 3, BigDecimal.ROUND_HALF_UP), 0.0);
+
+ Assert.assertEquals(-1.23, Precision.round(-1.23, 2, BigDecimal.ROUND_UNNECESSARY), 0.0);
+ Assert.assertEquals(1.23, Precision.round(1.23, 2, BigDecimal.ROUND_UNNECESSARY), 0.0);
+
+ try {
+ Precision.round(1.234, 2, BigDecimal.ROUND_UNNECESSARY);
+ Assert.fail();
+ } catch (ArithmeticException ex) {
+ // expected
+ }
+
+ Assert.assertEquals(1.24, Precision.round(x, 2, BigDecimal.ROUND_UP), 0.0);
+ Assert.assertEquals(1.235, Precision.round(x, 3, BigDecimal.ROUND_UP), 0.0);
+ Assert.assertEquals(1.2346, Precision.round(x, 4, BigDecimal.ROUND_UP), 0.0);
+ Assert.assertEquals(-1.24, Precision.round(-x, 2, BigDecimal.ROUND_UP), 0.0);
+ Assert.assertEquals(-1.235, Precision.round(-x, 3, BigDecimal.ROUND_UP), 0.0);
+ Assert.assertEquals(-1.2346, Precision.round(-x, 4, BigDecimal.ROUND_UP), 0.0);
+
+ try {
+ Precision.round(1.234, 2, 1923);
+ Assert.fail();
+ } catch (IllegalArgumentException ex) {
+ // expected
+ }
+
+ // MATH-151
+ Assert.assertEquals(39.25, Precision.round(39.245, 2, BigDecimal.ROUND_HALF_UP), 0.0);
+
+ // special values
+ TestUtils.assertEquals(Double.NaN, Precision.round(Double.NaN, 2), 0.0);
+ Assert.assertEquals(0.0, Precision.round(0.0, 2), 0.0);
+ Assert.assertEquals(Double.POSITIVE_INFINITY, Precision.round(Double.POSITIVE_INFINITY, 2), 0.0);
+ Assert.assertEquals(Double.NEGATIVE_INFINITY, Precision.round(Double.NEGATIVE_INFINITY, 2), 0.0);
+ // comparison of positive and negative zero is not possible -> always equal thus do string comparison
+ Assert.assertEquals("-0.0", Double.toString(Precision.round(-0.0, 0)));
+ Assert.assertEquals("-0.0", Double.toString(Precision.round(-1e-10, 0)));
+ }
+
+ @Test
+ public void testRoundFloat() {
+ float x = 1.234567890f;
+ Assert.assertEquals(1.23f, Precision.round(x, 2), 0.0);
+ Assert.assertEquals(1.235f, Precision.round(x, 3), 0.0);
+ Assert.assertEquals(1.2346f, Precision.round(x, 4), 0.0);
+
+ // BZ 35904
+ Assert.assertEquals(30.1f, Precision.round(30.095f, 2), 0.0f);
+ Assert.assertEquals(30.1f, Precision.round(30.095f, 1), 0.0f);
+ Assert.assertEquals(50.09f, Precision.round(50.085f, 2), 0.0f);
+ Assert.assertEquals(50.19f, Precision.round(50.185f, 2), 0.0f);
+ Assert.assertEquals(50.01f, Precision.round(50.005f, 2), 0.0f);
+ Assert.assertEquals(30.01f, Precision.round(30.005f, 2), 0.0f);
+ Assert.assertEquals(30.65f, Precision.round(30.645f, 2), 0.0f);
+
+ Assert.assertEquals(1.24f, Precision.round(x, 2, BigDecimal.ROUND_CEILING), 0.0);
+ Assert.assertEquals(1.235f, Precision.round(x, 3, BigDecimal.ROUND_CEILING), 0.0);
+ Assert.assertEquals(1.2346f, Precision.round(x, 4, BigDecimal.ROUND_CEILING), 0.0);
+ Assert.assertEquals(-1.23f, Precision.round(-x, 2, BigDecimal.ROUND_CEILING), 0.0);
+ Assert.assertEquals(-1.234f, Precision.round(-x, 3, BigDecimal.ROUND_CEILING), 0.0);
+ Assert.assertEquals(-1.2345f, Precision.round(-x, 4, BigDecimal.ROUND_CEILING), 0.0);
+
+ Assert.assertEquals(1.23f, Precision.round(x, 2, BigDecimal.ROUND_DOWN), 0.0);
+ Assert.assertEquals(1.234f, Precision.round(x, 3, BigDecimal.ROUND_DOWN), 0.0);
+ Assert.assertEquals(1.2345f, Precision.round(x, 4, BigDecimal.ROUND_DOWN), 0.0);
+ Assert.assertEquals(-1.23f, Precision.round(-x, 2, BigDecimal.ROUND_DOWN), 0.0);
+ Assert.assertEquals(-1.234f, Precision.round(-x, 3, BigDecimal.ROUND_DOWN), 0.0);
+ Assert.assertEquals(-1.2345f, Precision.round(-x, 4, BigDecimal.ROUND_DOWN), 0.0);
+
+ Assert.assertEquals(1.23f, Precision.round(x, 2, BigDecimal.ROUND_FLOOR), 0.0);
+ Assert.assertEquals(1.234f, Precision.round(x, 3, BigDecimal.ROUND_FLOOR), 0.0);
+ Assert.assertEquals(1.2345f, Precision.round(x, 4, BigDecimal.ROUND_FLOOR), 0.0);
+ Assert.assertEquals(-1.24f, Precision.round(-x, 2, BigDecimal.ROUND_FLOOR), 0.0);
+ Assert.assertEquals(-1.235f, Precision.round(-x, 3, BigDecimal.ROUND_FLOOR), 0.0);
+ Assert.assertEquals(-1.2346f, Precision.round(-x, 4, BigDecimal.ROUND_FLOOR), 0.0);
+
+ Assert.assertEquals(1.23f, Precision.round(x, 2, BigDecimal.ROUND_HALF_DOWN), 0.0);
+ Assert.assertEquals(1.235f, Precision.round(x, 3, BigDecimal.ROUND_HALF_DOWN), 0.0);
+ Assert.assertEquals(1.2346f, Precision.round(x, 4, BigDecimal.ROUND_HALF_DOWN), 0.0);
+ Assert.assertEquals(-1.23f, Precision.round(-x, 2, BigDecimal.ROUND_HALF_DOWN), 0.0);
+ Assert.assertEquals(-1.235f, Precision.round(-x, 3, BigDecimal.ROUND_HALF_DOWN), 0.0);
+ Assert.assertEquals(-1.2346f, Precision.round(-x, 4, BigDecimal.ROUND_HALF_DOWN), 0.0);
+ Assert.assertEquals(1.234f, Precision.round(1.2345f, 3, BigDecimal.ROUND_HALF_DOWN), 0.0);
+ Assert.assertEquals(-1.234f, Precision.round(-1.2345f, 3, BigDecimal.ROUND_HALF_DOWN), 0.0);
+
+ Assert.assertEquals(1.23f, Precision.round(x, 2, BigDecimal.ROUND_HALF_EVEN), 0.0);
+ Assert.assertEquals(1.235f, Precision.round(x, 3, BigDecimal.ROUND_HALF_EVEN), 0.0);
+ Assert.assertEquals(1.2346f, Precision.round(x, 4, BigDecimal.ROUND_HALF_EVEN), 0.0);
+ Assert.assertEquals(-1.23f, Precision.round(-x, 2, BigDecimal.ROUND_HALF_EVEN), 0.0);
+ Assert.assertEquals(-1.235f, Precision.round(-x, 3, BigDecimal.ROUND_HALF_EVEN), 0.0);
+ Assert.assertEquals(-1.2346f, Precision.round(-x, 4, BigDecimal.ROUND_HALF_EVEN), 0.0);
+ Assert.assertEquals(1.234f, Precision.round(1.2345f, 3, BigDecimal.ROUND_HALF_EVEN), 0.0);
+ Assert.assertEquals(-1.234f, Precision.round(-1.2345f, 3, BigDecimal.ROUND_HALF_EVEN), 0.0);
+ Assert.assertEquals(1.236f, Precision.round(1.2355f, 3, BigDecimal.ROUND_HALF_EVEN), 0.0);
+ Assert.assertEquals(-1.236f, Precision.round(-1.2355f, 3, BigDecimal.ROUND_HALF_EVEN), 0.0);
+
+ Assert.assertEquals(1.23f, Precision.round(x, 2, BigDecimal.ROUND_HALF_UP), 0.0);
+ Assert.assertEquals(1.235f, Precision.round(x, 3, BigDecimal.ROUND_HALF_UP), 0.0);
+ Assert.assertEquals(1.2346f, Precision.round(x, 4, BigDecimal.ROUND_HALF_UP), 0.0);
+ Assert.assertEquals(-1.23f, Precision.round(-x, 2, BigDecimal.ROUND_HALF_UP), 0.0);
+ Assert.assertEquals(-1.235f, Precision.round(-x, 3, BigDecimal.ROUND_HALF_UP), 0.0);
+ Assert.assertEquals(-1.2346f, Precision.round(-x, 4, BigDecimal.ROUND_HALF_UP), 0.0);
+ Assert.assertEquals(1.235f, Precision.round(1.2345f, 3, BigDecimal.ROUND_HALF_UP), 0.0);
+ Assert.assertEquals(-1.235f, Precision.round(-1.2345f, 3, BigDecimal.ROUND_HALF_UP), 0.0);
+
+ Assert.assertEquals(-1.23f, Precision.round(-1.23f, 2, BigDecimal.ROUND_UNNECESSARY), 0.0);
+ Assert.assertEquals(1.23f, Precision.round(1.23f, 2, BigDecimal.ROUND_UNNECESSARY), 0.0);
+
+ try {
+ Precision.round(1.234f, 2, BigDecimal.ROUND_UNNECESSARY);
+ Assert.fail();
+ } catch (ArithmeticException ex) {
+ // success
+ }
+
+ Assert.assertEquals(1.24f, Precision.round(x, 2, BigDecimal.ROUND_UP), 0.0);
+ Assert.assertEquals(1.235f, Precision.round(x, 3, BigDecimal.ROUND_UP), 0.0);
+ Assert.assertEquals(1.2346f, Precision.round(x, 4, BigDecimal.ROUND_UP), 0.0);
+ Assert.assertEquals(-1.24f, Precision.round(-x, 2, BigDecimal.ROUND_UP), 0.0);
+ Assert.assertEquals(-1.235f, Precision.round(-x, 3, BigDecimal.ROUND_UP), 0.0);
+ Assert.assertEquals(-1.2346f, Precision.round(-x, 4, BigDecimal.ROUND_UP), 0.0);
+
+ try {
+ Precision.round(1.234f, 2, 1923);
+ Assert.fail();
+ } catch (IllegalArgumentException ex) {
+ // success
+ }
+
+ // special values
+ TestUtils.assertEquals(Float.NaN, Precision.round(Float.NaN, 2), 0.0f);
+ Assert.assertEquals(0.0f, Precision.round(0.0f, 2), 0.0f);
+ Assert.assertEquals(Float.POSITIVE_INFINITY, Precision.round(Float.POSITIVE_INFINITY, 2), 0.0f);
+ Assert.assertEquals(Float.NEGATIVE_INFINITY, Precision.round(Float.NEGATIVE_INFINITY, 2), 0.0f);
+ // comparison of positive and negative zero is not possible -> always equal thus do string comparison
+ Assert.assertEquals("-0.0", Float.toString(Precision.round(-0.0f, 0)));
+ Assert.assertEquals("-0.0", Float.toString(Precision.round(-1e-10f, 0)));
+
+ // MATH-1070
+ Assert.assertEquals(0.0f, Precision.round(0f, 2, BigDecimal.ROUND_UP), 0.0f);
+ Assert.assertEquals(0.05f, Precision.round(0.05f, 2, BigDecimal.ROUND_UP), 0.0f);
+ Assert.assertEquals(0.06f, Precision.round(0.051f, 2, BigDecimal.ROUND_UP), 0.0f);
+ Assert.assertEquals(0.06f, Precision.round(0.0505f, 2, BigDecimal.ROUND_UP), 0.0f);
+ Assert.assertEquals(0.06f, Precision.round(0.059f, 2, BigDecimal.ROUND_UP), 0.0f);
+ }
+
+
+ @Test
+ public void testIssue721() {
+ Assert.assertEquals(-53, Math.getExponent(Precision.EPSILON));
+ Assert.assertEquals(-1022, Math.getExponent(Precision.SAFE_MIN));
+ }
+
+
+ @Test
+ public void testRepresentableDelta() {
+ int nonRepresentableCount = 0;
+ final double x = 100;
+ final int numTrials = 10000;
+ for (int i = 0; i < numTrials; i++) {
+ final double originalDelta = Math.random();
+ final double delta = Precision.representableDelta(x, originalDelta);
+ if (delta != originalDelta) {
+ ++nonRepresentableCount;
+ }
+ }
+
+ Assert.assertTrue(nonRepresentableCount / (double) numTrials > 0.9);
+ }
+
+ @Test
+ public void testMath843() {
+ final double afterEpsilon = Math.nextAfter(Precision.EPSILON,
+ Double.POSITIVE_INFINITY);
+
+ // a) 1 + EPSILON is equal to 1.
+ Assert.assertTrue(1 + Precision.EPSILON == 1);
+
+ // b) 1 + "the number after EPSILON" is not equal to 1.
+ Assert.assertFalse(1 + afterEpsilon == 1);
+ }
+
+ @Test
+ public void testMath1127() {
+ Assert.assertFalse(Precision.equals(2.0, -2.0, 1));
+ Assert.assertTrue(Precision.equals(0.0, -0.0, 0));
+ Assert.assertFalse(Precision.equals(2.0f, -2.0f, 1));
+ Assert.assertTrue(Precision.equals(0.0f, -0.0f, 0));
+ }
+}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/TestUtils.java
----------------------------------------------------------------------
diff --git a/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/TestUtils.java b/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/TestUtils.java
new file mode 100644
index 0000000..6700958
--- /dev/null
+++ b/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/TestUtils.java
@@ -0,0 +1,320 @@
+/*
+ * 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.
+ */
+
+package org.apache.commons.numbers.core;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+
+import org.junit.Assert;
+
+/**
+ * Test utilities.
+ * TODO: Cleanup (remove unused and obsolete methods).
+ */
+public class TestUtils {
+ /**
+ * Collection of static methods used in math unit tests.
+ */
+ private TestUtils() {
+ super();
+ }
+
+ /**
+ * Verifies that expected and actual are within delta, or are both NaN or
+ * infinities of the same sign.
+ */
+ public static void assertEquals(double expected, double actual, double delta) {
+ Assert.assertEquals(null, expected, actual, delta);
+ }
+
+ /**
+ * Verifies that expected and actual are within delta, or are both NaN or
+ * infinities of the same sign.
+ */
+ public static void assertEquals(String msg, double expected, double actual, double delta) {
+ // check for NaN
+ if(Double.isNaN(expected)){
+ Assert.assertTrue("" + actual + " is not NaN.",
+ Double.isNaN(actual));
+ } else {
+ Assert.assertEquals(msg, expected, actual, delta);
+ }
+ }
+
+ /**
+ * Verifies that the two arguments are exactly the same, either
+ * both NaN or infinities of same sign, or identical floating point values.
+ */
+ public static void assertSame(double expected, double actual) {
+ Assert.assertEquals(expected, actual, 0);
+ }
+
+ /**
+ * Verifies that two double arrays have equal entries, up to tolerance
+ */
+ public static void assertEquals(double expected[], double observed[], double tolerance) {
+ assertEquals("Array comparison failure", expected, observed, tolerance);
+ }
+
+ /**
+ * Serializes an object to a bytes array and then recovers the object from the bytes array.
+ * Returns the deserialized object.
+ *
+ * @param o object to serialize and recover
+ * @return the recovered, deserialized object
+ */
+ public static Object serializeAndRecover(Object o) {
+ try {
+ // serialize the Object
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ObjectOutputStream so = new ObjectOutputStream(bos);
+ so.writeObject(o);
+
+ // deserialize the Object
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ ObjectInputStream si = new ObjectInputStream(bis);
+ return si.readObject();
+ } catch (IOException ioe) {
+ return null;
+ } catch (ClassNotFoundException cnfe) {
+ return null;
+ }
+ }
+
+ /**
+ * Verifies that serialization preserves equals and hashCode.
+ * Serializes the object, then recovers it and checks equals and hash code.
+ *
+ * @param object the object to serialize and recover
+ */
+ public static void checkSerializedEquality(Object object) {
+ Object object2 = serializeAndRecover(object);
+ Assert.assertEquals("Equals check", object, object2);
+ Assert.assertEquals("HashCode check", object.hashCode(), object2.hashCode());
+ }
+
+ /**
+ * Verifies that the relative error in actual vs. expected is less than or
+ * equal to relativeError. If expected is infinite or NaN, actual must be
+ * the same (NaN or infinity of the same sign).
+ *
+ * @param expected expected value
+ * @param actual observed value
+ * @param relativeError maximum allowable relative error
+ */
+ public static void assertRelativelyEquals(double expected, double actual,
+ double relativeError) {
+ assertRelativelyEquals(null, expected, actual, relativeError);
+ }
+
+ /**
+ * Verifies that the relative error in actual vs. expected is less than or
+ * equal to relativeError. If expected is infinite or NaN, actual must be
+ * the same (NaN or infinity of the same sign).
+ *
+ * @param msg message to return with failure
+ * @param expected expected value
+ * @param actual observed value
+ * @param relativeError maximum allowable relative error
+ */
+ public static void assertRelativelyEquals(String msg, double expected,
+ double actual, double relativeError) {
+ if (Double.isNaN(expected)) {
+ Assert.assertTrue(msg, Double.isNaN(actual));
+ } else if (Double.isNaN(actual)) {
+ Assert.assertTrue(msg, Double.isNaN(expected));
+ } else if (Double.isInfinite(actual) || Double.isInfinite(expected)) {
+ Assert.assertEquals(expected, actual, relativeError);
+ } else if (expected == 0.0) {
+ Assert.assertEquals(msg, actual, expected, relativeError);
+ } else {
+ double absError = Math.abs(expected) * relativeError;
+ Assert.assertEquals(msg, expected, actual, absError);
+ }
+ }
+
+ /**
+ * Fails iff values does not contain a number within epsilon of x.
+ *
+ * @param msg message to return with failure
+ * @param values double array to search
+ * @param x value sought
+ * @param epsilon tolerance
+ */
+ public static void assertContains(String msg, double[] values,
+ double x, double epsilon) {
+ for (double value : values) {
+ if (Precision.equals(value, x, epsilon)) {
+ return;
+ }
+ }
+ Assert.fail(msg + " Unable to find " + x);
+ }
+
+ /**
+ * Fails iff values does not contain a number within epsilon of x.
+ *
+ * @param values double array to search
+ * @param x value sought
+ * @param epsilon tolerance
+ */
+ public static void assertContains(double[] values, double x,
+ double epsilon) {
+ assertContains(null, values, x, epsilon);
+ }
+
+ /** verifies that two arrays are close (sup norm) */
+ public static void assertEquals(String msg, double[] expected, double[] observed, double tolerance) {
+ StringBuilder out = new StringBuilder(msg);
+ if (expected.length != observed.length) {
+ out.append("\n Arrays not same length. \n");
+ out.append("expected has length ");
+ out.append(expected.length);
+ out.append(" observed length = ");
+ out.append(observed.length);
+ Assert.fail(out.toString());
+ }
+ boolean failure = false;
+ for (int i=0; i < expected.length; i++) {
+ if (!equalsIncludingNaN(expected[i], observed[i], tolerance)) {
+ failure = true;
+ out.append("\n Elements at index ");
+ out.append(i);
+ out.append(" differ. ");
+ out.append(" expected = ");
+ out.append(expected[i]);
+ out.append(" observed = ");
+ out.append(observed[i]);
+ }
+ }
+ if (failure) {
+ Assert.fail(out.toString());
+ }
+ }
+
+ /** verifies that two arrays are close (sup norm) */
+ public static void assertEquals(String msg, float[] expected, float[] observed, float tolerance) {
+ StringBuilder out = new StringBuilder(msg);
+ if (expected.length != observed.length) {
+ out.append("\n Arrays not same length. \n");
+ out.append("expected has length ");
+ out.append(expected.length);
+ out.append(" observed length = ");
+ out.append(observed.length);
+ Assert.fail(out.toString());
+ }
+ boolean failure = false;
+ for (int i=0; i < expected.length; i++) {
+ if (!equalsIncludingNaN(expected[i], observed[i], tolerance)) {
+ failure = true;
+ out.append("\n Elements at index ");
+ out.append(i);
+ out.append(" differ. ");
+ out.append(" expected = ");
+ out.append(expected[i]);
+ out.append(" observed = ");
+ out.append(observed[i]);
+ }
+ }
+ if (failure) {
+ Assert.fail(out.toString());
+ }
+ }
+
+ /**
+ * Updates observed counts of values in quartiles.
+ * counts[0] <-> 1st quartile ... counts[3] <-> top quartile
+ */
+ public static void updateCounts(double value, long[] counts, double[] quartiles) {
+ if (value < quartiles[0]) {
+ counts[0]++;
+ } else if (value > quartiles[2]) {
+ counts[3]++;
+ } else if (value > quartiles[1]) {
+ counts[2]++;
+ } else {
+ counts[1]++;
+ }
+ }
+
+ /**
+ * Eliminates points with zero mass from densityPoints and densityValues parallel
+ * arrays. Returns the number of positive mass points and collapses the arrays so
+ * that the first <returned value> elements of the input arrays represent the positive
+ * mass points.
+ */
+ public static int eliminateZeroMassPoints(int[] densityPoints, double[] densityValues) {
+ int positiveMassCount = 0;
+ for (int i = 0; i < densityValues.length; i++) {
+ if (densityValues[i] > 0) {
+ positiveMassCount++;
+ }
+ }
+ if (positiveMassCount < densityValues.length) {
+ int[] newPoints = new int[positiveMassCount];
+ double[] newValues = new double[positiveMassCount];
+ int j = 0;
+ for (int i = 0; i < densityValues.length; i++) {
+ if (densityValues[i] > 0) {
+ newPoints[j] = densityPoints[i];
+ newValues[j] = densityValues[i];
+ j++;
+ }
+ }
+ System.arraycopy(newPoints,0,densityPoints,0,positiveMassCount);
+ System.arraycopy(newValues,0,densityValues,0,positiveMassCount);
+ }
+ return positiveMassCount;
+ }
+
+ /**
+ * Returns true if the arguments are both NaN, are equal or are within the range
+ * of allowed error (inclusive).
+ *
+ * @param x first value
+ * @param y second value
+ * @param eps the amount of absolute error to allow.
+ * @return {@code true} if the values are equal or within range of each other,
+ * or both are NaN.
+ * @since 2.2
+ */
+ private static boolean equalsIncludingNaN(double x, double y, double eps) {
+ return equalsIncludingNaN(x, y) || (Math.abs(y - x) <= eps);
+ }
+
+ /**
+ * Returns true if the arguments are both NaN or they are
+ * equal as defined by {@link #equals(double,double) equals(x, y, 1)}.
+ *
+ * @param x first value
+ * @param y second value
+ * @return {@code true} if the values are equal or both are NaN.
+ * @since 2.2
+ */
+ private static boolean equalsIncludingNaN(double x, double y) {
+ return (x != x || y != y) ? !(x != x ^ y != y) : Precision.equals(x, y, 1);
+ }
+
+
+}
+
+
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-quaternion/LICENSE.txt
----------------------------------------------------------------------
diff --git a/commons-numbers-quaternion/LICENSE.txt b/commons-numbers-quaternion/LICENSE.txt
new file mode 100644
index 0000000..261eeb9
--- /dev/null
+++ b/commons-numbers-quaternion/LICENSE.txt
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-quaternion/NOTICE.txt
----------------------------------------------------------------------
diff --git a/commons-numbers-quaternion/NOTICE.txt b/commons-numbers-quaternion/NOTICE.txt
new file mode 100644
index 0000000..ea6ae07
--- /dev/null
+++ b/commons-numbers-quaternion/NOTICE.txt
@@ -0,0 +1,6 @@
+Apache Commons Numbers
+Copyright 2001-2016 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-quaternion/README.md
----------------------------------------------------------------------
diff --git a/commons-numbers-quaternion/README.md b/commons-numbers-quaternion/README.md
new file mode 100644
index 0000000..ab9f829
--- /dev/null
+++ b/commons-numbers-quaternion/README.md
@@ -0,0 +1,98 @@
+<!---
+ 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.
+-->
+<!---
+ +======================================================================+
+ |**** ****|
+ |**** THIS FILE IS GENERATED BY THE COMMONS BUILD PLUGIN ****|
+ |**** DO NOT EDIT DIRECTLY ****|
+ |**** ****|
+ +======================================================================+
+ | TEMPLATE FILE: readme-md-template.md |
+ | commons-build-plugin/trunk/src/main/resources/commons-xdoc-templates |
+ +======================================================================+
+ | |
+ | 1) Re-generate using: mvn commons:readme-md |
+ | |
+ | 2) Set the following properties in the component's pom: |
+ | - commons.componentid (required, alphabetic, lower case) |
+ | - commons.release.version (required) |
+ | |
+ | 3) Example Properties |
+ | |
+ | <properties> |
+ | <commons.componentid>math</commons.componentid> |
+ | <commons.release.version>1.2</commons.release.version> |
+ | </properties> |
+ | |
+ +======================================================================+
+--->
+Apache Commons Numbers Quaternion
+===================
+
+Quaternion numbers.
+
+Documentation
+-------------
+
+More information can be found on the [homepage](https://commons.apache.org/proper/commons-numbers).
+The [JavaDoc](https://commons.apache.org/proper/commons-numbers/javadocs/api-release) can be browsed.
+Questions related to the usage of Apache Commons Numbers Quaternion should be posted to the [user mailing list][ml].
+
+Where can I get the latest release?
+-----------------------------------
+You can download source and binaries from our [download page](https://commons.apache.org/proper/commons-numbers/download_numbers.cgi).
+
+Alternatively you can pull it from the central Maven repositories:
+
+```xml
+<dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-quaternion</artifactId>
+ <version>1.0</version>
+</dependency>
+```
+
+Contributing
+------------
+
+We accept PRs via github. The [developer mailing list][ml] is the main channel of communication for contributors.
+There are some guidelines which will make applying PRs easier for us:
++ No tabs! Please use spaces for indentation.
++ Respect the code style.
++ Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change.
++ Provide JUnit tests for your changes and make sure your changes don't break any existing tests by running ```mvn clean test```.
+
+If you plan to contribute on a regular basis, please consider filing a [contributor license agreement](https://www.apache.org/licenses/#clas).
+You can learn more about contributing via GitHub in our [contribution guidelines](CONTRIBUTING.md).
+
+License
+-------
+Code is under the [Apache Licence v2](https://www.apache.org/licenses/LICENSE-2.0.txt).
+
+Donations
+---------
+You like Apache Commons Numbers Quaternion? Then [donate back to the ASF](https://www.apache.org/foundation/contributing.html) to support the development.
+
+Additional Resources
+--------------------
+
++ [Apache Commons Homepage](https://commons.apache.org/)
++ [Apache Bugtracker (JIRA)](https://issues.apache.org/jira/)
++ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons)
++ #apachecommons IRC channel on freenode.org
+
+[ml]:https://commons.apache.org/mail-lists.html
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-quaternion/pom.xml
----------------------------------------------------------------------
diff --git a/commons-numbers-quaternion/pom.xml b/commons-numbers-quaternion/pom.xml
new file mode 100644
index 0000000..76a59e3
--- /dev/null
+++ b/commons-numbers-quaternion/pom.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-parent</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-quaternion</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <name>Apache Commons Numbers Quaternion</name>
+
+ <description>Quaternion numbers.</description>
+
+ <properties>
+ <!-- This value must reflect the current name of the base package. -->
+ <commons.osgi.symbolicName>org.apache.commons.numbers.quaternion</commons.osgi.symbolicName>
+ <!-- OSGi -->
+ <commons.osgi.export>org.apache.commons.numbers.quaternion</commons.osgi.export>
+ <!-- Workaround to avoid duplicating config files. -->
+ <numbers.parent.dir>${basedir}/..</numbers.parent.dir>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-core</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-quaternion/src/main/java/org/apache/commons/numbers/quaternion/Quaternion.java
----------------------------------------------------------------------
diff --git a/commons-numbers-quaternion/src/main/java/org/apache/commons/numbers/quaternion/Quaternion.java b/commons-numbers-quaternion/src/main/java/org/apache/commons/numbers/quaternion/Quaternion.java
new file mode 100644
index 0000000..1722f9b
--- /dev/null
+++ b/commons-numbers-quaternion/src/main/java/org/apache/commons/numbers/quaternion/Quaternion.java
@@ -0,0 +1,455 @@
+/*
+ * 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.
+ */
+
+package org.apache.commons.numbers.quaternion;
+
+import java.util.Arrays;
+import java.io.Serializable;
+import org.apache.commons.numbers.core.Precision;
+
+/**
+ * This class implements <a href="http://mathworld.wolfram.com/Quaternion.html">
+ * quaternions</a> (Hamilton's hypercomplex numbers).
+ *
+ * <p>Instance of this class are guaranteed to be immutable.</p>
+ */
+public final class Quaternion implements Serializable {
+ /** Serializable version identifier. */
+ private static final long serialVersionUID = 20170118L;
+ /** Error message. */
+ private static final String ZERO_NORM_MSG = "Norm is zero";
+
+ /** Identity quaternion. */
+ public static final Quaternion IDENTITY = new Quaternion(1, 0, 0, 0);
+ /** Zero quaternion. */
+ public static final Quaternion ZERO = new Quaternion(0, 0, 0, 0);
+ /** i */
+ public static final Quaternion I = new Quaternion(0, 1, 0, 0);
+ /** j */
+ public static final Quaternion J = new Quaternion(0, 0, 1, 0);
+ /** k */
+ public static final Quaternion K = new Quaternion(0, 0, 0, 1);
+
+ /** First component (scalar part). */
+ private final double q0;
+ /** Second component (first vector part). */
+ private final double q1;
+ /** Third component (second vector part). */
+ private final double q2;
+ /** Fourth component (third vector part). */
+ private final double q3;
+
+ /**
+ * Builds a quaternion from its components.
+ *
+ * @param a Scalar component.
+ * @param b First vector component.
+ * @param c Second vector component.
+ * @param d Third vector component.
+ */
+ public Quaternion(final double a,
+ final double b,
+ final double c,
+ final double d) {
+ q0 = a;
+ q1 = b;
+ q2 = c;
+ q3 = d;
+ }
+
+ /**
+ * Builds a quaternion from scalar and vector parts.
+ *
+ * @param scalar Scalar part of the quaternion.
+ * @param v Components of the vector part of the quaternion.
+ *
+ * @throws IllegalArgumentException if the array length is not 3.
+ */
+ public Quaternion(final double scalar,
+ final double[] v) {
+ if (v.length != 3) {
+ throw new IllegalArgumentException("Size of array must be 3");
+ }
+
+ q0 = scalar;
+ q1 = v[0];
+ q2 = v[1];
+ q3 = v[2];
+ }
+
+ /**
+ * Builds a pure quaternion from a vector (assuming that the scalar
+ * part is zero).
+ *
+ * @param v Components of the vector part of the pure quaternion.
+ */
+ public Quaternion(final double[] v) {
+ this(0, v);
+ }
+
+ /**
+ * Returns the conjugate quaternion of the instance.
+ *
+ * @return the conjugate quaternion
+ */
+ public Quaternion getConjugate() {
+ return new Quaternion(q0, -q1, -q2, -q3);
+ }
+
+ /**
+ * Returns the Hamilton product of two quaternions.
+ *
+ * @param q1 First quaternion.
+ * @param q2 Second quaternion.
+ * @return the product {@code q1} and {@code q2}, in that order.
+ */
+ public static Quaternion multiply(final Quaternion q1,
+ final Quaternion q2) {
+ // Components of the first quaternion.
+ final double q1a = q1.q0;
+ final double q1b = q1.q1;
+ final double q1c = q1.q2;
+ final double q1d = q1.q3;
+
+ // Components of the second quaternion.
+ final double q2a = q2.q0;
+ final double q2b = q2.q1;
+ final double q2c = q2.q2;
+ final double q2d = q2.q3;
+
+ // Components of the product.
+ final double w = q1a * q2a - q1b * q2b - q1c * q2c - q1d * q2d;
+ final double x = q1a * q2b + q1b * q2a + q1c * q2d - q1d * q2c;
+ final double y = q1a * q2c - q1b * q2d + q1c * q2a + q1d * q2b;
+ final double z = q1a * q2d + q1b * q2c - q1c * q2b + q1d * q2a;
+
+ return new Quaternion(w, x, y, z);
+ }
+
+ /**
+ * Returns the Hamilton product of the instance by a quaternion.
+ *
+ * @param q Quaternion.
+ * @return the product of this instance with {@code q}, in that order.
+ */
+ public Quaternion multiply(final Quaternion q) {
+ return multiply(this, q);
+ }
+
+ /**
+ * Computes the sum of two quaternions.
+ *
+ * @param q1 Quaternion.
+ * @param q2 Quaternion.
+ * @return the sum of {@code q1} and {@code q2}.
+ */
+ public static Quaternion add(final Quaternion q1,
+ final Quaternion q2) {
+ return new Quaternion(q1.q0 + q2.q0,
+ q1.q1 + q2.q1,
+ q1.q2 + q2.q2,
+ q1.q3 + q2.q3);
+ }
+
+ /**
+ * Computes the sum of the instance and another quaternion.
+ *
+ * @param q Quaternion.
+ * @return the sum of this instance and {@code q}
+ */
+ public Quaternion add(final Quaternion q) {
+ return add(this, q);
+ }
+
+ /**
+ * Subtracts two quaternions.
+ *
+ * @param q1 First Quaternion.
+ * @param q2 Second quaternion.
+ * @return the difference between {@code q1} and {@code q2}.
+ */
+ public static Quaternion subtract(final Quaternion q1,
+ final Quaternion q2) {
+ return new Quaternion(q1.q0 - q2.q0,
+ q1.q1 - q2.q1,
+ q1.q2 - q2.q2,
+ q1.q3 - q2.q3);
+ }
+
+ /**
+ * Subtracts a quaternion from the instance.
+ *
+ * @param q Quaternion.
+ * @return the difference between this instance and {@code q}.
+ */
+ public Quaternion subtract(final Quaternion q) {
+ return subtract(this, q);
+ }
+
+ /**
+ * Computes the dot-product of two quaternions.
+ *
+ * @param q1 Quaternion.
+ * @param q2 Quaternion.
+ * @return the dot product of {@code q1} and {@code q2}.
+ */
+ public static double dotProduct(final Quaternion q1,
+ final Quaternion q2) {
+ return q1.q0 * q2.q0 +
+ q1.q1 * q2.q1 +
+ q1.q2 * q2.q2 +
+ q1.q3 * q2.q3;
+ }
+
+ /**
+ * Computes the dot-product of the instance by a quaternion.
+ *
+ * @param q Quaternion.
+ * @return the dot product of this instance and {@code q}.
+ */
+ public double dotProduct(final Quaternion q) {
+ return dotProduct(this, q);
+ }
+
+ /**
+ * Computes the norm of the quaternion.
+ *
+ * @return the norm.
+ */
+ public double getNorm() {
+ return Math.sqrt(q0 * q0 +
+ q1 * q1 +
+ q2 * q2 +
+ q3 * q3);
+ }
+
+ /**
+ * Computes the normalized quaternion (the versor of the instance).
+ * The norm of the quaternion must not be zero.
+ *
+ * @return a normalized quaternion.
+ * @throws IllegalStateException if the norm of the quaternion is zero.
+ */
+ public Quaternion normalize() {
+ final double norm = getNorm();
+
+ if (norm < Precision.SAFE_MIN) {
+ throw new IllegalStateException(ZERO_NORM_MSG);
+ }
+
+ return new Quaternion(q0 / norm,
+ q1 / norm,
+ q2 / norm,
+ q3 / norm);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (other instanceof Quaternion) {
+ final Quaternion q = (Quaternion) other;
+ return q0 == q.q0 &&
+ q1 == q.q1 &&
+ q2 == q.q2 &&
+ q3 == q.q3;
+ }
+
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(new double[] { q0, q1, q2, q3 });
+ }
+
+ /**
+ * Checks whether this instance is equal to another quaternion
+ * within a given tolerance.
+ *
+ * @param q Quaternion with which to compare the current quaternion.
+ * @param eps Tolerance.
+ * @return {@code true} if the each of the components are equal
+ * within the allowed absolute error.
+ */
+ public boolean equals(final Quaternion q,
+ final double eps) {
+ return Precision.equals(q0, q.q0, eps) &&
+ Precision.equals(q1, q.q1, eps) &&
+ Precision.equals(q2, q.q2, eps) &&
+ Precision.equals(q3, q.q3, eps);
+ }
+
+ /**
+ * Checks whether the instance is a unit quaternion within a given
+ * tolerance.
+ *
+ * @param eps Tolerance (absolute error).
+ * @return {@code true} if the norm is 1 within the given tolerance,
+ * {@code false} otherwise
+ */
+ public boolean isUnitQuaternion(double eps) {
+ return Precision.equals(getNorm(), 1d, eps);
+ }
+
+ /**
+ * Checks whether the instance is a pure quaternion within a given
+ * tolerance.
+ *
+ * @param eps Tolerance (absolute error).
+ * @return {@code true} if the scalar part of the quaternion is zero.
+ */
+ public boolean isPureQuaternion(double eps) {
+ return Math.abs(q0) <= eps;
+ }
+
+ /**
+ * Returns the polar form of the quaternion.
+ *
+ * @return the unit quaternion with positive scalar part.
+ */
+ public Quaternion getPositivePolarForm() {
+ if (q0 < 0) {
+ final Quaternion unitQ = normalize();
+ // The quaternion of rotation (normalized quaternion) q and -q
+ // are equivalent (i.e. represent the same rotation).
+ return new Quaternion(-unitQ.q0,
+ -unitQ.q1,
+ -unitQ.q2,
+ -unitQ.q3);
+ } else {
+ return this.normalize();
+ }
+ }
+
+ /**
+ * Returns the inverse of this instance.
+ * The norm of the quaternion must not be zero.
+ *
+ * @return the inverse.
+ * @throws IllegalArgumentException if the norm (squared) of the quaternion is zero.
+ */
+ public Quaternion getInverse() {
+ final double squareNorm = q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3;
+ if (squareNorm < Precision.SAFE_MIN) {
+ throw new IllegalStateException(ZERO_NORM_MSG);
+ }
+
+ return new Quaternion(q0 / squareNorm,
+ -q1 / squareNorm,
+ -q2 / squareNorm,
+ -q3 / squareNorm);
+ }
+
+ /**
+ * Gets the first component of the quaternion (scalar part).
+ *
+ * @return the scalar part.
+ */
+ public double getQ0() {
+ return q0;
+ }
+
+ /**
+ * Gets the second component of the quaternion (first component
+ * of the vector part).
+ *
+ * @return the first component of the vector part.
+ */
+ public double getQ1() {
+ return q1;
+ }
+
+ /**
+ * Gets the third component of the quaternion (second component
+ * of the vector part).
+ *
+ * @return the second component of the vector part.
+ */
+ public double getQ2() {
+ return q2;
+ }
+
+ /**
+ * Gets the fourth component of the quaternion (third component
+ * of the vector part).
+ *
+ * @return the third component of the vector part.
+ */
+ public double getQ3() {
+ return q3;
+ }
+
+ /**
+ * Gets the scalar part of the quaternion.
+ *
+ * @return the scalar part.
+ * @see #getQ0()
+ */
+ public double getScalarPart() {
+ return q0;
+ }
+
+ /**
+ * Gets the three components of the vector part of the quaternion.
+ *
+ * @return the vector part.
+ * @see #getQ1()
+ * @see #getQ2()
+ * @see #getQ3()
+ */
+ public double[] getVectorPart() {
+ return new double[] { q1, q2, q3 };
+ }
+
+ /**
+ * Multiplies the instance by a scalar.
+ *
+ * @param alpha Scalar factor.
+ * @return a scaled quaternion.
+ */
+ public Quaternion multiply(final double alpha) {
+ return new Quaternion(alpha * q0,
+ alpha * q1,
+ alpha * q2,
+ alpha * q3);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ final String sp = " ";
+ final StringBuilder s = new StringBuilder();
+ s.append("[")
+ .append(q0).append(sp)
+ .append(q1).append(sp)
+ .append(q2).append(sp)
+ .append(q3)
+ .append("]");
+
+ return s.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-quaternion/src/main/java/org/apache/commons/numbers/quaternion/package-info.java
----------------------------------------------------------------------
diff --git a/commons-numbers-quaternion/src/main/java/org/apache/commons/numbers/quaternion/package-info.java b/commons-numbers-quaternion/src/main/java/org/apache/commons/numbers/quaternion/package-info.java
new file mode 100644
index 0000000..a8696ec
--- /dev/null
+++ b/commons-numbers-quaternion/src/main/java/org/apache/commons/numbers/quaternion/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+/**
+ * Quaternion number type.
+ */
+package org.apache.commons.numbers.quaternion;
[05/31] commons-numbers git commit: Cleanup (massive delete).
Posted by er...@apache.org.
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/chiSquareTestCases
----------------------------------------------------------------------
diff --git a/src/test/R/chiSquareTestCases b/src/test/R/chiSquareTestCases
deleted file mode 100644
index be6eb84..0000000
--- a/src/test/R/chiSquareTestCases
+++ /dev/null
@@ -1,101 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate ChiSquare tests in
-# org.apache.commons.math.stat.inference.ChiSquareTestTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-# R functions used
-#chisq.test(x, y = NULL, correct = TRUE,
-# p = rep(1/length(x), length(x)),
-# simulate.p.value = FALSE, B = 2000)
-#------------------------------------------------------------------------------
-tol <- 1E-9 # error tolerance for tests
-#------------------------------------------------------------------------------
-# Function definitions
-
-source("testFunctions") # utility test functions
-
-verifyTable <- function(counts, expectedP, expectedStat, tol, desc) {
- results <- chisq.test(counts)
- if (assertEquals(expectedP, results$p.value, tol, "p-value")) {
- displayPadded(c(desc," p-value test"), SUCCEEDED, WIDTH)
- } else {
- displayPadded(c(desc, " p-value test"), FAILED, WIDTH)
- }
- if (assertEquals(expectedStat, results$statistic, tol,
- "ChiSquare Statistic")) {
- displayPadded(c(desc, " chi-square statistic test"), SUCCEEDED, WIDTH)
- } else {
- displayPadded(c(desc, " chi-square statistic test"), FAILED, WIDTH)
- }
-}
-
-verifyHomogeneity <- function(obs, exp, expectedP, expectedStat,
- tol, desc) {
- results <- chisq.test(obs,p=exp,rescale.p=TRUE)
- chi <- results$statistic
- p <- results$p.value
- if (assertEquals(expectedP, p, tol, "p-value")) {
- displayPadded(c(desc, " p-value test"), SUCCEEDED, WIDTH)
- } else {
- displayPadded(c(desc, " p-value test"), FAILED, WIDTH)
- }
- if (assertEquals(expectedStat, chi, tol,
- "ChiSquare Statistic")) {
- displayPadded(c(desc, " chi-square statistic test"), SUCCEEDED, WIDTH)
- } else {
- displayPadded(c(desc, " chi-square statistic test"), FAILED, WIDTH)
- }
-}
-
-cat("ChiSquareTest test cases\n")
-
-observed <- c(10, 9, 11)
-expected <- c(10, 10, 10)
-verifyHomogeneity(observed, expected, 0.904837418036, 0.2, tol,
- "testChiSquare1")
-
-observed <- c(500, 623, 72, 70, 31)
-expected <- c(485, 541, 82, 61, 37)
-verifyHomogeneity(observed, expected, 0.06051952647453607, 9.023307936427388,
- tol, "testChiSquare2")
-
-observed <- c(2372383, 584222, 257170, 17750155, 7903832, 489265,
- 209628, 393899)
-expected <- c(3389119.5, 649136.6, 285745.4, 25357364.76, 11291189.78,
- 543628.0, 232921.0, 437665.75)
-verifyHomogeneity(observed, expected, 0, 114875.90421929007, tol,
- "testChiSquareLargeTestStatistic")
-
-counts <- matrix(c(40, 22, 43, 91, 21, 28, 60, 10, 22), nc = 3);
-verifyTable(counts, 0.000144751460134, 22.709027688, tol,
- "testChiSquareIndependence1")
-
-counts <- matrix(c(10, 15, 30, 40, 60, 90), nc = 3);
-verifyTable(counts, 0.918987499852, 0.168965517241, tol,
- "testChiSquareIndependence2")
-
-counts <- matrix(c(40, 0, 4, 91, 1, 2, 60, 2, 0), nc = 3);
-verifyTable(counts, 0.0462835770603, 9.67444662263, tol,
- "testChiSquareZeroCount")
-
-displayDashes(WIDTH)
-
-
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/correlationTestCases
----------------------------------------------------------------------
diff --git a/src/test/R/correlationTestCases b/src/test/R/correlationTestCases
deleted file mode 100644
index 07fdb27..0000000
--- a/src/test/R/correlationTestCases
+++ /dev/null
@@ -1,259 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate Pearson's correlation tests in
-# org.apache.commons.math.stat.correlation.PearsonsCorrelationTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-#------------------------------------------------------------------------------
-tol <- 1E-15 # error tolerance for tests
-#------------------------------------------------------------------------------
-# Function definitions
-
-source("testFunctions") # utility test functions
-options(digits=16) # override number of digits displayed
-
-# Verify Pearson's correlation
-verifyPearsonsCorrelation <- function(matrix, expectedCorrelation, name) {
- correlation <- cor(matrix)
- output <- c("Pearson's Correlation matrix test dataset = ", name)
- if (assertEquals(expectedCorrelation, correlation,tol,"Pearson's Correlations")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# Verify Spearman's correlation
-verifySpearmansCorrelation <- function(matrix, expectedCorrelation, name) {
- correlation <- cor(matrix, method="spearman")
- output <- c("Spearman's Correlation matrix test dataset = ", name)
- if (assertEquals(expectedCorrelation, correlation,tol,"Spearman's Correlations")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# Verify Kendall's correlation
-verifyKendallsCorrelation <- function(matrix, expectedCorrelation, name) {
- correlation <- cor(matrix, method="kendall")
- output <- c("Kendall's Correlation matrix test dataset = ", name)
- if (assertEquals(expectedCorrelation, correlation,tol,"Kendall's Correlations")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify p-values
-verifyPValues <- function(matrix, pValues, name) {
- dimension <- dim(matrix)[2]
- corValues <- matrix(nrow=dimension,ncol=dimension)
- expectedValues <- matrix(nrow=dimension,ncol=dimension)
- for (i in 2:dimension) {
- for (j in 1:(i-1)) {
- corValues[i,j]<-cor.test(matrix[,i], matrix[,j])$p.value
- corValues[j,i]<-corValues[i,j]
- }
- }
- for (i in 1:dimension) {
- corValues[i,i] <- 1
- expectedValues[i,i] <- 1
- }
- ptr <- 1
- for (i in 2:dimension) {
- for (j in 1:(i-1)) {
- expectedValues[i,j] <- pValues[ptr]
- expectedValues[j,i] <- expectedValues[i,j]
- ptr <- ptr + 1
- }
- }
- output <- c("Correlation p-values test dataset = ", name)
- if (assertEquals(expectedValues, corValues,tol,"p-values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
- }
-
-#--------------------------------------------------------------------------
-cat("Correlation test cases\n")
-
-# Longley -----------------------------------------------------------------
-longley <- matrix(c(60323,83.0,234289,2356,1590,107608,1947,
- 61122,88.5,259426,2325,1456,108632,1948,
- 60171,88.2,258054,3682,1616,109773,1949,
- 61187,89.5,284599,3351,1650,110929,1950,
- 63221,96.2,328975,2099,3099,112075,1951,
- 63639,98.1,346999,1932,3594,113270,1952,
- 64989,99.0,365385,1870,3547,115094,1953,
- 63761,100.0,363112,3578,3350,116219,1954,
- 66019,101.2,397469,2904,3048,117388,1955,
- 67857,104.6,419180,2822,2857,118734,1956,
- 68169,108.4,442769,2936,2798,120445,1957,
- 66513,110.8,444546,4681,2637,121950,1958,
- 68655,112.6,482704,3813,2552,123366,1959,
- 69564,114.2,502601,3931,2514,125368,1960,
- 69331,115.7,518173,4806,2572,127852,1961,
- 70551,116.9,554894,4007,2827,130081,1962),
- nrow = 16, ncol = 7, byrow = TRUE)
-
-# Pearson's
-expectedCorrelation <- matrix(c(
- 1.000000000000000, 0.9708985250610560, 0.9835516111796693, 0.5024980838759942,
- 0.4573073999764817, 0.960390571594376, 0.9713294591921188,
- 0.970898525061056, 1.0000000000000000, 0.9915891780247822, 0.6206333925590966,
- 0.4647441876006747, 0.979163432977498, 0.9911491900672053,
- 0.983551611179669, 0.9915891780247822, 1.0000000000000000, 0.6042609398895580,
- 0.4464367918926265, 0.991090069458478, 0.9952734837647849,
- 0.502498083875994, 0.6206333925590966, 0.6042609398895580, 1.0000000000000000,
- -0.1774206295018783, 0.686551516365312, 0.6682566045621746,
- 0.457307399976482, 0.4647441876006747, 0.4464367918926265, -0.1774206295018783,
- 1.0000000000000000, 0.364416267189032, 0.4172451498349454,
- 0.960390571594376, 0.9791634329774981, 0.9910900694584777, 0.6865515163653120,
- 0.3644162671890320, 1.000000000000000, 0.9939528462329257,
- 0.971329459192119, 0.9911491900672053, 0.9952734837647849, 0.6682566045621746,
- 0.4172451498349454, 0.993952846232926, 1.0000000000000000),
- nrow = 7, ncol = 7, byrow = TRUE)
- verifyPearsonsCorrelation(longley, expectedCorrelation, "longley")
-
- expectedPValues <- c(
- 4.38904690369668e-10,
- 8.36353208910623e-12, 7.8159700933611e-14,
- 0.0472894097790304, 0.01030636128354301, 0.01316878049026582,
- 0.0749178049642416, 0.06971758330341182, 0.0830166169296545, 0.510948586323452,
- 3.693245043123738e-09, 4.327782576751815e-11, 1.167954621905665e-13, 0.00331028281967516, 0.1652293725106684,
- 3.95834476307755e-10, 1.114663916723657e-13, 1.332267629550188e-15, 0.00466039138541463, 0.1078477071581498, 7.771561172376096e-15)
- verifyPValues(longley, expectedPValues, "longley")
-
-# Spearman's
-expectedCorrelation <- matrix(c(
- 1, 0.982352941176471, 0.985294117647059, 0.564705882352941, 0.2264705882352941, 0.976470588235294,
- 0.976470588235294, 0.982352941176471, 1, 0.997058823529412, 0.664705882352941, 0.2205882352941176,
- 0.997058823529412, 0.997058823529412, 0.985294117647059, 0.997058823529412, 1, 0.638235294117647,
- 0.2235294117647059, 0.9941176470588236, 0.9941176470588236, 0.564705882352941, 0.664705882352941,
- 0.638235294117647, 1, -0.3411764705882353, 0.685294117647059, 0.685294117647059, 0.2264705882352941,
- 0.2205882352941176, 0.2235294117647059, -0.3411764705882353, 1, 0.2264705882352941, 0.2264705882352941,
- 0.976470588235294, 0.997058823529412, 0.9941176470588236, 0.685294117647059, 0.2264705882352941, 1, 1,
- 0.976470588235294, 0.997058823529412, 0.9941176470588236, 0.685294117647059, 0.2264705882352941, 1, 1),
- nrow = 7, ncol = 7, byrow = TRUE)
- verifySpearmansCorrelation(longley, expectedCorrelation, "longley")
-
-# Kendall's
-expectedCorrelation <- matrix(c(
- 1, 0.9166666666666666, 0.9333333333333332, 0.3666666666666666, 0.05, 0.8999999999999999,
- 0.8999999999999999, 0.9166666666666666, 1, 0.9833333333333333, 0.45, 0.03333333333333333,
- 0.9833333333333333, 0.9833333333333333, 0.9333333333333332, 0.9833333333333333, 1,
- 0.4333333333333333, 0.05, 0.9666666666666666, 0.9666666666666666, 0.3666666666666666,
- 0.45, 0.4333333333333333, 1, -0.2166666666666666, 0.4666666666666666, 0.4666666666666666, 0.05,
- 0.03333333333333333, 0.05, -0.2166666666666666, 1, 0.05, 0.05, 0.8999999999999999, 0.9833333333333333,
- 0.9666666666666666, 0.4666666666666666, 0.05, 1, 0.9999999999999999, 0.8999999999999999,
- 0.9833333333333333, 0.9666666666666666, 0.4666666666666666, 0.05, 0.9999999999999999, 1),
- nrow = 7, ncol = 7, byrow = TRUE)
- verifyKendallsCorrelation(longley, expectedCorrelation, "longley")
-
- # Swiss Fertility ---------------------------------------------------------
- fertility <- matrix(c(80.2,17.0,15,12,9.96,
- 83.1,45.1,6,9,84.84,
- 92.5,39.7,5,5,93.40,
- 85.8,36.5,12,7,33.77,
- 76.9,43.5,17,15,5.16,
- 76.1,35.3,9,7,90.57,
- 83.8,70.2,16,7,92.85,
- 92.4,67.8,14,8,97.16,
- 82.4,53.3,12,7,97.67,
- 82.9,45.2,16,13,91.38,
- 87.1,64.5,14,6,98.61,
- 64.1,62.0,21,12,8.52,
- 66.9,67.5,14,7,2.27,
- 68.9,60.7,19,12,4.43,
- 61.7,69.3,22,5,2.82,
- 68.3,72.6,18,2,24.20,
- 71.7,34.0,17,8,3.30,
- 55.7,19.4,26,28,12.11,
- 54.3,15.2,31,20,2.15,
- 65.1,73.0,19,9,2.84,
- 65.5,59.8,22,10,5.23,
- 65.0,55.1,14,3,4.52,
- 56.6,50.9,22,12,15.14,
- 57.4,54.1,20,6,4.20,
- 72.5,71.2,12,1,2.40,
- 74.2,58.1,14,8,5.23,
- 72.0,63.5,6,3,2.56,
- 60.5,60.8,16,10,7.72,
- 58.3,26.8,25,19,18.46,
- 65.4,49.5,15,8,6.10,
- 75.5,85.9,3,2,99.71,
- 69.3,84.9,7,6,99.68,
- 77.3,89.7,5,2,100.00,
- 70.5,78.2,12,6,98.96,
- 79.4,64.9,7,3,98.22,
- 65.0,75.9,9,9,99.06,
- 92.2,84.6,3,3,99.46,
- 79.3,63.1,13,13,96.83,
- 70.4,38.4,26,12,5.62,
- 65.7,7.7,29,11,13.79,
- 72.7,16.7,22,13,11.22,
- 64.4,17.6,35,32,16.92,
- 77.6,37.6,15,7,4.97,
- 67.6,18.7,25,7,8.65,
- 35.0,1.2,37,53,42.34,
- 44.7,46.6,16,29,50.43,
- 42.8,27.7,22,29,58.33),
- nrow = 47, ncol = 5, byrow = TRUE)
-
-# Pearson's
- expectedCorrelation <- matrix(c(
- 1, 0.3530791836199747, -0.6458827064572875, -0.663788857035069, 0.463684700651794,
- 0.3530791836199747, 1, -0.6865422086171366, -0.63952251894832, 0.4010950530487398,
- -0.6458827064572875, -0.6865422086171366, 1, 0.698415296288483, -0.572741806064167,
- -0.663788857035069, -0.63952251894832, 0.698415296288483, 1, -0.1538589170909148,
- 0.463684700651794, 0.4010950530487398, -0.572741806064167, -0.1538589170909148, 1),
- nrow = 5, ncol = 5, byrow = TRUE)
-verifyPearsonsCorrelation(fertility, expectedCorrelation, "swiss fertility")
-
-expectedPValues <- c(
- 0.01491720061472623,
- 9.45043734069043e-07, 9.95151527133974e-08,
- 3.658616965962355e-07, 1.304590105694471e-06, 4.811397236181847e-08,
- 0.001028523190118147, 0.005204433539191644, 2.588307925380906e-05, 0.301807756132683)
-verifyPValues(fertility, expectedPValues, "swiss fertility")
-
-# Spearman's
-expectedCorrelation <- matrix(c(
- 1, 0.2426642769364176, -0.660902996352354, -0.443257690360988, 0.4136455623012432,
- 0.2426642769364176, 1, -0.598859938748963, -0.650463814145816, 0.2886878090882852,
- -0.660902996352354, -0.598859938748963, 1, 0.674603831406147, -0.4750575257171745,
- -0.443257690360988, -0.650463814145816, 0.674603831406147, 1, -0.1444163088302244,
- 0.4136455623012432, 0.2886878090882852, -0.4750575257171745, -0.1444163088302244, 1),
- nrow = 5, ncol = 5, byrow = TRUE)
- verifySpearmansCorrelation(fertility, expectedCorrelation, "swiss fertility")
-
-# Kendall's
-expectedCorrelation <- matrix(c(
- 1, 0.1795465254708308, -0.4762437404200669, -0.3306111613580587, 0.2453703703703704,
- 0.1795465254708308, 1, -0.4505221560842292, -0.4761645631778491, 0.2054604569820847,
- -0.4762437404200669, -0.4505221560842292, 1, 0.528943683925829, -0.3212755391722673,
- -0.3306111613580587, -0.4761645631778491, 0.528943683925829, 1, -0.08479652265379604,
- 0.2453703703703704, 0.2054604569820847, -0.3212755391722673, -0.08479652265379604, 1),
- nrow = 5, ncol = 5, byrow = TRUE)
- verifyKendallsCorrelation(fertility, expectedCorrelation, "swiss fertility")
-
-displayDashes(WIDTH)
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/covarianceTestCases
----------------------------------------------------------------------
diff --git a/src/test/R/covarianceTestCases b/src/test/R/covarianceTestCases
deleted file mode 100644
index eca5d0b..0000000
--- a/src/test/R/covarianceTestCases
+++ /dev/null
@@ -1,146 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate covariance tests in
-# org.apache.commons.math.stat.correlation.CovarianceTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-#------------------------------------------------------------------------------
-tol <- 1E-9 # error tolerance for tests
-#------------------------------------------------------------------------------
-# Function definitions
-
-source("testFunctions") # utility test functions
-options(digits=16) # override number of digits displayed
-
-# function to verify covariance computations
-verifyCovariance <- function(matrix, expectedCovariance, name) {
- covariance <- cov(matrix)
- output <- c("Covariance test dataset = ", name)
- if (assertEquals(expectedCovariance,covariance,tol,"Covariances")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-#--------------------------------------------------------------------------
-cat("Covariance test cases\n")
-
-# Longley
-
-longley <- matrix(c(60323,83.0,234289,2356,1590,107608,1947,
- 61122,88.5,259426,2325,1456,108632,1948,
- 60171,88.2,258054,3682,1616,109773,1949,
- 61187,89.5,284599,3351,1650,110929,1950,
- 63221,96.2,328975,2099,3099,112075,1951,
- 63639,98.1,346999,1932,3594,113270,1952,
- 64989,99.0,365385,1870,3547,115094,1953,
- 63761,100.0,363112,3578,3350,116219,1954,
- 66019,101.2,397469,2904,3048,117388,1955,
- 67857,104.6,419180,2822,2857,118734,1956,
- 68169,108.4,442769,2936,2798,120445,1957,
- 66513,110.8,444546,4681,2637,121950,1958,
- 68655,112.6,482704,3813,2552,123366,1959,
- 69564,114.2,502601,3931,2514,125368,1960,
- 69331,115.7,518173,4806,2572,127852,1961,
- 70551,116.9,554894,4007,2827,130081,1962),
- nrow = 16, ncol = 7, byrow = TRUE)
-
-expectedCovariance <- matrix(c(
- 12333921.73333333246, 3.679666000000000e+04, 343330206.333333313,
- 1649102.666666666744, 1117681.066666666651, 23461965.733333334, 16240.93333333333248,
- 36796.66000000000, 1.164576250000000e+02, 1063604.115416667,
- 6258.666250000000, 3490.253750000000, 73503.000000000, 50.92333333333334,
- 343330206.33333331347, 1.063604115416667e+06, 9879353659.329166412,
- 56124369.854166664183, 30880428.345833335072, 685240944.600000024, 470977.90000000002328,
- 1649102.66666666674, 6.258666250000000e+03, 56124369.854166664,
- 873223.429166666698, -115378.762499999997, 4462741.533333333, 2973.03333333333330,
- 1117681.06666666665, 3.490253750000000e+03, 30880428.345833335,
- -115378.762499999997, 484304.095833333326, 1764098.133333333, 1382.43333333333339,
- 23461965.73333333433, 7.350300000000000e+04, 685240944.600000024,
- 4462741.533333333209, 1764098.133333333302, 48387348.933333330, 32917.40000000000146,
- 16240.93333333333, 5.092333333333334e+01, 470977.900000000,
- 2973.033333333333, 1382.433333333333, 32917.40000000, 22.66666666666667),
- nrow = 7, ncol = 7, byrow = TRUE)
-
- verifyCovariance(longley, expectedCovariance, "longley")
-
- # Swiss Fertility
-
- fertility <- matrix(c(80.2,17.0,15,12,9.96,
- 83.1,45.1,6,9,84.84,
- 92.5,39.7,5,5,93.40,
- 85.8,36.5,12,7,33.77,
- 76.9,43.5,17,15,5.16,
- 76.1,35.3,9,7,90.57,
- 83.8,70.2,16,7,92.85,
- 92.4,67.8,14,8,97.16,
- 82.4,53.3,12,7,97.67,
- 82.9,45.2,16,13,91.38,
- 87.1,64.5,14,6,98.61,
- 64.1,62.0,21,12,8.52,
- 66.9,67.5,14,7,2.27,
- 68.9,60.7,19,12,4.43,
- 61.7,69.3,22,5,2.82,
- 68.3,72.6,18,2,24.20,
- 71.7,34.0,17,8,3.30,
- 55.7,19.4,26,28,12.11,
- 54.3,15.2,31,20,2.15,
- 65.1,73.0,19,9,2.84,
- 65.5,59.8,22,10,5.23,
- 65.0,55.1,14,3,4.52,
- 56.6,50.9,22,12,15.14,
- 57.4,54.1,20,6,4.20,
- 72.5,71.2,12,1,2.40,
- 74.2,58.1,14,8,5.23,
- 72.0,63.5,6,3,2.56,
- 60.5,60.8,16,10,7.72,
- 58.3,26.8,25,19,18.46,
- 65.4,49.5,15,8,6.10,
- 75.5,85.9,3,2,99.71,
- 69.3,84.9,7,6,99.68,
- 77.3,89.7,5,2,100.00,
- 70.5,78.2,12,6,98.96,
- 79.4,64.9,7,3,98.22,
- 65.0,75.9,9,9,99.06,
- 92.2,84.6,3,3,99.46,
- 79.3,63.1,13,13,96.83,
- 70.4,38.4,26,12,5.62,
- 65.7,7.7,29,11,13.79,
- 72.7,16.7,22,13,11.22,
- 64.4,17.6,35,32,16.92,
- 77.6,37.6,15,7,4.97,
- 67.6,18.7,25,7,8.65,
- 35.0,1.2,37,53,42.34,
- 44.7,46.6,16,29,50.43,
- 42.8,27.7,22,29,58.33),
- nrow = 47, ncol = 5, byrow = TRUE)
-
- expectedCovariance <- matrix(c(
- 156.0424976873265, 100.1691489361702, -64.36692876965772, -79.7295097132285, 241.5632030527289,
- 100.169148936170251, 515.7994172062905, -124.39283071230344, -139.6574005550416, 379.9043755781684,
- -64.3669287696577, -124.3928307123034, 63.64662349676226, 53.5758556891767, -190.5606105457909,
- -79.7295097132285, -139.6574005550416, 53.57585568917669, 92.4560592044403, -61.6988297872340,
- 241.5632030527289, 379.9043755781684, -190.56061054579092, -61.6988297872340, 1739.2945371877890),
- nrow = 5, ncol = 5, byrow = TRUE)
-
- verifyCovariance(fertility, expectedCovariance, "swiss fertility")
-
- displayDashes(WIDTH)
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/descriptiveTestCases
----------------------------------------------------------------------
diff --git a/src/test/R/descriptiveTestCases b/src/test/R/descriptiveTestCases
deleted file mode 100644
index f6a6183..0000000
--- a/src/test/R/descriptiveTestCases
+++ /dev/null
@@ -1,83 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate summary statistics tests in
-# org.apache.commons.math.stat.CertifiedDataTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-# R functions used
-# mean(x)
-# sd(x)
-#------------------------------------------------------------------------------
-tol <- 1E-14 # error tolerance for tests
-#------------------------------------------------------------------------------
-# Function definitions
-
-source("testFunctions") # utility test functions
-options(digits=15) # bump displayed digits to 15
-
-verifyMean <- function(values, expectedMean, tol, desc) {
- results <- mean(values)
- if (assertEquals(expectedMean, results, tol, "mean")) {
- displayPadded(c(desc," mean test"), SUCCEEDED, WIDTH)
- } else {
- displayPadded(c(desc, " mean test"), FAILED, WIDTH)
- }
-}
-
-verifySigma <- function(values, expectedSigma, tol, desc) {
- results <- sd(values)
- if (assertEquals(expectedSigma, results, tol, "std")) {
- displayPadded(c(desc," std test"), SUCCEEDED, WIDTH)
- } else {
- displayPadded(c(desc, " std test"), FAILED, WIDTH)
- }
-}
-
-cat("Descriptive test cases\n")
-
-# Michelson data
-values <- c(299.85,299.74,299.90,300.07,299.93,299.85,299.95,299.98,299.98,
-299.88,300.00,299.98,299.93,299.65,299.76,299.81,300.00,300.00,299.96,299.96,
-299.96,299.94,299.96,299.94,299.88,299.80,299.85,299.88,299.90,299.84,299.83,
-299.79,299.81,299.88,299.88,299.83,299.80,299.79,299.76,299.80,299.88,299.88,
-299.88,299.86,299.72,299.72,299.62,299.86,299.97,299.95,299.88,299.91,299.85,
-299.87,299.84,299.84,299.85,299.84,299.84,299.84,299.89,299.81,299.81,299.82,
-299.80,299.77,299.76,299.74,299.75,299.76,299.91,299.92,299.89,299.86,299.88,
-299.72,299.84,299.85,299.85,299.78,299.89,299.84,299.78,299.81,299.76,299.81,
-299.79,299.81,299.82,299.85,299.87,299.87,299.81,299.74,299.81,299.94,299.95,
-299.80,299.81,299.87)
-expectedMean <- 299.852400000000
-expectedSigma <- 0.0790105478190518
-verifyMean(values, expectedMean, tol, "Michelson")
-verifySigma(values, expectedSigma, tol, "Michelson")
-
-# Mavro data
-values <- c(2.00180,2.00170,2.00180,2.00190,2.00180,2.00170,2.00150,2.00140,
-2.00150,2.00150,2.00170,2.00180,2.00180,2.00190,2.00190,2.00210,2.00200,
-2.00160,2.00140,2.00130,2.00130,2.00150,2.00150,2.00160,2.00150,2.00140,
-2.00130,2.00140,2.00150,2.00140,2.00150,2.00160,2.00150,2.00160,2.00190,
-2.00200,2.00200,2.00210,2.00220,2.00230,2.00240,2.00250,2.00270,2.00260,
-2.00260,2.00260,2.00270,2.00260,2.00250,2.00240)
-expectedMean <- 2.00185600000000
-expectedSigma <- 0.000429123454003053
-verifyMean(values, expectedMean, tol, "Mavro")
-verifySigma(values, expectedSigma, tol, "Mavro")
-
-displayDashes(WIDTH)
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/exponentialTestCases
----------------------------------------------------------------------
diff --git a/src/test/R/exponentialTestCases b/src/test/R/exponentialTestCases
deleted file mode 100644
index c73e6dd..0000000
--- a/src/test/R/exponentialTestCases
+++ /dev/null
@@ -1,103 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate exponential distribution tests in
-# org.apache.commons.math.distribution.ExponentialDistributionTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-#------------------------------------------------------------------------------
-tol <- 1E-9
-
-# Function definitions
-
-source("testFunctions") # utility test functions
-
-# function to verify distribution computations
-
-verifyDistribution <- function(points, expected, mean, tol) {
- rDistValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDistValues[i] <- pexp(point, 1/mean)
- }
- output <- c("Distribution test mean = ", mean)
- if (assertEquals(expected, rDistValues, tol, "Distribution Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify density computations
-verifyDensity <- function(points, expected, mean, tol) {
- rDensityValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDensityValues[i] <- dexp(point, 1/mean)
- }
- output <- c("Density test mean = ", mean)
- if (assertEquals(expected, rDensityValues, tol, "Density Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify quantiles
-verifyQuantiles <- function(points, expected, mean, tol) {
- rQuantileValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rQuantileValues[i] <- qexp(point, 1/mean, log = FALSE)
- }
- output <- c("Quantile test mean = ", mean)
- if (assertEquals(expected, rQuantileValues, tol, "Quantile Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-
-#--------------------------------------------------------------------------
-cat("Exponential test cases\n")
-
-mean <- 5
-
-distributionValues <- c(0, 0, 0.001, 0.01, 0.025, 0.05, 0.1, 0.999,
- 0.990, 0.975, 0.950, 0.900)
-densityValues <- c(0.2, 0.2, 0.1998, 0.198, 0.195, 0.19, 0.18, 0.000200000000000,
- 0.00200000000002, 0.00499999999997, 0.00999999999994, 0.0199999999999)
-distributionPoints <- c(0, 0, 0.00500250166792, 0.0502516792675, 0.126589039921, 0.256466471938,
- 0.526802578289, 34.5387763949, 23.0258509299, 18.4443972706, 14.9786613678, 11.5129254650)
-verifyDistribution(distributionPoints, distributionValues, mean, tol)
-verifyQuantiles(distributionValues, distributionPoints, mean, tol)
-verifyDensity(distributionPoints, densityValues, mean, tol)
-
-output <- "Probability test P(.25 < X < .75)"
-if (assertEquals(0.0905214480757, pexp(.75, 1/mean) - pexp(.25, 1/mean), tol, "Probability value")) {
- displayPadded(output, SUCCEEDED, WIDTH)
-} else {
- displayPadded(output, FAILED, WIDTH)
-}
-
-displayDashes(WIDTH)
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/geometricTestCases
----------------------------------------------------------------------
diff --git a/src/test/R/geometricTestCases b/src/test/R/geometricTestCases
deleted file mode 100644
index 96ca82e..0000000
--- a/src/test/R/geometricTestCases
+++ /dev/null
@@ -1,121 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate Geometric distribution tests in
-# org.apache.commons.math.distribution.GeometricDistributionTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-# R functions used
-# dgeom(x, prob, log = FALSE) <- density
-# pgeom(q, prob, lower.tail = TRUE, log.p = FALSE) <- distribution
-# qgeom(p, prob, lower.tail = TRUE, log.p = FALSE) <- quantiles
-#------------------------------------------------------------------------------
-tol <- 1E-6 # error tolerance for tests
-#------------------------------------------------------------------------------
-# Function definitions
-
-source("testFunctions") # utility test functions
-
-# function to verify density computations
-
-verifyDensity <- function(points, expected, prob, tol, log = FALSE) {
- rDensityValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDensityValues[i] <- dgeom(point, prob, log)
- }
- output <- c("Density test prob = ", prob)
- if (assertEquals(expected,rDensityValues,tol,"Density Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify distribution computations
-
-verifyDistribution <- function(points, expected, prob, tol) {
- rDistValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDistValues[i] <- pgeom(point, prob)
- }
- output <- c("Distribution test prob = ", prob)
- if (assertEquals(expected,rDistValues,tol,"Distribution Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-#--------------------------------------------------------------------------
-cat("Geometric test cases\n")
-
-prob <- 0.4
-
-densityPoints <- c(-1, 0, 1, 2, 3, 4, 5, 6, 7, 8,
- 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
- 19, 20, 21, 22, 23, 24, 25, 26, 27, 28)
-densityValues <- c(0, 0.4, 0.24, 0.144, 0.0864, 0.05184, 0.031104, 0.0186624, 0.01119744, 0.006718464,
- 0.0040310784, 0.00241864704, 0.001451188224, 0.0008707129344, 0.00052242776064,
- 0.000313456656384, 0.0001880739938304, 0.00011284439629824, 6.7706637778944e-05,
- 4.06239826673664e-05, 2.43743896004198e-05, 1.46246337602519e-05, 8.77478025615113e-06,
- 5.26486815369068e-06, 3.15892089221441e-06, 1.89535253532865e-06, 1.13721152119719e-06,
- 6.82326912718312e-07, 4.09396147630988e-07, 2.45637688578593e-07)
-logDensityValues <- c(-Inf, -0.916290731874155, -1.42711635564015, -1.93794197940614, -2.44876760317213,
- -2.95959322693812, -3.47041885070411, -3.9812444744701, -4.49207009823609,
- -5.00289572200208, -5.51372134576807, -6.02454696953406, -6.53537259330005,
- -7.04619821706604, -7.55702384083203, -8.06784946459802, -8.57867508836402,
- -9.08950071213001, -9.600326335896, -10.111151959662, -10.621977583428,
- -11.132803207194, -11.64362883096, -12.154454454726, -12.6652800784919, -13.1761057022579,
- -13.6869313260239, -14.1977569497899, -14.7085825735559, -15.2194081973219)
-distributionValues <- c(0, 0.4, 0.64, 0.784, 0.8704, 0.92224, 0.953344, 0.9720064, 0.98320384, 0.989922304,
- 0.9939533824, 0.99637202944, 0.997823217664, 0.9986939305984, 0.99921635835904,
- 0.999529815015424, 0.999717889009254, 0.999830733405553, 0.999898440043332,
- 0.999939064025999, 0.999963438415599, 0.99997806304936, 0.999986837829616,
- 0.99999210269777, 0.999995261618662, 0.999997156971197, 0.999998294182718,
- 0.999998976509631, 0.999999385905779, 0.999999631543467)
-#Eliminate p=1 case because it will mess up adjustement below
-inverseCumPoints <- c(0, 0.001, 0.010, 0.025, 0.050, 0.100, 0.999,
- 0.990, 0.975, 0.950, 0.900)
-inverseCumValues <- c(-1, -1, -1, -1, -1, -1, 12, 8, 6, 4, 3)
-
-verifyDensity(densityPoints, densityValues, prob, tol)
-verifyDensity(densityPoints, logDensityValues, prob, tol, TRUE)
-verifyDistribution(densityPoints, distributionValues, prob, tol)
-
-i <- 0
-rInverseCumValues <- rep(0,length(inverseCumPoints))
-for (point in inverseCumPoints) {
- i <- i + 1
- rInverseCumValues[i] <- qgeom(point, prob)
-}
-
-output <- c("Inverse Distribution test prob = ", prob)
-# R defines quantiles from the right, need to subtract one
-if (assertEquals(inverseCumValues, rInverseCumValues-1, tol,
- "Inverse Dist Values")) {
- displayPadded(output, SUCCEEDED, 80)
-} else {
- displayPadded(output, FAILED, 80)
-}
-
-displayDashes(WIDTH)
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/gumbelTestCases.R
----------------------------------------------------------------------
diff --git a/src/test/R/gumbelTestCases.R b/src/test/R/gumbelTestCases.R
deleted file mode 100644
index e4fea7c..0000000
--- a/src/test/R/gumbelTestCases.R
+++ /dev/null
@@ -1,85 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate Gumbel distribution tests in
-# org.apache.commons.complex.distribution.GumbelDistributionTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-# R functions used
-# dgumbel(x, location = 0, scale = 1, log = FALSE, max = TRUE)
-# pgumbel(q, location = 0, scale = 1, lower.tail = TRUE, max = TRUE)
-
-#-----------------------------------------------------------------------------
-tol <- 1E-9
-
-# Function definitions
-
-source("testFunctions") # utility test functions
-library("VGAM")
-
-# function to verify distribution computations
-verifyDistribution <- function(points, expected, m, s, tol) {
- rDistValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDistValues[i] <- pgumbel(point, m, s)
- }
- output <- c("Distribution test m = ",m,", s = ", s)
- if (assertEquals(expected, rDistValues, tol, "Distribution Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify density computations
-verifyDensity <- function(points, expected, m, s, tol) {
- rDensityValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDensityValues[i] <- dgumbel(point, m, s)
- }
- output <- c("Density test m = ",m,", s = ", s)
- if (assertEquals(expected, rDensityValues, tol, "Density Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-#--------------------------------------------------------------------------
-cat("Gumbel test cases\n")
-
-m <- 0.5
-s <- 2
-distributionPoints <- c(-5:5)
-densityValues <- c(1.2582621126545528E-6,3.5946885566568164E-4,0.009115765822384943,0.05321099995044945,0.12743521041151834,0.17778637369097208,0.17871767308609124,0.14726615762017733,0.10756585897012155,0.07302735923472656,0.047427815138561126)
-distributionValues <- c(1.6087601139887782E-7,7.577547728260715E-5,0.003168165149053243,0.03049041346306221,0.12039226207982957,0.27692033409990896,0.4589560693076638,0.6235249162568004,0.7508834766393948,0.8404868737475784,0.8999651626606278)
-verifyDistribution(distributionPoints, distributionValues, m, s, tol)
-verifyDensity(distributionPoints, densityValues, m, s, tol)
-
-m <- 1.5
-s <- 3
-distributionPoints <- c(-5:5)
-densityValues <- c(4.707967970909721E-4,0.004005928431315734,0.01690237120332691,0.04314381688828758,0.07682272023182242,0.10568064035931406,0.12083781131699158,0.12102469295161239,0.11023476629680602,0.09380437047469757,0.07602582610501195)
-distributionValues <- c(1.6180181049060529E-4,0.0019214004612365587,0.011314286380459627,0.04030537101298144,0.10016104975617146,0.1922956455479649,0.30686099686684076,0.42892134369676455,0.545239211892605,0.6475247847679736,0.7324184876698198)
-verifyDistribution(distributionPoints, distributionValues, m, s, tol)
-verifyDensity(distributionPoints, densityValues, m, s, tol)
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/hypergeometricTestCases
----------------------------------------------------------------------
diff --git a/src/test/R/hypergeometricTestCases b/src/test/R/hypergeometricTestCases
deleted file mode 100644
index 04bc8a0..0000000
--- a/src/test/R/hypergeometricTestCases
+++ /dev/null
@@ -1,139 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate Hypergeometric distribution tests in
-# org.apache.commons.math.distribution.HypergeometricDistributionTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-# R functions used
-# dhyper(x, m, n, k, log = FALSE) <- density
-# phyper(q, m, n, k, lower.tail = TRUE, log.p = FALSE) <- distribution
-# qhyper(p, m, n, k, lower.tail = TRUE, log.p = FALSE) <- quantiles
-#------------------------------------------------------------------------------
-tol <- 1E-6 # error tolerance for tests
-#------------------------------------------------------------------------------
-# Function definitions
-
-source("testFunctions") # utility test functions
-
-# function to verify density computations
-
-verifyDensity <- function(points, expected, good, bad, selected, tol, log = FALSE) {
- rDensityValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDensityValues[i] <- dhyper(point, good, bad, selected, log)
- }
- output <- c("Density test good = ", good, ", bad = ", bad,
- ", selected = ",selected)
- if (assertEquals(expected,rDensityValues,tol,"Density Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify distribution computations
-
-verifyDistribution <- function(points, expected, good, bad, selected, tol) {
- rDistValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDistValues[i] <- phyper(point, good, bad, selected)
- }
- output <- c("Distribution test good = ", good, ", bad = ",
- bad, ", selected = ",selected)
- if (assertEquals(expected,rDistValues,tol,"Distribution Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-#--------------------------------------------------------------------------
-cat("Hypergeometric test cases\n")
-
-good <- 5
-bad <- 5
-selected <- 5
-
-densityPoints <- c(-1, 0, 1, 2, 3, 4, 5, 10)
-densityValues <- c(0, 0.00396825396825397, 0.0992063492063492, 0.396825396825397, 0.396825396825397,
- 0.0992063492063492, 0.00396825396825397, 0)
-logDensityValues <- c(-Inf, -5.52942908751142, -2.31055326264322, -0.924258901523332,
- -0.924258901523332, -2.31055326264322, -5.52942908751142, -Inf)
-distributionValues <- c(0, .003968, .103175, .50000, .896825, .996032,
- 1.00000, 1)
-#Eliminate p=1 case because it will mess up adjustement below
-inverseCumPoints <- c(0, 0.001, 0.010, 0.025, 0.050, 0.100, 0.999,
- 0.990, 0.975, 0.950, 0.900)
-inverseCumValues <- c(-1, -1, 0, 0, 0, 0, 4, 3, 3, 3, 3)
-
-verifyDensity(densityPoints, densityValues, good, bad, selected, tol)
-verifyDensity(densityPoints, logDensityValues, good, bad, selected, tol, TRUE)
-verifyDistribution(densityPoints, distributionValues, good, bad, selected, tol)
-
-i <- 0
-rInverseCumValues <- rep(0,length(inverseCumPoints))
-for (point in inverseCumPoints) {
- i <- i + 1
- rInverseCumValues[i] <- qhyper(point, good, bad, selected)
-}
-
-output <- c("Inverse Distribution test good = ", good, ", bad = ", bad,
- ", selected = ", selected)
-# R defines quantiles from the right, need to subtract one
-if (assertEquals(inverseCumValues, rInverseCumValues-1, tol,
- "Inverse Dist Values")) {
- displayPadded(output, SUCCEEDED, 80)
-} else {
- displayPadded(output, FAILED, 80)
-}
-
-# Degenerate cases
-good <- 5
-bad <- 0
-selected <- 3
-densityPoints <- c(-1, 0, 1, 3, 10)
-densityValues <- c(0, 0, 0, 1, 0)
-distributionValues <- c(0, 0, 0, 1, 1)
-verifyDensity(densityPoints, densityValues, good, bad, selected, tol)
-verifyDistribution(densityPoints, distributionValues, good, bad, selected, tol)
-
-good <- 0
-bad <- 5
-selected <- 3
-densityPoints <- c(-1, 0, 1, 3, 10)
-densityValues <- c(0, 1, 0, 0, 0)
-distributionValues <- c(0, 1, 1, 1, 1)
-verifyDensity(densityPoints, densityValues, good, bad, selected, tol)
-verifyDistribution(densityPoints, distributionValues, good, bad, selected, tol)
-
-good <- 3
-bad <- 2
-selected <- 5
-densityPoints <- c(-1, 0, 1, 3, 10)
-densityValues <- c(0, 0, 0, 1, 0)
-distributionValues <- c(0, 0, 0, 1, 1)
-verifyDensity(densityPoints, densityValues, good, bad, selected, tol)
-verifyDistribution(densityPoints, distributionValues, good, bad, selected, tol)
-
-displayDashes(WIDTH)
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/laplaceTestCases.R
----------------------------------------------------------------------
diff --git a/src/test/R/laplaceTestCases.R b/src/test/R/laplaceTestCases.R
deleted file mode 100644
index 0229787..0000000
--- a/src/test/R/laplaceTestCases.R
+++ /dev/null
@@ -1,85 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate Laplace distribution tests in
-# org.apache.commons.complex.distribution.LaplaceDistributionTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-# R functions used
-# dlaplace(x, location = 0, scale = 1, log = FALSE, max = TRUE)
-# plaplace(q, location = 0, scale = 1, lower.tail = TRUE, max = TRUE)
-
-#-----------------------------------------------------------------------------
-tol <- 1E-9
-
-# Function definitions
-
-source("testFunctions") # utility test functions
-library("VGAM")
-
-# function to verify distribution computations
-verifyDistribution <- function(points, expected, m, s, tol) {
- rDistValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDistValues[i] <- plaplace(point, m, s)
- }
- output <- c("Distribution test m = ",m,", s = ", s)
- if (assertEquals(expected, rDistValues, tol, "Distribution Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify density computations
-verifyDensity <- function(points, expected, m, s, tol) {
- rDensityValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDensityValues[i] <- dlaplace(point, m, s)
- }
- output <- c("Density test m = ",m,", s = ", s)
- if (assertEquals(expected, rDensityValues, tol, "Density Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-#--------------------------------------------------------------------------
-cat("Laplace test cases\n")
-
-m <- 0
-s <- 1
-distributionPoints <- c(-5:5)
-densityValues <- c(0.0033689734995427335,0.00915781944436709,0.024893534183931972,0.06766764161830635,0.18393972058572117,0.5,0.18393972058572117,0.06766764161830635,0.024893534183931972,0.00915781944436709,0.0033689734995427335)
-distributionValues <- c(0.0033689734995427335,0.00915781944436709,0.024893534183931972,0.06766764161830635,0.18393972058572117,0.5,0.8160602794142788,0.9323323583816936,0.9751064658160681,0.9908421805556329,0.9966310265004573)
-verifyDistribution(distributionPoints, distributionValues, m, s, tol)
-verifyDensity(distributionPoints, densityValues, m, s, tol)
-
-m <- -5
-s <- 4
-distributionPoints <- c(-5:5)
-densityValues <- c(0.125,0.09735009788392561,0.07581633246407918,0.059045819092626836,0.04598493014643029,0.03581309960752376,0.027891270018553727,0.021721742931305642,0.016916910404576588,0.013174903070233042,0.01026062482798735)
-distributionValues <- c(0.5,0.6105996084642975,0.6967346701436833,0.7638167236294926,0.8160602794142788,0.8567476015699049,0.888434919925785,0.9131130282747775,0.9323323583816936,0.9473003877190679,0.9589575006880506)
-verifyDistribution(distributionPoints, distributionValues, m, s, tol)
-verifyDensity(distributionPoints, densityValues, m, s, tol)
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/logNormalTestCases
----------------------------------------------------------------------
diff --git a/src/test/R/logNormalTestCases b/src/test/R/logNormalTestCases
deleted file mode 100644
index ac0ca30..0000000
--- a/src/test/R/logNormalTestCases
+++ /dev/null
@@ -1,107 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate LogNormal distribution tests in
-# org.apache.commons.math.distribution.LogNormalDistributionTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-# R functions used
-# plnorm(q, mean=0, sd=1, lower.tail = TRUE, log.p = FALSE) <-- distribution
-#-----------------------------------------------------------------------------
-tol <- 1E-9
-
-# Function definitions
-
-source("testFunctions") # utility test functions
-
-# function to verify distribution computations
-
-verifyDistribution <- function(points, expected, mu, sigma, tol) {
- rDistValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDistValues[i] <- plnorm(point, mu, sigma, log = FALSE)
- }
- output <- c("Distribution test mu = ",mu,", sigma = ", sigma)
- if (assertEquals(expected, rDistValues, tol, "Distribution Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify density computations
-
-verifyDensity <- function(points, expected, mu, sigma, tol) {
- rDensityValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDensityValues[i] <- dlnorm(point, mu, sigma, log = FALSE)
- }
- output <- c("Density test mu = ",mu,", sigma = ", sigma)
- if (assertEquals(expected, rDensityValues, tol, "Density Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-#--------------------------------------------------------------------------
-cat("LogNormal test cases\n")
-
-mu <- 2.1
-sigma <- 1.4
-distributionValues <- c(0, 0, 0, 0, 0.00948199951485, 0.432056525076, 0.381648158697, 0.354555726206, 0.329513316888, 0.298422824228)
-densityValues <- c(0, 0, 0, 0, 0.0594218160072, 0.0436977691036, 0.0508364857798, 0.054873528325, 0.0587182664085, 0.0636229042785)
-distributionPoints <- c(-2.226325228634938, -1.156887023657177, -0.643949578356075, -0.2027950777320613, 0.305827808237559,
- 6.42632522863494, 5.35688702365718, 4.843949578356074, 4.40279507773206, 3.89417219176244)
-verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol)
-verifyDensity(distributionPoints, densityValues, mu, sigma, tol)
-
-distributionValues <- c(0, 0.0396495152787, 0.16601209243, 0.272533253269, 0.357618409638, 0.426488363093, 0.483255136841, 0.530823013877)
-densityValues <- c(0, 0.0873055825147, 0.0847676303432, 0.0677935186237, 0.0544105523058, 0.0444614628804, 0.0369750288945, 0.0312206409653)
-distributionPoints <- c(mu - 2 *sigma, mu - sigma, mu, mu + sigma,
- mu + 2 * sigma, mu + 3 * sigma, mu + 4 * sigma,
- mu + 5 * sigma)
-verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol)
-verifyDensity(distributionPoints, densityValues, mu, sigma, tol)
-
-mu <- 0
-sigma <- 1
-distributionPoints <- c(mu - 2 *sigma, mu - sigma, mu, mu + sigma,
- mu + 2 * sigma, mu + 3 * sigma, mu + 4 * sigma,
- mu + 5 * sigma)
-distributionValues <- c(0, 0, 0, 0.5, 0.755891404214, 0.864031392359, 0.917171480998, 0.946239689548)
-densityValues <- c(0, 0, 0, 0.398942280401, 0.156874019279, 0.07272825614, 0.0381534565119, 0.0218507148303)
-verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol)
-verifyDensity(distributionPoints, densityValues, mu, sigma, tol)
-
-mu <- 0
-sigma <- 0.1
-distributionPoints <- c(mu - 2 *sigma, mu - sigma, mu, mu + sigma,
- mu + 2 * sigma, mu + 3 * sigma, mu + 4 * sigma,
- mu + 5 * sigma)
-distributionValues <- c(0, 0, 0, 1.28417563064e-117, 1.39679883412e-58, 1.09839325447e-33, 2.52587961726e-20, 2.0824223487e-12)
-densityValues <- c(0, 0, 0, 2.96247992535e-114, 1.1283370232e-55, 4.43812313223e-31, 5.85346445002e-18, 2.9446618076e-10)
-verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol)
-verifyDensity(distributionPoints, densityValues, mu, sigma, tol)
-
-displayDashes(WIDTH)
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/logisticsTestCases.R
----------------------------------------------------------------------
diff --git a/src/test/R/logisticsTestCases.R b/src/test/R/logisticsTestCases.R
deleted file mode 100644
index ff40d73..0000000
--- a/src/test/R/logisticsTestCases.R
+++ /dev/null
@@ -1,85 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate Logistics distribution tests in
-# org.apache.commons.complex.distribution.LogisticsDistributionTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-# R functions used
-# dlogis(x, location = 0, scale = 1, log = FALSE, max = TRUE)
-# plogis(q, location = 0, scale = 1, lower.tail = TRUE, max = TRUE)
-
-#-----------------------------------------------------------------------------
-tol <- 1E-9
-
-# Function definitions
-
-source("testFunctions") # utility test functions
-library("VGAM")
-
-# function to verify distribution computations
-verifyDistribution <- function(points, expected, m, s, tol) {
- rDistValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDistValues[i] <- plogis(point, m, s)
- }
- output <- c("Distribution test m = ",m,", s = ", s)
- if (assertEquals(expected, rDistValues, tol, "Distribution Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify density computations
-verifyDensity <- function(points, expected, m, s, tol) {
- rDensityValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDensityValues[i] <- dlogis(point, m, s)
- }
- output <- c("Density test m = ",m,", s = ", s)
- if (assertEquals(expected, rDensityValues, tol, "Density Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-#--------------------------------------------------------------------------
-cat("Logistics test cases\n")
-
-m <- 5
-s <- 2
-distributionPoints <- c(-5:5)
-densityValues <- c(0.0033240283353950773,0.005433114861112618,0.008831353106645559,0.014226511939867782,0.022588329865456065,0.03505185827255408,0.05249679270175326,0.07457322603516643,0.09830596662074093,0.11750185610079725,0.125)
-distributionValues <- c(0.0066928509242848554,0.01098694263059318,0.01798620996209156,0.02931223075135632,0.04742587317756678,0.07585818002124355,0.11920292202211755,0.18242552380635635,0.2689414213699951,0.3775406687981454,0.5)
-verifyDistribution(distributionPoints, distributionValues, m, s, tol)
-verifyDensity(distributionPoints, densityValues, m, s, tol)
-
-m <- 9
-s <- 3
-distributionPoints <- c(-5:5)
-densityValues <- c(0.0030763907488492496,0.004261976157918787,0.005887568737763705,0.008101066534475556,0.01108624138724253,0.01505888657697071,0.020249392063798367,0.026861724758915424,0.03499786180116884,0.04454323746508397,0.0550303365509679)
-distributionValues <- c(0.009315959345066693,0.012953727530695871,0.01798620996209156,0.02492442664711404,0.03444519566621118,0.04742587317756678,0.06496916912866407,0.08839967720705845,0.11920292202211755,0.15886910488091516,0.20860852732604496)
-verifyDistribution(distributionPoints, distributionValues, m, s, tol)
-verifyDensity(distributionPoints, densityValues, m, s, tol)
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/multipleOLSRegressionTestCases
----------------------------------------------------------------------
diff --git a/src/test/R/multipleOLSRegressionTestCases b/src/test/R/multipleOLSRegressionTestCases
deleted file mode 100644
index 458426f..0000000
--- a/src/test/R/multipleOLSRegressionTestCases
+++ /dev/null
@@ -1,309 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate OLS multiple regression tests in
-# org.apache.commons.math.stat.regression.OLSMultipleLinearRegressionTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-#------------------------------------------------------------------------------
-tol <- 1E-8 # default error tolerance for tests
-#------------------------------------------------------------------------------
-# Function definitions
-
-source("testFunctions") # utility test functions
-options(digits=16) # override number of digits displayed
-
-# function to verify OLS computations
-
-verifyRegression <- function(model, expectedBeta, expectedResiduals,
- expectedErrors, expectedStdError, expectedRSquare, expecteAdjRSquare, modelName) {
- betaHat <- as.vector(coefficients(model))
- residuals <- as.vector(residuals(model))
- errors <- as.vector(as.matrix(coefficients(summary(model)))[,2])
- stdError <- summary(model)$sigma
- rSquare <- summary(model)$r.squared
- adjRSquare <- summary(model)$adj.r.squared
- output <- c("Parameter test dataset = ", modelName)
- if (assertEquals(expectedBeta,betaHat,tol,"Parameters")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
- output <- c("Residuals test dataset = ", modelName)
- if (assertEquals(expectedResiduals,residuals,tol,"Residuals")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
- output <- c("Errors test dataset = ", modelName)
- if (assertEquals(expectedErrors,errors,tol,"Errors")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
- output <- c("Standard Error test dataset = ", modelName)
- if (assertEquals(expectedStdError,stdError,tol,"Regression Standard Error")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
- output <- c("RSquared test dataset = ", modelName)
- if (assertEquals(expectedRSquare,rSquare,tol,"RSquared")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
- output <- c("Adjusted RSquared test dataset = ", modelName)
- if (assertEquals(expecteAdjRSquare,adjRSquare,tol,"Adjusted RSquared")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-#--------------------------------------------------------------------------
-cat("Multiple regression OLS test cases\n")
-
-# Perfect fit
-x1 <- c(0,2,0,0,0,0)
-x2 <- c(0,0,3,0,0,0)
-x3 <- c(0,0,0,4,0,0)
-x4 <- c(0,0,0,0,5,0)
-x5 <- c(0,0,0,0,0,6)
-y <- c(11, 12, 13, 14, 15, 16)
-model <- lm(y ~ x1 + x2 + x3 + x4 + x5)
-expectedBeta <- c(11.0,0.5,0.666666666666667,0.75,0.8,0.8333333333333333)
-expectedResiduals <- c(0,0,0,0,0,0)
-expectedErrors <- c(NaN,NaN,NaN,NaN,NaN,NaN)
-expectedStdError <- NaN
-expectedRSquare <- 1
-expectedAdjRSquare <- NaN
-verifyRegression(model, expectedBeta, expectedResiduals, expectedErrors,
- expectedStdError, expectedRSquare, expectedAdjRSquare, "perfect fit")
-
-# Longley
-#
-# Data Source: J. Longley (1967) "An Appraisal of Least Squares Programs for the
-# Electronic Computer from the Point of View of the User",
-# Journal of the American Statistical Association,
-# vol. 62. September, pp. 819-841.
-#
-# Certified values (and data) are from NIST:
-# http://www.itl.nist.gov/div898/strd/lls/data/LINKS/DATA/Longley.dat
-#
-design <- matrix(c(60323,83.0,234289,2356,1590,107608,1947,
- 61122,88.5,259426,2325,1456,108632,1948,
- 60171,88.2,258054,3682,1616,109773,1949,
- 61187,89.5,284599,3351,1650,110929,1950,
- 63221,96.2,328975,2099,3099,112075,1951,
- 63639,98.1,346999,1932,3594,113270,1952,
- 64989,99.0,365385,1870,3547,115094,1953,
- 63761,100.0,363112,3578,3350,116219,1954,
- 66019,101.2,397469,2904,3048,117388,1955,
- 67857,104.6,419180,2822,2857,118734,1956,
- 68169,108.4,442769,2936,2798,120445,1957,
- 66513,110.8,444546,4681,2637,121950,1958,
- 68655,112.6,482704,3813,2552,123366,1959,
- 69564,114.2,502601,3931,2514,125368,1960,
- 69331,115.7,518173,4806,2572,127852,1961,
- 70551,116.9,554894,4007,2827,130081,1962),
- nrow = 16, ncol = 7, byrow = TRUE)
-y <- design[,1]
-x1 <- design[,2]
-x2 <- design[,3]
-x3 <- design[,4]
-x4 <- design[,5]
-x5 <- design[,6]
-x6 <- design[,7]
-model <- lm(y ~ x1 + x2 + x3 + x4 + x5 + x6)
-
-estimates <- matrix(c(-3482258.63459582,890420.383607373,
- 15.0618722713733,84.9149257747669,
- -0.358191792925910E-01,0.334910077722432E-01,
- -2.02022980381683,0.488399681651699,
- -1.03322686717359,0.214274163161675,
- -0.511041056535807E-01,0.226073200069370,
- 1829.15146461355,455.478499142212),
- nrow = 7, ncol = 2, byrow = TRUE)
-
-expectedBeta <- estimates[,1]
-expectedErrors <- estimates[,2]
-expectedResiduals <- c(267.340029759711,-94.0139423988359,46.28716775752924,
- -410.114621930906,309.7145907602313,-249.3112153297231,-164.0489563956039,
- -13.18035686637081,14.30477260005235,455.394094551857,-17.26892711483297,
- -39.0550425226967,-155.5499735953195,-85.6713080421283,341.9315139607727,
- -206.7578251937366)
-expectedStdError <- 304.8540735619638
-expectedRSquare <- 0.995479004577296
-expectedAdjRSquare <- 0.992465007628826
-
-verifyRegression(model, expectedBeta, expectedResiduals, expectedErrors,
-expectedStdError, expectedRSquare, expectedAdjRSquare, "Longley")
-
-# Model with no intercept
-model <- lm(y ~ 0 + x1 + x2 + x3 + x4 + x5 + x6)
-
-estimates <- matrix(c(-52.99357013868291, 129.54486693117232,
- 0.07107319907358, 0.03016640003786,
- -0.42346585566399, 0.41773654056612,
- -0.57256866841929, 0.27899087467676,
- -0.41420358884978, 0.32128496193363,
- 48.41786562001326, 17.68948737819961),
- nrow = 6, ncol = 2, byrow = TRUE)
-
-expectedBeta <- estimates[,1]
-expectedErrors <- estimates[,2]
-expectedResiduals <- c(279.90274927293092, -130.32465380836874, 90.73228661967445,
- -401.31252201634948, -440.46768772620027, -543.54512853774793, 201.32111639536299,
- 215.90889365977932, 73.09368242049943, 913.21694494481869, 424.82484953610174,
- -8.56475876776709, -361.32974610842876, 27.34560497213464, 151.28955976355002,
- -492.49937355336846)
-expectedStdError <- 475.1655079819517
-expectedRSquare <- 0.9999670130706
-expectedAdjRSquare <- 0.999947220913
-
-verifyRegression(model, expectedBeta, expectedResiduals, expectedErrors,
-expectedStdError, expectedRSquare, expectedAdjRSquare, "Longley No Intercept")
-
-# Swiss Fertility (R dataset named "swiss")
-
-design <- matrix(c(80.2,17.0,15,12,9.96,
- 83.1,45.1,6,9,84.84,
- 92.5,39.7,5,5,93.40,
- 85.8,36.5,12,7,33.77,
- 76.9,43.5,17,15,5.16,
- 76.1,35.3,9,7,90.57,
- 83.8,70.2,16,7,92.85,
- 92.4,67.8,14,8,97.16,
- 82.4,53.3,12,7,97.67,
- 82.9,45.2,16,13,91.38,
- 87.1,64.5,14,6,98.61,
- 64.1,62.0,21,12,8.52,
- 66.9,67.5,14,7,2.27,
- 68.9,60.7,19,12,4.43,
- 61.7,69.3,22,5,2.82,
- 68.3,72.6,18,2,24.20,
- 71.7,34.0,17,8,3.30,
- 55.7,19.4,26,28,12.11,
- 54.3,15.2,31,20,2.15,
- 65.1,73.0,19,9,2.84,
- 65.5,59.8,22,10,5.23,
- 65.0,55.1,14,3,4.52,
- 56.6,50.9,22,12,15.14,
- 57.4,54.1,20,6,4.20,
- 72.5,71.2,12,1,2.40,
- 74.2,58.1,14,8,5.23,
- 72.0,63.5,6,3,2.56,
- 60.5,60.8,16,10,7.72,
- 58.3,26.8,25,19,18.46,
- 65.4,49.5,15,8,6.10,
- 75.5,85.9,3,2,99.71,
- 69.3,84.9,7,6,99.68,
- 77.3,89.7,5,2,100.00,
- 70.5,78.2,12,6,98.96,
- 79.4,64.9,7,3,98.22,
- 65.0,75.9,9,9,99.06,
- 92.2,84.6,3,3,99.46,
- 79.3,63.1,13,13,96.83,
- 70.4,38.4,26,12,5.62,
- 65.7,7.7,29,11,13.79,
- 72.7,16.7,22,13,11.22,
- 64.4,17.6,35,32,16.92,
- 77.6,37.6,15,7,4.97,
- 67.6,18.7,25,7,8.65,
- 35.0,1.2,37,53,42.34,
- 44.7,46.6,16,29,50.43,
- 42.8,27.7,22,29,58.33),
- nrow = 47, ncol = 5, byrow = TRUE)
-
-y <- design[,1]
-x1 <- design[,2]
-x2 <- design[,3]
-x3 <- design[,4]
-x4 <- design[,5]
-
-model <- lm(y ~ x1 + x2 + x3 + x4)
-
-estimates <- matrix(c(91.05542390271397,6.94881329475087,
- -0.22064551045715,0.07360008972340,
- -0.26058239824328,0.27410957467466,
- -0.96161238456030,0.19454551679325,
- 0.12441843147162,0.03726654773803),
- nrow = 5, ncol = 2, byrow = TRUE)
-
-expectedBeta <- estimates[,1]
-expectedErrors <- estimates[,2]
-
-expectedResiduals <- c(7.1044267859730512,1.6580347433531366,
- 4.6944952770029644,8.4548022690166160,13.6547432343186212,
- -9.3586864458500774,7.5822446330520386,15.5568995563859289,
- 0.8113090736598980,7.1186762732484308,7.4251378771228724,
- 2.6761316873234109,0.8351584810309354,7.1769991119615177,
- -3.8746753206299553,-3.1337779476387251,-0.1412575244091504,
- 1.1186809170469780,-6.3588097346816594,3.4039270429434074,
- 2.3374058329820175,-7.9272368576900503,-7.8361010968497959,
- -11.2597369269357070,0.9445333697827101,6.6544245101380328,
- -0.9146136301118665,-4.3152449403848570,-4.3536932047009183,
- -3.8907885169304661,-6.3027643926302188,-7.8308982189289091,
- -3.1792280015332750,-6.7167298771158226,-4.8469946718041754,
- -10.6335664353633685,11.1031134362036958,6.0084032641811733,
- 5.4326230830188482,-7.2375578629692230,2.1671550814448222,
- 15.0147574652763112,4.8625103516321015,-7.1597256413907706,
- -0.4515205619767598,-10.2916870903837587,-15.7812984571900063)
-
-expectedStdError <- 7.73642194433223
-expectedRSquare <- 0.649789742860228
-expectedAdjRSquare <- 0.6164363850373927
-
-verifyRegression(model, expectedBeta, expectedResiduals, expectedErrors,
-expectedStdError, expectedRSquare, expectedAdjRSquare, "Swiss Fertility")
-
-# model with no intercept
-model <- lm(y ~ 0 + x1 + x2 + x3 + x4)
-
-estimates <- matrix(c(0.52191832900513, 0.10470063765677,
- 2.36588087917963, 0.41684100584290,
- -0.94770353802795, 0.43370143099691,
- 0.30851985863609, 0.07694953606522),
- nrow = 4, ncol = 2, byrow = TRUE)
-
-expectedBeta <- estimates[,1]
-expectedErrors <- estimates[,2]
-
-expectedResiduals <- c(44.138759883538249, 27.720705122356215, 35.873200836126799,
- 34.574619581211977, 26.600168342080213, 15.074636243026923, -12.704904871199814,
- 1.497443824078134, 2.691972687079431, 5.582798774291231, -4.422986561283165,
- -9.198581600334345, 4.481765170730647, 2.273520207553216, -22.649827853221336,
- -17.747900013943308, 20.298314638496436, 6.861405135329779, -8.684712790954924,
- -10.298639278062371, -9.896618896845819, 4.568568616351242, -15.313570491727944,
- -13.762961360873966, 7.156100301980509, 16.722282219843990, 26.716200609071898,
- -1.991466398777079, -2.523342564719335, 9.776486693095093, -5.297535127628603,
- -16.639070567471094, -10.302057295211819, -23.549487860816846, 1.506624392156384,
- -17.939174438345930, 13.105792202765040, -1.943329906928462, -1.516005841666695,
- -0.759066561832886, 20.793137744128977, -2.485236153005426, 27.588238710486976,
- 2.658333257106881, -15.998337823623046, -5.550742066720694, -14.219077806826615)
-
-expectedStdError <- 17.24710630547
-expectedRSquare <- 0.946350722085
-expectedAdjRSquare <- 0.9413600915813
-
-verifyRegression(model, expectedBeta, expectedResiduals, expectedErrors,
-expectedStdError, expectedRSquare, expectedAdjRSquare, "Swiss Fertility No Intercept")
-
-displayDashes(WIDTH)
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/nakagamiTestCases.R
----------------------------------------------------------------------
diff --git a/src/test/R/nakagamiTestCases.R b/src/test/R/nakagamiTestCases.R
deleted file mode 100644
index 71c1765..0000000
--- a/src/test/R/nakagamiTestCases.R
+++ /dev/null
@@ -1,85 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate Nakagami distribution tests in
-# org.apache.commons.complex.distribution.NakagamiDistributionTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-# R functions used
-# dnaka(x, location = 0, scale = 1, log = FALSE, max = TRUE)
-# pnaka(q, location = 0, scale = 1, lower.tail = TRUE, max = TRUE)
-
-#-----------------------------------------------------------------------------
-tol <- 1E-9
-
-# Function definitions
-
-source("testFunctions") # utility test functions
-library("VGAM")
-
-# function to verify distribution computations
-verifyDistribution <- function(points, expected, m, s, tol) {
- rDistValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDistValues[i] <- pnaka(point, s, m)
- }
- output <- c("Distribution test m = ",m,", s = ", s)
- if (assertEquals(expected, rDistValues, tol, "Distribution Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify density computations
-verifyDensity <- function(points, expected, m, s, tol) {
- rDensityValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDensityValues[i] <- dnaka(point, s, m)
- }
- output <- c("Density test m = ",m,", s = ", s)
- if (assertEquals(expected, rDensityValues, tol, "Density Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-#--------------------------------------------------------------------------
-cat("Nakagami test cases\n")
-
-m <- 0.5
-s <- 1
-distributionPoints <- seq(from = 0, to = 2, by = 0.2)
-densityValues <- c(0.0,0.7820853879509118,0.7365402806066467,0.6664492057835993,0.5793831055229655,0.48394144903828673,0.38837210996642585,0.29945493127148964,0.2218416693589111,0.1579003166017883,0.10798193302637613)
-distributionValues <- c(0.0,0.15851941887820603,0.3108434832206483,0.45149376449985296,0.5762892028332065,0.6826894921370859,0.7698606595565836,0.8384866815324576,0.8904014166008841,0.9281393617741498,0.9544997361036424)
-verifyDistribution(distributionPoints, distributionValues, m, s, tol)
-verifyDensity(distributionPoints, densityValues, m, s, tol)
-
-m <- 1
-s <- 2
-distributionPoints <- seq(from = 0, to = 2, by = 0.2)
-densityValues <- c(0.0,0.19603973466135105,0.36924653855465434,0.5011621268467633,0.5809192296589527,0.6065306597126334,0.584102707151966,0.5254355383919593,0.44485968072511056,0.3562176583505064,0.2706705664732254)
-distributionValues <- c(0.0,0.0198013266932447,0.07688365361336423,0.16472978858872803,0.273850962926309,0.3934693402873665,0.5132477440400285,0.6246889011486005,0.7219626995468056,0.8021013009163853,0.8646647167633873)
-verifyDistribution(distributionPoints, distributionValues, m, s, tol)
-verifyDensity(distributionPoints, densityValues, m, s, tol)
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/normalTestCases
----------------------------------------------------------------------
diff --git a/src/test/R/normalTestCases b/src/test/R/normalTestCases
deleted file mode 100644
index 7be2e75..0000000
--- a/src/test/R/normalTestCases
+++ /dev/null
@@ -1,111 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate Normal distribution tests in
-# org.apache.commons.math.distribution.NormalDistributionTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-# R functions used
-# pnorm(q, mean=0, sd=1, lower.tail = TRUE, log.p = FALSE) <-- distribution
-#-----------------------------------------------------------------------------
-tol <- 1E-9
-
-# Function definitions
-
-source("testFunctions") # utility test functions
-
-# function to verify distribution computations
-
-verifyDistribution <- function(points, expected, mu, sigma, tol) {
- rDistValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDistValues[i] <- pnorm(point, mu, sigma, log = FALSE)
- }
- output <- c("Distribution test mu = ",mu,", sigma = ", sigma)
- if (assertEquals(expected, rDistValues, tol, "Distribution Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify density computations
-
-verifyDensity <- function(points, expected, mu, sigma, tol) {
- rDensityValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDensityValues[i] <- dnorm(point, mu, sigma, log = FALSE)
- }
- output <- c("Density test mu = ",mu,", sigma = ", sigma)
- if (assertEquals(expected, rDensityValues, tol, "Density Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-#--------------------------------------------------------------------------
-cat("Normal test cases\n")
-
-mu <- 2.1
-sigma <- 1.4
-distributionValues <- c(0.001, 0.01, 0.025, 0.05, 0.1, 0.999,
- 0.990, 0.975, 0.950, 0.900)
-densityValues <- c(0.00240506434076, 0.0190372444310, 0.0417464784322, 0.0736683145538, 0.125355951380,
- 0.00240506434076, 0.0190372444310, 0.0417464784322, 0.0736683145538, 0.125355951380)
-distributionPoints <- c(-2.226325228634938, -1.156887023657177, -0.643949578356075, -0.2027950777320613, 0.305827808237559,
- 6.42632522863494, 5.35688702365718, 4.843949578356074, 4.40279507773206, 3.89417219176244)
-verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol)
-verifyDensity(distributionPoints, densityValues, mu, sigma, tol)
-
-distributionValues <- c( 0.0227501319482, 0.158655253931, 0.5, 0.841344746069, 0.977249868052,
- 0.998650101968, 0.999968328758, 0.999999713348)
-densityValues <- c(0.0385649760808, 0.172836231799, 0.284958771715, 0.172836231799, 0.0385649760808,
- 0.00316560600853, 9.55930184035e-05, 1.06194251052e-06)
-distributionPoints <- c(mu - 2 *sigma, mu - sigma, mu, mu + sigma,
- mu + 2 * sigma, mu + 3 * sigma, mu + 4 * sigma,
- mu + 5 * sigma)
-verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol)
-verifyDensity(distributionPoints, densityValues, mu, sigma, tol)
-
-mu <- 0
-sigma <- 1
-distributionPoints <- c(mu - 2 *sigma, mu - sigma, mu, mu + sigma,
- mu + 2 * sigma, mu + 3 * sigma, mu + 4 * sigma,
- mu + 5 * sigma)
-densityValues <- c(0.0539909665132, 0.241970724519, 0.398942280401, 0.241970724519, 0.0539909665132,
- 0.00443184841194, 0.000133830225765, 1.48671951473e-06)
-verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol)
-verifyDensity(distributionPoints, densityValues, mu, sigma, tol)
-
-mu <- 0
-sigma <- 0.1
-distributionPoints <- c(mu - 2 *sigma, mu - sigma, mu, mu + sigma,
- mu + 2 * sigma, mu + 3 * sigma, mu + 4 * sigma,
- mu + 5 * sigma)
-densityValues <- c(0.539909665132, 2.41970724519, 3.98942280401, 2.41970724519,
- 0.539909665132, 0.0443184841194, 0.00133830225765, 1.48671951473e-05)
-verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol)
-verifyDensity(distributionPoints, densityValues, mu, sigma, tol)
-
-displayDashes(WIDTH)
[19/31] commons-numbers git commit: Correct project info.
Posted by er...@apache.org.
Correct project info.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/81911e4c
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/81911e4c
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/81911e4c
Branch: refs/heads/master
Commit: 81911e4c754d7636ff2acb91e93b5fffc2f9e7c6
Parents: 7a4a3a6
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Fri Jan 20 13:39:29 2017 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Fri Jan 20 13:39:29 2017 +0100
----------------------------------------------------------------------
src/site/xdoc/developers.xml | 593 +++++++++++++-------------------
src/site/xdoc/download_numbers.xml | 154 +++++++++
src/site/xdoc/issue-tracking.xml | 30 +-
src/site/xdoc/mail-lists.xml | 39 ++-
4 files changed, 436 insertions(+), 380 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/81911e4c/src/site/xdoc/developers.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/developers.xml b/src/site/xdoc/developers.xml
index f280a6c..d62066b 100644
--- a/src/site/xdoc/developers.xml
+++ b/src/site/xdoc/developers.xml
@@ -17,352 +17,251 @@
-->
<document>
- <properties>
- <title>Developers Guide</title>
- </properties>
+ <properties>
+ <title>Developers Guide</title>
+ </properties>
+
+ <body>
+
+ <section name="Aims">
+ <p>
+ Maintenance of a library by decentralized team requires communication.
+ It is important that developers follow guidelines laid down by the community
+ to ensure that the code they create can be successfully maintained by others.
+ </p>
+ </section>
+
+ <section name='Guidelines'>
+ <p>
+ Developers are asked to comply with the following development guidelines.
+ Code that does not comply with the guidelines including the word <i>must</i>
+ will not be committed. Our aim will be to fix all of the exceptions to the
+ "<i>should</i>" guidelines prior to a release.
+ </p>
+ <subsection name="Contributing">
+ <p><strong>Getting Started</strong></p>
+ <p>
+ <ol>
+ <li>
+ Download the Commons Numbers source code. Follow the instructions
+ under the heading "Repository Checkout" on the
+ <a href="https://git-wip-us.apache.org/">Git at the ASF page</a>.
+ The git url for the current development sources of Commons Numbers
+ is <source>http://git-wip-us.apache.org/repos/asf/commons-numbers.git</source>
+ for anonymous read-only access and
+ <source>https://apacheid@git-wip-us.apache.org/repos/asf/commons-numbers.git</source>
+ (where apacheid should be replaced by each committer Apache ID) for committers
+ read-write access.
+ </li>
+ <li>
+ Like most commons components, Commons Numbers uses Apache Maven as our
+ build tool. The sources can also be built using Ant (a working
+ Ant build.xml is included in the top level project directory).
+ To build Commons Numbers using Maven, you can follow the instructions for
+ <a href="http://maven.apache.org/run-maven/index.html">Building a
+ project with Maven</a>.
+ Launch Maven from the top-level directory
+ in the checkout of Commons Numbers trunk. No special setup is required,
+ except that currently to build the site (i.e. to execute Maven's
+ "site" goal), you may need to increase the default memory allocation
+ (e.g. <code>export MAVEN_OPTS=-Xmx512m</code>) before launching
+ Maven.
+ </li>
+ <li>
+ Be sure to join the commons-dev and commons-user
+ <a href="mail-lists.html">
+ email lists</a> and use them appropriately (make sure the string
+ "[Numbers]" starts the Subject line of all your postings).
+ Make any proposals here where the group can comment on them.
+ </li>
+ <li>
+ <a href="https://issues.apache.org/jira/secure/Signup!default.jspa">
+ Setup an account on JIRA
+ </a>
+ and use it to submit patches and
+ identify bugs. Read the
+ <a href="http://issues.apache.org/bugwritinghelp.html">
+ directions</a>
+ for submitting bugs and search the database to
+ determine if an issue exists or has already been dealt with.
+ <p>
+ See the <a href="http://commons.apache.org/numbers/issue-tracking.html">
+ Commons Numbers Issue Tracking Page</a>
+ for more information on how to
+ search for or submit bugs or enhancement requests.
+ </p>
+ <li>
+ Generating patches: The requested format for generating patches is
+ the Unified Diff format, which can be easily generated using the git
+ client or various IDEs.
+ <source>git diff -p > patch </source>
+ Run this command from the top-level project directory (where pom.xml
+ resides).
+ </li>
+ </li>
+ </ol>
+ </p>
+ <p><strong>Contributing ideas and code</strong></p>
+ <p>
+ Follow the steps below when making suggestions for additions or
+ enhancements to Commons Numbers. This will make it easier for the community
+ to comment on your ideas and for the committers to keep track of them.
+ Thanks in advance!
+ <ol>
+ <li>Start with a post to the commons-dev mailing list, with [Numbers] at
+ the beginning of the subject line, followed by a short title
+ describing the new feature or enhancement; for example, "[Numbers]
+ New cryptographically secure generator".
+ The body of the post should include each of the following items
+ (but be <strong>as brief as possible</strong>):
+ <ul>
+ <li>A concise description of the new feature / enhancement</li>
+ <li>References to definitions and algorithms. Using standard
+ definitions and algorithms makes communication much easier and will
+ greatly increase the chances that we will accept the code / idea</li>
+ <li>Some indication of why the addition / enhancement is practically
+ useful</li>
+ </ul></li>
+ <li>Create a JIRA ticket using the the feature title as the short
+ description. Incorporate feedback from the initial posting in the
+ description. Add a reference to the JIRA ticket to the WishList entry.
+ </li>
+ <li>Submit code as attachments to the JIRA ticket. Please use one
+ ticket for each feature, adding multiple patches to the ticket
+ as necessary. Use the git diff command to generate your patches as
+ diffs. Please do not submit modified copies of existing java files. Be
+ patient (but not <strong>too</strong> patient) with committers reviewing
+ patches. Post a *nudge* message to commons-dev with a reference to the
+ ticket if a patch goes more than a few days with no comment or commit.
+ </li>
+ </ol>
+ </p>
+ </subsection>
- <body>
- <section name="Aims">
- <p>
- Creating and maintaining a mathematical and statistical library that is
- accurate requires a greater degree of communication than might be the
- case for other components. It is important that developers follow
- guidelines laid down by the community to ensure that the code they create
- can be successfully maintained by others.
- </p>
- </section>
- <section name='Guidelines'>
- <p>
- Developers are asked to comply with the following development guidelines.
- Code that does not comply with the guidelines including the word <i>must</i>
- will not be committed. Our aim will be to fix all of the exceptions to the
- "<i>should</i>" guidelines prior to a release.
- </p>
- <subsection name="Contributing">
- <p><strong>Getting Started</strong></p>
- <p>
- <ol>
- <li>Start by reviewing the overall objectives stated in the
- <a href="proposal.html">proposal</a> upon which the project is
- founded.
- </li>
- <li>Download the Commons Math source code. Follow the instructions
- under the heading "Repository Checkout" on the
- <a href="https://git-wip-us.apache.org/">Git at the ASF page</a>.
- The git url for the current development sources of Commons Math
- is <source>http://git-wip-us.apache.org/repos/asf/commons-math.git</source>
- for anonymous read-only access and
- <source>https://apacheid@git-wip-us.apache.org/repos/asf/commons-math.git</source>
- (where apacheid should be replaced by each committer Apache ID) for committers
- read-write access.
- </li>
- <li>Like most commons components, Commons Math uses Apache Maven as our
- build tool. The sources can also be built using Ant (a working
- Ant build.xml is included in the top level project directory).
- To build Commons Math using Maven, you can follow the instructions for
- <a href="http://maven.apache.org/run-maven/index.html">Building a
- project with Maven</a>. Launch Maven from the top-level directory
- in the checkout of Commons Math trunk. No special setup is required,
- except that currently to build the site (i.e. to execute Maven's
- "site" goal), you may need to increase the default memory allocation
- (e.g. <code>export MAVEN_OPTS=-Xmx512m</code>) before launching
- Maven.
- </li>
- <li>Have a look at the new features that users and developers have requested
- on the <a href="http://wiki.apache.org/commons/MathWishList">
- Math Wish List Wiki Page.</a>
- </li>
- <li>Be sure to join the commons-dev and commons-user
- <a href="mail-lists.html">
- email lists</a> and use them appropriately (make sure the string
- "[math]" starts the Subject line of all your postings).
- Make any proposals here where the group can comment on them.
- </li>
- <li>
- <a href="https://issues.apache.org/jira/secure/Signup!default.jspa">
- Setup an account on JIRA</a> and use it to submit patches and
- identify bugs. Read the
- <a href="http://issues.apache.org/bugwritinghelp.html">
- directions</a> for submitting bugs and search the database to
- determine if an issue exists or has already been dealt with.
- <p>
- See the <a href="http://commons.apache.org/math/issue-tracking.html">
- Commons Math Issue Tracking Page</a> for more information on how to
- search for or submit bugs or enhancement requests.
- </p>
- <li>
- Generating patches: The requested format for generating patches is
- the Unified Diff format, which can be easily generated using the git
- client or various IDEs.
-<source>git diff -p > patch </source>
- Run this command from the top-level project directory (where pom.xml
- resides).
- </li>
- </li>
- </ol>
- </p>
- <p><strong>Contributing ideas and code</strong></p>
- <p>
- Follow the steps below when making suggestions for additions or
- enhancements to Commons Math. This will make it easier for the community
- to comment on your ideas and for the committers to keep track of them.
- Thanks in advance!
- <ol>
- <li>Start with a post to the commons-dev mailing list, with [math] at
- the beginning of the subject line, followed by a good, short title
- describing the new feature or enhancement. For example, "[math]
- Principal Components Analysis." The body of the post should include each
- of the following items (but be <strong>as brief as possible</strong>):
- <ul>
- <li>A concise description of the new feature / enhancement</li>
- <li>References to definitions and algorithms. Using standard
- definitions and algorithms makes communication much easier and will
- greatly increase the chances that we will accept the code / idea</li>
- <li>Some indication of why the addition / enhancement is practically
- useful</li>
- </ul></li>
- <li>Assuming a generally favorable response to the idea on commons-dev,
- the next step is to add an entry to the
- <a href="http://wiki.apache.org/commons/MathWishList">Math Wish
- List</a> corresponding to the idea. Include a reference to the
- discussion thread. </li>
- <li>Create a JIRA ticket using the the feature title as the short
- description. Incorporate feedback from the initial posting in the
- description. Add a reference to the JIRA ticket to the WishList entry.
- </li>
- <li>Submit code as attachments to the JIRA ticket. Please use one
- ticket for each feature, adding multiple patches to the ticket
- as necessary. Use the git diff command to generate your patches as
- diffs. Please do not submit modified copies of existing java files. Be
- patient (but not <strong>too</strong> patient) with committers reviewing
- patches. Post a *nudge* message to commons-dev with a reference to the
- ticket if a patch goes more than a few days with no comment or commit.
- </li>
- </ol>
- </p>
- </subsection>
- <subsection name='Coding Style'>
- <p>
- Commons Math follows <a href="http://java.sun.com/docs/codeconv/">Code
- Conventions for the Java Programming Language</a>. As part of the maven
- build process, style checking is performed using the Checkstyle plugin,
- using the properties specified in <code>checkstyle.xml</code>.
- Committed code <i>should</i> generate no Checkstyle errors. One thing
- that Checkstyle will complain about is tabs included in the source code.
- Please make sure to set your IDE or editor to use spaces instead of tabs.
- </p>
- <p>
- Committers should configure the <source>user.name</source>,
- <source>user.email</source> and <source>core.autocrlf</source>
- git repository or global settings with <source>git config</source>.
- The first two settings define the identity and mail of the committer.
- The third setting deals with line endings to achieve consistency
- in line endings. Windows users should configure this setting to
- <source>true</source> (thus forcing git to convert CR/LF line endings
- in the workspace while maintaining LF only line endings in the repository)
- while OS X and Linux users should configure it to <source>input</source>
- (thus forcing git to only strip accidental CR/LF when committing into
- the repository, but never when cheking out files from the repository). See <a
- href="http://www.git-scm.com/book/en/Customizing-Git-Git-Configuration">Customizing
- Git - Git Configuration</a> in the git book for explanation about how to
- configure these settings and more.
- </p>
- </subsection>
- <subsection name='Documentation'>
- <ul>
- <li>
- Committed code <i>must</i> include full javadoc.</li>
- <li>
- All component contracts <i>must</i> be fully specified in the javadoc class,
- interface or method comments, including specification of acceptable ranges
- of values, exceptions or special return values.</li>
- <li>
- External references or full statements of definitions for all mathematical
- terms used in component documentation <i>must</i> be provided.</li>
- <li>
- Commons math javadoc generation now supports embedded LaTeX formulas via the
- <a href="http://www.mathjax.org">MathJax</a> javascript display engine. To
- embed mathematical expressions formatted in LaTeX in javadoc, simply surround
- the expression to be formatted with either \( and \) for inline
- formulas, or \[ and \] to have the formula appear on a separate line.
- For example, \(a^2 + b^2 = c^2\) will render an in-line formula
- saying that (a, b, c) is Pythagorean triplet. Using \[ and \] on
- the ends will render the same formula on a separate line. See the MathJax
- and LaTex documentation for details on how to represent formulas and
- escape special characters.</li>
- <li>
- Implementations <i>should</i> use standard algorithms and
- references or full descriptions of all algorithms <i>should</i> be
- provided.</li>
- <li>
- Additions and enhancements <i>should</i> include updates to the User
- Guide.</li>
- </ul>
- </subsection>
- <subsection name='Exceptions'>
- <ul>
- <li>
- Exceptions generated by Commons Math are all unchecked.</li>
- <li>
- All public methods advertise all exceptions that they can generate.
- Exceptions <i>must</i> be documented in both javadoc and method signatures
- and the documentation in the javadoc <i>must</i> include full description
- of the conditions under which exceptions are thrown.</li>
- <li>
- Methods <i>should</i> fully specify parameter preconditions required for
- successful activation. When preconditions are violated, a
- MathIllegalArgumentException should be thrown. Subclasses of
- MathIllegalArgumentException may be used to represent common parameter
- contract violations (for example, NoBracketingException). Exception
- messages <i>must</i> contain sufficient information on parameter values to
- determine the exact precondition failure.</li>
- <li>
- Exceptions generated by Commons Math make sense without knowing
- implementation details other than those stated in the public API.
- For example, a NoBracketingException makes sense thrown by a solver that
- has a precondition requiring that initial points bracket a root. This
- exception does not make sense, however, thrown by an inverse cumulative
- probability estimator.</li>
- <li>
- MathIllegalArgumentException should only be thrown in situations
- where preconditions can be exhaustively provided so that what arguments
- are "illegal" can be specified fully to the caller. Domain-specific
- exceptions need to be defined for cases where failures cannot be
- attributed to parameter precondition violation. For example, the exact
- domain of successful activation of a solver or quadrature method may be
- impossible to specify because of numerical properties of the method.
- If a solver fails to find a root or a quadrature method fails to converge
- for a given set of parameters, <i>unless those parameters violate the
- advertised preconditions</i> it is not appropriate to throw
- MathIllegalArgumentException.</li>
- <li>
- State information included in exception messages <i>must</i> be available
- in exception properties - i.e., successful handling or reporting of
- Commons Math exceptions must not require parsing exception messages.</li>
- </ul>
- </subsection>
- <subsection name='Unit Tests'>
- <ul>
- <li>
- Committed code <i>must</i> include unit tests.</li>
- <li>
- Unit tests <i>should</i> provide full path coverage. </li>
- <li>
- Unit tests <i>should</i> verify all boundary conditions specified in
- interface contracts, including verification that exceptions are thrown or
- special values (e.g. Double.NaN, Double.Infinity) are returned as
- expected. </li>
- </ul>
- </subsection>
- <subsection name='Licensing and copyright'>
- <ul>
- <li>
- All new source file submissions <i>must</i> include the Apache Software
- License in a comment that begins the file </li>
- <li>
- All contributions must comply with the terms of the Apache
- <a href="http://www.apache.org/licenses/cla.pdf">Contributor License
- Agreement (CLA)</a></li>
- <li>
- Patches <i>must</i> be accompanied by a clear reference to a "source"
- - if code has been "ported" from another language, clearly state the
- source of the original implementation. If the "expression" of a given
- algorithm is derivative, please note the original source (textbook,
- paper, etc.).</li>
- <li>
- References to source materials covered by restrictive proprietary
- licenses should be avoided. In particular, contributions should not
- implement or include references to algorithms in
- <a href="http://www.nr.com/">Numerical Recipes (NR)</a>.
- Any questions about copyright or patent issues should be raised on
- the commons-dev mailing list before contributing or committing code.
- </li>
- </ul>
- </subsection>
- </section>
- <section name='Recommended Readings'>
- <p>
- Here is a list of relevant materials. Much of the discussion surrounding
- the development of this component will refer to the various sources
- listed below, and frequently the Javadoc for a particular class or
- interface will link to a definition contained in these documents.
- </p>
- <subsection name='Recommended Readings'>
- <dl>
- <dt>Concerning floating point arithmetic.</dt>
- <dd>
- <a href="http://www.validlab.com/goldberg/paper.pdf">
- http://www.validlab.com/goldberg/paper.pdf
- </a><br/>
- <a href="http://www.cs.berkeley.edu/~wkahan/ieee754status/IEEE754.PDF">
- http://www.cs.berkeley.edu/~wkahan/ieee754status/IEEE754.PDF
- </a><br/>
- <a href="http://www.cs.berkeley.edu/~wkahan/JAVAhurt.pdf">
- http://www.cs.berkeley.edu/~wkahan/JAVAhurt.pdf
- </a><br/>
- </dd>
- <dt>Numerical analysis</dt>
- <dd>
- <a href="http://www.mathcom.com/corpdir/techinfo.mdir/scifaq/index.html">
- Scientific Computing FAQ @ Mathcom
- </a><br/>
- <a href="http://www.ma.man.ac.uk/~higham/asna/asna2.pdf">
- Bibliography of accuracy and stability of numerical algorithms
- </a><br/>
- <a href="http://tonic.physics.sunysb.edu/docs/num_meth.html">
- SUNY Stony Brook numerical methods page
- </a><br/>
- <a href="http://epubs.siam.org/sam-bin/dbq/toclist/SINUM">
- SIAM Journal of Numerical Analysis Online
- </a><br/>
- </dd>
- <dt>Probability and statistics</dt>
- <dd>
- <a href="http://lib.stat.cmu.edu/">
- Statlib at CMU
- </a><br/>
- <a href="http://www.itl.nist.gov/div898/handbook/">
- NIST Engineering Statistics Handbook
- </a><br/>
- <a href="http://www.psychstat.smsu.edu/sbk00.htm">
- Online Introductory Statistics (David W. Stockburger)
- </a><br/>
- <a href="http://www.jstatsoft.org/">
- Online Journal of Statistical Software
- </a><br/>
- </dd>
- </dl>
- </subsection>
- <subsection name='Javadoc comment resources'>
- <dl>
- <dt>References for mathematical definitions.</dt>
- <dd>
- <a href="http://rd11.web.cern.ch/RD11/rkb/titleA.html">
- http://rd11.web.cern.ch/RD11/rkb/titleA.html
- </a><br/>
- <a href="http://mathworld.wolfram.com/">
- http://mathworld.wolfram.com/
- </a><br/>
- <a href="http://www.itl.nist.gov/div898/handbook">
- http://www.itl.nist.gov/div898/handbook
- </a><br/>
- <a href="http://doi.acm.org/10.1145/359146.359152">
- Chan, T. F. and J. G. Lewis 1979, <i>Communications of the ACM</i>,
- vol. 22 no. 9, pp. 526-531.
- </a><br/>
- </dd>
- </dl>
- </subsection>
- <subsection name='XML'>
- <dl>
- <dt>XML related resources.</dt>
- <dd>
- <a href="http://www.openmath.org">
- http://www.openmath.org
- </a><br/>
- </dd>
- </dl>
- </subsection>
- </section>
- </body>
+ <subsection name='Coding Style'>
+ <p>
+ Commons Numbers follows <a href="http://java.sun.com/docs/codeconv/">Code
+ Conventions for the Java Programming Language</a>. As part of the maven
+ build process, style checking is performed using the Checkstyle plugin,
+ using the properties specified in <code>checkstyle.xml</code>.
+ Committed code <i>should</i> generate no Checkstyle errors. One thing
+ that Checkstyle will complain about is tabs included in the source code.
+ Please make sure to set your IDE or editor to use spaces instead of tabs.
+ </p>
+ <p>
+ Committers should configure the <source>user.name</source>,
+ <source>user.email</source> and <source>core.autocrlf</source>
+ git repository or global settings with <source>git config</source>.
+ The first two settings define the identity and mail of the committer.
+ The third setting deals with line endings to achieve consistency
+ in line endings. Windows users should configure this setting to
+ <source>true</source> (thus forcing git to convert CR/LF line endings
+ in the workspace while maintaining LF only line endings in the repository)
+ while OS X and Linux users should configure it to <source>input</source>
+ (thus forcing git to only strip accidental CR/LF when committing into
+ the repository, but never when cheking out files from the repository). See <a
+ href="http://www.git-scm.com/book/en/Customizing-Git-Git-Configuration">Customizing
+ Git - Git Configuration</a> in the git book for explanation about how to
+ configure these settings and more.
+ </p>
+ </subsection>
+ <subsection name='Documentation'>
+ <ul>
+ <li>
+ Committed code <i>must</i> include full javadoc.
+ </li>
+ <li>
+ All component contracts <i>must</i> be fully specified in the javadoc class,
+ interface or method comments, including specification of acceptable ranges
+ of values, exceptions or special return values.
+ </li>
+ <li>
+ External references or full statements of definitions for all the
+ terms used in component documentation <i>must</i> be provided.
+ </li>
+ <li>
+ Commons Numbers javadoc generation supports embedded LaTeX formulas via the
+ <a href="http://www.mathjax.org">MathJax</a> javascript display engine.
+ To embed mathematical expressions formatted in LaTeX in javadoc, simply surround
+ the expression to be formatted with either <code>\(</code> and <code>\)</code>
+ for inline formulas (or <code>\[</code> and <code>\]</code> to have the formula
+ appear on a separate line).
+ For example,
+ <code>\(</code><code>a^2 + b^2 = c^2</code><code>\)</code>
+ will render an in-line formula
+ saying that (a, b, c) is a Pythagorean triplet: \( a^2 + b^2 = c^2 \).
+ <br/>
+ See the MathJax and LaTex documentation for details on how to represent formulas
+ and escape special characters.
+ </li>
+ <li>
+ Implementations <i>should</i> use standard algorithms and
+ references or full descriptions of all algorithms <i>should</i> be
+ provided.
+ </li>
+ <li>
+ Additions and enhancements <i>should</i> include updates to the User
+ Guide.
+ </li>
+ </ul>
+ </subsection>
+ <subsection name='Exceptions'>
+ <ul>
+ <li>
+ Exceptions generated by Commons Numbers are all unchecked.
+ </li>
+ <li>
+ All public methods advertise all exceptions that they can generate.
+ Exceptions <i>must</i> be documented in Javadoc and the documentation
+ <i>must</i> include full description of the conditions under which
+ exceptions are thrown.
+ </li>
+ </ul>
+ </subsection>
+ <subsection name='Unit Tests'>
+ <ul>
+ <li>
+ Committed code <i>must</i> include unit tests.
+ </li>
+ <li>
+ Unit tests <i>should</i> provide full path coverage.
+ </li>
+ <li>
+ Unit tests <i>should</i> verify all boundary conditions specified in
+ interface contracts, including verification that exceptions are thrown or
+ special values (e.g. Double.NaN, Double.Infinity) are returned as
+ expected.
+ </li>
+ </ul>
+ </subsection>
+ <subsection name='Licensing and copyright'>
+ <ul>
+ <li>
+ All new source file submissions <i>must</i> include the Apache Software
+ License in a comment that begins the file.
+ </li>
+ <li>
+ All contributions must comply with the terms of the Apache
+ <a href="http://www.apache.org/licenses/cla.pdf">Contributor License
+ Agreement (CLA)</a>.
+ </li>
+ <li>
+ Patches <i>must</i> be accompanied by a clear reference to a "source"
+ - if code has been "ported" from another language, clearly state the
+ source of the original implementation. If the "expression" of a given
+ algorithm is derivative, please note the original source (textbook,
+ paper, etc.).
+ </li>
+ <li>
+ References to source materials covered by restrictive proprietary
+ licenses should be avoided. In particular, contributions should not
+ implement or include references to algorithms in
+ <a href="http://www.nr.com/">Numerical Recipes (NR)</a>.
+ Any questions about copyright or patent issues should be raised on
+ the commons-dev mailing list before contributing or committing code.
+ </li>
+ </ul>
+ </subsection>
+ </section>
+ </body>
</document>
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/81911e4c/src/site/xdoc/download_numbers.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/download_numbers.xml b/src/site/xdoc/download_numbers.xml
new file mode 100644
index 0000000..a144629
--- /dev/null
+++ b/src/site/xdoc/download_numbers.xml
@@ -0,0 +1,154 @@
+<?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.
+-->
+<!--
+ +======================================================================+
+ |**** ****|
+ |**** THIS FILE IS GENERATED BY THE COMMONS BUILD PLUGIN ****|
+ |**** DO NOT EDIT DIRECTLY ****|
+ |**** ****|
+ +======================================================================+
+ | TEMPLATE FILE: download-page-template.xml |
+ | commons-build-plugin/trunk/src/main/resources/commons-xdoc-templates |
+ +======================================================================+
+ | |
+ | 1) Re-generate using: mvn commons:download-page |
+ | |
+ | 2) Set the following properties in the component's pom: |
+ | - commons.componentid (required, alphabetic, lower case) |
+ | - commons.release.version (required) |
+ | - commons.release.name (required) |
+ | - commons.binary.suffix (optional) |
+ | (defaults to "-bin", set to "" for pre-maven2 releases) |
+ | - commons.release.desc (optional) |
+ | - commons.release.subdir (optional) |
+ | |
+ | - commons.release.2/3.version (conditional) |
+ | - commons.release.2/3.name (conditional) |
+ | - commons.release.2/3.binary.suffix (optional) |
+ | - commons.release.2/3.desc (optional) |
+ | - commons.release.2/3.subdir (optional) |
+ | |
+ | 3) Example Properties |
+ | (commons.release.name inherited by parent: |
+ | ${project.artifactId}-${commons.release.version} |
+ | |
+ | <properties> |
+ | <commons.componentid>math</commons.componentid> |
+ | <commons.release.version>1.2</commons.release.version> |
+ | </properties> |
+ | |
+ +======================================================================+
+-->
+<document>
+ <properties>
+ <title>Download Apache Commons Numbers</title>
+ <author email="dev@commons.apache.org">Apache Commons Documentation Team</author>
+ </properties>
+ <body>
+ <section name="Download Apache Commons Numbers">
+ <subsection name="Using a Mirror">
+ <p>
+ We recommend you use a mirror to download our release
+ builds, but you <strong>must</strong> <a href="http://www.apache.org/info/verification.html">verify the integrity</a> of
+ the downloaded files using signatures downloaded from our main
+ distribution directories. Recent releases (48 hours) may not yet
+ be available from all the mirrors.
+ </p>
+
+ <p>
+ You are currently using <b>[preferred]</b>. If you
+ encounter a problem with this mirror, please select another
+ mirror. If all mirrors are failing, there are <i>backup</i>
+ mirrors (at the end of the mirrors list) that should be
+ available.
+ <br></br>
+ [if-any logo]<a href="[link]"><img align="right" src="[logo]" border="0"></img></a>[end]
+ </p>
+
+ <form action="[location]" method="get" id="SelectMirror">
+ <p>
+ Other mirrors:
+ <select name="Preferred">
+ [if-any http]
+ [for http]<option value="[http]">[http]</option>[end]
+ [end]
+ [if-any ftp]
+ [for ftp]<option value="[ftp]">[ftp]</option>[end]
+ [end]
+ [if-any backup]
+ [for backup]<option value="[backup]">[backup] (backup)</option>[end]
+ [end]
+ </select>
+ <input type="submit" value="Change"></input>
+ </p>
+ </form>
+
+ <p>
+ It is essential that you
+ <a href="https://www.apache.org/info/verification.html">verify the integrity</a>
+ of downloaded files, preferably using the <code>PGP</code> signature (<code>*.asc</code> files);
+ failing that using the <code>MD5</code> hash (<code>*.md5</code> checksum files).
+ </p>
+ <p>
+ The <a href="https://www.apache.org/dist/commons/KEYS">KEYS</a>
+ file contains the public PGP keys used by Apache Commons developers
+ to sign releases.
+ </p>
+ </subsection>
+ </section>
+ <section name="Apache Commons Numbers 1.0 (requires Java 7+)">
+ <subsection name="Binaries">
+ <table>
+ <tr>
+ <td><a href="[preferred]/commons/numbers/binaries/commons-numbers-1.0-SNAPSHOT-bin.tar.gz">commons-numbers-1.0-SNAPSHOT-bin.tar.gz</a></td>
+ <td><a href="https://www.apache.org/dist/commons/numbers/binaries/commons-numbers-1.0-SNAPSHOT-bin.tar.gz.md5">md5</a></td>
+ <td><a href="https://www.apache.org/dist/commons/numbers/binaries/commons-numbers-1.0-SNAPSHOT-bin.tar.gz.asc">pgp</a></td>
+ </tr>
+ <tr>
+ <td><a href="[preferred]/commons/numbers/binaries/commons-numbers-1.0-SNAPSHOT-bin.zip">commons-numbers-1.0-SNAPSHOT-bin.zip</a></td>
+ <td><a href="https://www.apache.org/dist/commons/numbers/binaries/commons-numbers-1.0-SNAPSHOT-bin.zip.md5">md5</a></td>
+ <td><a href="https://www.apache.org/dist/commons/numbers/binaries/commons-numbers-1.0-SNAPSHOT-bin.zip.asc">pgp</a></td>
+ </tr>
+ </table>
+ </subsection>
+ <subsection name="Source">
+ <table>
+ <tr>
+ <td><a href="[preferred]/commons/numbers/source/commons-numbers-1.0-SNAPSHOT-src.tar.gz">commons-numbers-1.0-SNAPSHOT-src.tar.gz</a></td>
+ <td><a href="https://www.apache.org/dist/commons/numbers/source/commons-numbers-1.0-SNAPSHOT-src.tar.gz.md5">md5</a></td>
+ <td><a href="https://www.apache.org/dist/commons/numbers/source/commons-numbers-1.0-SNAPSHOT-src.tar.gz.asc">pgp</a></td>
+ </tr>
+ <tr>
+ <td><a href="[preferred]/commons/numbers/source/commons-numbers-1.0-SNAPSHOT-src.zip">commons-numbers-1.0-SNAPSHOT-src.zip</a></td>
+ <td><a href="https://www.apache.org/dist/commons/numbers/source/commons-numbers-1.0-SNAPSHOT-src.zip.md5">md5</a></td>
+ <td><a href="https://www.apache.org/dist/commons/numbers/source/commons-numbers-1.0-SNAPSHOT-src.zip.asc">pgp</a></td>
+ </tr>
+ </table>
+ </subsection>
+ </section>
+ <section name="Archives">
+ <p>
+ Older releases can be obtained from the archives.
+ </p>
+ <ul>
+ <li class="download"><a href="[preferred]/commons/numbers/">browse download area</a></li>
+ <li><a href="https://archive.apache.org/dist/commons/numbers/">archives...</a></li>
+ </ul>
+ </section>
+ </body>
+</document>
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/81911e4c/src/site/xdoc/issue-tracking.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/issue-tracking.xml b/src/site/xdoc/issue-tracking.xml
index 237c4c3..222833a 100644
--- a/src/site/xdoc/issue-tracking.xml
+++ b/src/site/xdoc/issue-tracking.xml
@@ -43,35 +43,35 @@ limitations under the License.
-->
<document>
<properties>
- <title>Commons Math Issue tracking</title>
- <author email="dev@commons.apache.org">Commons Documentation Team</author>
+ <title>Apache Commons Numbers Issue tracking</title>
+ <author email="dev@commons.apache.org">Apache Commons Documentation Team</author>
</properties>
<body>
- <section name="Commons Math Issue tracking">
+ <section name="Apache Commons Numbers Issue tracking">
<p>
- Commons Math uses <a href="http://issues.apache.org/jira/">ASF JIRA</a> for tracking issues.
- See the <a href="http://issues.apache.org/jira/browse/MATH">Commons Math JIRA project page</a>.
+ Apache Commons Numbers uses <a href="https://issues.apache.org/jira/">ASF JIRA</a> for tracking issues.
+ See the <a href="https://issues.apache.org/jira/browse/NUMBERS">Apache Commons Numbers JIRA project page</a>.
</p>
<p>
- To use JIRA you may need to <a href="http://issues.apache.org/jira/secure/Signup!default.jspa">create an account</a>
+ To use JIRA you may need to <a href="https://issues.apache.org/jira/secure/Signup!default.jspa">create an account</a>
(if you have previously created/updated Commons issues using Bugzilla an account will have been automatically
- created and you can use the <a href="http://issues.apache.org/jira/secure/ForgotPassword!default.jspa">Forgot Password</a>
+ created and you can use the <a href="https://issues.apache.org/jira/secure/ForgotPassword!default.jspa">Forgot Password</a>
page to get a new password).
</p>
<p>
If you would like to report a bug, or raise an enhancement request with
- Commons Math please do the following:
+ Apache Commons Numbers please do the following:
<ol>
- <li><a href="http://issues.apache.org/jira/secure/IssueNavigator.jspa?reset=true&pid=12310485&sorter/field=issuekey&sorter/order=DESC&status=1&status=3&status=4">Search existing open bugs</a>.
+ <li><a href="https://issues.apache.org/jira/secure/IssueNavigator.jspa?reset=true&pid=12310485&sorter/field=issuekey&sorter/order=DESC&status=1&status=3&status=4">Search existing open bugs</a>.
If you find your issue listed then please add a comment with your details.</li>
<li><a href="mail-lists.html">Search the mailing list archive(s)</a>.
You may find your issue or idea has already been discussed.</li>
<li>Decide if your issue is a bug or an enhancement.</li>
- <li>Submit either a <a href="http://issues.apache.org/jira/secure/CreateIssueDetails!init.jspa?pid=12310485&issuetype=1&priority=4&assignee=-1">bug report</a>
- or <a href="http://issues.apache.org/jira/secure/CreateIssueDetails!init.jspa?pid=12310485&issuetype=4&priority=4&assignee=-1">enhancement request</a>.</li>
+ <li>Submit either a <a href="https://issues.apache.org/jira/secure/CreateIssueDetails!init.jspa?pid=12310485&issuetype=1&priority=4&assignee=-1">bug report</a>
+ or <a href="https://issues.apache.org/jira/secure/CreateIssueDetails!init.jspa?pid=12310485&issuetype=4&priority=4&assignee=-1">enhancement request</a>.</li>
</ol>
</p>
@@ -80,7 +80,7 @@ limitations under the License.
<ul>
<li>the more information you provide, the better we can help you</li>
<li>test cases are vital, particularly for any proposed enhancements</li>
- <li>the developers of Commons Math are all unpaid volunteers</li>
+ <li>the developers of Apache Commons Numbers are all unpaid volunteers</li>
</ul>
</p>
@@ -92,9 +92,9 @@ limitations under the License.
<p>
You may also find these links useful:
<ul>
- <li><a href="http://issues.apache.org/jira/secure/IssueNavigator.jspa?reset=true&pid=12310485&sorter/field=issuekey&sorter/order=DESC&status=1&status=3&status=4">All Open Commons Math bugs</a></li>
- <li><a href="http://issues.apache.org/jira/secure/IssueNavigator.jspa?reset=true&pid=12310485&sorter/field=issuekey&sorter/order=DESC&status=5&status=6">All Resolved Commons Math bugs</a></li>
- <li><a href="http://issues.apache.org/jira/secure/IssueNavigator.jspa?reset=true&pid=12310485&sorter/field=issuekey&sorter/order=DESC">All Commons Math bugs</a></li>
+ <li><a href="https://issues.apache.org/jira/secure/IssueNavigator.jspa?reset=true&pid=12310485&sorter/field=issuekey&sorter/order=DESC&status=1&status=3&status=4">All Open Apache Commons Numbers bugs</a></li>
+ <li><a href="https://issues.apache.org/jira/secure/IssueNavigator.jspa?reset=true&pid=12310485&sorter/field=issuekey&sorter/order=DESC&status=5&status=6">All Resolved Apache Commons Numbers bugs</a></li>
+ <li><a href="https://issues.apache.org/jira/secure/IssueNavigator.jspa?reset=true&pid=12310485&sorter/field=issuekey&sorter/order=DESC">All Apache Commons Numbers bugs</a></li>
</ul>
</p>
</section>
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/81911e4c/src/site/xdoc/mail-lists.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/mail-lists.xml b/src/site/xdoc/mail-lists.xml
index d1f1de8..7461af4 100644
--- a/src/site/xdoc/mail-lists.xml
+++ b/src/site/xdoc/mail-lists.xml
@@ -41,42 +41,45 @@ limitations under the License.
-->
<document>
<properties>
- <title>Commons Math Mailing Lists</title>
- <author email="dev@commons.apache.org">Commons Documentation Team</author>
+ <title>Apache Commons Numbers Mailing Lists</title>
+ <author email="dev@commons.apache.org">Apache Commons Documentation Team</author>
</properties>
<body>
<section name="Overview">
<p>
- <a href="index.html">Commons Math</a> shares mailing lists with all the other
+ <a href="index.html">Apache Commons Numbers</a> shares mailing lists with all the other
<a href="http://commons.apache.org/components.html">Commons Components</a>.
To make it easier for people to only read messages related to components they are interested in,
the convention in Commons is to prefix the subject line of messages with the component's name,
for example:
<ul>
- <li>[math] Problem with the ...</li>
+ <li>[numbers] Problem with the ...</li>
</ul>
</p>
<p>
- Questions related to the usage of Commons Math should be posted to the
+ Questions related to the usage of Apache Commons Numbers should be posted to the
<a href="http://mail-archives.apache.org/mod_mbox/commons-user/">User List</a>.
<br />
The <a href="http://mail-archives.apache.org/mod_mbox/commons-dev/">Developer List</a>
- is for questions and discussion related to the development of Commons Math.
+ is for questions and discussion related to the development of Apache Commons Numbers.
<br />
Please do not cross-post; developers are also subscribed to the user list.
+ <br />
+ You must be subscribed to post to the mailing lists. Follow the Subscribe links below
+ to subscribe.
</p>
<p>
<strong>Note:</strong> please don't send patches or attachments to any of the mailing lists.
- Patches are best handled via the <a href="issue-tracking.html">Issue Tracking</a> system.
- Otherwise, please upload the file to a public server and include the URL in the mail.
+ Patches are best handled via the <a href="issue-tracking.html">Issue Tracking</a> system.
+ Otherwise, please upload the file to a public server and include the URL in the mail.
</p>
</section>
- <section name="Commons Math Mailing Lists">
+ <section name="Apache Commons Numbers Mailing Lists">
<p>
- <strong>Please prefix the subject line of any messages for <a href="index.html">Commons Math</a>
- with <i>[math]</i></strong> - <i>thanks!</i>
+ <strong>Please prefix the subject line of any messages for <a href="index.html">Apache Commons Numbers</a>
+ with <i>[numbers]</i></strong> - <i>thanks!</i>
<br />
<br />
</p>
@@ -96,12 +99,12 @@ limitations under the License.
<td>
<strong>Commons User List</strong>
<br /><br />
- Questions on using Commons Math.
+ Questions on using Apache Commons Numbers.
<br /><br />
</td>
<td><a href="mailto:user-subscribe@commons.apache.org">Subscribe</a></td>
<td><a href="mailto:user-unsubscribe@commons.apache.org">Unsubscribe</a></td>
- <td><a href="mailto:user@commons.apache.org?subject=[math]">Post</a></td>
+ <td><a href="mailto:user@commons.apache.org?subject=[numbers]">Post</a></td>
<td><a href="http://mail-archives.apache.org/mod_mbox/commons-user/">mail-archives.apache.org</a></td>
<td><a href="http://markmail.org/list/org.apache.commons.users/">markmail.org</a><br />
<a href="http://www.mail-archive.com/user@commons.apache.org/">www.mail-archive.com</a><br />
@@ -114,12 +117,12 @@ limitations under the License.
<td>
<strong>Commons Developer List</strong>
<br /><br />
- Discussion of development of Commons Math.
+ Discussion of development of Apache Commons Numbers.
<br /><br />
</td>
<td><a href="mailto:dev-subscribe@commons.apache.org">Subscribe</a></td>
<td><a href="mailto:dev-unsubscribe@commons.apache.org">Unsubscribe</a></td>
- <td><a href="mailto:dev@commons.apache.org?subject=[math]">Post</a></td>
+ <td><a href="mailto:dev@commons.apache.org?subject=[numbers]">Post</a></td>
<td><a href="http://mail-archives.apache.org/mod_mbox/commons-dev/">mail-archives.apache.org</a></td>
<td><a href="http://markmail.org/list/org.apache.commons.dev/">markmail.org</a><br />
<a href="http://www.mail-archive.com/dev@commons.apache.org/">www.mail-archive.com</a><br />
@@ -185,10 +188,10 @@ limitations under the License.
General announcements of Apache project releases.
<br /><br />
</td>
- <td><a class="externalLink" href="mailto:announce-subscribe@apache.org">Subscribe</a></td>
- <td><a class="externalLink" href="mailto:announce-unsubscribe@apache.org">Unsubscribe</a></td>
+ <td><a class="externalLink" href="mailto:announce-subscribe@apache.org">Subscribe</a></td>
+ <td><a class="externalLink" href="mailto:announce-unsubscribe@apache.org">Unsubscribe</a></td>
<td><i>read only</i></td>
- <td><a class="externalLink" href="http://mail-archives.apache.org/mod_mbox/www-announce/">mail-archives.apache.org</a></td>
+ <td><a class="externalLink" href="http://mail-archives.apache.org/mod_mbox/www-announce/">mail-archives.apache.org</a></td>
<td><a class="externalLink" href="http://markmail.org/list/org.apache.announce/">markmail.org</a><br />
<a class="externalLink" href="http://old.nabble.com/Apache-News-and-Announce-f109.html">old.nabble.com</a><br />
<a class="externalLink" href="http://www.mail-archive.com/announce@apache.org/">www.mail-archive.com</a><br />
[08/31] commons-numbers git commit: Cleanup (massive delete).
Posted by er...@apache.org.
Cleanup (massive delete).
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/a752ab8d
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/a752ab8d
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/a752ab8d
Branch: refs/heads/master
Commit: a752ab8d4e4d1a9982cd1df45743cafc6dedd5dc
Parents: 0d64d85
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Wed Jan 18 14:20:27 2017 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Wed Jan 18 14:20:27 2017 +0100
----------------------------------------------------------------------
checkstyle.xml | 202 ---
clirr-ignored.xml | 21 -
findbugs-exclude-filter.xml | 331 ----
license-header.txt | 16 -
pmd-ruleset.xml | 73 -
.../org/apache/commons/complex/Complex.java | 1369 ----------------
.../apache/commons/complex/ComplexFormat.java | 595 -------
.../apache/commons/complex/ComplexUtils.java | 1430 -----------------
.../org/apache/commons/complex/Precision.java | 128 --
.../org/apache/commons/complex/Quaternion.java | 467 ------
.../apache/commons/complex/RootsOfUnity.java | 116 --
.../apache/commons/complex/package-info.java | 23 -
src/test/R/ChiSquareDistributionTestCases.R | 97 --
src/test/R/FDistributionTestCases.R | 92 --
src/test/R/GammaDistributionTestCases.R | 92 --
.../R/KolmogorovSmirnovDistributionTestCases.R | 37 -
src/test/R/KolmogorovSmirnovTestCases.R | 208 ---
src/test/R/LevyDistributionTestCases.R | 88 --
src/test/R/README.txt | 168 --
src/test/R/TDistributionTestCases.R | 100 --
src/test/R/TTestCases | 106 --
src/test/R/WeibullDistributionTestCases.R | 92 --
src/test/R/anovaTestCases | 72 -
src/test/R/binomialTestCases | 127 --
src/test/R/cauchyTestCases.R | 97 --
src/test/R/chiSquareTestCases | 101 --
src/test/R/correlationTestCases | 259 ---
src/test/R/covarianceTestCases | 146 --
src/test/R/descriptiveTestCases | 83 -
src/test/R/exponentialTestCases | 103 --
src/test/R/geometricTestCases | 121 --
src/test/R/gumbelTestCases.R | 85 -
src/test/R/hypergeometricTestCases | 139 --
src/test/R/laplaceTestCases.R | 85 -
src/test/R/logNormalTestCases | 107 --
src/test/R/logisticsTestCases.R | 85 -
src/test/R/multipleOLSRegressionTestCases | 309 ----
src/test/R/nakagamiTestCases.R | 85 -
src/test/R/normalTestCases | 111 --
src/test/R/paretoTestCases | 111 --
src/test/R/pascalTestCases | 135 --
src/test/R/poissonTestCases | 116 --
src/test/R/regressionTestCases | 159 --
src/test/R/testAll | 83 -
src/test/R/testFunctions | 86 -
src/test/R/zipfTestCases | 89 --
.../complex/ComplexFormatAbstractTest.java | 310 ----
.../commons/complex/ComplexFormatTest.java | 33 -
.../org/apache/commons/complex/ComplexTest.java | 1477 ------------------
.../commons/complex/ComplexUtilsTest.java | 475 ------
.../commons/complex/ComplexUtilsTest.java.orig | 608 -------
.../complex/FrenchComplexFormatTest.java | 34 -
.../apache/commons/complex/QuaternionTest.java | 459 ------
.../java/org/apache/commons/complex/Retry.java | 29 -
.../org/apache/commons/complex/RetryRunner.java | 81 -
.../apache/commons/complex/RetryRunnerTest.java | 53 -
.../commons/complex/RootsOfUnityTest.java | 84 -
.../org/apache/commons/complex/TestUtils.java | 408 -----
.../apache/commons/complex/TestUtils.java.orig | 662 --------
test-jar.xml | 99 --
60 files changed, 13557 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/checkstyle.xml
----------------------------------------------------------------------
diff --git a/checkstyle.xml b/checkstyle.xml
deleted file mode 100644
index af59d2b..0000000
--- a/checkstyle.xml
+++ /dev/null
@@ -1,202 +0,0 @@
-<?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 "-//Puppy Crawl//DTD Check Configuration 1.1//EN" "http://www.puppycrawl.com/dtds/configuration_1_1.dtd">
-
-<!-- commons math customization of default Checkstyle behavior -->
-<module name="Checker">
- <property name="localeLanguage" value="en"/>
-
- <module name="TreeWalker">
-
- <!-- Operator must be at end of wrapped line -->
- <module name="OperatorWrap">
- <property name="option" value="eol"/>
- </module>
-
- <!-- No if/else/do/for/while without braces -->
- <module name="NeedBraces"/>
-
- <!-- Interfaces must be types (not just constants) -->
- <module name="InterfaceIsType"/>
-
- <!-- Must have class / interface header comments -->
- <module name="JavadocType"/>
-
- <!-- Require method javadocs, allow undeclared RTE -->
- <module name="JavadocMethod">
- <property name="allowUndeclaredRTE" value="true"/>
- <property name="allowThrowsTagsForSubclasses" value="true"/>
- <property name="validateThrows" value="false"/>
- </module>
-
- <!-- Require field javadoc -->
- <module name="JavadocVariable"/>
-
- <!-- No public fields -->
- <module name="VisibilityModifier">
- <property name="protectedAllowed" value="true"/>
- </module>
-
- <!-- Require hash code override when equals is -->
- <module name="EqualsHashCode"/>
-
- <!-- Disallow unnecessary instantiation of Boolean, String -->
- <module name="IllegalInstantiation">
- <property name="classes" value="java.lang.Boolean, java.lang.String"/>
- </module>
-
- <!-- Required for SuppressionCommentFilter below -->
- <module name="FileContentsHolder"/>
-
- <!-- Import should be explicit, really needed and only from pure java packages -->
- <module name="AvoidStarImport" />
- <module name="UnusedImports" />
- <module name="IllegalImport" />
-
- <!-- Utility class should not be instantiated, they must have a private constructor -->
- <module name="HideUtilityClassConstructor" />
-
- <!-- Switch statements should be complete and with independent cases -->
- <module name="FallThrough" />
- <module name="MissingSwitchDefault" />
-
- <!-- Constant names should obey the traditional all uppercase naming convention -->
- <module name="ConstantName" />
-
- <!-- 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>
-
- <!-- No trailing whitespace -->
- <module name="Regexp">
- <property name="format" value="[ \t]+$"/>
- <property name="illegalPattern" value="true"/>
- <property name="message" value="Trailing whitespace"/>
- </module>
-
- <!-- No System.out.println() statements -->
- <module name="Regexp">
- <!-- no sysouts -->
- <property name="format" value="System\.out\.println"/>
- <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 modifiers -->
- <module name="RedundantModifier" />
- <module name="ModifierOrder" />
-
- <!-- 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" />
-
- <!-- Don't declare multiple variables in the same statement -->
- <module name="MultipleVariableDeclarations" />
-
- <!-- 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" />
-
- <!-- <module name="TodoComment" /> -->
-
- </module>
-
- <!-- Verify that EVERY source file has the appropriate license -->
- <module name="Header">
- <property name="headerFile" value="${checkstyle.header.file}"/>
- </module>
-
- <!-- No tabs allowed! -->
- <module name="FileTabCharacter"/>
-
- <!-- Require files to end with newline characters -->
- <module name="NewlineAtEndOfFile"/>
-
- <!-- Require package javadoc -->
- <module name="JavadocPackage"/>
-
- <!-- Setup special comments to suppress specific checks from source files -->
- <module name="SuppressionCommentFilter">
- <property name="offCommentFormat" value="CHECKSTYLE\: stop JavadocVariable"/>
- <property name="onCommentFormat" value="CHECKSTYLE\: resume JavadocVariable"/>
- <property name="checkFormat" value="JavadocVariable"/>
- </module>
- <module name="SuppressionCommentFilter">
- <property name="offCommentFormat" value="CHECKSTYLE\: stop JavadocMethodCheck"/>
- <property name="onCommentFormat" value="CHECKSTYLE\: resume JavadocMethodCheck"/>
- <property name="checkFormat" value="JavadocMethodCheck"/>
- </module>
- <module name="SuppressionCommentFilter">
- <property name="offCommentFormat" value="CHECKSTYLE\: stop ConstantName"/>
- <property name="onCommentFormat" value="CHECKSTYLE\: resume ConstantName"/>
- <property name="checkFormat" value="ConstantName"/>
- </module>
- <module name="SuppressionCommentFilter">
- <property name="offCommentFormat" value="CHECKSTYLE\: stop HideUtilityClassConstructor"/>
- <property name="onCommentFormat" value="CHECKSTYLE\: resume HideUtilityClassConstructor"/>
- <property name="checkFormat" value="HideUtilityClassConstructor"/>
- </module>
- <module name="SuppressionCommentFilter">
- <property name="offCommentFormat" value="CHECKSTYLE\: stop MultipleVariableDeclarations"/>
- <property name="onCommentFormat" value="CHECKSTYLE\: resume MultipleVariableDeclarations"/>
- <property name="checkFormat" value="MultipleVariableDeclarations"/>
- </module>
- <module name="SuppressionCommentFilter">
- <property name="offCommentFormat" value="CHECKSTYLE\: stop IllegalCatch"/>
- <property name="onCommentFormat" value="CHECKSTYLE\: resume IllegalCatch"/>
- <property name="checkFormat" value="IllegalCatch"/>
- </module>
- <module name="SuppressionCommentFilter">
- <property name="offCommentFormat" value="CHECKSTYLE\: stop DeclarationOrder"/>
- <property name="onCommentFormat" value="CHECKSTYLE\: resume DeclarationOrder"/>
- <property name="checkFormat" value="DeclarationOrder"/>
- </module>
- <module name="SuppressionCommentFilter">
- <property name="offCommentFormat" value="CHECKSTYLE\: stop RedundantModifier"/>
- <property name="onCommentFormat" value="CHECKSTYLE\: resume RedundantModifier"/>
- <property name="checkFormat" value="RedundantModifier"/>
- </module>
- <module name="SuppressionCommentFilter">
- <property name="offCommentFormat" value="CHECKSTYLE\: stop all"/>
- <property name="onCommentFormat" value="CHECKSTYLE\: resume all"/>
- </module>
-</module>
-
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/clirr-ignored.xml
----------------------------------------------------------------------
diff --git a/clirr-ignored.xml b/clirr-ignored.xml
deleted file mode 100644
index ed97259..0000000
--- a/clirr-ignored.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?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.
--->
-
-<differences>
-
-</differences>
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/findbugs-exclude-filter.xml
----------------------------------------------------------------------
diff --git a/findbugs-exclude-filter.xml b/findbugs-exclude-filter.xml
deleted file mode 100644
index f76eb63..0000000
--- a/findbugs-exclude-filter.xml
+++ /dev/null
@@ -1,331 +0,0 @@
-<?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.
--->
-
-<!--
- This file contains some false positive bugs detected by findbugs. Their
- false positive nature has been analyzed individually and they have been
- put here to instruct findbugs it must ignore them.
--->
-<FindBugsFilter>
-
- <!-- the following equality tests are part of the reference algorithms -->
- <!-- which already know about limited precision of the double numbers -->
- <Match>
- <Class name="org.apache.commons.complex.analysis.solvers.BaseSecantSolver" />
- <Method name="doSolve" params="" returns="double" />
- <Bug pattern="FE_FLOATING_POINT_EQUALITY" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.distribution.SaddlePointExpansion" />
- <Or>
- <Method name="getDeviancePart" params="double,double" returns="double" />
- <Method name="getStirlingError" params="double" returns="double" />
- </Or>
- <Bug pattern="FE_FLOATING_POINT_EQUALITY" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.optim.univariate.BrentOptimizer" />
- <Method name="localMin" params="boolean,double,double,double,double,double" returns="double" />
- <Bug pattern="FE_FLOATING_POINT_EQUALITY" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.analysis.solvers.BrentSolver" />
- <Method name="brent" params="double,double,double,double" returns="double" />
- <Bug pattern="FE_FLOATING_POINT_EQUALITY" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.analysis.solvers.MullerSolver" />
- <Or>
- <Method name="solve" params="double,double,double,double" returns="double" />
- </Or>
- <Bug pattern="FE_FLOATING_POINT_EQUALITY" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.analysis.solvers.MullerSolver2" />
- <Or>
- <Method name="doSolve" params="" returns="double" />
- </Or>
- <Bug pattern="FE_FLOATING_POINT_EQUALITY" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.linear.EigenDecomposition" />
- <Method name="findEigenVectors" params="double[][]" returns="void" />
- <Bug pattern="FE_FLOATING_POINT_EQUALITY" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.optim.nonlinear.scalar.noderiv.BOBYQAOptimizer" />
- <Method name="altmov" params="int,double" returns="double[]" />
- <Bug pattern="FE_FLOATING_POINT_EQUALITY" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.optim.nonlinear.scalar.noderiv.CMAESOptimizer" />
- <Method name="doOptimize" params="" returns="org.apache.commons.complex.optim.PointValuePair" />
- <Bug pattern="FE_FLOATING_POINT_EQUALITY" />
- </Match>
-
- <!-- The following equality test is intentional and needed for semantic purposes -->
- <Match>
- <Or>
- <Class name="org.apache.commons.complex.geometry.euclidean.oned.Vector1D" />
- <Class name="org.apache.commons.complex.geometry.euclidean.twod.Vector2D" />
- <Class name="org.apache.commons.complex.geometry.euclidean.threed.Vector3D" />
- </Or>
- <Method name="equals" params="java.lang.Object" returns="boolean" />
- <Bug pattern="FE_FLOATING_POINT_EQUALITY" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.optim.linear.LinearConstraint" />
- <Method name="equals" params="java.lang.Object" returns="boolean" />
- <Bug pattern="FE_FLOATING_POINT_EQUALITY" />
- </Match>
-
- <!-- The following equality test is intentional and needed for rounding purposes -->
- <Match>
- <Class name="org.apache.commons.complex.util.Precision" />
- <Method name="roundUnscaled" params="double,double,int" returns="double" />
- <Bug pattern="FE_FLOATING_POINT_EQUALITY" />
- </Match>
-
- <!-- The following equality test is intentional for division protection -->
- <Match>
- <Class name="org.apache.commons.complex.analysis.interpolation.LoessInterpolator" />
- <Method name="smooth" params="double[],double[]" returns="double[]" />
- <Bug pattern="FE_FLOATING_POINT_EQUALITY" />
- </Match>
-
- <!-- The following equality test is intentional for infinity detection -->
- <Match>
- <Class name="org.apache.commons.complex.util.FastMath" />
- <Method name="atan2" params="double,double" returns="double" />
- <Bug pattern="FE_FLOATING_POINT_EQUALITY" />
- </Match>
-
- <!-- The following switch fall-through are due to conversion from FORTRAN goto,
- which are handled by a state integer representing the target labels of the goto.
- In the original code, this is sequential and fall-through is expected
- -->
- <Match>
- <Class name="org.apache.commons.complex.optim.nonlinear.scalar.noderiv.BOBYQAOptimizer" />
- <Or>
- <Method name="bobyqb" params="double[],double[]" returns="double" />
- <Method name="trsbox" />
- </Or>
- <Bug pattern="SF_SWITCH_FALLTHROUGH" />
- </Match>
-
- <!-- Spurious: Findbugs confused by final local variables -->
- <Match>
- <Class name="org.apache.commons.complex.util.FastMath" />
- <Method name="atan" params="double,double,boolean" returns="double" />
- <Bug pattern="DLS_DEAD_LOCAL_STORE" />
- </Match>
-
- <!-- Spurious: Findbugs confused by FastMath.PI - 1.0e-10 -->
- <Match>
- <Class name="org.apache.commons.complex.geometry.euclidean.threed.Plane" />
- <Method name="isSimilarTo" params="org.apache.commons.complex.geometry.euclidean.threed.Plane" returns="boolean" />
- <Bug pattern="CNT_ROUGH_CONSTANT_VALUE" />
- </Match>
-
- <!-- Spurious: Findbugs confused by constant 1.570796251296997 which is a
- intentionally slightly offset from PI/2 as per Cody Waite arguments reduction -->
- <Match>
- <Class name="org.apache.commons.complex.util.FastMath$CodyWaite" />
- <Method name="<init>" params="double" returns="void" />
- <Bug pattern="CNT_ROUGH_CONSTANT_VALUE" />
- </Match>
-
- <!-- the following expositions of internal representation are intentional and documented -->
- <Match>
- <Class name="org.apache.commons.complex.stat.regression.RegressionResults"/>
- <Method name="<init>" params="double[],double[][],boolean,long,int,double,double,double,boolean,boolean" returns="void" />
- <Bug pattern="EI_EXPOSE_REP2" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.stat.descriptive.AbstractUnivariateStatistic"/>
- <Method name="getDataRef" params="" returns="double[]" />
- <Bug pattern="EI_EXPOSE_REP" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.optim.PointValuePair"/>
- <Method name="getPointRef" params="" returns="double[]" />
- <Bug pattern="EI_EXPOSE_REP" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.optim.PointValuePair"/>
- <Method name="<init>" params="double[],double,boolean" returns="void" />
- <Bug pattern="EI_EXPOSE_REP2" />
- </Match>
- <!-- Serialization is handled by an internal class -->
- <Match>
- <Or>
- <Class name="org.apache.commons.complex.optim.PointValuePair"/>
- <Class name="org.apache.commons.complex.optim.PointVectorValuePair"/>
- </Or>
- <Bug pattern="SE_NO_SUITABLE_CONSTRUCTOR" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.optim.PointVectorValuePair"/>
- <Or>
- <Method name="getPointRef" params="" returns="double[]" />
- <Method name="getValueRef" params="" returns="double[]" />
- </Or>
- <Bug pattern="EI_EXPOSE_REP" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.optim.PointVectorValuePair"/>
- <Method name="<init>" params="double[],double[][],boolean" returns="void" />
- <Bug pattern="EI_EXPOSE_REP2" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.ode.sampling.DummyStepInterpolator"/>
- <Method name="<init>" params="double[],double[],boolean" returns="void" />
- <Bug pattern="EI_EXPOSE_REP2" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.ode.sampling.AbstractStepInterpolator"/>
- <Or>
- <Method name="getInterpolatedState" params="" returns="double[]" />
- <Method name="getInterpolatedDerivatives" params="" returns="double[]" />
- </Or>
- <Bug pattern="EI_EXPOSE_REP" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.ode.sampling.NordsieckStepInterpolator"/>
- <Method name="reinitialize" params="double,double,double[],org.apache.commons.complex.linear.Array2DRowRealMatrix" returns="void" />
- <Bug pattern="EI_EXPOSE_REP2" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.ode.sampling.NordsieckStepInterpolator"/>
- <Method name="getInterpolatedStateVariation" params="" returns="double[]" />
- <Bug pattern="EI_EXPOSE_REP" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.linear.Array2DRowRealMatrix"/>
- <Method name="<init>" params="double[][],boolean" returns="void" />
- <Bug pattern="EI_EXPOSE_REP2" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.linear.Array2DRowRealMatrix"/>
- <Method name="getDataRef" params="" returns="double[][]" />
- <Bug pattern="EI_EXPOSE_REP" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.linear.BlockFieldMatrix"/>
- <Method name="<init>" params="int,int,org.apache.commons.complex.FieldElement[][],boolean" returns="void" />
- <Bug pattern="EI_EXPOSE_REP2" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.linear.Array2DRowFieldMatrix"/>
- <Method name="<init>" params="org.apache.commons.complex.Field,org.apache.commons.complex.FieldElement[][],boolean" returns="void" />
- <Bug pattern="EI_EXPOSE_REP2" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.linear.Array2DRowFieldMatrix"/>
- <Method name="getDataRef" params="" returns="org.apache.commons.complex.FieldElement[][]" />
- <Bug pattern="EI_EXPOSE_REP" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.linear.BlockRealMatrix"/>
- <Method name="<init>" params="int,int,double[][],boolean" returns="void" />
- <Bug pattern="EI_EXPOSE_REP2" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.util.ResizableDoubleArray"/>
- <Or>
- <Method name="getValues" params="" returns="double[]" />
- <Method name="getInternalValues" params="" returns="double[]" />
- </Or>
- <Bug pattern="EI_EXPOSE_REP" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.linear.ArrayRealVector"/>
- <Method name="getDataRef" params="" returns="double[]" />
- <Bug pattern="EI_EXPOSE_REP" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.linear.ArrayFieldVector"/>
- <Method name="getDataRef" params="" returns="org.apache.commons.complex.FieldElement[]" />
- <Bug pattern="EI_EXPOSE_REP" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.linear.DiagonalMatrix"/>
- <Method name="getDataRef" params="" returns="double[]" />
- <Bug pattern="EI_EXPOSE_REP" />
- </Match>
- <!-- The equals method for RealVector intentionally throws an exception -->
- <Match>
- <Class name="org.apache.commons.complex.linear.RealVector"/>
- <Bug pattern="EQ_UNUSUAL" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.ml.clustering.DoublePoint"/>
- <Method name="<init>" params="double[]" returns="void" />
- <Bug pattern="EI_EXPOSE_REP2" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.ml.clustering.DoublePoint"/>
- <Method name="getPoint" params="" returns="double[]" />
- <Bug pattern="EI_EXPOSE_REP" />
- </Match>
-
- <!-- The following cases are intentional unit tests for null parameters -->
- <Match>
- <Class name="org.apache.commons.complex.stat.StatUtilsTest" />
- <Method name="testPercentile" params="" returns="void" />
- <Bug pattern="NP_NULL_PARAM_DEREF_NONVIRTUAL" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.analysis.UnivariateRealSolverFactoryImplTest" />
- <Method name="testNewNewtonSolverNull" params="" returns="void" />
- <Bug pattern="NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" />
- </Match>
- <Match>
- <Class name="org.apache.commons.complex.stat.regression.OLSMultipleLinearRegressionTest" />
- <Method name="cannotAddNullYSampleData" params="" returns="void" />
- <Bug pattern="NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" />
- </Match>
-
- <!-- IntDoublePair intentionally implements Comparable inconsistently with equals -->
- <Match>
- <Class name="org.apache.commons.complex.stat.ranking.NaturalRanking$IntDoublePair" />
- <Bug pattern="EQ_COMPARETO_USE_OBJECT_EQUALS" />
- </Match>
-
- <!-- False positive warning from findbugs, the integer division result cast to double is correct here -->
- <Match>
- <Class name="org.apache.commons.complex.stat.inference.MannWhitneyUTest" />
- <Method name="mannWhitneyU" params="double[],double[]" returns="double" />
- <Bug pattern="ICAST_IDIV_CAST_TO_DOUBLE" />
- </Match>
-
- <!-- The following switch fall-through is intended. -->
- <Match>
- <Class name="org.apache.commons.complex.ml.neuralnet.twod.NeuronSquareMesh2D" />
- <Method name="createLinks" />
- <Bug pattern="SF_SWITCH_FALLTHROUGH" />
- </Match>
-
- <!-- Integer division results cast to double are intentional. -->
- <Match>
- <Class name="org.apache.commons.complex.special.BesselJ" />
- <Method name="rjBesl" />
- <Bug pattern="ICAST_IDIV_CAST_TO_DOUBLE" />
- </Match>
-
-</FindBugsFilter>
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/license-header.txt
----------------------------------------------------------------------
diff --git a/license-header.txt b/license-header.txt
deleted file mode 100644
index ae6f28c..0000000
--- a/license-header.txt
+++ /dev/null
@@ -1,16 +0,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.
- */
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/pmd-ruleset.xml
----------------------------------------------------------------------
diff --git a/pmd-ruleset.xml b/pmd-ruleset.xml
deleted file mode 100644
index 12e6137..0000000
--- a/pmd-ruleset.xml
+++ /dev/null
@@ -1,73 +0,0 @@
-<?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.
--->
-<ruleset name="commons-math-customized"
- xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
- <description>
- This ruleset checks the code for discouraged programming constructs.
- </description>
-
- <rule ref="rulesets/java/basic.xml"/>
-
- <rule ref="rulesets/java/braces.xml"/>
-
- <rule ref="rulesets/java/comments.xml">
- <exclude name="CommentSize"/>
- </rule>
- <rule ref="rulesets/java/comments.xml/CommentSize">
- <properties>
- <property name="maxLines" value="200"/>
- <property name="maxLineLength" value="256"/>
- </properties>
- </rule>
-
- <rule ref="rulesets/java/empty.xml"/>
-
- <rule ref="rulesets/java/finalizers.xml"/>
-
- <rule ref="rulesets/java/imports.xml"/>
-
- <rule ref="rulesets/java/typeresolution.xml">
- <!-- TODO: we should reactivate this rule -->
- <exclude name="CloneMethodMustImplementCloneable"/>
- </rule>
-
- <!-- TODO: we should reactivate this ruleset -->
- <!-- <rule ref="rulesets/java/clone.xml"/> -->
-
- <rule ref="rulesets/java/unnecessary.xml">
-
- <!-- In many places in Apache Commons Math, there are complex boolean expressions.
- We do use extra parentheses there as most people do not recall operator precedence,
- this means even if the parentheses are useless for the compiler, we don't consider
- them useless for the developer. This is the reason why we disable this rule. -->
- <exclude name="UselessParentheses"/>
-
- <!-- At several places in the optimization package, we set up public "optimize" methods
- that simply call their base class optimize method. This is intentional and allows
- to update the javadoc and make sure the additional parameters implemented at the
- lower class level are properly documented. These new parameters are really taken
- into accound despite we merely call super.optimize because the top level optimze
- methods call a protected parseOptimizationData method implemented in the specialized
- class. This is the reason why we disable this rule. -->
- <exclude name="UselessOverridingMethod"/>
-
- </rule>
-
-</ruleset>
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/main/java/org/apache/commons/complex/Complex.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/complex/Complex.java b/src/main/java/org/apache/commons/complex/Complex.java
deleted file mode 100644
index 1313d8a..0000000
--- a/src/main/java/org/apache/commons/complex/Complex.java
+++ /dev/null
@@ -1,1369 +0,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.
- */
-
-package org.apache.commons.complex;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Representation of a Complex number, i.e. a number which has both a
- * real and imaginary part.
- * <p>
- * Implementations of arithmetic operations handle {@code NaN} and
- * infinite values according to the rules for {@link java.lang.Double}, i.e.
- * {@link #equals} is an equivalence relation for all instances that have
- * a {@code NaN} in either real or imaginary part, e.g. the following are
- * considered equal:
- * <ul>
- * <li>{@code 1 + NaNi}</li>
- * <li>{@code NaN + i}</li>
- * <li>{@code NaN + NaNi}</li>
- * </ul><p>
- * Note that this contradicts the IEEE-754 standard for floating
- * point numbers (according to which the test {@code x == x} must fail if
- * {@code x} is {@code NaN}). The method
- * {@link org.apache.commons.complex.util.Precision#equals(double,double,int)
- * equals for primitive double} in {@link org.apache.commons.complex.util.Precision}
- * conforms with IEEE-754 while this class conforms with the standard behavior
- * for Java object types.</p>
- *
- */
-public class Complex implements Serializable {
- /** The square root of -1. A number representing "0.0 + 1.0i" */
- public static final Complex I = new Complex(0.0, 1.0);
- // CHECKSTYLE: stop ConstantName
- /** A complex number representing "NaN + NaNi" */
- public static final Complex NaN = new Complex(Double.NaN, Double.NaN);
- // CHECKSTYLE: resume ConstantName
- /** A complex number representing "+INF + INFi" */
- public static final Complex INF = new Complex(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
- /** A complex number representing "1.0 + 0.0i" */
- public static final Complex ONE = new Complex(1.0, 0.0);
- /** A complex number representing "0.0 + 0.0i" */
- public static final Complex ZERO = new Complex(0.0, 0.0);
-
- /** Serializable version identifier */
- private static final long serialVersionUID = -6195664516687396620L;
-
- /** The imaginary part. */
- private final double imaginary;
- /** The real part. */
- private final double real;
- /** Record whether this complex number is equal to NaN. */
- private final transient boolean isNaN;
- /** Record whether this complex number is infinite. */
- private final transient boolean isInfinite;
-
- /**
- * Create a complex number given only the real part.
- *
- * @param real Real part.
- */
- public Complex(double real) {
- this(real, 0.0);
- }
-
- /**
- * Create a complex number given the real and imaginary parts.
- *
- * @param real Real part.
- * @param imaginary Imaginary part.
- */
- public Complex(double real, double imaginary) {
- this.real = real;
- this.imaginary = imaginary;
-
- isNaN = Double.isNaN(real) || Double.isNaN(imaginary);
- isInfinite = !isNaN &&
- (Double.isInfinite(real) || Double.isInfinite(imaginary));
- }
-
- /**
- * Return the absolute value of this complex number.
- * Returns {@code NaN} if either real or imaginary part is {@code NaN}
- * and {@code Double.POSITIVE_INFINITY} if neither part is {@code NaN},
- * but at least one part is infinite.
- *
- * @return the absolute value.
- */
- public double abs() {
- if (isNaN) {
- return Double.NaN;
- }
- if (isInfinite()) {
- return Double.POSITIVE_INFINITY;
- }
- if (Math.abs(real) < Math.abs(imaginary)) {
- if (imaginary == 0.0) {
- return Math.abs(real);
- }
- double q = real / imaginary;
- return Math.abs(imaginary) * Math.sqrt(1 + q * q);
- } else {
- if (real == 0.0) {
- return Math.abs(imaginary);
- }
- double q = imaginary / real;
- return Math.abs(real) * Math.sqrt(1 + q * q);
- }
- }
-
- /**
- * Returns a {@code Complex} whose value is
- * {@code (this + addend)}.
- * Uses the definitional formula
- * <p>
- * {@code (a + bi) + (c + di) = (a+c) + (b+d)i}
- * </p>
- * If either {@code this} or {@code addend} has a {@code NaN} value in
- * either part, {@link #NaN} is returned; otherwise {@code Infinite}
- * and {@code NaN} values are returned in the parts of the result
- * according to the rules for {@link java.lang.Double} arithmetic.
- *
- * @param addend Value to be added to this {@code Complex}.
- * @return {@code this + addend}.
- */
- public Complex add(Complex addend) {
- checkNotNull(addend);
- if (isNaN || addend.isNaN) {
- return NaN;
- }
-
- return createComplex(real + addend.getReal(),
- imaginary + addend.getImaginary());
- }
-
- /**
- * Returns a {@code Complex} whose value is {@code (this + addend)},
- * with {@code addend} interpreted as a real number.
- *
- * @param addend Value to be added to this {@code Complex}.
- * @return {@code this + addend}.
- * @see #add(Complex)
- */
- public Complex add(double addend) {
- if (isNaN || Double.isNaN(addend)) {
- return NaN;
- }
-
- return createComplex(real + addend, imaginary);
- }
-
- /**
- * Returns the conjugate of this complex number.
- * The conjugate of {@code a + bi} is {@code a - bi}.
- * <p>
- * {@link #NaN} is returned if either the real or imaginary
- * part of this Complex number equals {@code Double.NaN}.
- * </p><p>
- * If the imaginary part is infinite, and the real part is not
- * {@code NaN}, the returned value has infinite imaginary part
- * of the opposite sign, e.g. the conjugate of
- * {@code 1 + POSITIVE_INFINITY i} is {@code 1 - NEGATIVE_INFINITY i}.
- * </p>
- * @return the conjugate of this Complex object.
- */
- public Complex conjugate() {
- if (isNaN) {
- return NaN;
- }
-
- return createComplex(real, -imaginary);
- }
-
- /**
- * Returns a {@code Complex} whose value is
- * {@code (this / divisor)}.
- * Implements the definitional formula
- * <pre>
- * <code>
- * a + bi ac + bd + (bc - ad)i
- * ----------- = -------------------------
- * c + di c<sup>2</sup> + d<sup>2</sup>
- * </code>
- * </pre>
- * but uses
- * <a href="http://doi.acm.org/10.1145/1039813.1039814">
- * prescaling of operands</a> to limit the effects of overflows and
- * underflows in the computation.
- * <p>
- * {@code Infinite} and {@code NaN} values are handled according to the
- * following rules, applied in the order presented:
- * <ul>
- * <li>If either {@code this} or {@code divisor} has a {@code NaN} value
- * in either part, {@link #NaN} is returned.
- * </li>
- * <li>If {@code divisor} equals {@link #ZERO}, {@link #NaN} is returned.
- * </li>
- * <li>If {@code this} and {@code divisor} are both infinite,
- * {@link #NaN} is returned.
- * </li>
- * <li>If {@code this} is finite (i.e., has no {@code Infinite} or
- * {@code NaN} parts) and {@code divisor} is infinite (one or both parts
- * infinite), {@link #ZERO} is returned.
- * </li>
- * <li>If {@code this} is infinite and {@code divisor} is finite,
- * {@code NaN} values are returned in the parts of the result if the
- * {@link java.lang.Double} rules applied to the definitional formula
- * force {@code NaN} results.
- * </li>
- * </ul>
- *
- * @param divisor Value by which this {@code Complex} is to be divided.
- * @return {@code this / divisor}.
- */
- public Complex divide(Complex divisor) {
- checkNotNull(divisor);
- if (isNaN || divisor.isNaN) {
- return NaN;
- }
-
- final double c = divisor.getReal();
- final double d = divisor.getImaginary();
- if (c == 0.0 && d == 0.0) {
- return NaN;
- }
-
- if (divisor.isInfinite() && !isInfinite()) {
- return ZERO;
- }
-
- if (Math.abs(c) < Math.abs(d)) {
- double q = c / d;
- double denominator = c * q + d;
- return createComplex((real * q + imaginary) / denominator,
- (imaginary * q - real) / denominator);
- } else {
- double q = d / c;
- double denominator = d * q + c;
- return createComplex((imaginary * q + real) / denominator,
- (imaginary - real * q) / denominator);
- }
- }
-
- /**
- * Returns a {@code Complex} whose value is {@code (this / divisor)},
- * with {@code divisor} interpreted as a real number.
- *
- * @param divisor Value by which this {@code Complex} is to be divided.
- * @return {@code this / divisor}.
- * @see #divide(Complex)
- */
- public Complex divide(double divisor) {
- if (isNaN || Double.isNaN(divisor)) {
- return NaN;
- }
- if (divisor == 0d) {
- return NaN;
- }
- if (Double.isInfinite(divisor)) {
- return !isInfinite() ? ZERO : NaN;
- }
- return createComplex(real / divisor,
- imaginary / divisor);
- }
-
- /** {@inheritDoc} */
- public Complex reciprocal() {
- if (isNaN) {
- return NaN;
- }
-
- if (real == 0.0 && imaginary == 0.0) {
- return INF;
- }
-
- if (isInfinite) {
- return ZERO;
- }
-
- if (Math.abs(real) < Math.abs(imaginary)) {
- double q = real / imaginary;
- double scale = 1. / (real * q + imaginary);
- return createComplex(scale * q, -scale);
- } else {
- double q = imaginary / real;
- double scale = 1. / (imaginary * q + real);
- return createComplex(scale, -scale * q);
- }
- }
-
- /**
- * Test for equality with another object.
- * If both the real and imaginary parts of two complex numbers
- * are exactly the same, and neither is {@code Double.NaN}, the two
- * Complex objects are considered to be equal.
- * The behavior is the same as for JDK's {@link Double#equals(Object)
- * Double}:
- * <ul>
- * <li>All {@code NaN} values are considered to be equal,
- * i.e, if either (or both) real and imaginary parts of the complex
- * number are equal to {@code Double.NaN}, the complex number is equal
- * to {@code NaN}.
- * </li>
- * <li>
- * Instances constructed with different representations of zero (i.e.
- * either "0" or "-0") are <em>not</em> considered to be equal.
- * </li>
- * </ul>
- *
- * @param other Object to test for equality with this instance.
- * @return {@code true} if the objects are equal, {@code false} if object
- * is {@code null}, not an instance of {@code Complex}, or not equal to
- * this instance.
- */
- @Override
- public boolean equals(Object other) {
- if (this == other) {
- return true;
- }
- if (other instanceof Complex){
- Complex c = (Complex) other;
- if (c.isNaN) {
- return isNaN;
- } else {
- return equals(real, c.real) &&
- equals(imaginary, c.imaginary);
- }
- }
- return false;
- }
-
- /**
- * Test for the floating-point equality between Complex objects.
- * It returns {@code true} if both arguments are equal or within the
- * range of allowed error (inclusive).
- *
- * @param x First value (cannot be {@code null}).
- * @param y Second value (cannot be {@code null}).
- * @param maxUlps {@code (maxUlps - 1)} is the number of floating point
- * values between the real (resp. imaginary) parts of {@code x} and
- * {@code y}.
- * @return {@code true} if there are fewer than {@code maxUlps} floating
- * point values between the real (resp. imaginary) parts of {@code x}
- * and {@code y}.
- *
- * @see Precision#equals(double,double,int)
- * @since 3.3
- */
- public static boolean equals(Complex x, Complex y, int maxUlps) {
- return Precision.equals(x.real, y.real, maxUlps) &&
- Precision.equals(x.imaginary, y.imaginary, maxUlps);
- }
-
- /**
- * Returns {@code true} iff the values are equal as defined by
- * {@link #equals(Complex,Complex,int) equals(x, y, 1)}.
- *
- * @param x First value (cannot be {@code null}).
- * @param y Second value (cannot be {@code null}).
- * @return {@code true} if the values are equal.
- *
- * @since 3.3
- */
- public static boolean equals(Complex x, Complex y) {
- return equals(x, y, 1);
- }
-
- /**
- * Returns {@code true} if, both for the real part and for the imaginary
- * part, there is no double value strictly between the arguments or the
- * difference between them is within the range of allowed error
- * (inclusive). Returns {@code false} if either of the arguments is NaN.
- *
- * @param x First value (cannot be {@code null}).
- * @param y Second value (cannot be {@code null}).
- * @param eps Amount of allowed absolute error.
- * @return {@code true} if the values are two adjacent floating point
- * numbers or they are within range of each other.
- *
- * @see Precision#equals(double,double,double)
- * @since 3.3
- */
- public static boolean equals(Complex x, Complex y, double eps) {
- return Precision.equals(x.real, y.real, eps) &&
- Precision.equals(x.imaginary, y.imaginary, eps);
- }
-
- /**
- * Returns {@code true} if, both for the real part and for the imaginary
- * part, there is no double value strictly between the arguments or the
- * relative difference between them is smaller or equal to the given
- * tolerance. Returns {@code false} if either of the arguments is NaN.
- *
- * @param x First value (cannot be {@code null}).
- * @param y Second value (cannot be {@code null}).
- * @param eps Amount of allowed relative error.
- * @return {@code true} if the values are two adjacent floating point
- * numbers or they are within range of each other.
- *
- * @see Precision#equalsWithRelativeTolerance(double,double,double)
- * @since 3.3
- */
- public static boolean equalsWithRelativeTolerance(Complex x, Complex y,
- double eps) {
- return Precision.equalsWithRelativeTolerance(x.real, y.real, eps) &&
- Precision.equalsWithRelativeTolerance(x.imaginary, y.imaginary, eps);
- }
-
- /**
- * Get a hashCode for the complex number.
- * Any {@code Double.NaN} value in real or imaginary part produces
- * the same hash code {@code 7}.
- *
- * @return a hash code value for this object.
- */
- @Override
- public int hashCode() {
- if (isNaN) {
- return 7;
- }
- return 37 * (17 * hash(imaginary) +
- hash(real));
- }
-
- /**
- * Access the imaginary part.
- *
- * @return the imaginary part.
- */
- public double getImaginary() {
- return imaginary;
- }
-
- /**
- * Access the real part.
- *
- * @return the real part.
- */
- public double getReal() {
- return real;
- }
-
- /**
- * Checks whether either or both parts of this complex number is
- * {@code NaN}.
- *
- * @return true if either or both parts of this complex number is
- * {@code NaN}; false otherwise.
- */
- public boolean isNaN() {
- return isNaN;
- }
-
- /**
- * Checks whether either the real or imaginary part of this complex number
- * takes an infinite value (either {@code Double.POSITIVE_INFINITY} or
- * {@code Double.NEGATIVE_INFINITY}) and neither part
- * is {@code NaN}.
- *
- * @return true if one or both parts of this complex number are infinite
- * and neither part is {@code NaN}.
- */
- public boolean isInfinite() {
- return isInfinite;
- }
-
- /**
- * Returns a {@code Complex} whose value is {@code this * factor}.
- * Implements preliminary checks for {@code NaN} and infinity followed by
- * the definitional formula:
- * <p>
- * {@code (a + bi)(c + di) = (ac - bd) + (ad + bc)i}
- * </p>
- * Returns {@link #NaN} if either {@code this} or {@code factor} has one or
- * more {@code NaN} parts.
- * <p>
- * Returns {@link #INF} if neither {@code this} nor {@code factor} has one
- * or more {@code NaN} parts and if either {@code this} or {@code factor}
- * has one or more infinite parts (same result is returned regardless of
- * the sign of the components).
- * </p><p>
- * Returns finite values in components of the result per the definitional
- * formula in all remaining cases.</p>
- *
- * @param factor value to be multiplied by this {@code Complex}.
- * @return {@code this * factor}.
- */
- public Complex multiply(Complex factor) {
- checkNotNull(factor);
- if (isNaN || factor.isNaN) {
- return NaN;
- }
- if (Double.isInfinite(real) ||
- Double.isInfinite(imaginary) ||
- Double.isInfinite(factor.real) ||
- Double.isInfinite(factor.imaginary)) {
- // we don't use isInfinite() to avoid testing for NaN again
- return INF;
- }
- return createComplex(real * factor.real - imaginary * factor.imaginary,
- real * factor.imaginary + imaginary * factor.real);
- }
-
- /**
- * Returns a {@code Complex} whose value is {@code this * factor}, with {@code factor}
- * interpreted as a integer number.
- *
- * @param factor value to be multiplied by this {@code Complex}.
- * @return {@code this * factor}.
- * @see #multiply(Complex)
- */
- public Complex multiply(final int factor) {
- if (isNaN) {
- return NaN;
- }
- if (Double.isInfinite(real) ||
- Double.isInfinite(imaginary)) {
- return INF;
- }
- return createComplex(real * factor, imaginary * factor);
- }
-
- /**
- * Returns a {@code Complex} whose value is {@code this * factor}, with {@code factor}
- * interpreted as a real number.
- *
- * @param factor value to be multiplied by this {@code Complex}.
- * @return {@code this * factor}.
- * @see #multiply(Complex)
- */
- public Complex multiply(double factor) {
- if (isNaN || Double.isNaN(factor)) {
- return NaN;
- }
- if (Double.isInfinite(real) ||
- Double.isInfinite(imaginary) ||
- Double.isInfinite(factor)) {
- // we don't use isInfinite() to avoid testing for NaN again
- return INF;
- }
- return createComplex(real * factor, imaginary * factor);
- }
-
- /**
- * Returns a {@code Complex} whose value is {@code (-this)}.
- * Returns {@code NaN} if either real or imaginary
- * part of this Complex number is {@code Double.NaN}.
- *
- * @return {@code -this}.
- */
- public Complex negate() {
- if (isNaN) {
- return NaN;
- }
-
- return createComplex(-real, -imaginary);
- }
-
- /**
- * Returns a {@code Complex} whose value is
- * {@code (this - subtrahend)}.
- * Uses the definitional formula
- * <p>
- * {@code (a + bi) - (c + di) = (a-c) + (b-d)i}
- * </p>
- * If either {@code this} or {@code subtrahend} has a {@code NaN]} value in either part,
- * {@link #NaN} is returned; otherwise infinite and {@code NaN} values are
- * returned in the parts of the result according to the rules for
- * {@link java.lang.Double} arithmetic.
- *
- * @param subtrahend value to be subtracted from this {@code Complex}.
- * @return {@code this - subtrahend}.
- */
- public Complex subtract(Complex subtrahend) {
- checkNotNull(subtrahend);
- if (isNaN || subtrahend.isNaN) {
- return NaN;
- }
-
- return createComplex(real - subtrahend.getReal(),
- imaginary - subtrahend.getImaginary());
- }
-
- /**
- * Returns a {@code Complex} whose value is
- * {@code (this - subtrahend)}.
- *
- * @param subtrahend value to be subtracted from this {@code Complex}.
- * @return {@code this - subtrahend}.
- * @see #subtract(Complex)
- */
- public Complex subtract(double subtrahend) {
- if (isNaN || Double.isNaN(subtrahend)) {
- return NaN;
- }
- return createComplex(real - subtrahend, imaginary);
- }
-
- /**
- * Compute the
- * <a href="http://mathworld.wolfram.com/InverseCosine.html" TARGET="_top">
- * inverse cosine</a> of this complex number.
- * Implements the formula:
- * <p>
- * {@code acos(z) = -i (log(z + i (sqrt(1 - z<sup>2</sup>))))}
- * </p>
- * Returns {@link Complex#NaN} if either real or imaginary part of the
- * input argument is {@code NaN} or infinite.
- *
- * @return the inverse cosine of this complex number.
- * @since 1.2
- */
- public Complex acos() {
- if (isNaN) {
- return NaN;
- }
-
- return this.add(this.sqrt1z().multiply(I)).log().multiply(I.negate());
- }
-
- /**
- * Compute the
- * <a href="http://mathworld.wolfram.com/InverseSine.html" TARGET="_top">
- * inverse sine</a> of this complex number.
- * Implements the formula:
- * <p>
- * {@code asin(z) = -i (log(sqrt(1 - z<sup>2</sup>) + iz))}
- * </p><p>
- * Returns {@link Complex#NaN} if either real or imaginary part of the
- * input argument is {@code NaN} or infinite.</p>
- *
- * @return the inverse sine of this complex number.
- * @since 1.2
- */
- public Complex asin() {
- if (isNaN) {
- return NaN;
- }
-
- return sqrt1z().add(this.multiply(I)).log().multiply(I.negate());
- }
-
- /**
- * Compute the
- * <a href="http://mathworld.wolfram.com/InverseTangent.html" TARGET="_top">
- * inverse tangent</a> of this complex number.
- * Implements the formula:
- * <p>
- * {@code atan(z) = (i/2) log((i + z)/(i - z))}
- * </p><p>
- * Returns {@link Complex#NaN} if either real or imaginary part of the
- * input argument is {@code NaN} or infinite.</p>
- *
- * @return the inverse tangent of this complex number
- * @since 1.2
- */
- public Complex atan() {
- if (isNaN) {
- return NaN;
- }
-
- return this.add(I).divide(I.subtract(this)).log()
- .multiply(I.divide(createComplex(2.0, 0.0)));
- }
-
- /**
- * Compute the
- * <a href="http://mathworld.wolfram.com/Cosine.html" TARGET="_top">
- * cosine</a> of this complex number.
- * Implements the formula:
- * <p>
- * {@code cos(a + bi) = cos(a)cosh(b) - sin(a)sinh(b)i}
- * </p><p>
- * where the (real) functions on the right-hand side are
- * {@link Math#sin}, {@link Math#cos},
- * {@link Math#cosh} and {@link Math#sinh}.
- * </p><p>
- * Returns {@link Complex#NaN} if either real or imaginary part of the
- * input argument is {@code NaN}.
- * </p><p>
- * Infinite values in real or imaginary parts of the input may result in
- * infinite or NaN values returned in parts of the result.</p>
- * <pre>
- * Examples:
- * <code>
- * cos(1 ± INFINITY i) = 1 \u2213 INFINITY i
- * cos(±INFINITY + i) = NaN + NaN i
- * cos(±INFINITY ± INFINITY i) = NaN + NaN i
- * </code>
- * </pre>
- *
- * @return the cosine of this complex number.
- * @since 1.2
- */
- public Complex cos() {
- if (isNaN) {
- return NaN;
- }
-
- return createComplex(Math.cos(real) * Math.cosh(imaginary),
- -Math.sin(real) * Math.sinh(imaginary));
- }
-
- /**
- * Compute the
- * <a href="http://mathworld.wolfram.com/HyperbolicCosine.html" TARGET="_top">
- * hyperbolic cosine</a> of this complex number.
- * Implements the formula:
- * <pre>
- * <code>
- * cosh(a + bi) = cosh(a)cos(b) + sinh(a)sin(b)i
- * </code>
- * </pre>
- * where the (real) functions on the right-hand side are
- * {@link Math#sin}, {@link Math#cos},
- * {@link Math#cosh} and {@link Math#sinh}.
- * <p>
- * Returns {@link Complex#NaN} if either real or imaginary part of the
- * input argument is {@code NaN}.
- * </p>
- * Infinite values in real or imaginary parts of the input may result in
- * infinite or NaN values returned in parts of the result.
- * <pre>
- * Examples:
- * <code>
- * cosh(1 ± INFINITY i) = NaN + NaN i
- * cosh(±INFINITY + i) = INFINITY ± INFINITY i
- * cosh(±INFINITY ± INFINITY i) = NaN + NaN i
- * </code>
- * </pre>
- *
- * @return the hyperbolic cosine of this complex number.
- * @since 1.2
- */
- public Complex cosh() {
- if (isNaN) {
- return NaN;
- }
-
- return createComplex(Math.cosh(real) * Math.cos(imaginary),
- Math.sinh(real) * Math.sin(imaginary));
- }
-
- /**
- * Compute the
- * <a href="http://mathworld.wolfram.com/ExponentialFunction.html" TARGET="_top">
- * exponential function</a> of this complex number.
- * Implements the formula:
- * <pre>
- * <code>
- * exp(a + bi) = exp(a)cos(b) + exp(a)sin(b)i
- * </code>
- * </pre>
- * where the (real) functions on the right-hand side are
- * {@link Math#exp}, {@link Math#cos}, and
- * {@link Math#sin}.
- * <p>
- * Returns {@link Complex#NaN} if either real or imaginary part of the
- * input argument is {@code NaN}.
- * </p>
- * Infinite values in real or imaginary parts of the input may result in
- * infinite or NaN values returned in parts of the result.
- * <pre>
- * Examples:
- * <code>
- * exp(1 ± INFINITY i) = NaN + NaN i
- * exp(INFINITY + i) = INFINITY + INFINITY i
- * exp(-INFINITY + i) = 0 + 0i
- * exp(±INFINITY ± INFINITY i) = NaN + NaN i
- * </code>
- * </pre>
- *
- * @return <code><i>e</i><sup>this</sup></code>.
- * @since 1.2
- */
- public Complex exp() {
- if (isNaN) {
- return NaN;
- }
-
- double expReal = Math.exp(real);
- return createComplex(expReal * Math.cos(imaginary),
- expReal * Math.sin(imaginary));
- }
-
- /**
- * Compute the
- * <a href="http://mathworld.wolfram.com/NaturalLogarithm.html" TARGET="_top">
- * natural logarithm</a> of this complex number.
- * Implements the formula:
- * <pre>
- * <code>
- * log(a + bi) = ln(|a + bi|) + arg(a + bi)i
- * </code>
- * </pre>
- * where ln on the right hand side is {@link Math#log},
- * {@code |a + bi|} is the modulus, {@link Complex#abs}, and
- * {@code arg(a + bi) = }{@link Math#atan2}(b, a).
- * <p>
- * Returns {@link Complex#NaN} if either real or imaginary part of the
- * input argument is {@code NaN}.
- * </p>
- * Infinite (or critical) values in real or imaginary parts of the input may
- * result in infinite or NaN values returned in parts of the result.
- * <pre>
- * Examples:
- * <code>
- * log(1 ± INFINITY i) = INFINITY ± (π/2)i
- * log(INFINITY + i) = INFINITY + 0i
- * log(-INFINITY + i) = INFINITY + πi
- * log(INFINITY ± INFINITY i) = INFINITY ± (π/4)i
- * log(-INFINITY ± INFINITY i) = INFINITY ± (3π/4)i
- * log(0 + 0i) = -INFINITY + 0i
- * </code>
- * </pre>
- *
- * @return the value <code>ln this</code>, the natural logarithm
- * of {@code this}.
- * @since 1.2
- */
- public Complex log() {
- if (isNaN) {
- return NaN;
- }
-
- return createComplex(Math.log(abs()),
- Math.atan2(imaginary, real));
- }
-
- /**
- * Returns of value of this complex number raised to the power of {@code x}.
- * Implements the formula:
- * <pre>
- * <code>
- * y<sup>x</sup> = exp(x·log(y))
- * </code>
- * </pre>
- * where {@code exp} and {@code log} are {@link #exp} and
- * {@link #log}, respectively.
- * <p>
- * Returns {@link Complex#NaN} if either real or imaginary part of the
- * input argument is {@code NaN} or infinite, or if {@code y}
- * equals {@link Complex#ZERO}.</p>
- *
- * @param x exponent to which this {@code Complex} is to be raised.
- * @return <code> this<sup>x</sup></code>.
- * @since 1.2
- */
- public Complex pow(Complex x) {
- checkNotNull(x);
- if (real == 0 && imaginary == 0) {
- if (x.real > 0 && x.imaginary == 0) {
- // 0 raised to positive number is 0
- return ZERO;
- } else {
- // 0 raised to anything else is NaN
- return NaN;
- }
- }
- return this.log().multiply(x).exp();
- }
-
- /**
- * Returns of value of this complex number raised to the power of {@code x}.
- *
- * @param x exponent to which this {@code Complex} is to be raised.
- * @return <code>this<sup>x</sup></code>.
- * @see #pow(Complex)
- */
- public Complex pow(double x) {
- if (real == 0 && imaginary == 0) {
- if (x > 0) {
- // 0 raised to positive number is 0
- return ZERO;
- } else {
- // 0 raised to anything else is NaN
- return NaN;
- }
- }
- return this.log().multiply(x).exp();
- }
-
- /**
- * Compute the
- * <a href="http://mathworld.wolfram.com/Sine.html" TARGET="_top">
- * sine</a>
- * of this complex number.
- * Implements the formula:
- * <pre>
- * <code>
- * sin(a + bi) = sin(a)cosh(b) - cos(a)sinh(b)i
- * </code>
- * </pre>
- * where the (real) functions on the right-hand side are
- * {@link Math#sin}, {@link Math#cos},
- * {@link Math#cosh} and {@link Math#sinh}.
- * <p>
- * Returns {@link Complex#NaN} if either real or imaginary part of the
- * input argument is {@code NaN}.
- * </p><p>
- * Infinite values in real or imaginary parts of the input may result in
- * infinite or {@code NaN} values returned in parts of the result.
- * <pre>
- * Examples:
- * <code>
- * sin(1 ± INFINITY i) = 1 ± INFINITY i
- * sin(±INFINITY + i) = NaN + NaN i
- * sin(±INFINITY ± INFINITY i) = NaN + NaN i
- * </code>
- * </pre>
- *
- * @return the sine of this complex number.
- * @since 1.2
- */
- public Complex sin() {
- if (isNaN) {
- return NaN;
- }
-
- return createComplex(Math.sin(real) * Math.cosh(imaginary),
- Math.cos(real) * Math.sinh(imaginary));
- }
-
- /**
- * Compute the
- * <a href="http://mathworld.wolfram.com/HyperbolicSine.html" TARGET="_top">
- * hyperbolic sine</a> of this complex number.
- * Implements the formula:
- * <pre>
- * <code>
- * sinh(a + bi) = sinh(a)cos(b)) + cosh(a)sin(b)i
- * </code>
- * </pre>
- * where the (real) functions on the right-hand side are
- * {@link Math#sin}, {@link Math#cos},
- * {@link Math#cosh} and {@link Math#sinh}.
- * <p>
- * Returns {@link Complex#NaN} if either real or imaginary part of the
- * input argument is {@code NaN}.
- * </p><p>
- * Infinite values in real or imaginary parts of the input may result in
- * infinite or NaN values returned in parts of the result.
- * <pre>
- * Examples:
- * <code>
- * sinh(1 ± INFINITY i) = NaN + NaN i
- * sinh(±INFINITY + i) = ± INFINITY + INFINITY i
- * sinh(±INFINITY ± INFINITY i) = NaN + NaN i
- * </code>
- * </pre>
- *
- * @return the hyperbolic sine of {@code this}.
- * @since 1.2
- */
- public Complex sinh() {
- if (isNaN) {
- return NaN;
- }
-
- return createComplex(Math.sinh(real) * Math.cos(imaginary),
- Math.cosh(real) * Math.sin(imaginary));
- }
-
- /**
- * Compute the
- * <a href="http://mathworld.wolfram.com/SquareRoot.html" TARGET="_top">
- * square root</a> of this complex number.
- * Implements the following algorithm to compute {@code sqrt(a + bi)}:
- * <ol><li>Let {@code t = sqrt((|a| + |a + bi|) / 2)}</li>
- * <li><pre>if {@code a ≥ 0} return {@code t + (b/2t)i}
- * else return {@code |b|/2t + sign(b)t i }</pre></li>
- * </ol>
- * where <ul>
- * <li>{@code |a| = }{@link Math#abs}(a)</li>
- * <li>{@code |a + bi| = }{@link Complex#abs}(a + bi)</li>
- * <li>{@code sign(b) = }{@link Math#copySign(double,double) copySign(1d, b)}
- * </ul>
- * <p>
- * Returns {@link Complex#NaN} if either real or imaginary part of the
- * input argument is {@code NaN}.
- * </p>
- * Infinite values in real or imaginary parts of the input may result in
- * infinite or NaN values returned in parts of the result.
- * <pre>
- * Examples:
- * <code>
- * sqrt(1 ± INFINITY i) = INFINITY + NaN i
- * sqrt(INFINITY + i) = INFINITY + 0i
- * sqrt(-INFINITY + i) = 0 + INFINITY i
- * sqrt(INFINITY ± INFINITY i) = INFINITY + NaN i
- * sqrt(-INFINITY ± INFINITY i) = NaN ± INFINITY i
- * </code>
- * </pre>
- *
- * @return the square root of {@code this}.
- * @since 1.2
- */
- public Complex sqrt() {
- if (isNaN) {
- return NaN;
- }
-
- if (real == 0.0 && imaginary == 0.0) {
- return createComplex(0.0, 0.0);
- }
-
- double t = Math.sqrt((Math.abs(real) + abs()) / 2.0);
- if (real >= 0.0) {
- return createComplex(t, imaginary / (2.0 * t));
- } else {
- return createComplex(Math.abs(imaginary) / (2.0 * t),
- Math.copySign(1d, imaginary) * t);
- }
- }
-
- /**
- * Compute the
- * <a href="http://mathworld.wolfram.com/SquareRoot.html" TARGET="_top">
- * square root</a> of <code>1 - this<sup>2</sup></code> for this complex
- * number.
- * Computes the result directly as
- * {@code sqrt(ONE.subtract(z.multiply(z)))}.
- * <p>
- * Returns {@link Complex#NaN} if either real or imaginary part of the
- * input argument is {@code NaN}.
- * </p>
- * Infinite values in real or imaginary parts of the input may result in
- * infinite or NaN values returned in parts of the result.
- *
- * @return the square root of <code>1 - this<sup>2</sup></code>.
- * @since 1.2
- */
- public Complex sqrt1z() {
- return createComplex(1.0, 0.0).subtract(this.multiply(this)).sqrt();
- }
-
- /**
- * Compute the
- * <a href="http://mathworld.wolfram.com/Tangent.html" TARGET="_top">
- * tangent</a> of this complex number.
- * Implements the formula:
- * <pre>
- * <code>
- * tan(a + bi) = sin(2a)/(cos(2a)+cosh(2b)) + [sinh(2b)/(cos(2a)+cosh(2b))]i
- * </code>
- * </pre>
- * where the (real) functions on the right-hand side are
- * {@link Math#sin}, {@link Math#cos}, {@link Math#cosh} and
- * {@link Math#sinh}.
- * <p>
- * Returns {@link Complex#NaN} if either real or imaginary part of the
- * input argument is {@code NaN}.
- * </p>
- * Infinite (or critical) values in real or imaginary parts of the input may
- * result in infinite or NaN values returned in parts of the result.
- * <pre>
- * Examples:
- * <code>
- * tan(a ± INFINITY i) = 0 ± i
- * tan(±INFINITY + bi) = NaN + NaN i
- * tan(±INFINITY ± INFINITY i) = NaN + NaN i
- * tan(±π/2 + 0 i) = ±INFINITY + NaN i
- * </code>
- * </pre>
- *
- * @return the tangent of {@code this}.
- * @since 1.2
- */
- public Complex tan() {
- if (isNaN || Double.isInfinite(real)) {
- return NaN;
- }
- if (imaginary > 20.0) {
- return createComplex(0.0, 1.0);
- }
- if (imaginary < -20.0) {
- return createComplex(0.0, -1.0);
- }
-
- double real2 = 2.0 * real;
- double imaginary2 = 2.0 * imaginary;
- double d = Math.cos(real2) + Math.cosh(imaginary2);
-
- return createComplex(Math.sin(real2) / d,
- Math.sinh(imaginary2) / d);
- }
-
- /**
- * Compute the
- * <a href="http://mathworld.wolfram.com/HyperbolicTangent.html" TARGET="_top">
- * hyperbolic tangent</a> of this complex number.
- * Implements the formula:
- * <pre>
- * <code>
- * tan(a + bi) = sinh(2a)/(cosh(2a)+cos(2b)) + [sin(2b)/(cosh(2a)+cos(2b))]i
- * </code>
- * </pre>
- * where the (real) functions on the right-hand side are
- * {@link Math#sin}, {@link Math#cos}, {@link Math#cosh} and
- * {@link Math#sinh}.
- * <p>
- * Returns {@link Complex#NaN} if either real or imaginary part of the
- * input argument is {@code NaN}.
- * </p>
- * Infinite values in real or imaginary parts of the input may result in
- * infinite or NaN values returned in parts of the result.
- * <pre>
- * Examples:
- * <code>
- * tanh(a ± INFINITY i) = NaN + NaN i
- * tanh(±INFINITY + bi) = ±1 + 0 i
- * tanh(±INFINITY ± INFINITY i) = NaN + NaN i
- * tanh(0 + (π/2)i) = NaN + INFINITY i
- * </code>
- * </pre>
- *
- * @return the hyperbolic tangent of {@code this}.
- * @since 1.2
- */
- public Complex tanh() {
- if (isNaN || Double.isInfinite(imaginary)) {
- return NaN;
- }
- if (real > 20.0) {
- return createComplex(1.0, 0.0);
- }
- if (real < -20.0) {
- return createComplex(-1.0, 0.0);
- }
- double real2 = 2.0 * real;
- double imaginary2 = 2.0 * imaginary;
- double d = Math.cosh(real2) + Math.cos(imaginary2);
-
- return createComplex(Math.sinh(real2) / d,
- Math.sin(imaginary2) / d);
- }
-
-
-
- /**
- * Compute the argument of this complex number.
- * The argument is the angle phi between the positive real axis and
- * the point representing this number in the complex plane.
- * The value returned is between -PI (not inclusive)
- * and PI (inclusive), with negative values returned for numbers with
- * negative imaginary parts.
- * <p>
- * If either real or imaginary part (or both) is NaN, NaN is returned.
- * Infinite parts are handled as {@code Math.atan2} handles them,
- * essentially treating finite parts as zero in the presence of an
- * infinite coordinate and returning a multiple of pi/4 depending on
- * the signs of the infinite parts.
- * See the javadoc for {@code Math.atan2} for full details.
- *
- * @return the argument of {@code this}.
- */
- public double getArgument() {
- return Math.atan2(getImaginary(), getReal());
- }
-
- /**
- * Computes the n-th roots of this complex number.
- * The nth roots are defined by the formula:
- * <pre>
- * <code>
- * z<sub>k</sub> = abs<sup>1/n</sup> (cos(phi + 2πk/n) + i (sin(phi + 2πk/n))
- * </code>
- * </pre>
- * for <i>{@code k=0, 1, ..., n-1}</i>, where {@code abs} and {@code phi}
- * are respectively the {@link #abs() modulus} and
- * {@link #getArgument() argument} of this complex number.
- * <p>
- * If one or both parts of this complex number is NaN, a list with just
- * one element, {@link #NaN} is returned.
- * if neither part is NaN, but at least one part is infinite, the result
- * is a one-element list containing {@link #INF}.
- *
- * @param n Degree of root.
- * @return a List of all {@code n}-th roots of {@code this}.
- * @since 2.0
- */
- public List<Complex> nthRoot(int n) {
-
- if (n <= 0) {
- throw new RuntimeException("cannot compute nth root for null or negative n: {0}");
- }
-
- final List<Complex> result = new ArrayList<Complex>();
-
- if (isNaN) {
- result.add(NaN);
- return result;
- }
- if (isInfinite()) {
- result.add(INF);
- return result;
- }
-
- // nth root of abs -- faster / more accurate to use a solver here?
- final double nthRootOfAbs = Math.pow(abs(), 1.0 / n);
-
- // Compute nth roots of complex number with k = 0, 1, ... n-1
- final double nthPhi = getArgument() / n;
- final double slice = 2 * Math.PI / n;
- double innerPart = nthPhi;
- for (int k = 0; k < n ; k++) {
- // inner part
- final double realPart = nthRootOfAbs * Math.cos(innerPart);
- final double imaginaryPart = nthRootOfAbs * Math.sin(innerPart);
- result.add(createComplex(realPart, imaginaryPart));
- innerPart += slice;
- }
-
- return result;
- }
-
- /**
- * Create a complex number given the real and imaginary parts.
- *
- * @param realPart Real part.
- * @param imaginaryPart Imaginary part.
- * @return a new complex number instance.
- * @since 1.2
- * @see #valueOf(double, double)
- */
- protected Complex createComplex(double realPart,
- double imaginaryPart) {
- return new Complex(realPart, imaginaryPart);
- }
-
- /**
- * Create a complex number given the real and imaginary parts.
- *
- * @param realPart Real part.
- * @param imaginaryPart Imaginary part.
- * @return a Complex instance.
- */
- public static Complex valueOf(double realPart,
- double imaginaryPart) {
- if (Double.isNaN(realPart) ||
- Double.isNaN(imaginaryPart)) {
- return NaN;
- }
- return new Complex(realPart, imaginaryPart);
- }
-
- /**
- * Create a complex number given only the real part.
- *
- * @param realPart Real part.
- * @return a Complex instance.
- */
- public static Complex valueOf(double realPart) {
- if (Double.isNaN(realPart)) {
- return NaN;
- }
- return new Complex(realPart);
- }
-
- /**
- * Resolve the transient fields in a deserialized Complex Object.
- * Subclasses will need to override {@link #createComplex} to
- * deserialize properly.
- *
- * @return A Complex instance with all fields resolved.
- * @since 2.0
- */
- protected final Object readResolve() {
- return createComplex(real, imaginary);
- }
-
- /** {@inheritDoc} */
- @Override
- public String toString() {
- return "(" + real + ", " + imaginary + ")";
- }
-
- /**
- * Checks that an object is not null.
- *
- * @param o Object to be checked.
- */
- private static void checkNotNull(Object o) {
- if (o == null) {
- throw new RuntimeException("Null Argument to Complex Method");
- }
- }
-
- /**
- * Returns {@code true} if the values are equal according to semantics of
- * {@link Double#equals(Object)}.
- *
- * @param x Value
- * @param y Value
- * @return {@code new Double(x).equals(new Double(y))}
- */
- private static boolean equals(double x, double y) {
- return new Double(x).equals(new Double(y));
- }
-
- /**
- * Returns {@code true} if there is no double value strictly between the
- * arguments or the difference between them is within the range of allowed
- * error (inclusive). Returns {@code false} if either of the arguments
- * is NaN.
- *
- * @param x First value.
- * @param y Second value.
- * @param eps Amount of allowed absolute error.
- * @return {@code true} if the values are two adjacent floating point
- * numbers or they are within range of each other.
- */
- public static boolean equals(double x, double y, double eps) {
- return equals(x, y, 1) || Math.abs(y - x) <= eps;
- }
-
-
- /**
- * Returns {@code true} if there is no double value strictly between the
- * arguments or the relative difference between them is less than or equal
- * to the given tolerance. Returns {@code false} if either of the arguments
- * is NaN.
- *
- * @param x First value.
- * @param y Second value.
- * @param eps Amount of allowed relative error.
- * @return {@code true} if the values are two adjacent floating point
- * numbers or they are within range of each other.
- * @since 3.1
- */
- public static boolean equalsWithRelativeTolerance(double x, double y, double eps) {
- if (equals(x, y, 1)) {
- return true;
- }
-
- final double absoluteMax = Math.max(Math.abs(x), Math.abs(y));
- final double relativeDifference = Math.abs((x - y) / absoluteMax);
-
- return relativeDifference <= eps;
- }
-
- /**
- * Returns an integer hash code representing the given double value.
- *
- * @param value the value to be hashed
- * @return the hash code
- */
- public static int hash(double value) {
- return new Double(value).hashCode();
- }
-
-}
-
[16/31] commons-numbers git commit: Added module for generating the
distribution (archive) files.
Posted by er...@apache.org.
Added module for generating the distribution (archive) files.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/b026db1b
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/b026db1b
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/b026db1b
Branch: refs/heads/master
Commit: b026db1bdb7f8beb663484f4a04a93832ee99f50
Parents: b7dc0cf
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Wed Jan 18 14:47:33 2017 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Wed Jan 18 14:47:33 2017 +0100
----------------------------------------------------------------------
dist-archive/pom.xml | 148 +++++++++++++++++++++++++++++++++
dist-archive/src/assembly/bin.xml | 42 ++++++++++
dist-archive/src/assembly/src.xml | 35 ++++++++
3 files changed, 225 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/b026db1b/dist-archive/pom.xml
----------------------------------------------------------------------
diff --git a/dist-archive/pom.xml b/dist-archive/pom.xml
new file mode 100644
index 0000000..c0096cd
--- /dev/null
+++ b/dist-archive/pom.xml
@@ -0,0 +1,148 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-parent</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+ <name>Apache Commons Numbers (full distribution)</name>
+ <description>This module creates the Apache Commons Numbers distribution.</description>
+
+ <dependencies>
+
+ <!-- Module: Core -->
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-core</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-core</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <classifier>sources</classifier>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-core</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <classifier>javadoc</classifier>
+ </dependency>
+
+ <!-- Module: Complex -->
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-complex</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-complex</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <classifier>sources</classifier>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-complex</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <classifier>javadoc</classifier>
+ </dependency>
+
+ <!-- Module: Quaternion -->
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-quaternion</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-quaternion</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <classifier>sources</classifier>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-quaternion</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <classifier>javadoc</classifier>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+
+ <profile>
+ <id>release</id>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.4</version>
+ <executions>
+ <execution>
+ <id>create-distribution</id>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <configuration>
+ <descriptors>
+ <descriptor>src/assembly/bin.xml</descriptor>
+ <descriptor>src/assembly/src.xml</descriptor>
+ </descriptors>
+ <tarLongFileMode>gnu</tarLongFileMode>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-install-plugin</artifactId>
+ <configuration>
+ <createChecksum>true</createChecksum>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ </profiles>
+
+</project>
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/b026db1b/dist-archive/src/assembly/bin.xml
----------------------------------------------------------------------
diff --git a/dist-archive/src/assembly/bin.xml b/dist-archive/src/assembly/bin.xml
new file mode 100644
index 0000000..7927455
--- /dev/null
+++ b/dist-archive/src/assembly/bin.xml
@@ -0,0 +1,42 @@
+<!--
+ 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.
+-->
+<assembly>
+ <id>bin</id>
+ <formats>
+ <format>tar.gz</format>
+ <format>zip</format>
+ </formats>
+ <baseDirectory>${project.artifactId}-${project.version}</baseDirectory>
+ <includeSiteDirectory>false</includeSiteDirectory>
+ <dependencySets>
+ <dependencySet>
+ <useProjectArtifact>false</useProjectArtifact>
+ <useTransitiveDependencies>false</useTransitiveDependencies>
+ </dependencySet>
+ </dependencySets>
+
+ <fileSets>
+ <fileSet>
+ <directory>${project.basedir}/..</directory>
+ <includes>
+ <include>LICENSE*.txt</include>
+ <include>NOTICE.txt</include>
+ <include>RELEASE-NOTES.txt</include>
+ </includes>
+ </fileSet>
+ </fileSets>
+</assembly>
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/b026db1b/dist-archive/src/assembly/src.xml
----------------------------------------------------------------------
diff --git a/dist-archive/src/assembly/src.xml b/dist-archive/src/assembly/src.xml
new file mode 100644
index 0000000..cf75fed
--- /dev/null
+++ b/dist-archive/src/assembly/src.xml
@@ -0,0 +1,35 @@
+<!--
+ 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.
+-->
+<assembly>
+ <id>src</id>
+ <formats>
+ <format>tar.gz</format>
+ <format>zip</format>
+ </formats>
+ <baseDirectory>${project.artifactId}-${project.version}-src</baseDirectory>
+ <fileSets>
+ <fileSet>
+ <directory>${project.basedir}/..</directory>
+ <excludes>
+ <exclude>${project.build.directory}/**</exclude>
+ <exclude>.*/**</exclude>
+ <exclude>**/${project.build.directory}/**</exclude>
+ <exclude>**/.*/**</exclude>
+ </excludes>
+ </fileSet>
+ </fileSets>
+</assembly>
[09/31] commons-numbers git commit: Multimodule project setup.
Posted by er...@apache.org.
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-quaternion/src/test/java/org/apache/commons/numbers/quaternion/QuaternionTest.java
----------------------------------------------------------------------
diff --git a/commons-numbers-quaternion/src/test/java/org/apache/commons/numbers/quaternion/QuaternionTest.java b/commons-numbers-quaternion/src/test/java/org/apache/commons/numbers/quaternion/QuaternionTest.java
new file mode 100644
index 0000000..b96a0b4
--- /dev/null
+++ b/commons-numbers-quaternion/src/test/java/org/apache/commons/numbers/quaternion/QuaternionTest.java
@@ -0,0 +1,456 @@
+/*
+ * 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.
+ */
+package org.apache.commons.numbers.quaternion;
+
+import java.util.Random;
+
+import org.apache.commons.numbers.quaternion.Quaternion;
+import org.junit.Test;
+import org.junit.Assert;
+
+public class QuaternionTest {
+ /** Epsilon for double comparison. */
+ private static final double EPS = Math.ulp(1d);
+ /** Epsilon for double comparison. */
+ private static final double COMPARISON_EPS = 1e-14;
+
+ @Test
+ public final void testAccessors1() {
+ final double q0 = 2;
+ final double q1 = 5.4;
+ final double q2 = 17;
+ final double q3 = 0.0005;
+ final Quaternion q = new Quaternion(q0, q1, q2, q3);
+
+ Assert.assertEquals(q0, q.getQ0(), 0);
+ Assert.assertEquals(q1, q.getQ1(), 0);
+ Assert.assertEquals(q2, q.getQ2(), 0);
+ Assert.assertEquals(q3, q.getQ3(), 0);
+ }
+
+ @Test
+ public final void testAccessors2() {
+ final double q0 = 2;
+ final double q1 = 5.4;
+ final double q2 = 17;
+ final double q3 = 0.0005;
+ final Quaternion q = new Quaternion(q0, q1, q2, q3);
+
+ final double sP = q.getScalarPart();
+ final double[] vP = q.getVectorPart();
+
+ Assert.assertEquals(q0, sP, 0);
+ Assert.assertEquals(q1, vP[0], 0);
+ Assert.assertEquals(q2, vP[1], 0);
+ Assert.assertEquals(q3, vP[2], 0);
+ }
+
+ @Test
+ public final void testAccessors3() {
+ final double q0 = 2;
+ final double q1 = 5.4;
+ final double q2 = 17;
+ final double q3 = 0.0005;
+ final Quaternion q = new Quaternion(q0, new double[] { q1, q2, q3 });
+
+ final double sP = q.getScalarPart();
+ final double[] vP = q.getVectorPart();
+
+ Assert.assertEquals(q0, sP, 0);
+ Assert.assertEquals(q1, vP[0], 0);
+ Assert.assertEquals(q2, vP[1], 0);
+ Assert.assertEquals(q3, vP[2], 0);
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testWrongDimension() {
+ new Quaternion(new double[] { 1, 2 });
+ }
+
+ @Test
+ public final void testConjugate() {
+ final double q0 = 2;
+ final double q1 = 5.4;
+ final double q2 = 17;
+ final double q3 = 0.0005;
+ final Quaternion q = new Quaternion(q0, q1, q2, q3);
+
+ final Quaternion qConjugate = q.getConjugate();
+
+ Assert.assertEquals(q0, qConjugate.getQ0(), 0);
+ Assert.assertEquals(-q1, qConjugate.getQ1(), 0);
+ Assert.assertEquals(-q2, qConjugate.getQ2(), 0);
+ Assert.assertEquals(-q3, qConjugate.getQ3(), 0);
+ }
+
+ /* TODO remove dependency on Vector3D
+ @Test
+ public final void testProductQuaternionQuaternion() {
+
+ // Case : analytic test case
+
+ final Quaternion qA = new Quaternion(1, 0.5, -3, 4);
+ final Quaternion qB = new Quaternion(6, 2, 1, -9);
+ final Quaternion qResult = Quaternion.multiply(qA, qB);
+
+ Assert.assertEquals(44, qResult.getQ0(), EPS);
+ Assert.assertEquals(28, qResult.getQ1(), EPS);
+ Assert.assertEquals(-4.5, qResult.getQ2(), EPS);
+ Assert.assertEquals(21.5, qResult.getQ3(), EPS);
+
+ // comparison with the result given by the formula :
+ // qResult = (scalarA * scalarB - vectorA . vectorB) + (scalarA * vectorB + scalarB * vectorA + vectorA ^
+ // vectorB)
+
+ final Vector3D vectorA = new Vector3D(qA.getVectorPart());
+ final Vector3D vectorB = new Vector3D(qB.getVectorPart());
+ final Vector3D vectorResult = new Vector3D(qResult.getVectorPart());
+
+ final double scalarPartRef = qA.getScalarPart() * qB.getScalarPart() - Vector3D.dotProduct(vectorA, vectorB);
+
+ Assert.assertEquals(scalarPartRef, qResult.getScalarPart(), EPS);
+
+ final Vector3D vectorPartRef = ((vectorA.scalarMultiply(qB.getScalarPart())).add(vectorB.scalarMultiply(qA
+ .getScalarPart()))).add(Vector3D.crossProduct(vectorA, vectorB));
+ final double norm = (vectorResult.subtract(vectorPartRef)).getNorm();
+
+ Assert.assertEquals(0, norm, EPS);
+
+ // Conjugate of the product of two quaternions and product of their conjugates :
+ // Conj(qA * qB) = Conj(qB) * Conj(qA)
+
+ final Quaternion conjugateOfProduct = qB.getConjugate().multiply(qA.getConjugate());
+ final Quaternion productOfConjugate = (qA.multiply(qB)).getConjugate();
+
+ Assert.assertEquals(conjugateOfProduct.getQ0(), productOfConjugate.getQ0(), EPS);
+ Assert.assertEquals(conjugateOfProduct.getQ1(), productOfConjugate.getQ1(), EPS);
+ Assert.assertEquals(conjugateOfProduct.getQ2(), productOfConjugate.getQ2(), EPS);
+ Assert.assertEquals(conjugateOfProduct.getQ3(), productOfConjugate.getQ3(), EPS);
+ }
+ */
+ /* TODO remove dependency on Vector3D
+ @Test
+ public final void testProductQuaternionVector() {
+
+ // Case : Product between a vector and a quaternion : QxV
+
+ final Quaternion quaternion = new Quaternion(4, 7, -1, 2);
+ final double[] vector = {2.0, 1.0, 3.0};
+ final Quaternion qResultQxV = Quaternion.multiply(quaternion, new Quaternion(vector));
+
+ Assert.assertEquals(-19, qResultQxV.getQ0(), EPS);
+ Assert.assertEquals(3, qResultQxV.getQ1(), EPS);
+ Assert.assertEquals(-13, qResultQxV.getQ2(), EPS);
+ Assert.assertEquals(21, qResultQxV.getQ3(), EPS);
+
+ // comparison with the result given by the formula :
+ // qResult = (- vectorQ . vector) + (scalarQ * vector + vectorQ ^ vector)
+
+ final double[] vectorQ = quaternion.getVectorPart();
+ final double[] vectorResultQxV = qResultQxV.getVectorPart();
+
+ final double scalarPartRefQxV = -Vector3D.dotProduct(new Vector3D(vectorQ), new Vector3D(vector));
+ Assert.assertEquals(scalarPartRefQxV, qResultQxV.getScalarPart(), EPS);
+
+ final Vector3D vectorPartRefQxV = (new Vector3D(vector).scalarMultiply(quaternion.getScalarPart())).add(Vector3D
+ .crossProduct(new Vector3D(vectorQ), new Vector3D(vector)));
+ final double normQxV = (new Vector3D(vectorResultQxV).subtract(vectorPartRefQxV)).getNorm();
+ Assert.assertEquals(0, normQxV, EPS);
+
+ // Case : Product between a vector and a quaternion : VxQ
+
+ final Quaternion qResultVxQ = Quaternion.multiply(new Quaternion(vector), quaternion);
+
+ Assert.assertEquals(-19, qResultVxQ.getQ0(), EPS);
+ Assert.assertEquals(13, qResultVxQ.getQ1(), EPS);
+ Assert.assertEquals(21, qResultVxQ.getQ2(), EPS);
+ Assert.assertEquals(3, qResultVxQ.getQ3(), EPS);
+
+ final double[] vectorResultVxQ = qResultVxQ.getVectorPart();
+
+ // comparison with the result given by the formula :
+ // qResult = (- vector . vectorQ) + (scalarQ * vector + vector ^ vectorQ)
+
+ final double scalarPartRefVxQ = -Vector3D.dotProduct(new Vector3D(vectorQ), new Vector3D(vector));
+ Assert.assertEquals(scalarPartRefVxQ, qResultVxQ.getScalarPart(), EPS);
+
+ final Vector3D vectorPartRefVxQ = (new Vector3D(vector).scalarMultiply(quaternion.getScalarPart())).add(Vector3D
+ .crossProduct(new Vector3D(vector), new Vector3D(vectorQ)));
+ final double normVxQ = (new Vector3D(vectorResultVxQ).subtract(vectorPartRefVxQ)).getNorm();
+ Assert.assertEquals(0, normVxQ, EPS);
+ }
+ */
+ @Test
+ public final void testDotProductQuaternionQuaternion() {
+ // expected output
+ final double expected = -6.;
+ // inputs
+ final Quaternion q1 = new Quaternion(1, 2, 2, 1);
+ final Quaternion q2 = new Quaternion(3, -2, -1, -3);
+
+ final double actual1 = Quaternion.dotProduct(q1, q2);
+ final double actual2 = q1.dotProduct(q2);
+
+ Assert.assertEquals(expected, actual1, EPS);
+ Assert.assertEquals(expected, actual2, EPS);
+ }
+
+ @Test
+ public final void testScalarMultiplyDouble() {
+ // expected outputs
+ final double w = 1.6;
+ final double x = -4.8;
+ final double y = 11.20;
+ final double z = 2.56;
+ // inputs
+ final Quaternion q1 = new Quaternion(0.5, -1.5, 3.5, 0.8);
+ final double a = 3.2;
+
+ final Quaternion q = q1.multiply(a);
+
+ Assert.assertEquals(w, q.getQ0(), COMPARISON_EPS);
+ Assert.assertEquals(x, q.getQ1(), COMPARISON_EPS);
+ Assert.assertEquals(y, q.getQ2(), COMPARISON_EPS);
+ Assert.assertEquals(z, q.getQ3(), COMPARISON_EPS);
+ }
+
+ @Test
+ public final void testAddQuaternionQuaternion() {
+ // expected outputs
+ final double w = 4;
+ final double x = -1;
+ final double y = 2;
+ final double z = -4;
+ // inputs
+ final Quaternion q1 = new Quaternion(1., 2., -2., -1.);
+ final Quaternion q2 = new Quaternion(3., -3., 4., -3.);
+
+ final Quaternion qa = Quaternion.add(q1, q2);
+ final Quaternion qb = q1.add(q2);
+
+ Assert.assertEquals(w, qa.getQ0(), EPS);
+ Assert.assertEquals(x, qa.getQ1(), EPS);
+ Assert.assertEquals(y, qa.getQ2(), EPS);
+ Assert.assertEquals(z, qa.getQ3(), EPS);
+
+ Assert.assertEquals(w, qb.getQ0(), EPS);
+ Assert.assertEquals(x, qb.getQ1(), EPS);
+ Assert.assertEquals(y, qb.getQ2(), EPS);
+ Assert.assertEquals(z, qb.getQ3(), EPS);
+ }
+
+ @Test
+ public final void testSubtractQuaternionQuaternion() {
+ // expected outputs
+ final double w = -2.;
+ final double x = 5.;
+ final double y = -6.;
+ final double z = 2.;
+ // inputs
+ final Quaternion q1 = new Quaternion(1., 2., -2., -1.);
+ final Quaternion q2 = new Quaternion(3., -3., 4., -3.);
+
+ final Quaternion qa = Quaternion.subtract(q1, q2);
+ final Quaternion qb = q1.subtract(q2);
+
+ Assert.assertEquals(w, qa.getQ0(), EPS);
+ Assert.assertEquals(x, qa.getQ1(), EPS);
+ Assert.assertEquals(y, qa.getQ2(), EPS);
+ Assert.assertEquals(z, qa.getQ3(), EPS);
+
+ Assert.assertEquals(w, qb.getQ0(), EPS);
+ Assert.assertEquals(x, qb.getQ1(), EPS);
+ Assert.assertEquals(y, qb.getQ2(), EPS);
+ Assert.assertEquals(z, qb.getQ3(), EPS);
+}
+
+ @Test
+ public final void testNorm() {
+
+ final double q0 = 2;
+ final double q1 = 1;
+ final double q2 = -4;
+ final double q3 = 3;
+ final Quaternion q = new Quaternion(q0, q1, q2, q3);
+
+ final double norm = q.getNorm();
+
+ Assert.assertEquals(Math.sqrt(30), norm, 0);
+
+ final double normSquareRef = Quaternion.multiply(q, q.getConjugate()).getScalarPart();
+ Assert.assertEquals(Math.sqrt(normSquareRef), norm, 0);
+ }
+
+ @Test
+ public final void testNormalize() {
+
+ final Quaternion q = new Quaternion(2, 1, -4, -2);
+
+ final Quaternion versor = q.normalize();
+
+ Assert.assertEquals(2.0 / 5.0, versor.getQ0(), 0);
+ Assert.assertEquals(1.0 / 5.0, versor.getQ1(), 0);
+ Assert.assertEquals(-4.0 / 5.0, versor.getQ2(), 0);
+ Assert.assertEquals(-2.0 / 5.0, versor.getQ3(), 0);
+
+ Assert.assertEquals(1, versor.getNorm(), 0);
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public final void testNormalizeFail() {
+ final Quaternion zeroQ = new Quaternion(0, 0, 0, 0);
+ zeroQ.normalize();
+ }
+
+ @Test
+ public final void testObjectEquals() {
+ final double one = 1;
+ final Quaternion q1 = new Quaternion(one, one, one, one);
+ Assert.assertTrue(q1.equals(q1));
+
+ final Quaternion q2 = new Quaternion(one, one, one, one);
+ Assert.assertTrue(q2.equals(q1));
+
+ final Quaternion q3 = new Quaternion(one, Math.nextUp(one), one, one);
+ Assert.assertFalse(q3.equals(q1));
+ }
+
+ @Test
+ public final void testQuaternionEquals() {
+ final double inc = 1e-5;
+ final Quaternion q1 = new Quaternion(2, 1, -4, -2);
+ final Quaternion q2 = new Quaternion(q1.getQ0() + inc, q1.getQ1(), q1.getQ2(), q1.getQ3());
+ final Quaternion q3 = new Quaternion(q1.getQ0(), q1.getQ1() + inc, q1.getQ2(), q1.getQ3());
+ final Quaternion q4 = new Quaternion(q1.getQ0(), q1.getQ1(), q1.getQ2() + inc, q1.getQ3());
+ final Quaternion q5 = new Quaternion(q1.getQ0(), q1.getQ1(), q1.getQ2(), q1.getQ3() + inc);
+
+ Assert.assertFalse(q1.equals(q2, 0.9 * inc));
+ Assert.assertFalse(q1.equals(q3, 0.9 * inc));
+ Assert.assertFalse(q1.equals(q4, 0.9 * inc));
+ Assert.assertFalse(q1.equals(q5, 0.9 * inc));
+
+ Assert.assertTrue(q1.equals(q2, 1.1 * inc));
+ Assert.assertTrue(q1.equals(q3, 1.1 * inc));
+ Assert.assertTrue(q1.equals(q4, 1.1 * inc));
+ Assert.assertTrue(q1.equals(q5, 1.1 * inc));
+ }
+
+ @Test
+ public final void testQuaternionEquals2() {
+ final Quaternion q1 = new Quaternion(1, 4, 2, 3);
+ final double gap = 1e-5;
+ final Quaternion q2 = new Quaternion(1 + gap, 4 + gap, 2 + gap, 3 + gap);
+
+ Assert.assertTrue(q1.equals(q2, 10 * gap));
+ Assert.assertFalse(q1.equals(q2, gap));
+ Assert.assertFalse(q1.equals(q2, gap / 10));
+ }
+
+ @Test
+ public final void testIsUnitQuaternion() {
+ final Random r = new Random(48);
+ final int numberOfTrials = 1000;
+ for (int i = 0; i < numberOfTrials; i++) {
+ final Quaternion q1 = new Quaternion(r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble());
+ final Quaternion q2 = q1.normalize();
+ Assert.assertTrue(q2.isUnitQuaternion(COMPARISON_EPS));
+ }
+
+ final Quaternion q = new Quaternion(1, 1, 1, 1);
+ Assert.assertFalse(q.isUnitQuaternion(COMPARISON_EPS));
+ }
+
+ @Test
+ public final void testIsPureQuaternion() {
+ final Quaternion q1 = new Quaternion(0, 5, 4, 8);
+ Assert.assertTrue(q1.isPureQuaternion(EPS));
+
+ final Quaternion q2 = new Quaternion(0 - EPS, 5, 4, 8);
+ Assert.assertTrue(q2.isPureQuaternion(EPS));
+
+ final Quaternion q3 = new Quaternion(0 - 1.1 * EPS, 5, 4, 8);
+ Assert.assertFalse(q3.isPureQuaternion(EPS));
+
+ final Random r = new Random(48);
+ final double[] v = {r.nextDouble(), r.nextDouble(), r.nextDouble()};
+ final Quaternion q4 = new Quaternion(v);
+ Assert.assertTrue(q4.isPureQuaternion(0));
+
+ final Quaternion q5 = new Quaternion(0, v);
+ Assert.assertTrue(q5.isPureQuaternion(0));
+ }
+
+ /*
+ @Test
+ public final void testPolarForm() {
+ final Random r = new Random(48);
+ final int numberOfTrials = 1000;
+ for (int i = 0; i < numberOfTrials; i++) {
+ final Quaternion q = new Quaternion(2 * (r.nextDouble() - 0.5), 2 * (r.nextDouble() - 0.5),
+ 2 * (r.nextDouble() - 0.5), 2 * (r.nextDouble() - 0.5));
+ final Quaternion qP = q.getPositivePolarForm();
+
+ Assert.assertTrue(qP.isUnitQuaternion(COMPARISON_EPS));
+ Assert.assertTrue(qP.getQ0() >= 0);
+
+ final Rotation rot = new Rotation(q.getQ0(), q.getQ1(), q.getQ2(), q.getQ3(), true);
+ final Rotation rotP = new Rotation(qP.getQ0(), qP.getQ1(), qP.getQ2(), qP.getQ3(), true);
+
+ Assert.assertEquals(rot.getAngle(), rotP.getAngle(), COMPARISON_EPS);
+ Assert.assertEquals(rot.getAxis(RotationConvention.VECTOR_OPERATOR).getX(),
+ rot.getAxis(RotationConvention.VECTOR_OPERATOR).getX(),
+ COMPARISON_EPS);
+ Assert.assertEquals(rot.getAxis(RotationConvention.VECTOR_OPERATOR).getY(),
+ rot.getAxis(RotationConvention.VECTOR_OPERATOR).getY(),
+ COMPARISON_EPS);
+ Assert.assertEquals(rot.getAxis(RotationConvention.VECTOR_OPERATOR).getZ(),
+ rot.getAxis(RotationConvention.VECTOR_OPERATOR).getZ(),
+ COMPARISON_EPS);
+ }
+ }
+*/
+ @Test
+ public final void testGetInverse() {
+ final Quaternion q = new Quaternion(1.5, 4, 2, -2.5);
+
+ final Quaternion inverseQ = q.getInverse();
+ Assert.assertEquals(1.5 / 28.5, inverseQ.getQ0(), 0);
+ Assert.assertEquals(-4.0 / 28.5, inverseQ.getQ1(), 0);
+ Assert.assertEquals(-2.0 / 28.5, inverseQ.getQ2(), 0);
+ Assert.assertEquals(2.5 / 28.5, inverseQ.getQ3(), 0);
+
+ final Quaternion product = Quaternion.multiply(inverseQ, q);
+ Assert.assertEquals(1, product.getQ0(), EPS);
+ Assert.assertEquals(0, product.getQ1(), EPS);
+ Assert.assertEquals(0, product.getQ2(), EPS);
+ Assert.assertEquals(0, product.getQ3(), EPS);
+
+ final Quaternion qNul = new Quaternion(0, 0, 0, 0);
+ try {
+ final Quaternion inverseQNul = qNul.getInverse();
+ Assert.fail("expecting ZeroException but got : " + inverseQNul);
+ } catch (IllegalStateException ex) {
+ // expected
+ }
+ }
+
+ @Test
+ public final void testToString() {
+ final Quaternion q = new Quaternion(1, 2, 3, 4);
+ Assert.assertTrue(q.toString().equals("[1.0 2.0 3.0 4.0]"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index dbffb77..b1e4336 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,4 +1,4 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@@ -15,39 +15,40 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v0_0_1.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.apache.commons</groupId>
<artifactId>commons-parent</artifactId>
<version>41</version>
</parent>
+
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.commons</groupId>
- <artifactId>commons-complex</artifactId>
+ <artifactId>commons-numbers-parent</artifactId>
+ <packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
- <name>Apache Commons Complex</name>
-
- <inceptionYear>2016</inceptionYear>
- <description>The Apache Commons Complex project provides self-contained components addressing the most common practical problems involving Java computing with complex numbers.</description>
+ <name>Apache Commons Numbers</name>
- <url>http://commons.apache.org/proper/commons-complex/</url>
+ <inceptionYear>2017</inceptionYear>
+ <description>The Apache Commons Numbers project provides number types and utilities.</description>
+ <url>http://commons.apache.org/proper/commons-numbers/</url>
<issueManagement>
<system>jira</system>
- <url>http://issues.apache.org/jira/browse/COMPLEX</url>
+ <url>http://issues.apache.org/jira/browse/NUMBERS</url>
</issueManagement>
<scm>
- <connection>scm:git:http://git-wip-us.apache.org/repos/asf/commons-complex.git</connection>
- <developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/commons-complex.git</developerConnection>
- <url>https://git-wip-us.apache.org/repos/asf?p=commons-complex.git</url>
+ <connection>scm:git:http://git-wip-us.apache.org/repos/asf/commons-numbers.git</connection>
+ <developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/commons-numbers.git</developerConnection>
+ <url>https://git-wip-us.apache.org/repos/asf?p=commons-numbers.git</url>
</scm>
<distributionManagement>
<site>
<id>apache.website</id>
<name>Apache Commons Site</name>
- <url>scm:svn:https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-complex/</url>
+ <url>scm:svn:https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-numbers/</url>
</site>
</distributionManagement>
@@ -57,48 +58,54 @@
<id>ericbarnhill</id>
<email>ericbarnhill at apache dot org</email>
</developer>
+ <developer>
+ <name>Gilles Sadowski</name>
+ <id>erans</id>
+ <email>erans at apache dot org</email>
+ </developer>
</developers>
+ <contributors>
+ <contributor>
+ <name>Raymond DeCampo</name>
+ </contributor>
+ </contributors>
+
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>4.11</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-math3</artifactId>
- <version>3.6.1</version>
+ <version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
- <!-- Do not change: "math" is the name of the component even if the
+ <!-- Do not change: "numbers" is the name of the component even if the
name of the base package evolves with major release numbers
(see "commons.osgi.symbolicName", below). -->
- <!-- TODO: when releasing 4.0, the properties below need to be updated, and
- the 3.x release artifacts need to be put int commons.release.3 -->
- <commons.componentid>complex</commons.componentid>
+ <commons.componentid>numbers</commons.componentid>
<!-- This value must reflect the current name of the base package. -->
- <commons.osgi.symbolicName>org.apache.commons.complex</commons.osgi.symbolicName>
+ <commons.osgi.symbolicName>org.apache.commons.numbers</commons.osgi.symbolicName>
+ <!-- OSGi -->
+ <commons.osgi.export>org.apache.commons.numbers</commons.osgi.export>
<!-- do not use snapshot suffix here -->
<commons.release.version>1.0</commons.release.version>
- <commons.release.desc>(requires Java 1.5+)</commons.release.desc>
+ <commons.release.desc>(requires Java 7+)</commons.release.desc>
<!-- <commons.rc.version>RC1</commons.rc.version> -->
<commons.binary.suffix>-bin</commons.binary.suffix>
- <commons.jira.id>COMPLEX</commons.jira.id>
+ <commons.jira.id>NUMBERS</commons.jira.id>
<commons.jira.pid>12310485</commons.jira.pid>
<commons.encoding>UTF-8</commons.encoding>
- <maven.compiler.source>1.7</maven.compiler.source>
- <maven.compiler.target>1.7</maven.compiler.target>
- <math.pmd.version>3.5</math.pmd.version>
- <math.findbugs.version>3.0.2</math.findbugs.version>
- <math.checkstyle.version>2.17</math.checkstyle.version>
- <math.clirr.version>2.7</math.clirr.version>
+ <maven.compiler.source>1.6</maven.compiler.source>
+ <maven.compiler.target>1.6</maven.compiler.target>
+ <numbers.pmd.version>3.5</numbers.pmd.version>
+ <numbers.findbugs.version>3.0.2</numbers.findbugs.version>
+ <numbers.checkstyle.version>2.17</numbers.checkstyle.version>
+ <numbers.clirr.version>2.7</numbers.clirr.version>
+ <!-- Workaround to avoid duplicating config files. -->
+ <numbers.parent.dir>${basedir}</numbers.parent.dir>
<!-- Temporary fix to support Java 8 -->
<commons.jacoco.version>0.7.5.201505241946</commons.jacoco.version>
@@ -110,70 +117,61 @@
<commons.jacoco.lineRatio>0.85</commons.jacoco.lineRatio>
<commons.jacoco.haltOnFailure>false</commons.jacoco.haltOnFailure>
- <commons.site.path>complex</commons.site.path>
- <commons.scmPubUrl>https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-complex</commons.scmPubUrl>
+ <commons.site.path>numbers</commons.site.path>
+ <commons.scmPubUrl>https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-numbers</commons.scmPubUrl>
<commons.scmPubCheckoutDirectory>site-content</commons.scmPubCheckoutDirectory>
<!-- Temporary fix to replace svn-based build number with git-based build number -->
<buildnumber.skip>true</buildnumber.skip>
- <math.jgit.buildnumber.version>1.2.10</math.jgit.buildnumber.version>
+ <numbers.jgit.buildnumber.version>1.2.10</numbers.jgit.buildnumber.version>
<implementation.build>${git.revision}; ${maven.build.timestamp}</implementation.build>
<!-- Override default buildNumber timestamp format, needed for coveralls plugin -->
<maven.buildNumber.timestampFormat>{0,date,yyyy-MM-dd HH:mm:ssZ}</maven.buildNumber.timestampFormat>
+
+ <!--
+ Override so that "mvn commons:download-page" will generates a web page
+ referring to the files created by the "dist-archive" module.
+ Temporary workaround?
+ -->
+ <commons.release.name>commons-numbers-${project.version}</commons.release.name>
</properties>
<build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <includes>
- <include>**/*Test.java</include>
- <include>**/*TestBinary.java</include>
- <include>**/*TestPermutations.java</include>
- </includes>
- <excludes>
- <exclude>**/*AbstractTest.java</exclude>
- </excludes>
- </configuration>
- </plugin>
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <configuration>
- <descriptors>
- <descriptor>src/main/assembly/src.xml</descriptor>
- <descriptor>src/main/assembly/bin.xml</descriptor>
- </descriptors>
- <!-- There are a lot of long file names. Suppress the warnings. -->
- <tarLongFileMode>gnu</tarLongFileMode>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>clirr-maven-plugin</artifactId>
- <version>${math.clirr.version}</version>
- <configuration>
- <minSeverity>${minSeverity}</minSeverity>
- <ignoredDifferencesFile>${basedir}/clirr-ignored.xml</ignoredDifferencesFile>
- </configuration>
- <executions>
- <execution>
- <goals>
- </goals>
- </execution>
- </executions>
- </plugin>
+ <plugins>
<plugin>
- <artifactId>maven-pmd-plugin</artifactId>
- <version>${math.pmd.version}</version>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.5.1</version>
<configuration>
- <targetJdk>${maven.compiler.target}</targetJdk>
- <skipEmptyReport>false</skipEmptyReport>
- <rulesets>
- <ruleset>${basedir}/pmd-ruleset.xml</ruleset>
- </rulesets>
+ <compilerArgs>
+ <!-- <arg>-verbose</arg> -->
+ <arg>-Xlint:all,-options,-path</arg>
+ </compilerArgs>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <includes>
+ <include>**/*Test.java</include>
+ </includes>
+ <excludes>
+ <exclude>**/*AbstractTest.java</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <descriptors>
+ <descriptor>src/assembly/src.xml</descriptor>
+ <descriptor>src/assembly/bin.xml</descriptor>
+ </descriptors>
+ <!-- There are a lot of long file names. Suppress the warnings. -->
+ <tarLongFileMode>gnu</tarLongFileMode>
</configuration>
</plugin>
<plugin>
@@ -187,93 +185,98 @@
</plugin>
<plugin>
- <artifactId>maven-antrun-plugin</artifactId>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
<executions>
<execution>
- <phase>package</phase>
- <configuration>
- <target>
- <jar destfile="${project.build.directory}/${project.artifactId}-${project.version}-tools.jar">
- <metainf dir="${basedir}" includes="NOTICE.txt,LICENSE.txt" />
- <manifest>
- <attribute name="Specification-Title" value="${project.name} Tools" />
- <attribute name="Implementation-Title" value="${project.name} Tools" />
- <attribute name="Implementation-Vendor" value="${project.organization.name}" />
- <attribute name="Implementation-Version" value="${project.version}" />
- <attribute name="Implementation-Vendor-Id" value="org.apache" />
- <attribute name="Implementation-Build" value="${implementation.build}"/>
- <attribute name="X-Compile-Source-JDK" value="${maven.compiler.source}" />
- <attribute name="X-Compile-Target-JDK" value="${maven.compiler.target}" />
- </manifest>
- <fileset dir="${project.build.directory}/test-classes"
- includes="org/apache/commons/complex/PerfTestUtils*" />
- </jar>
- </target>
- </configuration>
+ <id>validate</id>
+ <phase>validate</phase>
<goals>
- <goal>run</goal>
+ <goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
- <!-- Attaches the commons-math4 tools JAR to the Maven lifecycle
- to ensure they will be signed and deployed as normal -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <version>1.7</version>
- <executions>
- <execution>
- <id>attach-artifacts</id>
- <phase>package</phase>
- <goals>
- <goal>attach-artifact</goal>
- </goals>
- <configuration>
- <artifacts>
- <artifact>
- <file>${project.build.directory}/${project.artifactId}-${project.version}-tools.jar</file>
- <type>jar</type>
- <classifier>tools</classifier>
- </artifact>
- </artifacts>
- </configuration>
- </execution>
- </executions>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <version>${numbers.findbugs.version}</version>
</plugin>
- <!-- MathJax -->
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <version>${commons.rat.version}</version>
<configuration>
- <additionalparam>-header '<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>'</additionalparam>
+ <!--
+ Needed for command-line access, e.g mvn apache-rat:rat and mvn apache-rat:check
+ Below should agree with config in <reporting> section, so the site
+ gets consistent output.
+ -->
+ <excludes combine.children="append">
+ <!-- version 0.8 of apache-rat-plugin does not exclude properly
+ some default development tools files (see RAT-126) -->
+ <exclude>.ekstazi/**</exclude>
+ <exclude>src/site/resources/txt/userguide/stress/dh/**</exclude>
+ <exclude>src/site/resources/txt/userguide/stress/tu/**</exclude>
+ <exclude>dist-archive/**</exclude>
+ </excludes>
</configuration>
</plugin>
</plugins>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>${numbers.checkstyle.version}</version>
+ <configuration>
+ <includeTestSourceDirectory>false</includeTestSourceDirectory>
+ <configLocation>${numbers.parent.dir}/src/main/resources/checkstyle/checkstyle.xml</configLocation>
+ <headerLocation>${numbers.parent.dir}/src/main/resources/checkstyle/license-header.txt</headerLocation>
+ <logViolationsToConsole>false</logViolationsToConsole>
+ <failOnViolation>false</failOnViolation>
+ <resourceExcludes>NOTICE.txt,LICENSE.txt</resourceExcludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
</build>
<reporting>
<plugins>
<plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <version>${commons.rat.version}</version>
+ <configuration>
+ <!-- Should agree with apache-rat-plugin config under <build> -->
+ <excludes combine.children="append">
+ <!-- version 0.8 of apache-rat-plugin does not exclude properly
+ some default development tools files (see RAT-126) -->
+ <exclude>.ekstazi/**</exclude>
+ <exclude>dist-archive/**</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-changes-plugin</artifactId>
<version>${commons.changes.version}</version>
<configuration>
- <issueLinkTemplatePerSystem>
- <default>%URL%/%ISSUE%</default>
- </issueLinkTemplatePerSystem>
- <!-- Add sample JIRA report - 'mvn changes:jira-report' or 'mvn site' -->
- <onlyCurrentVersion>false</onlyCurrentVersion>
- <columnNames>Fix Version,Key,Summary,Type,Resolution,Status</columnNames>
- <!-- Sort cols have to be reversed in JIRA 4 -->
- <sortColumnNames>Key DESC,Type,Fix Version DESC</sortColumnNames>
+ <xmlPath>${basedir}/src/changes/changes.xml</xmlPath>
+ <columnNames>Fix Version,Key,Component,Summary,Type,Resolution,Status</columnNames>
+ <!-- Sort cols in natural order when using JQL for JIRA 5.1 -->
+ <sortColumnNames>Fix Version DESC,Type,Key DESC</sortColumnNames>
<resolutionIds>Fixed</resolutionIds>
<statusIds>Resolved,Closed</statusIds>
<!-- Don't include sub-task -->
<typeIds>Bug,New Feature,Task,Improvement,Wish,Test</typeIds>
- <fixVersionIds>${commons.release.version}</fixVersionIds>
- <!-- The default is 100 -->
- <maxEntries>100</maxEntries>
+ <!-- For JIRA >= 5.1 -->
+ <useJql>true</useJql>
+ <onlyCurrentVersion>${commons.changes.onlyCurrentVersion}</onlyCurrentVersion>
+ <maxEntries>${commons.changes.maxEntries}</maxEntries>
+ <runOnlyAtExecutionRoot>${commons.changes.runOnlyAtExecutionRoot}</runOnlyAtExecutionRoot>
</configuration>
<reportSets>
<reportSet>
@@ -285,48 +288,24 @@
</reportSets>
</plugin>
<plugin>
- <groupId>org.apache.rat</groupId>
- <artifactId>apache-rat-plugin</artifactId>
- <version>${commons.rat.version}</version>
- <configuration>
- <excludes>
-
- <!-- MANIFEST files cannot have any comments, so we can't put license header -->
- <exclude>src/test/maxima/special/RealFunctionValidation/MANIFEST.txt</exclude>
-
- <!-- text file explaining reference to a public domain image -->
- <exclude>src/userguide/resources/references.txt</exclude>
-
- <!-- version 0.8 of apache-rat-plugin does not exclude properly
- some default development tools files (see RAT-126) -->
- <exclude>bin/**</exclude>
- <exclude>.gitignore</exclude>
- <exclude>.git/**</exclude>
- <exclude>.checkstyle</exclude>
- <exclude>.ekstazi/**</exclude>
-
- </excludes>
- </configuration>
- </plugin>
- <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
- <version>${complex.findbugs.version}</version>
+ <version>${numbers.findbugs.version}</version>
<configuration>
<threshold>Normal</threshold>
<effort>Default</effort>
- <excludeFilterFile>${basedir}/findbugs-exclude-filter.xml</excludeFilterFile>
- </configuration>
+ <excludeFilterFile>${numbers.parent.dir}/src/main/resources/findbugs/findbugs-exclude-filter.xml</excludeFilterFile>
+ </configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
- <version>${math.checkstyle.version}</version>
+ <version>${numbers.checkstyle.version}</version>
<configuration>
- <configLocation>${basedir}/checkstyle.xml</configLocation>
+ <configLocation>${numbers.parent.dir}/src/main/resources/checkstyle/checkstyle.xml</configLocation>
+ <headerLocation>${numbers.parent.dir}/src/main/resources/checkstyle/license-header.txt</headerLocation>
<enableRulesSummary>false</enableRulesSummary>
<includeResources>false</includeResources>
- <headerLocation>${basedir}/license-header.txt</headerLocation>
</configuration>
<reportSets>
<reportSet>
@@ -339,31 +318,27 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>clirr-maven-plugin</artifactId>
- <version>${math.clirr.version}</version>
+ <version>${numbers.clirr.version}</version>
<configuration>
<minSeverity>${minSeverity}</minSeverity>
- <ignoredDifferencesFile>${basedir}/clirr-ignored.xml</ignoredDifferencesFile>
- </configuration>
+ <ignoredDifferencesFile>${numbers.parent.dir}/src/main/resources/clirr/clirr-ignored.xml</ignoredDifferencesFile>
+ </configuration>
</plugin>
<plugin>
<artifactId>maven-pmd-plugin</artifactId>
- <version>${math.pmd.version}</version>
+ <version>${numbers.pmd.version}</version>
<configuration>
<targetJdk>${maven.compiler.target}</targetJdk>
<skipEmptyReport>false</skipEmptyReport>
<rulesets>
- <ruleset>${basedir}/pmd-ruleset.xml</ruleset>
+ <ruleset>${numbers.parent.dir}/src/main/resources/pmd/pmd-ruleset.xml</ruleset>
</rulesets>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>pmd</report>
- <!-- As of 3.x series, the cpd report sees (correctly) numerous duplications -->
- <!-- This is due to packages being renamed, and the old name still needs to be -->
- <!-- available for compatibility. They will be removed in 4.0 -->
- <!-- So we temporarily disable the CPD report -->
- <!-- <report>cpd</report> -->
+ <report>cpd</report>
</reports>
</reportSet>
</reportSets>
@@ -373,7 +348,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
- <additionalparam>-header '<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>'</additionalparam>
+ <additionalparam>-Xdoclint:all -header '<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>'</additionalparam>
+ <!-- <aggregate>true</aggregate> -->
</configuration>
</plugin>
</plugins>
@@ -392,7 +368,7 @@
<plugin>
<groupId>ru.concerteza.buildnumber</groupId>
<artifactId>maven-jgit-buildnumber-plugin</artifactId>
- <version>${math.jgit.buildnumber.version}</version>
+ <version>${numbers.jgit.buildnumber.version}</version>
<executions>
<execution>
<phase>generate-resources</phase>
@@ -430,18 +406,18 @@
<configuration>
<tasks>
<exec executable="svn">
- <arg line="checkout --depth immediates ${commons.scmPubUrl} ${commons.scmPubCheckoutDirectory}" />
+ <arg line="checkout --depth immediates ${commons.scmPubUrl} ${commons.scmPubCheckoutDirectory}"/>
</exec>
<exec executable="svn">
- <arg line="update --set-depth exclude ${commons.scmPubCheckoutDirectory}/javadocs" />
+ <arg line="update --set-depth exclude ${commons.scmPubCheckoutDirectory}/javadocs"/>
</exec>
<pathconvert pathsep=" " property="dirs">
- <dirset dir="${commons.scmPubCheckoutDirectory}" includes="*" />
+ <dirset dir="${commons.scmPubCheckoutDirectory}" includes="*"/>
</pathconvert>
<exec executable="svn">
- <arg line="update --set-depth infinity ${dirs}" />
+ <arg line="update --set-depth infinity ${dirs}"/>
</exec>
</tasks>
</configuration>
@@ -505,11 +481,51 @@
<version>${commons.jacoco.version}</version>
<executions>
<execution>
- <id>prepare-agent</id>
+ <id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
+ <execution>
+ <id>default-prepare-agent-integration</id>
+ <goals>
+ <goal>prepare-agent-integration</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>default-report</id>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>default-report-integration</id>
+ <goals>
+ <goal>report-integration</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>default-check</id>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ <configuration>
+ <rules>
+ <!-- implementation is needed only for Maven 2 -->
+ <rule implementation="org.jacoco.maven.RuleConfiguration">
+ <element>BUNDLE</element>
+ <limits>
+ <!-- implementation is needed only for Maven 2 -->
+ <limit implementation="org.jacoco.report.check.Limit">
+ <counter>COMPLEXITY</counter>
+ <value>COVEREDRATIO</value>
+ <minimum>0.60</minimum>
+ </limit>
+ </limits>
+ </rule>
+ </rules>
+ </configuration>
+ </execution>
</executions>
</plugin>
<plugin>
@@ -520,5 +536,15 @@
</plugins>
</build>
</profile>
+
</profiles>
+
+ <modules>
+ <module>commons-numbers-core</module>
+ <module>commons-numbers-complex</module>
+ <module>commons-numbers-quaternion</module>
+ <!-- <module>commons-numbers-fraction</module> -->
+ <!-- <module>commons-numbers-continuedfraction</module> -->
+ </modules>
+
</project>
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/src/main/resources/checkstyle/checkstyle.xml
----------------------------------------------------------------------
diff --git a/src/main/resources/checkstyle/checkstyle.xml b/src/main/resources/checkstyle/checkstyle.xml
new file mode 100644
index 0000000..a138af6
--- /dev/null
+++ b/src/main/resources/checkstyle/checkstyle.xml
@@ -0,0 +1,202 @@
+<?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 "-//Puppy Crawl//DTD Check Configuration 1.1//EN" "http://www.puppycrawl.com/dtds/configuration_1_1.dtd">
+
+<!-- Commons RNG customization of default Checkstyle behavior -->
+<module name="Checker">
+ <property name="localeLanguage" value="en"/>
+
+ <module name="TreeWalker">
+
+ <!-- Operator must be at end of wrapped line -->
+ <module name="OperatorWrap">
+ <property name="option" value="eol"/>
+ </module>
+
+ <!-- No if/else/do/for/while without braces -->
+ <module name="NeedBraces"/>
+
+ <!-- Interfaces must be types (not just constants) -->
+ <module name="InterfaceIsType"/>
+
+ <!-- Must have class / interface header comments -->
+ <module name="JavadocType"/>
+
+ <!-- Require method javadocs, allow undeclared RTE -->
+ <module name="JavadocMethod">
+ <property name="allowUndeclaredRTE" value="true"/>
+ <property name="allowThrowsTagsForSubclasses" value="true"/>
+ <property name="validateThrows" value="false"/>
+ </module>
+
+ <!-- Require field javadoc -->
+ <module name="JavadocVariable"/>
+
+ <!-- No public fields -->
+ <module name="VisibilityModifier">
+ <property name="protectedAllowed" value="true"/>
+ </module>
+
+ <!-- Require hash code override when equals is -->
+ <module name="EqualsHashCode"/>
+
+ <!-- Disallow unnecessary instantiation of Boolean, String -->
+ <module name="IllegalInstantiation">
+ <property name="classes" value="java.lang.Boolean, java.lang.String"/>
+ </module>
+
+ <!-- Required for SuppressionCommentFilter below -->
+ <module name="FileContentsHolder"/>
+
+ <!-- Import should be explicit, really needed and only from pure java packages -->
+ <module name="AvoidStarImport" />
+ <module name="UnusedImports" />
+ <module name="IllegalImport" />
+
+ <!-- Utility class should not be instantiated, they must have a private constructor -->
+ <module name="HideUtilityClassConstructor" />
+
+ <!-- Switch statements should be complete and with independent cases -->
+ <module name="FallThrough" />
+ <module name="MissingSwitchDefault" />
+
+ <!-- Constant names should obey the traditional all uppercase naming convention -->
+ <module name="ConstantName" />
+
+ <!-- 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>
+
+ <!-- No trailing whitespace -->
+ <module name="Regexp">
+ <property name="format" value="[ \t]+$"/>
+ <property name="illegalPattern" value="true"/>
+ <property name="message" value="Trailing whitespace"/>
+ </module>
+
+ <!-- No System.out.println() statements -->
+ <module name="Regexp">
+ <!-- no sysouts -->
+ <property name="format" value="System\.out\.println"/>
+ <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 modifiers -->
+ <module name="RedundantModifier" />
+ <module name="ModifierOrder" />
+
+ <!-- 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" />
+
+ <!-- Don't declare multiple variables in the same statement -->
+ <module name="MultipleVariableDeclarations" />
+
+ <!-- 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" />
+
+ <!-- <module name="TodoComment" /> -->
+
+ </module>
+
+ <!-- Verify that EVERY source file has the appropriate license -->
+ <module name="Header">
+ <property name="headerFile" value="${checkstyle.header.file}"/>
+ </module>
+
+ <!-- No tabs allowed! -->
+ <module name="FileTabCharacter"/>
+
+ <!-- Require files to end with newline characters -->
+ <module name="NewlineAtEndOfFile"/>
+
+ <!-- Require package javadoc -->
+ <module name="JavadocPackage"/>
+
+ <!-- Setup special comments to suppress specific checks from source files -->
+ <module name="SuppressionCommentFilter">
+ <property name="offCommentFormat" value="CHECKSTYLE\: stop JavadocVariable"/>
+ <property name="onCommentFormat" value="CHECKSTYLE\: resume JavadocVariable"/>
+ <property name="checkFormat" value="JavadocVariable"/>
+ </module>
+ <module name="SuppressionCommentFilter">
+ <property name="offCommentFormat" value="CHECKSTYLE\: stop JavadocMethodCheck"/>
+ <property name="onCommentFormat" value="CHECKSTYLE\: resume JavadocMethodCheck"/>
+ <property name="checkFormat" value="JavadocMethodCheck"/>
+ </module>
+ <module name="SuppressionCommentFilter">
+ <property name="offCommentFormat" value="CHECKSTYLE\: stop ConstantName"/>
+ <property name="onCommentFormat" value="CHECKSTYLE\: resume ConstantName"/>
+ <property name="checkFormat" value="ConstantName"/>
+ </module>
+ <module name="SuppressionCommentFilter">
+ <property name="offCommentFormat" value="CHECKSTYLE\: stop HideUtilityClassConstructor"/>
+ <property name="onCommentFormat" value="CHECKSTYLE\: resume HideUtilityClassConstructor"/>
+ <property name="checkFormat" value="HideUtilityClassConstructor"/>
+ </module>
+ <module name="SuppressionCommentFilter">
+ <property name="offCommentFormat" value="CHECKSTYLE\: stop MultipleVariableDeclarations"/>
+ <property name="onCommentFormat" value="CHECKSTYLE\: resume MultipleVariableDeclarations"/>
+ <property name="checkFormat" value="MultipleVariableDeclarations"/>
+ </module>
+ <module name="SuppressionCommentFilter">
+ <property name="offCommentFormat" value="CHECKSTYLE\: stop IllegalCatch"/>
+ <property name="onCommentFormat" value="CHECKSTYLE\: resume IllegalCatch"/>
+ <property name="checkFormat" value="IllegalCatch"/>
+ </module>
+ <module name="SuppressionCommentFilter">
+ <property name="offCommentFormat" value="CHECKSTYLE\: stop DeclarationOrder"/>
+ <property name="onCommentFormat" value="CHECKSTYLE\: resume DeclarationOrder"/>
+ <property name="checkFormat" value="DeclarationOrder"/>
+ </module>
+ <module name="SuppressionCommentFilter">
+ <property name="offCommentFormat" value="CHECKSTYLE\: stop RedundantModifier"/>
+ <property name="onCommentFormat" value="CHECKSTYLE\: resume RedundantModifier"/>
+ <property name="checkFormat" value="RedundantModifier"/>
+ </module>
+ <module name="SuppressionCommentFilter">
+ <property name="offCommentFormat" value="CHECKSTYLE\: stop all"/>
+ <property name="onCommentFormat" value="CHECKSTYLE\: resume all"/>
+ </module>
+</module>
+
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/src/main/resources/checkstyle/license-header.txt
----------------------------------------------------------------------
diff --git a/src/main/resources/checkstyle/license-header.txt b/src/main/resources/checkstyle/license-header.txt
new file mode 100644
index 0000000..ae6f28c
--- /dev/null
+++ b/src/main/resources/checkstyle/license-header.txt
@@ -0,0 +1,16 @@
+/*
+ * 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.
+ */
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/src/main/resources/clirr/clirr-ignored.xml
----------------------------------------------------------------------
diff --git a/src/main/resources/clirr/clirr-ignored.xml b/src/main/resources/clirr/clirr-ignored.xml
new file mode 100644
index 0000000..ed97259
--- /dev/null
+++ b/src/main/resources/clirr/clirr-ignored.xml
@@ -0,0 +1,21 @@
+<?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.
+-->
+
+<differences>
+
+</differences>
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/src/main/resources/findbugs/findbugs-exclude-filter.xml
----------------------------------------------------------------------
diff --git a/src/main/resources/findbugs/findbugs-exclude-filter.xml b/src/main/resources/findbugs/findbugs-exclude-filter.xml
new file mode 100644
index 0000000..8a9c858
--- /dev/null
+++ b/src/main/resources/findbugs/findbugs-exclude-filter.xml
@@ -0,0 +1,28 @@
+<?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.
+-->
+
+<!--
+ This file contains some false positive bugs detected by findbugs. Their
+ false positive nature has been analyzed individually and they have been
+ put here to instruct findbugs it must ignore them.
+-->
+<FindBugsFilter>
+
+ <Class name="~.*\.jmh\.generated\..*" />
+
+</FindBugsFilter>
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/src/main/resources/pmd/pmd-ruleset.xml
----------------------------------------------------------------------
diff --git a/src/main/resources/pmd/pmd-ruleset.xml b/src/main/resources/pmd/pmd-ruleset.xml
new file mode 100644
index 0000000..c637ef7
--- /dev/null
+++ b/src/main/resources/pmd/pmd-ruleset.xml
@@ -0,0 +1,57 @@
+<?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.
+-->
+<ruleset name="commons-rng-customized"
+ xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
+ <description>
+ This ruleset checks the code for discouraged programming constructs.
+ </description>
+
+ <rule ref="rulesets/java/basic.xml"/>
+
+ <rule ref="rulesets/java/braces.xml"/>
+
+ <rule ref="rulesets/java/comments.xml">
+ <exclude name="CommentSize"/>
+ </rule>
+ <rule ref="rulesets/java/comments.xml/CommentSize">
+ <properties>
+ <property name="maxLines" value="200"/>
+ <property name="maxLineLength" value="256"/>
+ </properties>
+ </rule>
+
+ <rule ref="rulesets/java/empty.xml"/>
+
+ <rule ref="rulesets/java/finalizers.xml"/>
+
+ <rule ref="rulesets/java/imports.xml"/>
+
+ <rule ref="rulesets/java/typeresolution.xml"/>
+
+ <rule ref="rulesets/java/clone.xml"/>
+
+ <rule ref="rulesets/java/unnecessary.xml">
+ <!-- We do use extra parentheses there as most people do not recall operator precedence,
+ this means even if the parentheses are useless for the compiler, we don't consider
+ them useless for the developer. This is the reason why we disable this rule. -->
+ <exclude name="UselessParentheses"/>
+ </rule>
+
+</ruleset>
[11/31] commons-numbers git commit: Multimodule project setup.
Posted by er...@apache.org.
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/TestUtils.java
----------------------------------------------------------------------
diff --git a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/TestUtils.java b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/TestUtils.java
new file mode 100644
index 0000000..70dc4c1
--- /dev/null
+++ b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/TestUtils.java
@@ -0,0 +1,409 @@
+/*
+ * 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.
+ */
+
+package org.apache.commons.numbers.complex;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.apache.commons.numbers.complex.Complex;
+
+import org.junit.Assert;
+
+/**
+ * Test utilities.
+ * TODO: Cleanup (remove unused and obsolete methods).
+ */
+public class TestUtils {
+ /**
+ * Collection of static methods used in math unit tests.
+ */
+ private TestUtils() {
+ super();
+ }
+
+ /**
+ * Verifies that expected and actual are within delta, or are both NaN or
+ * infinities of the same sign.
+ */
+ public static void assertEquals(double expected, double actual, double delta) {
+ Assert.assertEquals(null, expected, actual, delta);
+ }
+
+ /**
+ * Verifies that expected and actual are within delta, or are both NaN or
+ * infinities of the same sign.
+ */
+ public static void assertEquals(String msg, double expected, double actual, double delta) {
+ // check for NaN
+ if(Double.isNaN(expected)){
+ Assert.assertTrue("" + actual + " is not NaN.",
+ Double.isNaN(actual));
+ } else {
+ Assert.assertEquals(msg, expected, actual, delta);
+ }
+ }
+
+ /**
+ * Verifies that the two arguments are exactly the same, either
+ * both NaN or infinities of same sign, or identical floating point values.
+ */
+ public static void assertSame(double expected, double actual) {
+ Assert.assertEquals(expected, actual, 0);
+ }
+
+ /**
+ * Verifies that real and imaginary parts of the two complex arguments
+ * are exactly the same. Also ensures that NaN / infinite components match.
+ */
+ public static void assertSame(Complex expected, Complex actual) {
+ assertSame(expected.getReal(), actual.getReal());
+ assertSame(expected.getImaginary(), actual.getImaginary());
+ }
+
+ /**
+ * Verifies that real and imaginary parts of the two complex arguments
+ * differ by at most delta. Also ensures that NaN / infinite components match.
+ */
+ public static void assertEquals(Complex expected, Complex actual, double delta) {
+ Assert.assertEquals(expected.getReal(), actual.getReal(), delta);
+ Assert.assertEquals(expected.getImaginary(), actual.getImaginary(), delta);
+ }
+
+ /**
+ * Verifies that two double arrays have equal entries, up to tolerance
+ */
+ public static void assertEquals(double expected[], double observed[], double tolerance) {
+ assertEquals("Array comparison failure", expected, observed, tolerance);
+ }
+
+ /**
+ * Serializes an object to a bytes array and then recovers the object from the bytes array.
+ * Returns the deserialized object.
+ *
+ * @param o object to serialize and recover
+ * @return the recovered, deserialized object
+ */
+ public static Object serializeAndRecover(Object o) {
+ try {
+ // serialize the Object
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ObjectOutputStream so = new ObjectOutputStream(bos);
+ so.writeObject(o);
+
+ // deserialize the Object
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ ObjectInputStream si = new ObjectInputStream(bis);
+ return si.readObject();
+ } catch (IOException ioe) {
+ return null;
+ } catch (ClassNotFoundException cnfe) {
+ return null;
+ }
+ }
+
+ /**
+ * Verifies that serialization preserves equals and hashCode.
+ * Serializes the object, then recovers it and checks equals and hash code.
+ *
+ * @param object the object to serialize and recover
+ */
+ public static void checkSerializedEquality(Object object) {
+ Object object2 = serializeAndRecover(object);
+ Assert.assertEquals("Equals check", object, object2);
+ Assert.assertEquals("HashCode check", object.hashCode(), object2.hashCode());
+ }
+
+ /**
+ * Verifies that the relative error in actual vs. expected is less than or
+ * equal to relativeError. If expected is infinite or NaN, actual must be
+ * the same (NaN or infinity of the same sign).
+ *
+ * @param expected expected value
+ * @param actual observed value
+ * @param relativeError maximum allowable relative error
+ */
+ public static void assertRelativelyEquals(double expected, double actual,
+ double relativeError) {
+ assertRelativelyEquals(null, expected, actual, relativeError);
+ }
+
+ /**
+ * Verifies that the relative error in actual vs. expected is less than or
+ * equal to relativeError. If expected is infinite or NaN, actual must be
+ * the same (NaN or infinity of the same sign).
+ *
+ * @param msg message to return with failure
+ * @param expected expected value
+ * @param actual observed value
+ * @param relativeError maximum allowable relative error
+ */
+ public static void assertRelativelyEquals(String msg, double expected,
+ double actual, double relativeError) {
+ if (Double.isNaN(expected)) {
+ Assert.assertTrue(msg, Double.isNaN(actual));
+ } else if (Double.isNaN(actual)) {
+ Assert.assertTrue(msg, Double.isNaN(expected));
+ } else if (Double.isInfinite(actual) || Double.isInfinite(expected)) {
+ Assert.assertEquals(expected, actual, relativeError);
+ } else if (expected == 0.0) {
+ Assert.assertEquals(msg, actual, expected, relativeError);
+ } else {
+ double absError = Math.abs(expected) * relativeError;
+ Assert.assertEquals(msg, expected, actual, absError);
+ }
+ }
+
+ /**
+ * Fails iff values does not contain a number within epsilon of z.
+ *
+ * @param msg message to return with failure
+ * @param values complex array to search
+ * @param z value sought
+ * @param epsilon tolerance
+ */
+ public static void assertContains(String msg, Complex[] values,
+ Complex z, double epsilon) {
+ for (Complex value : values) {
+ if (Precision.equals(value.getReal(), z.getReal(), epsilon) &&
+ Precision.equals(value.getImaginary(), z.getImaginary(), epsilon)) {
+ return;
+ }
+ }
+ Assert.fail(msg + " Unable to find " + z);
+ }
+
+ /**
+ * Fails iff values does not contain a number within epsilon of z.
+ *
+ * @param values complex array to search
+ * @param z value sought
+ * @param epsilon tolerance
+ */
+ public static void assertContains(Complex[] values,
+ Complex z, double epsilon) {
+ assertContains(null, values, z, epsilon);
+ }
+
+ /**
+ * Fails iff values does not contain a number within epsilon of x.
+ *
+ * @param msg message to return with failure
+ * @param values double array to search
+ * @param x value sought
+ * @param epsilon tolerance
+ */
+ public static void assertContains(String msg, double[] values,
+ double x, double epsilon) {
+ for (double value : values) {
+ if (Precision.equals(value, x, epsilon)) {
+ return;
+ }
+ }
+ Assert.fail(msg + " Unable to find " + x);
+ }
+
+ /**
+ * Fails iff values does not contain a number within epsilon of x.
+ *
+ * @param values double array to search
+ * @param x value sought
+ * @param epsilon tolerance
+ */
+ public static void assertContains(double[] values, double x,
+ double epsilon) {
+ assertContains(null, values, x, epsilon);
+ }
+
+ /** verifies that two arrays are close (sup norm) */
+ public static void assertEquals(String msg, double[] expected, double[] observed, double tolerance) {
+ StringBuilder out = new StringBuilder(msg);
+ if (expected.length != observed.length) {
+ out.append("\n Arrays not same length. \n");
+ out.append("expected has length ");
+ out.append(expected.length);
+ out.append(" observed length = ");
+ out.append(observed.length);
+ Assert.fail(out.toString());
+ }
+ boolean failure = false;
+ for (int i=0; i < expected.length; i++) {
+ if (!equalsIncludingNaN(expected[i], observed[i], tolerance)) {
+ failure = true;
+ out.append("\n Elements at index ");
+ out.append(i);
+ out.append(" differ. ");
+ out.append(" expected = ");
+ out.append(expected[i]);
+ out.append(" observed = ");
+ out.append(observed[i]);
+ }
+ }
+ if (failure) {
+ Assert.fail(out.toString());
+ }
+ }
+
+ /** verifies that two arrays are close (sup norm) */
+ public static void assertEquals(String msg, float[] expected, float[] observed, float tolerance) {
+ StringBuilder out = new StringBuilder(msg);
+ if (expected.length != observed.length) {
+ out.append("\n Arrays not same length. \n");
+ out.append("expected has length ");
+ out.append(expected.length);
+ out.append(" observed length = ");
+ out.append(observed.length);
+ Assert.fail(out.toString());
+ }
+ boolean failure = false;
+ for (int i=0; i < expected.length; i++) {
+ if (!equalsIncludingNaN(expected[i], observed[i], tolerance)) {
+ failure = true;
+ out.append("\n Elements at index ");
+ out.append(i);
+ out.append(" differ. ");
+ out.append(" expected = ");
+ out.append(expected[i]);
+ out.append(" observed = ");
+ out.append(observed[i]);
+ }
+ }
+ if (failure) {
+ Assert.fail(out.toString());
+ }
+ }
+
+ /** verifies that two arrays are close (sup norm) */
+ public static void assertEquals(String msg, Complex[] expected, Complex[] observed, double tolerance) {
+ StringBuilder out = new StringBuilder(msg);
+ if (expected.length != observed.length) {
+ out.append("\n Arrays not same length. \n");
+ out.append("expected has length ");
+ out.append(expected.length);
+ out.append(" observed length = ");
+ out.append(observed.length);
+ Assert.fail(out.toString());
+ }
+ boolean failure = false;
+ for (int i=0; i < expected.length; i++) {
+ if (!equalsIncludingNaN(expected[i].getReal(), observed[i].getReal(), tolerance)) {
+ failure = true;
+ out.append("\n Real elements at index ");
+ out.append(i);
+ out.append(" differ. ");
+ out.append(" expected = ");
+ out.append(expected[i].getReal());
+ out.append(" observed = ");
+ out.append(observed[i].getReal());
+ }
+ if (!equalsIncludingNaN(expected[i].getImaginary(), observed[i].getImaginary(), tolerance)) {
+ failure = true;
+ out.append("\n Imaginary elements at index ");
+ out.append(i);
+ out.append(" differ. ");
+ out.append(" expected = ");
+ out.append(expected[i].getImaginary());
+ out.append(" observed = ");
+ out.append(observed[i].getImaginary());
+ }
+ }
+ if (failure) {
+ Assert.fail(out.toString());
+ }
+ }
+
+ /**
+ * Updates observed counts of values in quartiles.
+ * counts[0] <-> 1st quartile ... counts[3] <-> top quartile
+ */
+ public static void updateCounts(double value, long[] counts, double[] quartiles) {
+ if (value < quartiles[0]) {
+ counts[0]++;
+ } else if (value > quartiles[2]) {
+ counts[3]++;
+ } else if (value > quartiles[1]) {
+ counts[2]++;
+ } else {
+ counts[1]++;
+ }
+ }
+
+ /**
+ * Eliminates points with zero mass from densityPoints and densityValues parallel
+ * arrays. Returns the number of positive mass points and collapses the arrays so
+ * that the first <returned value> elements of the input arrays represent the positive
+ * mass points.
+ */
+ public static int eliminateZeroMassPoints(int[] densityPoints, double[] densityValues) {
+ int positiveMassCount = 0;
+ for (int i = 0; i < densityValues.length; i++) {
+ if (densityValues[i] > 0) {
+ positiveMassCount++;
+ }
+ }
+ if (positiveMassCount < densityValues.length) {
+ int[] newPoints = new int[positiveMassCount];
+ double[] newValues = new double[positiveMassCount];
+ int j = 0;
+ for (int i = 0; i < densityValues.length; i++) {
+ if (densityValues[i] > 0) {
+ newPoints[j] = densityPoints[i];
+ newValues[j] = densityValues[i];
+ j++;
+ }
+ }
+ System.arraycopy(newPoints,0,densityPoints,0,positiveMassCount);
+ System.arraycopy(newValues,0,densityValues,0,positiveMassCount);
+ }
+ return positiveMassCount;
+ }
+
+ /**
+ * Returns true if the arguments are both NaN, are equal or are within the range
+ * of allowed error (inclusive).
+ *
+ * @param x first value
+ * @param y second value
+ * @param eps the amount of absolute error to allow.
+ * @return {@code true} if the values are equal or within range of each other,
+ * or both are NaN.
+ * @since 2.2
+ */
+ private static boolean equalsIncludingNaN(double x, double y, double eps) {
+ return equalsIncludingNaN(x, y) || (Math.abs(y - x) <= eps);
+ }
+
+ /**
+ * Returns true if the arguments are both NaN or they are
+ * equal as defined by {@link #equals(double,double) equals(x, y, 1)}.
+ *
+ * @param x first value
+ * @param y second value
+ * @return {@code true} if the values are equal or both are NaN.
+ * @since 2.2
+ */
+ private static boolean equalsIncludingNaN(double x, double y) {
+ return (x != x || y != y) ? !(x != x ^ y != y) : Precision.equals(x, y, 1);
+ }
+
+
+}
+
+
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-core/LICENSE.txt
----------------------------------------------------------------------
diff --git a/commons-numbers-core/LICENSE.txt b/commons-numbers-core/LICENSE.txt
new file mode 100644
index 0000000..261eeb9
--- /dev/null
+++ b/commons-numbers-core/LICENSE.txt
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-core/NOTICE.txt
----------------------------------------------------------------------
diff --git a/commons-numbers-core/NOTICE.txt b/commons-numbers-core/NOTICE.txt
new file mode 100644
index 0000000..ea6ae07
--- /dev/null
+++ b/commons-numbers-core/NOTICE.txt
@@ -0,0 +1,6 @@
+Apache Commons Numbers
+Copyright 2001-2016 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-core/README.md
----------------------------------------------------------------------
diff --git a/commons-numbers-core/README.md b/commons-numbers-core/README.md
new file mode 100644
index 0000000..0701bed
--- /dev/null
+++ b/commons-numbers-core/README.md
@@ -0,0 +1,98 @@
+<!---
+ 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.
+-->
+<!---
+ +======================================================================+
+ |**** ****|
+ |**** THIS FILE IS GENERATED BY THE COMMONS BUILD PLUGIN ****|
+ |**** DO NOT EDIT DIRECTLY ****|
+ |**** ****|
+ +======================================================================+
+ | TEMPLATE FILE: readme-md-template.md |
+ | commons-build-plugin/trunk/src/main/resources/commons-xdoc-templates |
+ +======================================================================+
+ | |
+ | 1) Re-generate using: mvn commons:readme-md |
+ | |
+ | 2) Set the following properties in the component's pom: |
+ | - commons.componentid (required, alphabetic, lower case) |
+ | - commons.release.version (required) |
+ | |
+ | 3) Example Properties |
+ | |
+ | <properties> |
+ | <commons.componentid>math</commons.componentid> |
+ | <commons.release.version>1.2</commons.release.version> |
+ | </properties> |
+ | |
+ +======================================================================+
+--->
+Apache Commons Numbers Core
+===================
+
+Basic utilities.
+
+Documentation
+-------------
+
+More information can be found on the [homepage](https://commons.apache.org/proper/commons-numbers).
+The [JavaDoc](https://commons.apache.org/proper/commons-numbers/javadocs/api-release) can be browsed.
+Questions related to the usage of Apache Commons Numbers Core should be posted to the [user mailing list][ml].
+
+Where can I get the latest release?
+-----------------------------------
+You can download source and binaries from our [download page](https://commons.apache.org/proper/commons-numbers/download_numbers.cgi).
+
+Alternatively you can pull it from the central Maven repositories:
+
+```xml
+<dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-core</artifactId>
+ <version>1.0</version>
+</dependency>
+```
+
+Contributing
+------------
+
+We accept PRs via github. The [developer mailing list][ml] is the main channel of communication for contributors.
+There are some guidelines which will make applying PRs easier for us:
++ No tabs! Please use spaces for indentation.
++ Respect the code style.
++ Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change.
++ Provide JUnit tests for your changes and make sure your changes don't break any existing tests by running ```mvn clean test```.
+
+If you plan to contribute on a regular basis, please consider filing a [contributor license agreement](https://www.apache.org/licenses/#clas).
+You can learn more about contributing via GitHub in our [contribution guidelines](CONTRIBUTING.md).
+
+License
+-------
+Code is under the [Apache Licence v2](https://www.apache.org/licenses/LICENSE-2.0.txt).
+
+Donations
+---------
+You like Apache Commons Numbers Core? Then [donate back to the ASF](https://www.apache.org/foundation/contributing.html) to support the development.
+
+Additional Resources
+--------------------
+
++ [Apache Commons Homepage](https://commons.apache.org/)
++ [Apache Bugtracker (JIRA)](https://issues.apache.org/jira/)
++ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons)
++ #apachecommons IRC channel on freenode.org
+
+[ml]:https://commons.apache.org/mail-lists.html
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-core/pom.xml
----------------------------------------------------------------------
diff --git a/commons-numbers-core/pom.xml b/commons-numbers-core/pom.xml
new file mode 100644
index 0000000..39dbdcb
--- /dev/null
+++ b/commons-numbers-core/pom.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-parent</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-core</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <name>Apache Commons Numbers Core</name>
+
+ <description>Basic utilities.</description>
+
+ <properties>
+ <!-- This value must reflect the current name of the base package. -->
+ <commons.osgi.symbolicName>org.apache.commons.numbers.core</commons.osgi.symbolicName>
+ <!-- OSGi -->
+ <commons.osgi.export>org.apache.commons.numbers.core</commons.osgi.export>
+ <!-- Workaround to avoid duplicating config files. -->
+ <numbers.parent.dir>${basedir}/..</numbers.parent.dir>
+ </properties>
+
+
+</project>
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Precision.java
----------------------------------------------------------------------
diff --git a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Precision.java b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Precision.java
new file mode 100644
index 0000000..e71e1e4
--- /dev/null
+++ b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Precision.java
@@ -0,0 +1,598 @@
+/*
+ * 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.
+ */
+
+package org.apache.commons.numbers.core;
+
+import java.math.BigDecimal;
+
+/**
+ * Utilities for comparing numbers.
+ */
+public class Precision {
+ /**
+ * <p>
+ * Largest double-precision floating-point number such that
+ * {@code 1 + EPSILON} is numerically equal to 1. This value is an upper
+ * bound on the relative error due to rounding real numbers to double
+ * precision floating-point numbers.
+ * </p>
+ * <p>
+ * In IEEE 754 arithmetic, this is 2<sup>-53</sup>.
+ * </p>
+ *
+ * @see <a href="http://en.wikipedia.org/wiki/Machine_epsilon">Machine epsilon</a>
+ */
+ public static final double EPSILON;
+
+ /**
+ * Safe minimum, such that {@code 1 / SAFE_MIN} does not overflow.
+ * In IEEE 754 arithmetic, this is also the smallest normalized
+ * number 2<sup>-1022</sup>.
+ */
+ public static final double SAFE_MIN;
+
+ /** Exponent offset in IEEE754 representation. */
+ private static final long EXPONENT_OFFSET = 1023l;
+
+ /** Offset to order signed double numbers lexicographically. */
+ private static final long SGN_MASK = 0x8000000000000000L;
+ /** Offset to order signed double numbers lexicographically. */
+ private static final int SGN_MASK_FLOAT = 0x80000000;
+ /** Positive zero. */
+ private static final double POSITIVE_ZERO = 0d;
+ /** Positive zero bits. */
+ private static final long POSITIVE_ZERO_DOUBLE_BITS = Double.doubleToRawLongBits(+0.0);
+ /** Negative zero bits. */
+ private static final long NEGATIVE_ZERO_DOUBLE_BITS = Double.doubleToRawLongBits(-0.0);
+ /** Positive zero bits. */
+ private static final int POSITIVE_ZERO_FLOAT_BITS = Float.floatToRawIntBits(+0.0f);
+ /** Negative zero bits. */
+ private static final int NEGATIVE_ZERO_FLOAT_BITS = Float.floatToRawIntBits(-0.0f);
+
+ static {
+ /*
+ * This was previously expressed as = 0x1.0p-53;
+ * However, OpenJDK (Sparc Solaris) cannot handle such small
+ * constants: MATH-721
+ */
+ EPSILON = Double.longBitsToDouble((EXPONENT_OFFSET - 53l) << 52);
+
+ /*
+ * This was previously expressed as = 0x1.0p-1022;
+ * However, OpenJDK (Sparc Solaris) cannot handle such small
+ * constants: MATH-721
+ */
+ SAFE_MIN = Double.longBitsToDouble((EXPONENT_OFFSET - 1022l) << 52);
+ }
+
+ /**
+ * Private constructor.
+ */
+ private Precision() {}
+
+ /**
+ * Compares two numbers given some amount of allowed error.
+ * The returned value is
+ * <ul>
+ * <li>
+ * 0 if {@link #equals(double,double,double) equals(x, y, eps)},
+ * </li>
+ * <li>
+ * negative if !{@link #equals(double,double,double) equals(x, y, eps)} and {@code x < y},
+ * </li>
+ * <li>
+ * positive if !{@link #equals(double,double,double) equals(x, y, eps)} and {@code x > y} or
+ * either argument is {@code NaN}.
+ * </li>
+ * </ul>
+ *
+ * @param x First value.
+ * @param y Second value.
+ * @param eps Allowed error when checking for equality.
+ * @return 0 if the value are considered equal, -1 if the first is smaller than
+ * the second, 1 is the first is larger than the second.
+ */
+ public static int compareTo(double x, double y, double eps) {
+ if (equals(x, y, eps)) {
+ return 0;
+ } else if (x < y) {
+ return -1;
+ }
+ return 1;
+ }
+
+ /**
+ * Compares two numbers given some amount of allowed error.
+ * Two float numbers are considered equal if there are {@code (maxUlps - 1)}
+ * (or fewer) floating point numbers between them, i.e. two adjacent floating
+ * point numbers are considered equal.
+ * Adapted from
+ * <a href="http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/">
+ * Bruce Dawson</a>. Returns {@code false} if either of the arguments is NaN.
+ * The returned value is
+ * <ul>
+ * <li>
+ * zero if {@link #equals(double,double,int) equals(x, y, maxUlps)},
+ * </li>
+ * <li>
+ * negative if !{@link #equals(double,double,int) equals(x, y, maxUlps)} and {@code x < y},
+ * </li>
+ * <li>
+ * positive if !{@link #equals(double,double,int) equals(x, y, maxUlps)} and {@code x > y}
+ * or either argument is {@code NaN}.
+ * </li>
+ * </ul>
+ *
+ * @param x First value.
+ * @param y Second value.
+ * @param maxUlps {@code (maxUlps - 1)} is the number of floating point
+ * values between {@code x} and {@code y}.
+ * @return 0 if the value are considered equal, -1 if the first is smaller than
+ * the second, 1 is the first is larger than the second.
+ */
+ public static int compareTo(final double x, final double y, final int maxUlps) {
+ if (equals(x, y, maxUlps)) {
+ return 0;
+ } else if (x < y) {
+ return -1;
+ }
+ return 1;
+ }
+
+ /**
+ * Returns true iff they are equal as defined by
+ * {@link #equals(float,float,int) equals(x, y, 1)}.
+ *
+ * @param x first value
+ * @param y second value
+ * @return {@code true} if the values are equal.
+ */
+ public static boolean equals(float x, float y) {
+ return equals(x, y, 1);
+ }
+
+ /**
+ * Returns true if both arguments are NaN or they are
+ * equal as defined by {@link #equals(float,float) equals(x, y, 1)}.
+ *
+ * @param x first value
+ * @param y second value
+ * @return {@code true} if the values are equal or both are NaN.
+ */
+ public static boolean equalsIncludingNaN(float x, float y) {
+ return (x != x || y != y) ? !(x != x ^ y != y) : equals(x, y, 1);
+ }
+
+ /**
+ * Returns true if the arguments are equal or within the range of allowed
+ * error (inclusive). Returns {@code false} if either of the arguments
+ * is NaN.
+ *
+ * @param x first value
+ * @param y second value
+ * @param eps the amount of absolute error to allow.
+ * @return {@code true} if the values are equal or within range of each other.
+ */
+ public static boolean equals(float x, float y, float eps) {
+ return equals(x, y, 1) || Math.abs(y - x) <= eps;
+ }
+
+ /**
+ * Returns true if the arguments are both NaN, are equal, or are within the range
+ * of allowed error (inclusive).
+ *
+ * @param x first value
+ * @param y second value
+ * @param eps the amount of absolute error to allow.
+ * @return {@code true} if the values are equal or within range of each other,
+ * or both are NaN.
+ */
+ public static boolean equalsIncludingNaN(float x, float y, float eps) {
+ return equalsIncludingNaN(x, y) || (Math.abs(y - x) <= eps);
+ }
+
+ /**
+ * Returns true if the arguments are equal or within the range of allowed
+ * error (inclusive).
+ * Two float numbers are considered equal if there are {@code (maxUlps - 1)}
+ * (or fewer) floating point numbers between them, i.e. two adjacent floating
+ * point numbers are considered equal.
+ * Adapted from <a
+ * href="http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/">
+ * Bruce Dawson</a>. Returns {@code false} if either of the arguments is NaN.
+ *
+ * @param x first value
+ * @param y second value
+ * @param maxUlps {@code (maxUlps - 1)} is the number of floating point
+ * values between {@code x} and {@code y}.
+ * @return {@code true} if there are fewer than {@code maxUlps} floating
+ * point values between {@code x} and {@code y}.
+ */
+ public static boolean equals(final float x, final float y, final int maxUlps) {
+
+ final int xInt = Float.floatToRawIntBits(x);
+ final int yInt = Float.floatToRawIntBits(y);
+
+ final boolean isEqual;
+ if (((xInt ^ yInt) & SGN_MASK_FLOAT) == 0) {
+ // number have same sign, there is no risk of overflow
+ isEqual = Math.abs(xInt - yInt) <= maxUlps;
+ } else {
+ // number have opposite signs, take care of overflow
+ final int deltaPlus;
+ final int deltaMinus;
+ if (xInt < yInt) {
+ deltaPlus = yInt - POSITIVE_ZERO_FLOAT_BITS;
+ deltaMinus = xInt - NEGATIVE_ZERO_FLOAT_BITS;
+ } else {
+ deltaPlus = xInt - POSITIVE_ZERO_FLOAT_BITS;
+ deltaMinus = yInt - NEGATIVE_ZERO_FLOAT_BITS;
+ }
+
+ if (deltaPlus > maxUlps) {
+ isEqual = false;
+ } else {
+ isEqual = deltaMinus <= (maxUlps - deltaPlus);
+ }
+
+ }
+
+ return isEqual && !Float.isNaN(x) && !Float.isNaN(y);
+
+ }
+
+ /**
+ * Returns true if the arguments are both NaN or if they are equal as defined
+ * by {@link #equals(float,float,int) equals(x, y, maxUlps)}.
+ *
+ * @param x first value
+ * @param y second value
+ * @param maxUlps {@code (maxUlps - 1)} is the number of floating point
+ * values between {@code x} and {@code y}.
+ * @return {@code true} if both arguments are NaN or if there are less than
+ * {@code maxUlps} floating point values between {@code x} and {@code y}.
+ */
+ public static boolean equalsIncludingNaN(float x, float y, int maxUlps) {
+ return (x != x || y != y) ? !(x != x ^ y != y) : equals(x, y, maxUlps);
+ }
+
+ /**
+ * Returns true iff they are equal as defined by
+ * {@link #equals(double,double,int) equals(x, y, 1)}.
+ *
+ * @param x first value
+ * @param y second value
+ * @return {@code true} if the values are equal.
+ */
+ public static boolean equals(double x, double y) {
+ return equals(x, y, 1);
+ }
+
+ /**
+ * Returns true if the arguments are both NaN or they are
+ * equal as defined by {@link #equals(double,double) equals(x, y, 1)}.
+ *
+ * @param x first value
+ * @param y second value
+ * @return {@code true} if the values are equal or both are NaN.
+ */
+ public static boolean equalsIncludingNaN(double x, double y) {
+ return (x != x || y != y) ? !(x != x ^ y != y) : equals(x, y, 1);
+ }
+
+ /**
+ * Returns {@code true} if there is no double value strictly between the
+ * arguments or the difference between them is within the range of allowed
+ * error (inclusive). Returns {@code false} if either of the arguments
+ * is NaN.
+ *
+ * @param x First value.
+ * @param y Second value.
+ * @param eps Amount of allowed absolute error.
+ * @return {@code true} if the values are two adjacent floating point
+ * numbers or they are within range of each other.
+ */
+ public static boolean equals(double x, double y, double eps) {
+ return equals(x, y, 1) || Math.abs(y - x) <= eps;
+ }
+
+ /**
+ * Returns {@code true} if there is no double value strictly between the
+ * arguments or the relative difference between them is less than or equal
+ * to the given tolerance. Returns {@code false} if either of the arguments
+ * is NaN.
+ *
+ * @param x First value.
+ * @param y Second value.
+ * @param eps Amount of allowed relative error.
+ * @return {@code true} if the values are two adjacent floating point
+ * numbers or they are within range of each other.
+ */
+ public static boolean equalsWithRelativeTolerance(double x, double y, double eps) {
+ if (equals(x, y, 1)) {
+ return true;
+ }
+
+ final double absoluteMax = Math.max(Math.abs(x), Math.abs(y));
+ final double relativeDifference = Math.abs((x - y) / absoluteMax);
+
+ return relativeDifference <= eps;
+ }
+
+ /**
+ * Returns true if the arguments are both NaN, are equal or are within the range
+ * of allowed error (inclusive).
+ *
+ * @param x first value
+ * @param y second value
+ * @param eps the amount of absolute error to allow.
+ * @return {@code true} if the values are equal or within range of each other,
+ * or both are NaN.
+ */
+ public static boolean equalsIncludingNaN(double x, double y, double eps) {
+ return equalsIncludingNaN(x, y) || (Math.abs(y - x) <= eps);
+ }
+
+ /**
+ * Returns true if the arguments are equal or within the range of allowed
+ * error (inclusive).
+ * <p>
+ * Two float numbers are considered equal if there are {@code (maxUlps - 1)}
+ * (or fewer) floating point numbers between them, i.e. two adjacent
+ * floating point numbers are considered equal.
+ * </p>
+ * <p>
+ * Adapted from <a
+ * href="http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/">
+ * Bruce Dawson</a>. Returns {@code false} if either of the arguments is NaN.
+ * </p>
+ *
+ * @param x first value
+ * @param y second value
+ * @param maxUlps {@code (maxUlps - 1)} is the number of floating point
+ * values between {@code x} and {@code y}.
+ * @return {@code true} if there are fewer than {@code maxUlps} floating
+ * point values between {@code x} and {@code y}.
+ */
+ public static boolean equals(final double x, final double y, final int maxUlps) {
+
+ final long xInt = Double.doubleToRawLongBits(x);
+ final long yInt = Double.doubleToRawLongBits(y);
+
+ final boolean isEqual;
+ if (((xInt ^ yInt) & SGN_MASK) == 0l) {
+ // number have same sign, there is no risk of overflow
+ isEqual = Math.abs(xInt - yInt) <= maxUlps;
+ } else {
+ // number have opposite signs, take care of overflow
+ final long deltaPlus;
+ final long deltaMinus;
+ if (xInt < yInt) {
+ deltaPlus = yInt - POSITIVE_ZERO_DOUBLE_BITS;
+ deltaMinus = xInt - NEGATIVE_ZERO_DOUBLE_BITS;
+ } else {
+ deltaPlus = xInt - POSITIVE_ZERO_DOUBLE_BITS;
+ deltaMinus = yInt - NEGATIVE_ZERO_DOUBLE_BITS;
+ }
+
+ if (deltaPlus > maxUlps) {
+ isEqual = false;
+ } else {
+ isEqual = deltaMinus <= (maxUlps - deltaPlus);
+ }
+
+ }
+
+ return isEqual && !Double.isNaN(x) && !Double.isNaN(y);
+
+ }
+
+ /**
+ * Returns true if both arguments are NaN or if they are equal as defined
+ * by {@link #equals(double,double,int) equals(x, y, maxUlps)}.
+ *
+ * @param x first value
+ * @param y second value
+ * @param maxUlps {@code (maxUlps - 1)} is the number of floating point
+ * values between {@code x} and {@code y}.
+ * @return {@code true} if both arguments are NaN or if there are less than
+ * {@code maxUlps} floating point values between {@code x} and {@code y}.
+ */
+ public static boolean equalsIncludingNaN(double x, double y, int maxUlps) {
+ return (x != x || y != y) ? !(x != x ^ y != y) : equals(x, y, maxUlps);
+ }
+
+ /**
+ * Rounds the given value to the specified number of decimal places.
+ * The value is rounded using the {@link BigDecimal#ROUND_HALF_UP} method.
+ *
+ * @param x Value to round.
+ * @param scale Number of digits to the right of the decimal point.
+ * @return the rounded value.
+ */
+ public static double round(double x, int scale) {
+ return round(x, scale, BigDecimal.ROUND_HALF_UP);
+ }
+
+ /**
+ * Rounds the given value to the specified number of decimal places.
+ * The value is rounded using the given method which is any method defined
+ * in {@link BigDecimal}.
+ * If {@code x} is infinite or {@code NaN}, then the value of {@code x} is
+ * returned unchanged, regardless of the other parameters.
+ *
+ * @param x Value to round.
+ * @param scale Number of digits to the right of the decimal point.
+ * @param roundingMethod Rounding method as defined in {@link BigDecimal}.
+ * @return the rounded value.
+ * @throws ArithmeticException if {@code roundingMethod == ROUND_UNNECESSARY}
+ * and the specified scaling operation would require rounding.
+ * @throws IllegalArgumentException if {@code roundingMethod} does not
+ * represent a valid rounding mode.
+ */
+ public static double round(double x, int scale, int roundingMethod) {
+ try {
+ final double rounded = (new BigDecimal(Double.toString(x))
+ .setScale(scale, roundingMethod))
+ .doubleValue();
+ // MATH-1089: negative values rounded to zero should result in negative zero
+ return rounded == POSITIVE_ZERO ? POSITIVE_ZERO * x : rounded;
+ } catch (NumberFormatException ex) {
+ if (Double.isInfinite(x)) {
+ return x;
+ } else {
+ return Double.NaN;
+ }
+ }
+ }
+
+ /**
+ * Rounds the given value to the specified number of decimal places.
+ * The value is rounded using the {@link BigDecimal#ROUND_HALF_UP} method.
+ *
+ * @param x Value to round.
+ * @param scale Number of digits to the right of the decimal point.
+ * @return the rounded value.
+ */
+ public static float round(float x, int scale) {
+ return round(x, scale, BigDecimal.ROUND_HALF_UP);
+ }
+
+ /**
+ * Rounds the given value to the specified number of decimal places.
+ * The value is rounded using the given method which is any method defined
+ * in {@link BigDecimal}.
+ *
+ * @param x Value to round.
+ * @param scale Number of digits to the right of the decimal point.
+ * @param roundingMethod Rounding method as defined in {@link BigDecimal}.
+ * @return the rounded value.
+ * @throws ArithmeticException if an exact operation is required but result is not exact
+ * @throws IllegalArgumentException if {@code roundingMethod} is not a valid rounding method.
+ */
+ public static float round(float x, int scale, int roundingMethod) {
+ final float sign = Math.copySign(1f, x);
+ final float factor = (float) Math.pow(10.0f, scale) * sign;
+ return (float) roundUnscaled(x * factor, sign, roundingMethod) / factor;
+ }
+
+ /**
+ * Rounds the given non-negative value to the "nearest" integer. Nearest is
+ * determined by the rounding method specified. Rounding methods are defined
+ * in {@link BigDecimal}.
+ *
+ * @param unscaled Value to round.
+ * @param sign Sign of the original, scaled value.
+ * @param roundingMethod Rounding method, as defined in {@link BigDecimal}.
+ * @return the rounded value.
+ * @throws ArithmeticException if an exact operation is required but result is not exact
+ * @throws IllegalArgumentException if {@code roundingMethod} is not a valid rounding method.
+ */
+ private static double roundUnscaled(double unscaled,
+ double sign,
+ int roundingMethod) {
+ switch (roundingMethod) {
+ case BigDecimal.ROUND_CEILING :
+ if (sign == -1) {
+ unscaled = Math.floor(Math.nextAfter(unscaled, Double.NEGATIVE_INFINITY));
+ } else {
+ unscaled = Math.ceil(Math.nextAfter(unscaled, Double.POSITIVE_INFINITY));
+ }
+ break;
+ case BigDecimal.ROUND_DOWN :
+ unscaled = Math.floor(Math.nextAfter(unscaled, Double.NEGATIVE_INFINITY));
+ break;
+ case BigDecimal.ROUND_FLOOR :
+ if (sign == -1) {
+ unscaled = Math.ceil(Math.nextAfter(unscaled, Double.POSITIVE_INFINITY));
+ } else {
+ unscaled = Math.floor(Math.nextAfter(unscaled, Double.NEGATIVE_INFINITY));
+ }
+ break;
+ case BigDecimal.ROUND_HALF_DOWN : {
+ unscaled = Math.nextAfter(unscaled, Double.NEGATIVE_INFINITY);
+ double fraction = unscaled - Math.floor(unscaled);
+ if (fraction > 0.5) {
+ unscaled = Math.ceil(unscaled);
+ } else {
+ unscaled = Math.floor(unscaled);
+ }
+ break;
+ }
+ case BigDecimal.ROUND_HALF_EVEN : {
+ double fraction = unscaled - Math.floor(unscaled);
+ if (fraction > 0.5) {
+ unscaled = Math.ceil(unscaled);
+ } else if (fraction < 0.5) {
+ unscaled = Math.floor(unscaled);
+ } else {
+ // The following equality test is intentional and needed for rounding purposes
+ if (Math.floor(unscaled) / 2.0 == Math.floor(Math.floor(unscaled) / 2.0)) { // even
+ unscaled = Math.floor(unscaled);
+ } else { // odd
+ unscaled = Math.ceil(unscaled);
+ }
+ }
+ break;
+ }
+ case BigDecimal.ROUND_HALF_UP : {
+ unscaled = Math.nextAfter(unscaled, Double.POSITIVE_INFINITY);
+ double fraction = unscaled - Math.floor(unscaled);
+ if (fraction >= 0.5) {
+ unscaled = Math.ceil(unscaled);
+ } else {
+ unscaled = Math.floor(unscaled);
+ }
+ break;
+ }
+ case BigDecimal.ROUND_UNNECESSARY :
+ if (unscaled != Math.floor(unscaled)) {
+ throw new ArithmeticException();
+ }
+ break;
+ case BigDecimal.ROUND_UP :
+ // do not round if the discarded fraction is equal to zero
+ if (unscaled != Math.floor(unscaled)) {
+ unscaled = Math.ceil(Math.nextAfter(unscaled, Double.POSITIVE_INFINITY));
+ }
+ break;
+ default :
+ throw new IllegalArgumentException("Unhandled rounding method: " + roundingMethod);
+ }
+ return unscaled;
+ }
+
+
+ /**
+ * Computes a number {@code delta} close to {@code originalDelta} with
+ * the property that <pre><code>
+ * x + delta - x
+ * </code></pre>
+ * is exactly machine-representable.
+ * This is useful when computing numerical derivatives, in order to reduce
+ * roundoff errors.
+ *
+ * @param x Value.
+ * @param originalDelta Offset value.
+ * @return a number {@code delta} so that {@code x + delta} and {@code x}
+ * differ by a representable floating number.
+ */
+ public static double representableDelta(double x,
+ double originalDelta) {
+ return x + originalDelta - x;
+ }
+}
[03/31] commons-numbers git commit: Cleanup (massive delete).
Posted by er...@apache.org.
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/java/org/apache/commons/complex/ComplexTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/complex/ComplexTest.java b/src/test/java/org/apache/commons/complex/ComplexTest.java
deleted file mode 100644
index 7617128..0000000
--- a/src/test/java/org/apache/commons/complex/ComplexTest.java
+++ /dev/null
@@ -1,1477 +0,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.
- */
-
-package org.apache.commons.complex;
-
-import java.util.List;
-
-import org.apache.commons.complex.Complex;
-import org.apache.commons.complex.ComplexUtils;
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Test;
-
-
-/**
- */
-public class ComplexTest {
-
-
- private double inf = Double.POSITIVE_INFINITY;
- private double neginf = Double.NEGATIVE_INFINITY;
- private double nan = Double.NaN;
- private double pi = Math.PI;
- private Complex oneInf = new Complex(1, inf);
- private Complex oneNegInf = new Complex(1, neginf);
- private Complex infOne = new Complex(inf, 1);
- private Complex infZero = new Complex(inf, 0);
- private Complex infNaN = new Complex(inf, nan);
- private Complex infNegInf = new Complex(inf, neginf);
- private Complex infInf = new Complex(inf, inf);
- private Complex negInfInf = new Complex(neginf, inf);
- private Complex negInfZero = new Complex(neginf, 0);
- private Complex negInfOne = new Complex(neginf, 1);
- private Complex negInfNaN = new Complex(neginf, nan);
- private Complex negInfNegInf = new Complex(neginf, neginf);
- private Complex oneNaN = new Complex(1, nan);
- private Complex zeroInf = new Complex(0, inf);
- private Complex zeroNaN = new Complex(0, nan);
- private Complex nanInf = new Complex(nan, inf);
- private Complex nanNegInf = new Complex(nan, neginf);
- private Complex nanZero = new Complex(nan, 0);
-
- @Test
- public void testConstructor() {
- Complex z = new Complex(3.0, 4.0);
- Assert.assertEquals(3.0, z.getReal(), 1.0e-5);
- Assert.assertEquals(4.0, z.getImaginary(), 1.0e-5);
- }
-
- @Test
- public void testConstructorNaN() {
- Complex z = new Complex(3.0, Double.NaN);
- Assert.assertTrue(z.isNaN());
-
- z = new Complex(nan, 4.0);
- Assert.assertTrue(z.isNaN());
-
- z = new Complex(3.0, 4.0);
- Assert.assertFalse(z.isNaN());
- }
-
- @Test
- public void testAbs() {
- Complex z = new Complex(3.0, 4.0);
- Assert.assertEquals(5.0, z.abs(), 1.0e-5);
- }
-
- @Test
- public void testAbsNaN() {
- Assert.assertTrue(Double.isNaN(Complex.NaN.abs()));
- Complex z = new Complex(inf, nan);
- Assert.assertTrue(Double.isNaN(z.abs()));
- }
-
- @Test
- public void testAbsInfinite() {
- Complex z = new Complex(inf, 0);
- Assert.assertEquals(inf, z.abs(), 0);
- z = new Complex(0, neginf);
- Assert.assertEquals(inf, z.abs(), 0);
- z = new Complex(inf, neginf);
- Assert.assertEquals(inf, z.abs(), 0);
- }
-
- @Test
- public void testAdd() {
- Complex x = new Complex(3.0, 4.0);
- Complex y = new Complex(5.0, 6.0);
- Complex z = x.add(y);
- Assert.assertEquals(8.0, z.getReal(), 1.0e-5);
- Assert.assertEquals(10.0, z.getImaginary(), 1.0e-5);
- }
-
- @Test
- public void testAddNaN() {
- Complex x = new Complex(3.0, 4.0);
- Complex z = x.add(Complex.NaN);
- Assert.assertSame(Complex.NaN, z);
- z = new Complex(1, nan);
- Complex w = x.add(z);
- Assert.assertSame(Complex.NaN, w);
- }
-
- @Test
- public void testAddInf() {
- Complex x = new Complex(1, 1);
- Complex z = new Complex(inf, 0);
- Complex w = x.add(z);
- Assert.assertEquals(w.getImaginary(), 1, 0);
- Assert.assertEquals(inf, w.getReal(), 0);
-
- x = new Complex(neginf, 0);
- Assert.assertTrue(Double.isNaN(x.add(z).getReal()));
- }
-
-
- @Test
- public void testScalarAdd() {
- Complex x = new Complex(3.0, 4.0);
- double yDouble = 2.0;
- Complex yComplex = new Complex(yDouble);
- Assert.assertEquals(x.add(yComplex), x.add(yDouble));
- }
-
- @Test
- public void testScalarAddNaN() {
- Complex x = new Complex(3.0, 4.0);
- double yDouble = Double.NaN;
- Complex yComplex = new Complex(yDouble);
- Assert.assertEquals(x.add(yComplex), x.add(yDouble));
- }
-
- @Test
- public void testScalarAddInf() {
- Complex x = new Complex(1, 1);
- double yDouble = Double.POSITIVE_INFINITY;
-
- Complex yComplex = new Complex(yDouble);
- Assert.assertEquals(x.add(yComplex), x.add(yDouble));
-
- x = new Complex(neginf, 0);
- Assert.assertEquals(x.add(yComplex), x.add(yDouble));
- }
-
- @Test
- public void testConjugate() {
- Complex x = new Complex(3.0, 4.0);
- Complex z = x.conjugate();
- Assert.assertEquals(3.0, z.getReal(), 1.0e-5);
- Assert.assertEquals(-4.0, z.getImaginary(), 1.0e-5);
- }
-
- @Test
- public void testConjugateNaN() {
- Complex z = Complex.NaN.conjugate();
- Assert.assertTrue(z.isNaN());
- }
-
- @Test
- public void testConjugateInfiinite() {
- Complex z = new Complex(0, inf);
- Assert.assertEquals(neginf, z.conjugate().getImaginary(), 0);
- z = new Complex(0, neginf);
- Assert.assertEquals(inf, z.conjugate().getImaginary(), 0);
- }
-
- @Test
- public void testDivide() {
- Complex x = new Complex(3.0, 4.0);
- Complex y = new Complex(5.0, 6.0);
- Complex z = x.divide(y);
- Assert.assertEquals(39.0 / 61.0, z.getReal(), 1.0e-5);
- Assert.assertEquals(2.0 / 61.0, z.getImaginary(), 1.0e-5);
- }
-
- @Test
- public void testDivideReal() {
- Complex x = new Complex(2d, 3d);
- Complex y = new Complex(2d, 0d);
- Assert.assertEquals(new Complex(1d, 1.5), x.divide(y));
-
- }
-
- @Test
- public void testDivideImaginary() {
- Complex x = new Complex(2d, 3d);
- Complex y = new Complex(0d, 2d);
- Assert.assertEquals(new Complex(1.5d, -1d), x.divide(y));
- }
-
- @Test
- public void testDivideInf() {
- Complex x = new Complex(3, 4);
- Complex w = new Complex(neginf, inf);
- Assert.assertTrue(x.divide(w).equals(Complex.ZERO));
-
- Complex z = w.divide(x);
- Assert.assertTrue(Double.isNaN(z.getReal()));
- Assert.assertEquals(inf, z.getImaginary(), 0);
-
- w = new Complex(inf, inf);
- z = w.divide(x);
- Assert.assertTrue(Double.isNaN(z.getImaginary()));
- Assert.assertEquals(inf, z.getReal(), 0);
-
- w = new Complex(1, inf);
- z = w.divide(w);
- Assert.assertTrue(Double.isNaN(z.getReal()));
- Assert.assertTrue(Double.isNaN(z.getImaginary()));
- }
-
- @Test
- public void testDivideZero() {
- Complex x = new Complex(3.0, 4.0);
- Complex z = x.divide(Complex.ZERO);
- // Assert.assertEquals(z, Complex.INF); // See MATH-657
- Assert.assertEquals(z, Complex.NaN);
- }
-
- @Test
- public void testDivideZeroZero() {
- Complex x = new Complex(0.0, 0.0);
- Complex z = x.divide(Complex.ZERO);
- Assert.assertEquals(z, Complex.NaN);
- }
-
- @Test
- public void testDivideNaN() {
- Complex x = new Complex(3.0, 4.0);
- Complex z = x.divide(Complex.NaN);
- Assert.assertTrue(z.isNaN());
- }
-
- @Test
- public void testDivideNaNInf() {
- Complex z = oneInf.divide(Complex.ONE);
- Assert.assertTrue(Double.isNaN(z.getReal()));
- Assert.assertEquals(inf, z.getImaginary(), 0);
-
- z = negInfNegInf.divide(oneNaN);
- Assert.assertTrue(Double.isNaN(z.getReal()));
- Assert.assertTrue(Double.isNaN(z.getImaginary()));
-
- z = negInfInf.divide(Complex.ONE);
- Assert.assertTrue(Double.isNaN(z.getReal()));
- Assert.assertTrue(Double.isNaN(z.getImaginary()));
- }
-
- @Test
- public void testScalarDivide() {
- Complex x = new Complex(3.0, 4.0);
- double yDouble = 2.0;
- Complex yComplex = new Complex(yDouble);
- Assert.assertEquals(x.divide(yComplex), x.divide(yDouble));
- }
-
- @Test
- public void testScalarDivideNaN() {
- Complex x = new Complex(3.0, 4.0);
- double yDouble = Double.NaN;
- Complex yComplex = new Complex(yDouble);
- Assert.assertEquals(x.divide(yComplex), x.divide(yDouble));
- }
-
- @Test
- public void testScalarDivideZero() {
- Complex x = new Complex(1,1);
- TestUtils.assertEquals(x.divide(Complex.ZERO), x.divide(0), 0);
- }
-
- @Test
- public void testReciprocal() {
- Complex z = new Complex(5.0, 6.0);
- Complex act = z.reciprocal();
- double expRe = 5.0 / 61.0;
- double expIm = -6.0 / 61.0;
- Assert.assertEquals(expRe, act.getReal(), Math.ulp(expRe));
- Assert.assertEquals(expIm, act.getImaginary(), Math.ulp(expIm));
- }
-
- @Test
- public void testReciprocalReal() {
- Complex z = new Complex(-2.0, 0.0);
- Assert.assertTrue(Complex.equals(new Complex(-0.5, 0.0), z.reciprocal()));
- }
-
- @Test
- public void testReciprocalImaginary() {
- Complex z = new Complex(0.0, -2.0);
- Assert.assertEquals(new Complex(0.0, 0.5), z.reciprocal());
- }
-
- @Test
- public void testReciprocalInf() {
- Complex z = new Complex(neginf, inf);
- Assert.assertTrue(z.reciprocal().equals(Complex.ZERO));
-
- z = new Complex(1, inf).reciprocal();
- Assert.assertEquals(z, Complex.ZERO);
- }
-
- @Test
- public void testReciprocalZero() {
- Assert.assertEquals(Complex.ZERO.reciprocal(), Complex.INF);
- }
-
- @Test
- public void testReciprocalNaN() {
- Assert.assertTrue(Complex.NaN.reciprocal().isNaN());
- }
-
- @Test
- public void testMultiply() {
- Complex x = new Complex(3.0, 4.0);
- Complex y = new Complex(5.0, 6.0);
- Complex z = x.multiply(y);
- Assert.assertEquals(-9.0, z.getReal(), 1.0e-5);
- Assert.assertEquals(38.0, z.getImaginary(), 1.0e-5);
- }
-
- @Test
- public void testMultiplyNaN() {
- Complex x = new Complex(3.0, 4.0);
- Complex z = x.multiply(Complex.NaN);
- Assert.assertSame(Complex.NaN, z);
- z = Complex.NaN.multiply(5);
- Assert.assertSame(Complex.NaN, z);
- }
-
- @Test
- public void testMultiplyInfInf() {
- // Assert.assertTrue(infInf.multiply(infInf).isNaN()); // MATH-620
- Assert.assertTrue(infInf.multiply(infInf).isInfinite());
- }
-
- @Test
- public void testMultiplyNaNInf() {
- Complex z = new Complex(1,1);
- Complex w = z.multiply(infOne);
- Assert.assertEquals(w.getReal(), inf, 0);
- Assert.assertEquals(w.getImaginary(), inf, 0);
-
- // [MATH-164]
- Assert.assertTrue(new Complex( 1,0).multiply(infInf).equals(Complex.INF));
- Assert.assertTrue(new Complex(-1,0).multiply(infInf).equals(Complex.INF));
- Assert.assertTrue(new Complex( 1,0).multiply(negInfZero).equals(Complex.INF));
-
- w = oneInf.multiply(oneNegInf);
- Assert.assertEquals(w.getReal(), inf, 0);
- Assert.assertEquals(w.getImaginary(), inf, 0);
-
- w = negInfNegInf.multiply(oneNaN);
- Assert.assertTrue(Double.isNaN(w.getReal()));
- Assert.assertTrue(Double.isNaN(w.getImaginary()));
-
- z = new Complex(1, neginf);
- Assert.assertSame(Complex.INF, z.multiply(z));
- }
-
- @Test
- public void testScalarMultiply() {
- Complex x = new Complex(3.0, 4.0);
- double yDouble = 2.0;
- Complex yComplex = new Complex(yDouble);
- Assert.assertEquals(x.multiply(yComplex), x.multiply(yDouble));
- int zInt = -5;
- Complex zComplex = new Complex(zInt);
- Assert.assertEquals(x.multiply(zComplex), x.multiply(zInt));
- }
-
- @Test
- public void testScalarMultiplyNaN() {
- Complex x = new Complex(3.0, 4.0);
- double yDouble = Double.NaN;
- Complex yComplex = new Complex(yDouble);
- Assert.assertEquals(x.multiply(yComplex), x.multiply(yDouble));
- }
-
- @Test
- public void testScalarMultiplyInf() {
- Complex x = new Complex(1, 1);
- double yDouble = Double.POSITIVE_INFINITY;
- Complex yComplex = new Complex(yDouble);
- Assert.assertEquals(x.multiply(yComplex), x.multiply(yDouble));
-
- yDouble = Double.NEGATIVE_INFINITY;
- yComplex = new Complex(yDouble);
- Assert.assertEquals(x.multiply(yComplex), x.multiply(yDouble));
- }
-
- @Test
- public void testNegate() {
- Complex x = new Complex(3.0, 4.0);
- Complex z = x.negate();
- Assert.assertEquals(-3.0, z.getReal(), 1.0e-5);
- Assert.assertEquals(-4.0, z.getImaginary(), 1.0e-5);
- }
-
- @Test
- public void testNegateNaN() {
- Complex z = Complex.NaN.negate();
- Assert.assertTrue(z.isNaN());
- }
-
- @Test
- public void testSubtract() {
- Complex x = new Complex(3.0, 4.0);
- Complex y = new Complex(5.0, 6.0);
- Complex z = x.subtract(y);
- Assert.assertEquals(-2.0, z.getReal(), 1.0e-5);
- Assert.assertEquals(-2.0, z.getImaginary(), 1.0e-5);
- }
-
- @Test
- public void testSubtractNaN() {
- Complex x = new Complex(3.0, 4.0);
- Complex z = x.subtract(Complex.NaN);
- Assert.assertSame(Complex.NaN, z);
- z = new Complex(1, nan);
- Complex w = x.subtract(z);
- Assert.assertSame(Complex.NaN, w);
- }
-
- @Test
- public void testSubtractInf() {
- Complex x = new Complex(1, 1);
- Complex z = new Complex(neginf, 0);
- Complex w = x.subtract(z);
- Assert.assertEquals(w.getImaginary(), 1, 0);
- Assert.assertEquals(inf, w.getReal(), 0);
-
- x = new Complex(neginf, 0);
- Assert.assertTrue(Double.isNaN(x.subtract(z).getReal()));
- }
-
- @Test
- public void testScalarSubtract() {
- Complex x = new Complex(3.0, 4.0);
- double yDouble = 2.0;
- Complex yComplex = new Complex(yDouble);
- Assert.assertEquals(x.subtract(yComplex), x.subtract(yDouble));
- }
-
- @Test
- public void testScalarSubtractNaN() {
- Complex x = new Complex(3.0, 4.0);
- double yDouble = Double.NaN;
- Complex yComplex = new Complex(yDouble);
- Assert.assertEquals(x.subtract(yComplex), x.subtract(yDouble));
- }
-
- @Test
- public void testScalarSubtractInf() {
- Complex x = new Complex(1, 1);
- double yDouble = Double.POSITIVE_INFINITY;
- Complex yComplex = new Complex(yDouble);
- Assert.assertEquals(x.subtract(yComplex), x.subtract(yDouble));
-
- x = new Complex(neginf, 0);
- Assert.assertEquals(x.subtract(yComplex), x.subtract(yDouble));
- }
-
-
- @Test
- public void testEqualsNull() {
- Complex x = new Complex(3.0, 4.0);
- Assert.assertFalse(x.equals(null));
- }
-
- @Test(expected=NullPointerException.class)
- public void testFloatingPointEqualsPrecondition1() {
- Complex.equals(new Complex(3.0, 4.0), null, 3);
- }
- @Test(expected=NullPointerException.class)
- public void testFloatingPointEqualsPrecondition2() {
- Complex.equals(null, new Complex(3.0, 4.0), 3);
- }
-
- @Test
- public void testEqualsClass() {
- Complex x = new Complex(3.0, 4.0);
- Assert.assertFalse(x.equals(this));
- }
-
- @Test
- public void testEqualsSame() {
- Complex x = new Complex(3.0, 4.0);
- Assert.assertTrue(x.equals(x));
- }
-
- @Test
- public void testFloatingPointEquals() {
- double re = -3.21;
- double im = 456789e10;
-
- final Complex x = new Complex(re, im);
- Complex y = new Complex(re, im);
-
- Assert.assertTrue(x.equals(y));
- Assert.assertTrue(Complex.equals(x, y));
-
- final int maxUlps = 5;
- for (int i = 0; i < maxUlps; i++) {
- re = Math.nextUp(re);
- im = Math.nextUp(im);
- }
- y = new Complex(re, im);
- Assert.assertTrue(Complex.equals(x, y, maxUlps));
-
- re = Math.nextUp(re);
- im = Math.nextUp(im);
- y = new Complex(re, im);
- Assert.assertFalse(Complex.equals(x, y, maxUlps));
- }
-
- @Test
- public void testFloatingPointEqualsNaN() {
- Complex c = new Complex(Double.NaN, 1);
- Assert.assertFalse(Complex.equals(c, c));
-
- c = new Complex(1, Double.NaN);
- Assert.assertFalse(Complex.equals(c, c));
- }
-
- @Test
- public void testFloatingPointEqualsWithAllowedDelta() {
- final double re = 153.0000;
- final double im = 152.9375;
- final double tol1 = 0.0625;
- final Complex x = new Complex(re, im);
- final Complex y = new Complex(re + tol1, im + tol1);
- Assert.assertTrue(Complex.equals(x, y, tol1));
-
- final double tol2 = 0.0624;
- Assert.assertFalse(Complex.equals(x, y, tol2));
- }
-
- @Test
- public void testFloatingPointEqualsWithAllowedDeltaNaN() {
- final Complex x = new Complex(0, Double.NaN);
- final Complex y = new Complex(Double.NaN, 0);
- Assert.assertFalse(Complex.equals(x, Complex.ZERO, 0.1));
- Assert.assertFalse(Complex.equals(x, x, 0.1));
- Assert.assertFalse(Complex.equals(x, y, 0.1));
- }
-
- @Test
- public void testFloatingPointEqualsWithRelativeTolerance() {
- final double tol = 1e-4;
- final double re = 1;
- final double im = 1e10;
-
- final double f = 1 + tol;
- final Complex x = new Complex(re, im);
- final Complex y = new Complex(re * f, im * f);
- Assert.assertTrue(Complex.equalsWithRelativeTolerance(x, y, tol));
- }
-
- @Test
- public void testFloatingPointEqualsWithRelativeToleranceNaN() {
- final Complex x = new Complex(0, Double.NaN);
- final Complex y = new Complex(Double.NaN, 0);
- Assert.assertFalse(Complex.equalsWithRelativeTolerance(x, Complex.ZERO, 0.1));
- Assert.assertFalse(Complex.equalsWithRelativeTolerance(x, x, 0.1));
- Assert.assertFalse(Complex.equalsWithRelativeTolerance(x, y, 0.1));
- }
-
- @Test
- public void testEqualsTrue() {
- Complex x = new Complex(3.0, 4.0);
- Complex y = new Complex(3.0, 4.0);
- Assert.assertTrue(x.equals(y));
- }
-
- @Test
- public void testEqualsRealDifference() {
- Complex x = new Complex(0.0, 0.0);
- Complex y = new Complex(0.0 + Double.MIN_VALUE, 0.0);
- Assert.assertFalse(x.equals(y));
- }
-
- @Test
- public void testEqualsImaginaryDifference() {
- Complex x = new Complex(0.0, 0.0);
- Complex y = new Complex(0.0, 0.0 + Double.MIN_VALUE);
- Assert.assertFalse(x.equals(y));
- }
-
- @Test
- public void testEqualsNaN() {
- Complex realNaN = new Complex(Double.NaN, 0.0);
- Complex imaginaryNaN = new Complex(0.0, Double.NaN);
- Complex complexNaN = Complex.NaN;
- Assert.assertTrue(realNaN.equals(imaginaryNaN));
- Assert.assertTrue(imaginaryNaN.equals(complexNaN));
- Assert.assertTrue(realNaN.equals(complexNaN));
- }
-
- @Test
- public void testHashCode() {
- Complex x = new Complex(0.0, 0.0);
- Complex y = new Complex(0.0, 0.0 + Double.MIN_VALUE);
- Assert.assertFalse(x.hashCode()==y.hashCode());
- y = new Complex(0.0 + Double.MIN_VALUE, 0.0);
- Assert.assertFalse(x.hashCode()==y.hashCode());
- Complex realNaN = new Complex(Double.NaN, 0.0);
- Complex imaginaryNaN = new Complex(0.0, Double.NaN);
- Assert.assertEquals(realNaN.hashCode(), imaginaryNaN.hashCode());
- Assert.assertEquals(imaginaryNaN.hashCode(), Complex.NaN.hashCode());
-
- // MATH-1118
- // "equals" and "hashCode" must be compatible: if two objects have
- // different hash codes, "equals" must return false.
- final String msg = "'equals' not compatible with 'hashCode'";
-
- x = new Complex(0.0, 0.0);
- y = new Complex(0.0, -0.0);
- Assert.assertTrue(x.hashCode() != y.hashCode());
- Assert.assertFalse(msg, x.equals(y));
-
- x = new Complex(0.0, 0.0);
- y = new Complex(-0.0, 0.0);
- Assert.assertTrue(x.hashCode() != y.hashCode());
- Assert.assertFalse(msg, x.equals(y));
- }
-
- @Test
- public void testAcos() {
- Complex z = new Complex(3, 4);
- Complex expected = new Complex(0.936812, -2.30551);
- TestUtils.assertEquals(expected, z.acos(), 1.0e-5);
- TestUtils.assertEquals(new Complex(Math.acos(0), 0),
- Complex.ZERO.acos(), 1.0e-12);
- }
-
- @Test
- public void testAcosInf() {
- TestUtils.assertSame(Complex.NaN, oneInf.acos());
- TestUtils.assertSame(Complex.NaN, oneNegInf.acos());
- TestUtils.assertSame(Complex.NaN, infOne.acos());
- TestUtils.assertSame(Complex.NaN, negInfOne.acos());
- TestUtils.assertSame(Complex.NaN, infInf.acos());
- TestUtils.assertSame(Complex.NaN, infNegInf.acos());
- TestUtils.assertSame(Complex.NaN, negInfInf.acos());
- TestUtils.assertSame(Complex.NaN, negInfNegInf.acos());
- }
-
- @Test
- public void testAcosNaN() {
- Assert.assertTrue(Complex.NaN.acos().isNaN());
- }
-
- @Test
- public void testAsin() {
- Complex z = new Complex(3, 4);
- Complex expected = new Complex(0.633984, 2.30551);
- TestUtils.assertEquals(expected, z.asin(), 1.0e-5);
- }
-
- @Test
- public void testAsinNaN() {
- Assert.assertTrue(Complex.NaN.asin().isNaN());
- }
-
- @Test
- public void testAsinInf() {
- TestUtils.assertSame(Complex.NaN, oneInf.asin());
- TestUtils.assertSame(Complex.NaN, oneNegInf.asin());
- TestUtils.assertSame(Complex.NaN, infOne.asin());
- TestUtils.assertSame(Complex.NaN, negInfOne.asin());
- TestUtils.assertSame(Complex.NaN, infInf.asin());
- TestUtils.assertSame(Complex.NaN, infNegInf.asin());
- TestUtils.assertSame(Complex.NaN, negInfInf.asin());
- TestUtils.assertSame(Complex.NaN, negInfNegInf.asin());
- }
-
-
- @Test
- public void testAtan() {
- Complex z = new Complex(3, 4);
- Complex expected = new Complex(1.44831, 0.158997);
- TestUtils.assertEquals(expected, z.atan(), 1.0e-5);
- }
-
- @Test
- public void testAtanInf() {
- TestUtils.assertSame(Complex.NaN, oneInf.atan());
- TestUtils.assertSame(Complex.NaN, oneNegInf.atan());
- TestUtils.assertSame(Complex.NaN, infOne.atan());
- TestUtils.assertSame(Complex.NaN, negInfOne.atan());
- TestUtils.assertSame(Complex.NaN, infInf.atan());
- TestUtils.assertSame(Complex.NaN, infNegInf.atan());
- TestUtils.assertSame(Complex.NaN, negInfInf.atan());
- TestUtils.assertSame(Complex.NaN, negInfNegInf.atan());
- }
-
- @Test
- public void testAtanI() {
- Assert.assertTrue(Complex.I.atan().isNaN());
- }
-
- @Test
- public void testAtanNaN() {
- Assert.assertTrue(Complex.NaN.atan().isNaN());
- }
-
- @Test
- public void testCos() {
- Complex z = new Complex(3, 4);
- Complex expected = new Complex(-27.03495, -3.851153);
- TestUtils.assertEquals(expected, z.cos(), 1.0e-5);
- }
-
- @Test
- public void testCosNaN() {
- Assert.assertTrue(Complex.NaN.cos().isNaN());
- }
-
- @Test
- public void testCosInf() {
- TestUtils.assertSame(infNegInf, oneInf.cos());
- TestUtils.assertSame(infInf, oneNegInf.cos());
- TestUtils.assertSame(Complex.NaN, infOne.cos());
- TestUtils.assertSame(Complex.NaN, negInfOne.cos());
- TestUtils.assertSame(Complex.NaN, infInf.cos());
- TestUtils.assertSame(Complex.NaN, infNegInf.cos());
- TestUtils.assertSame(Complex.NaN, negInfInf.cos());
- TestUtils.assertSame(Complex.NaN, negInfNegInf.cos());
- }
-
- @Test
- public void testCosh() {
- Complex z = new Complex(3, 4);
- Complex expected = new Complex(-6.58066, -7.58155);
- TestUtils.assertEquals(expected, z.cosh(), 1.0e-5);
- }
-
- @Test
- public void testCoshNaN() {
- Assert.assertTrue(Complex.NaN.cosh().isNaN());
- }
-
- @Test
- public void testCoshInf() {
- TestUtils.assertSame(Complex.NaN, oneInf.cosh());
- TestUtils.assertSame(Complex.NaN, oneNegInf.cosh());
- TestUtils.assertSame(infInf, infOne.cosh());
- TestUtils.assertSame(infNegInf, negInfOne.cosh());
- TestUtils.assertSame(Complex.NaN, infInf.cosh());
- TestUtils.assertSame(Complex.NaN, infNegInf.cosh());
- TestUtils.assertSame(Complex.NaN, negInfInf.cosh());
- TestUtils.assertSame(Complex.NaN, negInfNegInf.cosh());
- }
-
- @Test
- public void testExp() {
- final double tol = Math.ulp(1d);
- Complex z = new Complex(3, 4);
- Complex expected = new Complex(-13.12878, -15.20078);
- TestUtils.assertEquals(expected, z.exp(), 1.0e-5);
- TestUtils.assertEquals(Complex.ONE,
- Complex.ZERO.exp(), tol);
- Complex iPi = Complex.I.multiply(new Complex(pi,0));
- TestUtils.assertEquals(Complex.ONE.negate(),
- iPi.exp(), tol);
- }
-
- @Test
- public void testExpNaN() {
- Assert.assertTrue(Complex.NaN.exp().isNaN());
- }
-
- @Test
- public void testExpInf1() {
- TestUtils.assertSame(Complex.NaN, oneInf.exp());
- }
-
- @Test
- public void testExpInf2() {
- TestUtils.assertSame(Complex.NaN, oneNegInf.exp());
- }
-
- @Test
- public void testExpInf3() {
- TestUtils.assertSame(infInf, infOne.exp());
- }
-
- @Test
- @Ignore
- public void testJava() {// TODO more debug
- System.out.println(">>testJava()");
- // MathTest#testExpSpecialCases() checks the following:
- // Assert.assertEquals("exp of -infinity should be 0.0", 0.0, Math.exp(Double.NEGATIVE_INFINITY), Precision.EPSILON);
- // Let's check how well Math works:
- System.out.println("Math.exp="+Math.exp(Double.NEGATIVE_INFINITY));
- String props[] = {
- "java.version", // Java Runtime Environment version
- "java.vendor", // Java Runtime Environment vendor
- "java.vm.specification.version", // Java Virtual Machine specification version
- "java.vm.specification.vendor", // Java Virtual Machine specification vendor
- "java.vm.specification.name", // Java Virtual Machine specification name
- "java.vm.version", // Java Virtual Machine implementation version
- "java.vm.vendor", // Java Virtual Machine implementation vendor
- "java.vm.name", // Java Virtual Machine implementation name
- "java.specification.version", // Java Runtime Environment specification version
- "java.specification.vendor", // Java Runtime Environment specification vendor
- "java.specification.name", // Java Runtime Environment specification name
- "java.class.version", // Java class format version number
- };
- for(String t : props) {
- System.out.println(t + "=" + System.getProperty(t));
- }
- System.out.println("<<testJava()");
- }
-
- @Test
- public void testExpInf4() {
- final Complex exp = negInfOne.exp();
- TestUtils.assertSame(Complex.ZERO, exp);
- }
-
- @Test
- public void testExpInf5() {
- TestUtils.assertSame(Complex.NaN, infInf.exp());
- }
-
- @Test
- public void testExpInf6() {
- TestUtils.assertSame(Complex.NaN, infNegInf.exp());
- }
-
- @Test
- public void testExpInf7() {
- TestUtils.assertSame(Complex.NaN, negInfInf.exp());
- }
-
- @Test
- public void testExpInf8() {
- TestUtils.assertSame(Complex.NaN, negInfNegInf.exp());
- }
-
- @Test
- public void testLog() {
- Complex z = new Complex(3, 4);
- Complex expected = new Complex(1.60944, 0.927295);
- TestUtils.assertEquals(expected, z.log(), 1.0e-5);
- }
-
- @Test
- public void testLogNaN() {
- Assert.assertTrue(Complex.NaN.log().isNaN());
- }
-
- @Test
- public void testLogInf() {
- final double tol = Math.ulp(1d);
- TestUtils.assertEquals(new Complex(inf, pi / 2),
- oneInf.log(), tol);
- TestUtils.assertEquals(new Complex(inf, -pi / 2),
- oneNegInf.log(), tol);
- TestUtils.assertEquals(infZero, infOne.log(), tol);
- TestUtils.assertEquals(new Complex(inf, pi),
- negInfOne.log(), tol);
- TestUtils.assertEquals(new Complex(inf, pi / 4),
- infInf.log(), tol);
- TestUtils.assertEquals(new Complex(inf, -pi / 4),
- infNegInf.log(), tol);
- TestUtils.assertEquals(new Complex(inf, 3d * pi / 4),
- negInfInf.log(), tol);
- TestUtils.assertEquals(new Complex(inf, - 3d * pi / 4),
- negInfNegInf.log(), tol);
- }
-
- @Test
- public void testLogZero() {
- TestUtils.assertSame(negInfZero, Complex.ZERO.log());
- }
-
- @Test
- public void testPow() {
- Complex x = new Complex(3, 4);
- Complex y = new Complex(5, 6);
- Complex expected = new Complex(-1.860893, 11.83677);
- TestUtils.assertEquals(expected, x.pow(y), 1.0e-5);
- }
-
- @Test
- public void testPowNaNBase() {
- Complex x = new Complex(3, 4);
- Assert.assertTrue(Complex.NaN.pow(x).isNaN());
- }
-
- @Test
- public void testPowNaNExponent() {
- Complex x = new Complex(3, 4);
- Assert.assertTrue(x.pow(Complex.NaN).isNaN());
- }
-
- @Test
- public void testPowInf() {
- TestUtils.assertSame(Complex.NaN,Complex.ONE.pow(oneInf));
- TestUtils.assertSame(Complex.NaN,Complex.ONE.pow(oneNegInf));
- TestUtils.assertSame(Complex.NaN,Complex.ONE.pow(infOne));
- TestUtils.assertSame(Complex.NaN,Complex.ONE.pow(infInf));
- TestUtils.assertSame(Complex.NaN,Complex.ONE.pow(infNegInf));
- TestUtils.assertSame(Complex.NaN,Complex.ONE.pow(negInfInf));
- TestUtils.assertSame(Complex.NaN,Complex.ONE.pow(negInfNegInf));
- TestUtils.assertSame(Complex.NaN,infOne.pow(Complex.ONE));
- TestUtils.assertSame(Complex.NaN,negInfOne.pow(Complex.ONE));
- TestUtils.assertSame(Complex.NaN,infInf.pow(Complex.ONE));
- TestUtils.assertSame(Complex.NaN,infNegInf.pow(Complex.ONE));
- TestUtils.assertSame(Complex.NaN,negInfInf.pow(Complex.ONE));
- TestUtils.assertSame(Complex.NaN,negInfNegInf.pow(Complex.ONE));
- TestUtils.assertSame(Complex.NaN,negInfNegInf.pow(infNegInf));
- TestUtils.assertSame(Complex.NaN,negInfNegInf.pow(negInfNegInf));
- TestUtils.assertSame(Complex.NaN,negInfNegInf.pow(infInf));
- TestUtils.assertSame(Complex.NaN,infInf.pow(infNegInf));
- TestUtils.assertSame(Complex.NaN,infInf.pow(negInfNegInf));
- TestUtils.assertSame(Complex.NaN,infInf.pow(infInf));
- TestUtils.assertSame(Complex.NaN,infNegInf.pow(infNegInf));
- TestUtils.assertSame(Complex.NaN,infNegInf.pow(negInfNegInf));
- TestUtils.assertSame(Complex.NaN,infNegInf.pow(infInf));
- }
-
- @Test
- public void testPowZero() {
- final double tol = Math.ulp(1d);
- TestUtils.assertEquals(Complex.ZERO,
- Complex.ZERO.pow(Complex.ONE), tol);
- TestUtils.assertEquals(Complex.ZERO,
- Complex.ZERO.pow(new Complex(2, 0)), tol);
- TestUtils.assertSame(Complex.NaN,
- Complex.ZERO.pow(Complex.ZERO));
- TestUtils.assertSame(Complex.NaN,
- Complex.ZERO.pow(Complex.I));
- TestUtils.assertEquals(Complex.ONE,
- Complex.ONE.pow(Complex.ZERO), tol);
- TestUtils.assertEquals(Complex.ONE,
- Complex.I.pow(Complex.ZERO), tol);
- TestUtils.assertEquals(Complex.ONE,
- new Complex(-1, 3).pow(Complex.ZERO), tol);
- }
-
- @Test
- public void testScalarPow() {
- Complex x = new Complex(3, 4);
- double yDouble = 5.0;
- Complex yComplex = new Complex(yDouble);
- Assert.assertEquals(x.pow(yComplex), x.pow(yDouble));
- }
-
- @Test
- public void testScalarPowNaNBase() {
- Complex x = Complex.NaN;
- double yDouble = 5.0;
- Complex yComplex = new Complex(yDouble);
- Assert.assertEquals(x.pow(yComplex), x.pow(yDouble));
- }
-
- @Test
- public void testScalarPowNaNExponent() {
- Complex x = new Complex(3, 4);
- double yDouble = Double.NaN;
- Complex yComplex = new Complex(yDouble);
- Assert.assertEquals(x.pow(yComplex), x.pow(yDouble));
- }
-
- @Test
- public void testScalarPowInf() {
- TestUtils.assertSame(Complex.NaN,Complex.ONE.pow(Double.POSITIVE_INFINITY));
- TestUtils.assertSame(Complex.NaN,Complex.ONE.pow(Double.NEGATIVE_INFINITY));
- TestUtils.assertSame(Complex.NaN,infOne.pow(1.0));
- TestUtils.assertSame(Complex.NaN,negInfOne.pow(1.0));
- TestUtils.assertSame(Complex.NaN,infInf.pow(1.0));
- TestUtils.assertSame(Complex.NaN,infNegInf.pow(1.0));
- TestUtils.assertSame(Complex.NaN,negInfInf.pow(10));
- TestUtils.assertSame(Complex.NaN,negInfNegInf.pow(1.0));
- TestUtils.assertSame(Complex.NaN,negInfNegInf.pow(Double.POSITIVE_INFINITY));
- TestUtils.assertSame(Complex.NaN,negInfNegInf.pow(Double.POSITIVE_INFINITY));
- TestUtils.assertSame(Complex.NaN,infInf.pow(Double.POSITIVE_INFINITY));
- TestUtils.assertSame(Complex.NaN,infInf.pow(Double.NEGATIVE_INFINITY));
- TestUtils.assertSame(Complex.NaN,infNegInf.pow(Double.NEGATIVE_INFINITY));
- TestUtils.assertSame(Complex.NaN,infNegInf.pow(Double.POSITIVE_INFINITY));
- }
-
- @Test
- public void testScalarPowZero() {
- final double tol = Math.ulp(1d);
- TestUtils.assertEquals(Complex.ZERO, Complex.ZERO.pow(1.0), tol);
- TestUtils.assertEquals(Complex.ZERO, Complex.ZERO.pow(2.0), tol);
- TestUtils.assertSame(Complex.NaN, Complex.ZERO.pow(0.0));
- TestUtils.assertSame(Complex.NaN, Complex.ZERO.pow(-1.0));
- TestUtils.assertEquals(Complex.ONE, Complex.ONE.pow(0.0), tol);
- TestUtils.assertEquals(Complex.ONE, Complex.I.pow(0.0), tol);
- TestUtils.assertEquals(Complex.ONE, new Complex(-1, 3).pow(0.0), tol);
- }
-
- @Test
- public void testSin() {
- Complex z = new Complex(3, 4);
- Complex expected = new Complex(3.853738, -27.01681);
- TestUtils.assertEquals(expected, z.sin(), 1.0e-5);
- }
-
- @Test
- public void testSinInf() {
- TestUtils.assertSame(infInf, oneInf.sin());
- TestUtils.assertSame(infNegInf, oneNegInf.sin());
- TestUtils.assertSame(Complex.NaN, infOne.sin());
- TestUtils.assertSame(Complex.NaN, negInfOne.sin());
- TestUtils.assertSame(Complex.NaN, infInf.sin());
- TestUtils.assertSame(Complex.NaN, infNegInf.sin());
- TestUtils.assertSame(Complex.NaN, negInfInf.sin());
- TestUtils.assertSame(Complex.NaN, negInfNegInf.sin());
- }
-
- @Test
- public void testSinNaN() {
- Assert.assertTrue(Complex.NaN.sin().isNaN());
- }
-
- @Test
- public void testSinh() {
- Complex z = new Complex(3, 4);
- Complex expected = new Complex(-6.54812, -7.61923);
- TestUtils.assertEquals(expected, z.sinh(), 1.0e-5);
- }
-
- @Test
- public void testSinhNaN() {
- Assert.assertTrue(Complex.NaN.sinh().isNaN());
- }
-
- @Test
- public void testSinhInf() {
- TestUtils.assertSame(Complex.NaN, oneInf.sinh());
- TestUtils.assertSame(Complex.NaN, oneNegInf.sinh());
- TestUtils.assertSame(infInf, infOne.sinh());
- TestUtils.assertSame(negInfInf, negInfOne.sinh());
- TestUtils.assertSame(Complex.NaN, infInf.sinh());
- TestUtils.assertSame(Complex.NaN, infNegInf.sinh());
- TestUtils.assertSame(Complex.NaN, negInfInf.sinh());
- TestUtils.assertSame(Complex.NaN, negInfNegInf.sinh());
- }
-
- @Test
- public void testSqrtRealPositive() {
- Complex z = new Complex(3, 4);
- Complex expected = new Complex(2, 1);
- TestUtils.assertEquals(expected, z.sqrt(), 1.0e-5);
- }
-
- @Test
- public void testSqrtRealZero() {
- Complex z = new Complex(0.0, 4);
- Complex expected = new Complex(1.41421, 1.41421);
- TestUtils.assertEquals(expected, z.sqrt(), 1.0e-5);
- }
-
- @Test
- public void testSqrtRealNegative() {
- Complex z = new Complex(-3.0, 4);
- Complex expected = new Complex(1, 2);
- TestUtils.assertEquals(expected, z.sqrt(), 1.0e-5);
- }
-
- @Test
- public void testSqrtImaginaryZero() {
- Complex z = new Complex(-3.0, 0.0);
- Complex expected = new Complex(0.0, 1.73205);
- TestUtils.assertEquals(expected, z.sqrt(), 1.0e-5);
- }
-
- @Test
- public void testSqrtImaginaryNegative() {
- Complex z = new Complex(-3.0, -4.0);
- Complex expected = new Complex(1.0, -2.0);
- TestUtils.assertEquals(expected, z.sqrt(), 1.0e-5);
- }
-
- @Test
- public void testSqrtPolar() {
- final double tol = 1e-12;
- double r = 1;
- for (int i = 0; i < 5; i++) {
- r += i;
- double theta = 0;
- for (int j = 0; j < 11; j++) {
- theta += pi / 12;
- Complex z = ComplexUtils.polar2Complex(r, theta);
- Complex sqrtz = ComplexUtils.polar2Complex(Math.sqrt(r), theta / 2);
- TestUtils.assertEquals(sqrtz, z.sqrt(), tol);
- }
- }
- }
-
- @Test
- public void testSqrtNaN() {
- Assert.assertTrue(Complex.NaN.sqrt().isNaN());
- }
-
- @Test
- public void testSqrtInf() {
- TestUtils.assertSame(infNaN, oneInf.sqrt());
- TestUtils.assertSame(infNaN, oneNegInf.sqrt());
- TestUtils.assertSame(infZero, infOne.sqrt());
- TestUtils.assertSame(zeroInf, negInfOne.sqrt());
- TestUtils.assertSame(infNaN, infInf.sqrt());
- TestUtils.assertSame(infNaN, infNegInf.sqrt());
- TestUtils.assertSame(nanInf, negInfInf.sqrt());
- TestUtils.assertSame(nanNegInf, negInfNegInf.sqrt());
- }
-
- @Test
- public void testSqrt1z() {
- Complex z = new Complex(3, 4);
- Complex expected = new Complex(4.08033, -2.94094);
- TestUtils.assertEquals(expected, z.sqrt1z(), 1.0e-5);
- }
-
- @Test
- public void testSqrt1zNaN() {
- Assert.assertTrue(Complex.NaN.sqrt1z().isNaN());
- }
-
- @Test
- public void testTan() {
- Complex z = new Complex(3, 4);
- Complex expected = new Complex(-0.000187346, 0.999356);
- TestUtils.assertEquals(expected, z.tan(), 1.0e-5);
- /* Check that no overflow occurs (MATH-722) */
- Complex actual = new Complex(3.0, 1E10).tan();
- expected = new Complex(0, 1);
- TestUtils.assertEquals(expected, actual, 1.0e-5);
- actual = new Complex(3.0, -1E10).tan();
- expected = new Complex(0, -1);
- TestUtils.assertEquals(expected, actual, 1.0e-5);
- }
-
- @Test
- public void testTanNaN() {
- Assert.assertTrue(Complex.NaN.tan().isNaN());
- }
-
- @Test
- public void testTanInf() {
- TestUtils.assertSame(Complex.valueOf(0.0, 1.0), oneInf.tan());
- TestUtils.assertSame(Complex.valueOf(0.0, -1.0), oneNegInf.tan());
- TestUtils.assertSame(Complex.NaN, infOne.tan());
- TestUtils.assertSame(Complex.NaN, negInfOne.tan());
- TestUtils.assertSame(Complex.NaN, infInf.tan());
- TestUtils.assertSame(Complex.NaN, infNegInf.tan());
- TestUtils.assertSame(Complex.NaN, negInfInf.tan());
- TestUtils.assertSame(Complex.NaN, negInfNegInf.tan());
- }
-
- @Test
- public void testTanCritical() {
- TestUtils.assertSame(infNaN, new Complex(pi/2, 0).tan());
- TestUtils.assertSame(negInfNaN, new Complex(-pi/2, 0).tan());
- }
-
- @Test
- public void testTanh() {
- Complex z = new Complex(3, 4);
- Complex expected = new Complex(1.00071, 0.00490826);
- TestUtils.assertEquals(expected, z.tanh(), 1.0e-5);
- /* Check that no overflow occurs (MATH-722) */
- Complex actual = new Complex(1E10, 3.0).tanh();
- expected = new Complex(1, 0);
- TestUtils.assertEquals(expected, actual, 1.0e-5);
- actual = new Complex(-1E10, 3.0).tanh();
- expected = new Complex(-1, 0);
- TestUtils.assertEquals(expected, actual, 1.0e-5);
- }
-
- @Test
- public void testTanhNaN() {
- Assert.assertTrue(Complex.NaN.tanh().isNaN());
- }
-
- @Test
- public void testTanhInf() {
- TestUtils.assertSame(Complex.NaN, oneInf.tanh());
- TestUtils.assertSame(Complex.NaN, oneNegInf.tanh());
- TestUtils.assertSame(Complex.valueOf(1.0, 0.0), infOne.tanh());
- TestUtils.assertSame(Complex.valueOf(-1.0, 0.0), negInfOne.tanh());
- TestUtils.assertSame(Complex.NaN, infInf.tanh());
- TestUtils.assertSame(Complex.NaN, infNegInf.tanh());
- TestUtils.assertSame(Complex.NaN, negInfInf.tanh());
- TestUtils.assertSame(Complex.NaN, negInfNegInf.tanh());
- }
-
- @Test
- public void testTanhCritical() {
- TestUtils.assertSame(nanInf, new Complex(0, pi/2).tanh());
- }
-
- /** test issue MATH-221 */
- @Test
- public void testMath221() {
- Assert.assertTrue(Complex.equals(new Complex(0,-1),
- new Complex(0,1).multiply(new Complex(-1,0))));
- }
-
- /**
- * Test: computing <b>third roots</b> of z.
- * <pre>
- * <code>
- * <b>z = -2 + 2 * i</b>
- * => z_0 = 1 + i
- * => z_1 = -1.3660 + 0.3660 * i
- * => z_2 = 0.3660 - 1.3660 * i
- * </code>
- * </pre>
- */
- @Test
- public void testNthRoot_normal_thirdRoot() {
- // The complex number we want to compute all third-roots for.
- Complex z = new Complex(-2,2);
- // The List holding all third roots
- Complex[] thirdRootsOfZ = z.nthRoot(3).toArray(new Complex[0]);
- // Returned Collection must not be empty!
- Assert.assertEquals(3, thirdRootsOfZ.length);
- // test z_0
- Assert.assertEquals(1.0, thirdRootsOfZ[0].getReal(), 1.0e-5);
- Assert.assertEquals(1.0, thirdRootsOfZ[0].getImaginary(), 1.0e-5);
- // test z_1
- Assert.assertEquals(-1.3660254037844386, thirdRootsOfZ[1].getReal(), 1.0e-5);
- Assert.assertEquals(0.36602540378443843, thirdRootsOfZ[1].getImaginary(), 1.0e-5);
- // test z_2
- Assert.assertEquals(0.366025403784439, thirdRootsOfZ[2].getReal(), 1.0e-5);
- Assert.assertEquals(-1.3660254037844384, thirdRootsOfZ[2].getImaginary(), 1.0e-5);
- }
-
-
- /**
- * Test: computing <b>fourth roots</b> of z.
- * <pre>
- * <code>
- * <b>z = 5 - 2 * i</b>
- * => z_0 = 1.5164 - 0.1446 * i
- * => z_1 = 0.1446 + 1.5164 * i
- * => z_2 = -1.5164 + 0.1446 * i
- * => z_3 = -1.5164 - 0.1446 * i
- * </code>
- * </pre>
- */
- @Test
- public void testNthRoot_normal_fourthRoot() {
- // The complex number we want to compute all third-roots for.
- Complex z = new Complex(5,-2);
- // The List holding all fourth roots
- Complex[] fourthRootsOfZ = z.nthRoot(4).toArray(new Complex[0]);
- // Returned Collection must not be empty!
- Assert.assertEquals(4, fourthRootsOfZ.length);
- // test z_0
- Assert.assertEquals(1.5164629308487783, fourthRootsOfZ[0].getReal(), 1.0e-5);
- Assert.assertEquals(-0.14469266210702247, fourthRootsOfZ[0].getImaginary(), 1.0e-5);
- // test z_1
- Assert.assertEquals(0.14469266210702256, fourthRootsOfZ[1].getReal(), 1.0e-5);
- Assert.assertEquals(1.5164629308487783, fourthRootsOfZ[1].getImaginary(), 1.0e-5);
- // test z_2
- Assert.assertEquals(-1.5164629308487783, fourthRootsOfZ[2].getReal(), 1.0e-5);
- Assert.assertEquals(0.14469266210702267, fourthRootsOfZ[2].getImaginary(), 1.0e-5);
- // test z_3
- Assert.assertEquals(-0.14469266210702275, fourthRootsOfZ[3].getReal(), 1.0e-5);
- Assert.assertEquals(-1.5164629308487783, fourthRootsOfZ[3].getImaginary(), 1.0e-5);
- }
-
- /**
- * Test: computing <b>third roots</b> of z.
- * <pre>
- * <code>
- * <b>z = 8</b>
- * => z_0 = 2
- * => z_1 = -1 + 1.73205 * i
- * => z_2 = -1 - 1.73205 * i
- * </code>
- * </pre>
- */
- @Test
- public void testNthRoot_cornercase_thirdRoot_imaginaryPartEmpty() {
- // The number 8 has three third roots. One we all already know is the number 2.
- // But there are two more complex roots.
- Complex z = new Complex(8,0);
- // The List holding all third roots
- Complex[] thirdRootsOfZ = z.nthRoot(3).toArray(new Complex[0]);
- // Returned Collection must not be empty!
- Assert.assertEquals(3, thirdRootsOfZ.length);
- // test z_0
- Assert.assertEquals(2.0, thirdRootsOfZ[0].getReal(), 1.0e-5);
- Assert.assertEquals(0.0, thirdRootsOfZ[0].getImaginary(), 1.0e-5);
- // test z_1
- Assert.assertEquals(-1.0, thirdRootsOfZ[1].getReal(), 1.0e-5);
- Assert.assertEquals(1.7320508075688774, thirdRootsOfZ[1].getImaginary(), 1.0e-5);
- // test z_2
- Assert.assertEquals(-1.0, thirdRootsOfZ[2].getReal(), 1.0e-5);
- Assert.assertEquals(-1.732050807568877, thirdRootsOfZ[2].getImaginary(), 1.0e-5);
- }
-
-
- /**
- * Test: computing <b>third roots</b> of z with real part 0.
- * <pre>
- * <code>
- * <b>z = 2 * i</b>
- * => z_0 = 1.0911 + 0.6299 * i
- * => z_1 = -1.0911 + 0.6299 * i
- * => z_2 = -2.3144 - 1.2599 * i
- * </code>
- * </pre>
- */
- @Test
- public void testNthRoot_cornercase_thirdRoot_realPartZero() {
- // complex number with only imaginary part
- Complex z = new Complex(0,2);
- // The List holding all third roots
- Complex[] thirdRootsOfZ = z.nthRoot(3).toArray(new Complex[0]);
- // Returned Collection must not be empty!
- Assert.assertEquals(3, thirdRootsOfZ.length);
- // test z_0
- Assert.assertEquals(1.0911236359717216, thirdRootsOfZ[0].getReal(), 1.0e-5);
- Assert.assertEquals(0.6299605249474365, thirdRootsOfZ[0].getImaginary(), 1.0e-5);
- // test z_1
- Assert.assertEquals(-1.0911236359717216, thirdRootsOfZ[1].getReal(), 1.0e-5);
- Assert.assertEquals(0.6299605249474365, thirdRootsOfZ[1].getImaginary(), 1.0e-5);
- // test z_2
- Assert.assertEquals(-2.3144374213981936E-16, thirdRootsOfZ[2].getReal(), 1.0e-5);
- Assert.assertEquals(-1.2599210498948732, thirdRootsOfZ[2].getImaginary(), 1.0e-5);
- }
-
- /**
- * Test cornercases with NaN and Infinity.
- */
- @Test
- public void testNthRoot_cornercase_NAN_Inf() {
- // NaN + finite -> NaN
- List<Complex> roots = oneNaN.nthRoot(3);
- Assert.assertEquals(1,roots.size());
- Assert.assertEquals(Complex.NaN, roots.get(0));
-
- roots = nanZero.nthRoot(3);
- Assert.assertEquals(1,roots.size());
- Assert.assertEquals(Complex.NaN, roots.get(0));
-
- // NaN + infinite -> NaN
- roots = nanInf.nthRoot(3);
- Assert.assertEquals(1,roots.size());
- Assert.assertEquals(Complex.NaN, roots.get(0));
-
- // finite + infinite -> Inf
- roots = oneInf.nthRoot(3);
- Assert.assertEquals(1,roots.size());
- Assert.assertEquals(Complex.INF, roots.get(0));
-
- // infinite + infinite -> Inf
- roots = negInfInf.nthRoot(3);
- Assert.assertEquals(1,roots.size());
- Assert.assertEquals(Complex.INF, roots.get(0));
- }
-
- /**
- * Test standard values
- */
- @Test
- public void testGetArgument() {
- Complex z = new Complex(1, 0);
- Assert.assertEquals(0.0, z.getArgument(), 1.0e-12);
-
- z = new Complex(1, 1);
- Assert.assertEquals(Math.PI/4, z.getArgument(), 1.0e-12);
-
- z = new Complex(0, 1);
- Assert.assertEquals(Math.PI/2, z.getArgument(), 1.0e-12);
-
- z = new Complex(-1, 1);
- Assert.assertEquals(3 * Math.PI/4, z.getArgument(), 1.0e-12);
-
- z = new Complex(-1, 0);
- Assert.assertEquals(Math.PI, z.getArgument(), 1.0e-12);
-
- z = new Complex(-1, -1);
- Assert.assertEquals(-3 * Math.PI/4, z.getArgument(), 1.0e-12);
-
- z = new Complex(0, -1);
- Assert.assertEquals(-Math.PI/2, z.getArgument(), 1.0e-12);
-
- z = new Complex(1, -1);
- Assert.assertEquals(-Math.PI/4, z.getArgument(), 1.0e-12);
-
- }
-
- /**
- * Verify atan2-style handling of infinite parts
- */
- @Test
- public void testGetArgumentInf() {
- Assert.assertEquals(Math.PI/4, infInf.getArgument(), 1.0e-12);
- Assert.assertEquals(Math.PI/2, oneInf.getArgument(), 1.0e-12);
- Assert.assertEquals(0.0, infOne.getArgument(), 1.0e-12);
- Assert.assertEquals(Math.PI/2, zeroInf.getArgument(), 1.0e-12);
- Assert.assertEquals(0.0, infZero.getArgument(), 1.0e-12);
- Assert.assertEquals(Math.PI, negInfOne.getArgument(), 1.0e-12);
- Assert.assertEquals(-3.0*Math.PI/4, negInfNegInf.getArgument(), 1.0e-12);
- Assert.assertEquals(-Math.PI/2, oneNegInf.getArgument(), 1.0e-12);
- }
-
- /**
- * Verify that either part NaN results in NaN
- */
- @Test
- public void testGetArgumentNaN() {
- Assert.assertTrue(Double.isNaN(nanZero.getArgument()));
- Assert.assertTrue(Double.isNaN(zeroNaN.getArgument()));
- Assert.assertTrue(Double.isNaN(Complex.NaN.getArgument()));
- }
-
- @Test
- public void testSerial() {
- Complex z = new Complex(3.0, 4.0);
- Assert.assertEquals(z, TestUtils.serializeAndRecover(z));
- Complex ncmplx = (Complex)TestUtils.serializeAndRecover(oneNaN);
- Assert.assertEquals(nanZero, ncmplx);
- Assert.assertTrue(ncmplx.isNaN());
- Complex infcmplx = (Complex)TestUtils.serializeAndRecover(infInf);
- Assert.assertEquals(infInf, infcmplx);
- Assert.assertTrue(infcmplx.isInfinite());
- TestComplex tz = new TestComplex(3.0, 4.0);
- Assert.assertEquals(tz, TestUtils.serializeAndRecover(tz));
- TestComplex ntcmplx = (TestComplex)TestUtils.serializeAndRecover(new TestComplex(oneNaN));
- Assert.assertEquals(nanZero, ntcmplx);
- Assert.assertTrue(ntcmplx.isNaN());
- TestComplex inftcmplx = (TestComplex)TestUtils.serializeAndRecover(new TestComplex(infInf));
- Assert.assertEquals(infInf, inftcmplx);
- Assert.assertTrue(inftcmplx.isInfinite());
- }
-
- /**
- * Class to test extending Complex
- */
- public static class TestComplex extends Complex {
-
- /**
- * Serialization identifier.
- */
- private static final long serialVersionUID = 3268726724160389237L;
-
- public TestComplex(double real, double imaginary) {
- super(real, imaginary);
- }
-
- public TestComplex(Complex other){
- this(other.getReal(), other.getImaginary());
- }
-
- @Override
- protected TestComplex createComplex(double real, double imaginary){
- return new TestComplex(real, imaginary);
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/java/org/apache/commons/complex/ComplexUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/complex/ComplexUtilsTest.java b/src/test/java/org/apache/commons/complex/ComplexUtilsTest.java
deleted file mode 100755
index 09ee4c8..0000000
--- a/src/test/java/org/apache/commons/complex/ComplexUtilsTest.java
+++ /dev/null
@@ -1,475 +0,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.
- */
-
-package org.apache.commons.complex;
-
-import org.apache.commons.complex.Complex;
-import org.apache.commons.complex.ComplexUtils;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- */
-public class ComplexUtilsTest {
-
- private final double inf = Double.POSITIVE_INFINITY;
- private final double negInf = Double.NEGATIVE_INFINITY;
- private final double nan = Double.NaN;
- private final double pi = Math.PI;
-
- private final Complex negInfInf = new Complex(negInf, inf);
- private final Complex infNegInf = new Complex(inf, negInf);
- private final Complex infInf = new Complex(inf, inf);
- private final Complex negInfNegInf = new Complex(negInf, negInf);
- private final Complex infNaN = new Complex(inf, nan);
-
- private static Complex c[]; // complex array with real values even and imag
- // values odd
- private static Complex cr[]; // complex array with real values consecutive
- private static Complex ci[]; // complex array with imag values consecutive
- private static double d[]; // real array with consecutive vals
- private static double di[]; // real array with consecutive vals,
- // 'interleaved' length
- private static float f[]; // real array with consecutive vals
- private static float fi[]; // real array with consec vals, interleaved
- // length
- private static double sr[]; // real component of split array, evens
- private static double si[]; // imag component of split array, odds
- private static float sfr[]; // real component of split array, float, evens
- private static float sfi[]; // imag component of split array, float, odds
- static Complex ans1, ans2; // answers to single value extraction methods
- static Complex[] ansArrayc1r, ansArrayc1i, ansArrayc2r, ansArrayc2i, ansArrayc3, ansArrayc4; // answers
- // to
- // range
- // extraction
- // methods
- static double[] ansArrayd1r, ansArrayd2r, ansArrayd1i, ansArrayd2i, ansArraydi1, ansArraydi2;
- static float[] ansArrayf1r, ansArrayf2r, ansArrayf1i, ansArrayf2i, ansArrayfi1, ansArrayfi2;
- static String msg; // error message for AssertEquals
- static Complex[][] c2d, cr2d, ci2d; // for 2d methods
- static Complex[][][] c3d, cr3d, ci3d; // for 3d methods
- static double[][] d2d, di2d, sr2d, si2d;
- static double[][][] d3d, di3d, sr3d, si3d;
- static float[][] f2d, fi2d, sfr2d, sfi2d;
- static float[][][] f3d, fi3d, sfr3d, sfi3d;
-
- private static void setArrays() { // initial setup method
- c = new Complex[10];
- cr = new Complex[10];
- ci = new Complex[10];
- d = new double[10];
- f = new float[10];
- di = new double[20];
- fi = new float[20];
- sr = new double[10];
- si = new double[10];
- sfr = new float[10];
- sfi = new float[10];
- c2d = new Complex[10][10];
- cr2d = new Complex[10][10];
- ci2d = new Complex[10][10];
- c3d = new Complex[10][10][10];
- cr3d = new Complex[10][10][10];
- ci3d = new Complex[10][10][10];
- d2d = new double[10][10];
- d3d = new double[10][10][10];
- f2d = new float[10][10];
- f3d = new float[10][10][10];
- sr2d = new double[10][10];
- sr3d = new double[10][10][10];
- si2d = new double[10][10];
- si3d = new double[10][10][10];
- sfr2d = new float[10][10];
- sfr3d = new float[10][10][10];
- sfi2d = new float[10][10];
- sfi3d = new float[10][10][10];
- di2d = new double[10][20];
- di3d = new double[10][10][20];
- fi2d = new float[10][20];
- fi3d = new float[10][10][20];
- for (int i = 0; i < 20; i += 2) {
- d[i / 2] = i / 2;
- f[i / 2] = i / 2;
- di[i] = i;
- di[i + 1] = i + 1;
- fi[i] = i;
- fi[i + 1] = i + 1;
- c[i / 2] = new Complex(i, i + 1);
- cr[i / 2] = new Complex(i / 2);
- ci[i / 2] = new Complex(0, i / 2);
- sr[i / 2] = i;
- si[i / 2] = i + 1;
- sfr[i / 2] = i;
- sfi[i / 2] = i + 1;
- }
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 20; j += 2) {
- d2d[i][j / 2] = 10 * i + j / 2;
- f2d[i][j / 2] = 10 * i + j / 2;
- sr2d[i][j / 2] = 10 * i + j;
- si2d[i][j / 2] = 10 * i + j + 1;
- sfr2d[i][j / 2] = 10 * i + j;
- sfi2d[i][j / 2] = 10 * i + j + 1;
- di2d[i][j] = 10 * i + j;
- di2d[i][j + 1] = 10 * i + j + 1;
- fi2d[i][j] = 10 * i + j;
- fi2d[i][j + 1] = 10 * i + j + 1;
- c2d[i][j / 2] = new Complex(10 * i + j, 10 * i + j + 1);
- cr2d[i][j / 2] = new Complex(10 * i + j / 2);
- ci2d[i][j / 2] = new Complex(0, 10 * i + j / 2);
- }
- }
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- for (int k = 0; k < 20; k += 2) {
- d3d[i][j][k / 2] = 100 * i + 10 * j + k / 2;
- f3d[i][j][k / 2] = 100 * i + 10 * j + k / 2;
- sr3d[i][j][k / 2] = 100 * i + 10 * j + k;
- si3d[i][j][k / 2] = 100 * i + 10 * j + k + 1;
- sfr3d[i][j][k / 2] = 100 * i + 10 * j + k;
- sfi3d[i][j][k / 2] = 100 * i + 10 * j + k + 1;
- di3d[i][j][k] = 100 * i + 10 * j + k;
- di3d[i][j][k + 1] = 100 * i + 10 * j + k + 1;
- fi3d[i][j][k] = 100 * i + 10 * j + k;
- fi3d[i][j][k + 1] = 100 * i + 10 * j + k + 1;
- c3d[i][j][k / 2] = new Complex(100 * i + 10 * j + k, 100 * i + 10 * j + k + 1);
- cr3d[i][j][k / 2] = new Complex(100 * i + 10 * j + k / 2);
- ci3d[i][j][k / 2] = new Complex(0, 100 * i + 10 * j + k / 2);
- }
- }
- }
- ansArrayc1r = new Complex[] { new Complex(3), new Complex(4), new Complex(5), new Complex(6), new Complex(7) };
- ansArrayc2r = new Complex[] { new Complex(3), new Complex(5), new Complex(7) };
- ansArrayc1i = new Complex[] { new Complex(0, 3), new Complex(0, 4), new Complex(0, 5), new Complex(0, 6),
- new Complex(0, 7) };
- ansArrayc2i = new Complex[] { new Complex(0, 3), new Complex(0, 5), new Complex(0, 7) };
- ansArrayc3 = new Complex[] { new Complex(6, 7), new Complex(8, 9), new Complex(10, 11), new Complex(12, 13),
- new Complex(14, 15) };
- ansArrayc4 = new Complex[] { new Complex(6, 7), new Complex(10, 11), new Complex(14, 15) };
- ansArrayd1r = new double[] { 6, 8, 10, 12, 14 };
- ansArrayd1i = new double[] { 7, 9, 11, 13, 15 };
- ansArrayd2r = new double[] { 6, 10, 14 };
- ansArrayd2i = new double[] { 7, 11, 15 };
- ansArrayf1r = new float[] { 6, 8, 10, 12, 14 };
- ansArrayf1i = new float[] { 7, 9, 11, 13, 15 };
- ansArrayf2r = new float[] { 6, 10, 14 };
- ansArrayf2i = new float[] { 7, 11, 15 };
- ansArraydi1 = new double[] { 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
- ansArrayfi1 = new float[] { 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
- ansArraydi2 = new double[] { 6, 7, 10, 11, 14, 15 };
- ansArrayfi2 = new float[] { 6, 7, 10, 11, 14, 15 };
- msg = "";
- }
-
- @Test
- public void testPolar2Complex() {
- TestUtils.assertEquals(Complex.ONE, ComplexUtils.polar2Complex(1, 0), 10e-12);
- TestUtils.assertEquals(Complex.ZERO, ComplexUtils.polar2Complex(0, 1), 10e-12);
- TestUtils.assertEquals(Complex.ZERO, ComplexUtils.polar2Complex(0, -1), 10e-12);
- TestUtils.assertEquals(Complex.I, ComplexUtils.polar2Complex(1, pi / 2), 10e-12);
- TestUtils.assertEquals(Complex.I.negate(), ComplexUtils.polar2Complex(1, -pi / 2), 10e-12);
- double r = 0;
- for (int i = 0; i < 5; i++) {
- r += i;
- double theta = 0;
- for (int j = 0; j < 20; j++) {
- theta += pi / 6;
- TestUtils.assertEquals(altPolar(r, theta), ComplexUtils.polar2Complex(r, theta), 10e-12);
- }
- theta = -2 * pi;
- for (int j = 0; j < 20; j++) {
- theta -= pi / 6;
- TestUtils.assertEquals(altPolar(r, theta), ComplexUtils.polar2Complex(r, theta), 10e-12);
- }
- }
- }
-
- protected Complex altPolar(double r, double theta) {
- return Complex.I.multiply(new Complex(theta, 0)).exp().multiply(new Complex(r, 0));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testPolar2ComplexIllegalModulus() {
- ComplexUtils.polar2Complex(-1, 0);
- }
-
- @Test
- public void testPolar2ComplexNaN() {
- TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(nan, 1));
- TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(1, nan));
- TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(nan, nan));
- }
-
- @Test
- public void testPolar2ComplexInf() {
- TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(1, inf));
- TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(1, negInf));
- TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(inf, inf));
- TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(inf, negInf));
- TestUtils.assertSame(infInf, ComplexUtils.polar2Complex(inf, pi / 4));
- TestUtils.assertSame(infNaN, ComplexUtils.polar2Complex(inf, 0));
- TestUtils.assertSame(infNegInf, ComplexUtils.polar2Complex(inf, -pi / 4));
- TestUtils.assertSame(negInfInf, ComplexUtils.polar2Complex(inf, 3 * pi / 4));
- TestUtils.assertSame(negInfNegInf, ComplexUtils.polar2Complex(inf, 5 * pi / 4));
- }
-
- @Test
- public void testCExtract() {
- final double[] real = new double[] { negInf, -123.45, 0, 1, 234.56, pi, inf };
- final Complex[] complex = ComplexUtils.real2Complex(real);
-
- for (int i = 0; i < real.length; i++) {
- Assert.assertEquals(real[i], complex[i].getReal(), 0d);
- }
- }
-
- // EXTRACTION METHODS
-
- @Test
- public void testExtractionMethods() {
- setArrays();
- // Extract complex from real double array, index 3
- TestUtils.assertSame(new Complex(3), ComplexUtils.extractComplexFromRealArray(d, 3));
- // Extract complex from real float array, index 3
- TestUtils.assertSame(new Complex(3), ComplexUtils.extractComplexFromRealArray(f, 3));
- // Extract real double from complex array, index 3
- TestUtils.assertSame(6, ComplexUtils.extractRealFromComplexArray(c, 3));
- // Extract real float from complex array, index 3
- TestUtils.assertSame(6, ComplexUtils.extractRealFloatFromComplexArray(c, 3));
- // Extract complex from interleaved double array, index 3
- TestUtils.assertSame(new Complex(6, 7), ComplexUtils.extractComplexFromInterleavedArray(d, 3));
- // Extract complex from interleaved float array, index 3
- TestUtils.assertSame(new Complex(6, 7), ComplexUtils.extractComplexFromInterleavedArray(f, 3));
- // Extract interleaved double from complex array, index 3
- TestUtils.assertEquals(msg, new double[] { 6, 7 }, ComplexUtils.extractInterleavedFromComplexArray(c, 3),
- Math.ulp(1));
- // Extract interleaved float from complex array, index 3
- TestUtils.assertEquals(msg, new double[] { 6, 7 }, ComplexUtils.extractInterleavedFromComplexArray(c, 3),
- Math.ulp(1));
- if (!msg.equals("")) {
- throw new RuntimeException(msg);
- }
- }
- // REAL <-> COMPLEX
-
- @Test
- public void testRealToComplex() {
- setArrays();
- // Real double to complex, range 3-7, increment 1, entered as ints
- // Real double to complex, whole array
- TestUtils.assertEquals(msg, cr, ComplexUtils.real2Complex(d),Math.ulp(1.0));
- // Real float to complex, whole array
- TestUtils.assertEquals(msg, cr, ComplexUtils.real2Complex(f),Math.ulp(1.0));
- // 2d
- for (int i = 0; i < 10; i++) {
- // Real double to complex, 2d
- TestUtils.assertEquals(msg, cr2d[i], ComplexUtils.real2Complex(d2d[i]),Math.ulp(1.0));
- // Real float to complex, 2d
- TestUtils.assertEquals(msg, cr2d[i], ComplexUtils.real2Complex(f2d[i]),Math.ulp(1.0));
- }
- // 3d
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- // Real double to complex, 3d
- TestUtils.assertEquals(msg, cr3d[i][j], ComplexUtils.real2Complex(d3d[i][j]),Math.ulp(1.0));
- // Real float to complex, 3d
- TestUtils.assertEquals(msg, cr3d[i][j], ComplexUtils.real2Complex(f3d[i][j]),Math.ulp(1.0));
- }
- }
- if (!msg.equals("")) {
- throw new RuntimeException(msg);
- }
- }
-
- @Test
- public void testComplexToReal() {
- setArrays();
- // Real complex to double, whole array
- TestUtils.assertEquals(msg, sr, ComplexUtils.complex2Real(c),Math.ulp(1.0));
- // Real complex to float, whole array
- TestUtils.assertEquals(msg, sfr, ComplexUtils.complex2RealFloat(c),Math.ulp(1.0f));
- // 2d
- for (int i = 0; i < 10; i++) {
- // Real complex to double, 2d
- TestUtils.assertEquals(msg, sr2d[i], ComplexUtils.complex2Real(c2d[i]),Math.ulp(1.0));
- // Real complex to float, 2d
- TestUtils.assertEquals(msg, sfr2d[i], ComplexUtils.complex2RealFloat(c2d[i]),Math.ulp(1.0f));
- }
- // 3d
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- // Real complex to double, 3d
- TestUtils.assertEquals(msg, sr3d[i][j], ComplexUtils.complex2Real(c3d[i][j]),Math.ulp(1.0));
- // Real complex to float, 3d
- TestUtils.assertEquals(msg, sfr3d[i][j], ComplexUtils.complex2RealFloat(c3d[i][j]),Math.ulp(1.0f));
- }
- }
- if (!msg.equals("")) {
- throw new RuntimeException(msg);
- }
- }
-
- // IMAGINARY <-> COMPLEX
-
- @Test
- public void testImaginaryToComplex() {
- setArrays();
- // Imaginary double to complex, whole array
- TestUtils.assertEquals(msg, ci, ComplexUtils.imaginary2Complex(d),Math.ulp(1.0));
- // Imaginary float to complex, whole array
- TestUtils.assertEquals(msg, ci, ComplexUtils.imaginary2Complex(f),Math.ulp(1.0));
- // 2d
- for (int i = 0; i < 10; i++) {
- // Imaginary double to complex, 2d
- TestUtils.assertEquals(msg, ci2d[i], ComplexUtils.imaginary2Complex(d2d[i]),Math.ulp(1.0));
- // Imaginary float to complex, 2d
- TestUtils.assertEquals(msg, ci2d[i], ComplexUtils.imaginary2Complex(f2d[i]),Math.ulp(1.0));
- }
- // 3d
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- // Imaginary double to complex, 3d
- TestUtils.assertEquals(msg, ci3d[i][j], ComplexUtils.imaginary2Complex(d3d[i][j]),Math.ulp(1.0));
- // Imaginary float to complex, 3d
- TestUtils.assertEquals(msg, ci3d[i][j], ComplexUtils.imaginary2Complex(f3d[i][j]),Math.ulp(1.0));
- }
- }
- if (!msg.equals("")) {
- throw new RuntimeException(msg);
- }
- }
-
- @Test
- public void testComplexToImaginary() {
- setArrays();
- // Imaginary complex to double, whole array
- TestUtils.assertEquals(msg, si, ComplexUtils.complex2Imaginary(c),Math.ulp(1.0));
- // Imaginary complex to float, whole array
- TestUtils.assertEquals(msg, sfi, ComplexUtils.complex2ImaginaryFloat(c),Math.ulp(1.0f));
- // 2d
- for (int i = 0; i < 10; i++) {
- // Imaginary complex to double, 2d
- TestUtils.assertEquals(msg, si2d[i], ComplexUtils.complex2Imaginary(c2d[i]),Math.ulp(1.0));
- // Imaginary complex to float, 2d
- TestUtils.assertEquals(msg, sfi2d[i], ComplexUtils.complex2ImaginaryFloat(c2d[i]),Math.ulp(1.0f));
- }
- // 3d
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- // Imaginary complex to double, 3d
- TestUtils.assertEquals(msg, si3d[i][j], ComplexUtils.complex2Imaginary(c3d[i][j]),Math.ulp(1.0));
- // Imaginary complex to float, 3d
- TestUtils.assertEquals(msg, sfi3d[i][j], ComplexUtils.complex2ImaginaryFloat(c3d[i][j]),Math.ulp(1.0f));
- }
- }
- if (!msg.equals("")) {
- throw new RuntimeException(msg);
- }
- }
-
- // INTERLEAVED <-> COMPLEX
-
- @Test
- public void testInterleavedToComplex() {
- setArrays();
- // Interleaved double to complex, whole array
- TestUtils.assertEquals(msg, c, ComplexUtils.interleaved2Complex(di),Math.ulp(1.0));
- // Interleaved float to complex, whole array
- TestUtils.assertEquals(msg, c, ComplexUtils.interleaved2Complex(fi),Math.ulp(1.0));
- // 2d
- for (int i = 0; i < 10; i++) {
- // Interleaved double to complex, 2d
- TestUtils.assertEquals(msg, c2d[i], ComplexUtils.interleaved2Complex(di2d[i]),Math.ulp(1.0));
- // Interleaved float to complex, 2d
- TestUtils.assertEquals(msg, c2d[i], ComplexUtils.interleaved2Complex(fi2d[i]),Math.ulp(1.0));
- }
- // 3d
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- // Interleaved double to complex, 3d
- TestUtils.assertEquals(msg, c3d[i][j], ComplexUtils.interleaved2Complex(di3d[i][j]),Math.ulp(1.0));
- // Interleaved float to complex, 3d
- TestUtils.assertEquals(msg, c3d[i][j], ComplexUtils.interleaved2Complex(fi3d[i][j]),Math.ulp(1.0));
- }
- }
- if (!msg.equals("")) {
- throw new RuntimeException(msg);
- }
- }
-
- @Test
- public void testComplexToInterleaved() {
- setArrays();
- TestUtils.assertEquals(msg, di, ComplexUtils.complex2Interleaved(c),Math.ulp(1.0));
- // Interleaved complex to float, whole array
- TestUtils.assertEquals(msg, fi, ComplexUtils.complex2InterleavedFloat(c),Math.ulp(1.0f));
- // 2d
- for (int i = 0; i < 10; i++) {
- // Interleaved complex to double, 2d
- TestUtils.assertEquals(msg, di2d[i], ComplexUtils.complex2Interleaved(c2d[i]),Math.ulp(1.0));
- // Interleaved complex to float, 2d
- TestUtils.assertEquals(msg, fi2d[i], ComplexUtils.complex2InterleavedFloat(c2d[i]),Math.ulp(1.0f));
- }
- // 3d
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- // Interleaved complex to double, 3d
- TestUtils.assertEquals(msg, di3d[i][j], ComplexUtils.complex2Interleaved(c3d[i][j]),Math.ulp(1.0));
- // Interleaved complex to float, 3d
- TestUtils.assertEquals(msg, fi3d[i][j], ComplexUtils.complex2InterleavedFloat(c3d[i][j]),Math.ulp(1.0f));
- }
- }
- if (!msg.equals("")) {
- throw new RuntimeException(msg);
- }
- }
-
- // SPLIT TO COMPLEX
- @Test
- public void testSplit2Complex() {
- setArrays();
- // Split double to complex, whole array
- TestUtils.assertEquals(msg, c, ComplexUtils.split2Complex(sr, si),Math.ulp(1.0));
-
- // 2d
- for (int i = 0; i < 10; i++) {
- // Split double to complex, 2d
- TestUtils.assertEquals(msg, c2d[i], ComplexUtils.split2Complex(sr2d[i], si2d[i]),Math.ulp(1.0));
- }
- // 3d
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- // Split double to complex, 3d
- TestUtils.assertEquals(msg, c3d[i][j], ComplexUtils.split2Complex(sr3d[i][j], si3d[i][j]),Math.ulp(1.0));
- }
- }
- if (!msg.equals("")) {
- throw new RuntimeException(msg);
- }
- }
-
- // INITIALIZATION METHODS
-
- @Test
- public void testInitialize() {
- Complex[] c = new Complex[10];
- ComplexUtils.initialize(c);
- for (Complex cc : c) {
- TestUtils.assertEquals(new Complex(0, 0), cc, Math.ulp(0));
- }
- }
-}
[23/31] commons-numbers git commit: Correct project info.
Posted by er...@apache.org.
Correct project info.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/c7608e46
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/c7608e46
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/c7608e46
Branch: refs/heads/master
Commit: c7608e46c519d56bdc1062c302632f3e82f5a171
Parents: d93af77
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Fri Jan 20 14:37:54 2017 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Fri Jan 20 14:37:54 2017 +0100
----------------------------------------------------------------------
src/changes/changes.xml | 3610 +-----------------------------------------
1 file changed, 7 insertions(+), 3603 deletions(-)
----------------------------------------------------------------------
[17/31] commons-numbers git commit: Enable Travis CI.
Posted by er...@apache.org.
Enable Travis CI.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/69d3b623
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/69d3b623
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/69d3b623
Branch: refs/heads/master
Commit: 69d3b623149d99893755bc7cafce9d8708cbbf58
Parents: b026db1
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Thu Jan 19 01:03:04 2017 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Thu Jan 19 01:03:04 2017 +0100
----------------------------------------------------------------------
.travis.yml | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/69d3b623/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..9db916b
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +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.
+
+language: java
+sudo: false
+
+jdk:
+ - openjdk7
+ - oraclejdk8
+
+after_success:
+ - mvn clean test pmd:pmd findbugs:findbugs checkstyle:checkstyle jacoco:report coveralls:report
[28/31] commons-numbers git commit: Method should not be part of the
public API.
Posted by er...@apache.org.
Method should not be part of the public API.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/b4907a33
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/b4907a33
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/b4907a33
Branch: refs/heads/master
Commit: b4907a33d771c60597c46c56d33a279184e76684
Parents: b797559
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Fri Jan 20 15:15:39 2017 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Fri Jan 20 15:15:39 2017 +0100
----------------------------------------------------------------------
.../main/java/org/apache/commons/numbers/complex/Complex.java | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/b4907a33/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
----------------------------------------------------------------------
diff --git a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
index b130558..2cfebd6 100644
--- a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
+++ b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
@@ -1320,9 +1320,7 @@ public class Complex implements Serializable {
* @param value the value to be hashed
* @return the hash code
*/
- public static int hash(double value) {
+ private static int hash(double value) {
return new Double(value).hashCode();
}
-
}
-
[31/31] commons-numbers git commit: Merge branch 'multimodule'
Posted by er...@apache.org.
Merge branch 'multimodule'
Completes issue NUMBERS-5 (see JIRA).
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/c5de65a2
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/c5de65a2
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/c5de65a2
Branch: refs/heads/master
Commit: c5de65a2cedbf7c62d6fcc5a01b5eca35d5e73b2
Parents: 0d64d85 65a58af
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Fri Jan 20 15:39:54 2017 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Fri Jan 20 15:39:54 2017 +0100
----------------------------------------------------------------------
.travis.yml | 24 +
NOTICE.txt | 2 +-
README.md | 23 +-
checkstyle.xml | 202 -
clirr-ignored.xml | 21 -
commons-numbers-complex/LICENSE.txt | 201 +
commons-numbers-complex/NOTICE.txt | 6 +
commons-numbers-complex/README.md | 98 +
commons-numbers-complex/pom.xml | 61 +
.../apache/commons/numbers/complex/Complex.java | 1304 +++++++
.../commons/numbers/complex/ComplexUtils.java | 1430 +++++++
.../commons/numbers/complex/Precision.java | 128 +
.../commons/numbers/complex/RootsOfUnity.java | 116 +
.../commons/numbers/complex/package-info.java | 20 +
.../commons/numbers/complex/ComplexTest.java | 1477 +++++++
.../numbers/complex/ComplexUtilsTest.java | 475 +++
.../numbers/complex/RootsOfUnityTest.java | 84 +
.../commons/numbers/complex/TestUtils.java | 409 ++
commons-numbers-core/LICENSE.txt | 201 +
commons-numbers-core/NOTICE.txt | 6 +
commons-numbers-core/README.md | 98 +
commons-numbers-core/pom.xml | 46 +
.../apache/commons/numbers/core/Precision.java | 598 +++
commons-numbers-core/src/site/site.xml | 35 +
commons-numbers-core/src/site/xdoc/index.xml | 40 +
.../commons/numbers/core/PrecisionTest.java | 547 +++
.../apache/commons/numbers/core/TestUtils.java | 320 ++
commons-numbers-quaternion/LICENSE.txt | 201 +
commons-numbers-quaternion/NOTICE.txt | 6 +
commons-numbers-quaternion/README.md | 98 +
commons-numbers-quaternion/pom.xml | 53 +
.../commons/numbers/quaternion/Quaternion.java | 455 +++
.../numbers/quaternion/package-info.java | 20 +
.../numbers/quaternion/QuaternionTest.java | 456 +++
dist-archive/pom.xml | 148 +
dist-archive/src/assembly/bin.xml | 42 +
dist-archive/src/assembly/src.xml | 35 +
doc/development/development.howto.txt | 35 +-
doc/release/release.howto.txt | 484 ++-
doc/release/settings.xml | 1 +
findbugs-exclude-filter.xml | 331 --
license-header.txt | 16 -
pmd-ruleset.xml | 73 -
pom.xml | 410 +-
src/changes/changes.xml | 3610 +-----------------
.../org/apache/commons/complex/Complex.java | 1369 -------
.../apache/commons/complex/ComplexFormat.java | 595 ---
.../apache/commons/complex/ComplexUtils.java | 1430 -------
.../org/apache/commons/complex/Precision.java | 128 -
.../org/apache/commons/complex/Quaternion.java | 467 ---
.../apache/commons/complex/RootsOfUnity.java | 116 -
.../apache/commons/complex/package-info.java | 23 -
src/main/resources/checkstyle/checkstyle.xml | 202 +
.../resources/checkstyle/license-header.txt | 16 +
src/main/resources/clirr/clirr-ignored.xml | 21 +
.../findbugs/findbugs-exclude-filter.xml | 28 +
src/main/resources/pmd/pmd-ruleset.xml | 57 +
src/site/apt/userguide/special.apt | 136 -
src/site/design/differentiation.puml | 105 -
src/site/design/oneD.puml | 81 -
src/site/design/partitioning.puml | 118 -
src/site/design/solver.puml | 102 -
src/site/design/threeD.puml | 86 -
src/site/design/twoD.puml | 84 -
src/site/site.xml | 64 +-
src/site/xdoc/developers.xml | 593 ++-
src/site/xdoc/download_math.xml | 168 -
src/site/xdoc/download_numbers.xml | 154 +
src/site/xdoc/index.xml | 71 +-
src/site/xdoc/issue-tracking.xml | 30 +-
src/site/xdoc/mail-lists.xml | 39 +-
src/site/xdoc/proposal.xml | 131 -
src/test/R/ChiSquareDistributionTestCases.R | 97 -
src/test/R/FDistributionTestCases.R | 92 -
src/test/R/GammaDistributionTestCases.R | 92 -
.../R/KolmogorovSmirnovDistributionTestCases.R | 37 -
src/test/R/KolmogorovSmirnovTestCases.R | 208 -
src/test/R/LevyDistributionTestCases.R | 88 -
src/test/R/README.txt | 168 -
src/test/R/TDistributionTestCases.R | 100 -
src/test/R/TTestCases | 106 -
src/test/R/WeibullDistributionTestCases.R | 92 -
src/test/R/anovaTestCases | 72 -
src/test/R/binomialTestCases | 127 -
src/test/R/cauchyTestCases.R | 97 -
src/test/R/chiSquareTestCases | 101 -
src/test/R/correlationTestCases | 259 --
src/test/R/covarianceTestCases | 146 -
src/test/R/descriptiveTestCases | 83 -
src/test/R/exponentialTestCases | 103 -
src/test/R/geometricTestCases | 121 -
src/test/R/gumbelTestCases.R | 85 -
src/test/R/hypergeometricTestCases | 139 -
src/test/R/laplaceTestCases.R | 85 -
src/test/R/logNormalTestCases | 107 -
src/test/R/logisticsTestCases.R | 85 -
src/test/R/multipleOLSRegressionTestCases | 309 --
src/test/R/nakagamiTestCases.R | 85 -
src/test/R/normalTestCases | 111 -
src/test/R/paretoTestCases | 111 -
src/test/R/pascalTestCases | 135 -
src/test/R/poissonTestCases | 116 -
src/test/R/regressionTestCases | 159 -
src/test/R/testAll | 83 -
src/test/R/testFunctions | 86 -
src/test/R/zipfTestCases | 89 -
.../complex/ComplexFormatAbstractTest.java | 310 --
.../commons/complex/ComplexFormatTest.java | 33 -
.../org/apache/commons/complex/ComplexTest.java | 1477 -------
.../commons/complex/ComplexUtilsTest.java | 475 ---
.../commons/complex/ComplexUtilsTest.java.orig | 608 ---
.../complex/FrenchComplexFormatTest.java | 34 -
.../apache/commons/complex/QuaternionTest.java | 459 ---
.../java/org/apache/commons/complex/Retry.java | 29 -
.../org/apache/commons/complex/RetryRunner.java | 81 -
.../apache/commons/complex/RetryRunnerTest.java | 53 -
.../commons/complex/RootsOfUnityTest.java | 84 -
.../org/apache/commons/complex/TestUtils.java | 408 --
.../apache/commons/complex/TestUtils.java.orig | 662 ----
test-jar.xml | 99 -
120 files changed, 10598 insertions(+), 19048 deletions(-)
----------------------------------------------------------------------
[04/31] commons-numbers git commit: Cleanup (massive delete).
Posted by er...@apache.org.
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/paretoTestCases
----------------------------------------------------------------------
diff --git a/src/test/R/paretoTestCases b/src/test/R/paretoTestCases
deleted file mode 100644
index 716dfef..0000000
--- a/src/test/R/paretoTestCases
+++ /dev/null
@@ -1,111 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate LogNormal distribution tests in
-# org.apache.commons.math.distribution.LogNormalDistributionTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-# R functions used
-# ppareto(q, mean=0, sd=1, lower.tail = TRUE, log.p = FALSE) <-- distribution
-# The VGAM library which includes the function above must be installed to run
-# this test.
-# See https://cran.r-project.org/web/packages/VGAM/index.html
-#-----------------------------------------------------------------------------
-tol <- 1E-9
-
-# Function definitions
-
-require("VGAM")
-source("testFunctions") # utility test functions
-
-# function to verify distribution computations
-
-verifyDistribution <- function(points, expected, mu, sigma, tol) {
- rDistValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDistValues[i] <- ppareto(point, mu, sigma)
- }
- output <- c("Distribution test mu = ",mu,", sigma = ", sigma)
- if (assertEquals(expected, rDistValues, tol, "Distribution Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify density computations
-
-verifyDensity <- function(points, expected, mu, sigma, tol) {
- rDensityValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDensityValues[i] <- dpareto(point, mu, sigma, log = FALSE)
- }
- output <- c("Density test mu = ",mu,", sigma = ", sigma)
- if (assertEquals(expected, rDensityValues, tol, "Density Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-#--------------------------------------------------------------------------
-cat("Pareto test cases\n")
-
-mu <- 2.1
-sigma <- 1.4
-distributionValues <- c(0, 0, 0, 0, 0, 0.791089998892, 0.730456085931, 0.689667290488, 0.645278794701, 0.578763688757)
-densityValues <- c(0, 0, 0, 0, 0, 0.0455118580441, 0.070444173646, 0.0896924681582, 0.112794186114, 0.151439332084)
-distributionPoints <- c(-2.226325228634938, -1.156887023657177, -0.643949578356075, -0.2027950777320613, 0.305827808237559,
- 6.42632522863494, 5.35688702365718, 4.843949578356074, 4.40279507773206, 3.89417219176244)
-verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol)
-verifyDensity(distributionPoints, densityValues, mu, sigma, tol)
-
-distributionValues <- c(0, 0, 0, 0.510884134236, 0.694625688662, 0.785201995008, 0.837811522357, 0.871634279326)
-densityValues <- c(0, 0, 0.666666666, 0.195646346305, 0.0872498032394, 0.0477328899983, 0.0294888141169, 0.0197485724114)
-distributionPoints <- c(mu - 2 *sigma, mu - sigma, mu, mu + sigma,
- mu + 2 * sigma, mu + 3 * sigma, mu + 4 * sigma,
- mu + 5 * sigma)
-verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol)
-verifyDensity(distributionPoints, densityValues, mu, sigma, tol)
-
-mu <- 1
-sigma <- 1
-distributionPoints <- c(mu - 2 *sigma, mu - sigma, mu, mu + sigma,
- mu + 2 * sigma, mu + 3 * sigma, mu + 4 * sigma,
- mu + 5 * sigma)
-distributionValues <- c(0, 0, 0, 0.5, 0.666666666667, 0.75, 0.8, 0.833333333333)
-densityValues <- c(0, 0, 1, 0.25, 0.111111111111, 0.0625, 0.04, 0.0277777777778)
-verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol)
-verifyDensity(distributionPoints, densityValues, mu, sigma, tol)
-
-mu <- 0.1
-sigma <- 0.1
-distributionPoints <- c(mu - 2 *sigma, 0, mu, mu + sigma,
- mu + 2 * sigma, mu + 3 * sigma, mu + 4 * sigma,
- mu + 5 * sigma)
-distributionValues <- c(0, 0, 0, 0.0669670084632, 0.104041540159, 0.129449436704, 0.148660077479, 0.164041197922)
-densityValues <- c(0, 0, 1, 0.466516495768, 0.298652819947, 0.217637640824, 0.170267984504, 0.139326467013)
-verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol)
-verifyDensity(distributionPoints, densityValues, mu, sigma, tol)
-
-displayDashes(WIDTH)
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/pascalTestCases
----------------------------------------------------------------------
diff --git a/src/test/R/pascalTestCases b/src/test/R/pascalTestCases
deleted file mode 100644
index 0e7e68e..0000000
--- a/src/test/R/pascalTestCases
+++ /dev/null
@@ -1,135 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate Pascal distribution tests in
-# org.apache.commons.math.distribution.PascalDistributionTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-# R functions used
-# dnbinom(x, size, prob, mu, log = FALSE) <- density
-# pnbinom(q, size, prob, mu, lower.tail = TRUE, log.p = FALSE) <- distribution
-# qnbinom(p, size, prob, mu, lower.tail = TRUE, log.p = FALSE) <- quantiles
-#------------------------------------------------------------------------------
-tol <- 1E-9 # error tolerance for tests
-#------------------------------------------------------------------------------
-# Function definitions
-
-source("testFunctions") # utility test functions
-
-# function to verify density computations
-
-verifyDensity <- function(points, expected, size, p, tol) {
- rDensityValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDensityValues[i] <- dnbinom(point, size, p)
- }
- output <- c("Density test size = ", size, ", p = ", p)
- if (assertEquals(expected,rDensityValues,tol,"Density Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify distribution computations
-
-verifyDistribution <- function(points, expected, size, p, tol) {
- rDistValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDistValues[i] <- pnbinom(point, size, p)
- }
- output <- c("Distribution test size = ", size, ", p = ", p)
- if (assertEquals(expected,rDistValues,tol,"Distribution Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-#--------------------------------------------------------------------------
-cat("Negative Binomial test cases\n")
-
-size <- 10.0
-probability <- 0.70
-
-densityPoints <- c(-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
-densityValues <- c(0, 0.0282475249, 0.0847425747, 0.139825248255, 0.167790297906, 0.163595540458,
- 0.137420253985, 0.103065190489, 0.070673273478, 0.0450542118422, 0.0270325271053,
- 0.0154085404500, 0.0084046584273)
-distributionValues <- c(0, 0.0282475249, 0.1129900996, 0.252815347855, 0.420605645761, 0.584201186219,
- 0.721621440204, 0.824686630693, 0.895359904171, 0.940414116013, 0.967446643119,
- 0.982855183569, 0.991259841996)
-inverseCumPoints <- c( 0, 0.001, 0.010, 0.025, 0.050, 0.100, 0.999,
- 0.990, 0.975, 0.950, 0.900)
-inverseCumValues <- c(-1, -1, -1, -1, 0, 0, 13, 10, 9, 8, 7)
-
-verifyDensity(densityPoints,densityValues,size,probability,tol)
-verifyDistribution(densityPoints, distributionValues, size, probability, tol)
-
-i <- 0
-rInverseCumValues <- rep(0,length(inverseCumPoints))
-for (point in inverseCumPoints) {
- i <- i + 1
- rInverseCumValues[i] <- qnbinom(point, size, probability)
-}
-
-output <- c("Inverse Distribution test n = ", size, ", p = ", probability)
-# R defines quantiles from the right, need to subtract one
-if (assertEquals(inverseCumValues, rInverseCumValues-1, tol,
- "Inverse Dist Values")) {
- displayPadded(output, SUCCEEDED, 80)
-} else {
- displayPadded(output, FAILED, 80)
-}
-
-# Degenerate cases
-
-size <- 5
-probability <- 0.0
-
-densityPoints <- c(-1, 0, 1, 10, 11)
-# Note: commons math returns 0's below
-densityValues <- c(NaN, NaN, NaN, NaN, NaN)
-distributionPoints <- c(-1, 0, 1, 5, 10)
-# Note: commons math returns 0's below
-distributionValues <- c(NaN, NaN, NaN, NaN, NaN)
-
-output <- c("Density test n = ", size, ", p = ", probability)
-verifyDensity(densityPoints,densityValues,size,probability,tol)
-output <- c("Distribution test n = ", size, ", p = ", probability)
-verifyDistribution(distributionPoints,distributionValues,size,probability,tol)
-
-size <- 5
-probability <- 1.0
-
-densityPoints <- c(-1, 0, 1, 2, 5, 10)
-densityValues <- c(0, 1, 0, 0, 0, 0)
-distributionPoints <- c(-1, 0, 1, 2, 5, 10)
-distributionValues <- c(0, 1, 1, 1, 1, 1)
-
-output <- c("Density test n = ", size, ", p = ", probability)
-verifyDensity(densityPoints,densityValues,size,probability,tol)
-output <- c("Distribution test n = ", size, ", p = ", probability)
-verifyDistribution(distributionPoints,distributionValues,size,probability,tol)
-
-displayDashes(WIDTH)
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/poissonTestCases
----------------------------------------------------------------------
diff --git a/src/test/R/poissonTestCases b/src/test/R/poissonTestCases
deleted file mode 100644
index 2b5bbb7..0000000
--- a/src/test/R/poissonTestCases
+++ /dev/null
@@ -1,116 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate Poisson distribution tests in
-# org.apache.commons.math.distribution.PoissonDistributionTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-# R functions used
-# dpois(x, lambda, log = FALSE) <-- density
-# ppois(q, lambda, lower.tail = TRUE, log.p = FALSE) <-- distribution
-# pnorm(q, mean=0, sd=1, lower.tail = TRUE, log.p = FALSE) <-- normal dist.
-#------------------------------------------------------------------------------
-tol <- 1E-10
-#------------------------------------------------------------------------------
-# Function definitions
-
-source("testFunctions") # utility test functions
-
-# function to verify density computations
-
-verifyDensity <- function(points, expected, lambda, tol) {
- rDensityValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDensityValues[i] <- dpois(point, lambda, log = FALSE)
- }
- output <- c("Density test lambda = ", lambda)
- if (assertEquals(expected, rDensityValues, tol, "Density Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify distribution computations
-
-verifyDistribution <- function(points, expected, lambda, tol) {
- rDistValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDistValues[i] <- ppois(point, lambda, log = FALSE)
- }
- output <- c("Distribution test lambda = ", lambda)
- if (assertEquals(expected, rDistValues, tol, "Distribution Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify normal approximation
-
-verifyNormalApproximation <- function(expected, lambda, lower, upper, tol) {
- rValue <- pnorm(upper, mean=lambda, sd=sqrt(lambda), lower.tail = TRUE,
- log.p = FALSE) -
- pnorm(lower, mean=lambda, sd=sqrt(lambda), lower.tail = TRUE,
- log.p = FALSE)
- output <- c("Normal approx. test lambda = ", lambda, " upper = ",
- upper, " lower = ", lower)
- if (assertEquals(expected, rValue, tol, "Distribution Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-cat("Poisson distribution test cases\n")
-
-# stock tests
-
-lambda <- 4.0
-densityPoints <- c(-1,0,1,2,3,4,5,10,20)
-densityValues <- c(0, 0.0183156388887, 0.073262555555, 0.14652511111,
- 0.195366814813, 0.195366814813, 0.156293451851,
- 0.00529247667642, 8.27746364655e-09)
-verifyDensity(densityPoints, densityValues, lambda, tol)
-
-
-distributionPoints <- c(-1, 0, 1, 2, 3, 4, 5, 10, 20)
-distributionValues <- c(0, 0.0183156388887, 0.0915781944437, 0.238103305554,
- 0.433470120367, 0.62883693518, 0.78513038703,
- 0.99716023388, 0.999999998077)
-verifyDistribution(distributionPoints, distributionValues, lambda, tol)
-
-# normal approximation tests
-
-lambda <- 100
-verifyNormalApproximation(0.706281887248, lambda, 89.5, 110.5, tol)
-
-lambda <- 10000
-verifyNormalApproximation(0.820070051552, lambda, 9899.5, 10200.5, tol)
-
-displayDashes(WIDTH)
-
-
-
-
-
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/regressionTestCases
----------------------------------------------------------------------
diff --git a/src/test/R/regressionTestCases b/src/test/R/regressionTestCases
deleted file mode 100644
index d8b3c73..0000000
--- a/src/test/R/regressionTestCases
+++ /dev/null
@@ -1,159 +0,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.
-#
-#-----------------------------------------------------------------------
-# R source file to validate Binomial distribution tests in
-# org.apache.commons.math.stat.regression.SimpleRegressionTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-# Output will be written to a file named "regTestResults"
-# in the directory from which R was launched
-#
-#------------------------------------------------------------------------------
-tol <- 1E-8
-#------------------------------------------------------------------------------
-# Function definitions
-
-source("testFunctions") # utility test functions
-#------------------------------------------------------------------------------
-# infData example
-
-cat("Regresssion test cases\n")
-
-x <- c(15.6, 26.8,37.8,36.4,35.5,18.6,15.3,7.9,0.0)
-y <- c(5.2, 6.1, 8.7, 8.5, 8.8, 4.9, 4.5, 2.5, 1.1)
-model<-lm(y~x)
-coef <- coefficients(summary(model))
-intercept <- coef[1, 1]
-interceptStd <- coef[1, 2]
-slope <- coef[2, 1]
-slopeStd <- coef[2, 2]
-significance <- coef[2, 4]
-
-output <- "InfData std error test"
-if (assertEquals(0.011448491, slopeStd, tol, "Slope Standard Error") &&
- assertEquals(0.286036932, interceptStd, tol, "Intercept Standard Error")) {
- displayPadded(output, SUCCEEDED, WIDTH)
-} else {
- displayPadded(output, FAILED, WIDTH)
-}
-
-output <- "InfData significance test"
-if (assertEquals(4.596e-07, significance, tol, "Significance")) {
- displayPadded(output, SUCCEEDED, WIDTH)
-} else {
- displayPadded(output, FAILED, WIDTH)
-}
-
-output <- "InfData conf interval test"
-ci<-confint(model)
-# ci[1,1] = lower 2.5% bound for intercept, ci[1,2] = upper 97.5% for intercept
-# ci[2,1] = lower 2.5% bound for slope, ci[2,2] = upper 97.5% for slope
-halfWidth <- ci[2,2] - slope
-if (assertEquals(0.0270713794287, halfWidth, tol,
- "Slope conf. interval half-width")) {
- displayPadded(output, SUCCEEDED, WIDTH)
-} else {
- displayPadded(output, FAILED, WIDTH)
-}
-#------------------------------------------------------------------------------
-# Norris dataset from NIST examples
-
-y <- c(0.1, 338.8, 118.1, 888.0, 9.2, 228.1, 668.5, 998.5, 449.1, 778.9, 559.2,
-0.3, 0.1, 778.1, 668.8, 339.3, 448.9, 10.8, 557.7, 228.3, 998.0, 888.8, 119.6,
-0.3, 0.6, 557.6, 339.3, 888.0, 998.5, 778.9, 10.2, 117.6, 228.9, 668.4, 449.2,
-0.2)
-x <- c(0.2, 337.4, 118.2, 884.6, 10.1, 226.5, 666.3, 996.3, 448.6, 777.0, 558.2,
-0.4, 0.6, 775.5, 666.9, 338.0, 447.5, 11.6, 556.0, 228.1, 995.8, 887.6, 120.2,
-0.3, 0.3, 556.8, 339.1, 887.2, 999.0, 779.0, 11.1, 118.3, 229.2, 669.1, 448.9,
-0.5)
-model<-lm(y~x)
-coef <- coefficients(summary(model))
-intercept <- coef[1, 1]
-interceptStd <- coef[1, 2]
-slope <- coef[2, 1]
-slopeStd <- coef[2, 2]
-
-output <- "Norris std error test"
-if (assertEquals(0.429796848199937E-03, slopeStd, tol, "Slope Standard Error")
- && assertEquals(0.232818234301152, interceptStd, tol,
- "Intercept Standard Error")) {
- displayPadded(output, SUCCEEDED, WIDTH)
-} else {
- displayPadded(output, FAILED, WIDTH)
-}
-#------------------------------------------------------------------------------
-# infData2 -- bad fit example
-#
-x <- c(1,2,3,4,5,6)
-y <- c(1,0,5,2,-1,12)
-model<-lm(y~x)
-coef <- coefficients(summary(model))
-intercept <- coef[1, 1]
-interceptStd <- coef[1, 2]
-slope <- coef[2, 1]
-slopeStd <- coef[2, 2]
-significance <- coef[2, 4]
-
-output <- "InfData2 std error test"
-if (assertEquals(1.07260253, slopeStd, tol, "Slope Standard Error") &&
- assertEquals(4.17718672, interceptStd, tol, "Intercept Standard Error")) {
- displayPadded(output, SUCCEEDED, WIDTH)
-} else {
- displayPadded(output, FAILED, WIDTH)
-}
-
-output <- "InfData2 significance test"
-if (assertEquals(0.261829133982, significance, tol, "Significance")) {
- displayPadded(output, SUCCEEDED, WIDTH)
-} else {
- displayPadded(output, FAILED, WIDTH)
-}
-
-output <- "InfData2 conf interval test"
-ci<-confint(model)
-# ci[1,1] = lower 2.5% bound for intercept, ci[1,2] = upper 97.5% for intercept
-# ci[2,1] = lower 2.5% bound for slope, ci[2,2] = upper 97.5% for slope
-halfWidth <- ci[2,2] - slope
-if (assertEquals(2.97802204827, halfWidth, tol,
- "Slope conf. interval half-width")) {
- displayPadded(output, SUCCEEDED, WIDTH)
-} else {
- displayPadded(output, FAILED, WIDTH)
-}
-#------------------------------------------------------------------------------
-# Correlation example
-
-x <- c(101.0, 100.1, 100.0, 90.6, 86.5, 89.7, 90.6, 82.8, 70.1, 65.4,
- 61.3, 62.5, 63.6, 52.6, 59.7, 59.5, 61.3)
-y <- c(99.2, 99.0, 100.0, 111.6, 122.2, 117.6, 121.1, 136.0, 154.2, 153.6,
- 158.5, 140.6, 136.2, 168.0, 154.3, 149.0, 165.5)
-
-output <- "Correlation test"
-if (assertEquals(-0.94663767742, cor(x,y, method="pearson"), tol,
- "Correlation coefficient")) {
- displayPadded(output, SUCCEEDED, WIDTH)
-} else {
- displayPadded(output, FAILED, WIDTH)
-}
-
-displayDashes(WIDTH)
-
-
-
-
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/testAll
----------------------------------------------------------------------
diff --git a/src/test/R/testAll b/src/test/R/testAll
deleted file mode 100644
index 49c460b..0000000
--- a/src/test/R/testAll
+++ /dev/null
@@ -1,83 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to run all commons-math R verification tests
-#
-# To run the test, install R, put this file and all other o.a.c.math R
-# verification tests and the testfunctions utilities file into the same
-# directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-# The KolmogorovSmirnov and Pareto distribution tests require the following
-# packages to be installed:
-#
-# https://cran.r-project.org/web/packages/Matching/index.html
-# https://cran.r-project.org/web/packages/VGAM/index.html
-#
-# To redirect output to a file, uncomment the following line, substituting
-# another file path if you like (default behavior is to write the file to the
-# current directory).
-#
-# sink("testResults")
-#------------------------------------------------------------------------------
-# distribution
-source("binomialTestCases")
-source("normalTestCases")
-source("poissonTestCases")
-source("paretoTestCases")
-source("logNormalTestCases")
-source("hypergeometricTestCases")
-source("exponentialTestCases")
-source("cauchyTestCases.R")
-source("pascalTestCases")
-source("TDistributionTestCases.R")
-source("FDistributionTestCases.R")
-source("GammaDistributionTestCases.R")
-source("WeibullDistributionTestCases.R")
-source("ChiSquareDistributionTestCases.R")
-source("LevyDistributionTestCases.R")
-source("gumbelTestCases.R")
-source("laplaceTestCases.R")
-source("logisticsTestCases.R")
-source("nakagamiTestCases.R")
-source("zipfTestCases")
-
-# regression
-source("regressionTestCases")
-
-# inference
-source("chiSquareTestCases")
-source("anovaTestCases")
-source("KolmogorovSmirnovTestCases.R")
-source("TTestCases")
-
-# descriptive
-source("descriptiveTestCases")
-
-# multiple regression
-source("multipleOLSRegressionTestCases")
-
-# covariance
-source("covarianceTestCases")
-
-# correlation
-source("correlationTestCases")
-
-#------------------------------------------------------------------------------
-# if output has been diverted, change it back
-if (sink.number()) {
- sink()
-}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/testFunctions
----------------------------------------------------------------------
diff --git a/src/test/R/testFunctions b/src/test/R/testFunctions
deleted file mode 100644
index 744b554..0000000
--- a/src/test/R/testFunctions
+++ /dev/null
@@ -1,86 +0,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.
-#
-#------------------------------------------------------------------------------
-#
-# Utility functions used in R comparison tests.
-#
-#------------------------------------------------------------------------------
-# Global constants
-#------------------------------------------------------------------------------
-WIDTH <- 80 # screen size constant for display functions
-SUCCEEDED <- "SUCCEEDED"
-FAILED <- "FAILED"
-options(digits=15) # display 12 digits throughout
-#------------------------------------------------------------------------------
-# Comparison functions
-#------------------------------------------------------------------------------
-# Tests to see if <expected> and <observed> are within <tol> of
-# one another in the sup norm.
-#
-# Returns 1 if no pair of corresponding non-NULL, non-NaN, non-na entries
-# differs by more than abs and NULLs, NaNs, na's correspond;
-# otherwise displays <message> and returns 0.
-# Works for both vectors and scalar values.
-#
-assertEquals <- function(expected, observed, tol, message) {
- failed <- 0
- if (any(is.na(observed) != is.na(expected))) {
- failed <- 1
- }
- if (any(is.null(observed) != is.null(expected))) {
- failed <- 1
- }
- if (any(is.nan(expected) != is.nan(observed))) {
- failed <- 1
- }
- if (any(is.na(expected) != is.na(observed))) {
- failed <- 1
- }
- if (!failed) {
- if(any(abs(observed - expected) > tol, na.rm = TRUE)) {
- failed <- 1
- }
- }
- if (failed) {
- cat("FAILURE: ",message,"\n")
- cat("EXPECTED: ",expected,"\n")
- cat("OBSERVED: ",observed,"\n")
- cat("DIFF: ",observed - expected,"\n")
- cat("TOLERANCE: ",tol,"\n")
- }
- return(!failed)
-}
-#------------------------------------------------------------------------------
-# Display functions
-#------------------------------------------------------------------------------
-# Displays n-col dashed line.
-#
-displayDashes <- function(n) {
- cat(rep("-",n),"\n",sep='')
- return(1)
-}
-#------------------------------------------------------------------------------
-# Displays <start>......<end> with enough dots in between to make <n> cols,
-# followed by a new line character. Blows up if <start><end> is longer than
-# <n> cols by itself.
-#
-# Expects <start> and <end> to be strings (character vectors).
-#
-displayPadded <- function(start, end, n) {
- len = sum(nchar(start)) + sum(nchar(end))
- cat(start, rep(".", n - len), end, "\n",sep='')
- return(1)
-}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/zipfTestCases
----------------------------------------------------------------------
diff --git a/src/test/R/zipfTestCases b/src/test/R/zipfTestCases
deleted file mode 100644
index 318fffa..0000000
--- a/src/test/R/zipfTestCases
+++ /dev/null
@@ -1,89 +0,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.
-#
-#------------------------------------------------------------------------------
-# R source file to validate Zipf distribution tests in
-# org.apache.commons.math.distribution.ZipfDistributionTest
-#
-# To run the test, install R, put this file and testFunctions
-# into the same directory, launch R from this directory and then enter
-# source("<name-of-this-file>")
-#
-# R functions used
-# dzipf(x, N, s, log = FALSE) <- density
-# pzipf(q, N, s) <- distribution
-#------------------------------------------------------------------------------
-tol <- 1E-6 # error tolerance for tests
-#------------------------------------------------------------------------------
-# Function definitions
-
-library(VGAM)
-source("testFunctions") # utility test functions
-
-# function to verify density computations
-
-verifyDensity <- function(points, expected, N, s, tol, log = FALSE) {
- rDensityValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDensityValues[i] <- dzipf(point, N, s, log)
- }
- output <- c("Density test N = ", N, ", s = ", s)
- if (assertEquals(expected,rDensityValues,tol,"Density Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-# function to verify distribution computations
-
-verifyDistribution <- function(points, expected, N, s, tol) {
- rDistValues <- rep(0, length(points))
- i <- 0
- for (point in points) {
- i <- i + 1
- rDistValues[i] <- pzipf(point, N, s)
- }
- output <- c("Distribution test N = ", N, ", s = ", s)
- if (assertEquals(expected,rDistValues,tol,"Distribution Values")) {
- displayPadded(output, SUCCEEDED, WIDTH)
- } else {
- displayPadded(output, FAILED, WIDTH)
- }
-}
-
-#--------------------------------------------------------------------------
-cat("Zipf test cases\n")
-
-N <- 10
-s <- 1
-
-densityPoints <- c(-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
-densityValues <- c(0, 0, 0.341417152147406, 0.170708576073703, 0.113805717382469, 0.0853542880368514,
- 0.0682834304294811, 0.0569028586912343, 0.0487738788782008, 0.0426771440184257,
- 0.0379352391274895, 0.0341417152147406, 0)
-logDensityValues <- c(Inf, NaN, -1.07465022926458, -1.76779740982453, -2.17326251793269, -2.46094459038447,
- -2.68408814169868, -2.86640969849264, -3.0205603783199, -3.15409177094442, -3.2718748066008,
- -3.37723532225863, -Inf)
-distributionValues <- c(0, 0, 0.341417152147406, 0.512125728221108, 0.625931445603577, 0.711285733640428,
- 0.779569164069909, 0.836472022761144, 0.885245901639344, 0.92792304565777,
- 0.96585828478526, 1, 1)
-
-verifyDensity(densityPoints, densityValues, N, s, tol)
-verifyDensity(densityPoints, logDensityValues, N, s, tol, TRUE)
-verifyDistribution(densityPoints, distributionValues, N, s, tol)
-
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/java/org/apache/commons/complex/ComplexFormatAbstractTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/complex/ComplexFormatAbstractTest.java b/src/test/java/org/apache/commons/complex/ComplexFormatAbstractTest.java
deleted file mode 100644
index d869e4d..0000000
--- a/src/test/java/org/apache/commons/complex/ComplexFormatAbstractTest.java
+++ /dev/null
@@ -1,310 +0,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.
- */
-
-package org.apache.commons.complex;
-
-import java.text.NumberFormat;
-import java.text.ParsePosition;
-import java.util.Locale;
-
-import org.junit.Test;
-import org.junit.Assert;
-import org.apache.commons.complex.Complex;
-import org.apache.commons.complex.ComplexFormat;
-
-public abstract class ComplexFormatAbstractTest {
-
- ComplexFormat complexFormat = null;
- ComplexFormat complexFormatJ = null;
-
- protected abstract Locale getLocale();
-
- protected abstract char getDecimalCharacter();
-
- protected ComplexFormatAbstractTest() {
- complexFormat = ComplexFormat.getInstance(getLocale());
- complexFormatJ = ComplexFormat.getInstance("j", getLocale());
- }
-
- @Test
- public void testSimpleNoDecimals() {
- Complex c = new Complex(1, 2);
- String expected = "1 + 2i";
- String actual = complexFormat.format(c);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testTrimOneImaginary() {
- final ComplexFormat fmt = ComplexFormat.getInstance(getLocale());
- fmt.getImaginaryFormat().setMaximumFractionDigits(1);
-
- Complex c = new Complex(1, 1.04);
- String expected = "1 + i";
- String actual = fmt.format(c);
- Assert.assertEquals(expected, actual);
-
- c = new Complex(1, 1.09);
- expected = "1 + 1" + getDecimalCharacter() + "1i";
- actual = fmt.format(c);
- Assert.assertEquals(expected, actual);
-
- c = new Complex(1, -1.09);
- expected = "1 - 1" + getDecimalCharacter() + "1i";
- actual = fmt.format(c);
- Assert.assertEquals(expected, actual);
-
- c = new Complex(1, -1.04);
- expected = "1 - i";
- actual = fmt.format(c);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testSimpleWithDecimals() {
- Complex c = new Complex(1.23, 1.43);
- String expected = "1" + getDecimalCharacter() + "23 + 1" + getDecimalCharacter() + "43i";
- String actual = complexFormat.format(c);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testSimpleWithDecimalsTrunc() {
- Complex c = new Complex(1.232323232323, 1.434343434343);
- String expected = "1" + getDecimalCharacter() + "2323232323 + 1" + getDecimalCharacter() + "4343434343i";
- String actual = complexFormat.format(c);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testNegativeReal() {
- Complex c = new Complex(-1.232323232323, 1.43);
- String expected = "-1" + getDecimalCharacter() + "2323232323 + 1" + getDecimalCharacter() + "43i";
- String actual = complexFormat.format(c);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testNegativeImaginary() {
- Complex c = new Complex(1.23, -1.434343434343);
- String expected = "1" + getDecimalCharacter() + "23 - 1" + getDecimalCharacter() + "4343434343i";
- String actual = complexFormat.format(c);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testNegativeBoth() {
- Complex c = new Complex(-1.232323232323, -1.434343434343);
- String expected = "-1" + getDecimalCharacter() + "2323232323 - 1" + getDecimalCharacter() + "4343434343i";
- String actual = complexFormat.format(c);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testZeroReal() {
- Complex c = new Complex(0.0, -1.434343434343);
- String expected = "0 - 1" + getDecimalCharacter() + "4343434343i";
- String actual = complexFormat.format(c);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testZeroImaginary() {
- Complex c = new Complex(30.23333333333, 0);
- String expected = "30" + getDecimalCharacter() + "2333333333";
- String actual = complexFormat.format(c);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testDifferentImaginaryChar() {
- Complex c = new Complex(1, 1);
- String expected = "1 + j";
- String actual = complexFormatJ.format(c);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testDefaultFormatComplex() {
- Locale defaultLocal = Locale.getDefault();
- Locale.setDefault(getLocale());
-
- Complex c = new Complex(232.22222222222, -342.3333333333);
- String expected = "232" + getDecimalCharacter() + "2222222222 - 342" + getDecimalCharacter() + "3333333333i";
- String actual = (new ComplexFormat()).format(c);
- Assert.assertEquals(expected, actual);
-
- Locale.setDefault(defaultLocal);
- }
-
- @Test
- public void testNan() {
- Complex c = new Complex(Double.NaN, Double.NaN);
- String expected = "(NaN) + (NaN)i";
- String actual = complexFormat.format(c);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testPositiveInfinity() {
- Complex c = new Complex(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
- String expected = "(Infinity) + (Infinity)i";
- String actual = complexFormat.format(c);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testNegativeInfinity() {
- Complex c = new Complex(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY);
- String expected = "(-Infinity) - (Infinity)i";
- String actual = complexFormat.format(c);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testParseSimpleNoDecimals() {
- String source = "1 + 1i";
- Complex expected = new Complex(1, 1);
- Complex actual = complexFormat.parse(source);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testParseSimpleWithDecimals() {
- String source = "1" + getDecimalCharacter() + "23 + 1" + getDecimalCharacter() + "43i";
- Complex expected = new Complex(1.23, 1.43);
- Complex actual = complexFormat.parse(source);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testParseSimpleWithDecimalsTrunc() {
- String source = "1" + getDecimalCharacter() + "232323232323 + 1" + getDecimalCharacter() + "434343434343i";
- Complex expected = new Complex(1.232323232323, 1.434343434343);
- Complex actual = complexFormat.parse(source);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testParseNegativeReal() {
- String source = "-1" + getDecimalCharacter() + "232323232323 + 1" + getDecimalCharacter() + "4343i";
- Complex expected = new Complex(-1.232323232323, 1.4343);
- Complex actual = complexFormat.parse(source);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testParseNegativeImaginary() {
- String source = "1" + getDecimalCharacter() + "2323 - 1" + getDecimalCharacter() + "434343434343i";
- Complex expected = new Complex(1.2323, -1.434343434343);
- Complex actual = complexFormat.parse(source);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testParseNegativeBoth() {
- String source = "-1" + getDecimalCharacter() + "232323232323 - 1" + getDecimalCharacter() + "434343434343i";
- Complex expected = new Complex(-1.232323232323, -1.434343434343);
- Complex actual = complexFormat.parse(source);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testParseZeroReal() {
- String source = "0" + getDecimalCharacter() + "0 - 1" + getDecimalCharacter() + "4343i";
- Complex expected = new Complex(0.0, -1.4343);
- Complex actual = complexFormat.parse(source);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testParseZeroImaginary() {
- String source = "-1" + getDecimalCharacter() + "2323";
- Complex expected = new Complex(-1.2323, 0);
- Complex actual = complexFormat.parse(source);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testParseDifferentImaginaryChar() {
- String source = "-1" + getDecimalCharacter() + "2323 - 1" + getDecimalCharacter() + "4343j";
- Complex expected = new Complex(-1.2323, -1.4343);
- Complex actual = complexFormatJ.parse(source);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testParseNan() {
- String source = "(NaN) + (NaN)i";
- Complex expected = new Complex(Double.NaN, Double.NaN);
- Complex actual = complexFormat.parse(source);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testParsePositiveInfinity() {
- String source = "(Infinity) + (Infinity)i";
- Complex expected = new Complex(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
- Complex actual = complexFormat.parse(source);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testPaseNegativeInfinity() {
- String source = "(-Infinity) - (Infinity)i";
- Complex expected = new Complex(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY);
- Complex actual = complexFormat.parse(source);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testConstructorSingleFormat() {
- NumberFormat nf = NumberFormat.getInstance();
- ComplexFormat cf = new ComplexFormat(nf);
- Assert.assertNotNull(cf);
- Assert.assertEquals(nf, cf.getRealFormat());
- }
-
- @Test
- public void testGetImaginaryFormat() {
- NumberFormat nf = NumberFormat.getInstance();
- ComplexFormat cf = new ComplexFormat(nf);
- Assert.assertSame(nf, cf.getImaginaryFormat());
- }
-
- @Test
- public void testGetRealFormat() {
- NumberFormat nf = NumberFormat.getInstance();
- ComplexFormat cf = new ComplexFormat(nf);
- Assert.assertSame(nf, cf.getRealFormat());
- }
-
- @Test
- public void testFormatNumber() {
- ComplexFormat cf = ComplexFormat.getInstance(getLocale());
- Double pi = Double.valueOf(Math.PI);
- String text = cf.format(pi);
- Assert.assertEquals("3" + getDecimalCharacter() + "1415926536", text);
- }
-
- @Test
- public void testForgottenImaginaryCharacter() {
- ParsePosition pos = new ParsePosition(0);
- Assert.assertNull(new ComplexFormat().parse("1 + 1", pos));
- Assert.assertEquals(5, pos.getErrorIndex());
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/java/org/apache/commons/complex/ComplexFormatTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/complex/ComplexFormatTest.java b/src/test/java/org/apache/commons/complex/ComplexFormatTest.java
deleted file mode 100644
index c308b46..0000000
--- a/src/test/java/org/apache/commons/complex/ComplexFormatTest.java
+++ /dev/null
@@ -1,33 +0,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.
- */
-
-package org.apache.commons.complex;
-
-import java.util.Locale;
-
-
-public class ComplexFormatTest extends ComplexFormatAbstractTest {
- @Override
- protected char getDecimalCharacter() {
- return '.';
- }
-
- @Override
- protected Locale getLocale() {
- return Locale.US;
- }
-}
[18/31] commons-numbers git commit: Cleanup.
Posted by er...@apache.org.
Cleanup.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/7a4a3a61
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/7a4a3a61
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/7a4a3a61
Branch: refs/heads/master
Commit: 7a4a3a61e75d23ae0e35c7b261b0f1daa2a1f94a
Parents: 69d3b62
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Fri Jan 20 13:38:52 2017 +0100
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Fri Jan 20 13:38:52 2017 +0100
----------------------------------------------------------------------
src/site/apt/userguide/special.apt | 136 ------------------------
src/site/design/differentiation.puml | 105 -------------------
src/site/design/oneD.puml | 81 --------------
src/site/design/partitioning.puml | 118 ---------------------
src/site/design/solver.puml | 102 ------------------
src/site/design/threeD.puml | 86 ---------------
src/site/design/twoD.puml | 84 ---------------
src/site/xdoc/download_math.xml | 168 ------------------------------
src/site/xdoc/proposal.xml | 131 -----------------------
9 files changed, 1011 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/7a4a3a61/src/site/apt/userguide/special.apt
----------------------------------------------------------------------
diff --git a/src/site/apt/userguide/special.apt b/src/site/apt/userguide/special.apt
deleted file mode 100644
index 420e055..0000000
--- a/src/site/apt/userguide/special.apt
+++ /dev/null
@@ -1,136 +0,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.
-~~
-
- -----------------------------------------------
- The Commons Math User Guide - Special Functions
- -----------------------------------------------
-
-5 Special Functions
-
-* 5.1 Overview
-
- The <<<special>>> package of Commons-Math gathers several useful special
- functions not provided by <<<java.lang.Math>>>.
-
-* 5.2 Erf functions
-
- {{{../apidocs/org/apache/commons/math4/special/Erf.html}Erf}} contains
- several useful functions involving the Error Function, Erf.
-
-*----------------+---------+-------------------------------------------------------------------+
-|| Function || Method || Reference |
-*----------------+---------+-------------------------------------------------------------------+
-| Error Function |erf | See {{{http://mathworld.wolfram.com/Erf.html}Erf}} from MathWorld |
-*----------------+---------+-------------------------------------------------------------------+
-
-* 5.3 Gamma functions
-
- Class {{{../apidocs/org/apache/commons/math4/special/Gamma.html}<<<Gamma>>>}}
- contains several useful functions involving the Gamma Function.
-
-** Gamma
-
- <<<Gamma.gamma(x)>>> computes the Gamma function, \u0393(x)
- (see {{{http://mathworld.wolfram.com/GammaFunction.html}MathWorld}},
- {{{http://dlmf.nist.gov/5}DLMF}}). The accuracy of the Commons-Math
- implementation is assessed by comparison with high precision values computed
- with the {{{http://maxima.sourceforge.net/}Maxima}} Computer Algebra System.
-
-*----------------+-----------------------------------------------+-----------------+----------------------+----------------+
-|| Interval || Values tested || Average error || Standard deviation || Maximum error |
-*----------------+-----------------------------------------------+-----------------+----------------------+----------------+
-| -5 \< x \< -4 | <<<x[i] = i / 1024, i = -5119, ..., -4097>>> | 0.49 ulps | 0.57 ulps | 3.0 ulps |
-*----------------+-----------------------------------------------+-----------------+----------------------+----------------+
-| -4 \< x \< -3 | <<<x[i] = i / 1024, i = -4095, ..., -3073>>> | 0.36 ulps | 0.51 ulps | 2.0 ulps |
-*----------------+-----------------------------------------------+-----------------+----------------------+----------------+
-| -3 \< x \< -2 | <<<x[i] = i / 1024, i = -3071, ..., -2049>>> | 0.41 ulps | 0.53 ulps | 2.0 ulps |
-*----------------+-----------------------------------------------+-----------------+----------------------+----------------+
-| -2 \< x \< -1 | <<<x[i] = i / 1024, i = -2047, ..., -1025>>> | 0.37 ulps | 0.50 ulps | 2.0 ulps |
-*----------------+-----------------------------------------------+-----------------+----------------------+----------------+
-| -1 \< x \< 0 | <<<x[i] = i / 1024, i = -1023, ..., -1>>> | 0.46 ulps | 0.54 ulps | 2.0 ulps |
-*----------------+-----------------------------------------------+-----------------+----------------------+----------------+
-| 0 \< x \u2264 8 | <<<x[i] = i / 1024, i = 1, ..., 8192>>> | 0.33 ulps | 0.48 ulps | 2.0 ulps |
-*----------------+-----------------------------------------------+-----------------+----------------------+----------------+
-| 8 \< x \u2264 141 | <<<x[i] = i / 64, i = 513, ..., 9024>>> | 1.32 ulps | 1.19 ulps | 7.0 ulps |
-*----------------+-----------------------------------------------+-----------------+----------------------+----------------+
-
-** Log Gamma
-
- <<<Gamma.logGamma(x)>>> computes the natural logarithm of the Gamma function,
- log \u0393(x), for x > 0
- (see {{{http://mathworld.wolfram.com/LogGammaFunction.html}MathWorld}},
- {{{http://dlmf.nist.gov/5}DLMF}}). The accuracy of the Commons-Math
- implementation is assessed by comparaison with high precision values computed
- with the {{{http://maxima.sourceforge.net/}Maxima}} Computer Algebra System.
-
-*------------------------------------------------+-----------------------------------------------+-----------------+----------------------+----------------+
-|| Interval || Values tested || Average error || Standard deviation || Maximum error |
-*------------------------------------------------+-----------------------------------------------+-----------------+----------------------+----------------+
-| 0 \< x \u2264 8 | <<<x[i] = i / 1024, i = 1, ..., 8192>>> | 0.32 ulps | 0.50 ulps | 4.0 ulps |
-*------------------------------------------------+-----------------------------------------------+-----------------+----------------------+----------------+
-| 8 \< x \u2264 1024 | <<<x[i] = i / 8, i = 65, ..., 8192>>> | 0.43 ulps | 0.53 ulps | 3.0 ulps |
-*------------------------------------------------+-----------------------------------------------+-----------------+----------------------+----------------+
-| 1024 \< x \u2264 8192 | <<<x[i], i = 1025, ..., 8192>>> | 0.53 ulps | 0.56 ulps | 3.0 ulps |
-*------------------------------------------------+-----------------------------------------------+-----------------+----------------------+----------------+
-| 8933.439345993791 \u2264 x \u2264 1.75555970201398e+305 | <<<x[i] = 2**(i / 8), i = 105, ..., 8112>>> | 0.35 ulps | 0.49 ulps | 2.0 ulps |
-*------------------------------------------------+-----------------------------------------------+-----------------+----------------------+----------------+
-
-** Regularized Gamma
-
- <<<Gamma.regularizedGammaP(a, x)>>> computes the value of the regularized
- Gamma function, P(a, x)
- (see {{{http://mathworld.wolfram.com/RegularizedGammaFunction.html}MathWorld}}).
-
-* 5.4 Beta functions
-
- {{{../apidocs/org/apache/commons/math4/special/Beta.html}Beta}} contains
- several useful functions involving the Beta Function.
-
-** Log Beta
-
- <<<Beta.logBeta(a, b)>>> computes the value of the natural logarithm of the
- Beta function, log B(a, b).
- (see {{{http://mathworld.wolfram.com/BetaFunction.html}MathWorld}},
- {{{http://dlmf.nist.gov/5.12}DLMF}}). The accuracy of the Commons-Math
- implementation is assessed by comparison with high precision values computed
- with the {{{http://maxima.sourceforge.net/}Maxima}} Computer Algebra System.
-
-*----------------+-----------------------------------------+-----------------+----------------------+----------------+
-|| Interval || Values tested || Average error || Standard deviation || Maximum error |
-*----------------+-----------------------------------------+-----------------+----------------------+-----------------+
-| 0 \< x \u2264 8\ | <<<x[i] = i / 32, i = 1, ..., 256>>>\ | 1.80 ulps | 81.08 ulps | 14031.0 ulps |
-| 0 \< y \u2264 8 | <<<y[j] = j / 32, j = 1, ..., 256>>> | | | |
-*----------------+-----------------------------------------+-----------------+----------------------+-----------------+
-| 0 \< x \u2264 8\ | <<<x[i] = i / 32, i = 1, ..., 256>>>\ | 0.50 ulps | 3.64 ulps | 694.0 ulps |
-| 8 \< y \u2264 16 | <<<y[j] = j / 32, j = 257, ..., 512>>> | | | |
-*----------------+-----------------------------------------+-----------------+----------------------+-----------------+
-| 0 \< x \u2264 8\ | <<<x[i] = i / 32, i = 1, ..., 256>>>\ | 1.04 ulps | 139.32 ulps | 34509.0 ulps |
-| 16 \< y \u2264 256 | <<<y[j] = j, j = 17, ..., 256>>> | | | |
-*----------------+-----------------------------------------+-----------------+----------------------+-----------------+
-| 8 \< x \u2264 16\ | <<<x[i] = i / 32, i = 257, ..., 512>>>\ | 0.35 ulps | 0.48 ulps | 2.0 ulps |
-| 8 \< y \u2264 16 | <<<y[j] = j / 32, j = 257, ..., 512>>> | | | |
-*----------------+-----------------------------------------+-----------------+----------------------+-----------------+
-| 8 \< x \u2264 16\ | <<<x[i] = i / 32, i = 257, ..., 512>>>\ | 0.31 ulps | 0.47 ulps | 2.0 ulps |
-| 16 \< y \u2264 256 | <<<y[j] = j, j = 17, ..., 256>>> | | | |
-*----------------+-----------------------------------------+-----------------+----------------------+-----------------+
-| 16 \< x \u2264 256\ | <<<x[i] = i, i = 17, ..., 256>>>\ | 0.35 ulps | 0.49 ulps | 2.0 ulps |
-| 16 \< y \u2264 256 | <<<y[j] = j, j = 17, ..., 256>>> | | | |
-*----------------+-----------------------------------------+-----------------+----------------------+-----------------+
-
-** Regularized Beta
-
- (see {{{http://mathworld.wolfram.com/RegularizedBetaFunction.html}MathWorld}})
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/7a4a3a61/src/site/design/differentiation.puml
----------------------------------------------------------------------
diff --git a/src/site/design/differentiation.puml b/src/site/design/differentiation.puml
deleted file mode 100644
index 8649345..0000000
--- a/src/site/design/differentiation.puml
+++ /dev/null
@@ -1,105 +0,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.
-
-@startuml
-
- skinparam svek true
- skinparam ClassBackgroundColor #F3EFEB
- skinparam ClassArrowColor #691616
- skinparam ClassBorderColor #691616
- skinparam NoteBackgroundColor #F3EFEB
- skinparam NoteBorderColor #691616
- skinparam NoteFontColor #691616
- skinparam ClassFontSize 11
-
- package org.apache.commons.math4 #ECEBD8 {
-
- interface "FieldElement<T>" as FieldElement_T_ {
- T add(T a)
- T subtract(T a)
- T negate()
- T multiply(int n)
- T multiply(T a)
- T divide(T a)
- T reciprocal()
- Field<T> getField()
- }
-
- package analysis #DDEBD8 {
- interface UnivariateFunction {
- double value(double x)
- }
-
- package differentiation #DDDBD8 {
-
- class DerivativeStructure {
- -DerivativeStructure(DSCompiler compiler)
- +DerivativeStructure(int parameters, int order, double value)
- +DerivativeStructure(int parameters, int order, int index, double value)
- +int getFreeParameters()
- +int getOrder()
- +double getValue()
- +double getPartialDerivative(int[] orders)
- +double taylor(double[] delta)
- +int getExponent()
- +DerivativeStructure compose(double[] f)
- +DerivativeStructure cos()
- +DerivativeStructure sin()
- +DerivativeStructure exp()
- +DerivativeStructure sqrt()
- }
- note bottom
- lots of mathematical methods
- and constructors ommitted for clarity
- end note
-
- class DSCompiler {
- {static} +DSCompiler getCompiler(int parameters, int order)
- +int getPartialDerivativeIndex(int[] orders)
- +int[] getPartialDerivativeOrders(int index)
- +int getFreeParameters()
- +int getOrder()
- +int getSize()
- +void checkCompatibility(DSCompiler compiler)
- +void compose(double[] operand, int operandOffset, double[] f, double[] result, int resultOffset)
- +double taylor(double[] ds, int dsOffset, double[] delta)
- +void add(double[] lhs, int lhsOffset, double[] rhs, int rhsOffset, double[] result, int resultOffset)
- +void exp(double[] operand, int operandOffset, double[] result, int resultOffset)
- }
- note bottom
- one compiler is built for each pair
- (number of parameters, derivation order)
- they are cached for efficiency
- end note
-
- interface UnivariateDifferentiable {
- DerivativeStructure value(DerivativeStructure t)
- }
-
- interface UnivariateDifferentiator {
- UnivariateDifferentiable differentiate(UnivariateFunction function)
- }
-
- FieldElement_T_ <.. DerivativeStructure
- DerivativeStructure o--> "1" DSCompiler : delegates computation
- UnivariateFunction <|.. UnivariateDifferentiable
- UnivariateDifferentiable <-- UnivariateDifferentiator : creates
- UnivariateDifferentiable --> DerivativeStructure : uses
-
- }
- }
- }
-
-@enduml
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/7a4a3a61/src/site/design/oneD.puml
----------------------------------------------------------------------
diff --git a/src/site/design/oneD.puml b/src/site/design/oneD.puml
deleted file mode 100644
index 8620f84..0000000
--- a/src/site/design/oneD.puml
+++ /dev/null
@@ -1,81 +0,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.
-
-@startuml
-
- skinparam svek true
- skinparam ClassBackgroundColor #F3EFEB
- skinparam ClassArrowColor #691616
- skinparam ClassBorderColor #691616
- skinparam NoteBackgroundColor #F3EFEB
- skinparam NoteBorderColor #691616
- skinparam NoteFontColor #691616
- skinparam ClassFontSize 11
-
- package org.apache.commons.complex.geometry #ECEBD8 {
-
- interface Space {
- +int getDimension()
- +Space getSubSpace()
- }
- note top
- Space is mainly used as a parameter
- for generics and to link d-dimensional
- space with (d-1)-dimensional space
- end note
-
- interface "Vector<S extends Space>" as Vector_S_ {
- +Space getSpace()
- +Vector getZero()
- +double getNorm()
- +Vector add()
- +Vector subtract()
- +Vector negate()
- +Vector normalize()
- +Vector scalarMultiply()
- +boolean isNaN()
- +boolean isInfinite()
- +double distance()
- +double dotProduct()
- }
-
- Space <-- Vector_S_
-
- package partitioning #DDEBD8 {
- interface "Region<S extends Space>" as Region_S_
- interface "Hyperplane<S extends Space>" as Hyperplane_S_
- interface "SubHyperplane<S extends Space>" as SubHyperplane_S_
- }
-
- package euclidean #DDEBD8 {
-
- package oned #DDDBD8 {
-
- class Euclidean1D
- class OrientedPoint
- class Interval
- class IntervalSet
-
- Space <|.. Euclidean1D
- Vector_S_ <|.. OrientedPoint
- Region_S_ <|.. IntervalSet
-
- }
-
- }
-
- }
-
-@enduml
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/7a4a3a61/src/site/design/partitioning.puml
----------------------------------------------------------------------
diff --git a/src/site/design/partitioning.puml b/src/site/design/partitioning.puml
deleted file mode 100644
index 5d52e7e..0000000
--- a/src/site/design/partitioning.puml
+++ /dev/null
@@ -1,118 +0,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.
-
-@startuml
-
- skinparam svek true
- skinparam ClassBackgroundColor #F3EFEB
- skinparam ClassArrowColor #691616
- skinparam ClassBorderColor #691616
- skinparam NoteBackgroundColor #F3EFEB
- skinparam NoteBorderColor #691616
- skinparam NoteFontColor #691616
- skinparam ClassFontSize 11
-
- package org.apache.commons.complex.geometry #ECEBD8 {
-
- package partitioning #DDEBD8 {
-
- abstract "AbstractSubHyperplane<S extends Space, T extends Space>" as AbstractSubHyperplane_S_T_
- note left
- an abstract sub-hyperplane contains
- - an hyperplane defined in space S
- - a region defined in space T
- T being a sub-space of S
- end note
-
- interface "Hyperplane<S extends Space>" as Hyperplane_S_ {
- +double getOffset(Vector point)
- +boolean sameOrientationAs(Hyperplane other)
- +SubHyperplane wholeHyperplane()
- +Region wholeSpace()
- }
-
- interface "SubHyperplane<S extends Space>" as SubHyperplane_S_ {
- +Hyperplane getHyperplane()
- +boolean isEmpty()
- +double getSize()
- +Side side(Hyperplane hyperplane)
- +SplitSubHyperplane split(Hyperplane hyperplane)
- +SubHyperplane reunite(SubHyperplane other)
- }
-
- class "BSPTree<S extends Space>" as BSPTree_S_ {
- +boolean insertCut(Hyperplane hyperplane)
- +void setAttribute(Object attribute)
- +Object getAttribute()
- +void visit(BSPTreeVisitor visitor)
- +BSPTree getCell(Vector point)
- +BSPTree split(SubHyperplane sub)
- }
-
- interface "BSPTreeVisitor<S extends Space>" as BSPTreeVisitor_S_ {
- +Order visitOrder(BSPTree node)
- +void visitInternalNode(BSPTree node)
- +void visitLeafNode(BSPTree node)
- }
-
- interface "Region<S extends Space>" as Region_S_ {
- +boolean isEmpty()
- +boolean contains(Region region)
- +Location checkPoint(Vector point)
- +double getBoundarySize()
- +double getSize()
- +Vector getBarycenter()
- +Side side(Hyperplane hyperplane)
- +SubHyperplane intersection(SubHyperplane sub)
- }
- note top
- a region is a part of the space
- it may be empty,
- it may cover the whole space,
- it may have infinite non-closed boundaries,
- it may be in several disconnected sub-parts,
- it may contain holes
- end note
-
- enum Location {
- +INSIDE
- +OUTSIDE
- +BOUNDARY
- }
-
- enum Side {
- +PLUS
- +MINUS
- +BOTH
- +HYPER
- }
-
- Hyperplane_S_ "1" <--* "1" SubHyperplane_S_
- SubHyperplane_S_ "0..1" <--* BSPTree_S_ : cut
- BSPTree_S_ <--o BSPTree_S_ : "parent "
- BSPTree_S_ o--> BSPTree_S_ : "children"
- Region_S_ *--> "1" BSPTree_S_
- Hyperplane_S_ <-- Region_S_
- AbstractSubHyperplane_S_T_ ..|> SubHyperplane_S_
- AbstractSubHyperplane_S_T_ *--> "1" Hyperplane_S_ : hyperplane
- AbstractSubHyperplane_S_T_ *--> "1" Region_S_ : region
- Region_S_ --> Location
- Region_S_ --> Side
- BSPTree_S_ <-- BSPTreeVisitor_S_ : visits
-
- }
-
- }
-@enduml
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/7a4a3a61/src/site/design/solver.puml
----------------------------------------------------------------------
diff --git a/src/site/design/solver.puml b/src/site/design/solver.puml
deleted file mode 100644
index d02d895..0000000
--- a/src/site/design/solver.puml
+++ /dev/null
@@ -1,102 +0,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.
-
-@startuml
-
- skinparam svek true
- skinparam ClassBackgroundColor #F3EFEB
- skinparam ClassArrowColor #691616
- skinparam ClassBorderColor #691616
- skinparam NoteBackgroundColor #F3EFEB
- skinparam NoteBorderColor #691616
- skinparam NoteFontColor #691616
- skinparam ClassFontSize 11
-
- package org.apache.commons.complex.differentiation.solvers #ECEBD8 {
-
- enum AllowedSolution {
- ANY_SIDE
- LEFT_SIDE
- RIGHT_SIDE
- BELOW_SIDE
- ABOVE_SIDE
- }
-
- interface "BaseUnivariateSolver<FUNC extends UnivariateFunction>" as BaseUnivariateSolver_FUNC_ {
- +int getMaxEvaluations()
- +int getEvaluations()
- +double getAbsoluteAccuracy()
- +double getRelativeAccuracy()
- +double getFunctionValueAccuracy()
- +double solve(int maxEval, FUNC f, double min, double max)
- +double solve(int maxEval, FUNC f, double min, double max, double startValue)
- +double solve(int maxEval, FUNC f, double startValue)
- }
-
- abstract class "BaseAbstractUnivariateSolver<FUNC extends UnivariateFunction>" as BaseAbstractUnivariateSolver_FUNC_ {
- #{Abstract} double doSolve()
- }
-
- interface UnivariateSolver
- abstract class AbstractUnivariateSolver
-
- interface DifferentiableUnivariateSolver
- abstract class AbstractDifferentiableUnivariateSolver
-
- interface PolynomialSolver
- abstract class AbstractPolynomialSolver
-
- BaseUnivariateSolver_FUNC_ <|.. BaseAbstractUnivariateSolver_FUNC_
-
- BaseUnivariateSolver_FUNC_ <|.. UnivariateSolver
- UnivariateSolver <|.. AbstractUnivariateSolver
- BaseAbstractUnivariateSolver_FUNC_ <|-- AbstractUnivariateSolver
-
- BaseUnivariateSolver_FUNC_ <|.. DifferentiableUnivariateSolver
- DifferentiableUnivariateSolver <|.. AbstractDifferentiableUnivariateSolver
- BaseAbstractUnivariateSolver_FUNC_ <|-- AbstractDifferentiableUnivariateSolver
-
- BaseUnivariateSolver_FUNC_ <|.. PolynomialSolver
- PolynomialSolver <|.. AbstractPolynomialSolver
- BaseAbstractUnivariateSolver_FUNC_ <|-- AbstractPolynomialSolver
-
-
-interface "BracketedUnivariateSolver<FUNC extends UnivariateFunction>" as BracketedUnivariateSolver_FUNC_
-AllowedSolution <-- BracketedUnivariateSolver_FUNC_ : solution side selector
-BaseUnivariateSolver_FUNC_ <|.. BracketedUnivariateSolver_FUNC_
-
-abstract class BaseSecantSolver
-
- AbstractUnivariateSolver <|-- BaseSecantSolver
- BracketedUnivariateSolver_FUNC_ <|.. BaseSecantSolver
- BaseSecantSolver <|-- IllinoisSolver
- BaseSecantSolver <|-- PegasusSolver
- BaseSecantSolver <|-- RegulaFalsiSolver
-
- AbstractUnivariateSolver <|-- BracketingNthOrderBrentSolver
- BracketedUnivariateSolver_FUNC_ <|.. BracketingNthOrderBrentSolver
-
- AbstractUnivariateSolver <|-- BrentSolver
- AbstractUnivariateSolver <|-- SecantSolver
- AbstractUnivariateSolver <|-- RiddersSolver
- AbstractUnivariateSolver <|-- MullerSolver
- AbstractUnivariateSolver <|-- MullerSolver2
- AbstractDifferentiableUnivariateSolver <|-- NewtonSolver
-AbstractPolynomialSolver <|-- LaguerreSolver
-
-AbstractUnivariateSolver <|-- BisectionSolver
- }
-
-@enduml
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/7a4a3a61/src/site/design/threeD.puml
----------------------------------------------------------------------
diff --git a/src/site/design/threeD.puml b/src/site/design/threeD.puml
deleted file mode 100644
index 1dc3605..0000000
--- a/src/site/design/threeD.puml
+++ /dev/null
@@ -1,86 +0,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.
-
-@startuml
-
- skinparam svek true
- skinparam ClassBackgroundColor #F3EFEB
- skinparam ClassArrowColor #691616
- skinparam ClassBorderColor #691616
- skinparam NoteBackgroundColor #F3EFEB
- skinparam NoteBorderColor #691616
- skinparam NoteFontColor #691616
- skinparam ClassFontSize 11
-
- package org.apache.commons.complex.geometry #ECEBD8 {
-
- interface Space {
- +int getDimension()
- +Space getSubSpace()
- }
- note top
- Space is mainly used as a parameter
- for generics and to link d-dimensional
- space with (d-1)-dimensional space
- end note
-
- interface "Vector<S extends Space>" as Vector_S_ {
- +Space getSpace()
- +Vector getZero()
- +double getNorm()
- +Vector add()
- +Vector subtract()
- +Vector negate()
- +Vector normalize()
- +Vector scalarMultiply()
- +boolean isNaN()
- +boolean isInfinite()
- +double distance()
- +double dotProduct()
- }
-
- Space <-- Vector_S_
-
- package partitioning #DDEBD8 {
- interface "Region<S extends Space>" as Region_S_
- interface "Hyperplane<S extends Space>" as Hyperplane_S_
- interface "SubHyperplane<S extends Space>" as SubHyperplane_S_
- }
-
- package euclidean #DDEBD8 {
-
- package threed #DDDBD8 {
-
- class Euclidean3D
- class Vector3D
- class Line
- class SubLine
- class Plane
- class SubPlane
- class PolyhedronsSet
-
- Space <|.. Euclidean3D
- Vector_S_ <|.. Vector3D
- Hyperplane_S_ <|.. Plane
- SubHyperplane_S_ <|.. SubPlane
- Region_S_ <|.. PolyhedronsSet
-
- }
-
- }
-
- }
-
-@enduml
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/7a4a3a61/src/site/design/twoD.puml
----------------------------------------------------------------------
diff --git a/src/site/design/twoD.puml b/src/site/design/twoD.puml
deleted file mode 100644
index 9182417..0000000
--- a/src/site/design/twoD.puml
+++ /dev/null
@@ -1,84 +0,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.
-
-@startuml
-
- skinparam svek true
- skinparam ClassBackgroundColor #F3EFEB
- skinparam ClassArrowColor #691616
- skinparam ClassBorderColor #691616
- skinparam NoteBackgroundColor #F3EFEB
- skinparam NoteBorderColor #691616
- skinparam NoteFontColor #691616
- skinparam ClassFontSize 11
-
- package org.apache.commons.complex.geometry #ECEBD8 {
-
- interface Space {
- +int getDimension()
- +Space getSubSpace()
- }
- note top
- Space is mainly used as a parameter
- for generics and to link d-dimensional
- space with (d-1)-dimensional space
- end note
-
- interface "Vector<S extends Space>" as Vector_S_ {
- +Space getSpace()
- +Vector getZero()
- +double getNorm()
- +Vector add()
- +Vector subtract()
- +Vector negate()
- +Vector normalize()
- +Vector scalarMultiply()
- +boolean isNaN()
- +boolean isInfinite()
- +double distance()
- +double dotProduct()
- }
-
- Space <-- Vector_S_
-
- package partitioning #DDEBD8 {
- interface "Region<S extends Space>" as Region_S_
- interface "Hyperplane<S extends Space>" as Hyperplane_S_
- interface "SubHyperplane<S extends Space>" as SubHyperplane_S_
- }
-
- package euclidean #DDEBD8 {
-
- package twod #DDDBD8 {
-
- class Euclidean2D
- class Vector2D
- class Line
- class SubLine
- class PolygonsSet
-
- Space <|.. Euclidean2D
- Vector_S_ <|.. Vector2D
- Hyperplane_S_ <|.. Line
- SubHyperplane_S_ <|.. SubLine
- Region_S_ <|.. PolygonsSet
-
- }
-
- }
-
- }
-
-@enduml
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/7a4a3a61/src/site/xdoc/download_math.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/download_math.xml b/src/site/xdoc/download_math.xml
deleted file mode 100644
index a934068..0000000
--- a/src/site/xdoc/download_math.xml
+++ /dev/null
@@ -1,168 +0,0 @@
-<?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.
--->
-<!--
- +======================================================================+
- |**** ****|
- |**** THIS FILE IS GENERATED BY THE COMMONS BUILD PLUGIN ****|
- |**** DO NOT EDIT DIRECTLY ****|
- |**** ****|
- +======================================================================+
- | TEMPLATE FILE: download-page-template.xml |
- | commons-build-plugin/trunk/src/main/resources/commons-xdoc-templates |
- +======================================================================+
- | |
- | 1) Re-generate using: mvn commons:download-page |
- | |
- | 2) Set the following properties in the component's pom: |
- | - commons.componentid (required, alphabetic, lower case) |
- | - commons.release.version (required) |
- | - commons.binary.suffix (optional) |
- | (defaults to "-bin", set to "" for pre-maven2 releases) |
- | |
- | 3) Example Properties |
- | |
- | <properties> |
- | <commons.componentid>math</commons.componentid> |
- | <commons.release.version>1.2</commons.release.version> |
- | </properties> |
- | |
- +======================================================================+
--->
-<document>
- <properties>
- <title>Download Apache Commons Math</title>
- <author email="dev@commons.apache.org">Commons Documentation Team</author>
- </properties>
- <body>
- <section name="Download Apache Commons Math">
- <subsection name="Using a Mirror">
- <p>
- We recommend you use a mirror to download our release
- builds, but you <strong>must</strong> verify the integrity of
- the downloaded files using signatures downloaded from our main
- distribution directories. Recent releases (48 hours) may not yet
- be available from the mirrors.
- </p>
-
- <p>
- You are currently using <b>[preferred]</b>. If you
- encounter a problem with this mirror, please select another
- mirror. If all mirrors are failing, there are <i>backup</i>
- mirrors (at the end of the mirrors list) that should be
- available.
- <br></br>
- [if-any logo]<a href="[link]"><img align="right" src="[logo]" border="0"></img></a>[end]
- </p>
-
- <form action="[location]" method="get" id="SelectMirror">
- <p>
- Other mirrors:
- <select name="Preferred">
- [if-any http]
- [for http]<option value="[http]">[http]</option>[end]
- [end]
- [if-any ftp]
- [for ftp]<option value="[ftp]">[ftp]</option>[end]
- [end]
- [if-any backup]
- [for backup]<option value="[backup]">[backup] (backup)</option>[end]
- [end]
- </select>
- <input type="submit" value="Change"></input>
- </p>
- </form>
-
- <p>
- The <a href="http://www.apache.org/dist/commons/KEYS">KEYS</a>
- link links to the code signing keys used to sign the product.
- The <code>PGP</code> link downloads the OpenPGP compatible signature from our main site.
- The <code>MD5</code> link downloads the checksum from the main site.
- </p>
- </subsection>
- </section>
- <section name="Apache Commons Math 3.4.1 (requires Java 1.5+)">
- <subsection name="Binaries">
- <table>
- <tr>
- <td><a href="[preferred]/commons/math/binaries/commons-math3-3.4.1-bin.tar.gz">commons-math3-3.4.1-bin.tar.gz</a></td>
- <td><a href="http://www.apache.org/dist/commons/math/binaries/commons-math3-3.4.1-bin.tar.gz.md5">md5</a></td>
- <td><a href="http://www.apache.org/dist/commons/math/binaries/commons-math3-3.4.1-bin.tar.gz.asc">pgp</a></td>
- </tr>
- <tr>
- <td><a href="[preferred]/commons/math/binaries/commons-math3-3.4.1-bin.zip">commons-math3-3.4.1-bin.zip</a></td>
- <td><a href="http://www.apache.org/dist/commons/math/binaries/commons-math3-3.4.1-bin.zip.md5">md5</a></td>
- <td><a href="http://www.apache.org/dist/commons/math/binaries/commons-math3-3.4.1-bin.zip.asc">pgp</a></td>
- </tr>
- </table>
- </subsection>
- <subsection name="Source">
- <table>
- <tr>
- <td><a href="[preferred]/commons/math/source/commons-math3-3.4.1-src.tar.gz">commons-math3-3.4.1-src.tar.gz</a></td>
- <td><a href="http://www.apache.org/dist/commons/math/source/commons-math3-3.4.1-src.tar.gz.md5">md5</a></td>
- <td><a href="http://www.apache.org/dist/commons/math/source/commons-math3-3.4.1-src.tar.gz.asc">pgp</a></td>
- </tr>
- <tr>
- <td><a href="[preferred]/commons/math/source/commons-math3-3.4.1-src.zip">commons-math3-3.4.1-src.zip</a></td>
- <td><a href="http://www.apache.org/dist/commons/math/source/commons-math3-3.4.1-src.zip.md5">md5</a></td>
- <td><a href="http://www.apache.org/dist/commons/math/source/commons-math3-3.4.1-src.zip.asc">pgp</a></td>
- </tr>
- </table>
- </subsection>
- </section>
- <section name="Apache Commons Math 2.2 (requires Java 1.5+)">
- <subsection name="Binaries">
- <table>
- <tr>
- <td><a href="[preferred]/commons/math/binaries/commons-math-2.2.tar.gz">commons-math-2.2.tar.gz</a></td>
- <td><a href="http://www.apache.org/dist/commons/math/binaries/commons-math-2.2.tar.gz.md5">md5</a></td>
- <td><a href="http://www.apache.org/dist/commons/math/binaries/commons-math-2.2.tar.gz.asc">pgp</a></td>
- </tr>
- <tr>
- <td><a href="[preferred]/commons/math/binaries/commons-math-2.2.zip">commons-math-2.2.zip</a></td>
- <td><a href="http://www.apache.org/dist/commons/math/binaries/commons-math-2.2.zip.md5">md5</a></td>
- <td><a href="http://www.apache.org/dist/commons/math/binaries/commons-math-2.2.zip.asc">pgp</a></td>
- </tr>
- </table>
- </subsection>
- <subsection name="Source">
- <table>
- <tr>
- <td><a href="[preferred]/commons/math/source/commons-math-2.2-src.tar.gz">commons-math-2.2-src.tar.gz</a></td>
- <td><a href="http://www.apache.org/dist/commons/math/source/commons-math-2.2-src.tar.gz.md5">md5</a></td>
- <td><a href="http://www.apache.org/dist/commons/math/source/commons-math-2.2-src.tar.gz.asc">pgp</a></td>
- </tr>
- <tr>
- <td><a href="[preferred]/commons/math/source/commons-math-2.2-src.zip">commons-math-2.2-src.zip</a></td>
- <td><a href="http://www.apache.org/dist/commons/math/source/commons-math-2.2-src.zip.md5">md5</a></td>
- <td><a href="http://www.apache.org/dist/commons/math/source/commons-math-2.2-src.zip.asc">pgp</a></td>
- </tr>
- </table>
- </subsection>
- </section>
- <section name="Archives">
- <p>
- Older releases can be obtained from the archives.
- </p>
- <ul>
- <li class="download"><a href="[preferred]/commons/math/">browse download area</a></li>
- <li><a href="http://archive.apache.org/dist/commons/math/">archives...</a></li>
- </ul>
- </section>
- </body>
-</document>
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/7a4a3a61/src/site/xdoc/proposal.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/proposal.xml b/src/site/xdoc/proposal.xml
deleted file mode 100644
index d277c5b..0000000
--- a/src/site/xdoc/proposal.xml
+++ /dev/null
@@ -1,131 +0,0 @@
-<?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.
- -->
-
-<document>
-
- <properties>
- <title>Proposal for math Package</title>
- <author email="martin@mvdb.net">Robert Burrell Donkin</author>
- </properties>
-
- <body>
-
- <section name='Proposal for math Package'>
-
- <subsection name='(0) Rationale'>
-<p>The Java programming language and the math extensions in commons-lang provide implementations
-for only the most basic mathematical algorithms. Routine development tasks such as computing
-basic statistics or solving a system of linear equations require components not available in java
-or commons-lang.</p>
-
-<p>Most basic mathematical or statistical algorithms are available in open source implementations,
-but to assemble a simple set of capabilities one has to use multiple libraries, many of which have
-more restrictive licensing terms than the ASF. In addition, many of the best open source
-implementations (e.g. the R statistical package) are either not available in Java or require large
-support libraries and/or external dependencies to work.</p>
-
-<p>A commons-math community will provide a productive environment for aggregation, testing and
-support of efficient Java implementations of commonly used mathematical and statistical algorithms.</p>
-
- </subsection>
-
- <subsection name='(1) Scope of the Package'>
-
-<p>The Math project shall create and maintain a library of lightweight, self-contained mathematics
-and statistics components addressing the most common practical problems not immediately available in
-the Java programming language or commons-lang. The guiding principles for commons-math will be:
-
-<ol>
-<li>Real-world application use cases determine priority</li>
-<li>Emphasis on small, easily integrated components rather than large libraries with complex
-dependencies</li>
-<li>All algorithms are fully documented and follow generally accepted best practices</li>
-<li>In situations where multiple standard algorithms exist, use the Strategy pattern to support
-multiple implementations</li>
-<li>Limited dependencies. No external dependencies beyond Commons components and the JDK</li>
-</ol>
-</p>
- </subsection>
-
- <subsection name='(1.5) Interaction With Other Packages'>
-
-<p><em>math</em> relies only on standard JDK 1.2 (or later) APIs for
-production deployment. It utilizes the JUnit unit testing framework for
-developing and executing unit tests, but this is of interest only to
-developers of the component.</p>
-
-<p>No external configuration files are utilized.</p>
-
- </subsection>
- <subsection name='(2) Initial Source of the Package'>
-
-<p>The initial codebase will consist of implementations of basic statistical algorithms such
-as the following:
-<ul>
-<li>Simple univariate statistics (mean, standard deviation, n, confidence intervals)</li>
-<li>Frequency distributions</li>
-<li>t-test, chi-square test</li>
-<li>Random numbers from Gaussian, Exponential, Poisson distributions</li>
-<li>Random sampling/resampling</li>
-<li>Bivariate regression, corellation</li>
-</ul>
-
-and mathematical algorithms such as the following:
-<ul>
-<li>Basic Complex Number representation with algebraic operations</li>
-<li>Newton's method for finding roots</li>
-<li>Binomial coefficients</li>
-<li>Exponential growth and decay (set up for financial applications)</li>
-<li>Polynomial Interpolation (curve fitting)</li>
-<li>Basic Matrix representation with algebraic operations</li>
-</ul>
-</p>
-
-<p>The proposed package name for the new component is
-<code>org.apache.commons.math</code>.</p>
-
- </subsection>
- <subsection name='(3) Required Jakarta-Commons Resources'>
-
-<ul>
-<li>CVS Repository - New directory <code>math</code> in the
- <code>jakarta-commons</code> CVS repository.</li>
-<li>Mailing List - Discussions will take place on the general
- <em>dev@commons.apache.org</em> mailing list. To help
- list subscribers identify messages of interest, it is suggested that
- the message subject of messages about this component be prefixed with
- [math].</li>
-<li>Bugzilla - New component "math" under the "Commons" product
- category, with appropriate version identifiers as needed.</li>
-<li>Jyve FAQ - New category "commons-math" (when available).</li>
-</ul>
-
- </subsection>
- <subsection name='(4) Initial Committers'>
-
-<p>The initial committers on the math component shall be:
-<ul>
- <li><a href="mailto:rdonkin@apache.org">Robert Burrell Donkin</a></li>
- <li><a href="mailto:tobrien@apache.org">Tim O'Brien</a></li>
-</ul>
-</p>
- </subsection>
- </section>
- </body>
-</document>
[13/31] commons-numbers git commit: Multimodule project setup.
Posted by er...@apache.org.
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/ComplexUtils.java
----------------------------------------------------------------------
diff --git a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/ComplexUtils.java b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/ComplexUtils.java
new file mode 100644
index 0000000..1298587
--- /dev/null
+++ b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/ComplexUtils.java
@@ -0,0 +1,1430 @@
+/*
+ * 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.
+ */
+
+package org.apache.commons.numbers.complex;
+
+/**
+ * Static implementations of common {@link Complex} utilities functions.
+ */
+public class ComplexUtils {
+
+ /**
+ * Utility class.
+ */
+ private ComplexUtils() {}
+
+ /**
+ * Creates a complex number from the given polar representation.
+ * <p>
+ * If either {@code r} or {@code theta} is NaN, or {@code theta} is
+ * infinite, {@link Complex#NaN} is returned.
+ * <p>
+ * If {@code r} is infinite and {@code theta} is finite, infinite or NaN
+ * values may be returned in parts of the result, following the rules for
+ * double arithmetic.
+ *
+ * <pre>
+ * Examples:
+ * {@code
+ * polar2Complex(INFINITY, \(\pi\)) = INFINITY + INFINITY i
+ * polar2Complex(INFINITY, 0) = INFINITY + NaN i
+ * polar2Complex(INFINITY, \(-\frac{\pi}{4}\)) = INFINITY - INFINITY i
+ * polar2Complex(INFINITY, \(5\frac{\pi}{4}\)) = -INFINITY - INFINITY i }
+ * </pre>
+ *
+ * @param r the modulus of the complex number to create
+ * @param theta the argument of the complex number to create
+ * @return {@code Complex}
+ * @since 1.1
+ */
+ public static Complex polar2Complex(double r, double theta) {
+ if (r < 0) {
+ throw new NegativeModulusException(r);
+ }
+ return new Complex(r * Math.cos(theta), r * Math.sin(theta));
+ }
+
+ /**
+ * Creates {@code Complex[]} array given {@code double[]} arrays of r and
+ * theta.
+ *
+ * @param r {@code double[]} of moduli
+ * @param theta {@code double[]} of arguments
+ * @return {@code Complex[]}
+ * @since 4.0
+ */
+ public static Complex[] polar2Complex(double[] r, double[] theta) {
+ final int length = r.length;
+ final Complex[] c = new Complex[length];
+ for (int x = 0; x < length; x++) {
+ if (r[x] < 0) {
+ throw new NegativeModulusException(r[x]);
+ }
+ c[x] = new Complex(r[x] * Math.cos(theta[x]), r[x] * Math.sin(theta[x]));
+ }
+ return c;
+ }
+
+ /**
+ * Creates {@code Complex[][]} array given {@code double[][]} arrays of r
+ * and theta.
+ *
+ * @param r {@code double[]} of moduli
+ * @param theta {@code double[]} of arguments
+ * @return {@code Complex[][]}
+ * @since 4.0
+ */
+ public static Complex[][] polar2Complex(double[][] r, double[][] theta) {
+ final int length = r.length;
+ final Complex[][] c = new Complex[length][];
+ for (int x = 0; x < length; x++) {
+ c[x] = polar2Complex(r[x], theta[x]);
+ }
+ return c;
+ }
+
+ /**
+ * Creates {@code Complex[][][]} array given {@code double[][][]} arrays of
+ * r and theta.
+ *
+ * @param r array of moduli
+ * @param theta array of arguments
+ * @return {@code Complex}
+ * @since 4.0
+ */
+ public static Complex[][][] polar2Complex(double[][][] r, double[][][] theta) {
+ final int length = r.length;
+ final Complex[][][] c = new Complex[length][][];
+ for (int x = 0; x < length; x++) {
+ c[x] = polar2Complex(r[x], theta[x]);
+ }
+ return c;
+ }
+
+ /**
+ * Returns double from array {@code real[]} at entry {@code index} as a
+ * {@code Complex}.
+ *
+ * @param real array of real numbers
+ * @param index location in the array
+ * @return {@code Complex}.
+ *
+ * @since 4.0
+ */
+ public static Complex extractComplexFromRealArray(double[] real, int index) {
+ return new Complex(real[index]);
+ }
+
+ /**
+ * Returns float from array {@code real[]} at entry {@code index} as a
+ * {@code Complex}.
+ *
+ * @param real array of real numbers
+ * @param index location in the array
+ * @return {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex extractComplexFromRealArray(float[] real, int index) {
+ return new Complex(real[index]);
+ }
+
+ /**
+ * Returns double from array {@code imaginary[]} at entry {@code index} as a
+ * {@code Complex}.
+ *
+ * @param imaginary array of imaginary numbers
+ * @param index location in the array
+ * @return {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex extractComplexFromImaginaryArray(double[] imaginary, int index) {
+ return new Complex(0, imaginary[index]);
+ }
+
+ /**
+ * Returns float from array {@code imaginary[]} at entry {@code index} as a
+ * {@code Complex}.
+ *
+ * @param imaginary array of imaginary numbers
+ * @param index location in the array
+ * @return {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex extractComplexFromImaginaryArray(float[] imaginary, int index) {
+ return new Complex(0, imaginary[index]);
+ }
+
+ /**
+ * Returns real component of Complex from array {@code Complex[]} at entry
+ * {@code index} as a {@code double}.
+ *
+ * @param complex array of complex numbers
+ * @param index location in the array
+ * @return {@code double}.
+ *
+ * @since 4.0
+ */
+ public static double extractRealFromComplexArray(Complex[] complex, int index) {
+ return complex[index].getReal();
+ }
+
+ /**
+ * Returns real component of array {@code Complex[]} at entry {@code index}
+ * as a {@code float}.
+ *
+ * @param complex array of complex numbers
+ * @param index location in the array
+ * @return {@code float}.
+ *
+ * @since 4.0
+ */
+ public static float extractRealFloatFromComplexArray(Complex[] complex, int index) {
+ return (float) complex[index].getReal();
+ }
+
+ /**
+ * Returns imaginary component of Complex from array {@code Complex[]} at
+ * entry {@code index} as a {@code double}.
+ *
+ * @param complex array of complex numbers
+ * @param index location in the array
+ * @return {@code double}.
+ *
+ * @since 4.0
+ */
+ public static double extractImaginaryFromComplexArray(Complex[] complex, int index) {
+ return complex[index].getImaginary();
+ }
+
+ /**
+ * Returns imaginary component of array {@code Complex[]} at entry
+ * {@code index} as a {@code float}.
+ *
+ * @param complex array of complex numbers
+ * @param index location in the array
+ * @return {@code float}.
+ *
+ * @since 4.0
+ */
+ public static float extractImaginaryFloatFromComplexArray(Complex[] complex, int index) {
+ return (float) complex[index].getImaginary();
+ }
+
+ /**
+ * Returns a Complex object from interleaved {@code double[]} array at entry
+ * {@code index}.
+ *
+ * @param d array of interleaved complex numbers alternating real and imaginary values
+ * @param index location in the array This is the location by complex number, e.g. index number 5 in the array will return {@code new Complex(d[10], d[11])}
+ * @return {@code Complex}.
+ *
+ * @since 4.0
+ */
+ public static Complex extractComplexFromInterleavedArray(double[] d, int index) {
+ return new Complex(d[index * 2], d[index * 2 + 1]);
+ }
+
+ /**
+ * Returns a Complex object from interleaved {@code float[]} array at entry
+ * {@code index}.
+ *
+ * @param f float array of interleaved complex numbers alternating real and imaginary values
+ * @param index location in the array This is the location by complex number, e.g. index number 5 in the {@code float[]} array will return new {@code Complex(d[10], d[11])}
+ * @return {@code Complex}.
+ *
+ * @since 4.0
+ */
+ public static Complex extractComplexFromInterleavedArray(float[] f, int index) {
+ return new Complex(f[index * 2], f[index * 2 + 1]);
+ }
+
+ /**
+ * Returns values of Complex object from array {@code Complex[]} at entry
+ * {@code index} as a size 2 {@code double} of the form {real, imag}.
+ *
+ * @param complex array of complex numbers
+ * @param index location in the array
+ * @return size 2 array.
+ *
+ * @since 4.0
+ */
+ public static double[] extractInterleavedFromComplexArray(Complex[] complex, int index) {
+ return new double[] { complex[index].getReal(), complex[index].getImaginary() };
+ }
+
+ /**
+ * Returns Complex object from array {@code Complex[]} at entry
+ * {@code index} as a size 2 {@code float} of the form {real, imag}.
+ *
+ * @param complex {@code Complex} array
+ * @param index location in the array
+ * @return size 2 {@code float[]}.
+ *
+ * @since 4.0
+ */
+ public static float[] extractInterleavedFloatFromComplexArray(Complex[] complex, int index) {
+ return new float[] { (float) complex[index].getReal(), (float) complex[index].getImaginary() };
+ }
+
+ /**
+ * Converts a {@code double[]} array to a {@code Complex[]} array.
+ *
+ * @param real array of numbers to be converted to their {@code Complex} equivalent
+ * @return {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex[] real2Complex(double[] real) {
+ int index = 0;
+ final Complex c[] = new Complex[real.length];
+ for (double d : real) {
+ c[index] = new Complex(d);
+ index++;
+ }
+ return c;
+ }
+
+ /**
+ * Converts a {@code float[]} array to a {@code Complex[]} array.
+ *
+ * @param real array of numbers to be converted to their {@code Complex} equivalent
+ * @return {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex[] real2Complex(float[] real) {
+ int index = 0;
+ final Complex c[] = new Complex[real.length];
+ for (float d : real) {
+ c[index] = new Complex(d);
+ index++;
+ }
+ return c;
+ }
+
+ /**
+ * Converts a 2D real {@code double[][]} array to a 2D {@code Complex[][]}
+ * array.
+ *
+ * @param d 2D array
+ * @return 2D {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex[][] real2Complex(double[][] d) {
+ final int width = d.length;
+ final Complex[][] c = new Complex[width][];
+ for (int n = 0; n < width; n++) {
+ c[n] = ComplexUtils.real2Complex(d[n]);
+ }
+ return c;
+ }
+
+ /**
+ * Converts a 3D real {@code double[][][]} array to a {@code Complex [][][]}
+ * array.
+ *
+ * @param d 3D complex interleaved array
+ * @return 3D {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex[][][] real2Complex(double[][][] d) {
+ final int width = d.length;
+ final Complex[][][] c = new Complex[width][][];
+ for (int x = 0; x < width; x++) {
+ c[x] = ComplexUtils.real2Complex(d[x]);
+ }
+ return c;
+ }
+
+ /**
+ * Converts real component of {@code Complex[]} array to a {@code double[]}
+ * array.
+ *
+ * @param c {@code Complex} array
+ * @return array of the real component
+ *
+ * @since 4.0
+ */
+ public static double[] complex2Real(Complex[] c) {
+ int index = 0;
+ final double d[] = new double[c.length];
+ for (Complex cc : c) {
+ d[index] = cc.getReal();
+ index++;
+ }
+ return d;
+ }
+
+ /**
+ * Converts real component of {@code Complex[]} array to a {@code float[]}
+ * array.
+ *
+ * @param c {@code Complex} array
+ * @return {@code float[]} array of the real component
+ *
+ * @since 4.0
+ */
+ public static float[] complex2RealFloat(Complex[] c) {
+ int index = 0;
+ final float f[] = new float[c.length];
+ for (Complex cc : c) {
+ f[index] = (float) cc.getReal();
+ index++;
+ }
+ return f;
+ }
+
+ /**
+ * Converts real component of a 2D {@code Complex[][]} array to a 2D
+ * {@code double[][]} array.
+ *
+ * @param c 2D {@code Complex} array
+ * @return {@code double[][]} of real component
+ * @since 4.0
+ */
+ public static double[][] complex2Real(Complex[][] c) {
+ final int length = c.length;
+ double[][] d = new double[length][];
+ for (int n = 0; n < length; n++) {
+ d[n] = complex2Real(c[n]);
+ }
+ return d;
+ }
+
+ /**
+ * Converts real component of a 2D {@code Complex[][]} array to a 2D
+ * {@code float[][]} array.
+ *
+ * @param c 2D {@code Complex} array
+ * @return {@code float[][]} of real component
+ * @since 4.0
+ */
+ public static float[][] complex2RealFloat(Complex[][] c) {
+ final int length = c.length;
+ float[][] f = new float[length][];
+ for (int n = 0; n < length; n++) {
+ f[n] = complex2RealFloat(c[n]);
+ }
+ return f;
+ }
+
+ /**
+ * Converts real component of a 3D {@code Complex[][][]} array to a 3D
+ * {@code double[][][]} array.
+ *
+ * @param c 3D complex interleaved array
+ * @return array of real component
+ *
+ * @since 4.0
+ */
+ public static double[][][] complex2Real(Complex[][][] c) {
+ final int length = c.length;
+ double[][][] d = new double[length][][];
+ for (int n = 0; n < length; n++) {
+ d[n] = complex2Real(c[n]);
+ }
+ return d;
+ }
+
+ /**
+ * Converts real component of a 3D {@code Complex[][][]} array to a 3D
+ * {@code float[][][]} array.
+ *
+ * @param c 3D {@code Complex} array
+ * @return {@code float[][][]} of real component
+ * @since 4.0
+ */
+ public static float[][][] complex2RealFloat(Complex[][][] c) {
+ final int length = c.length;
+ float[][][] f = new float[length][][];
+ for (int n = 0; n < length; n++) {
+ f[n] = complex2RealFloat(c[n]);
+ }
+ return f;
+ }
+
+ /**
+ * Converts a {@code double[]} array to an imaginary {@code Complex[]}
+ * array.
+ *
+ * @param imaginary array of numbers to be converted to their {@code Complex} equivalent
+ * @return {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex[] imaginary2Complex(double[] imaginary) {
+ int index = 0;
+ final Complex c[] = new Complex[imaginary.length];
+ for (double d : imaginary) {
+ c[index] = new Complex(0, d);
+ index++;
+ }
+ return c;
+ }
+
+ /**
+ * Converts a {@code float[]} array to an imaginary {@code Complex[]} array.
+ *
+ * @param imaginary array of numbers to be converted to their {@code Complex} equivalent
+ * @return {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex[] imaginary2Complex(float[] imaginary) {
+ int index = 0;
+ final Complex c[] = new Complex[imaginary.length];
+ for (float d : imaginary) {
+ c[index] = new Complex(0, d);
+ index++;
+ }
+ return c;
+ }
+
+ /**
+ * Converts a 2D imaginary array {@code double[][]} to a 2D
+ * {@code Complex[][]} array.
+ *
+ * @param d 2D array
+ * @return 2D {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex[][] imaginary2Complex(double[][] d) {
+ int width = d.length;
+ int height = d[0].length;
+ Complex[][] c = new Complex[width][height];
+ for (int n = 0; n < width; n++) {
+ c[n] = ComplexUtils.imaginary2Complex(d[n]);
+ }
+ return c;
+ }
+
+ /**
+ * Converts a 3D imaginary array {@code double[][][]} to a {@code Complex[]}
+ * array.
+ *
+ * @param d 3D complex imaginary array
+ * @return 3D {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex[][][] imaginary2Complex(double[][][] d) {
+ int width = d.length;
+ int height = d[0].length;
+ int depth = d[0].length;
+ Complex[][][] c = new Complex[width][height][depth];
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ c[x][y] = ComplexUtils.imaginary2Complex(d[x][y]);
+ }
+ }
+ return c;
+ }
+
+ /**
+ * Converts imaginary part of a {@code Complex[]} array to a
+ * {@code double[]} array.
+ *
+ * @param c {@code Complex} array.
+ * @return array of the imaginary component
+ *
+ * @since 4.0
+ */
+ public static double[] complex2Imaginary(Complex[] c) {
+ int index = 0;
+ final double d[] = new double[c.length];
+ for (Complex cc : c) {
+ d[index] = cc.getImaginary();
+ index++;
+ }
+ return d;
+ }
+
+ /**
+ * Converts imaginary component of a {@code Complex[]} array to a
+ * {@code float[]} array.
+ *
+ * @param c {@code Complex} array.
+ * @return {@code float[]} array of the imaginary component
+ *
+ * @since 4.0
+ */
+ public static float[] complex2ImaginaryFloat(Complex[] c) {
+ int index = 0;
+ final float f[] = new float[c.length];
+ for (Complex cc : c) {
+ f[index] = (float) cc.getImaginary();
+ index++;
+ }
+ return f;
+ }
+
+ /**
+ * Converts imaginary component of a 2D {@code Complex[][]} array to a 2D
+ * {@code double[][]} array.
+ *
+ * @param c 2D {@code Complex} array
+ * @return {@code double[][]} of imaginary component
+ * @since 4.0
+ */
+ public static double[][] complex2Imaginary(Complex[][] c) {
+ final int length = c.length;
+ double[][] d = new double[length][];
+ for (int n = 0; n < length; n++) {
+ d[n] = complex2Imaginary(c[n]);
+ }
+ return d;
+ }
+
+ /**
+ * Converts imaginary component of a 2D {@code Complex[][]} array to a 2D
+ * {@code float[][]} array.
+ *
+ * @param c 2D {@code Complex} array
+ * @return {@code float[][]} of imaginary component
+ * @since 4.0
+ */
+ public static float[][] complex2ImaginaryFloat(Complex[][] c) {
+ final int length = c.length;
+ float[][] f = new float[length][];
+ for (int n = 0; n < length; n++) {
+ f[n] = complex2ImaginaryFloat(c[n]);
+ }
+ return f;
+ }
+
+ /**
+ * Converts imaginary component of a 3D {@code Complex[][][]} array to a 3D
+ * {@code double[][][]} array.
+ *
+ * @param c 3D complex interleaved array
+ * @return 3D {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static double[][][] complex2Imaginary(Complex[][][] c) {
+ final int length = c.length;
+ double[][][] d = new double[length][][];
+ for (int n = 0; n < length; n++) {
+ d[n] = complex2Imaginary(c[n]);
+ }
+ return d;
+ }
+
+ /**
+ * Converts imaginary component of a 3D {@code Complex[][][]} array to a 3D
+ * {@code float[][][]} array.
+ *
+ * @param c 3D {@code Complex} array
+ * @return {@code float[][][]} of imaginary component
+ * @since 4.0
+ */
+ public static float[][][] complex2ImaginaryFloat(Complex[][][] c) {
+ final int length = c.length;
+ float[][][] f = new float[length][][];
+ for (int n = 0; n < length; n++) {
+ f[n] = complex2ImaginaryFloat(c[n]);
+ }
+ return f;
+ }
+
+ // INTERLEAVED METHODS
+
+ /**
+ * Converts a complex interleaved {@code double[]} array to a
+ * {@code Complex[]} array
+ *
+ * @param interleaved array of numbers to be converted to their {@code Complex} equivalent
+ * @return {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex[] interleaved2Complex(double[] interleaved) {
+ final int length = interleaved.length / 2;
+ final Complex c[] = new Complex[length];
+ for (int n = 0; n < length; n++) {
+ c[n] = new Complex(interleaved[n * 2], interleaved[n * 2 + 1]);
+ }
+ return c;
+ }
+
+ /**
+ * Converts a complex interleaved {@code float[]} array to a
+ * {@code Complex[]} array
+ *
+ * @param interleaved float[] array of numbers to be converted to their {@code Complex} equivalent
+ * @return {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex[] interleaved2Complex(float[] interleaved) {
+ final int length = interleaved.length / 2;
+ final Complex c[] = new Complex[length];
+ for (int n = 0; n < length; n++) {
+ c[n] = new Complex(interleaved[n * 2], interleaved[n * 2 + 1]);
+ }
+ return c;
+ }
+
+ /**
+ * Converts a {@code Complex[]} array to an interleaved complex
+ * {@code double[]} array
+ *
+ * @param c Complex array
+ * @return complex interleaved array alternating real and
+ * imaginary values
+ *
+ * @since 4.0
+ */
+ public static double[] complex2Interleaved(Complex[] c) {
+ int index = 0;
+ final double d[] = new double[c.length * 2];
+ for (Complex cc : c) {
+ int real = index * 2;
+ int imag = index * 2 + 1;
+ d[real] = cc.getReal();
+ d[imag] = cc.getImaginary();
+ index++;
+ }
+ return d;
+ }
+
+ /**
+ * Converts a {@code Complex[]} array to an interleaved complex
+ * {@code float[]} array
+ *
+ * @param c Complex array
+ * @return complex interleaved {@code float[]} alternating real and
+ * imaginary values
+ *
+ * @since 4.0
+ */
+ public static float[] complex2InterleavedFloat(Complex[] c) {
+ int index = 0;
+ final float f[] = new float[c.length * 2];
+ for (Complex cc : c) {
+ int real = index * 2;
+ int imag = index * 2 + 1;
+ f[real] = (float) cc.getReal();
+ f[imag] = (float) cc.getImaginary();
+ index++;
+ }
+ return f;
+ }
+
+ /**
+ * Converts a 2D {@code Complex[][]} array to an interleaved complex
+ * {@code double[][]} array.
+ *
+ * @param c 2D Complex array
+ * @param interleavedDim Depth level of the array to interleave
+ * @return complex interleaved array alternating real and
+ * imaginary values
+ *
+ * @since 4.0
+ */
+ public static double[][] complex2Interleaved(Complex[][] c, int interleavedDim) {
+ if (interleavedDim > 1 || interleavedDim < 0) {
+ new IndexOutOfRangeException(interleavedDim);
+ }
+ final int width = c.length;
+ final int height = c[0].length;
+ double[][] d;
+ if (interleavedDim == 0) {
+ d = new double[2 * width][height];
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ d[x * 2][y] = c[x][y].getReal();
+ d[x * 2 + 1][y] = c[x][y].getImaginary();
+ }
+ }
+ } else {
+ d = new double[width][2 * height];
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ d[x][y * 2] = c[x][y].getReal();
+ d[x][y * 2 + 1] = c[x][y].getImaginary();
+ }
+ }
+ }
+ return d;
+ }
+
+ /**
+ * Converts a 2D {@code Complex[][]} array to an interleaved complex
+ * {@code double[][]} array. The second depth level of the array is assumed
+ * to be interleaved.
+ *
+ * @param c 2D Complex array
+ * @return complex interleaved array alternating real and
+ * imaginary values
+ *
+ * @since 4.0
+ */
+ public static double[][] complex2Interleaved(Complex[][] c) {
+ return complex2Interleaved(c, 1);
+ }
+
+ /**
+ * Converts a 3D {@code Complex[][][]} array to an interleaved complex
+ * {@code double[][][]} array.
+ *
+ * @param c 3D Complex array
+ * @param interleavedDim Depth level of the array to interleave
+ * @return complex interleaved array alternating real and
+ * imaginary values
+ *
+ * @since 4.0
+ */
+ public static double[][][] complex2Interleaved(Complex[][][] c, int interleavedDim) {
+ if (interleavedDim > 2 || interleavedDim < 0) {
+ new IndexOutOfRangeException(interleavedDim);
+ }
+ int width = c.length;
+ int height = c[0].length;
+ int depth = c[0][0].length;
+ double[][][] d;
+ if (interleavedDim == 0) {
+ d = new double[2 * width][height][depth];
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ for (int z = 0; z < depth; z++) {
+ d[x * 2][y][z] = c[x][y][z].getReal();
+ d[x * 2 + 1][y][z] = c[x][y][z].getImaginary();
+ }
+ }
+ }
+ } else if (interleavedDim == 1) {
+ d = new double[width][2 * height][depth];
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ for (int z = 0; z < depth; z++) {
+ d[x][y * 2][z] = c[x][y][z].getReal();
+ d[x][y * 2 + 1][z] = c[x][y][z].getImaginary();
+ }
+ }
+ }
+ } else {
+ d = new double[width][height][2 * depth];
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ for (int z = 0; z < depth; z++) {
+ d[x][y][z * 2] = c[x][y][z].getReal();
+ d[x][y][z * 2 + 1] = c[x][y][z].getImaginary();
+ }
+ }
+ }
+ }
+ return d;
+ }
+
+ /**
+ * Converts a 3D {@code Complex[][][]} array to an interleaved complex
+ * {@code double[][][]} array. The third depth level of the array is
+ * interleaved.
+ *
+ * @param c 3D Complex array
+ * @return complex interleaved array alternating real and
+ * imaginary values
+ *
+ * @since 4.0
+ */
+ public static double[][][] complex2Interleaved(Complex[][][] c) {
+ return complex2Interleaved(c, 2);
+ }
+
+ /**
+ * Converts a 2D {@code Complex[][]} array to an interleaved complex
+ * {@code float[][]} array.
+ *
+ * @param c 2D Complex array
+ * @param interleavedDim Depth level of the array to interleave
+ * @return complex interleaved {@code float[][]} alternating real and
+ * imaginary values
+ *
+ * @since 4.0
+ */
+ public static float[][] complex2InterleavedFloat(Complex[][] c, int interleavedDim) {
+ if (interleavedDim > 1 || interleavedDim < 0) {
+ new IndexOutOfRangeException(interleavedDim);
+ }
+ final int width = c.length;
+ final int height = c[0].length;
+ float[][] d;
+ if (interleavedDim == 0) {
+ d = new float[2 * width][height];
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ d[x * 2][y] = (float) c[x][y].getReal();
+ d[x * 2 + 1][y] = (float) c[x][y].getImaginary();
+ }
+ }
+ } else {
+ d = new float[width][2 * height];
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ d[x][y * 2] = (float) c[x][y].getReal();
+ d[x][y * 2 + 1] = (float) c[x][y].getImaginary();
+ }
+ }
+ }
+ return d;
+ }
+
+ /**
+ * Converts a 2D {@code Complex[][]} array to an interleaved complex
+ * {@code float[][]} array. The second depth level of the array is assumed
+ * to be interleaved.
+ *
+ * @param c 2D Complex array
+ *
+ * @return complex interleaved {@code float[][]} alternating real and
+ * imaginary values
+ *
+ * @since 4.0
+ */
+ public static float[][] complex2InterleavedFloat(Complex[][] c) {
+ return complex2InterleavedFloat(c, 1);
+ }
+
+ /**
+ * Converts a 3D {@code Complex[][][]} array to an interleaved complex
+ * {@code float[][][]} array.
+ *
+ * @param c 3D Complex array
+ * @param interleavedDim Depth level of the array to interleave
+ * @return complex interleaved {@code float[][][]} alternating real and
+ * imaginary values
+ *
+ * @since 4.0
+ */
+ public static float[][][] complex2InterleavedFloat(Complex[][][] c, int interleavedDim) {
+ if (interleavedDim > 2 || interleavedDim < 0) {
+ new IndexOutOfRangeException(interleavedDim);
+ }
+ final int width = c.length;
+ final int height = c[0].length;
+ final int depth = c[0][0].length;
+ float[][][] d;
+ if (interleavedDim == 0) {
+ d = new float[2 * width][height][depth];
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ for (int z = 0; z < depth; z++) {
+ d[x * 2][y][z] = (float) c[x][y][z].getReal();
+ d[x * 2 + 1][y][z] = (float) c[x][y][z].getImaginary();
+ }
+ }
+ }
+ } else if (interleavedDim == 1) {
+ d = new float[width][2 * height][depth];
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ for (int z = 0; z < depth; z++) {
+ d[x][y * 2][z] = (float) c[x][y][z].getReal();
+ d[x][y * 2 + 1][z] = (float) c[x][y][z].getImaginary();
+ }
+ }
+ }
+ } else {
+ d = new float[width][height][2 * depth];
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ for (int z = 0; z < depth; z++) {
+ d[x][y][z * 2] = (float) c[x][y][z].getReal();
+ d[x][y][z * 2 + 1] = (float) c[x][y][z].getImaginary();
+ }
+ }
+ }
+ }
+ return d;
+ }
+
+ /**
+ * Converts a 3D {@code Complex[][][]} array to an interleaved complex
+ * {@code float[][][]} array. The third depth level of the array is
+ * interleaved.
+ *
+ * @param c 2D Complex array
+ *
+ * @return complex interleaved {@code float[][][]} alternating real and
+ * imaginary values
+ *
+ * @since 4.0
+ */
+ public static float[][][] complex2InterleavedFloat(Complex[][][] c) {
+ return complex2InterleavedFloat(c, 2);
+ }
+
+ /**
+ * Converts a 2D interleaved complex {@code double[][]} array to a
+ * {@code Complex[][]} array.
+ *
+ * @param d 2D complex interleaved array
+ * @param interleavedDim Depth level of the array to interleave
+ * @return 2D {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex[][] interleaved2Complex(double[][] d, int interleavedDim) {
+ if (interleavedDim > 1 || interleavedDim < 0) {
+ new IndexOutOfRangeException(interleavedDim);
+ }
+ final int width = d.length;
+ final int height = d[0].length;
+ Complex[][] c;
+ if (interleavedDim == 0) {
+ c = new Complex[width / 2][height];
+ for (int x = 0; x < width / 2; x++) {
+ for (int y = 0; y < height; y++) {
+ c[x][y] = new Complex(d[x * 2][y], d[x * 2 + 1][y]);
+ }
+ }
+ } else {
+ c = new Complex[width][height / 2];
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height / 2; y++) {
+ c[x][y] = new Complex(d[x][y * 2], d[x][y * 2 + 1]);
+ }
+ }
+ }
+ return c;
+ }
+
+ /**
+ * Converts a 2D interleaved complex {@code double[][]} array to a
+ * {@code Complex[][]} array. The second depth level of the array is assumed
+ * to be interleaved.
+ *
+ * @param d 2D complex interleaved array
+ * @return 2D {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex[][] interleaved2Complex(double[][] d) {
+ return interleaved2Complex(d, 1);
+ }
+
+ /**
+ * Converts a 3D interleaved complex {@code double[][][]} array to a
+ * {@code Complex[][][]} array.
+ *
+ * @param d 3D complex interleaved array
+ * @param interleavedDim Depth level of the array to interleave
+ * @return 3D {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex[][][] interleaved2Complex(double[][][] d, int interleavedDim) {
+ if (interleavedDim > 2 || interleavedDim < 0) {
+ new IndexOutOfRangeException(interleavedDim);
+ }
+ final int width = d.length;
+ final int height = d[0].length;
+ final int depth = d[0][0].length;
+ Complex[][][] c;
+ if (interleavedDim == 0) {
+ c = new Complex[width / 2][height][depth];
+ for (int x = 0; x < width / 2; x++) {
+ for (int y = 0; y < height; y++) {
+ for (int z = 0; z < depth; z++) {
+ c[x][y][z] = new Complex(d[x * 2][y][z], d[x * 2 + 1][y][z]);
+ }
+ }
+ }
+ } else if (interleavedDim == 1) {
+ c = new Complex[width][height / 2][depth];
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height / 2; y++) {
+ for (int z = 0; z < depth; z++) {
+ c[x][y][z] = new Complex(d[x][y * 2][z], d[x][y * 2 + 1][z]);
+ }
+ }
+ }
+ } else {
+ c = new Complex[width][height][depth / 2];
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ for (int z = 0; z < depth / 2; z++) {
+ c[x][y][z] = new Complex(d[x][y][z * 2], d[x][y][z * 2 + 1]);
+ }
+ }
+ }
+ }
+ return c;
+ }
+
+ /**
+ * Converts a 3D interleaved complex {@code double[][][]} array to a
+ * {@code Complex[][][]} array. The third depth level is assumed to be
+ * interleaved.
+ *
+ * @param d 3D complex interleaved array
+ * @return 3D {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex[][][] interleaved2Complex(double[][][] d) {
+ return interleaved2Complex(d, 2);
+ }
+
+ /**
+ * Converts a 2D interleaved complex {@code float[][]} array to a
+ * {@code Complex[][]} array.
+ *
+ * @param d 2D complex interleaved float array
+ * @param interleavedDim Depth level of the array to interleave
+ * @return 2D {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex[][] interleaved2Complex(float[][] d, int interleavedDim) {
+ if (interleavedDim > 1 || interleavedDim < 0) {
+ new IndexOutOfRangeException(interleavedDim);
+ }
+ final int width = d.length;
+ final int height = d[0].length;
+ Complex[][] c;
+ if (interleavedDim == 0) {
+ c = new Complex[width / 2][height];
+ for (int x = 0; x < width / 2; x++) {
+ for (int y = 0; y < height; y++) {
+ c[x][y] = new Complex(d[x * 2][y], d[x * 2 + 1][y]);
+ }
+ }
+ } else {
+ c = new Complex[width][height / 2];
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height / 2; y++) {
+ c[x][y] = new Complex(d[x][y * 2], d[x][y * 2 + 1]);
+ }
+ }
+ }
+ return c;
+ }
+
+ /**
+ * Converts a 2D interleaved complex {@code float[][]} array to a
+ * {@code Complex[][]} array. The second depth level of the array is assumed
+ * to be interleaved.
+ *
+ * @param d 2D complex interleaved float array
+ * @return 2D {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex[][] interleaved2Complex(float[][] d) {
+ return interleaved2Complex(d, 1);
+ }
+
+ /**
+ * Converts a 3D interleaved complex {@code float[][][]} array to a
+ * {@code Complex[][][]} array.
+ *
+ * @param d 3D complex interleaved float array
+ * @param interleavedDim Depth level of the array to interleave
+ * @return 3D {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex[][][] interleaved2Complex(float[][][] d, int interleavedDim) {
+ if (interleavedDim > 2 || interleavedDim < 0) {
+ new IndexOutOfRangeException(interleavedDim);
+ }
+ final int width = d.length;
+ final int height = d[0].length;
+ final int depth = d[0][0].length;
+ Complex[][][] c;
+ if (interleavedDim == 0) {
+ c = new Complex[width / 2][height][depth];
+ for (int x = 0; x < width/2; x ++) {
+ for (int y = 0; y < height; y++) {
+ for (int z = 0; z < depth; z++) {
+ c[x][y][z] = new Complex(d[x * 2][y][z], d[x * 2 + 1][y][z]);
+ }
+ }
+ }
+ } else if (interleavedDim == 1) {
+ c = new Complex[width][height / 2][depth];
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height/2; y ++) {
+ for (int z = 0; z < depth; z++) {
+ c[x][y][z] = new Complex(d[x][y * 2][z], d[x][y * 2 + 1][z]);
+ }
+ }
+ }
+ } else {
+ c = new Complex[width][height][depth / 2];
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ for (int z = 0; z < depth/2; z++) {
+ c[x][y][z] = new Complex(d[x][y][z * 2], d[x][y][z * 2 + 1]);
+ }
+ }
+ }
+ }
+ return c;
+ }
+
+ /**
+ * Converts a 3D interleaved complex {@code float[][][]} array to a
+ * {@code Complex[]} array. The third depth level of the array is assumed to
+ * be interleaved.
+ *
+ * @param d 3D complex interleaved float array
+ * @return 3D {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex[][][] interleaved2Complex(float[][][] d) {
+ return interleaved2Complex(d, 2);
+ }
+
+ // SPLIT METHODS
+
+ /**
+ * Converts a split complex array {@code double[] r, double[] i} to a
+ * {@code Complex[]} array.
+ *
+ * @param real real component
+ * @param imag imaginary component
+ * @return {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex[] split2Complex(double[] real, double[] imag) {
+ final int length = real.length;
+ final Complex[] c = new Complex[length];
+ for (int n = 0; n < length; n++) {
+ c[n] = new Complex(real[n], imag[n]);
+ }
+ return c;
+ }
+
+ /**
+ * Converts a 2D split complex array {@code double[][] r, double[][] i} to a
+ * 2D {@code Complex[][]} array.
+ *
+ * @param real real component
+ * @param imag imaginary component
+ * @return 2D {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex[][] split2Complex(double[][] real, double[][] imag) {
+ final int length = real.length;
+ Complex[][] c = new Complex[length][];
+ for (int x = 0; x < length; x++) {
+ c[x] = split2Complex(real[x], imag[x]);
+ }
+ return c;
+ }
+
+ /**
+ * Converts a 3D split complex array {@code double[][][] r, double[][][] i}
+ * to a 3D {@code Complex[][][]} array.
+ *
+ * @param real real component
+ * @param imag imaginary component
+ * @return 3D {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex[][][] split2Complex(double[][][] real, double[][][] imag) {
+ final int length = real.length;
+ Complex[][][] c = new Complex[length][][];
+ for (int x = 0; x < length; x++) {
+ c[x] = split2Complex(real[x], imag[x]);
+ }
+ return c;
+ }
+
+ /**
+ * Converts a split complex array {@code float[] r, float[] i} to a
+ * {@code Complex[]} array.
+ *
+ * @param real real component
+ * @param imag imaginary component
+ * @return {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex[] split2Complex(float[] real, float[] imag) {
+ final int length = real.length;
+ final Complex[] c = new Complex[length];
+ for (int n = 0; n < length; n++) {
+ c[n] = new Complex(real[n], imag[n]);
+ }
+ return c;
+ }
+
+ /**
+ * Converts a 2D split complex array {@code float[][] r, float[][] i} to a
+ * 2D {@code Complex[][]} array.
+ *
+ * @param real real component
+ * @param imag imaginary component
+ * @return 2D {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex[][] split2Complex(float[][] real, float[][] imag) {
+ final int length = real.length;
+ Complex[][] c = new Complex[length][];
+ for (int x = 0; x < length; x++) {
+ c[x] = split2Complex(real[x], imag[x]);
+ }
+ return c;
+ }
+
+ /**
+ * Converts a 3D split complex array {@code float[][][] r, float[][][] i} to
+ * a 3D {@code Complex[][][]} array.
+ *
+ * @param real real component
+ * @param imag imaginary component
+ * @return 3D {@code Complex} array
+ *
+ * @since 4.0
+ */
+ public static Complex[][][] split2Complex(float[][][] real, float[][][] imag) {
+ final int length = real.length;
+ Complex[][][] c = new Complex[length][][];
+ for (int x = 0; x < length; x++) {
+ c[x] = split2Complex(real[x], imag[x]);
+ }
+ return c;
+ }
+
+ // MISC
+
+ /**
+ * Initializes a {@code Complex[]} array to zero, to avoid
+ * NullPointerExceptions.
+ *
+ * @param c Complex array
+ * @return c
+ *
+ * @since 4.0
+ */
+ public static Complex[] initialize(Complex[] c) {
+ final int length = c.length;
+ for (int x = 0; x < length; x++) {
+ c[x] = Complex.ZERO;
+ }
+ return c;
+ }
+
+ /**
+ * Initializes a {@code Complex[][]} array to zero, to avoid
+ * NullPointerExceptions.
+ *
+ * @param c {@code Complex} array
+ * @return c
+ *
+ * @since 4.0
+ */
+ public static Complex[][] initialize(Complex[][] c) {
+ final int length = c.length;
+ for (int x = 0; x < length; x++) {
+ c[x] = initialize(c[x]);
+ }
+ return c;
+ }
+
+ /**
+ * Initializes a {@code Complex[][][]} array to zero, to avoid
+ * NullPointerExceptions.
+ *
+ * @param c {@code Complex} array
+ * @return c
+ *
+ * @since 4.0
+ */
+ public static Complex[][][] initialize(Complex[][][] c) {
+ final int length = c.length;
+ for (int x = 0; x < length; x++) {
+ c[x] = initialize(c[x]);
+ }
+ return c;
+ }
+
+ /**
+ * Returns {@code double[]} containing absolute values (magnitudes) of a
+ * {@code Complex[]} array.
+ *
+ * @param c {@code Complex} array
+ * @return {@code double[]}
+ *
+ * @since 4.0
+ */
+ public static double[] abs(Complex[] c) {
+ final int length = c.length;
+ final double[] d = new double[length];
+ for (int x = 0; x < length; x++) {
+ d[x] = c[x].abs();
+ }
+ return d;
+ }
+
+ /**
+ * Returns {@code double[]} containing arguments (phase angles) of a
+ * {@code Complex[]} array.
+ *
+ * @param c {@code Complex} array
+ * @return {@code double[]} array
+ *
+ * @since 4.0
+ */
+ public static double[] arg(Complex[] c) {
+ final int length = c.length;
+ final double[] d = new double[length];
+ for (int x = 0; x < length; x++) {
+ d[x] = c[x].getArgument();
+ }
+ return d;
+ }
+
+ /**
+ * Exception to be throw when a negative value is passed as the modulus.
+ */
+ private static class NegativeModulusException extends IllegalArgumentException {
+ /**
+ * @param r Wrong modulus.
+ */
+ NegativeModulusException(double r) {
+ super("Modulus is negative: " + r);
+ }
+ }
+
+ /**
+ * Exception to be throw when an out-of-range index value is passed.
+ */
+ private static class IndexOutOfRangeException extends IllegalArgumentException {
+ /**
+ * @param i Wrong index.
+ */
+ IndexOutOfRangeException(int i) {
+ super("Out of range: " + i);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Precision.java
----------------------------------------------------------------------
diff --git a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Precision.java b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Precision.java
new file mode 100644
index 0000000..529f8ff
--- /dev/null
+++ b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Precision.java
@@ -0,0 +1,128 @@
+/*
+ * 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.
+ */
+
+package org.apache.commons.numbers.complex;
+
+/**
+ * Utilities for comparing numbers.
+ */
+class Precision {
+ /** Offset to order signed double numbers lexicographically. */
+ private static final long SGN_MASK = 0x8000000000000000L;
+ /** Positive zero bits. */
+ private static final long POSITIVE_ZERO_DOUBLE_BITS = Double.doubleToRawLongBits(+0.0);
+ /** Negative zero bits. */
+ private static final long NEGATIVE_ZERO_DOUBLE_BITS = Double.doubleToRawLongBits(-0.0);
+
+ /**
+ * Private constructor.
+ */
+ private Precision() {}
+
+ /**
+ * Returns {@code true} if there is no double value strictly between the
+ * arguments or the difference between them is within the range of allowed
+ * error (inclusive). Returns {@code false} if either of the arguments
+ * is NaN.
+ *
+ * @param x First value.
+ * @param y Second value.
+ * @param eps Amount of allowed absolute error.
+ * @return {@code true} if the values are two adjacent floating point
+ * numbers or they are within range of each other.
+ */
+ public static boolean equals(double x, double y, double eps) {
+ return equals(x, y, 1) || Math.abs(y - x) <= eps;
+ }
+
+ /**
+ * Returns {@code true} if there is no double value strictly between the
+ * arguments or the relative difference between them is less than or equal
+ * to the given tolerance. Returns {@code false} if either of the arguments
+ * is NaN.
+ *
+ * @param x First value.
+ * @param y Second value.
+ * @param eps Amount of allowed relative error.
+ * @return {@code true} if the values are two adjacent floating point
+ * numbers or they are within range of each other.
+ */
+ public static boolean equalsWithRelativeTolerance(double x, double y, double eps) {
+ if (equals(x, y, 1)) {
+ return true;
+ }
+
+ final double absoluteMax = Math.max(Math.abs(x), Math.abs(y));
+ final double relativeDifference = Math.abs((x - y) / absoluteMax);
+
+ return relativeDifference <= eps;
+ }
+
+ /**
+ * Returns true if the arguments are equal or within the range of allowed
+ * error (inclusive).
+ * <p>
+ * Two float numbers are considered equal if there are {@code (maxUlps - 1)}
+ * (or fewer) floating point numbers between them, i.e. two adjacent
+ * floating point numbers are considered equal.
+ * </p>
+ * <p>
+ * Adapted from <a
+ * href="http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/">
+ * Bruce Dawson</a>. Returns {@code false} if either of the arguments is NaN.
+ * </p>
+ *
+ * @param x first value
+ * @param y second value
+ * @param maxUlps {@code (maxUlps - 1)} is the number of floating point
+ * values between {@code x} and {@code y}.
+ * @return {@code true} if there are fewer than {@code maxUlps} floating
+ * point values between {@code x} and {@code y}.
+ */
+ public static boolean equals(final double x, final double y, final int maxUlps) {
+
+ final long xInt = Double.doubleToRawLongBits(x);
+ final long yInt = Double.doubleToRawLongBits(y);
+
+ final boolean isEqual;
+ if (((xInt ^ yInt) & SGN_MASK) == 0l) {
+ // number have same sign, there is no risk of overflow
+ isEqual = Math.abs(xInt - yInt) <= maxUlps;
+ } else {
+ // number have opposite signs, take care of overflow
+ final long deltaPlus;
+ final long deltaMinus;
+ if (xInt < yInt) {
+ deltaPlus = yInt - POSITIVE_ZERO_DOUBLE_BITS;
+ deltaMinus = xInt - NEGATIVE_ZERO_DOUBLE_BITS;
+ } else {
+ deltaPlus = xInt - POSITIVE_ZERO_DOUBLE_BITS;
+ deltaMinus = yInt - NEGATIVE_ZERO_DOUBLE_BITS;
+ }
+
+ if (deltaPlus > maxUlps) {
+ isEqual = false;
+ } else {
+ isEqual = deltaMinus <= (maxUlps - deltaPlus);
+ }
+
+ }
+
+ return isEqual && !Double.isNaN(x) && !Double.isNaN(y);
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/RootsOfUnity.java
----------------------------------------------------------------------
diff --git a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/RootsOfUnity.java b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/RootsOfUnity.java
new file mode 100644
index 0000000..89bf8d3
--- /dev/null
+++ b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/RootsOfUnity.java
@@ -0,0 +1,116 @@
+/*
+ * 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.
+ */
+package org.apache.commons.numbers.complex;
+
+/**
+ * Computation of the {@code n}-th roots of unity.
+ */
+public class RootsOfUnity {
+ /** 2 * π */
+ private static final double TWO_PI = 2 * Math.PI;
+ /** Number of roots of unity. */
+ private final int omegaCount;
+ /** The roots. */
+ private final Complex[] omega;
+ /**
+ * {@code true} if the constructor was called with a positive
+ * value of its argument {@code n}.
+ */
+ private final boolean isCounterClockwise;
+
+ /**
+ * Computes the {@code n}-th roots of unity.
+ *
+ * The roots are stored in an array
+ * {@code omega[]}, such that {@code omega[k] = w ^ k}, where
+ * {@code k = 0, ..., n - 1}, {@code w = exp(2 * pi * i / n)} and
+ * {@code i = sqrt(-1)}.
+ *
+ * <p>{@code n} can be positive of negative ({@code abs(n)} is always
+ * the number of roots of unity):</p>
+ * <ul>
+ * <li>If {@code n > 0}, then the roots are stored in counter-clockwise order.</li>
+ * <li>If {@code n < 0}, then the roots are stored in clockwise order.</li>
+ * </ul>
+ *
+ * @param n The (signed) number of roots of unity to be computed.
+ * @throws IllegalArgumentException if {@code n == 0}?
+ */
+ public RootsOfUnity(int n) {
+ if (n == 0) {
+ throw new IllegalArgumentException("Zero-th root");
+ }
+
+ omegaCount = Math.abs(n);
+ isCounterClockwise = n > 0;
+
+ omega = new Complex[omegaCount];
+ final double t = TWO_PI / omegaCount;
+ final double cosT = Math.cos(t);
+ final double sinT = Math.sin(t);
+
+ double previousReal = 1;
+ double previousImag = 0;
+ omega[0] = new Complex(previousReal, previousImag);
+ for (int i = 1; i < omegaCount; i++) {
+ final double real = previousReal * cosT - previousImag * sinT;
+ final double imag = previousReal * sinT + previousImag * cosT;
+
+ omega[i] = isCounterClockwise ?
+ new Complex(real, imag) :
+ new Complex(real, -imag);
+
+ previousReal = real;
+ previousImag = imag;
+ }
+ }
+
+ /**
+ * Returns {@code true} if {@link #RootsOfUnity(int)} was called with a
+ * positive value of its argument {@code n}.
+ * If {@code true}, then the imaginary parts of the successive roots are
+ * {@link #getRoot(int) returned} in counter-clockwise order.
+ *
+ * @return {@code true} if the roots of unity are stored in
+ * counter-clockwise order.
+ */
+ public boolean isCounterClockwise() {
+ return isCounterClockwise;
+ }
+
+ /**
+ * Gets the {@code k}-th among the computed roots of unity.
+ *
+ * @param k Index of the requested value.
+ * @return the {@code k}-th among the {@code N}-th root of unity
+ * where {@code N} is the absolute value of the argument passed
+ * to the constructor.
+ * @throws IndexOutOfBoundsException if {@code k} is out of range.
+ */
+ public Complex getRoot(int k) {
+ return omega[k];
+ }
+
+ /**
+ * Gets the number of roots of unity.
+ *
+ * @return the number of roots of unity.
+ */
+ public int getNumberOfRoots() {
+ return omegaCount;
+ }
+}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4541327/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/package-info.java
----------------------------------------------------------------------
diff --git a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/package-info.java b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/package-info.java
new file mode 100644
index 0000000..152d08f
--- /dev/null
+++ b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+/**
+ * Complex numbers.
+ */
+package org.apache.commons.numbers.complex;