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/multimodule Commit: a752ab8d4e4d1a9982cd1df45743cafc6dedd5dc Parents: 0d64d85 Author: Gilles Sadowski <[email protected]> Authored: Wed Jan 18 14:20:27 2017 +0100 Committer: Gilles Sadowski <[email protected]> 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(); - } - -} -
