diff --git a/commons-math-examples/pom.xml b/commons-math-examples/pom.xml index 2b37839df..e182af04a 100644 --- a/commons-math-examples/pom.xml +++ b/commons-math-examples/pom.xml @@ -27,7 +27,7 @@ commons-math-examples 4.0-SNAPSHOT pom - Apache Commons Math Examples + Example applications Examples of use of the "Commons Math" library. Codes in this module and its sub-modules are not part of the public API. diff --git a/commons-math-legacy-core/LICENCE b/commons-math-legacy-core/LICENCE new file mode 100644 index 000000000..d97b49ab0 --- /dev/null +++ b/commons-math-legacy-core/LICENCE @@ -0,0 +1,457 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + +Apache Commons Math includes the following code provided to the ASF under the +Apache License 2.0: + + - The inverse error function implementation in the Erf class is based on CUDA + code developed by Mike Giles, Oxford-Man Institute of Quantitative Finance, + and published in GPU Computing Gems, volume 2, 2010 (grant received on + March 23th 2013) + - The LinearConstraint, LinearObjectiveFunction, LinearOptimizer, + RelationShip, SimplexSolver and SimplexTableau classes in package + org.apache.commons.math3.optimization.linear include software developed by + Benjamin McCann (http://www.benmccann.com) and distributed with + the following copyright: Copyright 2009 Google Inc. (grant received on + March 16th 2009) + - The class "org.apache.commons.math3.exception.util.LocalizedFormatsTest" which + is an adapted version of "OrekitMessagesTest" test class for the Orekit library + - The "org.apache.commons.math3.analysis.interpolation.HermiteInterpolator" + has been imported from the Orekit space flight dynamics library. + +=============================================================================== + + + +APACHE COMMONS MATH DERIVATIVE WORKS: + +The Apache commons-math library includes a number of subcomponents +whose implementation is derived from original sources written +in C or Fortran. License terms of the original sources +are reproduced below. + +=============================================================================== +For the lmder, lmpar and qrsolv Fortran routine from minpack and translated in +the LevenbergMarquardtOptimizer class in package +org.apache.commons.math3.optimization.general +Original source copyright and license statement: + +Minpack Copyright Notice (1999) University of Chicago. All rights reserved + +Redistribution and use in source and binary forms, with or +without modification, are permitted provided that the +following conditions are met: + +1. Redistributions of source code must retain the above +copyright notice, this list of conditions and the following +disclaimer. + +2. Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following +disclaimer in the documentation and/or other materials +provided with the distribution. + +3. The end-user documentation included with the +redistribution, if any, must include the following +acknowledgment: + + "This product includes software developed by the + University of Chicago, as Operator of Argonne National + Laboratory. + +Alternately, this acknowledgment may appear in the software +itself, if and wherever such third-party acknowledgments +normally appear. + +4. WARRANTY DISCLAIMER. THE SOFTWARE IS SUPPLIED "AS IS" +WITHOUT WARRANTY OF ANY KIND. THE COPYRIGHT HOLDER, THE +UNITED STATES, THE UNITED STATES DEPARTMENT OF ENERGY, AND +THEIR EMPLOYEES: (1) DISCLAIM ANY WARRANTIES, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO ANY IMPLIED WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE +OR NON-INFRINGEMENT, (2) DO NOT ASSUME ANY LEGAL LIABILITY +OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, OR +USEFULNESS OF THE SOFTWARE, (3) DO NOT REPRESENT THAT USE OF +THE SOFTWARE WOULD NOT INFRINGE PRIVATELY OWNED RIGHTS, (4) +DO NOT WARRANT THAT THE SOFTWARE WILL FUNCTION +UNINTERRUPTED, THAT IT IS ERROR-FREE OR THAT ANY ERRORS WILL +BE CORRECTED. + +5. LIMITATION OF LIABILITY. IN NO EVENT WILL THE COPYRIGHT +HOLDER, THE UNITED STATES, THE UNITED STATES DEPARTMENT OF +ENERGY, OR THEIR EMPLOYEES: BE LIABLE FOR ANY INDIRECT, +INCIDENTAL, CONSEQUENTIAL, SPECIAL OR PUNITIVE DAMAGES OF +ANY KIND OR NATURE, INCLUDING BUT NOT LIMITED TO LOSS OF +PROFITS OR LOSS OF DATA, FOR ANY REASON WHATSOEVER, WHETHER +SUCH LIABILITY IS ASSERTED ON THE BASIS OF CONTRACT, TORT +(INCLUDING NEGLIGENCE OR STRICT LIABILITY), OR OTHERWISE, +EVEN IF ANY OF SAID PARTIES HAS BEEN WARNED OF THE +POSSIBILITY OF SUCH LOSS OR DAMAGES. +=============================================================================== + +Copyright and license statement for the odex Fortran routine developed by +E. Hairer and G. Wanner and translated in GraggBulirschStoerIntegrator class +in package org.apache.commons.math3.ode.nonstiff: + + +Copyright (c) 2004, Ernst Hairer + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +- Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +=============================================================================== + +Copyright and license statement for the original Mersenne twister C +routines translated in MersenneTwister class in package +org.apache.commons.math3.random: + + Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + 3. The names of its contributors may not be used to endorse or promote + products derived from this software without specific prior written + permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=============================================================================== + +The initial code for shuffling an array (originally in class +"org.apache.commons.math3.random.RandomDataGenerator", now replaced by +a method in class "org.apache.commons.math3.util.MathArrays") was +inspired from the algorithm description provided in +"Algorithms", by Ian Craw and John Pulham (University of Aberdeen 1999). +The textbook (containing a proof that the shuffle is uniformly random) is +available here: + http://citeseerx.ist.psu.edu/viewdoc/download;?doi=10.1.1.173.1898&rep=rep1&type=pdf + +=============================================================================== +License statement for the direction numbers in the resource files for Sobol sequences. + +----------------------------------------------------------------------------- +Licence pertaining to sobol.cc and the accompanying sets of direction numbers + +----------------------------------------------------------------------------- +Copyright (c) 2008, Frances Y. Kuo and Stephen Joe +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the names of the copyright holders nor the names of the + University of New South Wales and the University of Waikato + and its contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +=============================================================================== + +The initial commit of package "org.apache.commons.math3.ml.neuralnet" is +an adapted version of code developed in the context of the Data Processing +and Analysis Consortium (DPAC) of the "Gaia" project of the European Space +Agency (ESA). +=============================================================================== + +The initial commit of the class "org.apache.commons.math3.special.BesselJ" is +an adapted version of code translated from the netlib Fortran program, rjbesl +http://www.netlib.org/specfun/rjbesl by R.J. Cody at Argonne National +Laboratory (USA). There is no license or copyright statement included with the +original Fortran sources. +=============================================================================== + + +The BracketFinder (package org.apache.commons.math3.optimization.univariate) +and PowellOptimizer (package org.apache.commons.math3.optimization.general) +classes are based on the Python code in module "optimize.py" (version 0.5) +developed by Travis E. Oliphant for the SciPy library (http://www.scipy.org/) +Copyright © 2003-2009 SciPy Developers. + +SciPy license +Copyright © 2001, 2002 Enthought, Inc. +All rights reserved. + +Copyright © 2003-2013 SciPy Developers. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Enthought nor the names of the SciPy Developers may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +=============================================================================== + diff --git a/commons-math-legacy-core/NOTICE b/commons-math-legacy-core/NOTICE new file mode 100644 index 000000000..587cd7f1d --- /dev/null +++ b/commons-math-legacy-core/NOTICE @@ -0,0 +1,9 @@ +Apache Commons Math +Copyright 2001-2020 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). + +This product includes software developed for Orekit by +CS Systèmes d'Information (http://www.c-s.fr/) +Copyright 2010-2012 CS Systèmes d'Information diff --git a/commons-math-legacy-core/pom.xml b/commons-math-legacy-core/pom.xml new file mode 100644 index 000000000..8b14ff6da --- /dev/null +++ b/commons-math-legacy-core/pom.xml @@ -0,0 +1,74 @@ + + + + 4.0.0 + + + org.apache.commons + commons-math-parent + 4.0-SNAPSHOT + + + commons-math4-legacy-core + Miscellaneous core classes (Legacy) + + Field, Dfp, ... + + + + org.apache.commons.math4.legacy.core + + org.apache.commons.math4.legacy.core + + org.apache.commons.math4.legacy.core + + ${basedir}/.. + + + + + + org.apache.commons + commons-math4-legacy-exception + + + + org.apache.commons + commons-numbers-core + + + + org.apache.commons + commons-numbers-arrays + + + + org.apache.commons + commons-rng-client-api + + + + org.apache.commons + commons-rng-simple + + + + + diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/Field.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/Field.java similarity index 97% rename from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/Field.java rename to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/Field.java index f6168c4b3..433021282 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/Field.java +++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/Field.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.commons.math4.legacy; +package org.apache.commons.math4.legacy.core; /** * Interface representing a field. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/FieldElement.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/FieldElement.java similarity index 98% rename from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/FieldElement.java rename to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/FieldElement.java index bcd1daef7..e2ee0fe13 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/FieldElement.java +++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/FieldElement.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.commons.math4.legacy; +package org.apache.commons.math4.legacy.core; import org.apache.commons.math4.legacy.exception.MathArithmeticException; import org.apache.commons.math4.legacy.exception.NullArgumentException; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/MathArrays.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/MathArrays.java similarity index 98% rename from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/MathArrays.java rename to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/MathArrays.java index 3d55cc84a..10a8ed15c 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/MathArrays.java +++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/MathArrays.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.commons.math4.legacy.util; +package org.apache.commons.math4.legacy.core; import java.lang.reflect.Array; import java.util.ArrayList; @@ -27,7 +27,6 @@ import java.util.List; import java.util.TreeSet; import org.apache.commons.numbers.core.Precision; -import org.apache.commons.math4.legacy.Field; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.MathArithmeticException; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; @@ -40,6 +39,7 @@ import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Arrays utilities. @@ -196,7 +196,7 @@ public class MathArrays { checkEqualLength(p1, p2); double sum = 0; for (int i = 0; i < p1.length; i++) { - sum += FastMath.abs(p1[i] - p2[i]); + sum += AccurateMath.abs(p1[i] - p2[i]); } return sum; } @@ -213,7 +213,7 @@ public class MathArrays { checkEqualLength(p1, p2); int sum = 0; for (int i = 0; i < p1.length; i++) { - sum += FastMath.abs(p1[i] - p2[i]); + sum += AccurateMath.abs(p1[i] - p2[i]); } return sum; } @@ -233,7 +233,7 @@ public class MathArrays { final double dp = p1[i] - p2[i]; sum += dp * dp; } - return FastMath.sqrt(sum); + return AccurateMath.sqrt(sum); } /** @@ -251,7 +251,7 @@ public class MathArrays { final double dp = p1[i] - p2[i]; sum += dp * dp; } - return FastMath.sqrt(sum); + return AccurateMath.sqrt(sum); } /** @@ -266,7 +266,7 @@ public class MathArrays { checkEqualLength(p1, p2); double max = 0; for (int i = 0; i < p1.length; i++) { - max = FastMath.max(max, FastMath.abs(p1[i] - p2[i])); + max = AccurateMath.max(max, AccurateMath.abs(p1[i] - p2[i])); } return max; } @@ -283,7 +283,7 @@ public class MathArrays { checkEqualLength(p1, p2); int max = 0; for (int i = 0; i < p1.length; i++) { - max = FastMath.max(max, FastMath.abs(p1[i] - p2[i])); + max = AccurateMath.max(max, AccurateMath.abs(p1[i] - p2[i])); } return max; } @@ -990,7 +990,7 @@ public class MathArrays { // straightforward implementation of the convolution sum for (int n = 0; n < totalLength; n++) { double yn = 0; - int k = FastMath.max(0, n + 1 - xLen); + int k = AccurateMath.max(0, n + 1 - xLen); int j = n - k; while (k < hLen && j >= 0) { yn += x[j--] * h[k++]; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/RealFieldElement.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/RealFieldElement.java similarity index 99% rename from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/RealFieldElement.java rename to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/RealFieldElement.java index 1bce77b24..2d8b0a433 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/RealFieldElement.java +++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/RealFieldElement.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.commons.math4.legacy; +package org.apache.commons.math4.legacy.core; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/dfp/Dfp.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/Dfp.java similarity index 99% rename from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/dfp/Dfp.java rename to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/Dfp.java index 3daefad1e..d6ece898d 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/dfp/Dfp.java +++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/Dfp.java @@ -15,13 +15,12 @@ * limitations under the License. */ -package org.apache.commons.math4.legacy.dfp; +package org.apache.commons.math4.legacy.core.dfp; import java.util.Arrays; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; -import org.apache.commons.math4.legacy.util.FastMath; /** * Decimal floating point library for Java @@ -625,12 +624,12 @@ public class Dfp implements RealFieldElement { return field.newDfp(sig, code); } - /** Get the {@link org.apache.commons.math4.legacy.Field Field} (really a {@link DfpField}) to which the instance belongs. + /** Get the {@link org.apache.commons.math4.legacy.core.Field Field} (really a {@link DfpField}) to which the instance belongs. *

* The field is linked to the number of digits and acts as a factory * for {@link Dfp} instances. *

- * @return {@link org.apache.commons.math4.legacy.Field Field} (really a {@link DfpField}) to which the instance belongs + * @return {@link org.apache.commons.math4.legacy.core.Field Field} (really a {@link DfpField}) to which the instance belongs */ @Override public DfpField getField() { @@ -2579,7 +2578,7 @@ public class Dfp implements RealFieldElement { */ @Override public long round() { - return FastMath.round(toDouble()); + return Math.round(toDouble()); } /** {@inheritDoc} @@ -2782,7 +2781,7 @@ public class Dfp implements RealFieldElement { // compute atan2(y, x) = +/- pi - 2 atan(y / (r - x)) final Dfp tmp = getTwo().multiply(divide(r.subtract(x)).atan()); - final Dfp pmPi = newInstance((tmp.sign <= 0) ? -FastMath.PI : FastMath.PI); + final Dfp pmPi = newInstance((tmp.sign <= 0) ? -Math.PI : Math.PI); return pmPi.subtract(tmp); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/dfp/DfpDec.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/DfpDec.java similarity index 99% rename from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/dfp/DfpDec.java rename to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/DfpDec.java index c42003bcd..4e1205342 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/dfp/DfpDec.java +++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/DfpDec.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.commons.math4.legacy.dfp; +package org.apache.commons.math4.legacy.core.dfp; /** Subclass of {@link Dfp} which hides the radix-10000 artifacts of the superclass. * This should give outward appearances of being a decimal number with DIGITS*4-3 diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/dfp/DfpField.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/DfpField.java similarity index 99% rename from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/dfp/DfpField.java rename to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/DfpField.java index fd4ae5457..10b30cd3a 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/dfp/DfpField.java +++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/DfpField.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package org.apache.commons.math4.legacy.dfp; +package org.apache.commons.math4.legacy.core.dfp; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.FieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.FieldElement; /** Field for Decimal floating point instances. * @since 2.2 diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/dfp/DfpMath.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/DfpMath.java similarity index 99% rename from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/dfp/DfpMath.java rename to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/DfpMath.java index 81eb2a60a..b1b98561d 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/dfp/DfpMath.java +++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/DfpMath.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.commons.math4.legacy.dfp; +package org.apache.commons.math4.legacy.core.dfp; /** Mathematical routines for use with {@link Dfp}. * The constants are defined in {@link DfpField} diff --git a/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/package-info.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/package-info.java new file mode 100644 index 000000000..f9186c4cf --- /dev/null +++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/package-info.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * + * Decimal floating point library for Java + * + *

Another floating point class. This one is built using radix 10000 + * which is 104, so its almost decimal.

+ * + *

The design goals here are: + *

    + *
  1. Decimal math, or close to it
  2. + *
  3. Settable precision (but no mix between numbers using different settings)
  4. + *
  5. Portability. Code should be keep as portable as possible.
  6. + *
  7. Performance
  8. + *
  9. Accuracy - Results should always be +/- 1 ULP for basic + * algebraic operation
  10. + *
  11. Comply with IEEE 854-1987 as much as possible. + * (See IEEE 854-1987 notes below)
  12. + *
+ * + *

Trade offs: + *

    + *
  1. Memory foot print. I'm using more memory than necessary to + * represent numbers to get better performance.
  2. + *
  3. Digits are bigger, so rounding is a greater loss. So, if you + * really need 12 decimal digits, better use 4 base 10000 digits + * there can be one partially filled.
  4. + *
+ * + *

Numbers are represented in the following form: + *

+ * n = sign × mant × (radix)exp; + *
+ * where sign is ±1, mantissa represents a fractional number between + * zero and one. mant[0] is the least significant digit. + * exp is in the range of -32767 to 32768 + * + *

IEEE 854-1987 Notes and differences

+ * + *

IEEE 854 requires the radix to be either 2 or 10. The radix here is + * 10000, so that requirement is not met, but it is possible that a + * subclassed can be made to make it behave as a radix 10 + * number. It is my opinion that if it looks and behaves as a radix + * 10 number then it is one and that requirement would be met.

+ * + *

The radix of 10000 was chosen because it should be faster to operate + * on 4 decimal digits at once instead of one at a time. Radix 10 behavior + * can be realized by add an additional rounding step to ensure that + * the number of decimal digits represented is constant.

+ * + *

The IEEE standard specifically leaves out internal data encoding, + * so it is reasonable to conclude that such a subclass of this radix + * 10000 system is merely an encoding of a radix 10 system.

+ * + *

IEEE 854 also specifies the existence of "sub-normal" numbers. This + * class does not contain any such entities. The most significant radix + * 10000 digit is always non-zero. Instead, we support "gradual underflow" + * by raising the underflow flag for numbers less with exponent less than + * expMin, but don't flush to zero until the exponent reaches MIN_EXP-digits. + * Thus the smallest number we can represent would be: + * 1E(-(MIN_EXP-digits-1)∗4), eg, for digits=5, MIN_EXP=-32767, that would + * be 1e-131092.

+ * + *

IEEE 854 defines that the implied radix point lies just to the right + * of the most significant digit and to the left of the remaining digits. + * This implementation puts the implied radix point to the left of all + * digits including the most significant one. The most significant digit + * here is the one just to the right of the radix point. This is a fine + * detail and is really only a matter of definition. Any side effects of + * this can be rendered invisible by a subclass.

+ * + */ +package org.apache.commons.math4.legacy.core.dfp; diff --git a/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMath.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMath.java new file mode 100644 index 000000000..a6307fb36 --- /dev/null +++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMath.java @@ -0,0 +1,4351 @@ +/* + * 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.legacy.core.jdkmath; + +import java.io.PrintStream; + +import org.apache.commons.numbers.core.Precision; +import org.apache.commons.math4.legacy.exception.MathArithmeticException; +import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; + +/** + * Portable alternative to {@link Math} and {@link StrictMath}. + *

+ * Caveat: At the time of implementation, the {@code AccurateMath} functions + * were often faster and/or more accurate than their JDK equivalent. + * Nowadays, it would not be surprising that they are always slower (due + * to the various JVM optimizations that have appeared since Java 5). + * However, any change to this class should ensure that the current + * accuracy is not lost. + *

+ * AccurateMath is a drop-in replacement for both Math and StrictMath. This + * means that for any method in Math (say {@code Math.sin(x)} or + * {@code Math.cbrt(y)}), user can directly change the class and use the + * methods as is (using {@code AccurateMath.sin(x)} or {@code AccurateMath.cbrt(y)} + * in the previous example). + *

+ *

+ * AccurateMath speed is achieved by relying heavily on optimizing compilers + * to native code present in many JVMs today and use of large tables. + * The larger tables are lazily initialized on first use, so that the setup + * time does not penalize methods that don't need them. + *

+ *

+ * Note that AccurateMath is + * extensively used inside Apache Commons Math, so by calling some algorithms, + * the overhead when the tables need to be initialized will occur + * regardless of the end-user calling AccurateMath methods directly or not. + * Performance figures for a specific JVM and hardware can be evaluated by + * running the AccurateMathTestPerformance tests in the test directory of the source + * distribution. + *

+ *

+ * AccurateMath accuracy should be mostly independent of the JVM as it relies only + * on IEEE-754 basic operations and on embedded tables. Almost all operations + * are accurate to about 0.5 ulp throughout the domain range. This statement, + * of course is only a rough global observed behavior, it is not a + * guarantee for every double numbers input (see William Kahan's Table + * Maker's Dilemma). + *

+ *

+ * AccurateMath additionally implements the following methods not found in Math/StrictMath: + *

    + *
  • {@link #asinh(double)}
  • + *
  • {@link #acosh(double)}
  • + *
  • {@link #atanh(double)}
  • + *
+ * The following methods are found in Math/StrictMath since 1.6 only, they are provided + * by AccurateMath even in 1.5 Java virtual machines + *
    + *
  • {@link #copySign(double, double)}
  • + *
  • {@link #getExponent(double)}
  • + *
  • {@link #nextAfter(double,double)}
  • + *
  • {@link #nextUp(double)}
  • + *
  • {@link #scalb(double, int)}
  • + *
  • {@link #copySign(float, float)}
  • + *
  • {@link #getExponent(float)}
  • + *
  • {@link #nextAfter(float,double)}
  • + *
  • {@link #nextUp(float)}
  • + *
  • {@link #scalb(float, int)}
  • + *
+ * @since 2.2 + */ +public class AccurateMath { + /** Archimede's constant PI, ratio of circle circumference to diameter. */ + public static final double PI = 105414357.0 / 33554432.0 + 1.984187159361080883e-9; + + /** Napier's constant e, base of the natural logarithm. */ + public static final double E = 2850325.0 / 1048576.0 + 8.254840070411028747e-8; + + /** Index of exp(0) in the array of integer exponentials. */ + static final int EXP_INT_TABLE_MAX_INDEX = 750; + /** Length of the array of integer exponentials. */ + static final int EXP_INT_TABLE_LEN = EXP_INT_TABLE_MAX_INDEX * 2; + /** Logarithm table length. */ + static final int LN_MANT_LEN = 1024; + /** Exponential fractions table length. */ + static final int EXP_FRAC_TABLE_LEN = 1025; // 0, 1/1024, ... 1024/1024 + + /** StrictMath.log(Double.MAX_VALUE): {@value} */ + private static final double LOG_MAX_VALUE = StrictMath.log(Double.MAX_VALUE); + + /** Indicator for tables initialization. + *

+ * This compile-time constant should be set to true only if one explicitly + * wants to compute the tables at class loading time instead of using the + * already computed ones provided as literal arrays below. + *

+ */ + private static final boolean RECOMPUTE_TABLES_AT_RUNTIME = false; + + /** log(2) (high bits). */ + private static final double LN_2_A = 0.693147063255310059; + + /** log(2) (low bits). */ + private static final double LN_2_B = 1.17304635250823482e-7; + + /** Coefficients for log, when input 0.99 < x < 1.01. */ + private static final double LN_QUICK_COEF[][] = { + {1.0, 5.669184079525E-24}, + {-0.25, -0.25}, + {0.3333333134651184, 1.986821492305628E-8}, + {-0.25, -6.663542893624021E-14}, + {0.19999998807907104, 1.1921056801463227E-8}, + {-0.1666666567325592, -7.800414592973399E-9}, + {0.1428571343421936, 5.650007086920087E-9}, + {-0.12502530217170715, -7.44321345601866E-11}, + {0.11113807559013367, 9.219544613762692E-9}, + }; + + /** Coefficients for log in the range of 1.0 < x < 1.0 + 2^-10. */ + private static final double LN_HI_PREC_COEF[][] = { + {1.0, -6.032174644509064E-23}, + {-0.25, -0.25}, + {0.3333333134651184, 1.9868161777724352E-8}, + {-0.2499999701976776, -2.957007209750105E-8}, + {0.19999954104423523, 1.5830993332061267E-10}, + {-0.16624879837036133, -2.6033824355191673E-8} + }; + + /** Sine, Cosine, Tangent tables are for 0, 1/8, 2/8, ... 13/8 = PI/2 approx. */ + private static final int SINE_TABLE_LEN = 14; + + /** Sine table (high bits). */ + private static final double SINE_TABLE_A[] = + { + +0.0d, + +0.1246747374534607d, + +0.24740394949913025d, + +0.366272509098053d, + +0.4794255495071411d, + +0.5850973129272461d, + +0.6816387176513672d, + +0.7675435543060303d, + +0.8414709568023682d, + +0.902267575263977d, + +0.9489846229553223d, + +0.9808930158615112d, + +0.9974949359893799d, + +0.9985313415527344d, + }; + + /** Sine table (low bits). */ + private static final double SINE_TABLE_B[] = + { + +0.0d, + -4.068233003401932E-9d, + +9.755392680573412E-9d, + +1.9987994582857286E-8d, + -1.0902938113007961E-8d, + -3.9986783938944604E-8d, + +4.23719669792332E-8d, + -5.207000323380292E-8d, + +2.800552834259E-8d, + +1.883511811213715E-8d, + -3.5997360512765566E-9d, + +4.116164446561962E-8d, + +5.0614674548127384E-8d, + -1.0129027912496858E-9d, + }; + + /** Cosine table (high bits). */ + private static final double COSINE_TABLE_A[] = + { + +1.0d, + +0.9921976327896118d, + +0.9689123630523682d, + +0.9305076599121094d, + +0.8775825500488281d, + +0.8109631538391113d, + +0.7316888570785522d, + +0.6409968137741089d, + +0.5403022766113281d, + +0.4311765432357788d, + +0.3153223395347595d, + +0.19454771280288696d, + +0.07073719799518585d, + -0.05417713522911072d, + }; + + /** Cosine table (low bits). */ + private static final double COSINE_TABLE_B[] = + { + +0.0d, + +3.4439717236742845E-8d, + +5.865827662008209E-8d, + -3.7999795083850525E-8d, + +1.184154459111628E-8d, + -3.43338934259355E-8d, + +1.1795268640216787E-8d, + +4.438921624363781E-8d, + +2.925681159240093E-8d, + -2.6437112632041807E-8d, + +2.2860509143963117E-8d, + -4.813899778443457E-9d, + +3.6725170580355583E-9d, + +2.0217439756338078E-10d, + }; + + + /** Tangent table, used by atan() (high bits). */ + private static final double TANGENT_TABLE_A[] = + { + +0.0d, + +0.1256551444530487d, + +0.25534194707870483d, + +0.3936265707015991d, + +0.5463024377822876d, + +0.7214844226837158d, + +0.9315965175628662d, + +1.1974215507507324d, + +1.5574076175689697d, + +2.092571258544922d, + +3.0095696449279785d, + +5.041914939880371d, + +14.101419448852539d, + -18.430862426757812d, + }; + + /** Tangent table, used by atan() (low bits). */ + private static final double TANGENT_TABLE_B[] = + { + +0.0d, + -7.877917738262007E-9d, + -2.5857668567479893E-8d, + +5.2240336371356666E-9d, + +5.206150291559893E-8d, + +1.8307188599677033E-8d, + -5.7618793749770706E-8d, + +7.848361555046424E-8d, + +1.0708593250394448E-7d, + +1.7827257129423813E-8d, + +2.893485277253286E-8d, + +3.1660099222737955E-7d, + +4.983191803254889E-7d, + -3.356118100840571E-7d, + }; + + /** Bits of 1/(2*pi), need for reducePayneHanek(). */ + private static final long RECIP_2PI[] = new long[] { + (0x28be60dbL << 32) | 0x9391054aL, + (0x7f09d5f4L << 32) | 0x7d4d3770L, + (0x36d8a566L << 32) | 0x4f10e410L, + (0x7f9458eaL << 32) | 0xf7aef158L, + (0x6dc91b8eL << 32) | 0x909374b8L, + (0x01924bbaL << 32) | 0x82746487L, + (0x3f877ac7L << 32) | 0x2c4a69cfL, + (0xba208d7dL << 32) | 0x4baed121L, + (0x3a671c09L << 32) | 0xad17df90L, + (0x4e64758eL << 32) | 0x60d4ce7dL, + (0x272117e2L << 32) | 0xef7e4a0eL, + (0xc7fe25ffL << 32) | 0xf7816603L, + (0xfbcbc462L << 32) | 0xd6829b47L, + (0xdb4d9fb3L << 32) | 0xc9f2c26dL, + (0xd3d18fd9L << 32) | 0xa797fa8bL, + (0x5d49eeb1L << 32) | 0xfaf97c5eL, + (0xcf41ce7dL << 32) | 0xe294a4baL, + 0x9afed7ecL << 32 }; + + /** Bits of pi/4, need for reducePayneHanek(). */ + private static final long PI_O_4_BITS[] = new long[] { + (0xc90fdaa2L << 32) | 0x2168c234L, + (0xc4c6628bL << 32) | 0x80dc1cd1L }; + + /** Eighths. + * This is used by sinQ, because its faster to do a table lookup than + * a multiply in this time-critical routine + */ + private static final double EIGHTHS[] = {0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1.0, 1.125, 1.25, 1.375, 1.5, 1.625}; + + /** Table of 2^((n+2)/3) */ + private static final double CBRTTWO[] = { 0.6299605249474366, + 0.7937005259840998, + 1.0, + 1.2599210498948732, + 1.5874010519681994 }; + + /* + * There are 52 bits in the mantissa of a double. + * For additional precision, the code splits double numbers into two parts, + * by clearing the low order 30 bits if possible, and then performs the arithmetic + * on each half separately. + */ + + /** + * 0x40000000 - used to split a double into two parts, both with the low order bits cleared. + * Equivalent to 2^30. + */ + private static final long HEX_40000000 = 0x40000000L; // 1073741824L + + /** Mask used to clear low order 30 bits */ + private static final long MASK_30BITS = -1L - (HEX_40000000 -1); // 0xFFFFFFFFC0000000L; + + /** Mask used to clear the non-sign part of an int. */ + private static final int MASK_NON_SIGN_INT = 0x7fffffff; + + /** Mask used to clear the non-sign part of a long. */ + private static final long MASK_NON_SIGN_LONG = 0x7fffffffffffffffl; + + /** Mask used to extract exponent from double bits. */ + private static final long MASK_DOUBLE_EXPONENT = 0x7ff0000000000000L; + + /** Mask used to extract mantissa from double bits. */ + private static final long MASK_DOUBLE_MANTISSA = 0x000fffffffffffffL; + + /** Mask used to add implicit high order bit for normalized double. */ + private static final long IMPLICIT_HIGH_BIT = 0x0010000000000000L; + + /** 2^52 - double numbers this large must be integral (no fraction) or NaN or Infinite */ + private static final double TWO_POWER_52 = 4503599627370496.0; + + /** Constant: {@value}. */ + private static final double F_1_3 = 1d / 3d; + /** Constant: {@value}. */ + private static final double F_1_5 = 1d / 5d; + /** Constant: {@value}. */ + private static final double F_1_7 = 1d / 7d; + /** Constant: {@value}. */ + private static final double F_1_9 = 1d / 9d; + /** Constant: {@value}. */ + private static final double F_1_11 = 1d / 11d; + /** Constant: {@value}. */ + private static final double F_1_13 = 1d / 13d; + /** Constant: {@value}. */ + private static final double F_1_15 = 1d / 15d; + /** Constant: {@value}. */ + private static final double F_1_17 = 1d / 17d; + /** Constant: {@value}. */ + private static final double F_3_4 = 3d / 4d; + /** Constant: {@value}. */ + private static final double F_15_16 = 15d / 16d; + /** Constant: {@value}. */ + private static final double F_13_14 = 13d / 14d; + /** Constant: {@value}. */ + private static final double F_11_12 = 11d / 12d; + /** Constant: {@value}. */ + private static final double F_9_10 = 9d / 10d; + /** Constant: {@value}. */ + private static final double F_7_8 = 7d / 8d; + /** Constant: {@value}. */ + private static final double F_5_6 = 5d / 6d; + /** Constant: {@value}. */ + private static final double F_1_2 = 1d / 2d; + /** Constant: {@value}. */ + private static final double F_1_4 = 1d / 4d; + + /** + * Private Constructor + */ + private AccurateMath() {} + + // Generic helper methods + + /** + * Get the high order bits from the mantissa. + * Equivalent to adding and subtracting HEX_40000 but also works for very large numbers + * + * @param d the value to split + * @return the high order part of the mantissa + */ + private static double doubleHighPart(double d) { + if (d > -Precision.SAFE_MIN && d < Precision.SAFE_MIN){ + return d; // These are un-normalised - don't try to convert + } + long xl = Double.doubleToRawLongBits(d); // can take raw bits because just gonna convert it back + xl &= MASK_30BITS; // Drop low order bits + return Double.longBitsToDouble(xl); + } + + /** Compute the square root of a number. + *

Note: this implementation currently delegates to {@link Math#sqrt} + * @param a number on which evaluation is done + * @return square root of a + */ + public static double sqrt(final double a) { + return Math.sqrt(a); + } + + /** Compute the hyperbolic cosine of a number. + * @param x number on which evaluation is done + * @return hyperbolic cosine of x + */ + public static double cosh(double x) { + if (Double.isNaN(x)) { + return x; + } + + // cosh[z] = (exp(z) + exp(-z))/2 + + // for numbers with magnitude 20 or so, + // exp(-z) can be ignored in comparison with exp(z) + + if (x > 20) { + if (x >= LOG_MAX_VALUE) { + // Avoid overflow (MATH-905). + final double t = exp(0.5 * x); + return (0.5 * t) * t; + } else { + return 0.5 * exp(x); + } + } else if (x < -20) { + if (x <= -LOG_MAX_VALUE) { + // Avoid overflow (MATH-905). + final double t = exp(-0.5 * x); + return (0.5 * t) * t; + } else { + return 0.5 * exp(-x); + } + } + + final double hiPrec[] = new double[2]; + if (x < 0.0) { + x = -x; + } + exp(x, 0.0, hiPrec); + + double ya = hiPrec[0] + hiPrec[1]; + double yb = -(ya - hiPrec[0] - hiPrec[1]); + + double temp = ya * HEX_40000000; + double yaa = ya + temp - temp; + double yab = ya - yaa; + + // recip = 1/y + double recip = 1.0/ya; + temp = recip * HEX_40000000; + double recipa = recip + temp - temp; + double recipb = recip - recipa; + + // Correct for rounding in division + recipb += (1.0 - yaa*recipa - yaa*recipb - yab*recipa - yab*recipb) * recip; + // Account for yb + recipb += -yb * recip * recip; + + // y = y + 1/y + temp = ya + recipa; + yb += -(temp - ya - recipa); + ya = temp; + temp = ya + recipb; + yb += -(temp - ya - recipb); + ya = temp; + + double result = ya + yb; + result *= 0.5; + return result; + } + + /** Compute the hyperbolic sine of a number. + * @param x number on which evaluation is done + * @return hyperbolic sine of x + */ + public static double sinh(double x) { + boolean negate = false; + if (Double.isNaN(x)) { + return x; + } + + // sinh[z] = (exp(z) - exp(-z) / 2 + + // for values of z larger than about 20, + // exp(-z) can be ignored in comparison with exp(z) + + if (x > 20) { + if (x >= LOG_MAX_VALUE) { + // Avoid overflow (MATH-905). + final double t = exp(0.5 * x); + return (0.5 * t) * t; + } else { + return 0.5 * exp(x); + } + } else if (x < -20) { + if (x <= -LOG_MAX_VALUE) { + // Avoid overflow (MATH-905). + final double t = exp(-0.5 * x); + return (-0.5 * t) * t; + } else { + return -0.5 * exp(-x); + } + } + + if (x == 0) { + return x; + } + + if (x < 0.0) { + x = -x; + negate = true; + } + + double result; + + if (x > 0.25) { + double hiPrec[] = new double[2]; + exp(x, 0.0, hiPrec); + + double ya = hiPrec[0] + hiPrec[1]; + double yb = -(ya - hiPrec[0] - hiPrec[1]); + + double temp = ya * HEX_40000000; + double yaa = ya + temp - temp; + double yab = ya - yaa; + + // recip = 1/y + double recip = 1.0/ya; + temp = recip * HEX_40000000; + double recipa = recip + temp - temp; + double recipb = recip - recipa; + + // Correct for rounding in division + recipb += (1.0 - yaa*recipa - yaa*recipb - yab*recipa - yab*recipb) * recip; + // Account for yb + recipb += -yb * recip * recip; + + recipa = -recipa; + recipb = -recipb; + + // y = y + 1/y + temp = ya + recipa; + yb += -(temp - ya - recipa); + ya = temp; + temp = ya + recipb; + yb += -(temp - ya - recipb); + ya = temp; + + result = ya + yb; + result *= 0.5; + } + else { + double hiPrec[] = new double[2]; + expm1(x, hiPrec); + + double ya = hiPrec[0] + hiPrec[1]; + double yb = -(ya - hiPrec[0] - hiPrec[1]); + + /* Compute expm1(-x) = -expm1(x) / (expm1(x) + 1) */ + double denom = 1.0 + ya; + double denomr = 1.0 / denom; + double denomb = -(denom - 1.0 - ya) + yb; + double ratio = ya * denomr; + double temp = ratio * HEX_40000000; + double ra = ratio + temp - temp; + double rb = ratio - ra; + + temp = denom * HEX_40000000; + double za = denom + temp - temp; + double zb = denom - za; + + rb += (ya - za*ra - za*rb - zb*ra - zb*rb) * denomr; + + // Adjust for yb + rb += yb*denomr; // numerator + rb += -ya * denomb * denomr * denomr; // denominator + + // y = y - 1/y + temp = ya + ra; + yb += -(temp - ya - ra); + ya = temp; + temp = ya + rb; + yb += -(temp - ya - rb); + ya = temp; + + result = ya + yb; + result *= 0.5; + } + + if (negate) { + result = -result; + } + + return result; + } + + /** Compute the hyperbolic tangent of a number. + * @param x number on which evaluation is done + * @return hyperbolic tangent of x + */ + public static double tanh(double x) { + boolean negate = false; + + if (Double.isNaN(x)) { + return x; + } + + // tanh[z] = sinh[z] / cosh[z] + // = (exp(z) - exp(-z)) / (exp(z) + exp(-z)) + // = (exp(2x) - 1) / (exp(2x) + 1) + + // for magnitude > 20, sinh[z] == cosh[z] in double precision + + if (x > 20.0) { + return 1.0; + } + + if (x < -20) { + return -1.0; + } + + if (x == 0) { + return x; + } + + if (x < 0.0) { + x = -x; + negate = true; + } + + double result; + if (x >= 0.5) { + double hiPrec[] = new double[2]; + // tanh(x) = (exp(2x) - 1) / (exp(2x) + 1) + exp(x*2.0, 0.0, hiPrec); + + double ya = hiPrec[0] + hiPrec[1]; + double yb = -(ya - hiPrec[0] - hiPrec[1]); + + /* Numerator */ + double na = -1.0 + ya; + double nb = -(na + 1.0 - ya); + double temp = na + yb; + nb += -(temp - na - yb); + na = temp; + + /* Denominator */ + double da = 1.0 + ya; + double db = -(da - 1.0 - ya); + temp = da + yb; + db += -(temp - da - yb); + da = temp; + + temp = da * HEX_40000000; + double daa = da + temp - temp; + double dab = da - daa; + + // ratio = na/da + double ratio = na/da; + temp = ratio * HEX_40000000; + double ratioa = ratio + temp - temp; + double ratiob = ratio - ratioa; + + // Correct for rounding in division + ratiob += (na - daa*ratioa - daa*ratiob - dab*ratioa - dab*ratiob) / da; + + // Account for nb + ratiob += nb / da; + // Account for db + ratiob += -db * na / da / da; + + result = ratioa + ratiob; + } + else { + double hiPrec[] = new double[2]; + // tanh(x) = expm1(2x) / (expm1(2x) + 2) + expm1(x*2.0, hiPrec); + + double ya = hiPrec[0] + hiPrec[1]; + double yb = -(ya - hiPrec[0] - hiPrec[1]); + + /* Numerator */ + double na = ya; + double nb = yb; + + /* Denominator */ + double da = 2.0 + ya; + double db = -(da - 2.0 - ya); + double temp = da + yb; + db += -(temp - da - yb); + da = temp; + + temp = da * HEX_40000000; + double daa = da + temp - temp; + double dab = da - daa; + + // ratio = na/da + double ratio = na/da; + temp = ratio * HEX_40000000; + double ratioa = ratio + temp - temp; + double ratiob = ratio - ratioa; + + // Correct for rounding in division + ratiob += (na - daa*ratioa - daa*ratiob - dab*ratioa - dab*ratiob) / da; + + // Account for nb + ratiob += nb / da; + // Account for db + ratiob += -db * na / da / da; + + result = ratioa + ratiob; + } + + if (negate) { + result = -result; + } + + return result; + } + + /** Compute the inverse hyperbolic cosine of a number. + * @param a number on which evaluation is done + * @return inverse hyperbolic cosine of a + */ + public static double acosh(final double a) { + return AccurateMath.log(a + AccurateMath.sqrt(a * a - 1)); + } + + /** Compute the inverse hyperbolic sine of a number. + * @param a number on which evaluation is done + * @return inverse hyperbolic sine of a + */ + public static double asinh(double a) { + boolean negative = false; + if (a < 0) { + negative = true; + a = -a; + } + + double absAsinh; + if (a > 0.167) { + absAsinh = AccurateMath.log(AccurateMath.sqrt(a * a + 1) + a); + } else { + final double a2 = a * a; + if (a > 0.097) { + absAsinh = a * (1 - a2 * (F_1_3 - a2 * (F_1_5 - a2 * (F_1_7 - a2 * (F_1_9 - a2 * (F_1_11 - a2 * (F_1_13 - a2 * (F_1_15 - a2 * F_1_17 * F_15_16) * F_13_14) * F_11_12) * F_9_10) * F_7_8) * F_5_6) * F_3_4) * F_1_2); + } else if (a > 0.036) { + absAsinh = a * (1 - a2 * (F_1_3 - a2 * (F_1_5 - a2 * (F_1_7 - a2 * (F_1_9 - a2 * (F_1_11 - a2 * F_1_13 * F_11_12) * F_9_10) * F_7_8) * F_5_6) * F_3_4) * F_1_2); + } else if (a > 0.0036) { + absAsinh = a * (1 - a2 * (F_1_3 - a2 * (F_1_5 - a2 * (F_1_7 - a2 * F_1_9 * F_7_8) * F_5_6) * F_3_4) * F_1_2); + } else { + absAsinh = a * (1 - a2 * (F_1_3 - a2 * F_1_5 * F_3_4) * F_1_2); + } + } + + return negative ? -absAsinh : absAsinh; + } + + /** Compute the inverse hyperbolic tangent of a number. + * @param a number on which evaluation is done + * @return inverse hyperbolic tangent of a + */ + public static double atanh(double a) { + boolean negative = false; + if (a < 0) { + negative = true; + a = -a; + } + + double absAtanh; + if (a > 0.15) { + absAtanh = 0.5 * AccurateMath.log((1 + a) / (1 - a)); + } else { + final double a2 = a * a; + if (a > 0.087) { + absAtanh = a * (1 + a2 * (F_1_3 + a2 * (F_1_5 + a2 * (F_1_7 + a2 * (F_1_9 + a2 * (F_1_11 + a2 * (F_1_13 + a2 * (F_1_15 + a2 * F_1_17)))))))); + } else if (a > 0.031) { + absAtanh = a * (1 + a2 * (F_1_3 + a2 * (F_1_5 + a2 * (F_1_7 + a2 * (F_1_9 + a2 * (F_1_11 + a2 * F_1_13)))))); + } else if (a > 0.003) { + absAtanh = a * (1 + a2 * (F_1_3 + a2 * (F_1_5 + a2 * (F_1_7 + a2 * F_1_9)))); + } else { + absAtanh = a * (1 + a2 * (F_1_3 + a2 * F_1_5)); + } + } + + return negative ? -absAtanh : absAtanh; + } + + /** Compute the signum of a number. + * The signum is -1 for negative numbers, +1 for positive numbers and 0 otherwise + * @param a number on which evaluation is done + * @return -1.0, -0.0, +0.0, +1.0 or NaN depending on sign of a + */ + public static double signum(final double a) { + return (a < 0.0) ? -1.0 : ((a > 0.0) ? 1.0 : a); // return +0.0/-0.0/NaN depending on a + } + + /** Compute the signum of a number. + * The signum is -1 for negative numbers, +1 for positive numbers and 0 otherwise + * @param a number on which evaluation is done + * @return -1.0, -0.0, +0.0, +1.0 or NaN depending on sign of a + */ + public static float signum(final float a) { + return (a < 0.0f) ? -1.0f : ((a > 0.0f) ? 1.0f : a); // return +0.0/-0.0/NaN depending on a + } + + /** Compute next number towards positive infinity. + * @param a number to which neighbor should be computed + * @return neighbor of a towards positive infinity + */ + public static double nextUp(final double a) { + return nextAfter(a, Double.POSITIVE_INFINITY); + } + + /** Compute next number towards positive infinity. + * @param a number to which neighbor should be computed + * @return neighbor of a towards positive infinity + */ + public static float nextUp(final float a) { + return nextAfter(a, Float.POSITIVE_INFINITY); + } + + /** Compute next number towards negative infinity. + * @param a number to which neighbor should be computed + * @return neighbor of a towards negative infinity + * @since 3.4 + */ + public static double nextDown(final double a) { + return nextAfter(a, Double.NEGATIVE_INFINITY); + } + + /** Compute next number towards negative infinity. + * @param a number to which neighbor should be computed + * @return neighbor of a towards negative infinity + * @since 3.4 + */ + public static float nextDown(final float a) { + return nextAfter(a, Float.NEGATIVE_INFINITY); + } + + /** Returns a pseudo-random number between 0.0 and 1.0. + *

Note: this implementation currently delegates to {@link Math#random} + * @return a random number between 0.0 and 1.0 + */ + public static double random() { + return Math.random(); + } + + /** + * Exponential function. + * + * Computes exp(x), function result is nearly rounded. It will be correctly + * rounded to the theoretical value for 99.9% of input values, otherwise it will + * have a 1 ULP error. + * + * Method: + * Lookup intVal = exp(int(x)) + * Lookup fracVal = exp(int(x-int(x) / 1024.0) * 1024.0 ); + * Compute z as the exponential of the remaining bits by a polynomial minus one + * exp(x) = intVal * fracVal * (1 + z) + * + * Accuracy: + * Calculation is done with 63 bits of precision, so result should be correctly + * rounded for 99.9% of input values, with less than 1 ULP error otherwise. + * + * @param x a double + * @return double ex + */ + public static double exp(double x) { + return exp(x, 0.0, null); + } + + /** + * Internal helper method for exponential function. + * @param x original argument of the exponential function + * @param extra extra bits of precision on input (To Be Confirmed) + * @param hiPrec extra bits of precision on output (To Be Confirmed) + * @return exp(x) + */ + private static double exp(double x, double extra, double[] hiPrec) { + double intPartA; + double intPartB; + int intVal = (int) x; + + /* Lookup exp(floor(x)). + * intPartA will have the upper 22 bits, intPartB will have the lower + * 52 bits. + */ + if (x < 0.0) { + + // We don't check against intVal here as conversion of large negative double values + // may be affected by a JIT bug. Subsequent comparisons can safely use intVal + if (x < -746d) { + if (hiPrec != null) { + hiPrec[0] = 0.0; + hiPrec[1] = 0.0; + } + return 0.0; + } + + if (intVal < -709) { + /* This will produce a subnormal output */ + final double result = exp(x+40.19140625, extra, hiPrec) / 285040095144011776.0; + if (hiPrec != null) { + hiPrec[0] /= 285040095144011776.0; + hiPrec[1] /= 285040095144011776.0; + } + return result; + } + + if (intVal == -709) { + /* exp(1.494140625) is nearly a machine number... */ + final double result = exp(x+1.494140625, extra, hiPrec) / 4.455505956692756620; + if (hiPrec != null) { + hiPrec[0] /= 4.455505956692756620; + hiPrec[1] /= 4.455505956692756620; + } + return result; + } + + intVal--; + + } else { + if (intVal > 709) { + if (hiPrec != null) { + hiPrec[0] = Double.POSITIVE_INFINITY; + hiPrec[1] = 0.0; + } + return Double.POSITIVE_INFINITY; + } + + } + + intPartA = ExpIntTable.EXP_INT_TABLE_A[EXP_INT_TABLE_MAX_INDEX+intVal]; + intPartB = ExpIntTable.EXP_INT_TABLE_B[EXP_INT_TABLE_MAX_INDEX+intVal]; + + /* Get the fractional part of x, find the greatest multiple of 2^-10 less than + * x and look up the exp function of it. + * fracPartA will have the upper 22 bits, fracPartB the lower 52 bits. + */ + final int intFrac = (int) ((x - intVal) * 1024.0); + final double fracPartA = ExpFracTable.EXP_FRAC_TABLE_A[intFrac]; + final double fracPartB = ExpFracTable.EXP_FRAC_TABLE_B[intFrac]; + + /* epsilon is the difference in x from the nearest multiple of 2^-10. It + * has a value in the range 0 <= epsilon < 2^-10. + * Do the subtraction from x as the last step to avoid possible loss of precision. + */ + final double epsilon = x - (intVal + intFrac / 1024.0); + + /* Compute z = exp(epsilon) - 1.0 via a minimax polynomial. z has + full double precision (52 bits). Since z < 2^-10, we will have + 62 bits of precision when combined with the constant 1. This will be + used in the last addition below to get proper rounding. */ + + /* Remez generated polynomial. Converges on the interval [0, 2^-10], error + is less than 0.5 ULP */ + double z = 0.04168701738764507; + z = z * epsilon + 0.1666666505023083; + z = z * epsilon + 0.5000000000042687; + z = z * epsilon + 1.0; + z = z * epsilon + -3.940510424527919E-20; + + /* Compute (intPartA+intPartB) * (fracPartA+fracPartB) by binomial + expansion. + tempA is exact since intPartA and intPartB only have 22 bits each. + tempB will have 52 bits of precision. + */ + double tempA = intPartA * fracPartA; + double tempB = intPartA * fracPartB + intPartB * fracPartA + intPartB * fracPartB; + + /* Compute the result. (1+z)(tempA+tempB). Order of operations is + important. For accuracy add by increasing size. tempA is exact and + much larger than the others. If there are extra bits specified from the + pow() function, use them. */ + final double tempC = tempB + tempA; + + // If tempC is positive infinite, the evaluation below could result in NaN, + // because z could be negative at the same time. + if (tempC == Double.POSITIVE_INFINITY) { + return Double.POSITIVE_INFINITY; + } + + final double result; + if (extra != 0.0) { + result = tempC*extra*z + tempC*extra + tempC*z + tempB + tempA; + } else { + result = tempC*z + tempB + tempA; + } + + if (hiPrec != null) { + // If requesting high precision + hiPrec[0] = tempA; + hiPrec[1] = tempC*extra*z + tempC*extra + tempC*z + tempB; + } + + return result; + } + + /** Compute exp(x) - 1 + * @param x number to compute shifted exponential + * @return exp(x) - 1 + */ + public static double expm1(double x) { + return expm1(x, null); + } + + /** Internal helper method for expm1 + * @param x number to compute shifted exponential + * @param hiPrecOut receive high precision result for -1.0 < x < 1.0 + * @return exp(x) - 1 + */ + private static double expm1(double x, double hiPrecOut[]) { + if (Double.isNaN(x) || x == 0.0) { // NaN or zero + return x; + } + + if (x <= -1.0 || x >= 1.0) { + // If not between +/- 1.0 + //return exp(x) - 1.0; + double hiPrec[] = new double[2]; + exp(x, 0.0, hiPrec); + if (x > 0.0) { + return -1.0 + hiPrec[0] + hiPrec[1]; + } else { + final double ra = -1.0 + hiPrec[0]; + double rb = -(ra + 1.0 - hiPrec[0]); + rb += hiPrec[1]; + return ra + rb; + } + } + + double baseA; + double baseB; + double epsilon; + boolean negative = false; + + if (x < 0.0) { + x = -x; + negative = true; + } + + { + int intFrac = (int) (x * 1024.0); + double tempA = ExpFracTable.EXP_FRAC_TABLE_A[intFrac] - 1.0; + double tempB = ExpFracTable.EXP_FRAC_TABLE_B[intFrac]; + + double temp = tempA + tempB; + tempB = -(temp - tempA - tempB); + tempA = temp; + + temp = tempA * HEX_40000000; + baseA = tempA + temp - temp; + baseB = tempB + (tempA - baseA); + + epsilon = x - intFrac/1024.0; + } + + + /* Compute expm1(epsilon) */ + double zb = 0.008336750013465571; + zb = zb * epsilon + 0.041666663879186654; + zb = zb * epsilon + 0.16666666666745392; + zb = zb * epsilon + 0.49999999999999994; + zb *= epsilon; + zb *= epsilon; + + double za = epsilon; + double temp = za + zb; + zb = -(temp - za - zb); + za = temp; + + temp = za * HEX_40000000; + temp = za + temp - temp; + zb += za - temp; + za = temp; + + /* Combine the parts. expm1(a+b) = expm1(a) + expm1(b) + expm1(a)*expm1(b) */ + double ya = za * baseA; + //double yb = za*baseB + zb*baseA + zb*baseB; + temp = ya + za * baseB; + double yb = -(temp - ya - za * baseB); + ya = temp; + + temp = ya + zb * baseA; + yb += -(temp - ya - zb * baseA); + ya = temp; + + temp = ya + zb * baseB; + yb += -(temp - ya - zb*baseB); + ya = temp; + + //ya = ya + za + baseA; + //yb = yb + zb + baseB; + temp = ya + baseA; + yb += -(temp - baseA - ya); + ya = temp; + + temp = ya + za; + //yb += (ya > za) ? -(temp - ya - za) : -(temp - za - ya); + yb += -(temp - ya - za); + ya = temp; + + temp = ya + baseB; + //yb += (ya > baseB) ? -(temp - ya - baseB) : -(temp - baseB - ya); + yb += -(temp - ya - baseB); + ya = temp; + + temp = ya + zb; + //yb += (ya > zb) ? -(temp - ya - zb) : -(temp - zb - ya); + yb += -(temp - ya - zb); + ya = temp; + + if (negative) { + /* Compute expm1(-x) = -expm1(x) / (expm1(x) + 1) */ + double denom = 1.0 + ya; + double denomr = 1.0 / denom; + double denomb = -(denom - 1.0 - ya) + yb; + double ratio = ya * denomr; + temp = ratio * HEX_40000000; + final double ra = ratio + temp - temp; + double rb = ratio - ra; + + temp = denom * HEX_40000000; + za = denom + temp - temp; + zb = denom - za; + + rb += (ya - za * ra - za * rb - zb * ra - zb * rb) * denomr; + + // f(x) = x/1+x + // Compute f'(x) + // Product rule: d(uv) = du*v + u*dv + // Chain rule: d(f(g(x)) = f'(g(x))*f(g'(x)) + // d(1/x) = -1/(x*x) + // d(1/1+x) = -1/( (1+x)^2) * 1 = -1/((1+x)*(1+x)) + // d(x/1+x) = -x/((1+x)(1+x)) + 1/1+x = 1 / ((1+x)(1+x)) + + // Adjust for yb + rb += yb * denomr; // numerator + rb += -ya * denomb * denomr * denomr; // denominator + + // negate + ya = -ra; + yb = -rb; + } + + if (hiPrecOut != null) { + hiPrecOut[0] = ya; + hiPrecOut[1] = yb; + } + + return ya + yb; + } + + /** + * Natural logarithm. + * + * @param x a double + * @return log(x) + */ + public static double log(final double x) { + return log(x, null); + } + + /** + * Internal helper method for natural logarithm function. + * @param x original argument of the natural logarithm function + * @param hiPrec extra bits of precision on output (To Be Confirmed) + * @return log(x) + */ + private static double log(final double x, final double[] hiPrec) { + if (x==0) { // Handle special case of +0/-0 + return Double.NEGATIVE_INFINITY; + } + long bits = Double.doubleToRawLongBits(x); + + /* Handle special cases of negative input, and NaN */ + if (((bits & 0x8000000000000000L) != 0 || Double.isNaN(x)) && x != 0.0) { + if (hiPrec != null) { + hiPrec[0] = Double.NaN; + } + + return Double.NaN; + } + + /* Handle special cases of Positive infinity. */ + if (x == Double.POSITIVE_INFINITY) { + if (hiPrec != null) { + hiPrec[0] = Double.POSITIVE_INFINITY; + } + + return Double.POSITIVE_INFINITY; + } + + /* Extract the exponent */ + int exp = (int)(bits >> 52)-1023; + + if ((bits & 0x7ff0000000000000L) == 0) { + // Subnormal! + if (x == 0) { + // Zero + if (hiPrec != null) { + hiPrec[0] = Double.NEGATIVE_INFINITY; + } + + return Double.NEGATIVE_INFINITY; + } + + /* Normalize the subnormal number. */ + bits <<= 1; + while ( (bits & 0x0010000000000000L) == 0) { + --exp; + bits <<= 1; + } + } + + + if ((exp == -1 || exp == 0) && x < 1.01 && x > 0.99 && hiPrec == null) { + /* The normal method doesn't work well in the range [0.99, 1.01], so call do a straight + polynomial expansion in higer precision. */ + + /* Compute x - 1.0 and split it */ + double xa = x - 1.0; + double xb = xa - x + 1.0; + double tmp = xa * HEX_40000000; + double aa = xa + tmp - tmp; + double ab = xa - aa; + xa = aa; + xb = ab; + + final double[] lnCoef_last = LN_QUICK_COEF[LN_QUICK_COEF.length - 1]; + double ya = lnCoef_last[0]; + double yb = lnCoef_last[1]; + + for (int i = LN_QUICK_COEF.length - 2; i >= 0; i--) { + /* Multiply a = y * x */ + aa = ya * xa; + ab = ya * xb + yb * xa + yb * xb; + /* split, so now y = a */ + tmp = aa * HEX_40000000; + ya = aa + tmp - tmp; + yb = aa - ya + ab; + + /* Add a = y + lnQuickCoef */ + final double[] lnCoef_i = LN_QUICK_COEF[i]; + aa = ya + lnCoef_i[0]; + ab = yb + lnCoef_i[1]; + /* Split y = a */ + tmp = aa * HEX_40000000; + ya = aa + tmp - tmp; + yb = aa - ya + ab; + } + + /* Multiply a = y * x */ + aa = ya * xa; + ab = ya * xb + yb * xa + yb * xb; + /* split, so now y = a */ + tmp = aa * HEX_40000000; + ya = aa + tmp - tmp; + yb = aa - ya + ab; + + return ya + yb; + } + + // lnm is a log of a number in the range of 1.0 - 2.0, so 0 <= lnm < ln(2) + final double[] lnm = lnMant.LN_MANT[(int)((bits & 0x000ffc0000000000L) >> 42)]; + + /* + double epsilon = x / Double.longBitsToDouble(bits & 0xfffffc0000000000L); + + epsilon -= 1.0; + */ + + // y is the most significant 10 bits of the mantissa + //double y = Double.longBitsToDouble(bits & 0xfffffc0000000000L); + //double epsilon = (x - y) / y; + final double epsilon = (bits & 0x3ffffffffffL) / (TWO_POWER_52 + (bits & 0x000ffc0000000000L)); + + double lnza = 0.0; + double lnzb = 0.0; + + if (hiPrec != null) { + /* split epsilon -> x */ + double tmp = epsilon * HEX_40000000; + double aa = epsilon + tmp - tmp; + double ab = epsilon - aa; + double xa = aa; + double xb = ab; + + /* Need a more accurate epsilon, so adjust the division. */ + final double numer = bits & 0x3ffffffffffL; + final double denom = TWO_POWER_52 + (bits & 0x000ffc0000000000L); + aa = numer - xa*denom - xb * denom; + xb += aa / denom; + + /* Remez polynomial evaluation */ + final double[] lnCoef_last = LN_HI_PREC_COEF[LN_HI_PREC_COEF.length-1]; + double ya = lnCoef_last[0]; + double yb = lnCoef_last[1]; + + for (int i = LN_HI_PREC_COEF.length - 2; i >= 0; i--) { + /* Multiply a = y * x */ + aa = ya * xa; + ab = ya * xb + yb * xa + yb * xb; + /* split, so now y = a */ + tmp = aa * HEX_40000000; + ya = aa + tmp - tmp; + yb = aa - ya + ab; + + /* Add a = y + lnHiPrecCoef */ + final double[] lnCoef_i = LN_HI_PREC_COEF[i]; + aa = ya + lnCoef_i[0]; + ab = yb + lnCoef_i[1]; + /* Split y = a */ + tmp = aa * HEX_40000000; + ya = aa + tmp - tmp; + yb = aa - ya + ab; + } + + /* Multiply a = y * x */ + aa = ya * xa; + ab = ya * xb + yb * xa + yb * xb; + + /* split, so now lnz = a */ + /* + tmp = aa * 1073741824.0; + lnza = aa + tmp - tmp; + lnzb = aa - lnza + ab; + */ + lnza = aa + ab; + lnzb = -(lnza - aa - ab); + } else { + /* High precision not required. Eval Remez polynomial + using standard double precision */ + lnza = -0.16624882440418567; + lnza = lnza * epsilon + 0.19999954120254515; + lnza = lnza * epsilon + -0.2499999997677497; + lnza = lnza * epsilon + 0.3333333333332802; + lnza = lnza * epsilon + -0.5; + lnza = lnza * epsilon + 1.0; + lnza *= epsilon; + } + + /* Relative sizes: + * lnzb [0, 2.33E-10] + * lnm[1] [0, 1.17E-7] + * ln2B*exp [0, 1.12E-4] + * lnza [0, 9.7E-4] + * lnm[0] [0, 0.692] + * ln2A*exp [0, 709] + */ + + /* Compute the following sum: + * lnzb + lnm[1] + ln2B*exp + lnza + lnm[0] + ln2A*exp; + */ + + //return lnzb + lnm[1] + ln2B*exp + lnza + lnm[0] + ln2A*exp; + double a = LN_2_A*exp; + double b = 0.0; + double c = a+lnm[0]; + double d = -(c-a-lnm[0]); + a = c; + b += d; + + c = a + lnza; + d = -(c - a - lnza); + a = c; + b += d; + + c = a + LN_2_B*exp; + d = -(c - a - LN_2_B*exp); + a = c; + b += d; + + c = a + lnm[1]; + d = -(c - a - lnm[1]); + a = c; + b += d; + + c = a + lnzb; + d = -(c - a - lnzb); + a = c; + b += d; + + if (hiPrec != null) { + hiPrec[0] = a; + hiPrec[1] = b; + } + + return a + b; + } + + /** + * Computes log(1 + x). + * + * @param x Number. + * @return {@code log(1 + x)}. + */ + public static double log1p(final double x) { + if (x == -1) { + return Double.NEGATIVE_INFINITY; + } + + if (x == Double.POSITIVE_INFINITY) { + return Double.POSITIVE_INFINITY; + } + + if (x > 1e-6 || + x < -1e-6) { + final double xpa = 1 + x; + final double xpb = -(xpa - 1 - x); + + final double[] hiPrec = new double[2]; + final double lores = log(xpa, hiPrec); + if (Double.isInfinite(lores)) { // Don't allow this to be converted to NaN + return lores; + } + + // Do a taylor series expansion around xpa: + // f(x+y) = f(x) + f'(x) y + f''(x)/2 y^2 + final double fx1 = xpb / xpa; + final double epsilon = 0.5 * fx1 + 1; + return epsilon * fx1 + hiPrec[1] + hiPrec[0]; + } else { + // Value is small |x| < 1e6, do a Taylor series centered on 1. + final double y = (x * F_1_3 - F_1_2) * x + 1; + return y * x; + } + } + + /** Compute the base 10 logarithm. + * @param x a number + * @return log10(x) + */ + public static double log10(final double x) { + final double hiPrec[] = new double[2]; + + final double lores = log(x, hiPrec); + if (Double.isInfinite(lores)){ // don't allow this to be converted to NaN + return lores; + } + + final double tmp = hiPrec[0] * HEX_40000000; + final double lna = hiPrec[0] + tmp - tmp; + final double lnb = hiPrec[0] - lna + hiPrec[1]; + + final double rln10a = 0.4342944622039795; + final double rln10b = 1.9699272335463627E-8; + + return rln10b * lnb + rln10b * lna + rln10a * lnb + rln10a * lna; + } + + /** + * Computes the + * logarithm in a given base. + * + * Returns {@code NaN} if either argument is negative. + * If {@code base} is 0 and {@code x} is positive, 0 is returned. + * If {@code base} is positive and {@code x} is 0, + * {@code Double.NEGATIVE_INFINITY} is returned. + * If both arguments are 0, the result is {@code NaN}. + * + * @param base Base of the logarithm, must be greater than 0. + * @param x Argument, must be greater than 0. + * @return the value of the logarithm, i.e. the number {@code y} such that + * basey = x. + * @since 3.0 + */ + public static double log(double base, double x) { + return log(x) / log(base); + } + + /** + * Power function. Compute x^y. + * + * @param x a double + * @param y a double + * @return double + */ + public static double pow(final double x, final double y) { + + if (y == 0) { + // y = -0 or y = +0 + return 1.0; + } else { + + final long yBits = Double.doubleToRawLongBits(y); + final int yRawExp = (int) ((yBits & MASK_DOUBLE_EXPONENT) >> 52); + final long yRawMantissa = yBits & MASK_DOUBLE_MANTISSA; + final long xBits = Double.doubleToRawLongBits(x); + final int xRawExp = (int) ((xBits & MASK_DOUBLE_EXPONENT) >> 52); + final long xRawMantissa = xBits & MASK_DOUBLE_MANTISSA; + + if (yRawExp > 1085) { + // y is either a very large integral value that does not fit in a long or it is a special number + + if ((yRawExp == 2047 && yRawMantissa != 0) || + (xRawExp == 2047 && xRawMantissa != 0)) { + // NaN + return Double.NaN; + } else if (xRawExp == 1023 && xRawMantissa == 0) { + // x = -1.0 or x = +1.0 + if (yRawExp == 2047) { + // y is infinite + return Double.NaN; + } else { + // y is a large even integer + return 1.0; + } + } else { + // the absolute value of x is either greater or smaller than 1.0 + + // if yRawExp == 2047 and mantissa is 0, y = -infinity or y = +infinity + // if 1085 < yRawExp < 2047, y is simply a large number, however, due to limited + // accuracy, at this magnitude it behaves just like infinity with regards to x + if ((y > 0) ^ (xRawExp < 1023)) { + // either y = +infinity (or large engouh) and abs(x) > 1.0 + // or y = -infinity (or large engouh) and abs(x) < 1.0 + return Double.POSITIVE_INFINITY; + } else { + // either y = +infinity (or large engouh) and abs(x) < 1.0 + // or y = -infinity (or large engouh) and abs(x) > 1.0 + return +0.0; + } + } + + } else { + // y is a regular non-zero number + + if (yRawExp >= 1023) { + // y may be an integral value, which should be handled specifically + final long yFullMantissa = IMPLICIT_HIGH_BIT | yRawMantissa; + if (yRawExp < 1075) { + // normal number with negative shift that may have a fractional part + final long integralMask = (-1L) << (1075 - yRawExp); + if ((yFullMantissa & integralMask) == yFullMantissa) { + // all fractional bits are 0, the number is really integral + final long l = yFullMantissa >> (1075 - yRawExp); + return AccurateMath.pow(x, (y < 0) ? -l : l); + } + } else { + // normal number with positive shift, always an integral value + // we know it fits in a primitive long because yRawExp > 1085 has been handled above + final long l = yFullMantissa << (yRawExp - 1075); + return AccurateMath.pow(x, (y < 0) ? -l : l); + } + } + + // y is a non-integral value + + if (x == 0) { + // x = -0 or x = +0 + // the integer powers have already been handled above + return y < 0 ? Double.POSITIVE_INFINITY : +0.0; + } else if (xRawExp == 2047) { + if (xRawMantissa == 0) { + // x = -infinity or x = +infinity + return (y < 0) ? +0.0 : Double.POSITIVE_INFINITY; + } else { + // NaN + return Double.NaN; + } + } else if (x < 0) { + // the integer powers have already been handled above + return Double.NaN; + } else { + + // this is the general case, for regular fractional numbers x and y + + // Split y into ya and yb such that y = ya+yb + final double tmp = y * HEX_40000000; + final double ya = (y + tmp) - tmp; + final double yb = y - ya; + + /* Compute ln(x) */ + final double lns[] = new double[2]; + final double lores = log(x, lns); + if (Double.isInfinite(lores)) { // don't allow this to be converted to NaN + return lores; + } + + double lna = lns[0]; + double lnb = lns[1]; + + /* resplit lns */ + final double tmp1 = lna * HEX_40000000; + final double tmp2 = (lna + tmp1) - tmp1; + lnb += lna - tmp2; + lna = tmp2; + + // y*ln(x) = (aa+ab) + final double aa = lna * ya; + final double ab = lna * yb + lnb * ya + lnb * yb; + + lna = aa+ab; + lnb = -(lna - aa - ab); + + double z = 1.0 / 120.0; + z = z * lnb + (1.0 / 24.0); + z = z * lnb + (1.0 / 6.0); + z = z * lnb + 0.5; + z = z * lnb + 1.0; + z *= lnb; + + final double result = exp(lna, z, null); + //result = result + result * z; + return result; + + } + } + + } + + } + + /** + * Raise a double to an int power. + * + * @param d Number to raise. + * @param e Exponent. + * @return de + * @since 3.1 + */ + public static double pow(double d, int e) { + return pow(d, (long) e); + } + + + /** + * Raise a double to a long power. + * + * @param d Number to raise. + * @param e Exponent. + * @return de + * @since 3.6 + */ + public static double pow(double d, long e) { + if (e == 0) { + return 1.0; + } else if (e > 0) { + return new Split(d).pow(e).full; + } else { + return new Split(d).reciprocal().pow(-e).full; + } + } + + /** Class operator on double numbers split into one 26 bits number and one 27 bits number. */ + private static class Split { + + /** Split version of NaN. */ + public static final Split NAN = new Split(Double.NaN, 0); + + /** Split version of positive infinity. */ + public static final Split POSITIVE_INFINITY = new Split(Double.POSITIVE_INFINITY, 0); + + /** Split version of negative infinity. */ + public static final Split NEGATIVE_INFINITY = new Split(Double.NEGATIVE_INFINITY, 0); + + /** Full number. */ + private final double full; + + /** High order bits. */ + private final double high; + + /** Low order bits. */ + private final double low; + + /** Simple constructor. + * @param x number to split + */ + Split(final double x) { + full = x; + high = Double.longBitsToDouble(Double.doubleToRawLongBits(x) & ((-1L) << 27)); + low = x - high; + } + + /** Simple constructor. + * @param high high order bits + * @param low low order bits + */ + Split(final double high, final double low) { + this(high == 0.0 ? (low == 0.0 && Double.doubleToRawLongBits(high) == Long.MIN_VALUE /* negative zero */ ? -0.0 : low) : high + low, high, low); + } + + /** Simple constructor. + * @param full full number + * @param high high order bits + * @param low low order bits + */ + Split(final double full, final double high, final double low) { + this.full = full; + this.high = high; + this.low = low; + } + + /** Multiply the instance by another one. + * @param b other instance to multiply by + * @return product + */ + public Split multiply(final Split b) { + // beware the following expressions must NOT be simplified, they rely on floating point arithmetic properties + final Split mulBasic = new Split(full * b.full); + final double mulError = low * b.low - (((mulBasic.full - high * b.high) - low * b.high) - high * b.low); + return new Split(mulBasic.high, mulBasic.low + mulError); + } + + /** Compute the reciprocal of the instance. + * @return reciprocal of the instance + */ + public Split reciprocal() { + + final double approximateInv = 1.0 / full; + final Split splitInv = new Split(approximateInv); + + // if 1.0/d were computed perfectly, remultiplying it by d should give 1.0 + // we want to estimate the error so we can fix the low order bits of approximateInvLow + // beware the following expressions must NOT be simplified, they rely on floating point arithmetic properties + final Split product = multiply(splitInv); + final double error = (product.high - 1) + product.low; + + // better accuracy estimate of reciprocal + return Double.isNaN(error) ? splitInv : new Split(splitInv.high, splitInv.low - error / full); + + } + + /** Computes this^e. + * @param e exponent (beware, here it MUST be > 0; the only exclusion is Long.MIN_VALUE) + * @return d^e, split in high and low bits + * @since 3.6 + */ + private Split pow(final long e) { + + // prepare result + Split result = new Split(1); + + // d^(2p) + Split d2p = new Split(full, high, low); + + for (long p = e; p != 0; p >>>= 1) { + + if ((p & 0x1) != 0) { + // accurate multiplication result = result * d^(2p) using Veltkamp TwoProduct algorithm + result = result.multiply(d2p); + } + + // accurate squaring d^(2(p+1)) = d^(2p) * d^(2p) using Veltkamp TwoProduct algorithm + d2p = d2p.multiply(d2p); + + } + + if (Double.isNaN(result.full)) { + if (Double.isNaN(full)) { + return Split.NAN; + } else { + // some intermediate numbers exceeded capacity, + // and the low order bits became NaN (because infinity - infinity = NaN) + if (AccurateMath.abs(full) < 1) { + return new Split(AccurateMath.copySign(0.0, full), 0.0); + } else if (full < 0 && (e & 0x1) == 1) { + return Split.NEGATIVE_INFINITY; + } else { + return Split.POSITIVE_INFINITY; + } + } + } else { + return result; + } + + } + + } + + /** + * Computes sin(x) - x, where |x| < 1/16. + * Use a Remez polynomial approximation. + * @param x a number smaller than 1/16 + * @return sin(x) - x + */ + private static double polySine(final double x) + { + double x2 = x*x; + + double p = 2.7553817452272217E-6; + p = p * x2 + -1.9841269659586505E-4; + p = p * x2 + 0.008333333333329196; + p = p * x2 + -0.16666666666666666; + //p *= x2; + //p *= x; + p = p * x2 * x; + + return p; + } + + /** + * Computes cos(x) - 1, where |x| < 1/16. + * Use a Remez polynomial approximation. + * @param x a number smaller than 1/16 + * @return cos(x) - 1 + */ + private static double polyCosine(double x) { + double x2 = x*x; + + double p = 2.479773539153719E-5; + p = p * x2 + -0.0013888888689039883; + p = p * x2 + 0.041666666666621166; + p = p * x2 + -0.49999999999999994; + p *= x2; + + return p; + } + + /** + * Compute sine over the first quadrant (0 < x < pi/2). + * Use combination of table lookup and rational polynomial expansion. + * @param xa number from which sine is requested + * @param xb extra bits for x (may be 0.0) + * @return sin(xa + xb) + */ + private static double sinQ(double xa, double xb) { + int idx = (int) ((xa * 8.0) + 0.5); + final double epsilon = xa - EIGHTHS[idx]; //idx*0.125; + + // Table lookups + final double sintA = SINE_TABLE_A[idx]; + final double sintB = SINE_TABLE_B[idx]; + final double costA = COSINE_TABLE_A[idx]; + final double costB = COSINE_TABLE_B[idx]; + + // Polynomial eval of sin(epsilon), cos(epsilon) + double sinEpsA = epsilon; + double sinEpsB = polySine(epsilon); + final double cosEpsA = 1.0; + final double cosEpsB = polyCosine(epsilon); + + // Split epsilon xa + xb = x + final double temp = sinEpsA * HEX_40000000; + double temp2 = (sinEpsA + temp) - temp; + sinEpsB += sinEpsA - temp2; + sinEpsA = temp2; + + /* Compute sin(x) by angle addition formula */ + double result; + + /* Compute the following sum: + * + * result = sintA + costA*sinEpsA + sintA*cosEpsB + costA*sinEpsB + + * sintB + costB*sinEpsA + sintB*cosEpsB + costB*sinEpsB; + * + * Ranges of elements + * + * xxxtA 0 PI/2 + * xxxtB -1.5e-9 1.5e-9 + * sinEpsA -0.0625 0.0625 + * sinEpsB -6e-11 6e-11 + * cosEpsA 1.0 + * cosEpsB 0 -0.0625 + * + */ + + //result = sintA + costA*sinEpsA + sintA*cosEpsB + costA*sinEpsB + + // sintB + costB*sinEpsA + sintB*cosEpsB + costB*sinEpsB; + + //result = sintA + sintA*cosEpsB + sintB + sintB * cosEpsB; + //result += costA*sinEpsA + costA*sinEpsB + costB*sinEpsA + costB * sinEpsB; + double a = 0; + double b = 0; + + double t = sintA; + double c = a + t; + double d = -(c - a - t); + a = c; + b += d; + + t = costA * sinEpsA; + c = a + t; + d = -(c - a - t); + a = c; + b += d; + + b = b + sintA * cosEpsB + costA * sinEpsB; + /* + t = sintA*cosEpsB; + c = a + t; + d = -(c - a - t); + a = c; + b = b + d; + + t = costA*sinEpsB; + c = a + t; + d = -(c - a - t); + a = c; + b = b + d; + */ + + b = b + sintB + costB * sinEpsA + sintB * cosEpsB + costB * sinEpsB; + /* + t = sintB; + c = a + t; + d = -(c - a - t); + a = c; + b = b + d; + + t = costB*sinEpsA; + c = a + t; + d = -(c - a - t); + a = c; + b = b + d; + + t = sintB*cosEpsB; + c = a + t; + d = -(c - a - t); + a = c; + b = b + d; + + t = costB*sinEpsB; + c = a + t; + d = -(c - a - t); + a = c; + b = b + d; + */ + + if (xb != 0.0) { + t = ((costA + costB) * (cosEpsA + cosEpsB) - + (sintA + sintB) * (sinEpsA + sinEpsB)) * xb; // approximate cosine*xb + c = a + t; + d = -(c - a - t); + a = c; + b += d; + } + + result = a + b; + + return result; + } + + /** + * Compute cosine in the first quadrant by subtracting input from PI/2 and + * then calling sinQ. This is more accurate as the input approaches PI/2. + * @param xa number from which cosine is requested + * @param xb extra bits for x (may be 0.0) + * @return cos(xa + xb) + */ + private static double cosQ(double xa, double xb) { + final double pi2a = 1.5707963267948966; + final double pi2b = 6.123233995736766E-17; + + final double a = pi2a - xa; + double b = -(a - pi2a + xa); + b += pi2b - xb; + + return sinQ(a, b); + } + + /** + * Compute tangent (or cotangent) over the first quadrant. 0 < x < pi/2 + * Use combination of table lookup and rational polynomial expansion. + * @param xa number from which sine is requested + * @param xb extra bits for x (may be 0.0) + * @param cotanFlag if true, compute the cotangent instead of the tangent + * @return tan(xa+xb) (or cotangent, depending on cotanFlag) + */ + private static double tanQ(double xa, double xb, boolean cotanFlag) { + + int idx = (int) ((xa * 8.0) + 0.5); + final double epsilon = xa - EIGHTHS[idx]; //idx*0.125; + + // Table lookups + final double sintA = SINE_TABLE_A[idx]; + final double sintB = SINE_TABLE_B[idx]; + final double costA = COSINE_TABLE_A[idx]; + final double costB = COSINE_TABLE_B[idx]; + + // Polynomial eval of sin(epsilon), cos(epsilon) + double sinEpsA = epsilon; + double sinEpsB = polySine(epsilon); + final double cosEpsA = 1.0; + final double cosEpsB = polyCosine(epsilon); + + // Split epsilon xa + xb = x + double temp = sinEpsA * HEX_40000000; + double temp2 = (sinEpsA + temp) - temp; + sinEpsB += sinEpsA - temp2; + sinEpsA = temp2; + + /* Compute sin(x) by angle addition formula */ + + /* Compute the following sum: + * + * result = sintA + costA*sinEpsA + sintA*cosEpsB + costA*sinEpsB + + * sintB + costB*sinEpsA + sintB*cosEpsB + costB*sinEpsB; + * + * Ranges of elements + * + * xxxtA 0 PI/2 + * xxxtB -1.5e-9 1.5e-9 + * sinEpsA -0.0625 0.0625 + * sinEpsB -6e-11 6e-11 + * cosEpsA 1.0 + * cosEpsB 0 -0.0625 + * + */ + + //result = sintA + costA*sinEpsA + sintA*cosEpsB + costA*sinEpsB + + // sintB + costB*sinEpsA + sintB*cosEpsB + costB*sinEpsB; + + //result = sintA + sintA*cosEpsB + sintB + sintB * cosEpsB; + //result += costA*sinEpsA + costA*sinEpsB + costB*sinEpsA + costB * sinEpsB; + double a = 0; + double b = 0; + + // Compute sine + double t = sintA; + double c = a + t; + double d = -(c - a - t); + a = c; + b += d; + + t = costA*sinEpsA; + c = a + t; + d = -(c - a - t); + a = c; + b += d; + + b += sintA*cosEpsB + costA*sinEpsB; + b += sintB + costB*sinEpsA + sintB*cosEpsB + costB*sinEpsB; + + double sina = a + b; + double sinb = -(sina - a - b); + + // Compute cosine + + a = b = c = d = 0.0; + + t = costA*cosEpsA; + c = a + t; + d = -(c - a - t); + a = c; + b += d; + + t = -sintA*sinEpsA; + c = a + t; + d = -(c - a - t); + a = c; + b += d; + + b += costB*cosEpsA + costA*cosEpsB + costB*cosEpsB; + b -= sintB*sinEpsA + sintA*sinEpsB + sintB*sinEpsB; + + double cosa = a + b; + double cosb = -(cosa - a - b); + + if (cotanFlag) { + double tmp; + tmp = cosa; cosa = sina; sina = tmp; + tmp = cosb; cosb = sinb; sinb = tmp; + } + + + /* estimate and correct, compute 1.0/(cosa+cosb) */ + /* + double est = (sina+sinb)/(cosa+cosb); + double err = (sina - cosa*est) + (sinb - cosb*est); + est += err/(cosa+cosb); + err = (sina - cosa*est) + (sinb - cosb*est); + */ + + // f(x) = 1/x, f'(x) = -1/x^2 + + double est = sina/cosa; + + /* Split the estimate to get more accurate read on division rounding */ + temp = est * HEX_40000000; + double esta = (est + temp) - temp; + double estb = est - esta; + + temp = cosa * HEX_40000000; + double cosaa = (cosa + temp) - temp; + double cosab = cosa - cosaa; + + //double err = (sina - est*cosa)/cosa; // Correction for division rounding + double err = (sina - esta*cosaa - esta*cosab - estb*cosaa - estb*cosab)/cosa; // Correction for division rounding + err += sinb/cosa; // Change in est due to sinb + err += -sina * cosb / cosa / cosa; // Change in est due to cosb + + if (xb != 0.0) { + // tan' = 1 + tan^2 cot' = -(1 + cot^2) + // Approximate impact of xb + double xbadj = xb + est*est*xb; + if (cotanFlag) { + xbadj = -xbadj; + } + + err += xbadj; + } + + return est+err; + } + + /** Reduce the input argument using the Payne and Hanek method. + * This is good for all inputs 0.0 < x < inf + * Output is remainder after dividing by PI/2 + * The result array should contain 3 numbers. + * result[0] is the integer portion, so mod 4 this gives the quadrant. + * result[1] is the upper bits of the remainder + * result[2] is the lower bits of the remainder + * + * @param x number to reduce + * @param result placeholder where to put the result + */ + private static void reducePayneHanek(double x, double result[]) + { + /* Convert input double to bits */ + long inbits = Double.doubleToRawLongBits(x); + int exponent = (int) ((inbits >> 52) & 0x7ff) - 1023; + + /* Convert to fixed point representation */ + inbits &= 0x000fffffffffffffL; + inbits |= 0x0010000000000000L; + + /* Normalize input to be between 0.5 and 1.0 */ + exponent++; + inbits <<= 11; + + /* Based on the exponent, get a shifted copy of recip2pi */ + long shpi0; + long shpiA; + long shpiB; + int idx = exponent >> 6; + int shift = exponent - (idx << 6); + + if (shift != 0) { + shpi0 = (idx == 0) ? 0 : (RECIP_2PI[idx-1] << shift); + shpi0 |= RECIP_2PI[idx] >>> (64-shift); + shpiA = (RECIP_2PI[idx] << shift) | (RECIP_2PI[idx+1] >>> (64-shift)); + shpiB = (RECIP_2PI[idx+1] << shift) | (RECIP_2PI[idx+2] >>> (64-shift)); + } else { + shpi0 = (idx == 0) ? 0 : RECIP_2PI[idx-1]; + shpiA = RECIP_2PI[idx]; + shpiB = RECIP_2PI[idx+1]; + } + + /* Multiply input by shpiA */ + long a = inbits >>> 32; + long b = inbits & 0xffffffffL; + + long c = shpiA >>> 32; + long d = shpiA & 0xffffffffL; + + long ac = a * c; + long bd = b * d; + long bc = b * c; + long ad = a * d; + + long prodB = bd + (ad << 32); + long prodA = ac + (ad >>> 32); + + boolean bita = (bd & 0x8000000000000000L) != 0; + boolean bitb = (ad & 0x80000000L ) != 0; + boolean bitsum = (prodB & 0x8000000000000000L) != 0; + + /* Carry */ + if ( (bita && bitb) || + ((bita || bitb) && !bitsum) ) { + prodA++; + } + + bita = (prodB & 0x8000000000000000L) != 0; + bitb = (bc & 0x80000000L ) != 0; + + prodB += bc << 32; + prodA += bc >>> 32; + + bitsum = (prodB & 0x8000000000000000L) != 0; + + /* Carry */ + if ( (bita && bitb) || + ((bita || bitb) && !bitsum) ) { + prodA++; + } + + /* Multiply input by shpiB */ + c = shpiB >>> 32; + d = shpiB & 0xffffffffL; + ac = a * c; + bc = b * c; + ad = a * d; + + /* Collect terms */ + ac += (bc + ad) >>> 32; + + bita = (prodB & 0x8000000000000000L) != 0; + bitb = (ac & 0x8000000000000000L ) != 0; + prodB += ac; + bitsum = (prodB & 0x8000000000000000L) != 0; + /* Carry */ + if ( (bita && bitb) || + ((bita || bitb) && !bitsum) ) { + prodA++; + } + + /* Multiply by shpi0 */ + c = shpi0 >>> 32; + d = shpi0 & 0xffffffffL; + + bd = b * d; + bc = b * c; + ad = a * d; + + prodA += bd + ((bc + ad) << 32); + + /* + * prodA, prodB now contain the remainder as a fraction of PI. We want this as a fraction of + * PI/2, so use the following steps: + * 1.) multiply by 4. + * 2.) do a fixed point muliply by PI/4. + * 3.) Convert to floating point. + * 4.) Multiply by 2 + */ + + /* This identifies the quadrant */ + int intPart = (int)(prodA >>> 62); + + /* Multiply by 4 */ + prodA <<= 2; + prodA |= prodB >>> 62; + prodB <<= 2; + + /* Multiply by PI/4 */ + a = prodA >>> 32; + b = prodA & 0xffffffffL; + + c = PI_O_4_BITS[0] >>> 32; + d = PI_O_4_BITS[0] & 0xffffffffL; + + ac = a * c; + bd = b * d; + bc = b * c; + ad = a * d; + + long prod2B = bd + (ad << 32); + long prod2A = ac + (ad >>> 32); + + bita = (bd & 0x8000000000000000L) != 0; + bitb = (ad & 0x80000000L ) != 0; + bitsum = (prod2B & 0x8000000000000000L) != 0; + + /* Carry */ + if ( (bita && bitb) || + ((bita || bitb) && !bitsum) ) { + prod2A++; + } + + bita = (prod2B & 0x8000000000000000L) != 0; + bitb = (bc & 0x80000000L ) != 0; + + prod2B += bc << 32; + prod2A += bc >>> 32; + + bitsum = (prod2B & 0x8000000000000000L) != 0; + + /* Carry */ + if ( (bita && bitb) || + ((bita || bitb) && !bitsum) ) { + prod2A++; + } + + /* Multiply input by pio4bits[1] */ + c = PI_O_4_BITS[1] >>> 32; + d = PI_O_4_BITS[1] & 0xffffffffL; + ac = a * c; + bc = b * c; + ad = a * d; + + /* Collect terms */ + ac += (bc + ad) >>> 32; + + bita = (prod2B & 0x8000000000000000L) != 0; + bitb = (ac & 0x8000000000000000L ) != 0; + prod2B += ac; + bitsum = (prod2B & 0x8000000000000000L) != 0; + /* Carry */ + if ( (bita && bitb) || + ((bita || bitb) && !bitsum) ) { + prod2A++; + } + + /* Multiply inputB by pio4bits[0] */ + a = prodB >>> 32; + b = prodB & 0xffffffffL; + c = PI_O_4_BITS[0] >>> 32; + d = PI_O_4_BITS[0] & 0xffffffffL; + ac = a * c; + bc = b * c; + ad = a * d; + + /* Collect terms */ + ac += (bc + ad) >>> 32; + + bita = (prod2B & 0x8000000000000000L) != 0; + bitb = (ac & 0x8000000000000000L ) != 0; + prod2B += ac; + bitsum = (prod2B & 0x8000000000000000L) != 0; + /* Carry */ + if ( (bita && bitb) || + ((bita || bitb) && !bitsum) ) { + prod2A++; + } + + /* Convert to double */ + double tmpA = (prod2A >>> 12) / TWO_POWER_52; // High order 52 bits + double tmpB = (((prod2A & 0xfffL) << 40) + (prod2B >>> 24)) / TWO_POWER_52 / TWO_POWER_52; // Low bits + + double sumA = tmpA + tmpB; + double sumB = -(sumA - tmpA - tmpB); + + /* Multiply by PI/2 and return */ + result[0] = intPart; + result[1] = sumA * 2.0; + result[2] = sumB * 2.0; + } + + /** + * Sine function. + * + * @param x Argument. + * @return sin(x) + */ + public static double sin(double x) { + boolean negative = false; + int quadrant = 0; + double xa; + double xb = 0.0; + + /* Take absolute value of the input */ + xa = x; + if (x < 0) { + negative = true; + xa = -xa; + } + + /* Check for zero and negative zero */ + if (xa == 0.0) { + long bits = Double.doubleToRawLongBits(x); + if (bits < 0) { + return -0.0; + } + return 0.0; + } + + if (xa != xa || xa == Double.POSITIVE_INFINITY) { + return Double.NaN; + } + + /* Perform any argument reduction */ + if (xa > 3294198.0) { + // PI * (2**20) + // Argument too big for CodyWaite reduction. Must use + // PayneHanek. + double reduceResults[] = new double[3]; + reducePayneHanek(xa, reduceResults); + quadrant = ((int) reduceResults[0]) & 3; + xa = reduceResults[1]; + xb = reduceResults[2]; + } else if (xa > 1.5707963267948966) { + final CodyWaite cw = new CodyWaite(xa); + quadrant = cw.getK() & 3; + xa = cw.getRemA(); + xb = cw.getRemB(); + } + + if (negative) { + quadrant ^= 2; // Flip bit 1 + } + + switch (quadrant) { + case 0: + return sinQ(xa, xb); + case 1: + return cosQ(xa, xb); + case 2: + return -sinQ(xa, xb); + case 3: + return -cosQ(xa, xb); + default: + return Double.NaN; + } + } + + /** + * Cosine function. + * + * @param x Argument. + * @return cos(x) + */ + public static double cos(double x) { + int quadrant = 0; + + /* Take absolute value of the input */ + double xa = x; + if (x < 0) { + xa = -xa; + } + + if (xa != xa || xa == Double.POSITIVE_INFINITY) { + return Double.NaN; + } + + /* Perform any argument reduction */ + double xb = 0; + if (xa > 3294198.0) { + // PI * (2**20) + // Argument too big for CodyWaite reduction. Must use + // PayneHanek. + double reduceResults[] = new double[3]; + reducePayneHanek(xa, reduceResults); + quadrant = ((int) reduceResults[0]) & 3; + xa = reduceResults[1]; + xb = reduceResults[2]; + } else if (xa > 1.5707963267948966) { + final CodyWaite cw = new CodyWaite(xa); + quadrant = cw.getK() & 3; + xa = cw.getRemA(); + xb = cw.getRemB(); + } + + //if (negative) + // quadrant = (quadrant + 2) % 4; + + switch (quadrant) { + case 0: + return cosQ(xa, xb); + case 1: + return -sinQ(xa, xb); + case 2: + return -cosQ(xa, xb); + case 3: + return sinQ(xa, xb); + default: + return Double.NaN; + } + } + + /** + * Tangent function. + * + * @param x Argument. + * @return tan(x) + */ + public static double tan(double x) { + boolean negative = false; + int quadrant = 0; + + /* Take absolute value of the input */ + double xa = x; + if (x < 0) { + negative = true; + xa = -xa; + } + + /* Check for zero and negative zero */ + if (xa == 0.0) { + long bits = Double.doubleToRawLongBits(x); + if (bits < 0) { + return -0.0; + } + return 0.0; + } + + if (xa != xa || xa == Double.POSITIVE_INFINITY) { + return Double.NaN; + } + + /* Perform any argument reduction */ + double xb = 0; + if (xa > 3294198.0) { + // PI * (2**20) + // Argument too big for CodyWaite reduction. Must use + // PayneHanek. + double reduceResults[] = new double[3]; + reducePayneHanek(xa, reduceResults); + quadrant = ((int) reduceResults[0]) & 3; + xa = reduceResults[1]; + xb = reduceResults[2]; + } else if (xa > 1.5707963267948966) { + final CodyWaite cw = new CodyWaite(xa); + quadrant = cw.getK() & 3; + xa = cw.getRemA(); + xb = cw.getRemB(); + } + + if (xa > 1.5) { + // Accuracy suffers between 1.5 and PI/2 + final double pi2a = 1.5707963267948966; + final double pi2b = 6.123233995736766E-17; + + final double a = pi2a - xa; + double b = -(a - pi2a + xa); + b += pi2b - xb; + + xa = a + b; + xb = -(xa - a - b); + quadrant ^= 1; + negative ^= true; + } + + double result; + if ((quadrant & 1) == 0) { + result = tanQ(xa, xb, false); + } else { + result = -tanQ(xa, xb, true); + } + + if (negative) { + result = -result; + } + + return result; + } + + /** + * Arctangent function + * @param x a number + * @return atan(x) + */ + public static double atan(double x) { + return atan(x, 0.0, false); + } + + /** Internal helper function to compute arctangent. + * @param xa number from which arctangent is requested + * @param xb extra bits for x (may be 0.0) + * @param leftPlane if true, result angle must be put in the left half plane + * @return atan(xa + xb) (or angle shifted by {@code PI} if leftPlane is true) + */ + private static double atan(double xa, double xb, boolean leftPlane) { + if (xa == 0.0) { // Matches +/- 0.0; return correct sign + return leftPlane ? copySign(Math.PI, xa) : xa; + } + + final boolean negate; + if (xa < 0) { + // negative + xa = -xa; + xb = -xb; + negate = true; + } else { + negate = false; + } + + if (xa > 1.633123935319537E16) { // Very large input + return (negate ^ leftPlane) ? (-Math.PI * F_1_2) : (Math.PI * F_1_2); + } + + /* Estimate the closest tabulated arctan value, compute eps = xa-tangentTable */ + final int idx; + if (xa < 1) { + idx = (int) (((-1.7168146928204136 * xa * xa + 8.0) * xa) + 0.5); + } else { + final double oneOverXa = 1 / xa; + idx = (int) (-((-1.7168146928204136 * oneOverXa * oneOverXa + 8.0) * oneOverXa) + 13.07); + } + + final double ttA = TANGENT_TABLE_A[idx]; + final double ttB = TANGENT_TABLE_B[idx]; + + double epsA = xa - ttA; + double epsB = -(epsA - xa + ttA); + epsB += xb - ttB; + + double temp = epsA + epsB; + epsB = -(temp - epsA - epsB); + epsA = temp; + + /* Compute eps = eps / (1.0 + xa*tangent) */ + temp = xa * HEX_40000000; + double ya = xa + temp - temp; + double yb = xb + xa - ya; + xa = ya; + xb += yb; + + //if (idx > 8 || idx == 0) + if (idx == 0) { + /* If the slope of the arctan is gentle enough (< 0.45), this approximation will suffice */ + //double denom = 1.0 / (1.0 + xa*tangentTableA[idx] + xb*tangentTableA[idx] + xa*tangentTableB[idx] + xb*tangentTableB[idx]); + final double denom = 1d / (1d + (xa + xb) * (ttA + ttB)); + //double denom = 1.0 / (1.0 + xa*tangentTableA[idx]); + ya = epsA * denom; + yb = epsB * denom; + } else { + double temp2 = xa * ttA; + double za = 1d + temp2; + double zb = -(za - 1d - temp2); + temp2 = xb * ttA + xa * ttB; + temp = za + temp2; + zb += -(temp - za - temp2); + za = temp; + + zb += xb * ttB; + ya = epsA / za; + + temp = ya * HEX_40000000; + final double yaa = (ya + temp) - temp; + final double yab = ya - yaa; + + temp = za * HEX_40000000; + final double zaa = (za + temp) - temp; + final double zab = za - zaa; + + /* Correct for rounding in division */ + yb = (epsA - yaa * zaa - yaa * zab - yab * zaa - yab * zab) / za; + + yb += -epsA * zb / za / za; + yb += epsB / za; + } + + + epsA = ya; + epsB = yb; + + /* Evaluate polynomial */ + final double epsA2 = epsA * epsA; + + /* + yb = -0.09001346640161823; + yb = yb * epsA2 + 0.11110718400605211; + yb = yb * epsA2 + -0.1428571349122913; + yb = yb * epsA2 + 0.19999999999273194; + yb = yb * epsA2 + -0.33333333333333093; + yb = yb * epsA2 * epsA; + */ + + yb = 0.07490822288864472; + yb = yb * epsA2 - 0.09088450866185192; + yb = yb * epsA2 + 0.11111095942313305; + yb = yb * epsA2 - 0.1428571423679182; + yb = yb * epsA2 + 0.19999999999923582; + yb = yb * epsA2 - 0.33333333333333287; + yb = yb * epsA2 * epsA; + + + ya = epsA; + + temp = ya + yb; + yb = -(temp - ya - yb); + ya = temp; + + /* Add in effect of epsB. atan'(x) = 1/(1+x^2) */ + yb += epsB / (1d + epsA * epsA); + + final double eighths = EIGHTHS[idx]; + + //result = yb + eighths[idx] + ya; + double za = eighths + ya; + double zb = -(za - eighths - ya); + temp = za + yb; + zb += -(temp - za - yb); + za = temp; + + double result = za + zb; + + if (leftPlane) { + // Result is in the left plane + final double resultb = -(result - za - zb); + final double pia = 1.5707963267948966 * 2; + final double pib = 6.123233995736766E-17 * 2; + + za = pia - result; + zb = -(za - pia + result); + zb += pib - resultb; + + result = za + zb; + } + + + if (negate ^ leftPlane) { + result = -result; + } + + return result; + } + + /** + * Two arguments arctangent function + * @param y ordinate + * @param x abscissa + * @return phase angle of point (x,y) between {@code -PI} and {@code PI} + */ + public static double atan2(double y, double x) { + if (Double.isNaN(x) || Double.isNaN(y)) { + return Double.NaN; + } + + if (y == 0) { + final double result = x * y; + final double invx = 1d / x; + final double invy = 1d / y; + + if (invx == 0) { // X is infinite + if (x > 0) { + return y; // return +/- 0.0 + } else { + return copySign(Math.PI, y); + } + } + + if (x < 0 || invx < 0) { + if (y < 0 || invy < 0) { + return -Math.PI; + } else { + return Math.PI; + } + } else { + return result; + } + } + + // y cannot now be zero + + if (y == Double.POSITIVE_INFINITY) { + if (x == Double.POSITIVE_INFINITY) { + return Math.PI * F_1_4; + } + + if (x == Double.NEGATIVE_INFINITY) { + return Math.PI * F_3_4; + } + + return Math.PI * F_1_2; + } + + if (y == Double.NEGATIVE_INFINITY) { + if (x == Double.POSITIVE_INFINITY) { + return -Math.PI * F_1_4; + } + + if (x == Double.NEGATIVE_INFINITY) { + return -Math.PI * F_3_4; + } + + return -Math.PI * F_1_2; + } + + if (x == Double.POSITIVE_INFINITY) { + if (y > 0 || 1 / y > 0) { + return 0d; + } + + if (y < 0 || 1 / y < 0) { + return -0d; + } + } + + if (x == Double.NEGATIVE_INFINITY) + { + if (y > 0.0 || 1 / y > 0.0) { + return Math.PI; + } + + if (y < 0 || 1 / y < 0) { + return -Math.PI; + } + } + + // Neither y nor x can be infinite or NAN here + + if (x == 0) { + if (y > 0 || 1 / y > 0) { + return Math.PI * F_1_2; + } + + if (y < 0 || 1 / y < 0) { + return -Math.PI * F_1_2; + } + } + + // Compute ratio r = y/x + final double r = y / x; + if (Double.isInfinite(r)) { // bypass calculations that can create NaN + return atan(r, 0, x < 0); + } + + double ra = doubleHighPart(r); + double rb = r - ra; + + // Split x + final double xa = doubleHighPart(x); + final double xb = x - xa; + + rb += (y - ra * xa - ra * xb - rb * xa - rb * xb) / x; + + final double temp = ra + rb; + rb = -(temp - ra - rb); + ra = temp; + + if (ra == 0) { // Fix up the sign so atan works correctly + ra = copySign(0d, y); + } + + // Call atan + final double result = atan(ra, rb, x < 0); + + return result; + } + + /** Compute the arc sine of a number. + * @param x number on which evaluation is done + * @return arc sine of x + */ + public static double asin(double x) { + if (Double.isNaN(x)) { + return Double.NaN; + } + + if (x > 1.0 || x < -1.0) { + return Double.NaN; + } + + if (x == 1.0) { + return Math.PI/2.0; + } + + if (x == -1.0) { + return -Math.PI/2.0; + } + + if (x == 0.0) { // Matches +/- 0.0; return correct sign + return x; + } + + /* Compute asin(x) = atan(x/sqrt(1-x*x)) */ + + /* Split x */ + double temp = x * HEX_40000000; + final double xa = x + temp - temp; + final double xb = x - xa; + + /* Square it */ + double ya = xa*xa; + double yb = xa*xb*2.0 + xb*xb; + + /* Subtract from 1 */ + ya = -ya; + yb = -yb; + + double za = 1.0 + ya; + double zb = -(za - 1.0 - ya); + + temp = za + yb; + zb += -(temp - za - yb); + za = temp; + + /* Square root */ + double y; + y = sqrt(za); + temp = y * HEX_40000000; + ya = y + temp - temp; + yb = y - ya; + + /* Extend precision of sqrt */ + yb += (za - ya*ya - 2*ya*yb - yb*yb) / (2.0*y); + + /* Contribution of zb to sqrt */ + double dx = zb / (2.0*y); + + // Compute ratio r = x/y + double r = x/y; + temp = r * HEX_40000000; + double ra = r + temp - temp; + double rb = r - ra; + + rb += (x - ra*ya - ra*yb - rb*ya - rb*yb) / y; // Correct for rounding in division + rb += -x * dx / y / y; // Add in effect additional bits of sqrt. + + temp = ra + rb; + rb = -(temp - ra - rb); + ra = temp; + + return atan(ra, rb, false); + } + + /** Compute the arc cosine of a number. + * @param x number on which evaluation is done + * @return arc cosine of x + */ + public static double acos(double x) { + if (Double.isNaN(x)) { + return Double.NaN; + } + + if (x > 1.0 || x < -1.0) { + return Double.NaN; + } + + if (x == -1.0) { + return Math.PI; + } + + if (x == 1.0) { + return 0.0; + } + + if (x == 0) { + return Math.PI/2.0; + } + + /* Compute acos(x) = atan(sqrt(1-x*x)/x) */ + + /* Split x */ + double temp = x * HEX_40000000; + final double xa = x + temp - temp; + final double xb = x - xa; + + /* Square it */ + double ya = xa*xa; + double yb = xa*xb*2.0 + xb*xb; + + /* Subtract from 1 */ + ya = -ya; + yb = -yb; + + double za = 1.0 + ya; + double zb = -(za - 1.0 - ya); + + temp = za + yb; + zb += -(temp - za - yb); + za = temp; + + /* Square root */ + double y = sqrt(za); + temp = y * HEX_40000000; + ya = y + temp - temp; + yb = y - ya; + + /* Extend precision of sqrt */ + yb += (za - ya*ya - 2*ya*yb - yb*yb) / (2.0*y); + + /* Contribution of zb to sqrt */ + yb += zb / (2.0*y); + y = ya+yb; + yb = -(y - ya - yb); + + // Compute ratio r = y/x + double r = y/x; + + // Did r overflow? + if (Double.isInfinite(r)) { // x is effectively zero + return Math.PI/2; // so return the appropriate value + } + + double ra = doubleHighPart(r); + double rb = r - ra; + + rb += (y - ra*xa - ra*xb - rb*xa - rb*xb) / x; // Correct for rounding in division + rb += yb / x; // Add in effect additional bits of sqrt. + + temp = ra + rb; + rb = -(temp - ra - rb); + ra = temp; + + return atan(ra, rb, x<0); + } + + /** Compute the cubic root of a number. + * @param x number on which evaluation is done + * @return cubic root of x + */ + public static double cbrt(double x) { + /* Convert input double to bits */ + long inbits = Double.doubleToRawLongBits(x); + int exponent = (int) ((inbits >> 52) & 0x7ff) - 1023; + boolean subnormal = false; + + if (exponent == -1023) { + if (x == 0) { + return x; + } + + /* Subnormal, so normalize */ + subnormal = true; + x *= 1.8014398509481984E16; // 2^54 + inbits = Double.doubleToRawLongBits(x); + exponent = (int) ((inbits >> 52) & 0x7ff) - 1023; + } + + if (exponent == 1024) { + // Nan or infinity. Don't care which. + return x; + } + + /* Divide the exponent by 3 */ + int exp3 = exponent / 3; + + /* p2 will be the nearest power of 2 to x with its exponent divided by 3 */ + double p2 = Double.longBitsToDouble((inbits & 0x8000000000000000L) | + (long)(((exp3 + 1023) & 0x7ff)) << 52); + + /* This will be a number between 1 and 2 */ + final double mant = Double.longBitsToDouble((inbits & 0x000fffffffffffffL) | 0x3ff0000000000000L); + + /* Estimate the cube root of mant by polynomial */ + double est = -0.010714690733195933; + est = est * mant + 0.0875862700108075; + est = est * mant + -0.3058015757857271; + est = est * mant + 0.7249995199969751; + est = est * mant + 0.5039018405998233; + + est *= CBRTTWO[exponent % 3 + 2]; + + // est should now be good to about 15 bits of precision. Do 2 rounds of + // Newton's method to get closer, this should get us full double precision + // Scale down x for the purpose of doing newtons method. This avoids over/under flows. + final double xs = x / (p2*p2*p2); + est += (xs - est*est*est) / (3*est*est); + est += (xs - est*est*est) / (3*est*est); + + // Do one round of Newton's method in extended precision to get the last bit right. + double temp = est * HEX_40000000; + double ya = est + temp - temp; + double yb = est - ya; + + double za = ya * ya; + double zb = ya * yb * 2.0 + yb * yb; + temp = za * HEX_40000000; + double temp2 = za + temp - temp; + zb += za - temp2; + za = temp2; + + zb = za * yb + ya * zb + zb * yb; + za *= ya; + + double na = xs - za; + double nb = -(na - xs + za); + nb -= zb; + + est += (na+nb)/(3*est*est); + + /* Scale by a power of two, so this is exact. */ + est *= p2; + + if (subnormal) { + est *= 3.814697265625E-6; // 2^-18 + } + + return est; + } + + /** + * Convert degrees to radians, with error of less than 0.5 ULP + * @param x angle in degrees + * @return x converted into radians + */ + public static double toRadians(double x) + { + if (Double.isInfinite(x) || x == 0.0) { // Matches +/- 0.0; return correct sign + return x; + } + + // These are PI/180 split into high and low order bits + final double facta = 0.01745329052209854; + final double factb = 1.997844754509471E-9; + + double xa = doubleHighPart(x); + double xb = x - xa; + + double result = xb * factb + xb * facta + xa * factb + xa * facta; + if (result == 0) { + result *= x; // ensure correct sign if calculation underflows + } + return result; + } + + /** + * Convert radians to degrees, with error of less than 0.5 ULP + * @param x angle in radians + * @return x converted into degrees + */ + public static double toDegrees(double x) + { + if (Double.isInfinite(x) || x == 0.0) { // Matches +/- 0.0; return correct sign + return x; + } + + // These are 180/PI split into high and low order bits + final double facta = 57.2957763671875; + final double factb = 3.145894820876798E-6; + + double xa = doubleHighPart(x); + double xb = x - xa; + + return xb * factb + xb * facta + xa * factb + xa * facta; + } + + /** + * Absolute value. + * @param x number from which absolute value is requested + * @return abs(x) + */ + public static int abs(final int x) { + final int i = x >>> 31; + return (x ^ (~i + 1)) + i; + } + + /** + * Absolute value. + * @param x number from which absolute value is requested + * @return abs(x) + */ + public static long abs(final long x) { + final long l = x >>> 63; + // l is one if x negative zero else + // ~l+1 is zero if x is positive, -1 if x is negative + // x^(~l+1) is x is x is positive, ~x if x is negative + // add around + return (x ^ (~l + 1)) + l; + } + + /** + * Absolute value. + * @param x number from which absolute value is requested + * @return abs(x) + */ + public static float abs(final float x) { + return Float.intBitsToFloat(MASK_NON_SIGN_INT & Float.floatToRawIntBits(x)); + } + + /** + * Absolute value. + * @param x number from which absolute value is requested + * @return abs(x) + */ + public static double abs(double x) { + return Double.longBitsToDouble(MASK_NON_SIGN_LONG & Double.doubleToRawLongBits(x)); + } + + /** + * Compute least significant bit (Unit in Last Position) for a number. + * @param x number from which ulp is requested + * @return ulp(x) + */ + public static double ulp(double x) { + if (Double.isInfinite(x)) { + return Double.POSITIVE_INFINITY; + } + return abs(x - Double.longBitsToDouble(Double.doubleToRawLongBits(x) ^ 1)); + } + + /** + * Compute least significant bit (Unit in Last Position) for a number. + * @param x number from which ulp is requested + * @return ulp(x) + */ + public static float ulp(float x) { + if (Float.isInfinite(x)) { + return Float.POSITIVE_INFINITY; + } + return abs(x - Float.intBitsToFloat(Float.floatToIntBits(x) ^ 1)); + } + + /** + * Multiply a double number by a power of 2. + * @param d number to multiply + * @param n power of 2 + * @return d × 2n + */ + public static double scalb(final double d, final int n) { + + // first simple and fast handling when 2^n can be represented using normal numbers + if ((n > -1023) && (n < 1024)) { + return d * Double.longBitsToDouble(((long) (n + 1023)) << 52); + } + + // handle special cases + if (Double.isNaN(d) || Double.isInfinite(d) || (d == 0)) { + return d; + } + if (n < -2098) { + return (d > 0) ? 0.0 : -0.0; + } + if (n > 2097) { + return (d > 0) ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY; + } + + // decompose d + final long bits = Double.doubleToRawLongBits(d); + final long sign = bits & 0x8000000000000000L; + int exponent = ((int) (bits >>> 52)) & 0x7ff; + long mantissa = bits & 0x000fffffffffffffL; + + // compute scaled exponent + int scaledExponent = exponent + n; + + if (n < 0) { + // we are really in the case n <= -1023 + if (scaledExponent > 0) { + // both the input and the result are normal numbers, we only adjust the exponent + return Double.longBitsToDouble(sign | (((long) scaledExponent) << 52) | mantissa); + } else if (scaledExponent > -53) { + // the input is a normal number and the result is a subnormal number + + // recover the hidden mantissa bit + mantissa |= 1L << 52; + + // scales down complete mantissa, hence losing least significant bits + final long mostSignificantLostBit = mantissa & (1L << (-scaledExponent)); + mantissa >>>= 1 - scaledExponent; + if (mostSignificantLostBit != 0) { + // we need to add 1 bit to round up the result + mantissa++; + } + return Double.longBitsToDouble(sign | mantissa); + + } else { + // no need to compute the mantissa, the number scales down to 0 + return (sign == 0L) ? 0.0 : -0.0; + } + } else { + // we are really in the case n >= 1024 + if (exponent == 0) { + + // the input number is subnormal, normalize it + while ((mantissa >>> 52) != 1) { + mantissa <<= 1; + --scaledExponent; + } + ++scaledExponent; + mantissa &= 0x000fffffffffffffL; + + if (scaledExponent < 2047) { + return Double.longBitsToDouble(sign | (((long) scaledExponent) << 52) | mantissa); + } else { + return (sign == 0L) ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY; + } + + } else if (scaledExponent < 2047) { + return Double.longBitsToDouble(sign | (((long) scaledExponent) << 52) | mantissa); + } else { + return (sign == 0L) ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY; + } + } + + } + + /** + * Multiply a float number by a power of 2. + * @param f number to multiply + * @param n power of 2 + * @return f × 2n + */ + public static float scalb(final float f, final int n) { + + // first simple and fast handling when 2^n can be represented using normal numbers + if ((n > -127) && (n < 128)) { + return f * Float.intBitsToFloat((n + 127) << 23); + } + + // handle special cases + if (Float.isNaN(f) || Float.isInfinite(f) || (f == 0f)) { + return f; + } + if (n < -277) { + return (f > 0) ? 0.0f : -0.0f; + } + if (n > 276) { + return (f > 0) ? Float.POSITIVE_INFINITY : Float.NEGATIVE_INFINITY; + } + + // decompose f + final int bits = Float.floatToIntBits(f); + final int sign = bits & 0x80000000; + int exponent = (bits >>> 23) & 0xff; + int mantissa = bits & 0x007fffff; + + // compute scaled exponent + int scaledExponent = exponent + n; + + if (n < 0) { + // we are really in the case n <= -127 + if (scaledExponent > 0) { + // both the input and the result are normal numbers, we only adjust the exponent + return Float.intBitsToFloat(sign | (scaledExponent << 23) | mantissa); + } else if (scaledExponent > -24) { + // the input is a normal number and the result is a subnormal number + + // recover the hidden mantissa bit + mantissa |= 1 << 23; + + // scales down complete mantissa, hence losing least significant bits + final int mostSignificantLostBit = mantissa & (1 << (-scaledExponent)); + mantissa >>>= 1 - scaledExponent; + if (mostSignificantLostBit != 0) { + // we need to add 1 bit to round up the result + mantissa++; + } + return Float.intBitsToFloat(sign | mantissa); + + } else { + // no need to compute the mantissa, the number scales down to 0 + return (sign == 0) ? 0.0f : -0.0f; + } + } else { + // we are really in the case n >= 128 + if (exponent == 0) { + + // the input number is subnormal, normalize it + while ((mantissa >>> 23) != 1) { + mantissa <<= 1; + --scaledExponent; + } + ++scaledExponent; + mantissa &= 0x007fffff; + + if (scaledExponent < 255) { + return Float.intBitsToFloat(sign | (scaledExponent << 23) | mantissa); + } else { + return (sign == 0) ? Float.POSITIVE_INFINITY : Float.NEGATIVE_INFINITY; + } + + } else if (scaledExponent < 255) { + return Float.intBitsToFloat(sign | (scaledExponent << 23) | mantissa); + } else { + return (sign == 0) ? Float.POSITIVE_INFINITY : Float.NEGATIVE_INFINITY; + } + } + + } + + /** + * Get the next machine representable number after a number, moving + * in the direction of another number. + *

+ * The ordering is as follows (increasing): + *

    + *
  • -INFINITY
  • + *
  • -MAX_VALUE
  • + *
  • -MIN_VALUE
  • + *
  • -0.0
  • + *
  • +0.0
  • + *
  • +MIN_VALUE
  • + *
  • +MAX_VALUE
  • + *
  • +INFINITY
  • + *
  • + *
+ *

+ * If arguments compare equal, then the second argument is returned. + *

+ * If {@code direction} is greater than {@code d}, + * the smallest machine representable number strictly greater than + * {@code d} is returned; if less, then the largest representable number + * strictly less than {@code d} is returned.

+ *

+ * If {@code d} is infinite and direction does not + * bring it back to finite numbers, it is returned unchanged.

+ * + * @param d base number + * @param direction (the only important thing is whether + * {@code direction} is greater or smaller than {@code d}) + * @return the next machine representable number in the specified direction + */ + public static double nextAfter(double d, double direction) { + + // handling of some important special cases + if (Double.isNaN(d) || Double.isNaN(direction)) { + return Double.NaN; + } else if (d == direction) { + return direction; + } else if (Double.isInfinite(d)) { + return (d < 0) ? -Double.MAX_VALUE : Double.MAX_VALUE; + } else if (d == 0) { + return (direction < 0) ? -Double.MIN_VALUE : Double.MIN_VALUE; + } + // special cases MAX_VALUE to infinity and MIN_VALUE to 0 + // are handled just as normal numbers + // can use raw bits since already dealt with infinity and NaN + final long bits = Double.doubleToRawLongBits(d); + final long sign = bits & 0x8000000000000000L; + if ((direction < d) ^ (sign == 0L)) { + return Double.longBitsToDouble(sign | ((bits & 0x7fffffffffffffffL) + 1)); + } else { + return Double.longBitsToDouble(sign | ((bits & 0x7fffffffffffffffL) - 1)); + } + + } + + /** + * Get the next machine representable number after a number, moving + * in the direction of another number. + *

+ * The ordering is as follows (increasing): + *

    + *
  • -INFINITY
  • + *
  • -MAX_VALUE
  • + *
  • -MIN_VALUE
  • + *
  • -0.0
  • + *
  • +0.0
  • + *
  • +MIN_VALUE
  • + *
  • +MAX_VALUE
  • + *
  • +INFINITY
  • + *
  • + *
+ *

+ * If arguments compare equal, then the second argument is returned. + *

+ * If {@code direction} is greater than {@code f}, + * the smallest machine representable number strictly greater than + * {@code f} is returned; if less, then the largest representable number + * strictly less than {@code f} is returned.

+ *

+ * If {@code f} is infinite and direction does not + * bring it back to finite numbers, it is returned unchanged.

+ * + * @param f base number + * @param direction (the only important thing is whether + * {@code direction} is greater or smaller than {@code f}) + * @return the next machine representable number in the specified direction + */ + public static float nextAfter(final float f, final double direction) { + + // handling of some important special cases + if (Double.isNaN(f) || Double.isNaN(direction)) { + return Float.NaN; + } else if (f == direction) { + return (float) direction; + } else if (Float.isInfinite(f)) { + return (f < 0f) ? -Float.MAX_VALUE : Float.MAX_VALUE; + } else if (f == 0f) { + return (direction < 0) ? -Float.MIN_VALUE : Float.MIN_VALUE; + } + // special cases MAX_VALUE to infinity and MIN_VALUE to 0 + // are handled just as normal numbers + + final int bits = Float.floatToIntBits(f); + final int sign = bits & 0x80000000; + if ((direction < f) ^ (sign == 0)) { + return Float.intBitsToFloat(sign | ((bits & 0x7fffffff) + 1)); + } else { + return Float.intBitsToFloat(sign | ((bits & 0x7fffffff) - 1)); + } + + } + + /** Get the largest whole number smaller than x. + * @param x number from which floor is requested + * @return a double number f such that f is an integer f <= x < f + 1.0 + */ + public static double floor(double x) { + long y; + + if (Double.isNaN(x)) { + return x; + } + + if (x >= TWO_POWER_52 || x <= -TWO_POWER_52) { + return x; + } + + y = (long) x; + if (x < 0 && y != x) { + y--; + } + + if (y == 0) { + return x*y; + } + + return y; + } + + /** Get the smallest whole number larger than x. + * @param x number from which ceil is requested + * @return a double number c such that c is an integer c - 1.0 < x <= c + */ + public static double ceil(double x) { + double y; + + if (Double.isNaN(x)) { + return x; + } + + y = floor(x); + if (y == x) { + return y; + } + + y += 1.0; + + if (y == 0) { + return x*y; + } + + return y; + } + + /** Get the whole number that is the nearest to x, or the even one if x is exactly half way between two integers. + * @param x number from which nearest whole number is requested + * @return a double number r such that r is an integer r - 0.5 <= x <= r + 0.5 + */ + public static double rint(double x) { + double y = floor(x); + double d = x - y; + + if (d > 0.5) { + if (y == -1.0) { + return -0.0; // Preserve sign of operand + } + return y+1.0; + } + if (d < 0.5) { + return y; + } + + /* half way, round to even */ + long z = (long) y; + return (z & 1) == 0 ? y : y + 1.0; + } + + /** Get the closest long to x. + * @param x number from which closest long is requested + * @return closest long to x + */ + public static long round(double x) { + final long bits = Double.doubleToRawLongBits(x); + final int biasedExp = ((int)(bits>>52)) & 0x7ff; + // Shift to get rid of bits past comma except first one: will need to + // 1-shift to the right to end up with correct magnitude. + final int shift = (52 - 1 + Double.MAX_EXPONENT) - biasedExp; + if ((shift & -64) == 0) { + // shift in [0,63], so unbiased exp in [-12,51]. + long extendedMantissa = 0x0010000000000000L | (bits & 0x000fffffffffffffL); + if (bits < 0) { + extendedMantissa = -extendedMantissa; + } + // If value is positive and first bit past comma is 0, rounding + // to lower integer, else to upper one, which is what "+1" and + // then ">>1" do. + return ((extendedMantissa >> shift) + 1L) >> 1; + } else { + // +-Infinity, NaN, or a mathematical integer. + return (long) x; + } + } + + /** Get the closest int to x. + * @param x number from which closest int is requested + * @return closest int to x + */ + public static int round(final float x) { + final int bits = Float.floatToRawIntBits(x); + final int biasedExp = (bits>>23) & 0xff; + // Shift to get rid of bits past comma except first one: will need to + // 1-shift to the right to end up with correct magnitude. + final int shift = (23 - 1 + Float.MAX_EXPONENT) - biasedExp; + if ((shift & -32) == 0) { + // shift in [0,31], so unbiased exp in [-9,22]. + int extendedMantissa = 0x00800000 | (bits & 0x007fffff); + if (bits < 0) { + extendedMantissa = -extendedMantissa; + } + // If value is positive and first bit past comma is 0, rounding + // to lower integer, else to upper one, which is what "+1" and + // then ">>1" do. + return ((extendedMantissa >> shift) + 1) >> 1; + } else { + // +-Infinity, NaN, or a mathematical integer. + return (int) x; + } + } + + /** Compute the minimum of two values + * @param a first value + * @param b second value + * @return a if a is lesser or equal to b, b otherwise + */ + public static int min(final int a, final int b) { + return (a <= b) ? a : b; + } + + /** Compute the minimum of two values + * @param a first value + * @param b second value + * @return a if a is lesser or equal to b, b otherwise + */ + public static long min(final long a, final long b) { + return (a <= b) ? a : b; + } + + /** Compute the minimum of two values + * @param a first value + * @param b second value + * @return a if a is lesser or equal to b, b otherwise + */ + public static float min(final float a, final float b) { + if (a > b) { + return b; + } + if (a < b) { + return a; + } + /* if either arg is NaN, return NaN */ + if (a != b) { + return Float.NaN; + } + /* min(+0.0,-0.0) == -0.0 */ + /* 0x80000000 == Float.floatToRawIntBits(-0.0d) */ + int bits = Float.floatToRawIntBits(a); + if (bits == 0x80000000) { + return a; + } + return b; + } + + /** Compute the minimum of two values + * @param a first value + * @param b second value + * @return a if a is lesser or equal to b, b otherwise + */ + public static double min(final double a, final double b) { + if (a > b) { + return b; + } + if (a < b) { + return a; + } + /* if either arg is NaN, return NaN */ + if (a != b) { + return Double.NaN; + } + /* min(+0.0,-0.0) == -0.0 */ + /* 0x8000000000000000L == Double.doubleToRawLongBits(-0.0d) */ + long bits = Double.doubleToRawLongBits(a); + if (bits == 0x8000000000000000L) { + return a; + } + return b; + } + + /** Compute the maximum of two values + * @param a first value + * @param b second value + * @return b if a is lesser or equal to b, a otherwise + */ + public static int max(final int a, final int b) { + return (a <= b) ? b : a; + } + + /** Compute the maximum of two values + * @param a first value + * @param b second value + * @return b if a is lesser or equal to b, a otherwise + */ + public static long max(final long a, final long b) { + return (a <= b) ? b : a; + } + + /** Compute the maximum of two values + * @param a first value + * @param b second value + * @return b if a is lesser or equal to b, a otherwise + */ + public static float max(final float a, final float b) { + if (a > b) { + return a; + } + if (a < b) { + return b; + } + /* if either arg is NaN, return NaN */ + if (a != b) { + return Float.NaN; + } + /* min(+0.0,-0.0) == -0.0 */ + /* 0x80000000 == Float.floatToRawIntBits(-0.0d) */ + int bits = Float.floatToRawIntBits(a); + if (bits == 0x80000000) { + return b; + } + return a; + } + + /** Compute the maximum of two values + * @param a first value + * @param b second value + * @return b if a is lesser or equal to b, a otherwise + */ + public static double max(final double a, final double b) { + if (a > b) { + return a; + } + if (a < b) { + return b; + } + /* if either arg is NaN, return NaN */ + if (a != b) { + return Double.NaN; + } + /* min(+0.0,-0.0) == -0.0 */ + /* 0x8000000000000000L == Double.doubleToRawLongBits(-0.0d) */ + long bits = Double.doubleToRawLongBits(a); + if (bits == 0x8000000000000000L) { + return b; + } + return a; + } + + /** + * Returns the hypotenuse of a triangle with sides {@code x} and {@code y} + * - sqrt(x2 +y2)
+ * avoiding intermediate overflow or underflow. + * + *
    + *
  • If either argument is infinite, then the result is positive infinity.
  • + *
  • else, if either argument is NaN then the result is NaN.
  • + *
+ * + * @param x a value + * @param y a value + * @return sqrt(x2 +y2) + */ + public static double hypot(final double x, final double y) { + if (Double.isInfinite(x) || Double.isInfinite(y)) { + return Double.POSITIVE_INFINITY; + } else if (Double.isNaN(x) || Double.isNaN(y)) { + return Double.NaN; + } else { + + final int expX = getExponent(x); + final int expY = getExponent(y); + if (expX > expY + 27) { + // y is neglectible with respect to x + return abs(x); + } else if (expY > expX + 27) { + // x is neglectible with respect to y + return abs(y); + } else { + + // find an intermediate scale to avoid both overflow and underflow + final int middleExp = (expX + expY) / 2; + + // scale parameters without losing precision + final double scaledX = scalb(x, -middleExp); + final double scaledY = scalb(y, -middleExp); + + // compute scaled hypotenuse + final double scaledH = sqrt(scaledX * scaledX + scaledY * scaledY); + + // remove scaling + return scalb(scaledH, middleExp); + + } + + } + } + + /** + * Computes the remainder as prescribed by the IEEE 754 standard. + * The remainder value is mathematically equal to {@code x - y*n} + * where {@code n} is the mathematical integer closest to the exact mathematical value + * of the quotient {@code x/y}. + * If two mathematical integers are equally close to {@code x/y} then + * {@code n} is the integer that is even. + *
    + *
  • If either operand is NaN, the result is NaN.
  • + *
  • If the result is not NaN, the sign of the result equals the sign of the dividend.
  • + *
  • If the dividend is an infinity, or the divisor is a zero, or both, the result is NaN.
  • + *
  • If the dividend is finite and the divisor is an infinity, the result equals the dividend.
  • + *
  • If the dividend is a zero and the divisor is finite, the result equals the dividend.
  • + *
+ * @param dividend the number to be divided + * @param divisor the number by which to divide + * @return the remainder, rounded + */ + public static double IEEEremainder(final double dividend, final double divisor) { + if (getExponent(dividend) == 1024 || getExponent(divisor) == 1024 || divisor == 0.0) { + // we are in one of the special cases + if (Double.isInfinite(divisor) && !Double.isInfinite(dividend)) { + return dividend; + } else { + return Double.NaN; + } + } else { + // we are in the general case + final double n = AccurateMath.rint(dividend / divisor); + final double remainder = Double.isInfinite(n) ? 0.0 : dividend - divisor * n; + return (remainder == 0) ? AccurateMath.copySign(remainder, dividend) : remainder; + } + } + + /** Convert a long to integer, detecting overflows + * @param n number to convert to int + * @return integer with same value as n if no overflows occur + * @exception MathArithmeticException if n cannot fit into an int + * @since 3.4 + */ + public static int toIntExact(final long n) throws MathArithmeticException { + if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE) { + throw new MathArithmeticException(LocalizedFormats.OVERFLOW); + } + return (int) n; + } + + /** Increment a number, detecting overflows. + * @param n number to increment + * @return n+1 if no overflows occur + * @exception MathArithmeticException if an overflow occurs + * @since 3.4 + */ + public static int incrementExact(final int n) throws MathArithmeticException { + + if (n == Integer.MAX_VALUE) { + throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_ADDITION, n, 1); + } + + return n + 1; + + } + + /** Increment a number, detecting overflows. + * @param n number to increment + * @return n+1 if no overflows occur + * @exception MathArithmeticException if an overflow occurs + * @since 3.4 + */ + public static long incrementExact(final long n) throws MathArithmeticException { + + if (n == Long.MAX_VALUE) { + throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_ADDITION, n, 1); + } + + return n + 1; + + } + + /** Decrement a number, detecting overflows. + * @param n number to decrement + * @return n-1 if no overflows occur + * @exception MathArithmeticException if an overflow occurs + * @since 3.4 + */ + public static int decrementExact(final int n) throws MathArithmeticException { + + if (n == Integer.MIN_VALUE) { + throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_SUBTRACTION, n, 1); + } + + return n - 1; + + } + + /** Decrement a number, detecting overflows. + * @param n number to decrement + * @return n-1 if no overflows occur + * @exception MathArithmeticException if an overflow occurs + * @since 3.4 + */ + public static long decrementExact(final long n) throws MathArithmeticException { + + if (n == Long.MIN_VALUE) { + throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_SUBTRACTION, n, 1); + } + + return n - 1; + + } + + /** Add two numbers, detecting overflows. + * @param a first number to add + * @param b second number to add + * @return a+b if no overflows occur + * @exception MathArithmeticException if an overflow occurs + * @since 3.4 + */ + public static int addExact(final int a, final int b) throws MathArithmeticException { + + // compute sum + final int sum = a + b; + + // check for overflow + if ((a ^ b) >= 0 && (sum ^ b) < 0) { + throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_ADDITION, a, b); + } + + return sum; + + } + + /** Add two numbers, detecting overflows. + * @param a first number to add + * @param b second number to add + * @return a+b if no overflows occur + * @exception MathArithmeticException if an overflow occurs + * @since 3.4 + */ + public static long addExact(final long a, final long b) throws MathArithmeticException { + + // compute sum + final long sum = a + b; + + // check for overflow + if ((a ^ b) >= 0 && (sum ^ b) < 0) { + throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_ADDITION, a, b); + } + + return sum; + + } + + /** Subtract two numbers, detecting overflows. + * @param a first number + * @param b second number to subtract from a + * @return a-b if no overflows occur + * @exception MathArithmeticException if an overflow occurs + * @since 3.4 + */ + public static int subtractExact(final int a, final int b) { + + // compute subtraction + final int sub = a - b; + + // check for overflow + if ((a ^ b) < 0 && (sub ^ b) >= 0) { + throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_SUBTRACTION, a, b); + } + + return sub; + + } + + /** Subtract two numbers, detecting overflows. + * @param a first number + * @param b second number to subtract from a + * @return a-b if no overflows occur + * @exception MathArithmeticException if an overflow occurs + * @since 3.4 + */ + public static long subtractExact(final long a, final long b) { + + // compute subtraction + final long sub = a - b; + + // check for overflow + if ((a ^ b) < 0 && (sub ^ b) >= 0) { + throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_SUBTRACTION, a, b); + } + + return sub; + + } + + /** Multiply two numbers, detecting overflows. + * @param a first number to multiply + * @param b second number to multiply + * @return a*b if no overflows occur + * @exception MathArithmeticException if an overflow occurs + * @since 3.4 + */ + public static int multiplyExact(final int a, final int b) { + if (((b > 0) && (a > Integer.MAX_VALUE / b || a < Integer.MIN_VALUE / b)) || + ((b < -1) && (a > Integer.MIN_VALUE / b || a < Integer.MAX_VALUE / b)) || + ((b == -1) && (a == Integer.MIN_VALUE))) { + throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_MULTIPLICATION, a, b); + } + return a * b; + } + + /** Multiply two numbers, detecting overflows. + * @param a first number to multiply + * @param b second number to multiply + * @return a*b if no overflows occur + * @exception MathArithmeticException if an overflow occurs + * @since 3.4 + */ + public static long multiplyExact(final long a, final long b) { + if (((b > 0l) && (a > Long.MAX_VALUE / b || a < Long.MIN_VALUE / b)) || + ((b < -1l) && (a > Long.MIN_VALUE / b || a < Long.MAX_VALUE / b)) || + ((b == -1l) && (a == Long.MIN_VALUE))) { + throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_MULTIPLICATION, a, b); + } + return a * b; + } + + /** Finds q such that a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b < 0. + *

+ * This methods returns the same value as integer division when + * a and b are same signs, but returns a different value when + * they are opposite (i.e. q is negative). + *

+ * @param a dividend + * @param b divisor + * @return q such that a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b < 0 + * @exception MathArithmeticException if b == 0 + * @see #floorMod(int, int) + * @since 3.4 + */ + public static int floorDiv(final int a, final int b) throws MathArithmeticException { + + if (b == 0) { + throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR); + } + + final int m = a % b; + if ((a ^ b) >= 0 || m == 0) { + // a an b have same sign, or division is exact + return a / b; + } else { + // a and b have opposite signs and division is not exact + return (a / b) - 1; + } + + } + + /** Finds q such that a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b < 0. + *

+ * This methods returns the same value as integer division when + * a and b are same signs, but returns a different value when + * they are opposite (i.e. q is negative). + *

+ * @param a dividend + * @param b divisor + * @return q such that a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b < 0 + * @exception MathArithmeticException if b == 0 + * @see #floorMod(long, long) + * @since 3.4 + */ + public static long floorDiv(final long a, final long b) throws MathArithmeticException { + + if (b == 0l) { + throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR); + } + + final long m = a % b; + if ((a ^ b) >= 0l || m == 0l) { + // a an b have same sign, or division is exact + return a / b; + } else { + // a and b have opposite signs and division is not exact + return (a / b) - 1l; + } + + } + + /** Finds r such that a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b < 0. + *

+ * This methods returns the same value as integer modulo when + * a and b are same signs, but returns a different value when + * they are opposite (i.e. q is negative). + *

+ * @param a dividend + * @param b divisor + * @return r such that a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b < 0 + * @exception MathArithmeticException if b == 0 + * @see #floorDiv(int, int) + * @since 3.4 + */ + public static int floorMod(final int a, final int b) throws MathArithmeticException { + + if (b == 0) { + throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR); + } + + final int m = a % b; + if ((a ^ b) >= 0 || m == 0) { + // a an b have same sign, or division is exact + return m; + } else { + // a and b have opposite signs and division is not exact + return b + m; + } + + } + + /** Finds r such that a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b < 0. + *

+ * This methods returns the same value as integer modulo when + * a and b are same signs, but returns a different value when + * they are opposite (i.e. q is negative). + *

+ * @param a dividend + * @param b divisor + * @return r such that a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b < 0 + * @exception MathArithmeticException if b == 0 + * @see #floorDiv(long, long) + * @since 3.4 + */ + public static long floorMod(final long a, final long b) { + + if (b == 0l) { + throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR); + } + + final long m = a % b; + if ((a ^ b) >= 0l || m == 0l) { + // a an b have same sign, or division is exact + return m; + } else { + // a and b have opposite signs and division is not exact + return b + m; + } + + } + + /** + * Returns the first argument with the sign of the second argument. + * A NaN {@code sign} argument is treated as positive. + * + * @param magnitude the value to return + * @param sign the sign for the returned value + * @return the magnitude with the same sign as the {@code sign} argument + */ + public static double copySign(double magnitude, double sign){ + // The highest order bit is going to be zero if the + // highest order bit of m and s is the same and one otherwise. + // So (m^s) will be positive if both m and s have the same sign + // and negative otherwise. + final long m = Double.doubleToRawLongBits(magnitude); // don't care about NaN + final long s = Double.doubleToRawLongBits(sign); + if ((m^s) >= 0) { + return magnitude; + } + return -magnitude; // flip sign + } + + /** + * Returns the first argument with the sign of the second argument. + * A NaN {@code sign} argument is treated as positive. + * + * @param magnitude the value to return + * @param sign the sign for the returned value + * @return the magnitude with the same sign as the {@code sign} argument + */ + public static float copySign(float magnitude, float sign){ + // The highest order bit is going to be zero if the + // highest order bit of m and s is the same and one otherwise. + // So (m^s) will be positive if both m and s have the same sign + // and negative otherwise. + final int m = Float.floatToRawIntBits(magnitude); + final int s = Float.floatToRawIntBits(sign); + if ((m^s) >= 0) { + return magnitude; + } + return -magnitude; // flip sign + } + + /** + * Return the exponent of a double number, removing the bias. + *

+ * For double numbers of the form 2x, the unbiased + * exponent is exactly x. + *

+ * @param d number from which exponent is requested + * @return exponent for d in IEEE754 representation, without bias + */ + public static int getExponent(final double d) { + // NaN and Infinite will return 1024 anywho so can use raw bits + return (int) ((Double.doubleToRawLongBits(d) >>> 52) & 0x7ff) - 1023; + } + + /** + * Return the exponent of a float number, removing the bias. + *

+ * For float numbers of the form 2x, the unbiased + * exponent is exactly x. + *

+ * @param f number from which exponent is requested + * @return exponent for d in IEEE754 representation, without bias + */ + public static int getExponent(final float f) { + // NaN and Infinite will return the same exponent anywho so can use raw bits + return ((Float.floatToRawIntBits(f) >>> 23) & 0xff) - 127; + } + + /** + * Print out contents of arrays, and check the length. + *

used to generate the preset arrays originally.

+ * @param a unused + */ + public static void main(String[] a) { + PrintStream out = System.out; + AccurateMathCalc.printarray(out, "EXP_INT_TABLE_A", EXP_INT_TABLE_LEN, ExpIntTable.EXP_INT_TABLE_A); + AccurateMathCalc.printarray(out, "EXP_INT_TABLE_B", EXP_INT_TABLE_LEN, ExpIntTable.EXP_INT_TABLE_B); + AccurateMathCalc.printarray(out, "EXP_FRAC_TABLE_A", EXP_FRAC_TABLE_LEN, ExpFracTable.EXP_FRAC_TABLE_A); + AccurateMathCalc.printarray(out, "EXP_FRAC_TABLE_B", EXP_FRAC_TABLE_LEN, ExpFracTable.EXP_FRAC_TABLE_B); + AccurateMathCalc.printarray(out, "LN_MANT",LN_MANT_LEN, lnMant.LN_MANT); + AccurateMathCalc.printarray(out, "SINE_TABLE_A", SINE_TABLE_LEN, SINE_TABLE_A); + AccurateMathCalc.printarray(out, "SINE_TABLE_B", SINE_TABLE_LEN, SINE_TABLE_B); + AccurateMathCalc.printarray(out, "COSINE_TABLE_A", SINE_TABLE_LEN, COSINE_TABLE_A); + AccurateMathCalc.printarray(out, "COSINE_TABLE_B", SINE_TABLE_LEN, COSINE_TABLE_B); + AccurateMathCalc.printarray(out, "TANGENT_TABLE_A", SINE_TABLE_LEN, TANGENT_TABLE_A); + AccurateMathCalc.printarray(out, "TANGENT_TABLE_B", SINE_TABLE_LEN, TANGENT_TABLE_B); + } + + /** Enclose large data table in nested static class so it's only loaded on first access. */ + private static class ExpIntTable { + /** Exponential evaluated at integer values, + * exp(x) = expIntTableA[x + EXP_INT_TABLE_MAX_INDEX] + expIntTableB[x+EXP_INT_TABLE_MAX_INDEX]. + */ + private static final double[] EXP_INT_TABLE_A; + /** Exponential evaluated at integer values, + * exp(x) = expIntTableA[x + EXP_INT_TABLE_MAX_INDEX] + expIntTableB[x+EXP_INT_TABLE_MAX_INDEX] + */ + private static final double[] EXP_INT_TABLE_B; + + static { + if (RECOMPUTE_TABLES_AT_RUNTIME) { + EXP_INT_TABLE_A = new double[AccurateMath.EXP_INT_TABLE_LEN]; + EXP_INT_TABLE_B = new double[AccurateMath.EXP_INT_TABLE_LEN]; + + final double tmp[] = new double[2]; + final double recip[] = new double[2]; + + // Populate expIntTable + for (int i = 0; i < AccurateMath.EXP_INT_TABLE_MAX_INDEX; i++) { + AccurateMathCalc.expint(i, tmp); + EXP_INT_TABLE_A[i + AccurateMath.EXP_INT_TABLE_MAX_INDEX] = tmp[0]; + EXP_INT_TABLE_B[i + AccurateMath.EXP_INT_TABLE_MAX_INDEX] = tmp[1]; + + if (i != 0) { + // Negative integer powers + AccurateMathCalc.splitReciprocal(tmp, recip); + EXP_INT_TABLE_A[AccurateMath.EXP_INT_TABLE_MAX_INDEX - i] = recip[0]; + EXP_INT_TABLE_B[AccurateMath.EXP_INT_TABLE_MAX_INDEX - i] = recip[1]; + } + } + } else { + EXP_INT_TABLE_A = AccurateMathLiteralArrays.loadExpIntA(); + EXP_INT_TABLE_B = AccurateMathLiteralArrays.loadExpIntB(); + } + } + } + + /** Enclose large data table in nested static class so it's only loaded on first access. */ + private static class ExpFracTable { + /** Exponential over the range of 0 - 1 in increments of 2^-10 + * exp(x/1024) = expFracTableA[x] + expFracTableB[x]. + * 1024 = 2^10 + */ + private static final double[] EXP_FRAC_TABLE_A; + /** Exponential over the range of 0 - 1 in increments of 2^-10 + * exp(x/1024) = expFracTableA[x] + expFracTableB[x]. + */ + private static final double[] EXP_FRAC_TABLE_B; + + static { + if (RECOMPUTE_TABLES_AT_RUNTIME) { + EXP_FRAC_TABLE_A = new double[AccurateMath.EXP_FRAC_TABLE_LEN]; + EXP_FRAC_TABLE_B = new double[AccurateMath.EXP_FRAC_TABLE_LEN]; + + final double tmp[] = new double[2]; + + // Populate expFracTable + final double factor = 1d / (EXP_FRAC_TABLE_LEN - 1); + for (int i = 0; i < EXP_FRAC_TABLE_A.length; i++) { + AccurateMathCalc.slowexp(i * factor, tmp); + EXP_FRAC_TABLE_A[i] = tmp[0]; + EXP_FRAC_TABLE_B[i] = tmp[1]; + } + } else { + EXP_FRAC_TABLE_A = AccurateMathLiteralArrays.loadExpFracA(); + EXP_FRAC_TABLE_B = AccurateMathLiteralArrays.loadExpFracB(); + } + } + } + + /** Enclose large data table in nested static class so it's only loaded on first access. */ + private static class lnMant { + /** Extended precision logarithm table over the range 1 - 2 in increments of 2^-10. */ + private static final double[][] LN_MANT; + + static { + if (RECOMPUTE_TABLES_AT_RUNTIME) { + LN_MANT = new double[AccurateMath.LN_MANT_LEN][]; + + // Populate lnMant table + for (int i = 0; i < LN_MANT.length; i++) { + final double d = Double.longBitsToDouble( (((long) i) << 42) | 0x3ff0000000000000L ); + LN_MANT[i] = AccurateMathCalc.slowLog(d); + } + } else { + LN_MANT = AccurateMathLiteralArrays.loadLnMant(); + } + } + } + + /** Enclose the Cody/Waite reduction (used in "sin", "cos" and "tan"). */ + private static class CodyWaite { + /** k */ + private final int finalK; + /** remA */ + private final double finalRemA; + /** remB */ + private final double finalRemB; + + /** + * @param xa Argument. + */ + CodyWaite(double xa) { + // Estimate k. + //k = (int)(xa / 1.5707963267948966); + int k = (int)(xa * 0.6366197723675814); + + // Compute remainder. + double remA; + double remB; + while (true) { + double a = -k * 1.570796251296997; + remA = xa + a; + remB = -(remA - xa - a); + + a = -k * 7.549789948768648E-8; + double b = remA; + remA = a + b; + remB += -(remA - b - a); + + a = -k * 6.123233995736766E-17; + b = remA; + remA = a + b; + remB += -(remA - b - a); + + if (remA > 0) { + break; + } + + // Remainder is negative, so decrement k and try again. + // This should only happen if the input is very close + // to an even multiple of pi/2. + --k; + } + + this.finalK = k; + this.finalRemA = remA; + this.finalRemB = remB; + } + + /** + * @return k + */ + int getK() { + return finalK; + } + /** + * @return remA + */ + double getRemA() { + return finalRemA; + } + /** + * @return remB + */ + double getRemB() { + return finalRemB; + } + } +} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMath.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMath.java.bak similarity index 97% rename from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMath.java rename to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMath.java.bak index 07175f4cf..7a39abcde 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMath.java +++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMath.java.bak @@ -25,36 +25,36 @@ import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; /** * Portable alternative to {@link Math} and {@link StrictMath}. *

- * Caveat: At the time of implementation, the {@code FastMath} functions + * Caveat: At the time of implementation, the {@code AccurateMath} functions * were often faster and/or more accurate than their JDK equivalent. * Nowadays, it would not be surprising that they are always slower (due * to the various JVM optimizations that have appeared since Java 5). * However, any change to this class should ensure that the current * accuracy is not lost. *

- * FastMath is a drop-in replacement for both Math and StrictMath. This + * AccurateMath is a drop-in replacement for both Math and StrictMath. This * means that for any method in Math (say {@code Math.sin(x)} or * {@code Math.cbrt(y)}), user can directly change the class and use the - * methods as is (using {@code FastMath.sin(x)} or {@code FastMath.cbrt(y)} + * methods as is (using {@code AccurateMath.sin(x)} or {@code AccurateMath.cbrt(y)} * in the previous example). *

*

- * FastMath speed is achieved by relying heavily on optimizing compilers + * AccurateMath speed is achieved by relying heavily on optimizing compilers * to native code present in many JVMs today and use of large tables. * The larger tables are lazily initialized on first use, so that the setup * time does not penalize methods that don't need them. *

*

- * Note that FastMath is + * Note that AccurateMath is * extensively used inside Apache Commons Math, so by calling some algorithms, * the overhead when the tables need to be initialized will occur - * regardless of the end-user calling FastMath methods directly or not. + * regardless of the end-user calling AccurateMath methods directly or not. * Performance figures for a specific JVM and hardware can be evaluated by - * running the FastMathTestPerformance tests in the test directory of the source + * running the AccurateMathTestPerformance tests in the test directory of the source * distribution. *

*

- * FastMath accuracy should be mostly independent of the JVM as it relies only + * AccurateMath accuracy should be mostly independent of the JVM as it relies only * on IEEE-754 basic operations and on embedded tables. Almost all operations * are accurate to about 0.5 ulp throughout the domain range. This statement, * of course is only a rough global observed behavior, it is not a @@ -63,14 +63,14 @@ import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; * Maker's Dilemma). *

*

- * FastMath additionally implements the following methods not found in Math/StrictMath: + * AccurateMath additionally implements the following methods not found in Math/StrictMath: *

    *
  • {@link #asinh(double)}
  • *
  • {@link #acosh(double)}
  • *
  • {@link #atanh(double)}
  • *
* The following methods are found in Math/StrictMath since 1.6 only, they are provided - * by FastMath even in 1.5 Java virtual machines + * by AccurateMath even in 1.5 Java virtual machines *
    *
  • {@link #copySign(double, double)}
  • *
  • {@link #getExponent(double)}
  • @@ -85,7 +85,7 @@ import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; *
* @since 2.2 */ -public class FastMath { +public class AccurateMath { /** Archimede's constant PI, ratio of circle circumference to diameter. */ public static final double PI = 105414357.0 / 33554432.0 + 1.984187159361080883e-9; @@ -371,7 +371,7 @@ public class FastMath { /** * Private Constructor */ - private FastMath() {} + private AccurateMath() {} // Generic helper methods @@ -723,7 +723,7 @@ public class FastMath { * @return inverse hyperbolic cosine of a */ public static double acosh(final double a) { - return FastMath.log(a + FastMath.sqrt(a * a - 1)); + return AccurateMath.log(a + AccurateMath.sqrt(a * a - 1)); } /** Compute the inverse hyperbolic sine of a number. @@ -739,7 +739,7 @@ public class FastMath { double absAsinh; if (a > 0.167) { - absAsinh = FastMath.log(FastMath.sqrt(a * a + 1) + a); + absAsinh = AccurateMath.log(AccurateMath.sqrt(a * a + 1) + a); } else { final double a2 = a * a; if (a > 0.097) { @@ -769,7 +769,7 @@ public class FastMath { double absAtanh; if (a > 0.15) { - absAtanh = 0.5 * FastMath.log((1 + a) / (1 - a)); + absAtanh = 0.5 * AccurateMath.log((1 + a) / (1 - a)); } else { final double a2 = a * a; if (a > 0.087) { @@ -1536,13 +1536,13 @@ public class FastMath { if ((yFullMantissa & integralMask) == yFullMantissa) { // all fractional bits are 0, the number is really integral final long l = yFullMantissa >> (1075 - yRawExp); - return FastMath.pow(x, (y < 0) ? -l : l); + return AccurateMath.pow(x, (y < 0) ? -l : l); } } else { // normal number with positive shift, always an integral value // we know it fits in a primitive long because yRawExp > 1085 has been handled above final long l = yFullMantissa << (yRawExp - 1075); - return FastMath.pow(x, (y < 0) ? -l : l); + return AccurateMath.pow(x, (y < 0) ? -l : l); } } @@ -1754,8 +1754,8 @@ public class FastMath { } else { // some intermediate numbers exceeded capacity, // and the low order bits became NaN (because infinity - infinity = NaN) - if (FastMath.abs(full) < 1) { - return new Split(FastMath.copySign(0.0, full), 0.0); + if (AccurateMath.abs(full) < 1) { + return new Split(AccurateMath.copySign(0.0, full), 0.0); } else if (full < 0 && (e & 0x1) == 1) { return Split.NEGATIVE_INFINITY; } else { @@ -3778,9 +3778,9 @@ public class FastMath { } } else { // we are in the general case - final double n = FastMath.rint(dividend / divisor); + final double n = AccurateMath.rint(dividend / divisor); final double remainder = Double.isInfinite(n) ? 0.0 : dividend - divisor * n; - return (remainder == 0) ? FastMath.copySign(remainder, dividend) : remainder; + return (remainder == 0) ? AccurateMath.copySign(remainder, dividend) : remainder; } } @@ -4174,17 +4174,17 @@ public class FastMath { */ public static void main(String[] a) { PrintStream out = System.out; - FastMathCalc.printarray(out, "EXP_INT_TABLE_A", EXP_INT_TABLE_LEN, ExpIntTable.EXP_INT_TABLE_A); - FastMathCalc.printarray(out, "EXP_INT_TABLE_B", EXP_INT_TABLE_LEN, ExpIntTable.EXP_INT_TABLE_B); - FastMathCalc.printarray(out, "EXP_FRAC_TABLE_A", EXP_FRAC_TABLE_LEN, ExpFracTable.EXP_FRAC_TABLE_A); - FastMathCalc.printarray(out, "EXP_FRAC_TABLE_B", EXP_FRAC_TABLE_LEN, ExpFracTable.EXP_FRAC_TABLE_B); - FastMathCalc.printarray(out, "LN_MANT",LN_MANT_LEN, lnMant.LN_MANT); - FastMathCalc.printarray(out, "SINE_TABLE_A", SINE_TABLE_LEN, SINE_TABLE_A); - FastMathCalc.printarray(out, "SINE_TABLE_B", SINE_TABLE_LEN, SINE_TABLE_B); - FastMathCalc.printarray(out, "COSINE_TABLE_A", SINE_TABLE_LEN, COSINE_TABLE_A); - FastMathCalc.printarray(out, "COSINE_TABLE_B", SINE_TABLE_LEN, COSINE_TABLE_B); - FastMathCalc.printarray(out, "TANGENT_TABLE_A", SINE_TABLE_LEN, TANGENT_TABLE_A); - FastMathCalc.printarray(out, "TANGENT_TABLE_B", SINE_TABLE_LEN, TANGENT_TABLE_B); + AccurateMathCalc.printarray(out, "EXP_INT_TABLE_A", EXP_INT_TABLE_LEN, ExpIntTable.EXP_INT_TABLE_A); + AccurateMathCalc.printarray(out, "EXP_INT_TABLE_B", EXP_INT_TABLE_LEN, ExpIntTable.EXP_INT_TABLE_B); + AccurateMathCalc.printarray(out, "EXP_FRAC_TABLE_A", EXP_FRAC_TABLE_LEN, ExpFracTable.EXP_FRAC_TABLE_A); + AccurateMathCalc.printarray(out, "EXP_FRAC_TABLE_B", EXP_FRAC_TABLE_LEN, ExpFracTable.EXP_FRAC_TABLE_B); + AccurateMathCalc.printarray(out, "LN_MANT",LN_MANT_LEN, lnMant.LN_MANT); + AccurateMathCalc.printarray(out, "SINE_TABLE_A", SINE_TABLE_LEN, SINE_TABLE_A); + AccurateMathCalc.printarray(out, "SINE_TABLE_B", SINE_TABLE_LEN, SINE_TABLE_B); + AccurateMathCalc.printarray(out, "COSINE_TABLE_A", SINE_TABLE_LEN, COSINE_TABLE_A); + AccurateMathCalc.printarray(out, "COSINE_TABLE_B", SINE_TABLE_LEN, COSINE_TABLE_B); + AccurateMathCalc.printarray(out, "TANGENT_TABLE_A", SINE_TABLE_LEN, TANGENT_TABLE_A); + AccurateMathCalc.printarray(out, "TANGENT_TABLE_B", SINE_TABLE_LEN, TANGENT_TABLE_B); } /** Enclose large data table in nested static class so it's only loaded on first access. */ @@ -4200,28 +4200,28 @@ public class FastMath { static { if (RECOMPUTE_TABLES_AT_RUNTIME) { - EXP_INT_TABLE_A = new double[FastMath.EXP_INT_TABLE_LEN]; - EXP_INT_TABLE_B = new double[FastMath.EXP_INT_TABLE_LEN]; + EXP_INT_TABLE_A = new double[AccurateMath.EXP_INT_TABLE_LEN]; + EXP_INT_TABLE_B = new double[AccurateMath.EXP_INT_TABLE_LEN]; final double tmp[] = new double[2]; final double recip[] = new double[2]; // Populate expIntTable - for (int i = 0; i < FastMath.EXP_INT_TABLE_MAX_INDEX; i++) { - FastMathCalc.expint(i, tmp); - EXP_INT_TABLE_A[i + FastMath.EXP_INT_TABLE_MAX_INDEX] = tmp[0]; - EXP_INT_TABLE_B[i + FastMath.EXP_INT_TABLE_MAX_INDEX] = tmp[1]; + for (int i = 0; i < AccurateMath.EXP_INT_TABLE_MAX_INDEX; i++) { + AccurateMathCalc.expint(i, tmp); + EXP_INT_TABLE_A[i + AccurateMath.EXP_INT_TABLE_MAX_INDEX] = tmp[0]; + EXP_INT_TABLE_B[i + AccurateMath.EXP_INT_TABLE_MAX_INDEX] = tmp[1]; if (i != 0) { // Negative integer powers - FastMathCalc.splitReciprocal(tmp, recip); - EXP_INT_TABLE_A[FastMath.EXP_INT_TABLE_MAX_INDEX - i] = recip[0]; - EXP_INT_TABLE_B[FastMath.EXP_INT_TABLE_MAX_INDEX - i] = recip[1]; + AccurateMathCalc.splitReciprocal(tmp, recip); + EXP_INT_TABLE_A[AccurateMath.EXP_INT_TABLE_MAX_INDEX - i] = recip[0]; + EXP_INT_TABLE_B[AccurateMath.EXP_INT_TABLE_MAX_INDEX - i] = recip[1]; } } } else { - EXP_INT_TABLE_A = FastMathLiteralArrays.loadExpIntA(); - EXP_INT_TABLE_B = FastMathLiteralArrays.loadExpIntB(); + EXP_INT_TABLE_A = AccurateMathLiteralArrays.loadExpIntA(); + EXP_INT_TABLE_B = AccurateMathLiteralArrays.loadExpIntB(); } } } @@ -4240,21 +4240,21 @@ public class FastMath { static { if (RECOMPUTE_TABLES_AT_RUNTIME) { - EXP_FRAC_TABLE_A = new double[FastMath.EXP_FRAC_TABLE_LEN]; - EXP_FRAC_TABLE_B = new double[FastMath.EXP_FRAC_TABLE_LEN]; + EXP_FRAC_TABLE_A = new double[AccurateMath.EXP_FRAC_TABLE_LEN]; + EXP_FRAC_TABLE_B = new double[AccurateMath.EXP_FRAC_TABLE_LEN]; final double tmp[] = new double[2]; // Populate expFracTable final double factor = 1d / (EXP_FRAC_TABLE_LEN - 1); for (int i = 0; i < EXP_FRAC_TABLE_A.length; i++) { - FastMathCalc.slowexp(i * factor, tmp); + AccurateMathCalc.slowexp(i * factor, tmp); EXP_FRAC_TABLE_A[i] = tmp[0]; EXP_FRAC_TABLE_B[i] = tmp[1]; } } else { - EXP_FRAC_TABLE_A = FastMathLiteralArrays.loadExpFracA(); - EXP_FRAC_TABLE_B = FastMathLiteralArrays.loadExpFracB(); + EXP_FRAC_TABLE_A = AccurateMathLiteralArrays.loadExpFracA(); + EXP_FRAC_TABLE_B = AccurateMathLiteralArrays.loadExpFracB(); } } } @@ -4266,15 +4266,15 @@ public class FastMath { static { if (RECOMPUTE_TABLES_AT_RUNTIME) { - LN_MANT = new double[FastMath.LN_MANT_LEN][]; + LN_MANT = new double[AccurateMath.LN_MANT_LEN][]; // Populate lnMant table for (int i = 0; i < LN_MANT.length; i++) { final double d = Double.longBitsToDouble( (((long) i) << 42) | 0x3ff0000000000000L ); - LN_MANT[i] = FastMathCalc.slowLog(d); + LN_MANT[i] = AccurateMathCalc.slowLog(d); } } else { - LN_MANT = FastMathLiteralArrays.loadLnMant(); + LN_MANT = AccurateMathLiteralArrays.loadLnMant(); } } } diff --git a/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathCalc.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathCalc.java new file mode 100644 index 000000000..bb189f211 --- /dev/null +++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathCalc.java @@ -0,0 +1,658 @@ +/* + * 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.legacy.core.jdkmath; + +import java.io.PrintStream; + +import org.apache.commons.math4.legacy.exception.DimensionMismatchException; + +/** Class used to compute the classical functions tables. + * @since 3.0 + */ +class AccurateMathCalc { + + /** + * 0x40000000 - used to split a double into two parts, both with the low order bits cleared. + * Equivalent to 2^30. + */ + private static final long HEX_40000000 = 0x40000000L; // 1073741824L + + /** Factorial table, for Taylor series expansions. 0!, 1!, 2!, ... 19! */ + private static final double FACT[] = new double[] + { + +1.0d, // 0 + +1.0d, // 1 + +2.0d, // 2 + +6.0d, // 3 + +24.0d, // 4 + +120.0d, // 5 + +720.0d, // 6 + +5040.0d, // 7 + +40320.0d, // 8 + +362880.0d, // 9 + +3628800.0d, // 10 + +39916800.0d, // 11 + +479001600.0d, // 12 + +6227020800.0d, // 13 + +87178291200.0d, // 14 + +1307674368000.0d, // 15 + +20922789888000.0d, // 16 + +355687428096000.0d, // 17 + +6402373705728000.0d, // 18 + +121645100408832000.0d, // 19 + }; + + /** Coefficients for slowLog. */ + private static final double LN_SPLIT_COEF[][] = { + {2.0, 0.0}, + {0.6666666269302368, 3.9736429850260626E-8}, + {0.3999999761581421, 2.3841857910019882E-8}, + {0.2857142686843872, 1.7029898543501842E-8}, + {0.2222222089767456, 1.3245471311735498E-8}, + {0.1818181574344635, 2.4384203044354907E-8}, + {0.1538461446762085, 9.140260083262505E-9}, + {0.13333332538604736, 9.220590270857665E-9}, + {0.11764700710773468, 1.2393345855018391E-8}, + {0.10526403784751892, 8.251545029714408E-9}, + {0.0952233225107193, 1.2675934823758863E-8}, + {0.08713622391223907, 1.1430250008909141E-8}, + {0.07842259109020233, 2.404307984052299E-9}, + {0.08371849358081818, 1.176342548272881E-8}, + {0.030589580535888672, 1.2958646899018938E-9}, + {0.14982303977012634, 1.225743062930824E-8}, + }; + + /** Table start declaration. */ + private static final String TABLE_START_DECL = " {"; + + /** Table end declaration. */ + private static final String TABLE_END_DECL = " };"; + + /** + * Private Constructor. + */ + private AccurateMathCalc() { + } + + /** Build the sine and cosine tables. + * @param SINE_TABLE_A table of the most significant part of the sines + * @param SINE_TABLE_B table of the least significant part of the sines + * @param COSINE_TABLE_A table of the most significant part of the cosines + * @param COSINE_TABLE_B table of the most significant part of the cosines + * @param SINE_TABLE_LEN length of the tables + * @param TANGENT_TABLE_A table of the most significant part of the tangents + * @param TANGENT_TABLE_B table of the most significant part of the tangents + */ + @SuppressWarnings("unused") + private static void buildSinCosTables(double[] SINE_TABLE_A, double[] SINE_TABLE_B, + double[] COSINE_TABLE_A, double[] COSINE_TABLE_B, + int SINE_TABLE_LEN, double[] TANGENT_TABLE_A, double[] TANGENT_TABLE_B) { + final double result[] = new double[2]; + + /* Use taylor series for 0 <= x <= 6/8 */ + for (int i = 0; i < 7; i++) { + double x = i / 8.0; + + slowSin(x, result); + SINE_TABLE_A[i] = result[0]; + SINE_TABLE_B[i] = result[1]; + + slowCos(x, result); + COSINE_TABLE_A[i] = result[0]; + COSINE_TABLE_B[i] = result[1]; + } + + /* Use angle addition formula to complete table to 13/8, just beyond pi/2 */ + for (int i = 7; i < SINE_TABLE_LEN; i++) { + double xs[] = new double[2]; + double ys[] = new double[2]; + double as[] = new double[2]; + double bs[] = new double[2]; + double temps[] = new double[2]; + + if ( (i & 1) == 0) { + // Even, use double angle + xs[0] = SINE_TABLE_A[i/2]; + xs[1] = SINE_TABLE_B[i/2]; + ys[0] = COSINE_TABLE_A[i/2]; + ys[1] = COSINE_TABLE_B[i/2]; + + /* compute sine */ + splitMult(xs, ys, result); + SINE_TABLE_A[i] = result[0] * 2.0; + SINE_TABLE_B[i] = result[1] * 2.0; + + /* Compute cosine */ + splitMult(ys, ys, as); + splitMult(xs, xs, temps); + temps[0] = -temps[0]; + temps[1] = -temps[1]; + splitAdd(as, temps, result); + COSINE_TABLE_A[i] = result[0]; + COSINE_TABLE_B[i] = result[1]; + } else { + xs[0] = SINE_TABLE_A[i/2]; + xs[1] = SINE_TABLE_B[i/2]; + ys[0] = COSINE_TABLE_A[i/2]; + ys[1] = COSINE_TABLE_B[i/2]; + as[0] = SINE_TABLE_A[i/2+1]; + as[1] = SINE_TABLE_B[i/2+1]; + bs[0] = COSINE_TABLE_A[i/2+1]; + bs[1] = COSINE_TABLE_B[i/2+1]; + + /* compute sine */ + splitMult(xs, bs, temps); + splitMult(ys, as, result); + splitAdd(result, temps, result); + SINE_TABLE_A[i] = result[0]; + SINE_TABLE_B[i] = result[1]; + + /* Compute cosine */ + splitMult(ys, bs, result); + splitMult(xs, as, temps); + temps[0] = -temps[0]; + temps[1] = -temps[1]; + splitAdd(result, temps, result); + COSINE_TABLE_A[i] = result[0]; + COSINE_TABLE_B[i] = result[1]; + } + } + + /* Compute tangent = sine/cosine */ + for (int i = 0; i < SINE_TABLE_LEN; i++) { + double xs[] = new double[2]; + double ys[] = new double[2]; + double as[] = new double[2]; + + as[0] = COSINE_TABLE_A[i]; + as[1] = COSINE_TABLE_B[i]; + + splitReciprocal(as, ys); + + xs[0] = SINE_TABLE_A[i]; + xs[1] = SINE_TABLE_B[i]; + + splitMult(xs, ys, as); + + TANGENT_TABLE_A[i] = as[0]; + TANGENT_TABLE_B[i] = as[1]; + } + + } + + /** + * For x between 0 and pi/4 compute cosine using Talor series + * cos(x) = 1 - x^2/2! + x^4/4! ... + * @param x number from which cosine is requested + * @param result placeholder where to put the result in extended precision + * (may be null) + * @return cos(x) + */ + static double slowCos(final double x, final double result[]) { + + final double xs[] = new double[2]; + final double ys[] = new double[2]; + final double facts[] = new double[2]; + final double as[] = new double[2]; + split(x, xs); + ys[0] = ys[1] = 0.0; + + for (int i = FACT.length-1; i >= 0; i--) { + splitMult(xs, ys, as); + ys[0] = as[0]; ys[1] = as[1]; + + if ( (i & 1) != 0) { // skip odd entries + continue; + } + + split(FACT[i], as); + splitReciprocal(as, facts); + + if ( (i & 2) != 0 ) { // alternate terms are negative + facts[0] = -facts[0]; + facts[1] = -facts[1]; + } + + splitAdd(ys, facts, as); + ys[0] = as[0]; ys[1] = as[1]; + } + + if (result != null) { + result[0] = ys[0]; + result[1] = ys[1]; + } + + return ys[0] + ys[1]; + } + + /** + * For x between 0 and pi/4 compute sine using Taylor expansion: + * sin(x) = x - x^3/3! + x^5/5! - x^7/7! ... + * @param x number from which sine is requested + * @param result placeholder where to put the result in extended precision + * (may be null) + * @return sin(x) + */ + static double slowSin(final double x, final double result[]) { + final double xs[] = new double[2]; + final double ys[] = new double[2]; + final double facts[] = new double[2]; + final double as[] = new double[2]; + split(x, xs); + ys[0] = ys[1] = 0.0; + + for (int i = FACT.length-1; i >= 0; i--) { + splitMult(xs, ys, as); + ys[0] = as[0]; ys[1] = as[1]; + + if ( (i & 1) == 0) { // Ignore even numbers + continue; + } + + split(FACT[i], as); + splitReciprocal(as, facts); + + if ( (i & 2) != 0 ) { // alternate terms are negative + facts[0] = -facts[0]; + facts[1] = -facts[1]; + } + + splitAdd(ys, facts, as); + ys[0] = as[0]; ys[1] = as[1]; + } + + if (result != null) { + result[0] = ys[0]; + result[1] = ys[1]; + } + + return ys[0] + ys[1]; + } + + + /** + * For x between 0 and 1, returns exp(x), uses extended precision + * @param x argument of exponential + * @param result placeholder where to place exp(x) split in two terms + * for extra precision (i.e. exp(x) = result[0] + result[1] + * @return exp(x) + */ + static double slowexp(final double x, final double result[]) { + final double xs[] = new double[2]; + final double ys[] = new double[2]; + final double facts[] = new double[2]; + final double as[] = new double[2]; + split(x, xs); + ys[0] = ys[1] = 0.0; + + for (int i = FACT.length-1; i >= 0; i--) { + splitMult(xs, ys, as); + ys[0] = as[0]; + ys[1] = as[1]; + + split(FACT[i], as); + splitReciprocal(as, facts); + + splitAdd(ys, facts, as); + ys[0] = as[0]; + ys[1] = as[1]; + } + + if (result != null) { + result[0] = ys[0]; + result[1] = ys[1]; + } + + return ys[0] + ys[1]; + } + + /** Compute split[0], split[1] such that their sum is equal to d, + * and split[0] has its 30 least significant bits as zero. + * @param d number to split + * @param split placeholder where to place the result + */ + private static void split(final double d, final double split[]) { + if (d < 8e298 && d > -8e298) { + final double a = d * HEX_40000000; + split[0] = (d + a) - a; + split[1] = d - split[0]; + } else { + final double a = d * 9.31322574615478515625E-10; + split[0] = (d + a - d) * HEX_40000000; + split[1] = d - split[0]; + } + } + + /** Recompute a split. + * @param a input/out array containing the split, changed + * on output + */ + private static void resplit(final double a[]) { + final double c = a[0] + a[1]; + final double d = -(c - a[0] - a[1]); + + if (c < 8e298 && c > -8e298) { // MAGIC NUMBER + double z = c * HEX_40000000; + a[0] = (c + z) - z; + a[1] = c - a[0] + d; + } else { + double z = c * 9.31322574615478515625E-10; + a[0] = (c + z - c) * HEX_40000000; + a[1] = c - a[0] + d; + } + } + + /** Multiply two numbers in split form. + * @param a first term of multiplication + * @param b second term of multiplication + * @param ans placeholder where to put the result + */ + private static void splitMult(double a[], double b[], double ans[]) { + ans[0] = a[0] * b[0]; + ans[1] = a[0] * b[1] + a[1] * b[0] + a[1] * b[1]; + + /* Resplit */ + resplit(ans); + } + + /** Add two numbers in split form. + * @param a first term of addition + * @param b second term of addition + * @param ans placeholder where to put the result + */ + private static void splitAdd(final double a[], final double b[], final double ans[]) { + ans[0] = a[0] + b[0]; + ans[1] = a[1] + b[1]; + + resplit(ans); + } + + /** Compute the reciprocal of in. Use the following algorithm. + * in = c + d. + * want to find x + y such that x+y = 1/(c+d) and x is much + * larger than y and x has several zero bits on the right. + * + * Set b = 1/(2^22), a = 1 - b. Thus (a+b) = 1. + * Use following identity to compute (a+b)/(c+d) + * + * (a+b)/(c+d) = a/c + (bc - ad) / (c^2 + cd) + * set x = a/c and y = (bc - ad) / (c^2 + cd) + * This will be close to the right answer, but there will be + * some rounding in the calculation of X. So by carefully + * computing 1 - (c+d)(x+y) we can compute an error and + * add that back in. This is done carefully so that terms + * of similar size are subtracted first. + * @param in initial number, in split form + * @param result placeholder where to put the result + */ + static void splitReciprocal(final double in[], final double result[]) { + final double b = 1.0/4194304.0; + final double a = 1.0 - b; + + if (in[0] == 0.0) { + in[0] = in[1]; + in[1] = 0.0; + } + + result[0] = a / in[0]; + result[1] = (b*in[0]-a*in[1]) / (in[0]*in[0] + in[0]*in[1]); + + if (result[1] != result[1]) { // can happen if result[1] is NAN + result[1] = 0.0; + } + + /* Resplit */ + resplit(result); + + for (int i = 0; i < 2; i++) { + /* this may be overkill, probably once is enough */ + double err = 1.0 - result[0] * in[0] - result[0] * in[1] - + result[1] * in[0] - result[1] * in[1]; + /*err = 1.0 - err; */ + err *= result[0] + result[1]; + /*printf("err = %16e\n", err); */ + result[1] += err; + } + } + + /** Compute (a[0] + a[1]) * (b[0] + b[1]) in extended precision. + * @param a first term of the multiplication + * @param b second term of the multiplication + * @param result placeholder where to put the result + */ + private static void quadMult(final double a[], final double b[], final double result[]) { + final double xs[] = new double[2]; + final double ys[] = new double[2]; + final double zs[] = new double[2]; + + /* a[0] * b[0] */ + split(a[0], xs); + split(b[0], ys); + splitMult(xs, ys, zs); + + result[0] = zs[0]; + result[1] = zs[1]; + + /* a[0] * b[1] */ + split(b[1], ys); + splitMult(xs, ys, zs); + + double tmp = result[0] + zs[0]; + result[1] -= tmp - result[0] - zs[0]; + result[0] = tmp; + tmp = result[0] + zs[1]; + result[1] -= tmp - result[0] - zs[1]; + result[0] = tmp; + + /* a[1] * b[0] */ + split(a[1], xs); + split(b[0], ys); + splitMult(xs, ys, zs); + + tmp = result[0] + zs[0]; + result[1] -= tmp - result[0] - zs[0]; + result[0] = tmp; + tmp = result[0] + zs[1]; + result[1] -= tmp - result[0] - zs[1]; + result[0] = tmp; + + /* a[1] * b[0] */ + split(a[1], xs); + split(b[1], ys); + splitMult(xs, ys, zs); + + tmp = result[0] + zs[0]; + result[1] -= tmp - result[0] - zs[0]; + result[0] = tmp; + tmp = result[0] + zs[1]; + result[1] -= tmp - result[0] - zs[1]; + result[0] = tmp; + } + + /** Compute exp(p) for a integer p in extended precision. + * @param p integer whose exponential is requested + * @param result placeholder where to put the result in extended precision + * @return exp(p) in standard precision (equal to result[0] + result[1]) + */ + static double expint(int p, final double result[]) { + //double x = M_E; + final double xs[] = new double[2]; + final double as[] = new double[2]; + final double ys[] = new double[2]; + //split(x, xs); + //xs[1] = (double)(2.7182818284590452353602874713526625L - xs[0]); + //xs[0] = 2.71827697753906250000; + //xs[1] = 4.85091998273542816811e-06; + //xs[0] = Double.longBitsToDouble(0x4005bf0800000000L); + //xs[1] = Double.longBitsToDouble(0x3ed458a2bb4a9b00L); + + /* E */ + xs[0] = 2.718281828459045; + xs[1] = 1.4456468917292502E-16; + + split(1.0, ys); + + while (p > 0) { + if ((p & 1) != 0) { + quadMult(ys, xs, as); + ys[0] = as[0]; ys[1] = as[1]; + } + + quadMult(xs, xs, as); + xs[0] = as[0]; xs[1] = as[1]; + + p >>= 1; + } + + if (result != null) { + result[0] = ys[0]; + result[1] = ys[1]; + + resplit(result); + } + + return ys[0] + ys[1]; + } + /** xi in the range of [1, 2]. + * 3 5 7 + * x+1 / x x x \ + * ln ----- = 2 * | x + ---- + ---- + ---- + ... | + * 1-x \ 3 5 7 / + * + * So, compute a Remez approximation of the following function + * + * ln ((sqrt(x)+1)/(1-sqrt(x))) / x + * + * This will be an even function with only positive coefficents. + * x is in the range [0 - 1/3]. + * + * Transform xi for input to the above function by setting + * x = (xi-1)/(xi+1). Input to the polynomial is x^2, then + * the result is multiplied by x. + * @param xi number from which log is requested + * @return log(xi) + */ + static double[] slowLog(double xi) { + double x[] = new double[2]; + double x2[] = new double[2]; + double y[] = new double[2]; + double a[] = new double[2]; + + split(xi, x); + + /* Set X = (x-1)/(x+1) */ + x[0] += 1.0; + resplit(x); + splitReciprocal(x, a); + x[0] -= 2.0; + resplit(x); + splitMult(x, a, y); + x[0] = y[0]; + x[1] = y[1]; + + /* Square X -> X2*/ + splitMult(x, x, x2); + + + //x[0] -= 1.0; + //resplit(x); + + y[0] = LN_SPLIT_COEF[LN_SPLIT_COEF.length-1][0]; + y[1] = LN_SPLIT_COEF[LN_SPLIT_COEF.length-1][1]; + + for (int i = LN_SPLIT_COEF.length-2; i >= 0; i--) { + splitMult(y, x2, a); + y[0] = a[0]; + y[1] = a[1]; + splitAdd(y, LN_SPLIT_COEF[i], a); + y[0] = a[0]; + y[1] = a[1]; + } + + splitMult(y, x, a); + y[0] = a[0]; + y[1] = a[1]; + + return y; + } + + + /** + * Print an array. + * @param out text output stream where output should be printed + * @param name array name + * @param expectedLen expected length of the array + * @param array2d array data + */ + static void printarray(PrintStream out, String name, int expectedLen, double[][] array2d) { + out.println(name); + checkLen(expectedLen, array2d.length); + out.println(TABLE_START_DECL + " "); + int i = 0; + for(double[] array : array2d) { // "double array[]" causes PMD parsing error + out.print(" {"); + for(double d : array) { // assume inner array has very few entries + out.printf("%-25.25s", format(d)); // multiple entries per line + } + out.println("}, // " + i++); + } + out.println(TABLE_END_DECL); + } + + /** + * Print an array. + * @param out text output stream where output should be printed + * @param name array name + * @param expectedLen expected length of the array + * @param array array data + */ + static void printarray(PrintStream out, String name, int expectedLen, double[] array) { + out.println(name + "="); + checkLen(expectedLen, array.length); + out.println(TABLE_START_DECL); + for(double d : array){ + out.printf(" %s%n", format(d)); // one entry per line + } + out.println(TABLE_END_DECL); + } + + /** Format a double. + * @param d double number to format + * @return formatted number + */ + static String format(double d) { + if (d != d) { + return "Double.NaN,"; + } else { + return ((d >= 0) ? "+" : "") + Double.toString(d) + "d,"; + } + } + + /** + * Check two lengths are equal. + * @param expectedLen expected length + * @param actual actual length + * @exception DimensionMismatchException if the two lengths are not equal + */ + private static void checkLen(int expectedLen, int actual) + throws DimensionMismatchException { + if (expectedLen != actual) { + throw new DimensionMismatchException(actual, expectedLen); + } + } + +} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMathCalc.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathCalc.java.bak similarity index 99% rename from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMathCalc.java rename to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathCalc.java.bak index 342d4b28f..13ff2f18f 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMathCalc.java +++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathCalc.java.bak @@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException; /** Class used to compute the classical functions tables. * @since 3.0 */ -class FastMathCalc { +class AccurateMathCalc { /** * 0x40000000 - used to split a double into two parts, both with the low order bits cleared. @@ -85,7 +85,7 @@ class FastMathCalc { /** * Private Constructor. */ - private FastMathCalc() { + private AccurateMathCalc() { } /** Build the sine and cosine tables. diff --git a/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathLiteralArrays.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathLiteralArrays.java new file mode 100644 index 000000000..6461eac79 --- /dev/null +++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathLiteralArrays.java @@ -0,0 +1,6175 @@ +/* + * 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.legacy.core.jdkmath; + +/** + * Utility class for loading tabulated data used by {@link AccurateMath}. + * + */ +class AccurateMathLiteralArrays { + /** Exponential evaluated at integer values, + * exp(x) = expIntTableA[x + EXP_INT_TABLE_MAX_INDEX] + expIntTableB[x+EXP_INT_TABLE_MAX_INDEX]. + */ + private static final double[] EXP_INT_A = new double[] { + +0.0d, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + +1.2167807682331913E-308d, + +3.3075532478807267E-308d, + +8.990862214387203E-308d, + +2.4439696075216986E-307d, + +6.64339758024534E-307d, + +1.8058628951432254E-306d, + +4.908843759498681E-306d, + +1.334362017065677E-305d, + +3.627172425759641E-305d, + +9.85967600992008E-305d, + +2.680137967689915E-304d, + +7.285370725133842E-304d, + +1.9803689272433392E-303d, + +5.3832011494782624E-303d, + +1.463305638201413E-302d, + +3.9776772027043775E-302d, + +1.0812448255518705E-301d, + +2.9391280956327795E-301d, + +7.989378677301346E-301d, + +2.1717383041010577E-300d, + +5.903396499766243E-300d, + +1.604709595901607E-299d, + +4.3620527352131126E-299d, + +1.1857289715706991E-298d, + +3.2231452986239366E-298d, + +8.761416875971053E-298d, + +2.381600167287677E-297d, + +6.473860152384321E-297d, + +1.7597776278732318E-296d, + +4.7835721669653157E-296d, + +1.3003096668152053E-295d, + +3.5346080979652066E-295d, + +9.608060944124859E-295d, + +2.6117415961302846E-294d, + +7.099449830809996E-294d, + +1.9298305829106006E-293d, + +5.245823134132673E-293d, + +1.4259627797225802E-292d, + +3.8761686729764145E-292d, + +1.0536518897078156E-291d, + +2.864122672853628E-291d, + +7.785491934690374E-291d, + +2.116316283183901E-290d, + +5.7527436249968E-290d, + +1.5637579898345352E-289d, + +4.250734424415339E-289d, + +1.1554696041977512E-288d, + +3.1408919441362495E-288d, + +8.537829238438662E-288d, + +2.320822576772103E-287d, + +6.308649765138419E-287d, + +1.7148689119310826E-286d, + +4.66149719271323E-286d, + +1.267126226441217E-285d, + +3.444406231880653E-285d, + +9.362866914115166E-285d, + +2.5450911557068313E-284d, + +6.918275021321188E-284d, + +1.880582039589629E-283d, + +5.111952261540649E-283d, + +1.3895726688907995E-282d, + +3.7772500667438066E-282d, + +1.026763015362553E-281d, + +2.791031173360063E-281d, + +7.586808748646825E-281d, + +2.0623086887184633E-280d, + +5.605936171588964E-280d, + +1.5238514098804918E-279d, + +4.1422578754033235E-279d, + +1.1259823210174452E-278d, + +3.060737220976933E-278d, + +8.319947089683576E-278d, + +2.2615958035357106E-277d, + +6.147655179898435E-277d, + +1.6711060014400145E-276d, + +4.542536646012133E-276d, + +1.2347896500246374E-275d, + +3.3565057475434694E-275d, + +9.123929070778758E-275d, + +2.4801413921885483E-274d, + +6.741722283079056E-274d, + +1.8325902719086093E-273d, + +4.981496462621207E-273d, + +1.3541112064618357E-272d, + +3.68085620656127E-272d, + +1.0005602916630382E-271d, + +2.719805132368625E-271d, + +7.393196131284108E-271d, + +2.0096791226867E-270d, + +5.462874707256208E-270d, + +1.4849631831943512E-269d, + +4.036548930895323E-269d, + +1.0972476870931676E-268d, + +2.9826282194717127E-268d, + +8.107624153838987E-268d, + +2.2038806519542315E-267d, + +5.990769236615968E-267d, + +1.628459873440512E-266d, + +4.4266130556431266E-266d, + +1.203278237867575E-265d, + +3.270849446965521E-265d, + +8.891090288030614E-265d, + +2.4168487931443637E-264d, + +6.569676185250389E-264d, + +1.7858231429575898E-263d, + +4.85437090269903E-263d, + +1.3195548295785448E-262d, + +3.5869215528816054E-262d, + +9.750264097807267E-262d, + +2.650396454019762E-261d, + +7.204525142098426E-261d, + +1.958392846081373E-260d, + +5.32346341339996E-260d, + +1.4470673509275515E-259d, + +3.9335373658569176E-259d, + +1.0692462289051038E-258d, + +2.9065128598079075E-258d, + +7.900720862969045E-258d, + +2.147638465376883E-257d, + +5.8378869339035456E-257d, + +1.5869022483809747E-256d, + +4.3136475849391444E-256d, + +1.1725710340687719E-255d, + +3.1873780814410126E-255d, + +8.66419234315257E-255d, + +2.35517168886351E-254d, + +6.402020300783889E-254d, + +1.740249660600677E-253d, + +4.7304887145310405E-253d, + +1.2858802448614707E-252d, + +3.495384792953975E-252d, + +9.501439740542955E-252d, + +2.582759362004277E-251d, + +7.020668578160457E-251d, + +1.908415302517694E-250d, + +5.1876107490791666E-250d, + +1.4101386971763257E-249d, + +3.8331545111676784E-249d, + +1.0419594359065132E-248d, + +2.8323395451363237E-248d, + +7.699097067385825E-248d, + +2.0928317096428755E-247d, + +5.688906371296133E-247d, + +1.5464049837965422E-246d, + +4.2035646586788297E-246d, + +1.1426473877336358E-245d, + +3.106037603716254E-245d, + +8.443084996839363E-245d, + +2.2950686306677644E-244d, + +6.238642390386363E-244d, + +1.695838923802857E-243d, + +4.6097680405580995E-243d, + +1.2530649392922358E-242d, + +3.4061835424180075E-242d, + +9.25896798127602E-242d, + +2.5168480541429286E-241d, + +6.841502859109196E-241d, + +1.8597132378953187E-240d, + +5.055224959032211E-240d, + +1.374152583940637E-239d, + +3.735333866258403E-239d, + +1.0153690688015855E-238d, + +2.7600590782738726E-238d, + +7.502618487550056E-238d, + +2.0394233446495043E-237d, + +5.543727690168612E-237d, + +1.5069412868172555E-236d, + +4.0962906236847E-236d, + +1.1134873918971586E-235d, + +3.026772467749944E-235d, + +8.227620163729258E-235d, + +2.2364990583200056E-234d, + +6.079434951446575E-234d, + +1.6525617499662284E-233d, + +4.4921289690525345E-233d, + +1.2210872189854344E-232d, + +3.3192593301633E-232d, + +9.02268127425393E-232d, + +2.4526190464373087E-231d, + +6.666909874218774E-231d, + +1.8122539547625083E-230d, + +4.926216840507529E-230d, + +1.3390847149416908E-229d, + +3.6400093808551196E-229d, + +9.894571625944288E-229d, + +2.689623698321582E-228d, + +7.31115423069187E-228d, + +1.9873779569310022E-227d, + +5.402252865260326E-227d, + +1.4684846983789053E-226d, + +3.991755413823315E-226d, + +1.0850715739509136E-225d, + +2.9495302004590423E-225d, + +8.017654713159388E-225d, + +2.179424521221378E-224d, + +5.924290380648597E-224d, + +1.6103890140790331E-223d, + +4.377491272857675E-223d, + +1.1899254154663847E-222d, + +3.2345523990372546E-222d, + +8.792425221770645E-222d, + +2.3900289095512176E-221d, + +6.496772856703278E-221d, + +1.7660059778220905E-220d, + +4.800501435803201E-220d, + +1.3049116216750674E-219d, + +3.5471180281159325E-219d, + +9.642065709892252E-219d, + +2.6209850274990846E-218d, + +7.124574366530717E-218d, + +1.9366601417010147E-217d, + +5.264388476949737E-217d, + +1.431009021985696E-216d, + +3.889885799962507E-216d, + +1.057380684430436E-215d, + +2.8742587656021775E-215d, + +7.813044552050569E-215d, + +2.1238058974550874E-214d, + +5.773102661099307E-214d, + +1.5692921723471877E-213d, + +4.2657777816050375E-213d, + +1.1595585743839232E-212d, + +3.1520070828798975E-212d, + +8.568043768122183E-212d, + +2.329035966595791E-211d, + +6.33097561889469E-211d, + +1.720937714565362E-210d, + +4.677993239821998E-210d, + +1.2716105485691878E-209d, + +3.456595573934475E-209d, + +9.396000024637834E-209d, + +2.55409795397022E-208d, + +6.942757623821567E-208d, + +1.887237361505784E-207d, + +5.13004286606108E-207d, + +1.3944901709366118E-206d, + +3.7906173667738715E-206d, + +1.0303966192973381E-205d, + +2.8009086220877197E-205d, + +7.613657850210907E-205d, + +2.0696069842597556E-204d, + +5.6257755605305175E-204d, + +1.5292444435954893E-203d, + +4.156916476922876E-203d, + +1.12996721591364E-202d, + +3.071569248856111E-202d, + +8.349390727162016E-202d, + +2.2695999828608633E-201d, + +6.1694117899971836E-201d, + +1.677020107827128E-200d, + +4.558612479525779E-200d, + +1.2391595516612638E-199d, + +3.3683846288580648E-199d, + +9.156218120779494E-199d, + +2.4889182184335247E-198d, + +6.765580431441772E-198d, + +1.839075686473352E-197d, + +4.999126524757713E-197d, + +1.3589033107846643E-196d, + +3.6938826366068014E-196d, + +1.0041012794280992E-195d, + +2.7294301888986675E-195d, + +7.419361045185406E-195d, + +2.016791373353671E-194d, + +5.482208065983983E-194d, + +1.490218341008089E-193d, + +4.050833763855709E-193d, + +1.101130773265179E-192d, + +2.993183789477209E-192d, + +8.136316299122392E-192d, + +2.2116799789922265E-191d, + +6.011969568315371E-191d, + +1.6342228966392253E-190d, + +4.4422779589171113E-190d, + +1.2075364784547675E-189d, + +3.282424571107068E-189d, + +8.92255448602772E-189d, + +2.425402115319395E-188d, + +6.592926904915355E-188d, + +1.79214305133496E-187d, + +4.871550528055661E-187d, + +1.3242245776666673E-186d, + +3.599615946028287E-186d, + +9.78476998200719E-186d, + +2.659776075359514E-185d, + +7.230020851688713E-185d, + +1.9653234116333892E-184d, + +5.34230278107224E-184d, + +1.4521887058451231E-183d, + +3.947457923821984E-183d, + +1.0730302255093144E-182d, + +2.9167986204137332E-182d, + +7.928680793406766E-182d, + +2.1552386987482013E-181d, + +5.858546779607288E-181d, + +1.5925182066949723E-180d, + +4.328913614497258E-180d, + +1.1767205227552116E-179d, + +3.198658219194836E-179d, + +8.694853785564504E-179d, + +2.363506255864984E-178d, + +6.42467573615509E-178d, + +1.746408207555959E-177d, + +4.747229597770176E-177d, + +1.2904307529671472E-176d, + +3.507754341050756E-176d, + +9.535066345267336E-176d, + +2.591899541396432E-175d, + +7.045512786902009E-175d, + +1.9151693415969248E-174d, + +5.205969622575851E-174d, + +1.4151292367806538E-173d, + +3.846720258072078E-173d, + +1.045647032279984E-172d, + +2.8423629805010285E-172d, + +7.726344058192276E-172d, + +2.1002377128928765E-171d, + +5.709039546124285E-171d, + +1.5518778128928824E-170d, + +4.218440703602533E-170d, + +1.1466910691560932E-169d, + +3.1170298734336303E-169d, + +8.472965161251656E-169d, + +2.303190374523956E-168d, + +6.260720440258473E-168d, + +1.701840523821621E-167d, + +4.62608152166211E-167d, + +1.2574995962791943E-166d, + +3.418237608335161E-166d, + +9.29173407843235E-166d, + +2.5257552661512635E-165d, + +6.865714679174435E-165d, + +1.866294830116931E-164d, + +5.073114566291778E-164d, + +1.3790154522394582E-163d, + +3.7485528226129495E-163d, + +1.0189624503698769E-162d, + +2.7698267293941856E-162d, + +7.529170882336924E-162d, + +2.0466404088178596E-161d, + +5.56334611651382E-161d, + +1.512274346576166E-160d, + +4.110787043867721E-160d, + +1.1174279267498045E-159d, + +3.0374839443564585E-159d, + +8.25673801176584E-159d, + +2.244414150254963E-158d, + +6.1009492034592176E-158d, + +1.6584100275603453E-157d, + +4.50802633729044E-157d, + +1.2254085656601853E-156d, + +3.3310057014599044E-156d, + +9.054612259832416E-156d, + +2.4612985502035675E-155d, + +6.690503835950083E-155d, + +1.8186679660152888E-154d, + +4.9436516047443576E-154d, + +1.3438240331106108E-153d, + +3.652892398145774E-153d, + +9.92958982547828E-153d, + +2.6991427376823027E-152d, + +7.3370297995122135E-152d, + +1.994411660450821E-151d, + +5.421372463189529E-151d, + +1.4736818914204564E-150d, + +4.005882964287806E-150d, + +1.088911919926534E-149d, + +2.9599693109692324E-149d, + +8.046030012041041E-149d, + +2.18713790898745E-148d, + +5.945256705384597E-148d, + +1.6160884846515524E-147d, + +4.392983574030969E-147d, + +1.1941366764543551E-146d, + +3.2460001983475855E-146d, + +8.8235440586675E-146d, + +2.3984878190403553E-145d, + +6.519765758635405E-145d, + +1.772256261139753E-144d, + +4.817491674217065E-144d, + +1.3095299991573769E-143d, + +3.559671483107555E-143d, + +9.676190774054103E-143d, + +2.630261301303634E-142d, + +7.149792225695347E-142d, + +1.943514969662872E-141d, + +5.283020542151163E-141d, + +1.4360739330834996E-140d, + +3.9036541111764032E-140d, + +1.0611230602364477E-139d, + +2.8844319473099593E-139d, + +7.84069876400596E-139d, + +2.1313228444765414E-138d, + +5.793536445518422E-138d, + +1.5748463788034308E-137d, + +4.2808762411845363E-137d, + +1.1636629220608724E-136d, + +3.163163464591171E-136d, + +8.598369704466743E-136d, + +2.337279322276433E-135d, + +6.353384093665193E-135d, + +1.7270287031459572E-134d, + +4.694550492773212E-134d, + +1.2761111606368036E-133d, + +3.4688299108856403E-133d, + +9.429257929713919E-133d, + +2.5631381141873417E-132d, + +6.967331001069377E-132d, + +1.8939170679975288E-131d, + +5.148199748336684E-131d, + +1.3994258162094293E-130d, + +3.804034213613942E-130d, + +1.0340436948077763E-129d, + +2.8108219632627907E-129d, + +7.640606938467665E-129d, + +2.0769322678328357E-128d, + +5.645687086879944E-128d, + +1.5346568127351796E-127d, + +4.171630237420918E-127d, + +1.1339665711932977E-126d, + +3.0824406750909563E-126d, + +8.37894218404787E-126d, + +2.2776327994966818E-125d, + +6.191247522703296E-125d, + +1.6829556040859853E-124d, + +4.5747479502862494E-124d, + +1.2435453481209945E-123d, + +3.3803067202247166E-123d, + +9.188625696750548E-123d, + +2.4977273040076145E-122d, + +6.789527378582775E-122d, + +1.845584943222965E-121d, + +5.016820182185716E-121d, + +1.3637129731022491E-120d, + +3.706956710275979E-120d, + +1.0076552294433743E-119d, + +2.739090595934893E-119d, + +7.445620503219039E-119d, + +2.023929422267303E-118d, + +5.501611507503037E-118d, + +1.4954928881576769E-117d, + +4.0651709187617596E-117d, + +1.1050280679513555E-116d, + +3.003777734030334E-116d, + +8.165114384910189E-116d, + +2.219508285637377E-115d, + +6.033249389304709E-115d, + +1.6400070480930697E-114d, + +4.458001565878111E-114d, + +1.2118105325725891E-113d, + +3.2940421731384895E-113d, + +8.954135150208654E-113d, + +2.433986351722258E-112d, + +6.616260705434716E-112d, + +1.7984863104885375E-111d, + +4.888792154132158E-111d, + +1.3289115531074511E-110d, + +3.612356038181234E-110d, + +9.819402293160495E-110d, + +2.6691899766673256E-109d, + +7.255611264437603E-109d, + +1.9722796756250217E-108d, + +5.361211684173837E-108d, + +1.4573285967670963E-107d, + +3.961429477016909E-107d, + +1.0768281419102595E-106d, + +2.9271223293841774E-106d, + +7.956744351476403E-106d, + +2.1628672925745152E-105d, + +5.879282834821692E-105d, + +1.5981547034872092E-104d, + +4.344234755347641E-104d, + +1.1808855501885005E-103d, + +3.2099795870407646E-103d, + +8.725629524586503E-103d, + +2.3718718327094683E-102d, + +6.44741641521183E-102d, + +1.7525895549820557E-101d, + +4.7640323331013947E-101d, + +1.2949980563724296E-100d, + +3.5201699899499525E-100d, + +9.56881327374431E-100d, + +2.6010732940533088E-99d, + +7.070450309820548E-99d, + +1.9219478787856753E-98d, + +5.2243955659975294E-98d, + +1.4201378353978042E-97d, + +3.8603349913851996E-97d, + +1.0493479260117497E-96d, + +2.8524232604238555E-96d, + +7.753690709912764E-96d, + +2.1076716069929933E-95d, + +5.72924572981599E-95d, + +1.5573703263204683E-94d, + +4.233371554108682E-94d, + +1.1507496472539512E-93d, + +3.1280620563875923E-93d, + +8.5029538631631E-93d, + +2.3113425190436427E-92d, + +6.28287989314225E-92d, + +1.7078641226055994E-91d, + +4.6424556110307644E-91d, + +1.261950308999819E-90d, + +3.430336362898836E-90d, + +9.324622137237299E-90d, + +2.5346947846365435E-89d, + +6.890014851450124E-89d, + +1.8729003560057785E-88d, + +5.091070300111434E-88d, + +1.3838964592430477E-87d, + +3.761820584522275E-87d, + +1.0225689628581036E-86d, + +2.7796303536272215E-86d, + +7.555818934379333E-86d, + +2.053884626293416E-85d, + +5.583037134407759E-85d, + +1.5176268538776042E-84d, + +4.125337057189083E-84d, + +1.121383042095528E-83d, + +3.0482348236054953E-83d, + +8.285962249116636E-83d, + +2.2523580600947705E-82d, + +6.122543452787843E-82d, + +1.664279766968299E-81d, + +4.523982262003404E-81d, + +1.2297456769063303E-80d, + +3.342795345742034E-80d, + +9.086660081726823E-80d, + +2.4700104681773258E-79d, + +6.714184569587689E-79d, + +1.8251046352720517E-78d, + +4.961148056969105E-78d, + +1.3485799924445315E-77d, + +3.665820371396835E-77d, + +9.964732578705785E-77d, + +2.708695208461993E-76d, + +7.362996533913695E-76d, + +2.0014700145557332E-75d, + +5.440559532453721E-75d, + +1.4788974793889734E-74d, + +4.020060558571273E-74d, + +1.092765612182012E-73d, + +2.970445258959489E-73d, + +8.074507236705857E-73d, + +2.1948784599535102E-72d, + +5.966298125808066E-72d, + +1.6218081151910012E-71d, + +4.408531734441582E-71d, + +1.198363039426718E-70d, + +3.257488853378793E-70d, + +8.854771398921902E-70d, + +2.406976727302894E-69d, + +6.542840888268955E-69d, + +1.778528517418201E-68d, + +4.834541417183388E-68d, + +1.3141647465063647E-67d, + +3.572270133517001E-67d, + +9.710435805122717E-67d, + +2.63957027915428E-66d, + +7.175096392165733E-66d, + +1.9503931430716318E-65d, + +5.3017188565638215E-65d, + +1.4411566290936352E-64d, + +3.9174693825966044E-64d, + +1.0648786018364265E-63d, + +2.8946401383311E-63d, + +7.868447965383903E-63d, + +2.1388659707647114E-62d, + +5.814040618670345E-62d, + +1.5804200403673568E-61d, + +4.296027044486766E-61d, + +1.1677812418806031E-60d, + +3.174358801839755E-60d, + +8.62880163941313E-60d, + +2.345551464945955E-59d, + +6.3758692300917355E-59d, + +1.733140900346534E-58d, + +4.711165925070571E-58d, + +1.2806275683797178E-57d, + +3.481106736845E-57d, + +9.462629520363307E-57d, + +2.5722094667974783E-56d, + +6.9919903587080315E-56d, + +1.9006201022568844E-55d, + +5.166420404109835E-55d, + +1.4043786616805493E-54d, + +3.8174968984748894E-54d, + +1.03770335512154E-53d, + +2.820769858672565E-53d, + +7.667647949477605E-53d, + +2.0842827711783212E-52d, + +5.6656680900216754E-52d, + +1.5400881501571645E-51d, + +4.1863938339341257E-51d, + +1.1379799629071911E-50d, + +3.093350150840571E-50d, + +8.408597060399334E-50d, + +2.2856938448387544E-49d, + +6.2131591878042886E-49d, + +1.688911928929718E-48d, + +4.5909386437919143E-48d, + +1.2479464696643861E-47d, + +3.3922703599272275E-47d, + +9.221146830884422E-47d, + +2.5065676066043174E-46d, + +6.8135571305481364E-46d, + +1.8521166948363666E-45d, + +5.0345752964740226E-45d, + +1.368539456379101E-44d, + +3.720075801577098E-44d, + +1.0112214979786464E-43d, + +2.7487849807248755E-43d, + +7.47197247068667E-43d, + +2.0310928323153876E-42d, + +5.521082422279256E-42d, + +1.5007857288519654E-41d, + +4.0795586181406803E-41d, + +1.108938997126179E-40d, + +3.0144088843073416E-40d, + +8.194012195477669E-40d, + +2.2273635587196807E-39d, + +6.054601485195952E-39d, + +1.6458113136245473E-38d, + +4.473779311490168E-38d, + +1.2160992719555806E-37d, + +3.3057007442449645E-37d, + +8.985825281444118E-37d, + +2.442600707513088E-36d, + +6.639677673630215E-36d, + +1.8048513285848406E-35d, + +4.906094420881007E-35d, + +1.3336148713971936E-34d, + +3.625141007634431E-34d, + +9.854154449263851E-34d, + +2.6786368134431636E-33d, + +7.28128971953363E-33d, + +1.9792597720953414E-32d, + +5.380185921962174E-32d, + +1.4624861244004054E-31d, + +3.975449484028966E-31d, + +1.080639291795678E-30d, + +2.9374821418009058E-30d, + +7.984904044796711E-30d, + +2.1705221445447534E-29d, + +5.900089995748943E-29d, + +1.6038109389511792E-28d, + +4.359610133382778E-28d, + +1.185064946717304E-27d, + +3.221340469489223E-27d, + +8.756510122348782E-27d, + +2.380266370880709E-26d, + +6.47023467943241E-26d, + +1.75879225876483E-25d, + +4.780892502168074E-25d, + +1.2995814853898995E-24d, + +3.5326287852455166E-24d, + +9.602680736954162E-24d, + +2.6102792042257208E-23d, + +7.095474414148981E-23d, + +1.9287497671359936E-22d, + +5.242885191553114E-22d, + +1.4251641388208515E-21d, + +3.873997809109103E-21d, + +1.0530616658562386E-20d, + +2.862518609581133E-20d, + +7.78113163345177E-20d, + +2.1151310700892382E-19d, + +5.74952254077566E-19d, + +1.5628822871880503E-18d, + +4.24835413113866E-18d, + +1.1548223864099742E-17d, + +3.139132557537509E-17d, + +8.533046968331264E-17d, + +2.3195229636950566E-16d, + +6.305116324200775E-16d, + +1.71390848833098E-15d, + +4.6588861918718874E-15d, + +1.2664165777252073E-14d, + +3.442477422913037E-14d, + +9.357622912219837E-14d, + +2.5436656904062604E-13d, + +6.914399608426436E-13d, + +1.879528650772233E-12d, + +5.1090893668503945E-12d, + +1.3887944613766301E-11d, + +3.775134371775124E-11d, + +1.0261880234452292E-10d, + +2.789468100949932E-10d, + +7.582560135332983E-10d, + +2.061153470123145E-9d, + +5.602796449011294E-9d, + +1.5229979055675358E-8d, + +4.139937459513021E-8d, + +1.1253517584464134E-7d, + +3.059023470086686E-7d, + +8.315287232107949E-7d, + +2.260329438286135E-6d, + +6.1442124206223525E-6d, + +1.670170240686275E-5d, + +4.539993096841499E-5d, + +1.2340981629677117E-4d, + +3.35462624207139E-4d, + +9.118819143623114E-4d, + +0.0024787522852420807d, + +0.006737947463989258d, + +0.018315639346837997d, + +0.049787066876888275d, + +0.1353352963924408d, + +0.3678794503211975d, + +1.0d, + +2.7182817459106445d, + +7.389056205749512d, + +20.08553695678711d, + +54.59815216064453d, + +148.41314697265625d, + +403.42877197265625d, + +1096.633056640625d, + +2980.9580078125d, + +8103.083984375d, + +22026.46484375d, + +59874.140625d, + +162754.78125d, + +442413.375d, + +1202604.25d, + +3269017.5d, + +8886110.0d, + +2.4154952E7d, + +6.5659968E7d, + +1.78482304E8d, + +4.85165184E8d, + +1.318815744E9d, + +3.584912896E9d, + +9.74480384E9d, + +2.6489122816E10d, + +7.200489472E10d, + +1.95729620992E11d, + +5.32048248832E11d, + +1.446257098752E12d, + +3.9313342464E12d, + +1.0686474223616E13d, + +2.904884772864E13d, + +7.8962956959744E13d, + +2.14643574308864E14d, + +5.83461777702912E14d, + +1.586013579247616E15d, + +4.31123180027904E15d, + +1.1719142537166848E16d, + +3.1855931348221952E16d, + +8.6593395455164416E16d, + +2.35385270340419584E17d, + +6.3984347447610573E17d, + +1.73927483790327808E18d, + +4.7278395262972723E18d, + +1.285159987981792E19d, + +3.493427277593156E19d, + +9.496119530068797E19d, + +2.581312717296228E20d, + +7.016736290557636E20d, + +1.907346499785443E21d, + +5.1847060206155E21d, + +1.4093490364499379E22d, + +3.831007739580998E22d, + +1.0413759887481643E23d, + +2.8307533984544136E23d, + +7.694785471490595E23d, + +2.0916595931561093E24d, + +5.685720022003016E24d, + +1.545539007875769E25d, + +4.201209991636407E25d, + +1.142007304008196E26d, + +3.104297782658242E26d, + +8.43835682327257E26d, + +2.2937832658080656E27d, + +6.23514943204966E27d, + +1.694889206675675E28d, + +4.607187019879158E28d, + +1.2523630909973607E29d, + +3.4042761729010895E29d, + +9.253781621373885E29d, + +2.5154385492401904E30d, + +6.837671137556327E30d, + +1.8586717056324128E31d, + +5.05239404378821E31d, + +1.3733830589835937E32d, + +3.733241849647479E32d, + +1.014800418749161E33d, + +2.758513549969986E33d, + +7.498416981578345E33d, + +2.0382811492597872E34d, + +5.540622484676759E34d, + +1.5060972626944096E35d, + +4.0939972479624634E35d, + +1.1128638067747114E36d, + +3.0250770246136387E36d, + +8.223012393018281E36d, + +2.2352467822017166E37d, + +6.076029840339376E37d, + +1.6516361647240826E38d, + +4.4896127778163155E38d, + +1.2204032949639917E39d, + +3.3174000012927697E39d, + +9.017628107716908E39d, + +2.451245443147225E40d, + +6.663175904917432E40d, + +1.8112388823726723E41d, + +4.923458004084836E41d, + +1.3383347029375378E42d, + +3.637970747803715E42d, + +9.889030935681123E42d, + +2.6881169167589747E43d, + +7.307059786371152E43d, + +1.986264756071962E44d, + +5.399227989109673E44d, + +1.467662348860426E45d, + +3.989519470441919E45d, + +1.0844638420493122E46d, + +2.9478781225754055E46d, + +8.013164089994031E46d, + +2.1782039447564253E47d, + +5.920972420778763E47d, + +1.609486943324346E48d, + +4.3750396394525074E48d, + +1.1892591576149107E49d, + +3.2327411123173475E49d, + +8.787501601904039E49d, + +2.3886908001521312E50d, + +6.493134033643613E50d, + +1.7650169203544438E51d, + +4.7978130078372714E51d, + +1.3041809768060802E52d, + +3.5451314095271004E52d, + +9.636666808527841E52d, + +2.6195174357581655E53d, + +7.120586694432509E53d, + +1.9355758655647052E54d, + +5.2614409704305464E54d, + +1.4302079642723736E55d, + +3.8877083524279136E55d, + +1.0567886837680406E56d, + +2.872649515690124E56d, + +7.808670894670738E56d, + +2.1226166967029073E57d, + +5.769871153180574E57d, + +1.568413405104933E58d, + +4.263390023436419E58d, + +1.1589095247718807E59d, + +3.150242850860434E59d, + +8.563247933339596E59d, + +2.3277319969498524E60d, + +6.327431953939798E60d, + +1.719974302355042E61d, + +4.675374788964851E61d, + +1.2708985520400816E62d, + +3.454660807101683E62d, + +9.390740355567705E62d, + +2.5526681615684215E63d, + +6.938871462941557E63d, + +1.8861808782043154E64d, + +5.1271712215233855E64d, + +1.3937096689052236E65d, + +3.7884955399150257E65d, + +1.0298199046367501E66d, + +2.799340708992666E66d, + +7.609396391563323E66d, + +2.0684484008569103E67d, + +5.622626080395226E67d, + +1.528388084444653E68d, + +4.1545899609113734E68d, + +1.1293346659459732E69d, + +3.069849599753188E69d, + +8.344717266683004E69d, + +2.268329019570017E70d, + +6.165958325782564E70d, + +1.676081191364984E71d, + +4.556060380835955E71d, + +1.2384658100355657E72d, + +3.3664990715562672E72d, + +9.15109220707761E72d, + +2.4875248571153216E73d, + +6.761793219649385E73d, + +1.8380461271305958E74d, + +4.996327312938759E74d, + +1.3581426848077408E75d, + +3.691814001080034E75d, + +1.0035391101975138E76d, + +2.7279024753382288E76d, + +7.415207287657125E76d, + +2.0156621983963848E77d, + +5.479138512760614E77d, + +1.4893842728520671E78d, + +4.048565732162643E78d, + +1.1005142643914475E79d, + +2.991508131437659E79d, + +8.131762373533769E79d, + +2.210442148596269E80d, + +6.008604166110734E80d, + +1.633308028614055E81d, + +4.439791652732591E81d, + +1.206860599814453E82d, + +3.280586734644871E82d, + +8.917559854082513E82d, + +2.4240442814945802E83d, + +6.589235682116406E83d, + +1.7911398904871E84d, + +4.86882298924053E84d, + +1.3234832005748183E85d, + +3.597600556519039E85d, + +9.77929222446451E85d, + +2.658286976862848E86d, + +7.225974166887662E86d, + +1.9642232209552433E87d, + +5.3393125705958075E87d, + +1.4513757076459615E88d, + +3.945247871835613E88d, + +1.0724295693252266E89d, + +2.915165904253785E89d, + +7.924242330665303E89d, + +2.1540322390343345E90d, + +5.855267177907345E90d, + +1.5916266807316476E91d, + +4.326489915443873E91d, + +1.1760619079592718E92d, + +3.1968677404735245E92d, + +8.689987517871135E92d, + +2.3621834216830225E93d, + +6.421080550439423E93d, + +1.7454306955949023E94d, + +4.744571892885607E94d, + +1.2897084285532175E95d, + +3.505791114318544E95d, + +9.529727908157224E95d, + +2.5904487437231458E96d, + +7.041568925985714E96d, + +1.9140971884979424E97d, + +5.203055142575272E97d, + +1.4143368931719686E98d, + +3.8445667684706366E98d, + +1.0450615121235744E99d, + +2.8407720200442806E99d, + +7.722018663521402E99d, + +2.0990624115923312E100d, + +5.705842978547001E100d, + +1.5510089388648915E101d, + +4.216079296087462E101d, + +1.1460491592124923E102d, + +3.1152847602082673E102d, + +8.468222063292654E102d, + +2.3019011105282883E103d, + +6.257216813084462E103d, + +1.7008878437355237E104d, + +4.62349260394851E104d, + +1.2567956334920216E105d, + +3.416324322370112E105d, + +9.286532888251822E105d, + +2.5243410574836706E106d, + +6.861870970598542E106d, + +1.8652499723625443E107d, + +5.070274654122399E107d, + +1.3782437251846782E108d, + +3.746454626411946E108d, + +1.0183920005400422E109d, + +2.768276122845335E109d, + +7.524954624697075E109d, + +2.0454950851007314E110d, + +5.56023190218245E110d, + +1.511427628805191E111d, + +4.1084862677372065E111d, + +1.1168024085164686E112d, + +3.0357834799588566E112d, + +8.252116273466952E112d, + +2.2431576057283144E113d, + +6.097534318207731E113d, + +1.65748157925005E114d, + +4.5055022172222453E114d, + +1.2247224482958058E115d, + +3.329140840363789E115d, + +9.049543313665034E115d, + +2.4599209935197392E116d, + +6.686758417135634E116d, + +1.817649308779104E117d, + +4.940883275207154E117d, + +1.3430713954289087E118d, + +3.6508464654683645E118d, + +9.924030156169606E118d, + +2.697631034485758E119d, + +7.332921137166064E119d, + +1.9932945470297703E120d, + +5.418336099279846E120d, + +1.472856595860236E121d, + +4.0036393271908754E121d, + +1.0883019300873278E122d, + +2.9583112936666607E122d, + +8.041523923017192E122d, + +2.1859129781586158E123d, + +5.941927186144745E123d, + +1.6151834292371802E124d, + +4.390523815859274E124d, + +1.1934680816813702E125d, + +3.2441826014060764E125d, + +8.81860282490643E125d, + +2.3971445233885962E126d, + +6.516115189736396E126d, + +1.7712635751001657E127d, + +4.814793918384117E127d, + +1.3087966177291396E128d, + +3.557678449715009E128d, + +9.670771210463886E128d, + +2.628788218289742E129d, + +7.145787619369324E129d, + +1.9424264981694277E130d, + +5.280062387569078E130d, + +1.4352697002457768E131d, + +3.901467289560222E131d, + +1.0605288965077546E132d, + +2.882816299252225E132d, + +7.836307815186044E132d, + +2.1301292155181736E133d, + +5.790291758828013E133d, + +1.573964437869041E134d, + +4.278478878300888E134d, + +1.1630112062985817E135d, + +3.1613917467297413E135d, + +8.593554223894477E135d, + +2.335970335559215E136d, + +6.349826172787151E136d, + +1.7260616357651607E137d, + +4.691921416188566E137d, + +1.2753966504932798E138d, + +3.466887271843006E138d, + +9.423976538577447E138d, + +2.561702766944378E139d, + +6.963429563637273E139d, + +1.892856346657855E140d, + +5.1453167686439515E140d, + +1.3986421289359558E141d, + +3.8019036618832785E141d, + +1.033464507572145E142d, + +2.809247950589945E142d, + +7.636326960498012E142d, + +2.075769060297565E143d, + +5.64252553828769E143d, + +1.5337974510118784E144d, + +4.169293918423203E144d, + +1.1333315586787883E145d, + +3.080714152600695E145d, + +8.374250298636991E145d, + +2.276357074042286E146d, + +6.187780443461367E146d, + +1.6820131331794073E147d, + +4.572185635487065E147d, + +1.2428488853188662E148d, + +3.378413594504258E148d, + +9.183480622172801E148d, + +2.4963286658278886E149d, + +6.785725312893433E149d, + +1.8445514681108982E150d, + +5.014010481958507E150d, + +1.3629491735708616E151d, + +3.7048805655699485E151d, + +1.0070909418550386E152d, + +2.7375567044077912E152d, + +7.441451374243517E152d, + +2.022795961737854E153d, + +5.4985298195094216E153d, + +1.494655405262451E154d, + +4.062894701808608E154d, + +1.1044092571980793E155d, + +3.002095574584687E155d, + +8.160542326793782E155d, + +2.218265110516721E156d, + +6.02987028472758E156d, + +1.6390888071605646E157d, + +4.455504920700703E157d, + +1.2111317421229415E158d, + +3.2921976772303727E158d, + +8.94912101169977E158d, + +2.432623425087251E159d, + +6.612555731556604E159d, + +1.7974788874847574E160d, + +4.8860545948985793E160d, + +1.328167263606087E161d, + +3.610333312791256E161d, + +9.813901863427107E161d, + +2.667695552814763E162d, + +7.251548346906463E162d, + +1.9711751621240536E163d, + +5.3582093498119173E163d, + +1.4565123573071036E164d, + +3.959211091077107E164d, + +1.0762251933089556E165d, + +2.9254832789181E165d, + +7.952287052787358E165d, + +2.161656025361765E166d, + +5.8759898326913254E166d, + +1.597259768214821E167d, + +4.3418021646459346E167d, + +1.1802241249113175E168d, + +3.2081817253680657E168d, + +8.720743087611513E168d, + +2.3705435424427623E169d, + +6.443805025317327E169d, + +1.7516078165936552E170d, + +4.7613641572445654E170d, + +1.2942728582966776E171d, + +3.518198614137319E171d, + +9.563454814394247E171d, + +2.5996166206245285E172d, + +7.066491077377918E172d, + +1.920871394985668E173d, + +5.221469250951617E173d, + +1.4193426880442385E174d, + +3.8581732071331E174d, + +1.0487601931965087E175d, + +2.850825930161946E175d, + +7.749348772180658E175d, + +2.1064911705560668E176d, + +5.726036941135634E176d, + +1.5564982816556894E177d, + +4.231000988846797E177d, + +1.1501053030837989E178d, + +3.1263099916916113E178d, + +8.498192212235393E178d, + +2.3100480183046895E179d, + +6.279361500971995E179d, + +1.7069074829463731E180d, + +4.63985600437427E180d, + +1.2612435745231905E181d, + +3.4284156709489884E181d, + +9.319400030019162E181d, + +2.5332752658571312E182d, + +6.88615578404537E182d, + +1.8718514371423056E183d, + +5.088219872370737E183d, + +1.3831214731781958E184d, + +3.759713966511158E184d, + +1.021996184153141E185d, + +2.778073442169904E185d, + +7.55158797540476E185d, + +2.0527342305586606E186d, + +5.579910641313343E186d, + +1.5167767828844167E187d, + +4.123026721295484E187d, + +1.1207549425651513E188d, + +3.0465278560980536E188d, + +8.281321669236493E188d, + +2.251096660331649E189d, + +6.119114404399683E189d, + +1.6633478556884994E190d, + +4.521448560089285E190d, + +1.2290570545894685E191d, + +3.340923580982338E191d, + +9.081571104550255E191d, + +2.468626868232408E192d, + +6.710424255583952E192d, + +1.8240823171621646E193d, + +4.958369974640573E193d, + +1.3478247120462365E194d, + +3.6637673548790206E194d, + +9.959152908532152E194d, + +2.707178052117959E195d, + +7.358873642076596E195d, + +2.0003490682463053E196d, + +5.4375131636754E196d, + +1.4780692924846082E197d, + +4.01780853635105E197d, + +1.0921536132159379E198d, + +2.968781250496917E198d, + +8.069984512111955E198d, + +2.193649279840519E199d, + +5.962956589227457E199d, + +1.620899738203635E200d, + +4.406062052965071E200d, + +1.1976919074588434E201d, + +3.2556641859513496E201d, + +8.849812639395597E201d, + +2.40562867677584E202d, + +6.539175932653188E202d, + +1.7775323307944624E203d, + +4.831833881898182E203d, + +1.3134287685114547E204d, + +3.5702693195009266E204d, + +9.704997606668411E204d, + +2.63809219778715E205d, + +7.171077244202293E205d, + +1.949300880034352E206d, + +5.298749302736127E206d, + +1.4403494631058154E207d, + +3.91527572177694E207d, + +1.0642823992403076E208d, + +2.8930193727937684E208d, + +7.8640411896421955E208d, + +2.1376680994038112E209d, + +5.8107841809216616E209d, + +1.5795351101531684E210d, + +4.293620869258453E210d, + +1.1671272667059652E211d, + +3.172580666390786E211d, + +8.623968972387222E211d, + +2.3442378838418366E212d, + +6.372298757235201E212d, + +1.7321703934464356E213d, + +4.708527306855985E213d, + +1.279910496643312E214d, + +3.479157135998568E214d, + +9.45732984079136E214d, + +2.5707689593428096E215d, + +6.988074107282322E215d, + +1.8995553996578656E216d, + +5.1635269305465607E216d, + +1.4035923083915864E217d, + +3.815359096108819E217d, + +1.0371220592190472E218d, + +2.819190456167585E218d, + +7.663353127378024E218d, + +2.083115484919861E219d, + +5.662495731848751E219d, + +1.5392257142577226E220d, + +4.184049381430498E220d, + +1.1373425785132867E221d, + +3.091617462831603E221d, + +8.403887374207366E221d, + +2.2844135610697528E222d, + +6.209679892802781E222d, + +1.6879660933816274E223d, + +4.588367423411997E223d, + +1.2472476068464461E224d, + +3.3903703993793316E224d, + +9.215982463319503E224d, + +2.5051637206758385E225d, + +6.809741127603255E225d, + +1.8510795864289367E226d, + +5.031755776868959E226d, + +1.3677729802316034E227d, + +3.7179924024793253E227d, + +1.0106552237522032E228d, + +2.7472456017809066E228d, + +7.467788172398272E228d, + +2.029955237703202E229d, + +5.517990469846618E229d, + +1.4999452522236406E230d, + +4.0772734783595525E230d, + +1.1083180046837618E231d, + +3.012720614547867E231d, + +8.18942426109357E231d, + +2.2261161215322043E232d, + +6.051211457626543E232d, + +1.6448897917725177E233d, + +4.471273900208441E233d, + +1.2154183152078517E234d, + +3.3038494682728794E234d, + +8.98079409878202E234d, + +2.4412328161430576E235d, + +6.63595840453991E235d, + +1.8038406914061554E236d, + +4.90334700062756E236d, + +1.3328680266667662E237d, + +3.623110695743118E237d, + +9.848636053777669E237d, + +2.677136737066629E238d, + +7.277212447141125E238d, + +1.978151484427976E239d, + +5.377173488599035E239d, + +1.4616672175682191E240d, + +3.973222981713661E240d, + +1.0800340064859439E241d, + +2.935837009891444E241d, + +7.980432566722885E241d, + +2.169306470354036E242d, + +5.896786161387733E242d, + +1.6029126916635028E243d, + +4.357168123448786E243d, + +1.1844011798406507E244d, + +3.2195361624179725E244d, + +8.751606149833694E244d, + +2.3789334438756013E245d, + +6.466611224443739E245d, + +1.7578073785142153E246d, + +4.7782149589194885E246d, + +1.2988535295611824E247d, + +3.5306502960727705E247d, + +9.597302512507479E247d, + +2.608817438130718E248d, + +7.091500562953208E248d, + +1.9276698418065647E249d, + +5.239949786641934E249d, + +1.42436589329759E250d, + +3.8718282216768776E250d, + +1.0524719896550007E251d, + +2.860915548426704E251d, + +7.77677492833005E251d, + +2.113946677051906E252d, + +5.7463023795153145E252d, + +1.56200679236425E253d, + +4.2459748085663055E253d, + +1.1541756557557508E254d, + +3.137374584307575E254d, + +8.528268445871411E254d, + +2.3182239583484444E255d, + +6.301585387776819E255d, + +1.7129486892266285E256d, + +4.6562769567905925E256d, + +1.26570724146049E257d, + +3.4405490416979487E257d, + +9.352382323649647E257d, + +2.54224113415832E258d, + +6.910528108396216E258d, + +1.8784760208391767E259d, + +5.106228040084293E259d, + +1.3880166914480165E260d, + +3.7730204737910044E260d, + +1.0256131352582533E261d, + +2.787906051540986E261d, + +7.578313650939932E261d, + +2.0599991793068063E262d, + +5.5996586041611455E262d, + +1.522145133131402E263d, + +4.137618951061827E263d, + +1.1247213964487372E264d, + +3.0573102223682595E264d, + +8.310629417537063E264d, + +2.2590636576955473E265d, + +6.1407711078356886E265d, + +1.6692346202615142E266d, + +4.5374504961394207E266d, + +1.2334070098307164E267d, + +3.3527476928456816E267d, + +9.113713162029408E267d, + +2.4773638527240193E268d, + +6.734172833429278E268d, + +1.8305382378470305E269d, + +4.9759187284770303E269d, + +1.352594940263854E270d, + +3.6767339705169146E270d, + +9.994400500679653E270d, + +2.716759624268743E271d, + +7.384918458508588E271d, + +2.007428933605617E272d, + +5.456757565532369E272d, + +1.4833003969415539E273d, + +4.0320284712983994E273d, + +1.096019026243815E274d, + +2.979288529962515E274d, + +8.098545495417704E274d, + +2.201412886580694E275d, + +5.984060832462728E275d, + +1.6266362950862408E276d, + +4.4216561713555547E276d, + +1.2019307065458128E277d, + +3.2671863888979078E277d, + +8.881133159512924E277d, + +2.4141423627760256E278d, + +6.562319473965767E278d, + +1.7838233889223407E279d, + +4.848934634563382E279d, + +1.3180771991576186E280d, + +3.5829049382293792E280d, + +9.739345931419228E280d, + +2.6474285478041252E281d, + +7.196457718729758E281d, + +1.956199868121249E282d, + +5.31750271790054E282d, + +1.4454470027638629E283d, + +3.929132560365955E283d, + +1.0680488848057261E284d, + +2.9032581477488686E284d, + +7.89187408872514E284d, + +2.1452336456259667E285d, + +5.831349876080173E285d, + +1.5851251724785243E286d, + +4.308816643345461E286d, + +1.1712579802975851E287d, + +3.1838092090922606E287d, + +8.654490685278886E287d, + +2.3525345191912968E288d, + +6.39485115791896E288d, + +1.7383009254496851E289d, + +4.725191397657393E289d, + +1.2844402232816276E290d, + +3.491470347090126E290d, + +9.490800658395667E290d, + +2.579867270991543E291d, + +7.012806239173502E291d, + +1.906278351789277E292d, + +5.181801397059486E292d, + +1.408559707497606E293d, + +3.8288623079292884E293d, + +1.0407926842436056E294d, + +2.829168201470791E294d, + +7.690475570840264E294d, + +2.0904882610105383E295d, + +5.68253547942899E295d, + +1.544673396032028E296d, + +4.1988574190754736E296d, + +1.1413677466646359E297d, + +3.102559332875688E297d, + +8.433630296371073E297d, + +2.292498520423419E298d, + +6.23165710486722E298d, + +1.6939399242810123E299d, + +4.604606371472047E299d, + +1.2516618713553432E300d, + +3.402369329874797E300d, + +9.248598815279678E300d, + +2.51402968559859E301d, + +6.833842035076675E301d, + +1.8576309291617257E302d, + +5.049564425991982E302d, + +1.3726137091534984E303d, + +3.7311513682845094E303d, + +1.0142320772726397E304d, + +2.7569686255975333E304d, + +7.494218049456063E304d, + +2.037139607241041E305d, + +5.5375196488302575E305d, + +1.5052539519895093E306d, + +4.091704288360009E306d, + +1.1122405335641184E307d, + +3.023383151402969E307d, + +8.218407798110846E307d, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + }; + + /** Exponential evaluated at integer values, + * exp(x) = expIntTableA[x + EXP_INT_TABLE_MAX_INDEX] + expIntTableB[x+EXP_INT_TABLE_MAX_INDEX] + */ + private static final double[] EXP_INT_B = new double[] { + +0.0d, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + -1.76097684E-316d, + -2.44242319E-315d, + -9.879317845E-315d, + -1.3811462167E-314d, + +2.1775261204E-314d, + -1.4379095864E-313d, + +1.4219324087E-313d, + +1.00605438061E-312d, + -1.287101187097E-312d, + +5.33839690397E-312d, + -9.35130825405E-313d, + -4.15218681073E-311d, + +4.546040329134E-311d, + -1.57333572310673E-310d, + +1.05387548454467E-309d, + +2.095732474644446E-309d, + -2.62524392470767E-310d, + +5.86440876259637E-309d, + -2.401816502004675E-309d, + -2.2711230715729753E-308d, + +2.0670460065057715E-307d, + +3.436860020483706E-308d, + +2.0862243734177337E-306d, + -4.637025318037353E-306d, + +9.222671009756424E-306d, + +6.704597874020559E-305d, + +4.351284159444109E-305d, + +4.232889602759328E-304d, + +1.2840977763293412E-303d, + -2.6993478083348727E-303d, + -1.053265874779237E-303d, + +1.207746682843556E-303d, + +5.21281096513035E-303d, + +1.6515377082609677E-301d, + +3.3951607353932444E-301d, + +5.609418227003629E-301d, + +4.238775357914848E-300d, + -9.441842771290538E-300d, + -2.1745347282493023E-299d, + -6.203839803215248E-299d, + -5.617718879466363E-299d, + +5.2869976233132615E-298d, + -1.4300075619643524E-298d, + +4.3198234936686506E-297d, + -2.6448316331572387E-297d, + +4.315655444002347E-296d, + -7.253671992213344E-296d, + -1.1288398461391523E-295d, + -4.83901764243093E-296d, + +1.7407497662694827E-295d, + +1.1969717029666017E-294d, + -7.752519943329177E-294d, + -4.019569741253664E-293d, + -2.4467928392518484E-293d, + -1.0269233640424235E-292d, + -3.2330960700986594E-292d, + -1.440995270758115E-291d, + -3.726946038150935E-291d, + -1.3424576100819801E-291d, + -3.128894928199484E-290d, + -5.989337506920005E-290d, + -9.438168176533759E-290d, + -1.9220613500411237E-289d, + +2.1186736024949195E-289d, + +6.3015208029537436E-288d, + -8.168129112703755E-288d, + -1.6040513288090055E-287d, + -1.0809972724404233E-287d, + -3.080380385962424E-286d, + +2.6399157174374624E-286d, + +1.3317127674213423E-285d, + -3.5821668044872306E-285d, + +1.978536584535392E-284d, + +1.3399392455370071E-284d, + -2.870168560029448E-284d, + +3.5311184272663063E-283d, + -7.204247881190918E-283d, + +3.2425604548983798E-282d, + +3.913063150326019E-282d, + -2.260957518848075E-281d, + +3.807242187736102E-281d, + -5.095591405025083E-281d, + +2.3400625068490396E-280d, + -1.1564717694090882E-280d, + -3.517594695450786E-279d, + +6.666544384808297E-279d, + -9.204784113858607E-279d, + +4.8677119923665573E-278d, + +7.942176091555472E-278d, + -2.5113270522478854E-277d, + +5.332900939354667E-277d, + -3.491241408725929E-276d, + -2.1141094074221325E-276d, + +1.722049095222509E-275d, + +4.0430160253378594E-275d, + +1.9888195459082551E-274d, + +3.230089643550739E-275d, + +5.077824728028163E-274d, + -3.526547961682877E-274d, + -6.4376298274983765E-273d, + -2.5338279333399964E-272d, + -3.614847626733713E-272d, + +2.510812179067931E-272d, + +3.953806005373127E-272d, + +7.112596406315374E-272d, + -2.850217520533226E-270d, + -8.571477929711754E-270d, + +1.2902019831221148E-269d, + -6.978783784755863E-270d, + +9.89845486618531E-269d, + -3.538563171970534E-268d, + +3.537475449241181E-268d, + +3.6924578046381256E-267d, + +1.3555502536444713E-266d, + -1.1279742372661484E-266d, + +5.475072932318336E-266d, + -1.1679889049814275E-265d, + -8.946297908979776E-266d, + +1.0565816011650582E-264d, + -3.2161237736296753E-265d, + -6.022045553485609E-264d, + -2.0332050860436034E-263d, + -1.0488538406930105E-262d, + +1.6793752843984384E-262d, + +3.2558720916543104E-263d, + -1.9546569053899882E-262d, + +5.082190670014963E-262d, + -1.0188117475357564E-260d, + +3.7920054509691455E-261d, + -8.330969967504819E-260d, + -1.1623181434592597E-259d, + +9.09665088462258E-259d, + -1.56400149127482E-259d, + -7.796557225750673E-258d, + +6.751460509863465E-258d, + +7.243157658226935E-258d, + +1.2574668958946027E-256d, + +2.2678858131411216E-256d, + +5.1079306249351287E-256d, + -5.672261759108003E-257d, + +3.476539491009769E-256d, + -1.3481093992496937E-254d, + -3.314051560952014E-254d, + +7.408112967339146E-255d, + -7.164884605413269E-254d, + -6.456588023278983E-253d, + -1.4881197370811587E-252d, + +1.7534012237555307E-252d, + -1.3070101381473173E-251d, + +6.081420141954215E-251d, + +6.591143677421159E-251d, + +2.6917461073773043E-250d, + +3.683043641790553E-251d, + +1.2195076420741757E-249d, + -8.220283439582378E-249d, + +1.637852737426943E-248d, + -8.332543237340988E-249d, + +2.9581193516975647E-248d, + -1.7790661150204172E-247d, + -1.7809679916043692E-247d, + +8.378574405736031E-247d, + -2.883847036065813E-246d, + +1.3223776943337897E-245d, + +3.098547586845664E-245d, + -1.1036542789147287E-244d, + -5.7187703271582225E-244d, + -1.8058492822440396E-244d, + +4.4373726292703545E-243d, + -3.4631935816990754E-243d, + -1.82770041073856E-243d, + +3.845535085273936E-242d, + +8.446532344375812E-242d, + +2.7751016140238277E-242d, + +1.3158882241538003E-241d, + -3.579433051074272E-240d, + -6.151751570213211E-240d, + -2.990535475079021E-239d, + +2.3396028616528764E-239d, + +7.233790684263346E-239d, + +1.0847913100494912E-238d, + +7.103148400942551E-238d, + +3.463600299750966E-237d, + -4.873121855093712E-237d, + +1.3407295326570417E-236d, + +9.390271617387205E-237d, + -2.4767709454727603E-235d, + +3.205923535388443E-235d, + -1.0074984709952582E-234d, + +2.4747880175747574E-234d, + -5.146939682310558E-234d, + -2.827581009333298E-233d, + -3.0307641004671077E-233d, + +5.92044714050651E-233d, + -2.0582596893119236E-232d, + -6.58066591313112E-232d, + -4.869955151949929E-231d, + -5.763495903609913E-231d, + -2.3580462372762525E-230d, + +1.8559980428862584E-230d, + +2.854978560542175E-229d, + +5.637945686485334E-229d, + +2.1454644909004582E-228d, + -1.1918070206953359E-228d, + -5.021851606912854E-228d, + +3.861525553653117E-227d, + +6.533561982617909E-227d, + -3.015709444206057E-226d, + -5.042005018212734E-227d, + +1.5959614205422845E-225d, + +2.0402105689098835E-224d, + +5.164902728917601E-224d, + +9.981031744879876E-224d, + +4.0281104210095145E-223d, + +1.1158160971176672E-222d, + +2.0736172194624895E-222d, + +4.983162653734032E-222d, + +2.1753390051977871E-221d, + +3.969413618002761E-221d, + +1.3961255018698695E-220d, + +2.1290855095314206E-220d, + +1.1927747883417406E-219d, + +3.7264401117998796E-219d, + +9.318532410862293E-219d, + +2.3414841777613345E-218d, + +4.3791842770430786E-218d, + +1.7173159016511951E-217d, + +3.5037536832675478E-217d, + +1.4300098613455884E-216d, + +2.4189403362149483E-216d, + +9.306541421999056E-216d, + +3.442100456607687E-215d, + +5.94407068841904E-215d, + +2.0483260435783403E-214d, + +3.8410992889527954E-214d, + +1.2038281262953917E-213d, + +3.865007795216205E-213d, + +9.754659138599756E-213d, + +2.7653605770745684E-212d, + +5.359568079675375E-212d, + +2.61726605666378E-211d, + +5.054202073556894E-211d, + +8.707092668016246E-211d, + +1.4080573899148006E-210d, + +1.288124387778789E-209d, + +1.8639901642011898E-209d, + +6.076014540574561E-209d, + +1.798489141298457E-208d, + +2.1525406805994896E-208d, + +1.1864056832305874E-207d, + +2.1077440662171152E-207d, + +1.3784853708457332E-206d, + +1.6965806532093783E-206d, + +7.241626420445137E-206d, + +2.575584299085016E-205d, + +6.151951078101721E-205d, + +2.40652042118887E-204d, + +4.022633486003565E-204d, + +5.8840879519086286E-204d, + +3.2820308007277566E-203d, + +4.31880454864738E-203d, + +2.427240455243201E-202d, + +7.326955749884755E-202d, + +1.4310184489676175E-201d, + +4.464279133463661E-201d, + +4.895131474682867E-201d, + +4.48614966943544E-200d, + +8.924048768324976E-200d, + +2.5035535029701945E-199d, + +6.627829836338812E-199d, + +2.6066826304502746E-198d, + +8.042275310036546E-198d, + +2.115062964308555E-197d, + +4.413745413236018E-197d, + +1.644449394585716E-196d, + +3.138217752973845E-196d, + +7.48533983136081E-196d, + +2.613626422028823E-195d, + +3.6741841454219095E-195d, + +5.906102862953403E-195d, + +4.4940857547850743E-194d, + +5.840064709376958E-194d, + +3.087661273836024E-193d, + +4.995552216100365E-193d, + +1.991444798915497E-192d, + +7.097454751809522E-192d, + +2.0510193986749737E-191d, + +5.759440286608551E-191d, + +1.7013941257113314E-190d, + +2.1383323934483528E-190d, + +8.280292810015406E-190d, + +3.138655772049104E-189d, + +7.961506427685701E-189d, + +2.0579001228504997E-188d, + +7.530840351477639E-188d, + +1.4582863136475673E-187d, + +3.149267215638608E-187d, + +5.443114553057336E-187d, + +3.4672966834277804E-186d, + +7.374944406615125E-186d, + +2.7318417252599104E-185d, + +7.913674211949961E-185d, + +2.5217716516462005E-184d, + +4.0866585874353075E-184d, + +1.2087698972768686E-183d, + +3.7072473866919033E-183d, + +1.1333588840402273E-182d, + +1.61949812578045E-182d, + +6.567779607147072E-182d, + +2.422974840736314E-181d, + +2.551170809294396E-181d, + +1.0905890688083124E-180d, + +3.221279639653057E-180d, + +7.068244813489027E-180d, + +1.3752309224575428E-179d, + +7.20154303462761E-179d, + +1.5391707185581056E-178d, + +7.708777608683431E-178d, + +5.597398155472547E-178d, + +1.8487854656676722E-177d, + +1.0577249492414076E-176d, + +2.8926683313922764E-176d, + +4.090184282164232E-176d, + +1.6142943398013813E-175d, + +7.873864351702525E-175d, + +2.242630017261011E-174d, + +3.4637009373878283E-174d, + +1.5907089565090164E-173d, + +1.6985075903314236E-173d, + +1.1552273904608563E-172d, + +2.237894048535414E-172d, + +5.321990399912051E-172d, + +1.4106062639738257E-171d, + +2.9850404523368767E-171d, + +1.5683802588004895E-170d, + +4.880146806045633E-170d, + +1.1489352403441815E-169d, + +1.6401586605693734E-169d, + +8.29169700697816E-169d, + +1.0380723705441457E-168d, + +7.126414081261746E-168d, + +1.253325949455206E-167d, + +2.595079206183114E-167d, + +1.537490712803659E-166d, + +2.6338455225993276E-166d, + +7.994936425058567E-166d, + +1.5716634677516025E-165d, + +3.669404761339415E-165d, + +1.9941628263579332E-164d, + +4.5012079983352374E-164d, + +7.283163019991001E-164d, + +2.398038505188316E-163d, + +7.868666894503849E-163d, + +2.1478649410390003E-162d, + +8.306111510463843E-162d, + +1.5453160659068463E-161d, + -4.590496588813841E-162d, + +3.5449293983801232E-161d, + -1.0440854056870505E-160d, + -2.321064927632431E-160d, + +5.707867001443433E-160d, + -2.238614484037969E-159d, + +2.482282821883242E-159d, + -1.1508772192025259E-158d, + +1.9903990578876104E-158d, + -1.2116165315442256E-158d, + -2.9084557554502667E-157d, + -1.1211083853006645E-156d, + -1.309893394818129E-156d, + +4.2269712317468864E-156d, + -7.678973146281339E-156d, + +3.2021376921211934E-155d, + -7.08313012515209E-155d, + +1.944398214330544E-154d, + +1.1860061363751161E-153d, + +1.5234465914578058E-153d, + -2.9020908354550263E-153d, + +4.980100072851796E-153d, + +2.3101551448625578E-152d, + -1.1959241322537072E-151d, + -9.27398924154364E-153d, + +5.999390491704392E-152d, + +1.3373196561281372E-150d, + -1.0271780540759147E-150d, + +2.575620466387945E-150d, + -6.56250013356227E-149d, + -1.1961357917482867E-148d, + +5.5807813570926636E-148d, + +9.252840189663807E-148d, + -1.830335419852293E-147d, + +9.350990339947455E-147d, + -1.6072409939877762E-146d, + -2.5309995887229526E-146d, + -1.6014373376410622E-146d, + -3.303297758377758E-145d, + +1.5640419864850202E-145d, + +9.544642884951585E-145d, + -8.64864445321803E-144d, + +7.580392204597681E-144d, + +2.678334184447568E-143d, + -3.7269289985326055E-143d, + -2.851965258161176E-142d, + +7.243267286265823E-142d, + +4.4510805312036926E-141d, + +9.008499734799015E-141d, + +1.130435759928337E-140d, + -3.096539751496479E-140d, + -1.497405487919762E-139d, + +3.51519845948652E-139d, + -4.713790209541894E-139d, + +4.740753295616865E-138d, + +9.517570994930463E-138d, + -1.8842098029339485E-137d, + -3.825558165008403E-137d, + +1.1817638600528107E-136d, + -3.514601201473235E-136d, + -6.344612631552417E-136d, + -1.6754164785291923E-136d, + +4.445372986583078E-135d, + -3.89604237755475E-134d, + -1.0155552195374609E-134d, + +2.1858142063550155E-134d, + +3.497714990137842E-133d, + -7.635830383612894E-133d, + +1.2050744860079718E-132d, + -7.683019590615251E-133d, + -3.344806129021162E-131d, + -1.6737914131474577E-131d, + -4.30610076666344E-131d, + +5.184023388254773E-130d, + +2.6290763595212492E-129d, + +7.90041744728452E-130d, + -3.204473056113754E-129d, + -2.552517201762272E-128d, + +7.130134251490065E-128d, + -3.2244113258340395E-127d, + -1.064920993515727E-127d, + +2.7466520735457463E-126d, + +4.368312797746065E-126d, + +1.8802599072446818E-125d, + -4.257625799463564E-125d, + +5.491672256552995E-125d, + +3.7298611779671127E-124d, + +5.724180836308973E-124d, + +1.3861841053630075E-123d, + +4.2303826056297614E-123d, + +3.5335436928899096E-123d, + -2.522906629540626E-122d, + +1.0147808005267102E-121d, + +6.734406065735473E-122d, + -4.948973160958133E-121d, + +2.4256181927024344E-120d, + +4.9056283164780554E-120d, + +6.846440394397547E-120d, + +3.512747689569002E-119d, + -9.020907406701404E-119d, + +2.5718749916003624E-118d, + +4.3724191002977524E-119d, + +1.001455050575191E-117d, + -2.4442443105031435E-117d, + +2.38873950760028E-116d, + -4.831068747037129E-118d, + -5.148989321866988E-116d, + +1.7875271881514469E-115d, + -1.1821586412088555E-114d, + +4.43247726423679E-115d, + +4.634817120492781E-114d, + +1.671311907037975E-113d, + -4.595250028278979E-113d, + -5.905511605694905E-113d, + -1.3657642265608213E-112d, + +2.881416869529271E-112d, + +2.1253302469985373E-111d, + -5.301386276260592E-111d, + +1.4198782892306878E-112d, + -3.395494928605007E-110d, + +9.284633292147283E-110d, + -6.054133004896379E-110d, + -8.324100783330331E-109d, + -2.193190669794277E-108d, + +1.3613655394659198E-107d, + +6.463452607647978E-108d, + +1.0187183636134904E-106d, + +1.0705673935006142E-106d, + +2.509050608571019E-106d, + -1.5096182622106617E-105d, + +1.7794190449526737E-106d, + +1.2261246749706581E-104d, + +2.1377905661197194E-104d, + -2.2015877944429946E-104d, + +7.873970951802825E-104d, + -1.7999197335480384E-103d, + +1.0487383011058756E-105d, + -2.9988278531841556E-102d, + +4.7976477743232285E-102d, + +3.452316818502442E-102d, + +5.89953246760617E-101d, + -4.0785601577267006E-101d, + +2.7214076662438963E-100d, + +5.237807655758373E-100d, + +6.180972117932364E-99d, + -1.3019742873005683E-98d, + +4.501188264957416E-99d, + -2.4075054705261798E-98d, + +1.6503086546628772E-97d, + -6.878666975101243E-97d, + +1.196718116616528E-96d, + +2.476190162339265E-96d, + -7.1844969234484515E-96d, + +5.088386759261555E-95d, + +6.749368983223726E-95d, + +1.965737856765605E-94d, + -5.574080023496771E-94d, + +1.2493696959436675E-93d, + +8.533262777516794E-94d, + -7.225259028588793E-93d, + -7.340587186324432E-93d, + -3.482412195764625E-92d, + +3.4742610108480497E-91d, + -7.177274244758699E-91d, + +1.2736636153072213E-90d, + -5.730160886217076E-90d, + -1.545495535488274E-89d, + +1.1304179460367007E-89d, + +1.249260560756154E-88d, + -4.7439719382414206E-88d, + +7.164663249266942E-88d, + +1.7617425105337704E-87d, + +2.4175248449172035E-87d, + -1.043079666926483E-86d, + -2.8137609614326677E-86d, + -1.2091497144395591E-85d, + +3.7944631664558904E-85d, + -2.8144926807308225E-85d, + +3.9782728352520784E-85d, + +4.313978872469646E-84d, + +5.82190887044604E-84d, + +5.883385169571802E-83d, + +1.134857098306787E-82d, + +3.468049324128309E-82d, + +2.625423995658143E-82d, + -3.42827917465521E-81d, + +5.119461911618321E-81d, + -2.134387988350615E-80d, + -4.4703076268400615E-80d, + +4.806078883451016E-80d, + +2.3820250362443495E-79d, + -7.258551497833573E-79d, + -4.0297835558876335E-78d, + +2.1424166787650852E-78d, + -3.2117127164185917E-77d, + +4.8459153070935316E-77d, + -1.766924303914492E-76d, + -2.6921749814579492E-76d, + -4.1291070428848755E-76d, + +2.2086994756104319E-75d, + -7.814146377574201E-75d, + -1.9589778310104216E-74d, + +6.52658129486538E-74d, + +1.7804909509998055E-74d, + -4.1900132227036916E-73d, + +1.5705861683841123E-72d, + -1.904714978998808E-72d, + -7.81295459930537E-72d, + +2.818537910881676E-71d, + +5.840507984320445E-71d, + +1.7331720051707087E-70d, + +1.936946987935961E-70d, + -5.86517231340979E-71d, + -1.3277440528416646E-69d, + +1.9906256185827793E-69d, + +8.668714514280051E-69d, + +6.643105496829061E-69d, + -2.5436254170647032E-67d, + -4.8279217213630774E-67d, + -1.2640304072937576E-66d, + +3.51187258511716E-66d, + +1.4199501303738373E-65d, + -1.2351697477129173E-65d, + +7.0542365522414836E-65d, + +1.030593104122615E-64d, + -5.452692909894593E-65d, + -9.415506349675128E-64d, + -3.6206211446779087E-63d, + -1.6699188275658641E-62d, + +2.287280262665656E-62d, + +7.076135457313529E-62d, + +2.9019628518165404E-61d, + -3.1305705497720186E-61d, + +2.2978757040142953E-60d, + +1.2424439441817321E-60d, + +7.140343013236265E-60d, + +8.633726388939636E-60d, + +1.3483035574114863E-58d, + +1.653701058949654E-58d, + -8.939932297357388E-58d, + -1.395320103272191E-57d, + +6.440430933947252E-58d, + -1.681200826841738E-56d, + +3.9904382022898837E-56d, + -4.870518577546228E-56d, + -1.6990896855901115E-55d, + -6.751434891261518E-56d, + -1.669012123121194E-54d, + -4.079585475491198E-54d, + -1.3070436427679952E-53d, + -3.090028378908628E-53d, + +7.468160889798606E-53d, + +6.229095980733463E-53d, + +1.4794751934479566E-52d, + +1.7444373785853918E-51d, + -5.3681978363391484E-52d, + +2.71853394036182E-51d, + -1.3334367969274016E-50d, + -1.6958057665854177E-49d, + -1.452507231312146E-49d, + +3.3855429446520427E-49d, + +4.903687986212687E-49d, + +2.2185957416622524E-48d, + -9.924196700842429E-48d, + +4.285128462851149E-47d, + +3.076063086193525E-48d, + +4.102052341676543E-46d, + +1.1745772638457318E-45d, + -5.309047216809048E-47d, + +2.72972449891179E-45d, + -1.1748423022293739E-44d, + +6.626052626622228E-44d, + +3.0227439688367925E-44d, + -4.740494808228372E-43d, + +5.926057457356852E-43d, + +3.09768273342776E-42d, + -5.589493227475577E-42d, + -8.84908716783327E-42d, + +2.3684740712822874E-41d, + +1.4836491430755657E-40d, + +4.5878801324451396E-40d, + +1.0585156316103144E-39d, + +2.3805896467049493E-39d, + +1.0285082556185196E-38d, + +2.5187968110874885E-38d, + -1.4088399542613178E-38d, + -3.00901028043488E-38d, + +2.0089026801414973E-37d, + -1.3324111396289096E-36d, + +5.458481186294964E-36d, + -4.8402541351522003E-36d, + -1.3331969720555312E-35d, + -8.248332290732976E-35d, + -1.8349670703969982E-34d, + +6.403477383195494E-34d, + +3.7813691654412385E-34d, + +2.4621305031382827E-33d, + -5.634051826192439E-33d, + +3.817173955083142E-32d, + -6.038239639506472E-32d, + -2.130447095555397E-31d, + -6.824454861992054E-31d, + -1.3455801602048414E-30d, + -2.518642767561659E-30d, + +8.082792416221215E-30d, + +4.718103502869148E-29d, + -5.607991635038776E-29d, + -1.8042191582018579E-28d, + +6.989914264479507E-28d, + -2.9031739430339586E-28d, + +6.076820259849921E-27d, + -3.24981577480893E-27d, + -2.7648210023059463E-26d, + -9.785306155980342E-26d, + +1.241529292737115E-25d, + +3.0891604448087654E-25d, + +2.3451052074796954E-24d, + +6.574128018028633E-24d, + -1.3345148716925826E-23d, + +4.3594621428644293E-23d, + -5.678896695157704E-23d, + -4.676849004137386E-23d, + -2.281578975407609E-22d, + -3.144430608076357E-21d, + +5.662033727488754E-22d, + -4.30293375386492E-21d, + +4.985137671479376E-20d, + +1.657668502165438E-19d, + -3.3878706977811337E-19d, + -7.488022803661722E-19d, + +1.725039737424264E-18d, + -6.0275040161173166E-18d, + -8.081007442213538E-19d, + +2.9257892371894816E-17d, + +1.5231541295722552E-16d, + -1.1474026049124666E-17d, + +6.890372706231206E-16d, + +2.592721454922832E-15d, + -1.1253822296423454E-15d, + -2.650684279637763E-14d, + -4.107226967119929E-15d, + -3.130508064738312E-14d, + -6.729414275200856E-14d, + -1.6166170913368169E-12d, + -1.2059301405584488E-12d, + -1.2210091619211167E-11d, + +3.695372823623631E-12d, + +5.119220484478292E-11d, + -1.0857572226543142E-10d, + -4.6490379071586397E-10d, + -4.5810381714280557E-10d, + +1.4909756678328582E-9d, + -1.3155828104004438E-8d, + -9.149755188170102E-9d, + +0.0d, + +8.254840070411029E-8d, + -1.0681886149151956E-7d, + -3.359944163407147E-8d, + -2.1275002921718894E-6d, + +1.2129920353421116E-5d, + +2.1520078872608393E-5d, + +1.0178783359926372E-4d, + -2.077077172525637E-5d, + -5.67996159922899E-5d, + +9.510567165169581E-4d, + +0.0010901978184553272d, + +0.010169003920808009d, + +0.017008920503326107d, + +0.03416477677774927d, + -0.1275278893606981d, + +0.5205078726367633d, + +0.7535752982147762d, + +1.1373305111387886d, + -3.036812739155085d, + +11.409790277969124d, + -9.516785302789955d, + -49.86840843831867d, + -393.7510973999651d, + -686.1565277058598d, + +4617.385872524165d, + -11563.161235730215d, + -8230.201383316231d, + -34460.52482632287d, + +50744.04207438878d, + +357908.46214699093d, + +1936607.425231087d, + +3222936.695160983d, + +5477052.0646243105d, + -3.517545711859706E7d, + -1.2693418527187027E8d, + -2.5316384477288628E8d, + -1.6436423669122624E8d, + +4.0889180422033095E8d, + +4.968829330953611E9d, + -3.503399598592085E9d, + +1.905394922122271E10d, + +1.0361722296739479E11d, + -5.806792575852521E10d, + +2.3454138776381036E11d, + -1.718446464587963E12d, + -1.0946634815588584E12d, + +1.6889383928999305E13d, + -3.784600043778247E13d, + +7.270965670658928E13d, + -4.9202842786896806E14d, + +4.597700093952774E14d, + +2.6113557852262235E15d, + -4.544525556171388E15d, + -9.517971970450354E15d, + -2.0634857819227416E16d, + -9.7143113104549808E16d, + -2.2667083759873216E16d, + -7.2285665164439578E17d, + +4.1215410760803866E18d, + +8.5807488300972206E18d, + +1.530436781375042E19d, + -1.5453111533064765E19d, + -1.0633845571643594E20d, + -3.512380426745336E20d, + +3.7734658676841284E20d, + -3.855478664503271E21d, + +7.984485303520287E21d, + -1.2296934902142301E22d, + +1.042139023692827E22d, + +1.2167897656061312E23d, + +9.22064170155394E22d, + +3.965171513035854E23d, + -4.135121057126514E24d, + -7.944341754299148E24d, + +1.4715152230577016E25d, + -3.0635272288480756E25d, + -9.54468158713835E25d, + +1.5411775738825048E25d, + -8.274711842374368E26d, + -1.0028324930788433E27d, + +5.189062091114782E27d, + -2.8583500869462184E28d, + -5.198295198128238E28d, + +2.9758750368256437E29d, + +3.216046320616945E29d, + -1.7846700158234043E30d, + +3.847174961282827E30d, + +9.026991921214922E30d, + +4.1358029739592175E30d, + -6.461509354879894E29d, + +9.704297297526684E31d, + +2.9731739067444943E32d, + +9.97728609663656E32d, + +3.1149346370027763E33d, + +2.0051635097366476E34d, + +2.819272221032373E34d, + +1.6266731695798413E34d, + +1.998050894021586E35d, + -6.1633417615076335E35d, + +2.2505716077585116E36d, + +1.9299691540987203E36d, + +8.006569251375383E36d, + -3.785295042408568E37d, + -1.1870498357197593E38d, + +1.0010529668998112E38d, + +1.3240710866573994E38d, + +2.6888010385137123E39d, + +1.7400655988987023E39d, + -6.402740469853475E39d, + -3.93114092562274E40d, + +1.2363717201084252E41d, + -1.9219116633978794E41d, + -1.347867098583136E42d, + +7.87675118338788E41d, + +3.3932984011177642E41d, + -1.9872713979884691E43d, + +2.220208491349658E43d, + -3.466267817480825E43d, + +3.19462030745197E44d, + -9.841244788104406E44d, + -2.2676593395522725E45d, + -1.1349246400274207E46d, + -1.1700910284427406E46d, + -3.6754317105801715E46d, + +1.7647101734915075E47d, + +2.122358392979746E47d, + +3.156243682143956E47d, + +5.356668151937413E47d, + +2.7668218233914262E48d, + +3.5127708120698784E48d, + +1.7884841356632925E49d, + +1.716531820904728E50d, + -2.9114757102866277E50d, + +1.0657703081219677E51d, + -7.512169809356372E50d, + +1.764200470879736E51d, + -1.0088898215431471E52d, + -3.1085734725176E52d, + +4.3529009584292495E52d, + -2.467842129213774E53d, + -3.9317379627195146E53d, + -4.332335454045836E52d, + +7.979013724931926E54d, + -1.5038413653121357E55d, + +9.310799925566843E55d, + -2.2042966348036592E55d, + -4.518315366841937E55d, + -6.971366338144781E56d, + -2.0461505570781806E57d, + -8.823884392655312E57d, + -1.1264032993918548E58d, + -7.692065092509875E58d, + -1.8472516879728875E59d, + +8.72220314694275E58d, + +1.6525336989036362E59d, + -3.343201925128334E60d, + +5.493352163155986E60d, + -2.548073509300398E61d, + -9.566541624209933E61d, + +4.0891054447206644E61d, + -7.724182294653349E62d, + +1.0143022354947225E63d, + -4.952031310451961E63d, + -7.877410133454722E63d, + +4.505432606253564E64d, + -7.330635250808021E64d, + -1.642361029990822E65d, + +5.982180242124184E65d, + +7.120242132370469E65d, + +5.908356249789671E66d, + -2.8477710945673134E65d, + +6.65688196961235E66d, + -9.233295580238604E67d, + +3.2850043261803593E68d, + +7.041681569694413E68d, + -1.5652761725518397E69d, + +1.5377053215489084E68d, + +1.282130763903269E70d, + -2.380286345847567E70d, + -7.207022875977515E70d, + +2.7641662602473095E71d, + +7.685235201534525E71d, + +4.3239378585884645E70d, + -1.6840562544109314E72d, + -5.04128025464686E71d, + +5.4557485189210095E73d, + +7.160277784358221E73d, + +7.636179075087608E73d, + -8.18804507680012E74d, + +2.807397988979441E75d, + +2.165163304600171E75d, + -1.3208450062862734E76d, + -5.1939252391404724E76d, + -6.985952908805853E76d, + -1.6259920998287064E77d, + +6.098975200926637E77d, + -5.63383579957466E77d, + -1.5876819186852907E78d, + +2.1487475413123092E79d, + -3.987619123706934E79d, + +9.772655251656639E79d, + -1.638756156057952E79d, + -7.83892088580041E80d, + +1.274413296252691E81d, + +2.51946651720982E81d, + -2.516866097506943E81d, + +1.053956282234684E82d, + +1.8279051206232177E83d, + +1.2250764591564252E82d, + -4.0353723442917463E83d, + -1.4121324224340735E84d, + -5.45287716696021E84d, + -1.7514953095665195E85d, + -5.0706081370522526E85d, + -4.35799392139009E85d, + -3.982538093450217E86d, + -1.4591838284752642E87d, + +2.5313735821872488E87d, + -3.718501227185903E86d, + -1.3907979640327008E88d, + -5.79002114093961E86d, + -1.2500675565781447E89d, + +4.8182788286170926E89d, + -1.7198866036687559E90d, + -4.690417668647599E88d, + +1.3020631859056421E91d, + -1.3850458263351744E91d, + +4.87301010703588E91d, + -1.695546877943826E92d, + -1.6353756659909833E92d, + -1.5483926773679628E93d, + -1.8921091400297595E93d, + -6.183525570536406E93d, + -4.987913342551977E93d, + +1.0186485886120274E93d, + -1.5343120819745468E95d, + -5.262123923229857E95d, + +1.618327917706804E96d, + -4.135185828158998E96d, + -8.016793741945299E96d, + -3.0399439534134115E97d, + -1.2319346292749103E98d, + +7.536337311795176E97d, + -3.577715974851322E98d, + +2.0521614818695524E99d, + +1.2627736197958951E98d, + -5.206910481915062E99d, + +3.0974593993948837E100d, + -9.522726334561169E100d, + -1.1909272509710985E100d, + -5.056512677995137E101d, + +2.0902045062932175E102d, + +6.243669516810509E102d, + -1.7375090618655787E103d, + -2.5445477450140954E103d, + +3.619891246849381E103d, + +8.90737333900943E103d, + -2.7897360297480367E104d, + +1.3725786770437066E105d, + -8.316530604593264E105d, + -6.054541568735673E105d, + +7.523374196797555E105d, + +1.1475955030427985E107d, + +1.5260756679495707E107d, + +7.370294848920685E107d, + +1.3608995799112174E108d, + +1.0700758858011432E108d, + -4.989318918773146E108d, + -1.6629755787634093E108d, + +7.635999584053557E109d, + +1.892621828736983E109d, + -6.793094743406533E110d, + -8.160628910742724E110d, + -7.724219106106896E111d, + -1.6059226011778748E112d, + -1.5277127454062126E112d, + +3.911086668967361E112d, + +3.529920406834134E113d, + -4.3991443996021166E113d, + -1.2631909085915044E114d, + +3.8656278695544835E114d, + +1.71845288713123E115d, + +3.7660598745907915E115d, + -4.048086182363988E115d, + +2.3093822298965837E116d, + -9.684925795536813E116d, + -3.137992585221854E117d, + -5.637415935329794E117d, + -1.5536658521931418E118d, + -6.336314643222911E118d, + +8.550658957115427E118d, + -5.591880480212007E119d, + +2.4137404318673354E119d, + -2.631656656397244E120d, + -7.653117429165879E119d, + -4.073965591445897E121d, + +3.634781057940233E121d, + +4.537273754534966E121d, + -2.5138919966097735E122d, + -1.0292817180691822E123d, + -1.4265564976097062E122d, + +6.000235114895513E123d, + +4.186590347846346E124d, + -1.8950538406321535E124d, + +7.716762345695022E124d, + -4.443798187035849E125d, + -2.268994961992292E125d, + -2.8169291774231604E126d, + -2.749127978087685E126d, + -2.2929764629585683E126d, + -7.369842361872221E127d, + +2.81312841469177E128d, + +2.7856896414497757E128d, + -3.096733638475319E128d, + -5.4199510725063615E129d, + -7.315860999413894E129d, + +3.6424644535156437E130d, + -7.886250961456327E130d, + +5.289988151341401E130d, + +2.7758613753516344E131d, + -2.738246981762776E132d, + -2.2667181460478093E132d, + -3.614672661225457E131d, + +2.325337720526947E133d, + +4.16603235883392E133d, + -6.50348962894948E133d, + +3.851445905038431E134d, + -5.46060534001412E134d, + +5.4679180659102885E135d, + -3.037477806841494E135d, + -3.0417051809209134E136d, + -6.995964550587914E136d, + -3.6897084415718804E137d, + -6.938000231893302E137d, + +2.403806217004454E138d, + -3.4552363953199905E138d, + +7.3409917428393E138d, + -1.7445917446236717E139d, + -6.680679913078676E139d, + -8.193572619487537E139d, + +5.337290292186291E139d, + -3.951314467739045E140d, + -4.4662073456574476E141d, + +6.249381778908997E141d, + -2.928362616578011E142d, + -1.6661676835672304E143d, + -1.974465323891493E143d, + +1.3083870531380308E144d, + -2.382825271750576E144d, + -5.4826958838142734E144d, + +1.5340733916570804E145d, + -3.1327120557842516E145d, + +1.5790297768522832E146d, + +1.1518771984292262E146d, + -4.789917000227385E145d, + -8.689594184775204E146d, + +3.0680417869552433E146d, + +4.877860620031438E147d, + -3.4650891244084597E148d, + +1.8702183451052442E149d, + -3.5727227900139915E148d, + -1.3457821696677932E150d, + +3.3212950284273017E149d, + +7.316033240396569E150d, + -7.187723217018267E150d, + -8.537194547485455E150d, + -1.4561530066010593E152d, + -7.548155147049997E151d, + +1.0047353208353007E153d, + -1.2489460589853119E153d, + +4.426120229279107E153d, + -2.5466223330961086E154d, + +8.831699889789037E154d, + -2.0258084311749475E155d, + -5.525009099476396E155d, + -1.0235056525096769E156d, + -4.117971654572494E154d, + -4.7559175309753334E156d, + -1.4656240137098836E157d, + -7.675790582869644E157d, + -1.0126616322947826E158d, + +7.084865265284368E158d, + -9.374695893307895E158d, + +2.05597910889115E159d, + -7.368602086210704E159d, + -1.6167825196198978E160d, + +2.3832096207000712E160d, + +1.3166970112139726E161d, + -6.432337568761393E161d, + +2.9279594746502846E161d, + +4.8926595743317624E162d, + +1.2704793774453618E163d, + -1.1345910784680524E163d, + +7.75933511025868E163d, + -1.1441115218462356E163d, + +5.162248481759758E164d, + +6.362563919556132E164d, + -2.8362173224732088E165d, + -4.342161053332263E165d, + +4.388125271425036E166d, + -7.049068240916723E166d, + +3.8520227881415595E166d, + +2.9274120974020826E167d, + -7.500936767542933E167d, + -6.540181860667302E168d, + +4.664436780622191E168d, + -1.436111169285268E169d, + -1.0407581736224179E170d, + -2.7670181051374297E170d, + -6.788169932297778E170d, + +1.6997387217850427E171d, + -1.0965324942770584E171d, + +9.841563119484623E171d, + +3.175748919314254E172d, + +2.9621181706527444E172d, + -3.30101656090905E173d, + -3.791840683760427E173d, + -2.841347842666459E174d, + -7.836327226971707E174d, + +9.650358667643114E174d, + +5.9994277301267294E175d, + -6.0490084078440215E175d, + -2.8964095485948707E176d, + +9.916187343252014E175d, + +2.7535627955313556E176d, + +3.886891475472745E177d, + +3.1962472803616787E178d, + -5.50599549115449E178d, + +5.672812341879918E178d, + -3.295268490032475E179d, + +9.761163062156018E179d, + +3.107837179570674E180d, + +3.3894811576571423E179d, + -5.235397688850367E180d, + -5.004237248003625E181d, + -1.7544995191195304E182d, + +2.645622651144787E182d, + -3.459885432869825E182d, + -4.0361435606199565E183d, + -1.8382923511801317E183d, + -1.7332235571505177E184d, + +2.847653455671381E184d, + +1.7991060813894693E185d, + -2.0937429891059164E185d, + +5.744446753652847E185d, + -2.1349396267483754E184d, + -1.2542332720182776E186d, + +3.3730714236579374E186d, + -5.923734606208998E187d, + +2.24669039465627E188d, + -1.2588742703536392E188d, + +1.474522484905093E189d, + -2.4006971787803736E189d, + -3.52597540499141E189d, + +2.6676722922838097E190d, + +5.27579825970359E190d, + +2.1360492104281465E191d, + +1.9442210982008953E191d, + -1.4691239161932232E190d, + +3.8218180377739526E192d, + +1.9722862688653467E192d, + +3.047601928063002E193d, + +1.6747356805175311E193d, + +7.710512446969693E192d, + +1.7780021277684035E194d, + -1.4015110811648513E195d, + +4.0447634595724164E195d, + +9.023639664212642E195d, + +1.976868146639626E196d, + -9.084495133765657E196d, + -1.2023077889892748E196d, + +5.7455368446308694E197d, + -1.7766273910482863E198d, + +3.5590470673352285E198d, + +1.1304970373249033E199d, + +1.6496143246803731E199d, + -2.394588390685223E199d, + -1.4677321100833294E199d, + -1.1843870433971731E201d, + -1.8853982316037226E201d, + +2.8829871423339434E201d, + +5.369687677705385E200d, + +1.8356062677502141E202d, + -1.5544655377217875E203d, + +2.955364187248884E203d, + -2.7651059253677425E203d, + +9.903174064539538E203d, + -3.284204788892967E204d, + -1.5843229740595697E205d, + +5.333371443528904E204d, + +1.2781631468016048E205d, + +3.2188292385399854E205d, + -6.619064395428225E206d, + +1.291561142865928E207d, + +1.3142988156905172E207d, + -1.3841980097978606E208d, + +6.380177790989479E207d, + +1.0386032577072378E209d, + +2.7681631086098026E209d, + -9.053874899534375E209d, + +1.2424707839848734E210d, + +1.045546633850141E211d, + -1.2448938139338362E211d, + +7.221902646057552E211d, + +6.651345415954053E211d, + -5.8180712702152444E212d, + +5.275183961165903E212d, + +5.092753117288608E212d, + -2.437796532151255E213d, + +1.3480763914637323E214d, + +5.619995933180841E214d, + +2.547000388735681E214d, + +4.817319356453926E214d, + -7.897146442236022E215d, + -7.93844120619577E215d, + -4.9489938500591624E216d, + -2.862720607805682E216d, + -2.9275804461593914E217d, + -3.411186219855533E217d, + -2.0110092718356274E218d, + -8.472642266772353E218d, + -4.357990742470246E217d, + +4.793444363780116E219d, + +1.6544084224626834E220d, + -6.017988576347111E220d, + -3.580397221598409E220d, + -4.7208848667217906E221d, + -7.724899660259369E221d, + -2.4459728627968634E222d, + +3.667348665023154E221d, + +4.544122762558404E223d, + -4.0573420909530794E223d, + -3.2552002992257195E223d, + -6.488296536838142E224d, + +1.7544839352461719E224d, + -4.0873400635183405E225d, + -8.833499967268279E225d, + -1.0953484767704112E226d, + -8.56825295972308E226d, + -1.8097633115378247E227d, + -6.171564449018882E227d, + -4.351843341274115E227d, + +2.8032429752543687E228d, + -1.0065901934522996E229d, + +9.863720960170636E228d, + -9.481088691357648E229d, + -1.6843492713373762E229d, + -1.3282890219894906E230d, + +6.883577595238845E230d, + -1.153577281189635E231d, + -8.009548754642203E231d, + -4.722612904888278E232d, + -4.768909872963015E232d, + +3.2542391242036633E233d, + +6.513425781583774E233d, + -1.8889614379831606E233d, + -2.227647301474917E234d, + -4.7971208532986115E234d, + +6.693500938105557E234d, + -6.587776621471115E234d, + +3.0099905634916516E236d, + -4.6694407626686244E235d, + +2.965546585110978E236d, + +5.771457643937893E237d, + -9.029878114318277E237d, + +8.169926810324408E237d, + -1.779945804977441E239d, + +4.1218749988429474E239d, + +7.201319954099161E239d, + -1.530845432304069E240d, + -3.861762510530086E240d, + -2.4090696463777446E241d, + -1.8196842273916379E241d, + -1.7959243076374794E242d, + -3.7257346819782323E242d, + +3.413310324247329E242d, + -2.0406580894051073E243d, + -1.5335923091350053E243d, + -1.056727406551016E244d, + -4.6753408714233723E244d, + -2.0697130057384643E245d, + -1.0356006160554071E245d, + +1.1339195187304043E246d, + +1.792783182582235E246d, + +9.599214853681978E245d, + +1.5367645598839362E247d, + +2.934570385464815E247d, + -1.6411525886171892E248d, + +2.2638862982382794E248d, + -1.2268014119628852E249d, + +4.737693450915584E247d, + +6.3818993714899675E249d, + +1.2639113706171572E250d, + -4.011320021817099E249d, + -5.2744376732859406E250d, + -3.732266217624991E251d, + +1.7591819833844019E252d, + -3.292458622014749E252d, + -9.161340309319204E252d, + -1.728610646009749E253d, + +1.1698424008604891E254d, + -1.8494343291160577E254d, + +2.0568656302182574E254d, + +1.0537591246531136E255d, + +1.803052068234866E254d, + -1.053036399720808E256d, + +2.1836166619192508E256d, + +1.0368403169781264E257d, + -2.0648015610276362E257d, + +8.426174035728768E257d, + -1.3577357192972777E258d, + +2.1313950901331177E258d, + +8.919141843592823E258d, + -1.1800039972549816E259d, + -1.1878772398311421E260d, + -1.538273497873993E260d, + -4.51305093266001E260d, + +1.1241179396053055E261d, + +6.154786508667658E261d, + -1.0626125049032536E262d, + -1.8908603201210102E262d, + -4.571195152299358E262d, + +1.526100002923062E263d, + -9.457084582570225E263d, + -1.5460500618825853E264d, + -5.598276199126451E264d, + -1.2074097381167957E265d, + -3.015972957475025E265d, + +1.4345106852061226E265d, + +8.28479585346867E265d, + -3.118741081244705E266d, + -1.2054747399765794E266d, + +3.4454766202661184E267d, + +1.1279135096919439E268d, + +1.2066382528772518E268d, + +1.1984128162292276E269d, + +3.685169705587367E268d, + +6.570047690198998E269d, + +1.8836492887460383E270d, + +7.4364594917181125E270d, + +1.2773080633674971E271d, + +1.8928981707279692E271d, + +4.039437286589528E271d, + +1.785277385538302E272d, + -6.017681359527226E272d, + +1.9716943051755635E273d, + -8.772048092842086E271d, + +1.5645672698520312E274d, + -3.7979660725865874E274d, + +5.324902289537048E274d, + -1.8806716685063293E274d, + +9.320900373401115E275d, + +1.4615985810260016E275d, + +8.321226457219046E276d, + -4.608112855795952E276d, + -3.476352191116455E277d, + +5.266381689434054E277d, + -9.622106063561645E277d, + +4.1719443712336026E278d, + +4.222411269063919E279d, + -6.714376022102489E279d, + -1.0732735585199074E280d, + -2.5866883048437488E280d, + -1.1306860837934988E281d, + +3.690690354793168E281d, + -5.5299180508885456E281d, + +2.7006726968568243E282d, + +4.135457669031131E282d, + +2.8401159516008676E283d, + +5.127265762024798E283d, + -3.4893601256685762E283d, + -1.145160459652136E283d, + +2.1742808735341656E284d, + +4.656972469326391E285d, + +7.672307991205681E285d, + +1.5781599575584034E286d, + +4.218682431618625E286d, + -2.4602260687026867E287d, + +2.7211316452521414E287d, + -1.8740018211089393E288d, + +2.6367639658206183E288d, + -3.102678910525039E288d, + +1.1992295328636466E289d, + +6.8190133180135345E289d, + +5.783203879030497E289d, + +5.171047077293295E290d, + +1.8396930096213817E290d, + +1.4977047507315718E290d, + +1.0672499803427623E292d, + +3.3310942289102464E291d, + -7.962256961838823E292d, + +1.7396889119023863E293d, + +3.8072183820435085E293d, + +2.2772059538865722E294d, + -2.0549866377878678E294d, + -1.2277120342804144E295d, + -3.609949022969024E295d, + +1.1479863663699871E296d, + -1.5314373779304356E296d, + -2.2537635160762597E296d, + -6.1370690793508674E296d, + -4.996854125490041E297d, + -6.883499809714189E297d, + -2.595456638706416E298d, + -1.1892631528580186E299d, + -1.4672600326020399E299d, + -3.200068509818696E299d, + -7.126913872617518E298d, + -3.3655587417265094E300d, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + Double.NaN, + }; + + + /** Exponential over the range of 0 - 1 in increments of 2^-10 + * exp(x/1024) = expFracTableA[x] + expFracTableB[x]. + * 1024 = 2^10 + */ + private static final double[] EXP_FRAC_A = new double[] { + +1.0d, + +1.0009770393371582d, + +1.0019550323486328d, + +1.0029339790344238d, + +1.0039138793945312d, + +1.004894733428955d, + +1.0058765411376953d, + +1.006859302520752d, + +1.007843017578125d, + +1.0088276863098145d, + +1.0098135471343994d, + +1.0108001232147217d, + +1.0117876529693604d, + +1.0127761363983154d, + +1.013765811920166d, + +1.014756202697754d, + +1.0157477855682373d, + +1.016740083694458d, + +1.0177335739135742d, + +1.0187277793884277d, + +1.0197231769561768d, + +1.0207195281982422d, + +1.021716833114624d, + +1.0227150917053223d, + +1.023714303970337d, + +1.024714469909668d, + +1.0257158279418945d, + +1.0267179012298584d, + +1.0277209281921387d, + +1.0287251472473145d, + +1.0297303199768066d, + +1.0307364463806152d, + +1.0317435264587402d, + +1.0327515602111816d, + +1.0337605476379395d, + +1.0347704887390137d, + +1.0357816219329834d, + +1.0367934703826904d, + +1.037806510925293d, + +1.038820505142212d, + +1.0398354530334473d, + +1.040851354598999d, + +1.0418684482574463d, + +1.0428862571716309d, + +1.043905258178711d, + +1.0449252128601074d, + +1.0459461212158203d, + +1.0469679832458496d, + +1.0479910373687744d, + +1.0490150451660156d, + +1.0500397682189941d, + +1.0510656833648682d, + +1.0520927906036377d, + +1.0531206130981445d, + +1.0541496276855469d, + +1.0551795959472656d, + +1.0562105178833008d, + +1.0572423934936523d, + +1.0582754611968994d, + +1.059309482574463d, + +1.0603444576263428d, + +1.061380386352539d, + +1.0624175071716309d, + +1.06345534324646d, + +1.0644943714141846d, + +1.0655345916748047d, + +1.066575527191162d, + +1.067617654800415d, + +1.0686607360839844d, + +1.0697050094604492d, + +1.0707499980926514d, + +1.071796178817749d, + +1.072843313217163d, + +1.0738916397094727d, + +1.0749409198760986d, + +1.075991153717041d, + +1.0770423412322998d, + +1.078094720840454d, + +1.0791480541229248d, + +1.080202341079712d, + +1.0812578201293945d, + +1.0823142528533936d, + +1.083371639251709d, + +1.08443021774292d, + +1.0854897499084473d, + +1.086550235748291d, + +1.0876119136810303d, + +1.088674545288086d, + +1.089738130569458d, + +1.0908029079437256d, + +1.0918686389923096d, + +1.092935562133789d, + +1.094003438949585d, + +1.0950722694396973d, + +1.096142053604126d, + +1.0972130298614502d, + +1.09828519821167d, + +1.099358320236206d, + +1.1004323959350586d, + +1.1015074253082275d, + +1.102583646774292d, + +1.103661060333252d, + +1.1047391891479492d, + +1.105818748474121d, + +1.1068990230560303d, + +1.107980489730835d, + +1.1090631484985352d, + +1.1101467609405518d, + +1.1112313270568848d, + +1.1123170852661133d, + +1.1134037971496582d, + +1.1144917011260986d, + +1.1155805587768555d, + +1.1166706085205078d, + +1.1177616119384766d, + +1.1188538074493408d, + +1.1199469566345215d, + +1.1210410594940186d, + +1.1221363544464111d, + +1.1232328414916992d, + +1.1243302822113037d, + +1.1254286766052246d, + +1.126528263092041d, + +1.127629041671753d, + +1.1287307739257812d, + +1.129833459854126d, + +1.1309373378753662d, + +1.132042407989502d, + +1.133148431777954d, + +1.1342556476593018d, + +1.1353638172149658d, + +1.1364731788635254d, + +1.1375834941864014d, + +1.1386950016021729d, + +1.1398074626922607d, + +1.1409211158752441d, + +1.142035961151123d, + +1.1431517601013184d, + +1.14426851272583d, + +1.1453864574432373d, + +1.14650559425354d, + +1.1476259231567383d, + +1.148747205734253d, + +1.149869441986084d, + +1.1509928703308105d, + +1.1521174907684326d, + +1.153243064880371d, + +1.154369831085205d, + +1.1554977893829346d, + +1.1566267013549805d, + +1.1577568054199219d, + +1.1588881015777588d, + +1.160020351409912d, + +1.161153793334961d, + +1.1622881889343262d, + +1.163423776626587d, + +1.1645605564117432d, + +1.1656982898712158d, + +1.166837215423584d, + +1.1679773330688477d, + +1.1691184043884277d, + +1.1702606678009033d, + +1.1714041233062744d, + +1.172548532485962d, + +1.173694133758545d, + +1.1748409271240234d, + +1.1759889125823975d, + +1.177137851715088d, + +1.1782879829406738d, + +1.1794393062591553d, + +1.1805915832519531d, + +1.1817450523376465d, + +1.1828997135162354d, + +1.1840553283691406d, + +1.1852121353149414d, + +1.1863701343536377d, + +1.1875293254852295d, + +1.1886897087097168d, + +1.1898510456085205d, + +1.1910135746002197d, + +1.1921772956848145d, + +1.1933419704437256d, + +1.1945080757141113d, + +1.1956751346588135d, + +1.1968433856964111d, + +1.1980125904083252d, + +1.1991832256317139d, + +1.200354814529419d, + +1.2015275955200195d, + +1.2027015686035156d, + +1.2038767337799072d, + +1.2050528526306152d, + +1.2062301635742188d, + +1.2074086666107178d, + +1.2085883617401123d, + +1.2097692489624023d, + +1.210951328277588d, + +1.2121343612670898d, + +1.2133188247680664d, + +1.2145042419433594d, + +1.2156908512115479d, + +1.2168786525726318d, + +1.2180676460266113d, + +1.2192575931549072d, + +1.2204489707946777d, + +1.2216413021087646d, + +1.222834825515747d, + +1.224029779434204d, + +1.2252256870269775d, + +1.2264227867126465d, + +1.227621078491211d, + +1.2288203239440918d, + +1.2300209999084473d, + +1.2312228679656982d, + +1.2324256896972656d, + +1.2336299419403076d, + +1.234835147857666d, + +1.23604154586792d, + +1.2372493743896484d, + +1.2384581565856934d, + +1.2396681308746338d, + +1.2408792972564697d, + +1.2420918941497803d, + +1.2433054447174072d, + +1.2445201873779297d, + +1.2457361221313477d, + +1.2469532489776611d, + +1.2481715679168701d, + +1.2493910789489746d, + +1.2506117820739746d, + +1.2518336772918701d, + +1.2530567646026611d, + +1.2542810440063477d, + +1.2555065155029297d, + +1.2567331790924072d, + +1.2579610347747803d, + +1.2591900825500488d, + +1.260420322418213d, + +1.2616519927978516d, + +1.2628846168518066d, + +1.2641184329986572d, + +1.2653534412384033d, + +1.266589879989624d, + +1.2678272724151611d, + +1.2690660953521729d, + +1.27030611038208d, + +1.2715470790863037d, + +1.272789478302002d, + +1.2740330696105957d, + +1.275277853012085d, + +1.2765238285064697d, + +1.27777099609375d, + +1.2790195941925049d, + +1.2802691459655762d, + +1.281519889831543d, + +1.2827720642089844d, + +1.2840254306793213d, + +1.2852799892425537d, + +1.2865357398986816d, + +1.287792682647705d, + +1.2890510559082031d, + +1.2903103828430176d, + +1.2915711402893066d, + +1.2928330898284912d, + +1.2940962314605713d, + +1.2953605651855469d, + +1.296626091003418d, + +1.2978930473327637d, + +1.2991611957550049d, + +1.3004305362701416d, + +1.3017010688781738d, + +1.3029727935791016d, + +1.304245948791504d, + +1.3055200576782227d, + +1.3067958354949951d, + +1.308072566986084d, + +1.3093504905700684d, + +1.3106298446655273d, + +1.3119103908538818d, + +1.3131921291351318d, + +1.3144752979278564d, + +1.3157594203948975d, + +1.317044973373413d, + +1.3183319568634033d, + +1.31961989402771d, + +1.3209092617034912d, + +1.322199821472168d, + +1.3234915733337402d, + +1.324784755706787d, + +1.3260791301727295d, + +1.3273746967315674d, + +1.3286716938018799d, + +1.329969882965088d, + +1.3312692642211914d, + +1.3325698375701904d, + +1.333871841430664d, + +1.3351752758026123d, + +1.336479663848877d, + +1.3377854824066162d, + +1.339092493057251d, + +1.3404009342193604d, + +1.3417105674743652d, + +1.3430213928222656d, + +1.3443336486816406d, + +1.3456470966339111d, + +1.3469617366790771d, + +1.3482778072357178d, + +1.349595069885254d, + +1.3509137630462646d, + +1.352233648300171d, + +1.3535549640655518d, + +1.3548774719238281d, + +1.356201171875d, + +1.3575263023376465d, + +1.3588526248931885d, + +1.360180139541626d, + +1.361509084701538d, + +1.3628394603729248d, + +1.364171028137207d, + +1.3655037879943848d, + +1.366837978363037d, + +1.368173360824585d, + +1.3695101737976074d, + +1.3708481788635254d, + +1.372187614440918d, + +1.373528242111206d, + +1.3748703002929688d, + +1.376213550567627d, + +1.3775582313537598d, + +1.378904104232788d, + +1.380251407623291d, + +1.3815999031066895d, + +1.3829498291015625d, + +1.384300947189331d, + +1.3856534957885742d, + +1.387007236480713d, + +1.3883624076843262d, + +1.389719009399414d, + +1.3910768032073975d, + +1.3924360275268555d, + +1.393796443939209d, + +1.395158290863037d, + +1.3965213298797607d, + +1.397885799407959d, + +1.3992514610290527d, + +1.4006187915802002d, + +1.401987075805664d, + +1.4033570289611816d, + +1.4047281742095947d, + +1.4061005115509033d, + +1.4074742794036865d, + +1.4088494777679443d, + +1.4102261066436768d, + +1.4116039276123047d, + +1.4129831790924072d, + +1.4143636226654053d, + +1.415745496749878d, + +1.4171288013458252d, + +1.418513298034668d, + +1.4198992252349854d, + +1.4212865829467773d, + +1.4226751327514648d, + +1.424065351486206d, + +1.4254565238952637d, + +1.426849365234375d, + +1.4282433986663818d, + +1.4296388626098633d, + +1.4310357570648193d, + +1.432433843612671d, + +1.433833360671997d, + +1.4352343082427979d, + +1.4366366863250732d, + +1.4380402565002441d, + +1.4394452571868896d, + +1.4408516883850098d, + +1.4422595500946045d, + +1.4436686038970947d, + +1.4450790882110596d, + +1.446491003036499d, + +1.447904348373413d, + +1.4493188858032227d, + +1.450735092163086d, + +1.4521524906158447d, + +1.4535713195800781d, + +1.454991340637207d, + +1.4564130306243896d, + +1.4578359127044678d, + +1.4592602252960205d, + +1.460686206817627d, + +1.4621131420135498d, + +1.4635417461395264d, + +1.4649717807769775d, + +1.4664030075073242d, + +1.4678359031677246d, + +1.4692699909210205d, + +1.470705509185791d, + +1.4721424579620361d, + +1.4735808372497559d, + +1.475020408630371d, + +1.47646164894104d, + +1.4779040813446045d, + +1.4793481826782227d, + +1.4807934761047363d, + +1.4822404384613037d, + +1.4836885929107666d, + +1.485138177871704d, + +1.4865891933441162d, + +1.488041639328003d, + +1.4894955158233643d, + +1.4909508228302002d, + +1.4924075603485107d, + +1.493865728378296d, + +1.4953253269195557d, + +1.49678635597229d, + +1.49824857711792d, + +1.4997124671936035d, + +1.5011777877807617d, + +1.5026445388793945d, + +1.504112720489502d, + +1.505582332611084d, + +1.5070531368255615d, + +1.5085256099700928d, + +1.5099995136260986d, + +1.511474847793579d, + +1.5129516124725342d, + +1.5144298076629639d, + +1.5159096717834473d, + +1.5173907279968262d, + +1.5188732147216797d, + +1.5203571319580078d, + +1.5218427181243896d, + +1.523329496383667d, + +1.524817943572998d, + +1.5263078212738037d, + +1.5277988910675049d, + +1.5292916297912598d, + +1.5307857990264893d, + +1.5322813987731934d, + +1.5337786674499512d, + +1.5352771282196045d, + +1.5367772579193115d, + +1.538278579711914d, + +1.5397815704345703d, + +1.5412859916687012d, + +1.5427920818328857d, + +1.5442993640899658d, + +1.5458080768585205d, + +1.547318458557129d, + +1.548830270767212d, + +1.5503435134887695d, + +1.5518584251403809d, + +1.5533745288848877d, + +1.5548923015594482d, + +1.5564115047454834d, + +1.5579321384429932d, + +1.5594542026519775d, + +1.5609779357910156d, + +1.5625030994415283d, + +1.5640296936035156d, + +1.5655577182769775d, + +1.5670874118804932d, + +1.5686185359954834d, + +1.5701510906219482d, + +1.5716853141784668d, + +1.5732207298278809d, + +1.5747578144073486d, + +1.5762965679168701d, + +1.577836513519287d, + +1.5793781280517578d, + +1.5809214115142822d, + +1.5824658870697021d, + +1.5840120315551758d, + +1.5855598449707031d, + +1.587108850479126d, + +1.5886595249176025d, + +1.5902118682861328d, + +1.5917654037475586d, + +1.593320608139038d, + +1.5948774814605713d, + +1.596435785293579d, + +1.5979955196380615d, + +1.5995566844940186d, + +1.6011195182800293d, + +1.6026840209960938d, + +1.6042497158050537d, + +1.6058173179626465d, + +1.6073861122131348d, + +1.6089565753936768d, + +1.6105287075042725d, + +1.6121022701263428d, + +1.6136772632598877d, + +1.6152539253234863d, + +1.6168320178985596d, + +1.6184117794036865d, + +1.619992971420288d, + +1.6215758323669434d, + +1.6231601238250732d, + +1.6247460842132568d, + +1.626333475112915d, + +1.627922534942627d, + +1.6295130252838135d, + +1.6311051845550537d, + +1.6326987743377686d, + +1.634294033050537d, + +1.6358907222747803d, + +1.6374890804290771d, + +1.6390891075134277d, + +1.640690565109253d, + +1.6422934532165527d, + +1.6438980102539062d, + +1.6455042362213135d, + +1.6471118927001953d, + +1.6487212181091309d, + +1.6503322124481201d, + +1.651944637298584d, + +1.6535584926605225d, + +1.6551742553710938d, + +1.6567914485931396d, + +1.6584100723266602d, + +1.6600303649902344d, + +1.6616523265838623d, + +1.663275957107544d, + +1.6649010181427002d, + +1.666527509689331d, + +1.6681559085845947d, + +1.669785737991333d, + +1.671417236328125d, + +1.6730501651763916d, + +1.674684762954712d, + +1.676321029663086d, + +1.6779589653015137d, + +1.679598331451416d, + +1.681239366531372d, + +1.6828820705413818d, + +1.6845262050628662d, + +1.6861720085144043d, + +1.687819480895996d, + +1.6894686222076416d, + +1.6911191940307617d, + +1.6927716732025146d, + +1.6944255828857422d, + +1.6960809230804443d, + +1.6977381706237793d, + +1.6993968486785889d, + +1.7010571956634521d, + +1.7027192115783691d, + +1.7043828964233398d, + +1.7060482501983643d, + +1.7077150344848633d, + +1.709383487701416d, + +1.7110536098480225d, + +1.7127254009246826d, + +1.7143988609313965d, + +1.716073989868164d, + +1.7177505493164062d, + +1.7194287776947021d, + +1.7211089134216309d, + +1.7227904796600342d, + +1.7244737148284912d, + +1.726158618927002d, + +1.7278449535369873d, + +1.7295331954956055d, + +1.7312231063842773d, + +1.7329144477844238d, + +1.7346076965332031d, + +1.736302375793457d, + +1.7379989624023438d, + +1.739696979522705d, + +1.7413966655731201d, + +1.7430980205535889d, + +1.7448012828826904d, + +1.7465059757232666d, + +1.7482123374938965d, + +1.74992036819458d, + +1.7516300678253174d, + +1.7533416748046875d, + +1.7550547122955322d, + +1.7567694187164307d, + +1.7584857940673828d, + +1.7602040767669678d, + +1.7619237899780273d, + +1.7636451721191406d, + +1.7653684616088867d, + +1.7670931816101074d, + +1.768819808959961d, + +1.770547866821289d, + +1.77227783203125d, + +1.7740094661712646d, + +1.775742769241333d, + +1.777477741241455d, + +1.7792143821716309d, + +1.7809526920318604d, + +1.7826926708221436d, + +1.7844345569610596d, + +1.7861778736114502d, + +1.7879230976104736d, + +1.7896699905395508d, + +1.7914185523986816d, + +1.7931687831878662d, + +1.7949209213256836d, + +1.7966744899749756d, + +1.7984299659729004d, + +1.800187110900879d, + +1.8019459247589111d, + +1.8037066459655762d, + +1.8054687976837158d, + +1.8072328567504883d, + +1.8089985847473145d, + +1.8107659816741943d, + +1.812535285949707d, + +1.8143062591552734d, + +1.8160789012908936d, + +1.8178532123565674d, + +1.819629430770874d, + +1.8214070796966553d, + +1.8231868743896484d, + +1.8249680995941162d, + +1.8267512321472168d, + +1.828536033630371d, + +1.830322504043579d, + +1.83211088180542d, + +1.8339009284973145d, + +1.8356926441192627d, + +1.8374862670898438d, + +1.8392815589904785d, + +1.841078519821167d, + +1.8428773880004883d, + +1.8446779251098633d, + +1.846480131149292d, + +1.8482842445373535d, + +1.8500902652740479d, + +1.8518977165222168d, + +1.8537070751190186d, + +1.8555183410644531d, + +1.8573312759399414d, + +1.8591458797454834d, + +1.8609623908996582d, + +1.8627805709838867d, + +1.864600658416748d, + +1.866422414779663d, + +1.8682458400726318d, + +1.8700714111328125d, + +1.8718984127044678d, + +1.8737273216247559d, + +1.8755581378936768d, + +1.8773906230926514d, + +1.8792247772216797d, + +1.8810608386993408d, + +1.8828988075256348d, + +1.8847384452819824d, + +1.886579990386963d, + +1.888423204421997d, + +1.890268325805664d, + +1.8921151161193848d, + +1.8939638137817383d, + +1.8958141803741455d, + +1.8976664543151855d, + +1.8995206356048584d, + +1.901376485824585d, + +1.9032342433929443d, + +1.9050939083099365d, + +1.9069552421569824d, + +1.908818244934082d, + +1.9106833934783936d, + +1.9125502109527588d, + +1.9144186973571777d, + +1.9162893295288086d, + +1.9181616306304932d, + +1.9200356006622314d, + +1.9219114780426025d, + +1.9237892627716064d, + +1.9256689548492432d, + +1.9275505542755127d, + +1.929433822631836d, + +1.931318759918213d, + +1.9332058429718018d, + +1.9350945949554443d, + +1.9369852542877197d, + +1.938877820968628d, + +1.940772294998169d, + +1.9426684379577637d, + +1.9445664882659912d, + +1.9464664459228516d, + +1.9483680725097656d, + +1.9502718448638916d, + +1.9521772861480713d, + +1.9540846347808838d, + +1.955993890762329d, + +1.9579050540924072d, + +1.959817886352539d, + +1.9617326259613037d, + +1.9636495113372803d, + +1.9655680656433105d, + +1.9674885272979736d, + +1.9694106578826904d, + +1.9713349342346191d, + +1.9732608795166016d, + +1.975188970565796d, + +1.977118730545044d, + +1.9790503978729248d, + +1.9809842109680176d, + +1.982919692993164d, + +1.9848570823669434d, + +1.9867963790893555d, + +1.9887375831604004d, + +1.990680456161499d, + +1.9926254749298096d, + +1.994572401046753d, + +1.996521234512329d, + +1.998471736907959d, + +2.000424385070801d, + +2.0023789405822754d, + +2.004335403442383d, + +2.006293773651123d, + +2.008254051208496d, + +2.010216236114502d, + +2.0121798515319824d, + +2.014145851135254d, + +2.016113758087158d, + +2.0180835723876953d, + +2.0200552940368652d, + +2.022029399871826d, + +2.0240049362182617d, + +2.02598237991333d, + +2.0279617309570312d, + +2.0299429893493652d, + +2.0319266319274902d, + +2.03391170501709d, + +2.0358991622924805d, + +2.0378880500793457d, + +2.039879322052002d, + +2.041872501373291d, + +2.0438671112060547d, + +2.0458641052246094d, + +2.047863006591797d, + +2.049863815307617d, + +2.0518670082092285d, + +2.0538716316223145d, + +2.055878162384033d, + +2.057887077331543d, + +2.0598974227905273d, + +2.0619101524353027d, + +2.063924789428711d, + +2.065941333770752d, + +2.067959785461426d, + +2.0699801445007324d, + +2.07200288772583d, + +2.0740270614624023d, + +2.0760536193847656d, + +2.0780820846557617d, + +2.0801124572753906d, + +2.0821447372436523d, + +2.084178924560547d, + +2.0862154960632324d, + +2.0882534980773926d, + +2.0902938842773438d, + +2.0923361778259277d, + +2.0943803787231445d, + +2.0964269638061523d, + +2.0984749794006348d, + +2.100525379180908d, + +2.1025776863098145d, + +2.1046319007873535d, + +2.1066884994506836d, + +2.1087465286254883d, + +2.110806941986084d, + +2.1128692626953125d, + +2.114933490753174d, + +2.117000102996826d, + +2.1190686225891113d, + +2.1211390495300293d, + +2.12321138381958d, + +2.1252856254577637d, + +2.1273622512817383d, + +2.1294407844543457d, + +2.131521224975586d, + +2.133604049682617d, + +2.135688304901123d, + +2.13777494430542d, + +2.139863967895508d, + +2.1419544219970703d, + +2.144047260284424d, + +2.14614200592041d, + +2.1482391357421875d, + +2.1503376960754395d, + +2.1524391174316406d, + +2.1545419692993164d, + +2.156647205352783d, + +2.1587538719177246d, + +2.1608633995056152d, + +2.1629743576049805d, + +2.1650876998901367d, + +2.167203426361084d, + +2.169320583343506d, + +2.1714401245117188d, + +2.1735615730285645d, + +2.175685405731201d, + +2.1778111457824707d, + +2.179938793182373d, + +2.1820688247680664d, + +2.1842007637023926d, + +2.1863350868225098d, + +2.1884708404541016d, + +2.1906094551086426d, + +2.192749500274658d, + +2.194891929626465d, + +2.1970362663269043d, + +2.1991829872131348d, + +2.201331615447998d, + +2.2034826278686523d, + +2.2056355476379395d, + +2.2077903747558594d, + +2.2099475860595703d, + +2.212106704711914d, + +2.214268207550049d, + +2.2164316177368164d, + +2.218596935272217d, + +2.220764636993408d, + +2.2229342460632324d, + +2.2251062393188477d, + +2.2272801399230957d, + +2.2294564247131348d, + +2.2316346168518066d, + +2.2338151931762695d, + +2.2359976768493652d, + +2.2381820678710938d, + +2.2403693199157715d, + +2.242558002471924d, + +2.244749069213867d, + +2.2469425201416016d, + +2.2491378784179688d, + +2.2513351440429688d, + +2.2535347938537598d, + +2.2557363510131836d, + +2.2579402923583984d, + +2.2601466178894043d, + +2.262354850769043d, + +2.2645654678344727d, + +2.266777992248535d, + +2.2689924240112305d, + +2.271209716796875d, + +2.273428440093994d, + +2.2756495475769043d, + +2.2778730392456055d, + +2.2800989151000977d, + +2.2823266983032227d, + +2.2845563888549805d, + +2.2867884635925293d, + +2.289022922515869d, + +2.291259288787842d, + +2.2934980392456055d, + +2.295738697052002d, + +2.2979817390441895d, + +2.300227165222168d, + +2.3024744987487793d, + +2.3047242164611816d, + +2.306975841522217d, + +2.309229850769043d, + +2.31148624420166d, + +2.31374454498291d, + +2.316005229949951d, + +2.318267822265625d, + +2.32053279876709d, + +2.3228001594543457d, + +2.3250694274902344d, + +2.3273415565490723d, + +2.3296151161193848d, + +2.3318915367126465d, + +2.334169864654541d, + +2.3364500999450684d, + +2.338733196258545d, + +2.3410181999206543d, + +2.3433055877685547d, + +2.345594882965088d, + +2.347886562347412d, + +2.3501806259155273d, + +2.3524770736694336d, + +2.3547754287719727d, + +2.3570761680603027d, + +2.3593788146972656d, + +2.3616843223571777d, + +2.3639917373657227d, + +2.3663015365600586d, + +2.3686132431030273d, + +2.370927333831787d, + +2.373243808746338d, + +2.3755626678466797d, + +2.3778839111328125d, + +2.380207061767578d, + +2.3825325965881348d, + +2.3848605155944824d, + +2.387190818786621d, + +2.3895230293273926d, + +2.391857624053955d, + +2.3941946029663086d, + +2.396533966064453d, + +2.3988752365112305d, + +2.401218891143799d, + +2.4035654067993164d, + +2.4059133529663086d, + +2.40826416015625d, + +2.4106173515319824d, + +2.4129724502563477d, + +2.415329933166504d, + +2.417689800262451d, + +2.4200520515441895d, + +2.4224166870117188d, + +2.424783229827881d, + +2.427152633666992d, + +2.4295239448547363d, + +2.4318976402282715d, + +2.4342737197875977d, + +2.436652183532715d, + +2.439032554626465d, + +2.441415786743164d, + +2.4438014030456543d, + +2.4461889266967773d, + +2.4485788345336914d, + +2.4509711265563965d, + +2.4533658027648926d, + +2.4557628631591797d, + +2.458162307739258d, + +2.460564136505127d, + +2.462968349456787d, + +2.46537446975708d, + +2.4677834510803223d, + +2.4701943397521973d, + +2.4726080894470215d, + +2.4750237464904785d, + +2.4774417877197266d, + +2.479862689971924d, + +2.482285499572754d, + +2.484710693359375d, + +2.487138271331787d, + +2.4895682334899902d, + +2.4920010566711426d, + +2.4944357872009277d, + +2.496872901916504d, + +2.499312400817871d, + +2.5017542839050293d, + +2.5041985511779785d, + +2.5066452026367188d, + +2.50909423828125d, + +2.5115456581115723d, + +2.5139999389648438d, + +2.516456127166748d, + +2.5189146995544434d, + +2.5213756561279297d, + +2.5238394737243652d, + +2.5263051986694336d, + +2.528773307800293d, + +2.5312442779541016d, + +2.533717155456543d, + +2.5361928939819336d, + +2.538670539855957d, + +2.5411510467529297d, + +2.5436339378356934d, + +2.546119213104248d, + +2.5486068725585938d, + +2.5510969161987305d, + +2.553589344024658d, + +2.556084632873535d, + +2.558581829071045d, + +2.5610814094543457d, + +2.5635838508605957d, + +2.5660886764526367d, + +2.5685958862304688d, + +2.571105480194092d, + +2.573617458343506d, + +2.576131820678711d, + +2.5786490440368652d, + +2.5811686515808105d, + +2.5836901664733887d, + +2.586214542388916d, + +2.5887417793273926d, + +2.591270923614502d, + +2.5938024520874023d, + +2.596336841583252d, + +2.5988736152648926d, + +2.601412773132324d, + +2.603954315185547d, + +2.6064987182617188d, + +2.6090455055236816d, + +2.6115946769714355d, + +2.6141462326049805d, + +2.6167001724243164d, + +2.6192569732666016d, + +2.6218161582946777d, + +2.624377727508545d, + +2.626941680908203d, + +2.6295084953308105d, + +2.632077217102051d, + +2.6346492767333984d, + +2.637223243713379d, + +2.6398000717163086d, + +2.6423792839050293d, + +2.644960880279541d, + +2.6475448608398438d, + +2.6501317024230957d, + +2.6527209281921387d, + +2.655313014984131d, + +2.657907009124756d, + +2.6605043411254883d, + +2.6631035804748535d, + +2.665705680847168d, + +2.6683101654052734d, + +2.67091703414917d, + +2.6735267639160156d, + +2.6761388778686523d, + +2.67875337600708d, + +2.681370735168457d, + +2.683990478515625d, + +2.686613082885742d, + +2.689237594604492d, + +2.6918654441833496d, + +2.69449520111084d, + +2.6971278190612793d, + +2.699763298034668d, + +2.7024011611938477d, + +2.7050414085388184d, + +2.70768404006958d, + +2.710329532623291d, + +2.712977886199951d, + +2.7156286239624023d, + +2.7182817459106445d, + }; + + /** Exponential over the range of 0 - 1 in increments of 2^-10 + * exp(x/1024) = expFracTableA[x] + expFracTableB[x]. + */ + private static final double[] EXP_FRAC_B = new double[] { + +0.0d, + +1.552583321178453E-10d, + +1.2423699995465188E-9d, + +4.194022929828008E-9d, + +9.94381632344361E-9d, + +1.9426261544163577E-8d, + +3.3576783010266685E-8d, + +5.3331719086630523E-8d, + +7.962832297769345E-8d, + +1.1340476362128895E-7d, + -8.281845251820919E-8d, + -3.126416414805498E-8d, + +3.058997113995161E-8d, + +1.0368579417304741E-7d, + -4.9452513107409435E-8d, + +4.8955889659397494E-8d, + -7.698155155722897E-8d, + +5.051784853384516E-8d, + -4.443661736519001E-8d, + +1.1593958457401774E-7d, + +5.575759739697068E-8d, + +1.4385227981629147E-8d, + -7.227368462584163E-9d, + -8.129108387083023E-9d, + +1.263202100290635E-8d, + +5.600896265625552E-8d, + -1.154629885168314E-7d, + -2.399186832888246E-8d, + +9.295948298604103E-8d, + -2.070841011504222E-9d, + -6.97066538508643E-8d, + -1.0898941254272996E-7d, + -1.1895963756343625E-7d, + -9.865691193993138E-8d, + -4.711988033385175E-8d, + +3.6613751875298095E-8d, + -8.491135959370133E-8d, + +6.610611940107793E-8d, + +1.3794148633283659E-8d, + -2.462631860370667E-9d, + +1.830278273495162E-8d, + +7.705834203598065E-8d, + -6.364563771711373E-8d, + +7.39978436695387E-8d, + +1.4122417557484554E-8d, + -3.881598887298574E-9d, + +2.0958481826069642E-8d, + +8.96162975425619E-8d, + -3.535214171178576E-8d, + -1.1455271549574576E-7d, + +9.140964977432485E-8d, + +1.0667524445105459E-7d, + -6.777752790396222E-8d, + +4.586785041291296E-8d, + -2.8245462428022094E-8d, + -5.071761314397018E-8d, + -2.0566368810068663E-8d, + +6.319146317890346E-8d, + -3.687854305539139E-8d, + -8.137269363160008E-8d, + -6.930491127388755E-8d, + +3.1184473002226595E-10d, + -1.0995299963140049E-7d, + +7.772668425499348E-8d, + +8.750367485925089E-8d, + -7.963112393823186E-8d, + +5.415131809829094E-8d, + +1.3006683896462346E-8d, + +3.634736373360733E-8d, + -1.132504393233074E-7d, + +4.2046187038837375E-8d, + +2.6396811618001066E-8d, + +7.92177143584738E-8d, + -3.691100820545433E-8d, + -8.257112559083188E-8d, + -5.676200971739166E-8d, + +4.151794514828518E-8d, + -2.5147255753587636E-8d, + -1.7335469415174996E-8d, + +6.595784859136531E-8d, + -1.2680354928109105E-8d, + -1.3824992526093461E-8d, + +6.353142754175797E-8d, + -1.8021197722549054E-8d, + -1.9054827792903468E-8d, + +6.144098503892116E-8d, + -1.3940903373095247E-8d, + -5.7694907599522404E-9d, + +8.696863522320578E-8d, + +2.6869297963554945E-8d, + +5.3366470162689076E-8d, + -7.094204160127543E-8d, + -1.0662027949814858E-7d, + -5.26498707801063E-8d, + +9.198855229106814E-8d, + +8.989677431456647E-8d, + -5.790384407322479E-8d, + -1.1197236522467887E-7d, + -7.12854317090566E-8d, + +6.51813137650059E-8d, + +6.003465022483798E-8d, + -8.569906238528267E-8d, + +1.0584469687624562E-7d, + -7.956144278281947E-8d, + +7.43676272093501E-8d, + +9.182512565315022E-8d, + -2.6157563728873715E-8d, + -4.012947040998503E-8d, + +5.094280572218447E-8d, + +9.675095351161728E-9d, + +7.552139802281006E-8d, + +1.1099566726533146E-8d, + +5.58656252899437E-8d, + -2.756054703800197E-8d, + +2.791018095971047E-10d, + -9.799351869734466E-8d, + -8.291832428736212E-8d, + +4.654720780112994E-8d, + +5.302803981406403E-8d, + -6.243126731995636E-8d, + -6.036655299348577E-8d, + +6.026878587378257E-8d, + +6.210379583313526E-8d, + -5.381287389094251E-8d, + -4.8012970400697E-8d, + +8.055420567281602E-8d, + +9.452180117175641E-8d, + -5.057430382371206E-9d, + +2.1288872215266507E-8d, + -6.380305844689076E-8d, + -2.0858800984600168E-8d, + -8.724006061713588E-8d, + -2.3470351753125604E-8d, + -6.690931338790221E-8d, + +2.192160831263035E-8d, + +5.6648446166177225E-9d, + -1.1461755745719884E-7d, + -9.944393412663547E-8d, + +5.2249837964645906E-8d, + +1.0311034276196487E-7d, + +5.4203784018566126E-8d, + -9.340259278913173E-8d, + -1.0022192034216903E-7d, + +3.481513333662908E-8d, + +7.436036590244714E-8d, + +1.9485199912395296E-8d, + +1.0968068384729757E-7d, + +1.0760175582979094E-7d, + +1.4322981952798675E-8d, + +6.933855730431659E-8d, + +3.530656968851287E-8d, + -8.669526204279467E-8d, + -5.7169586962345785E-8d, + -1.1345515834332824E-7d, + -1.605251622332555E-8d, + -2.298302779758532E-9d, + -7.110952399338234E-8d, + +1.70164513845372E-8d, + +2.4746155561368937E-8d, + -4.6834239957353325E-8d, + +4.1781076667923185E-8d, + +5.326182134294869E-8d, + -1.1302647617762544E-8d, + +8.759667154796094E-8d, + +1.126326877851684E-7d, + +6.48979555673987E-8d, + -5.451390316294111E-8d, + -6.0896188500539086E-9d, + -2.7152010585461855E-8d, + -1.1660424775832058E-7d, + -3.492984900939992E-8d, + -1.944841848873016E-8d, + -6.905990750285027E-8d, + +5.575538653428039E-8d, + +1.1768108384670781E-7d, + +1.178204606523101E-7d, + +5.727787111340131E-8d, + -6.284125161007433E-8d, + -3.0118152047565877E-9d, + -5.448044533034374E-10d, + -5.433154287341921E-8d, + +7.515630833946181E-8d, + -8.780756503572527E-8d, + -6.527407547535494E-8d, + -9.45487863616303E-8d, + +6.390098458668406E-8d, + -6.564672913105876E-8d, + -5.238488022920792E-9d, + +7.824500749252316E-9d, + -2.5339299158309795E-8d, + -1.036103313062145E-7d, + +1.2550633697348567E-8d, + +8.584676196065558E-8d, + +1.1740089468291563E-7d, + +1.0833697012353316E-7d, + +5.978002467397905E-8d, + -2.7143806069290897E-8d, + +8.711129287069315E-8d, + -7.316349947981893E-8d, + -3.00015852582934E-8d, + -2.0691000399732483E-8d, + -4.4100097152254264E-8d, + -9.909612209943178E-8d, + +5.38733640215475E-8d, + -6.0893829005035E-8d, + +3.457553391989844E-8d, + +1.0300006058273187E-7d, + -9.290053015365092E-8d, + -7.514966995961323E-8d, + -8.10254145615142E-8d, + -1.0938612624777085E-7d, + +7.932952721989251E-8d, + +9.428257290008738E-9d, + -7.952636967837795E-8d, + +5.203033137154554E-8d, + -7.159157201731446E-8d, + +2.7593424989059015E-8d, + +1.1231621190000476E-7d, + -5.469119869891027E-8d, + +4.560067256086347E-9d, + +5.280427179595944E-8d, + +9.119538242455128E-8d, + -1.1753008498403413E-7d, + -9.537874867759656E-8d, + -7.96118345325538E-8d, + -6.907085854395348E-8d, + -6.259620482221904E-8d, + -5.902712448725381E-8d, + -5.720173456146447E-8d, + -5.5957016861703E-8d, + -5.412881689012608E-8d, + -5.0551842723970724E-8d, + -4.405966390424518E-8d, + -3.348471032333413E-8d, + -1.7658271111516935E-8d, + +4.589506477601956E-9d, + +3.4429618182751655E-8d, + +7.303420385174346E-8d, + -1.168420305422519E-7d, + -5.718749537552229E-8d, + +1.4754809136835937E-8d, + +1.001616104682875E-7d, + -3.8207793300052055E-8d, + +7.766278405014509E-8d, + -2.7883635712109803E-8d, + -1.1524714043067699E-7d, + +5.517333625963128E-8d, + +7.724278756071081E-9d, + -1.7990934773848504E-8d, + -2.0786347668702902E-8d, + +5.251554594269693E-10d, + +4.7131849857076246E-8d, + -1.1819540733893871E-7d, + -1.742885956093543E-8d, + +1.1220467571570283E-7d, + +3.347954541376715E-8d, + -1.399157980498908E-8d, + -2.9013441705763093E-8d, + -1.0389614239253089E-8d, + +4.307749759934266E-8d, + -1.0583192018912101E-7d, + +2.0919226941745448E-8d, + -5.2305110482722706E-8d, + -8.588407110184028E-8d, + -7.861419797923639E-8d, + -2.929085835358592E-8d, + +6.329175751021792E-8d, + -3.807794163054899E-8d, + -9.377320954068088E-8d, + -1.0258469865953145E-7d, + -6.330187984612758E-8d, + +2.5286958775281306E-8d, + -7.40238661307607E-8d, + +1.1681688445204168E-7d, + -1.1623125976292733E-7d, + -5.6696107089038004E-8d, + +5.822140627806124E-8d, + -8.678466172071259E-9d, + -1.7757121899175995E-8d, + +3.220665454652531E-8d, + -9.598330731102836E-8d, + +7.573375369829243E-8d, + +7.174547784678893E-8d, + -1.0672213971363184E-7d, + +1.8395252217743006E-8d, + -2.8511112548600118E-8d, + -7.79306270997787E-9d, + +8.178019529487065E-8d, + +3.0220784595602374E-9d, + -4.4156343103298585E-9d, + +6.07014616741277E-8d, + -3.8809601937571554E-8d, + -6.329342805230603E-8d, + -1.1511990258493999E-8d, + +1.177739474561431E-7d, + +8.738625278484571E-8d, + -1.0143341551207646E-7d, + +2.9394972678456236E-8d, + +4.278345398213486E-9d, + +6.28805835150457E-8d, + -3.197037359731606E-8d, + -4.060821046423735E-8d, + +3.82160283750664E-8d, + -3.2666060441373307E-8d, + -1.3584500601329896E-8d, + +9.671332777035621E-8d, + +6.10626893063691E-8d, + +1.1913723189736356E-7d, + +3.3774671482641995E-8d, + +4.4651109654500895E-8d, + -8.539328154875224E-8d, + -1.166799420361101E-7d, + -4.794765976694151E-8d, + -1.1635256954820579E-7d, + -8.221241452580445E-8d, + +5.5737717715868425E-8d, + +6.034539636024073E-8d, + -6.712199323081945E-8d, + -8.697724830833087E-8d, + +2.0494942705297694E-9d, + -3.718924074653624E-8d, + +3.499747150995707E-8d, + -1.8535359161566028E-8d, + +4.1905679587096103E-8d, + -2.0821912536551675E-8d, + +3.297776915751238E-8d, + -3.3835280846270374E-8d, + +1.8437339356553904E-8d, + -4.734187609526424E-8d, + +8.527976799299225E-9d, + -5.1088103279787804E-8d, + +1.3513294656751725E-8d, + -3.480032127343472E-8d, + +4.367697180842916E-8d, + +1.1815196363705356E-8d, + +1.0932279207149782E-7d, + +9.907230065250944E-8d, + -1.764389559496152E-8d, + -1.1135725625095859E-9d, + -8.846040040259342E-8d, + -3.996962588736431E-8d, + -9.276238757878814E-8d, + -7.12139818505956E-9d, + -2.016525972830718E-8d, + +1.0782585410141121E-7d, + -9.868269632073771E-8d, + +7.686861750031585E-8d, + -7.947087669425045E-8d, + -8.955768055535647E-8d, + +4.791582240886607E-8d, + +9.583994718167641E-8d, + +5.5524866689108584E-8d, + -7.171796605211277E-8d, + -4.6157237582310713E-8d, + -1.0489751005162237E-7d, + -8.204903560604627E-9d, + +6.818588687884566E-9d, + -5.850916105103205E-8d, + +3.5549586192569994E-8d, + +5.1896700056778354E-8d, + -8.146080588190463E-9d, + +9.516285362051742E-8d, + -1.1368933260611668E-7d, + +8.187871486648885E-8d, + -3.206182925646474E-8d, + +2.265440168347286E-8d, + +8.938334752179552E-9d, + -7.187922490287331E-8d, + +1.9952407216533937E-8d, + +4.734805892507655E-8d, + +1.1642439930208906E-8d, + -8.582843599651953E-8d, + -5.3086706437795354E-9d, + +1.6121782610217253E-8d, + -2.0197142620980974E-8d, + -1.129242035557684E-7d, + -2.2298267863810133E-8d, + +1.4605950309628873E-8d, + -8.663710700190489E-10d, + -6.736873974532501E-8d, + +5.486523121881414E-8d, + -1.0965249168570443E-7d, + -8.27343074126263E-8d, + -1.0144703278439455E-7d, + +7.39809943048038E-8d, + -3.193297932837415E-8d, + +5.900393284617182E-8d, + +1.0973020465397083E-7d, + -1.1681436418514489E-7d, + +9.5985669644661E-8d, + +3.423560333632085E-8d, + -6.22836197265283E-8d, + +4.621027492345726E-8d, + -1.1575484316683829E-7d, + -6.997545435826076E-8d, + -5.3502441327259514E-8d, + -6.49667713553005E-8d, + -1.029980741248172E-7d, + +7.219393868923887E-8d, + -1.4854841678687828E-8d, + +1.1406713393562271E-7d, + -1.650155887561251E-8d, + +7.165331603232264E-8d, + -9.692697614257269E-8d, + -4.402550702194912E-8d, + -6.679737442193143E-9d, + +1.6492800268960003E-8d, + +2.68759245092879E-8d, + +2.5854805721793077E-8d, + +1.4815967715704613E-8d, + -4.852711011229633E-9d, + -3.176199594915881E-8d, + -6.452129525125173E-8d, + -1.01738658407525E-7d, + +9.639780418418697E-8d, + +5.4445606140746644E-8d, + +1.2219361033150988E-8d, + -2.8883532688356087E-8d, + -6.746431126005811E-8d, + -1.0212284427080097E-7d, + +1.0696094577483825E-7d, + +8.43527683868743E-8d, + +6.987544103716777E-8d, + +6.493457409236137E-8d, + +7.093715125593688E-8d, + +8.929153091001965E-8d, + -1.1701113164306871E-7d, + -6.972256643013266E-8d, + -5.848862070736576E-9d, + +7.602385197610123E-8d, + -6.110775144284437E-8d, + +6.101012058093429E-8d, + -3.304167134225169E-8d, + -1.0342514383702196E-7d, + +8.969907328603505E-8d, + +7.091600108064668E-8d, + +8.006778743052707E-8d, + +1.1857939200074815E-7d, + -5.0541412403312774E-8d, + +5.0970277930552287E-8d, + -5.229355472795119E-8d, + +1.1793478462381443E-7d, + +8.625007227318527E-8d, + +9.250422086873268E-8d, + -1.0028661472061573E-7d, + -1.384914052949463E-8d, + +1.1483560326413004E-7d, + +4.878798101459259E-8d, + +2.7866921183936055E-8d, + +5.3514180410849046E-8d, + -1.1124565511436785E-7d, + +1.186914813275767E-8d, + -5.253258132241335E-8d, + -6.458486486369316E-8d, + -2.2838888809969377E-8d, + +7.415557606805398E-8d, + -1.0568403170659571E-8d, + -3.7139182948393606E-8d, + -4.1022790876160215E-9d, + +8.999821367768787E-8d, + +8.201043988912348E-9d, + -9.616457442665051E-9d, + +3.8005886250603055E-8d, + -8.588890051473289E-8d, + +9.699937202692456E-8d, + +1.11298006674538E-7d, + -4.1527104733570825E-8d, + +1.1682852007826251E-7d, + +1.1099648061301941E-7d, + -5.755303038890997E-8d, + +8.948877445235827E-8d, + +7.675780395028194E-8d, + -9.427143563390596E-8d, + +5.471416081500162E-8d, + +4.8354824064383506E-8d, + -1.118706134478866E-7d, + +5.235528379688445E-8d, + +6.567708120053687E-8d, + -7.042204992948526E-8d, + -1.1603891006723397E-7d, + -6.968742825553785E-8d, + +7.01199184127881E-8d, + +6.645352711199266E-8d, + -7.919617109348822E-8d, + +1.1149986927391714E-7d, + -7.522074418324674E-8d, + +7.739252980388984E-8d, + +9.39987974788905E-8d, + -2.390421480210064E-8d, + -3.639873824357815E-8d, + +5.8015881615938497E-8d, + +2.2423186335040668E-8d, + +9.674534330665206E-8d, + +4.4068830785712375E-8d, + +1.0431875573076199E-7d, + +4.0584538834428926E-8d, + +9.279423236781974E-8d, + +2.404020521381534E-8d, + +7.425346071427343E-8d, + +6.529321706138789E-9d, + +6.080174837146273E-8d, + +1.6902327633329284E-10d, + +6.456806922371733E-8d, + +1.7100134295216033E-8d, + +9.770510970673519E-8d, + +6.94872148530716E-8d, + -6.602926393514549E-8d, + -6.889997193778161E-8d, + +6.240235720677117E-8d, + +9.098790295810902E-8d, + +1.8386917534879182E-8d, + +8.454972737414241E-8d, + +5.259099728747365E-8d, + -7.595453077213505E-8d, + -6.113203624663034E-8d, + +9.859622328905143E-8d, + -7.206766550807255E-8d, + -9.474579567171831E-8d, + +3.210408693366267E-8d, + +7.160716418525417E-8d, + +2.530870537724554E-8d, + -1.0524451040704701E-7d, + -8.008561371849434E-8d, + +1.0233519853128553E-7d, + -3.326791455362767E-8d, + -8.504961764629757E-9d, + -6.024017201863256E-8d, + +5.1500902632092514E-8d, + +8.98570720774568E-8d, + +5.638724693948384E-8d, + -4.734813904255994E-8d, + +1.8631451577542948E-8d, + +1.7470924137873214E-8d, + -4.926470933588261E-8d, + +5.84096713620797E-8d, + +1.0364355880696472E-7d, + +8.800655674349468E-8d, + +1.3069802481237792E-8d, + +1.1882454749452428E-7d, + -6.999215748398631E-8d, + -7.49674072510849E-8d, + +1.054760847603618E-7d, + -3.920012014371067E-9d, + +7.526183084319617E-8d, + +1.0618494853096868E-7d, + +9.043280094115832E-8d, + +2.9590395068826316E-8d, + -7.475571347653619E-8d, + +1.7401160143611842E-8d, + +6.923209420670962E-8d, + +8.232829924979753E-8d, + +5.82825404854514E-8d, + -1.3108606792380822E-9d, + -9.485602512220194E-8d, + +1.7663064617118723E-8d, + +9.942682855652123E-8d, + -8.638275100090915E-8d, + -6.132639063569726E-8d, + -6.221897889344726E-8d, + -8.745525834919404E-8d, + +1.029901759234897E-7d, + +3.3888561478632076E-8d, + -5.47315553588771E-8d, + +7.715994473741065E-8d, + -4.566098167230033E-8d, + +5.5257514455273825E-8d, + -9.530545662611411E-8d, + -1.889488909834863E-8d, + +4.769006625301079E-8d, + +1.0607041998938709E-7d, + -8.054981263802322E-8d, + -3.370929373457322E-8d, + +9.799164177397836E-9d, + +5.160291611526656E-8d, + +9.333090708652975E-8d, + -1.0180490545927503E-7d, + -5.533523366931846E-8d, + -4.044932340334176E-9d, + +5.370131904567218E-8d, + -1.1887814032213867E-7d, + -4.3307634616102625E-8d, + +4.363437558318513E-8d, + -9.482896784430338E-8d, + +1.9782818312325887E-8d, + -8.77224935488516E-8d, + +6.113879253864931E-8d, + -8.822335132515693E-9d, + -5.753754066078771E-8d, + -8.335545536862392E-8d, + -8.462309712606694E-8d, + -5.968586877433824E-8d, + -6.887556547891059E-9d, + +7.542967150507818E-8d, + -4.949331199790077E-8d, + +9.684172421525468E-8d, + +3.9260317944365246E-8d, + +1.784536881359796E-8d, + +3.426282345243592E-8d, + +9.018025618601154E-8d, + -5.1151708476133135E-8d, + +8.877492215808044E-8d, + +3.479545684576179E-8d, + +2.7002575714977818E-8d, + +6.707201545505014E-8d, + -8.173742908533777E-8d, + +5.909041310777802E-8d, + +1.439903710393587E-8d, + +2.4289317341982113E-8d, + +9.044519282818302E-8d, + -2.3866331257845713E-8d, + -7.853944465095286E-8d, + -7.188526769607005E-8d, + -2.2132706360079843E-9d, + -1.0624985110080394E-7d, + +9.453598391231829E-8d, + -1.134160131581847E-7d, + -1.315295870404327E-8d, + -7.981320644583728E-8d, + -7.327771300038971E-8d, + +8.155647334672472E-9d, + -7.222791579580787E-8d, + -7.430436987497092E-8d, + +3.633404807819848E-9d, + -7.512438321498593E-8d, + -7.044869765481105E-8d, + +1.9372589859580955E-8d, + -4.2365298585101096E-8d, + -1.552830824758035E-8d, + +1.0160071259930585E-7d, + +7.232201430620959E-8d, + -1.0164389431039905E-7d, + +5.826233477413577E-8d, + +7.6927415825689E-8d, + -4.392309439525734E-8d, + -6.414337408955734E-8d, + +1.799550702470095E-8d, + -3.4194410638967946E-8d, + +1.9437762419688045E-8d, + -5.7792549966531335E-8d, + -2.5731071572354522E-8d, + +1.173595905705643E-7d, + -1.0361863127101014E-7d, + +2.8330789837569332E-8d, + +3.81131861433539E-8d, + -7.252724942149532E-8d, + -6.342604067787756E-8d, + +6.716441526213986E-8d, + +8.257484966196574E-8d, + -1.5443717968117592E-8d, + +1.3280021798948244E-8d, + -6.79180673261558E-8d, + -1.8863249269709046E-8d, + -7.62162303263991E-8d, + +2.011589233663723E-10d, + -2.62683511147141E-8d, + +8.455684903712996E-8d, + +9.602293320384794E-8d, + +9.896378545255258E-9d, + +6.636396724067746E-8d, + +2.8777050870552646E-8d, + -1.0109271059094341E-7d, + -8.305334708631055E-8d, + +8.467026501338835E-8d, + -7.29821745001452E-8d, + -7.739491336852633E-8d, + +7.321238022013781E-8d, + -9.621538067089515E-8d, + -1.0705722541811197E-7d, + +4.247240125405735E-8d, + +1.1574222007764044E-7d, + +1.145412771487496E-7d, + +4.066036653218687E-8d, + -1.0410796803072171E-7d, + -7.955085231106037E-8d, + +1.1612776191572459E-7d, + +7.888519481107568E-9d, + +7.436813814737735E-8d, + +7.894935661289349E-8d, + +2.343525263620692E-8d, + -9.036933434595339E-8d, + -2.2239222395888823E-8d, + -8.784622656707742E-9d, + -4.819540032304379E-8d, + +9.975892708522332E-8d, + -3.9945124955316294E-8d, + +1.1345047468988893E-8d, + +1.702808472925844E-8d, + -2.10770182066344E-8d, + -1.0114948914089626E-7d, + +1.70518021921727E-8d, + +9.693260855961159E-8d, + -9.809953482725758E-8d, + -8.937957126662392E-8d, + -1.134963954323427E-7d, + +6.980004387880031E-8d, + -1.4494150014095534E-8d, + +1.122932337832262E-7d, + -2.483811732227808E-8d, + +5.278759515330048E-8d, + +1.0859222881334994E-7d, + -9.400056055939758E-8d, + -7.630957994128623E-8d, + -7.490757191850264E-8d, + -8.794689652049879E-8d, + -1.1357810855950775E-7d, + +8.846862323478745E-8d, + +4.32092015744956E-8d, + -9.082923009890997E-9d, + -6.655106680680314E-8d, + +1.1108184705020206E-7d, + +4.8838973948592766E-8d, + -1.2998975819628988E-8d, + -7.25680516883106E-8d, + -1.280024819379844E-7d, + -1.7743467191652895E-7d, + -2.1899520225809197E-7d, + +2.2602433110285232E-7d, + +2.0582268590356215E-7d, + +1.9911192455808124E-7d, + +2.0776878313278689E-7d, + +2.3367183133931002E-7d, + -1.9813568387704588E-7d, + -1.320972037315105E-7d, + -4.316580502355056E-8d, + +7.054443447243064E-8d, + +2.109212796025238E-7d, + -9.698281856949837E-8d, + +1.0239791185239086E-7d, + -1.4271754202157014E-7d, + +1.232402895636637E-7d, + -5.150590480969644E-8d, + -1.882201085012735E-7d, + +1.918355503889933E-7d, + +1.368893262241355E-7d, + +1.256828068633383E-7d, + +1.601222826656464E-7d, + -2.3472125169205568E-7d, + -1.032634625827871E-7d, + +7.957037517331382E-8d, + -1.6114314525832115E-7d, + +1.3018591370778052E-7d, + +1.8007284821359149E-9d, + -6.75421764491544E-8d, + -7.592155950645605E-8d, + -2.1414301981236817E-8d, + +9.79045937979623E-8d, + -1.9287515190177685E-7d, + +6.184953843236509E-8d, + -8.966500602352001E-8d, + -1.686490951669855E-7d, + -1.7316830893872364E-7d, + -1.0128633727463388E-7d, + +4.8935021740786486E-8d, + -1.9740129448026905E-7d, + +1.1532102163380318E-7d, + +3.5371542244169364E-8d, + +4.153321337726989E-8d, + +1.3575372396796738E-7d, + -1.5685449228299222E-7d, + +1.1933437776279623E-7d, + +1.2599421120614435E-8d, + +1.7331079674066365E-9d, + +8.869266069401045E-8d, + -2.013999442282902E-7d, + +8.709065843311144E-8d, + +2.453117120472083E-9d, + +2.3489472779602617E-8d, + +1.5216652792122652E-7d, + -8.638415150333099E-8d, + -2.1335475961524608E-7d, + -2.2677272333821516E-7d, + -1.246635423141374E-7d, + +9.494921297991565E-8d, + -4.27932550865546E-8d, + -5.907349480138712E-8d, + +4.809072216941908E-8d, + -1.9615359732789476E-7d, + +1.6385396676990034E-7d, + +1.7642714221524228E-7d, + -1.564440844355254E-7d, + +1.2090653407564583E-7d, + +5.679855838941285E-8d, + +1.3006497185242537E-7d, + -1.341336085949317E-7d, + +2.1987686050231372E-7d, + -2.3641341460419062E-7d, + -7.048932272279454E-8d, + -2.3401958604540354E-7d, + +2.2867766559333004E-7d, + -1.1089952719756529E-7d, + +1.7977178878541792E-7d, + +1.4903074102418675E-7d, + -2.011072593789072E-7d, + +8.504948422097802E-8d, + +5.5846006716348844E-8d, + +1.9014079059505456E-7d, + +1.3119976852347583E-8d, + +3.645999732952202E-9d, + +1.6374611405314333E-7d, + +1.8612397134087598E-8d, + +4.7113225346448296E-8d, + -2.2555535676499395E-7d, + +1.5631615647329739E-7d, + -2.3574653182047758E-7d, + +3.08072210937242E-8d, + +4.344259288116142E-9d, + +1.6374489573868447E-7d, + +3.42171232580676E-8d, + +9.46452492584643E-8d, + -1.297587351085525E-7d, + -1.601065201853145E-7d, + +5.6550495386976275E-9d, + -1.0725602261510391E-7d, + -1.9945408945084193E-8d, + -2.071910882200156E-7d, + -1.900947109027913E-7d, + +3.34069282059055E-8d, + -1.145810806477298E-8d, + +1.5421457732308477E-7d, + +5.5657084775121975E-8d, + +1.7177785285061278E-7d, + +2.7813027425289027E-8d, + +1.0267509648109748E-7d, + -7.839574072711142E-8d, + -3.648293887796095E-8d, + +2.3049492079013518E-7d, + -2.290530257391564E-7d, + +1.747018414872141E-8d, + +1.8477759656842807E-8d, + -2.2394073401050633E-7d, + -2.3085653185818848E-7d, + -1.7598351175286083E-10d, + -6.640551220774385E-9d, + +2.2868466674913266E-7d, + +2.3106230530437902E-7d, + +2.594209135294356E-9d, + +2.2221434720602702E-8d, + -1.847872222755186E-7d, + -1.3948659218254467E-7d, + +1.6023339607737848E-7d, + -2.3718944120137026E-7d, + +1.0087056692827474E-7d, + +2.228553660510707E-7d, + +1.3088328582956644E-7d, + -1.7292527438195104E-7d, + -2.0961068531216087E-7d, + +2.2951597845188004E-8d, + +5.005103745740068E-8d, + -1.2618366811281002E-7d, + -2.6784582477238417E-8d, + -1.2645600379949252E-7d, + +5.3774170051560117E-8d, + +3.9205810725333715E-8d, + -1.6802196396307013E-7d, + -8.893078799284047E-8d, + -1.9821451970481713E-7d, + -1.689060694498032E-8d, + -1.9648717830943396E-8d, + -2.0433926409457167E-7d, + -9.1973399031975E-8d, + -1.5723449006087263E-7d, + +7.887051614592191E-8d, + +1.4166246290402286E-7d, + +3.330146018487787E-8d, + +2.3278688667580978E-7d, + -2.1139124097042925E-7d, + +1.334449995534113E-7d, + -1.6104730195920897E-7d, + -1.3902314592614197E-7d, + +2.0169027167169864E-7d, + -9.040643863751471E-8d, + -5.946190852360168E-8d, + -1.8013411720005014E-7d, + +2.6595401669835947E-8d, + +8.607292924069425E-8d, + +4.84038176769263E-10d, + -2.2798356346688802E-7d, + -1.203028719549339E-7d, + -1.5111906039270745E-7d, + +1.5859915617670956E-7d, + -1.426262681506497E-7d, + -9.892260062323546E-8d, + -1.8492643515928268E-7d, + +7.840210076743552E-8d, + +2.1643071541578027E-7d, + +2.313664294893465E-7d, + +1.2541842003811723E-7d, + -9.920197743470107E-8d, + +3.655589133934081E-8d, + +5.807052689551411E-8d, + -3.244024724169575E-8d, + -2.327564406466327E-7d, + -6.38187356721971E-8d, + -2.3995994000400915E-10d, + -3.9793609609721186E-8d, + -1.802510054588344E-7d, + +5.745586744591196E-8d, + +1.987228872666507E-7d, + -2.3105188606976847E-7d, + +2.0088042407239129E-7d, + +6.624793114025702E-8d, + -1.5587043044056635E-7d, + +1.3606464059428694E-8d, + +1.0008761540741556E-7d, + +1.058213771597129E-7d, + +3.3058299602856804E-8d, + -1.1594886810010702E-7d, + +1.378919824418909E-7d, + -1.5683631181406778E-7d, + -4.4200075770425176E-8d, + +1.2250985436706623E-9d, + -1.8297013058336644E-8d, + -1.005004229646318E-7d, + +2.337202285991116E-7d, + +3.296104292035678E-8d, + -2.23668185816307E-7d, + -5.7055442971184756E-8d, + +5.82391923137467E-8d, + +1.244950238958056E-7d, + +1.4399358260219398E-7d, + +1.1901862840583523E-7d, + +5.1856152603337505E-8d, + -5.520562000491495E-8d, + -1.9987622893254038E-7d, + +9.697418238031897E-8d, + -1.1603376405901542E-7d, + +1.170714288147407E-7d, + -1.550851303094034E-7d, + +2.3472546699189522E-8d, + +1.78211222185955E-7d, + -1.6540009048230807E-7d, + -5.137865010872577E-8d, + +4.57490653163866E-8d, + +1.2829599363166098E-7d, + +1.985773325073412E-7d, + -2.1792661654989742E-7d, + -1.652218131743459E-7d, + -1.178234251477505E-7d, + -7.34071933723896E-8d, + -2.9646587857612632E-8d, + +1.5787194498912167E-8d, + +6.52252321321176E-8d, + +1.2100088103262734E-7d, + +1.8544977697201776E-7d, + -2.159273204728711E-7d, + -1.2711589287782304E-7d, + -2.2610609958205195E-8d, + +9.993330547750349E-8d, + -2.33974236642384E-7d, + -6.830955860192377E-8d, + +1.2244183812423448E-7d, + -1.3620325027706252E-7d, + +1.1178574689680927E-7d, + -8.490693031052439E-8d, + +2.2975389535985893E-7d, + +1.0445707500867073E-7d, + +1.8405243253979117E-8d, + -2.6033812325397097E-8d, + -2.6489990728664908E-8d, + +1.9409124727247465E-8d, + +1.1403826867020365E-7d, + -2.1706266226554237E-7d, + -1.7839974359909697E-8d, + +2.3725087624341041E-7d, + +7.37567604176979E-8d, + -2.9098805266958403E-8d, + -6.892713087722722E-8d, + -4.333719263537725E-8d, + +5.006436936098099E-8d, + +2.1367325342138113E-7d, + -2.6949659655907758E-8d, + -1.9256682968755803E-7d, + +1.960616287777496E-7d, + +1.876664741413704E-7d, + -2.1534486893602122E-7d, + -5.688830723853217E-8d, + +1.8861113228746644E-7d, + +4.6730779443102234E-8d, + -3.275360514112964E-9d, + +4.1011920825226876E-8d, + +1.820141955326842E-7d, + -5.468175655175594E-8d, + -1.8981247089866317E-7d, + -2.209492705846306E-7d, + -1.4566110577298295E-7d, + +3.848544860465368E-8d, + -1.429109630340783E-7d, + -2.105749999899302E-7d, + -1.6206609756618993E-7d, + +5.058693461947143E-9d, + -1.8359244902596882E-7d, + +2.2810251664891242E-7d, + -1.8791776732592608E-7d, + +1.3106843166204263E-9d, + -1.5543153797220025E-7d, + -1.7884997059081524E-7d, + -6.648490725635754E-8d, + +1.8412576154421806E-7d, + +9.860939269906055E-8d, + +1.5627006743114285E-7d, + -1.17260039161597E-7d, + +2.3416513526430908E-7d, + -2.1749172296989992E-7d, + -3.9242560971295217E-8d, + -1.822826971477839E-7d, + -1.6729355321895212E-7d, + +8.208715337901827E-9d, + -1.301267783434537E-7d, + -1.029741755377153E-7d, + +9.215765583599035E-8d, + -1.907487641016455E-8d, + +4.2661388254716074E-8d, + -1.9697226735187428E-7d, + +2.1819935527247946E-7d, + -1.398318929248588E-7d, + +1.6195123407015624E-7d, + +1.723826394935661E-7d, + -1.0602700638269148E-7d, + -1.9392742205954563E-7d, + -8.880302882034106E-8d, + +2.1186420987133E-7d, + +2.3375763256988976E-7d, + -2.0599801342241997E-8d, + -7.184550924856607E-8d, + +8.254840070367875E-8d, + }; + + /** Extended precision logarithm table over the range 1 - 2 in increments of 2^-10. */ + private static final double[][] LN_MANT = new double[][] { + {+0.0d, +0.0d, }, // 0 + {+9.760860120877624E-4d, -3.903230345984362E-11d, }, // 1 + {+0.0019512202125042677d, -8.124251825289188E-11d, }, // 2 + {+0.0029254043474793434d, -1.8374207360194882E-11d,}, // 3 + {+0.0038986406289041042d, -2.1324678121885073E-10d,}, // 4 + {+0.004870930686593056d, -4.5199654318611534E-10d,}, // 5 + {+0.00584227591753006d, -2.933016992001806E-10d, }, // 6 + {+0.006812678650021553d, -2.325147219074669E-10d, }, // 7 + {+0.007782140746712685d, -3.046577356838847E-10d, }, // 8 + {+0.008750664070248604d, -5.500631513861575E-10d, }, // 9 + {+0.00971824862062931d, +8.48292035519895E-10d, }, // 10 + {+0.010684899985790253d, +1.1422610134013436E-10d,}, // 11 + {+0.01165061630308628d, +9.168889933128375E-10d, }, // 12 + {+0.012615403160452843d, -5.303786078838E-10d, }, // 13 + {+0.013579258695244789d, -5.688639355498786E-10d, }, // 14 + {+0.01454218477010727d, +7.296670293275653E-10d, }, // 15 + {+0.015504186972975731d, -4.370104767451421E-10d, }, // 16 + {+0.016465261578559875d, +1.43695591408832E-9d, }, // 17 + {+0.01742541790008545d, -1.1862263158849434E-9d, }, // 18 + {+0.018384650349617004d, -9.482976524690715E-10d, }, // 19 + {+0.01934296265244484d, +1.9068609515836638E-10d,}, // 20 + {+0.020300358533859253d, +2.655990315697216E-10d, }, // 21 + {+0.021256837993860245d, +1.0315548713040775E-9d, }, // 22 + {+0.022212404757738113d, +5.13345647019085E-10d, }, // 23 + {+0.02316705882549286d, +4.5604151934208014E-10d,}, // 24 + {+0.02412080392241478d, -1.1255706987475148E-9d, }, // 25 + {+0.025073636323213577d, +1.2289023836765196E-9d, }, // 26 + {+0.02602556347846985d, +1.7990281828096504E-9d, }, // 27 + {+0.026976589113473892d, -1.4152718164638451E-9d, }, // 28 + {+0.02792670577764511d, +7.568772963781632E-10d, }, // 29 + {+0.0288759246468544d, -1.1449998592111558E-9d, }, // 30 + {+0.029824241995811462d, -1.6850976862319495E-9d, }, // 31 + {+0.030771657824516296d, +8.422373919843096E-10d, }, // 32 + {+0.0317181795835495d, +6.872350402175489E-10d, }, // 33 + {+0.03266380727291107d, -4.541194749189272E-10d, }, // 34 + {+0.03360854089260101d, -8.9064764856495E-10d, }, // 35 + {+0.034552380442619324d, +1.0640404096769032E-9d, }, // 36 + {+0.0354953333735466d, -3.5901655945224663E-10d,}, // 37 + {+0.03643739968538284d, -3.4829517943661266E-9d, }, // 38 + {+0.037378571927547455d, +8.149473794244232E-10d, }, // 39 + {+0.03831886500120163d, -6.990650304449166E-10d, }, // 40 + {+0.03925827145576477d, +1.0883076226453258E-9d, }, // 41 + {+0.040196798741817474d, +3.845192807999274E-10d, }, // 42 + {+0.04113444685935974d, -1.1570594692045927E-9d, }, // 43 + {+0.04207121580839157d, -1.8877045166697178E-9d, }, // 44 + {+0.043007105588912964d, -1.6332083257987747E-10d,}, // 45 + {+0.04394212365150452d, -1.7950057534514933E-9d, }, // 46 + {+0.04487626254558563d, +2.302710041648838E-9d, }, // 47 + {+0.045809537172317505d, -1.1410233017161343E-9d, }, // 48 + {+0.04674194008111954d, -3.0498741599744685E-9d, }, // 49 + {+0.04767347127199173d, -1.8026348269183678E-9d, }, // 50 + {+0.04860413819551468d, -3.233204600453039E-9d, }, // 51 + {+0.04953393340110779d, +1.7211688427961583E-9d, }, // 52 + {+0.05046287178993225d, -2.329967807055457E-10d, }, // 53 + {+0.05139094591140747d, -4.191810118556531E-11d, }, // 54 + {+0.052318163216114044d, -3.5574324788328143E-9d, }, // 55 + {+0.053244516253471375d, -1.7346590916458485E-9d, }, // 56 + {+0.05417001247406006d, -4.343048751383674E-10d, }, // 57 + {+0.055094651877880096d, +1.92909364037955E-9d, }, // 58 + {+0.056018441915512085d, -5.139745677199588E-10d, }, // 59 + {+0.05694137513637543d, +1.2637629975129189E-9d, }, // 60 + {+0.05786345899105072d, +1.3840561112481119E-9d, }, // 61 + {+0.058784693479537964d, +1.414889689612056E-9d, }, // 62 + {+0.05970507860183716d, +2.9199191907666474E-9d, }, // 63 + {+0.0606246218085289d, +7.90594243412116E-12d, }, // 64 + {+0.06154331564903259d, +1.6844747839686189E-9d, }, // 65 + {+0.06246116757392883d, +2.0498074572151747E-9d, }, // 66 + {+0.06337818503379822d, -4.800180493433863E-9d, }, // 67 + {+0.06429435312747955d, -2.4220822960064277E-9d, }, // 68 + {+0.06520968675613403d, -4.179048566709334E-9d, }, // 69 + {+0.06612417101860046d, +6.363872957010456E-9d, }, // 70 + {+0.06703783571720123d, +9.339468680056365E-10d, }, // 71 + {+0.06795066595077515d, -4.04226739708981E-9d, }, // 72 + {+0.0688626617193222d, -7.043545052852817E-9d, }, // 73 + {+0.06977382302284241d, -6.552819560439773E-9d, }, // 74 + {+0.07068414986133575d, -1.0571674860370546E-9d, }, // 75 + {+0.07159365713596344d, -3.948954622015801E-9d, }, // 76 + {+0.07250232994556427d, +1.1776625988228244E-9d, }, // 77 + {+0.07341018319129944d, +9.221072639606492E-10d, }, // 78 + {+0.07431721687316895d, -3.219119568928366E-9d, }, // 79 + {+0.0752234160900116d, +5.147575929018918E-9d, }, // 80 + {+0.07612881064414978d, -2.291749683541979E-9d, }, // 81 + {+0.07703337073326111d, +5.749565906124772E-9d, }, // 82 + {+0.07793712615966797d, +9.495158151301779E-10d, }, // 83 + {+0.07884006202220917d, -3.144331429489291E-10d, }, // 84 + {+0.0797421783208847d, +3.430029236134205E-9d, }, // 85 + {+0.08064348995685577d, -1.2499290483167703E-9d, }, // 86 + {+0.08154398202896118d, +2.011215719133196E-9d, }, // 87 + {+0.08244366943836212d, -2.2728753031387152E-10d,}, // 88 + {+0.0833425521850586d, -6.508966857277253E-9d, }, // 89 + {+0.0842406153678894d, -4.801131671405377E-10d, }, // 90 + {+0.08513787388801575d, +4.406750291994231E-9d, }, // 91 + {+0.08603434264659882d, -5.304795662536171E-9d, }, // 92 + {+0.08692999184131622d, +1.6284313912612293E-9d, }, // 93 + {+0.08782485127449036d, -3.158898981674071E-9d, }, // 94 + {+0.08871890604496002d, -3.3324878834139977E-9d, }, // 95 + {+0.08961215615272522d, +2.536961912893389E-9d, }, // 96 + {+0.09050461649894714d, +9.737596728980696E-10d, }, // 97 + {+0.0913962870836258d, -6.600437262505396E-9d, }, // 98 + {+0.09228715300559998d, -3.866609889222889E-9d, }, // 99 + {+0.09317722916603088d, -4.311847594020281E-9d, }, // 100 + {+0.09406651556491852d, -6.525851105645959E-9d, }, // 101 + {+0.09495499730110168d, +5.799080912675435E-9d, }, // 102 + {+0.09584270417690277d, +4.2634204358490415E-9d, }, // 103 + {+0.09672962129116058d, +5.167390528799477E-9d, }, // 104 + {+0.09761576354503632d, -4.994827392841906E-9d, }, // 105 + {+0.09850110113620758d, +4.970725577861395E-9d, }, // 106 + {+0.09938566386699677d, +6.6496705953229645E-9d, }, // 107 + {+0.10026945173740387d, +1.4262712796792241E-9d, }, // 108 + {+0.1011524498462677d, +5.5822855204629114E-9d, }, // 109 + {+0.10203467309474945d, +5.593494835247651E-9d, }, // 110 + {+0.10291612148284912d, +2.8332008343480686E-9d, }, // 111 + {+0.10379679501056671d, -1.3289231465997192E-9d, }, // 112 + {+0.10467669367790222d, -5.526819276639527E-9d, }, // 113 + {+0.10555580258369446d, +6.503128678219282E-9d, }, // 114 + {+0.10643415153026581d, +6.317463237641817E-9d, }, // 115 + {+0.10731174051761627d, -4.728528221305482E-9d, }, // 116 + {+0.10818853974342346d, +4.519199083083901E-9d, }, // 117 + {+0.10906457901000977d, +5.606492666349878E-9d, }, // 118 + {+0.10993985831737518d, -1.220176214398581E-10d, }, // 119 + {+0.11081436276435852d, +3.5759315936869937E-9d, }, // 120 + {+0.11168810725212097d, +3.1367659571899855E-9d, }, // 121 + {+0.11256109178066254d, -1.0543075713098835E-10d,}, // 122 + {+0.11343331634998322d, -4.820065619207094E-9d, }, // 123 + {+0.11430476605892181d, +5.221136819669415E-9d, }, // 124 + {+0.11517547070980072d, +1.5395018670011342E-9d, }, // 125 + {+0.11604541540145874d, +3.5638391501880846E-10d,}, // 126 + {+0.11691460013389587d, +2.9885336757136527E-9d, }, // 127 + {+0.11778303980827332d, -4.151889860890893E-9d, }, // 128 + {+0.11865071952342987d, -4.853823938804204E-9d, }, // 129 + {+0.11951763927936554d, +2.189226237170704E-9d, }, // 130 + {+0.12038381397724152d, +3.3791993048776982E-9d, }, // 131 + {+0.1212492436170578d, +1.5811884868243975E-11d,}, // 132 + {+0.12211392819881439d, -6.6045909118908625E-9d, }, // 133 + {+0.1229778528213501d, -2.8786263916116364E-10d,}, // 134 + {+0.12384103238582611d, +5.354472503748251E-9d, }, // 135 + {+0.12470348179340363d, -3.2924463896248744E-9d, }, // 136 + {+0.12556517124176025d, +4.856678149580005E-9d, }, // 137 + {+0.12642613053321838d, +1.2791850600366742E-9d, }, // 138 + {+0.12728634476661682d, +2.1525945093362843E-9d, }, // 139 + {+0.12814581394195557d, +8.749974471767862E-9d, }, // 140 + {+0.129004567861557d, -7.461209161105275E-9d, }, // 141 + {+0.12986254692077637d, +1.4390208226263824E-8d, }, // 142 + {+0.1307198405265808d, -1.3839477920475328E-8d, }, // 143 + {+0.13157635927200317d, -1.483283901239408E-9d, }, // 144 + {+0.13243216276168823d, -6.889072914229094E-9d, }, // 145 + {+0.1332872211933136d, +9.990351100568362E-10d, }, // 146 + {+0.13414156436920166d, -6.370937412495338E-9d, }, // 147 + {+0.13499516248703003d, +2.05047480130511E-9d, }, // 148 + {+0.1358480453491211d, -2.29509872547079E-9d, }, // 149 + {+0.13670018315315247d, +1.16354361977249E-8d, }, // 150 + {+0.13755163550376892d, -1.452496267904829E-8d, }, // 151 + {+0.1384023129940033d, +9.865115839786888E-9d, }, // 152 + {+0.13925230503082275d, -3.369999130712228E-9d, }, // 153 + {+0.14010155200958252d, +6.602496401651853E-9d, }, // 154 + {+0.14095008373260498d, +1.1205312852298845E-8d, }, // 155 + {+0.14179790019989014d, +1.1660367213160203E-8d, }, // 156 + {+0.142645001411438d, +9.186471222585239E-9d, }, // 157 + {+0.14349138736724854d, +4.999341878263704E-9d, }, // 158 + {+0.14433705806732178d, +3.11611905696257E-10d, }, // 159 + {+0.14518201351165771d, -3.6671598175618173E-9d, }, // 160 + {+0.14602625370025635d, -5.730477881659618E-9d, }, // 161 + {+0.14686977863311768d, -4.674900007989718E-9d, }, // 162 + {+0.1477125883102417d, +6.999732437141968E-10d, }, // 163 + {+0.14855468273162842d, +1.159150872494107E-8d, }, // 164 + {+0.14939609169960022d, -6.082714828488485E-10d, }, // 165 + {+0.15023678541183472d, -4.905712741596318E-9d, }, // 166 + {+0.1510767638683319d, -1.124848988733307E-10d, }, // 167 + {+0.15191605687141418d, -1.484557220949851E-8d, }, // 168 + {+0.15275460481643677d, +1.1682026251371384E-8d, }, // 169 + {+0.15359249711036682d, -8.757272519238786E-9d, }, // 170 + {+0.15442964434623718d, +1.4419920764774415E-8d, }, // 171 + {+0.15526613593101501d, -7.019891063126053E-9d, }, // 172 + {+0.15610191226005554d, -1.230153548825964E-8d, }, // 173 + {+0.15693697333335876d, -2.574172005933276E-10d, }, // 174 + {+0.15777134895324707d, +4.748140799544371E-10d, }, // 175 + {+0.15860503911972046d, -8.943081874891003E-9d, }, // 176 + {+0.15943801403045654d, +2.4500739038517657E-9d, }, // 177 + {+0.1602703034877777d, +6.007922084557054E-9d, }, // 178 + {+0.16110190749168396d, +2.8835418231126645E-9d, }, // 179 + {+0.1619328260421753d, -5.772862039728412E-9d, }, // 180 + {+0.16276302933692932d, +1.0988372954605789E-8d, }, // 181 + {+0.16359257698059082d, -5.292913162607026E-9d, }, // 182 + {+0.16442140936851501d, +6.12956339275823E-9d, }, // 183 + {+0.16524958610534668d, -1.3210039516811888E-8d, }, // 184 + {+0.16607704758644104d, -2.5711014608334873E-9d, }, // 185 + {+0.16690382361412048d, +9.37721319457112E-9d, }, // 186 + {+0.1677299439907074d, -6.0370682395944045E-9d, }, // 187 + {+0.168555349111557d, +1.1918249660105651E-8d, }, // 188 + {+0.1693800985813141d, +4.763282949656017E-9d, }, // 189 + {+0.17020416259765625d, +3.4223342273948817E-9d, }, // 190 + {+0.1710275411605835d, +9.014612241310916E-9d, }, // 191 + {+0.1718502640724182d, -7.145758990550526E-9d, }, // 192 + {+0.172672301530838d, -1.4142763934081504E-8d, }, // 193 + {+0.1734936535358429d, -1.0865453656579032E-8d, }, // 194 + {+0.17431432008743286d, +3.794385569450774E-9d, }, // 195 + {+0.1751343309879303d, +1.1399188501627291E-9d, }, // 196 + {+0.17595365643501282d, +1.2076238768270153E-8d, }, // 197 + {+0.1767723262310028d, +7.901084730502162E-9d, }, // 198 + {+0.17759034037590027d, -1.0288181007465474E-8d, }, // 199 + {+0.1784076690673828d, -1.15945645153806E-8d, }, // 200 + {+0.17922431230545044d, +5.073923825786778E-9d, }, // 201 + {+0.18004029989242554d, +1.1004278077575267E-8d, }, // 202 + {+0.1808556318283081d, +7.2831502374676964E-9d, }, // 203 + {+0.18167030811309814d, -5.0054634662706464E-9d, }, // 204 + {+0.18248429894447327d, +5.022108460298934E-9d, }, // 205 + {+0.18329763412475586d, +8.642254225732676E-9d, }, // 206 + {+0.18411031365394592d, +6.931054493326395E-9d, }, // 207 + {+0.18492233753204346d, +9.619685356326533E-10d, }, // 208 + {+0.18573370575904846d, -8.194157257980706E-9d, }, // 209 + {+0.18654438853263855d, +1.0333241479437797E-8d, }, // 210 + {+0.1873544454574585d, -1.9948340196027965E-9d, }, // 211 + {+0.1881638467311859d, -1.4313002926259948E-8d, }, // 212 + {+0.1889725625514984d, +4.241536392174967E-9d, }, // 213 + {+0.18978065252304077d, -4.877952454011428E-9d, }, // 214 + {+0.1905880868434906d, -1.0813801247641613E-8d, }, // 215 + {+0.1913948655128479d, -1.2513218445781325E-8d, }, // 216 + {+0.19220098853111267d, -8.925958555729115E-9d, }, // 217 + {+0.1930064558982849d, +9.956860681280245E-10d, }, // 218 + {+0.193811297416687d, -1.1505428993246996E-8d, }, // 219 + {+0.1946154534816742d, +1.4217997464522202E-8d, }, // 220 + {+0.19541901350021362d, -1.0200858727747717E-8d, }, // 221 + {+0.19622188806533813d, +5.682607223902455E-9d, }, // 222 + {+0.1970241367816925d, +3.2988908516009827E-9d, }, // 223 + {+0.19782572984695435d, +1.3482965534659446E-8d, }, // 224 + {+0.19862669706344604d, +7.462678536479685E-9d, }, // 225 + {+0.1994270384311676d, -1.3734273888891115E-8d, }, // 226 + {+0.20022669434547424d, +1.0521983802642893E-8d, }, // 227 + {+0.20102575421333313d, -8.152742388541905E-9d, }, // 228 + {+0.2018241584300995d, -9.133484280193855E-9d, }, // 229 + {+0.20262190699577332d, +8.59763959528144E-9d, }, // 230 + {+0.2034190595149994d, -1.3548568223001414E-8d, }, // 231 + {+0.20421552658081055d, +1.4847880344628818E-8d, }, // 232 + {+0.20501139760017395d, +5.390620378060543E-9d, }, // 233 + {+0.2058066427707672d, -1.1109834472051523E-8d, }, // 234 + {+0.20660123229026794d, -3.845373872038116E-9d, }, // 235 + {+0.20739519596099854d, -1.6149279479975042E-9d, }, // 236 + {+0.20818853378295898d, -3.4174925203771133E-9d, }, // 237 + {+0.2089812457561493d, -8.254443919468538E-9d, }, // 238 + {+0.20977330207824707d, +1.4672790944499144E-8d, }, // 239 + {+0.2105647623538971d, +6.753452542942992E-9d, }, // 240 + {+0.21135559678077698d, -1.218609462241927E-9d, }, // 241 + {+0.21214580535888672d, -8.254218316367887E-9d, }, // 242 + {+0.21293538808822632d, -1.3366540360587255E-8d, }, // 243 + {+0.2137243151664734d, +1.4231244750190031E-8d, }, // 244 + {+0.2145126760005951d, -1.3885660525939072E-8d, }, // 245 + {+0.21530038118362427d, -7.3304404046850136E-9d, }, // 246 + {+0.2160874605178833d, +5.072117654842356E-9d, }, // 247 + {+0.21687394380569458d, -5.505080220459036E-9d, }, // 248 + {+0.21765980124473572d, -8.286782292266659E-9d, }, // 249 + {+0.2184450328350067d, -2.302351152358085E-9d, }, // 250 + {+0.21922963857650757d, +1.3416565858314603E-8d, }, // 251 + {+0.22001364827156067d, +1.0033721426962048E-8d, }, // 252 + {+0.22079706192016602d, -1.1487079818684332E-8d, }, // 253 + {+0.22157981991767883d, +9.420348186357043E-9d, }, // 254 + {+0.2223619818687439d, +1.4110645699377834E-8d, }, // 255 + {+0.2231435477733612d, +3.5408485497116107E-9d, }, // 256 + {+0.22392448782920837d, +8.468072777056227E-9d, }, // 257 + {+0.2247048318386078d, +4.255446699237779E-11d, }, // 258 + {+0.22548454999923706d, +9.016946273084244E-9d, }, // 259 + {+0.22626367211341858d, +6.537034810260226E-9d, }, // 260 + {+0.22704219818115234d, -6.451285264969768E-9d, }, // 261 + {+0.22782009840011597d, +7.979956357126066E-10d, }, // 262 + {+0.22859740257263184d, -5.759582672039005E-10d, }, // 263 + {+0.22937411069869995d, -9.633854121180397E-9d, }, // 264 + {+0.23015019297599792d, +4.363736368635843E-9d, }, // 265 + {+0.23092567920684814d, +1.2549416560182509E-8d, }, // 266 + {+0.231700599193573d, -1.3946383592553814E-8d, }, // 267 + {+0.2324748933315277d, -1.458843364504023E-8d, }, // 268 + {+0.23324856162071228d, +1.1551692104697154E-8d, }, // 269 + {+0.23402166366577148d, +5.795621295524984E-9d, }, // 270 + {+0.23479416966438293d, -1.1301979046684263E-9d, }, // 271 + {+0.23556607961654663d, -8.303779721781787E-9d, }, // 272 + {+0.23633739352226257d, -1.4805271785394075E-8d, }, // 273 + {+0.23710808157920837d, +1.0085373835899469E-8d, }, // 274 + {+0.2378782033920288d, +7.679117635349454E-9d, }, // 275 + {+0.2386477291584015d, +8.69177352065934E-9d, }, // 276 + {+0.23941665887832642d, +1.4034725764547136E-8d, }, // 277 + {+0.24018502235412598d, -5.185064518887831E-9d, }, // 278 + {+0.2409527599811554d, +1.1544236628121676E-8d, }, // 279 + {+0.24171993136405945d, +5.523085719902123E-9d, }, // 280 + {+0.24248650670051575d, +7.456824943331887E-9d, }, // 281 + {+0.24325251579284668d, -1.1555923403029638E-8d, }, // 282 + {+0.24401789903640747d, +8.988361382732908E-9d, }, // 283 + {+0.2447827160358429d, +1.0381848020926893E-8d, }, // 284 + {+0.24554696679115295d, -6.480706118857055E-9d, }, // 285 + {+0.24631062150001526d, -1.0904271124793968E-8d, }, // 286 + {+0.2470736801624298d, -1.998183061531611E-9d, }, // 287 + {+0.247836172580719d, -8.676137737360023E-9d, }, // 288 + {+0.24859806895256042d, -2.4921733203932487E-10d,}, // 289 + {+0.2493593990802765d, -5.635173762130303E-9d, }, // 290 + {+0.2501201629638672d, -2.3951455355985637E-8d, }, // 291 + {+0.25088030099868774d, +5.287121672447825E-9d, }, // 292 + {+0.2516399025917053d, -6.447877375049486E-9d, }, // 293 + {+0.25239890813827515d, +1.32472428796441E-9d, }, // 294 + {+0.2531573176383972d, +2.9479464287605006E-8d, }, // 295 + {+0.2539151906967163d, +1.9284247135543574E-8d, }, // 296 + {+0.2546725273132324d, -2.8390360197221716E-8d, }, // 297 + {+0.255429208278656d, +6.533522495226226E-9d, }, // 298 + {+0.2561853528022766d, +5.713225978895991E-9d, }, // 299 + {+0.25694090127944946d, +2.9618050962556135E-8d, }, // 300 + {+0.25769591331481934d, +1.950605015323617E-8d, }, // 301 + {+0.25845038890838623d, -2.3762031507525576E-8d, }, // 302 + {+0.2592042088508606d, +1.98818938195077E-8d, }, // 303 + {+0.25995755195617676d, -2.751925069084042E-8d, }, // 304 + {+0.2607102394104004d, +1.3703391844683932E-8d, }, // 305 + {+0.26146239042282104d, +2.5193525310038174E-8d, }, // 306 + {+0.2622140049934387d, +7.802219817310385E-9d, }, // 307 + {+0.26296502351760864d, +2.1983272709242607E-8d, }, // 308 + {+0.2637155055999756d, +8.979279989292184E-9d, }, // 309 + {+0.2644653916358948d, +2.9240221157844312E-8d, }, // 310 + {+0.265214741230011d, +2.4004885823813374E-8d, }, // 311 + {+0.2659635543823242d, -5.885186277410878E-9d, }, // 312 + {+0.2667117714881897d, +1.4300386517357162E-11d,}, // 313 + {+0.2674594521522522d, -1.7063531531989365E-8d, }, // 314 + {+0.26820653676986694d, +3.3218524692903896E-9d, }, // 315 + {+0.2689530849456787d, +2.3998252479954764E-9d, }, // 316 + {+0.2696990966796875d, -1.8997462070389404E-8d, }, // 317 + {+0.27044451236724854d, -4.350745270980051E-10d, }, // 318 + {+0.2711893916130066d, -6.892221115467135E-10d, }, // 319 + {+0.27193373441696167d, -1.89333199110902E-8d, }, // 320 + {+0.272677481174469d, +5.262017392507765E-9d, }, // 321 + {+0.27342069149017334d, +1.3115046679980076E-8d, }, // 322 + {+0.2741633653640747d, +5.4468361834451975E-9d, }, // 323 + {+0.2749055027961731d, -1.692337384653611E-8d, }, // 324 + {+0.27564704418182373d, +6.426479056697412E-9d, }, // 325 + {+0.2763880491256714d, +1.670735065191342E-8d, }, // 326 + {+0.27712851762771606d, +1.4733029698334834E-8d, }, // 327 + {+0.27786844968795776d, +1.315498542514467E-9d, }, // 328 + {+0.2786078453063965d, -2.2735061539223372E-8d, }, // 329 + {+0.27934664487838745d, +2.994379757313727E-9d, }, // 330 + {+0.28008490800857544d, +1.970577274107218E-8d, }, // 331 + {+0.28082263469696045d, +2.820392733542077E-8d, }, // 332 + {+0.2815598249435425d, +2.929187356678173E-8d, }, // 333 + {+0.28229647874832153d, +2.377086680926386E-8d, }, // 334 + {+0.2830325961112976d, +1.2440393009992529E-8d, }, // 335 + {+0.2837681770324707d, -3.901826104778096E-9d, }, // 336 + {+0.2845032215118408d, -2.4459827842685974E-8d, }, // 337 + {+0.2852376699447632d, +1.1165241398059789E-8d, }, // 338 + {+0.28597164154052734d, -1.54434478239181E-8d, }, // 339 + {+0.28670501708984375d, +1.5714110564653245E-8d, }, // 340 + {+0.28743791580200195d, -1.3782394940142479E-8d, }, // 341 + {+0.2881702184677124d, +1.6063569876284005E-8d, }, // 342 + {+0.28890204429626465d, -1.317176818216125E-8d, }, // 343 + {+0.28963327407836914d, +1.8504673536253893E-8d, }, // 344 + {+0.29036402702331543d, -7.334319635123628E-9d, }, // 345 + {+0.29109418392181396d, +2.9300903540317107E-8d, }, // 346 + {+0.2918238639831543d, +9.979706999541057E-9d, }, // 347 + {+0.29255300760269165d, -4.916314210412424E-9d, }, // 348 + {+0.293281614780426d, -1.4611908070155308E-8d, }, // 349 + {+0.2940096855163574d, -1.833351586679361E-8d, }, // 350 + {+0.29473721981048584d, -1.530926726615185E-8d, }, // 351 + {+0.2954642176628113d, -4.7689754029101934E-9d, }, // 352 + {+0.29619067907333374d, +1.4055868011423819E-8d, }, // 353 + {+0.296916663646698d, -1.7672547212604003E-8d, }, // 354 + {+0.2976420521736145d, +2.0020234215759705E-8d, }, // 355 + {+0.2983669638633728d, +8.688424478730524E-9d, }, // 356 + {+0.2990913391113281d, +8.69851089918337E-9d, }, // 357 + {+0.29981517791748047d, +2.0810681643102672E-8d, }, // 358 + {+0.3005385398864746d, -1.3821169493779352E-8d, }, // 359 + {+0.301261305809021d, +2.4769140784919128E-8d, }, // 360 + {+0.3019835948944092d, +1.8127576600610336E-8d, }, // 361 + {+0.3027053475379944d, +2.6612401062437074E-8d, }, // 362 + {+0.3034266233444214d, -8.629042891789934E-9d, }, // 363 + {+0.3041473627090454d, -2.724174869314043E-8d, }, // 364 + {+0.30486756563186646d, -2.8476975783775358E-8d, }, // 365 + {+0.3055872321128845d, -1.1587600174449919E-8d, }, // 366 + {+0.3063063621520996d, +2.417189020581056E-8d, }, // 367 + {+0.3070250153541565d, +1.99407553679345E-8d, }, // 368 + {+0.3077431917190552d, -2.35387025694381E-8d, }, // 369 + {+0.3084607720375061d, +1.3683509995845583E-8d, }, // 370 + {+0.30917787551879883d, +1.3137214081023085E-8d, }, // 371 + {+0.30989450216293335d, -2.444006866174775E-8d, }, // 372 + {+0.3106105327606201d, +2.0896888605749563E-8d, }, // 373 + {+0.31132614612579346d, -2.893149098508887E-8d, }, // 374 + {+0.31204116344451904d, +5.621509038251498E-9d, }, // 375 + {+0.3127557039260864d, +6.0778104626050015E-9d, }, // 376 + {+0.3134697675704956d, -2.6832941696716294E-8d, }, // 377 + {+0.31418323516845703d, +2.6826625274495256E-8d, }, // 378 + {+0.31489628553390503d, -1.1030897183911054E-8d, }, // 379 + {+0.31560879945755005d, -2.047124671392676E-8d, }, // 380 + {+0.3163207769393921d, -7.709990443086711E-10d, }, // 381 + {+0.3170322775840759d, -1.0812918808112342E-8d, }, // 382 + {+0.3177432417869568d, +9.727979174888975E-9d, }, // 383 + {+0.31845372915267944d, +1.9658551724508715E-9d, }, // 384 + {+0.3191636800765991d, +2.6222628001695826E-8d, }, // 385 + {+0.3198731541633606d, +2.3609400272358744E-8d, }, // 386 + {+0.32058215141296387d, -5.159602957634814E-9d, }, // 387 + {+0.32129061222076416d, +2.329701319016099E-10d, }, // 388 + {+0.32199859619140625d, -1.910633190395738E-8d, }, // 389 + {+0.32270604372024536d, -2.863180390093667E-9d, }, // 390 + {+0.32341301441192627d, -9.934041364456825E-9d, }, // 391 + {+0.3241194486618042d, +1.999240777687192E-8d, }, // 392 + {+0.3248254060745239d, +2.801670341647724E-8d, }, // 393 + {+0.32553088665008545d, +1.4842534265191358E-8d, }, // 394 + {+0.32623589038848877d, -1.882789920477354E-8d, }, // 395 + {+0.3269403576850891d, -1.268923579073577E-8d, }, // 396 + {+0.32764434814453125d, -2.564688370677835E-8d, }, // 397 + {+0.3283478021621704d, +2.6015626820520968E-9d, }, // 398 + {+0.32905077934265137d, +1.3147747907784344E-8d, }, // 399 + {+0.3297532796859741d, +6.686493860720675E-9d, }, // 400 + {+0.33045530319213867d, -1.608884086544153E-8d, }, // 401 + {+0.33115679025650024d, +5.118287907840204E-9d, }, // 402 + {+0.3318578004837036d, +1.139367970944884E-8d, }, // 403 + {+0.3325583338737488d, +3.426327822115399E-9d, }, // 404 + {+0.33325839042663574d, -1.809622142990733E-8d, }, // 405 + {+0.3339579105377197d, +7.116780143398601E-9d, }, // 406 + {+0.3346569538116455d, +2.0145352306345386E-8d, }, // 407 + {+0.3353555202484131d, +2.167272474431968E-8d, }, // 408 + {+0.33605360984802246d, +1.2380696294966822E-8d, }, // 409 + {+0.33675122261047363d, -7.050361059209181E-9d, }, // 410 + {+0.3374482989311218d, +2.366314656322868E-8d, }, // 411 + {+0.3381449580192566d, -1.4010540194086646E-8d, }, // 412 + {+0.3388410806655884d, -1.860165465666482E-10d, }, // 413 + {+0.33953672647476196d, +6.206776940880773E-9d, }, // 414 + {+0.34023189544677734d, +5.841137379010982E-9d, }, // 415 + {+0.3409265875816345d, -6.11041311179286E-10d, }, // 416 + {+0.3416208028793335d, -1.2479264502054702E-8d, }, // 417 + {+0.34231454133987427d, -2.909443297645926E-8d, }, // 418 + {+0.34300774335861206d, +9.815805717097634E-9d, }, // 419 + {+0.3437005281448364d, -1.4291517981101049E-8d, }, // 420 + {+0.3443927764892578d, +1.8457821628427503E-8d, }, // 421 + {+0.34508460760116577d, -1.0481908869377813E-8d, }, // 422 + {+0.34577590227127075d, +1.876076001514746E-8d, }, // 423 + {+0.3464667797088623d, -1.2362653723769037E-8d, }, // 424 + {+0.3471571207046509d, +1.6016578405624026E-8d, }, // 425 + {+0.347847044467926d, -1.4652759033760925E-8d, }, // 426 + {+0.3485364317893982d, +1.549533655901835E-8d, }, // 427 + {+0.34922540187835693d, -1.2093068629412478E-8d, }, // 428 + {+0.3499138355255127d, +2.244531711424792E-8d, }, // 429 + {+0.35060185194015503d, +5.538565518604807E-10d, }, // 430 + {+0.35128939151763916d, -1.7511499366215853E-8d, }, // 431 + {+0.3519763946533203d, +2.850385787215544E-8d, }, // 432 + {+0.35266298055648804d, +2.003926370146842E-8d, }, // 433 + {+0.35334908962249756d, +1.734665280502264E-8d, }, // 434 + {+0.3540347218513489d, +2.1071983674869414E-8d, }, // 435 + {+0.35471993684768677d, -2.774475773922311E-8d, }, // 436 + {+0.3554046154022217d, -9.250975291734664E-9d, }, // 437 + {+0.3560888171195984d, +1.7590672330295415E-8d, }, // 438 + {+0.35677260160446167d, -6.1837904549178745E-9d, }, // 439 + {+0.35745590925216675d, -2.0330362973820856E-8d, }, // 440 + {+0.3581387400627136d, -2.42109990366786E-8d, }, // 441 + {+0.3588210940361023d, -1.7188958587407816E-8d, }, // 442 + {+0.35950297117233276d, +1.3711958590112228E-9d, }, // 443 + {+0.3601844310760498d, -2.7501042008405925E-8d, }, // 444 + {+0.36086535453796387d, +1.6036460343275798E-8d, }, // 445 + {+0.3615458607673645d, +1.3405964389498495E-8d, }, // 446 + {+0.36222589015960693d, +2.484237749027735E-8d, }, // 447 + {+0.36290550231933594d, -8.629967484362177E-9d, }, // 448 + {+0.36358463764190674d, -2.6778729562324134E-8d, }, // 449 + {+0.36426329612731934d, -2.8977490516960565E-8d, }, // 450 + {+0.36494147777557373d, -1.4601106624823502E-8d, }, // 451 + {+0.3656191825866699d, +1.69742947894444E-8d, }, // 452 + {+0.3662964701652527d, +6.7666740211281175E-9d, }, // 453 + {+0.36697328090667725d, +1.500201674336832E-8d, }, // 454 + {+0.3676496744155884d, -1.730424167425052E-8d, }, // 455 + {+0.36832553148269653d, +2.9676011119845104E-8d, }, // 456 + {+0.36900103092193604d, -2.2253590346826743E-8d, }, // 457 + {+0.36967599391937256d, +6.3372065441089185E-9d, }, // 458 + {+0.37035053968429565d, -3.145816653215968E-9d, }, // 459 + {+0.37102460861206055d, +9.515812117036965E-9d, }, // 460 + {+0.371698260307312d, -1.4669965113042639E-8d, }, // 461 + {+0.3723714351654053d, -1.548715389333397E-8d, }, // 462 + {+0.37304413318634033d, +7.674361647125109E-9d, }, // 463 + {+0.37371641397476196d, -4.181177882069608E-9d, }, // 464 + {+0.3743882179260254d, +9.158530500130718E-9d, }, // 465 + {+0.3750596046447754d, -1.13047236597869E-8d, }, // 466 + {+0.3757305145263672d, -5.36108186384227E-9d, }, // 467 + {+0.3764009475708008d, +2.7593452284747873E-8d, }, // 468 + {+0.37707096338272095d, +2.8557016344085205E-8d, }, // 469 + {+0.3777405619621277d, -1.868818164036E-9d, }, // 470 + {+0.3784096837043762d, -3.479042513414447E-9d, }, // 471 + {+0.37907832860946655d, +2.432550290565648E-8d, }, // 472 + {+0.37974655628204346d, +2.2538131805476768E-8d, }, // 473 + {+0.38041436672210693d, -8.244395239939089E-9d, }, // 474 + {+0.3810817003250122d, -7.821867597227376E-9d, }, // 475 + {+0.3817485570907593d, +2.4400089062515914E-8d, }, // 476 + {+0.3824149966239929d, +2.9410015940087773E-8d, }, // 477 + {+0.38308101892471313d, +7.799913824734797E-9d, }, // 478 + {+0.38374656438827515d, +1.976524624939355E-8d, }, // 479 + {+0.38441169261932373d, +6.291008309266035E-9d, }, // 480 + {+0.3850763440132141d, +2.757030889767851E-8d, }, // 481 + {+0.38574057817459106d, +2.4585794728405612E-8d, }, // 482 + {+0.3864043951034546d, -2.0764122246389383E-9d, }, // 483 + {+0.3870677351951599d, +7.77328837578952E-9d, }, // 484 + {+0.3877306580543518d, -4.8859560029989374E-9d, }, // 485 + {+0.3883931040763855d, +2.0133131420595028E-8d, }, // 486 + {+0.38905513286590576d, +2.380738071335498E-8d, }, // 487 + {+0.3897167444229126d, +6.7171126157142075E-9d, }, // 488 + {+0.39037787914276123d, +2.9046141593926277E-8d, }, // 489 + {+0.3910386562347412d, -2.7836800219410262E-8d, }, // 490 + {+0.3916988968849182d, +1.545909820981726E-8d, }, // 491 + {+0.39235877990722656d, -1.930436269002062E-8d, }, // 492 + {+0.3930181860923767d, -1.2343297554921835E-8d, }, // 493 + {+0.3936771750450134d, -2.268889128622553E-8d, }, // 494 + {+0.39433568716049194d, +9.835827818608177E-9d, }, // 495 + {+0.39499378204345703d, +2.6197411946856397E-8d, }, // 496 + {+0.3956514596939087d, +2.6965931069318893E-8d, }, // 497 + {+0.3963087201118469d, +1.2710331127772166E-8d, }, // 498 + {+0.39696556329727173d, -1.6001563011916016E-8d, }, // 499 + {+0.39762192964553833d, +1.0016001590267064E-9d, }, // 500 + {+0.3982778787612915d, +4.680767399874334E-9d, }, // 501 + {+0.39893341064453125d, -4.399582029272418E-9d, }, // 502 + {+0.39958852529525757d, -2.5676078228301587E-8d, }, // 503 + {+0.4002431631088257d, +1.0181870233355787E-9d, }, // 504 + {+0.40089738368988037d, +1.6639728835984655E-8d, }, // 505 + {+0.40155118703842163d, +2.174860642202632E-8d, }, // 506 + {+0.40220457315444946d, +1.6903781197123503E-8d, }, // 507 + {+0.40285754203796387d, +2.663119647467697E-9d, }, // 508 + {+0.40351009368896484d, -2.0416603812329616E-8d, }, // 509 + {+0.4041621685028076d, +7.82494078472695E-9d, }, // 510 + {+0.40481382608413696d, +2.833770747113627E-8d, }, // 511 + {+0.40546512603759766d, -1.7929433274271985E-8d, }, // 512 + {+0.40611594915390015d, -1.1214757379328965E-8d, }, // 513 + {+0.4067663550376892d, -1.0571553019207106E-8d, }, // 514 + {+0.40741634368896484d, -1.5449538712332313E-8d, }, // 515 + {+0.40806591510772705d, -2.529950530235105E-8d, }, // 516 + {+0.40871500968933105d, +2.0031331601617008E-8d, }, // 517 + {+0.4093637466430664d, +1.880755298741952E-9d, }, // 518 + {+0.41001206636428833d, -1.9600580584843318E-8d, }, // 519 + {+0.41065990924835205d, +1.573691633515306E-8d, }, // 520 + {+0.4113073945045471d, -1.0772154376548336E-8d, }, // 521 + {+0.411954402923584d, +2.0624330192486066E-8d, }, // 522 + {+0.4126010537147522d, -8.741139170029572E-9d, }, // 523 + {+0.4132472276687622d, +2.0881457123894216E-8d, }, // 524 + {+0.41389304399490356d, -9.177488027521808E-9d, }, // 525 + {+0.4145383834838867d, +2.0829952491625585E-8d, }, // 526 + {+0.4151833653450012d, -7.767915492597301E-9d, }, // 527 + {+0.4158278703689575d, +2.4774753446082082E-8d, }, // 528 + {+0.41647201776504517d, -2.1581119071750435E-10d,}, // 529 + {+0.4171157479286194d, -2.260047972865202E-8d, }, // 530 + {+0.4177590012550354d, +1.775884601423381E-8d, }, // 531 + {+0.41840189695358276d, +2.185301053838889E-9d, }, // 532 + {+0.4190443754196167d, -9.185071463667081E-9d, }, // 533 + {+0.4196864366531372d, -1.5821896727910552E-8d, }, // 534 + {+0.4203280806541443d, -1.719582086188318E-8d, }, // 535 + {+0.42096930742263794d, -1.2778508303324259E-8d, }, // 536 + {+0.42161011695861816d, -2.042639194493364E-9d, }, // 537 + {+0.42225050926208496d, +1.5538093219698803E-8d, }, // 538 + {+0.4228905439376831d, -1.9115659590156936E-8d, }, // 539 + {+0.42353010177612305d, +1.3729680248843432E-8d, }, // 540 + {+0.42416930198669434d, -4.611893838830296E-9d, }, // 541 + {+0.4248080849647522d, -1.4013456880651706E-8d, }, // 542 + {+0.42544645071029663d, -1.3953728897042917E-8d, }, // 543 + {+0.42608439922332764d, -3.912427573594197E-9d, }, // 544 + {+0.4267219305038452d, +1.6629734283189315E-8d, }, // 545 + {+0.42735910415649414d, -1.1413593493354881E-8d, }, // 546 + {+0.42799586057662964d, -2.792046157580119E-8d, }, // 547 + {+0.42863214015960693d, +2.723009182661306E-8d, }, // 548 + {+0.42926812171936035d, -2.4260535621557444E-8d, }, // 549 + {+0.42990362644195557d, -3.064060124024764E-9d, }, // 550 + {+0.43053877353668213d, -2.787640178598121E-8d, }, // 551 + {+0.4311734437942505d, +2.102412085257792E-8d, }, // 552 + {+0.4318077564239502d, +2.4939635093999683E-8d, }, // 553 + {+0.43244171142578125d, -1.5619414792273914E-8d, }, // 554 + {+0.4330751895904541d, +1.9065734894871523E-8d, }, // 555 + {+0.4337083101272583d, +1.0294301092654604E-8d, }, // 556 + {+0.4343410134315491d, +1.8178469851136E-8d, }, // 557 + {+0.4349733591079712d, -1.6379825102473853E-8d, }, // 558 + {+0.4356052279472351d, +2.6334323946685834E-8d, }, // 559 + {+0.43623673915863037d, +2.761628769925529E-8d, }, // 560 + {+0.436867892742157d, -1.2030229087793677E-8d, }, // 561 + {+0.4374985694885254d, +2.7106814809424793E-8d, }, // 562 + {+0.43812888860702515d, +2.631993083235205E-8d, }, // 563 + {+0.43875885009765625d, -1.3890028312254422E-8d, }, // 564 + {+0.43938833475112915d, +2.6186133735555794E-8d, }, // 565 + {+0.4400174617767334d, +2.783809071694788E-8d, }, // 566 + {+0.440646231174469d, -8.436135220472006E-9d, }, // 567 + {+0.44127458333969116d, -2.2534815932619883E-8d, }, // 568 + {+0.4419025182723999d, -1.3961804471714283E-8d, }, // 569 + {+0.4425300359725952d, +1.7778112039716255E-8d, }, // 570 + {+0.4431571960449219d, +1.3574569976673652E-8d, }, // 571 + {+0.4437839984893799d, -2.607907890164073E-8d, }, // 572 + {+0.4444103240966797d, +1.8518879652136628E-8d, }, // 573 + {+0.44503629207611084d, +2.865065604247164E-8d, }, // 574 + {+0.44566190242767334d, +4.806827797299427E-9d, }, // 575 + {+0.4462870955467224d, +7.0816970994232115E-9d, }, // 576 + {+0.44691193103790283d, -2.3640641240074437E-8d, }, // 577 + {+0.4475363492965698d, -2.7267718387865538E-8d, }, // 578 + {+0.4481603503227234d, -3.3126235292976077E-9d, }, // 579 + {+0.4487839937210083d, -1.0894001590268427E-8d, }, // 580 + {+0.4494072198867798d, +1.0077883359971829E-8d, }, // 581 + {+0.4500300884246826d, +4.825712712114668E-10d, }, // 582 + {+0.450652539730072d, +2.0407987470746858E-8d, }, // 583 + {+0.4512746334075928d, +1.073186581170719E-8d, }, // 584 + {+0.4518963694572449d, -2.8064314757880205E-8d, }, // 585 + {+0.45251762866973877d, +2.3709316816226527E-8d, }, // 586 + {+0.4531385898590088d, -1.2281487504266522E-8d, }, // 587 + {+0.4537591338157654d, -1.634864487421458E-8d, }, // 588 + {+0.45437926054000854d, +1.1985747222409522E-8d, }, // 589 + {+0.45499902963638306d, +1.3594057956219485E-8d, }, // 590 + {+0.4556184411048889d, -1.1047585095328619E-8d, }, // 591 + {+0.45623743534088135d, -1.8592937532754405E-9d, }, // 592 + {+0.4568560719490051d, -1.797135137545755E-8d, }, // 593 + {+0.4574742913246155d, +6.943684261645378E-10d, }, // 594 + {+0.4580921530723572d, -4.994175141684681E-9d, }, // 595 + {+0.45870959758758545d, +2.5039391215625133E-8d, }, // 596 + {+0.45932674407958984d, -2.7943366835352838E-8d, }, // 597 + {+0.45994341373443604d, +1.534146910128904E-8d, }, // 598 + {+0.46055978536605835d, -2.3450920230816267E-8d, }, // 599 + {+0.46117573976516724d, -2.4642997069960124E-8d, }, // 600 + {+0.4617912769317627d, +1.2232622070370946E-8d, }, // 601 + {+0.4624064564704895d, +2.80378133047839E-8d, }, // 602 + {+0.46302127838134766d, +2.3238237048117092E-8d, }, // 603 + {+0.46363574266433716d, -1.7013046451109475E-9d, }, // 604 + {+0.46424978971481323d, +1.3287778803035383E-8d, }, // 605 + {+0.46486347913742065d, +9.06393426961373E-9d, }, // 606 + {+0.4654768109321594d, -1.3910598647592876E-8d, }, // 607 + {+0.46608972549438477d, +4.430214458933614E-9d, }, // 608 + {+0.46670228242874146d, +4.942270562885745E-9d, }, // 609 + {+0.4673144817352295d, -1.1914734393460718E-8d, }, // 610 + {+0.4679262638092041d, +1.3922696570638494E-8d, }, // 611 + {+0.46853768825531006d, +2.3307929211781914E-8d, }, // 612 + {+0.46914875507354736d, +1.669813444584674E-8d, }, // 613 + {+0.469759464263916d, -5.450354376430758E-9d, }, // 614 + {+0.47036975622177124d, +1.6922605350647674E-8d, }, // 615 + {+0.4709796905517578d, +2.4667033200046904E-8d, }, // 616 + {+0.47158926725387573d, +1.8236762070433784E-8d, }, // 617 + {+0.472198486328125d, -1.915204563140137E-9d, }, // 618 + {+0.47280728816986084d, +2.426795414605756E-8d, }, // 619 + {+0.4734157919883728d, -2.19717006713618E-8d, }, // 620 + {+0.47402387857437134d, -2.0974352165535873E-8d, }, // 621 + {+0.47463154792785645d, +2.770970558184228E-8d, }, // 622 + {+0.4752389192581177d, +5.32006955298355E-9d, }, // 623 + {+0.47584593296051025d, -2.809054633964104E-8d, }, // 624 + {+0.4764525294303894d, -1.2470243596102937E-8d, }, // 625 + {+0.4770587682723999d, -6.977226702440138E-9d, }, // 626 + {+0.47766464948654175d, -1.1165866833118273E-8d, }, // 627 + {+0.47827017307281494d, -2.4591344661022708E-8d, }, // 628 + {+0.4788752794265747d, +1.2794996377383974E-8d, }, // 629 + {+0.4794800877571106d, -1.7772927065973874E-8d, }, // 630 + {+0.48008447885513306d, +3.35657712457243E-9d, }, // 631 + {+0.48068851232528687d, +1.7020465042442242E-8d, }, // 632 + {+0.481292188167572d, +2.365953779624783E-8d, }, // 633 + {+0.4818955063819885d, +2.3713798664443718E-8d, }, // 634 + {+0.4824984669685364d, +1.7622455019548098E-8d, }, // 635 + {+0.4831010699272156d, +5.823920246566496E-9d, }, // 636 + {+0.4837033152580261d, -1.1244184344361017E-8d, }, // 637 + {+0.48430514335632324d, +2.645961716432205E-8d, }, // 638 + {+0.4849066734313965d, +1.6207809718247905E-10d,}, // 639 + {+0.4855077862739563d, +2.9507744508973654E-8d, }, // 640 + {+0.48610860109329224d, -4.278201128741098E-9d, }, // 641 + {+0.48670899868011475d, +1.844722015961139E-8d, }, // 642 + {+0.4873090982437134d, -2.1092372471088425E-8d, }, // 643 + {+0.4879087805747986d, -3.2555596107382053E-9d, }, // 644 + {+0.48850810527801514d, +1.2784366845429667E-8d, }, // 645 + {+0.48910707235336304d, +2.7457984659996047E-8d, }, // 646 + {+0.48970574140548706d, -1.8409546441412518E-8d, }, // 647 + {+0.49030399322509766d, -5.179903818099661E-9d, }, // 648 + {+0.4909018874168396d, +7.97053127828682E-9d, }, // 649 + {+0.4914994239807129d, +2.146925464473481E-8d, }, // 650 + {+0.4920966625213623d, -2.3861648589988232E-8d, }, // 651 + {+0.4926934838294983d, -8.386923035320549E-9d, }, // 652 + {+0.4932899475097656d, +8.713990131749256E-9d, }, // 653 + {+0.4938860535621643d, +2.7865534085810115E-8d, }, // 654 + {+0.4944818615913391d, -1.011325138560159E-8d, }, // 655 + {+0.4950772523880005d, +1.4409851026316708E-8d, }, // 656 + {+0.495672345161438d, -1.735227547472004E-8d, }, // 657 + {+0.49626702070236206d, +1.4231078209064581E-8d, }, // 658 + {+0.49686139822006226d, -9.628709342929729E-9d, }, // 659 + {+0.4974554181098938d, -2.8907074856577267E-8d, }, // 660 + {+0.4980490207672119d, +1.6419797090870802E-8d, }, // 661 + {+0.49864232540130615d, +7.561041519403049E-9d, }, // 662 + {+0.49923527240753174d, +4.538983468118194E-9d, }, // 663 + {+0.49982786178588867d, +7.770560657946324E-9d, }, // 664 + {+0.500420093536377d, +1.767197002609876E-8d, }, // 665 + {+0.5010119676589966d, +3.46586694799214E-8d, }, // 666 + {+0.5016034841537476d, +5.914537964556077E-8d, }, // 667 + {+0.5021947622299194d, -2.7663203939320167E-8d, }, // 668 + {+0.5027855634689331d, +1.3064749115929298E-8d, }, // 669 + {+0.5033761262893677d, -5.667682106730711E-8d, }, // 670 + {+0.503966212272644d, +1.9424534974370594E-9d, }, // 671 + {+0.5045560598373413d, -4.908494602153544E-8d, }, // 672 + {+0.5051454305648804d, +2.906989285008994E-8d, }, // 673 + {+0.5057345628738403d, -1.602000800745108E-9d, }, // 674 + {+0.5063233375549316d, -2.148245271118002E-8d, }, // 675 + {+0.5069117546081543d, -3.016329994276181E-8d, }, // 676 + {+0.5074998140335083d, -2.7237099632871992E-8d, }, // 677 + {+0.5080875158309937d, -1.2297127301923986E-8d, }, // 678 + {+0.5086748600006104d, +1.5062624834468093E-8d, }, // 679 + {+0.5092618465423584d, +5.524744954836658E-8d, }, // 680 + {+0.5098485946655273d, -1.054736327333046E-8d, }, // 681 + {+0.5104348659515381d, +5.650063324725722E-8d, }, // 682 + {+0.5110208988189697d, +1.8376017791642605E-8d, }, // 683 + {+0.5116065740585327d, -5.309470636324855E-9d, }, // 684 + {+0.512191891670227d, -1.4154089255217218E-8d, }, // 685 + {+0.5127768516540527d, -7.756800301729815E-9d, }, // 686 + {+0.5133614540100098d, +1.4282730618002001E-8d, }, // 687 + {+0.5139456987380981d, +5.2364136172269755E-8d, }, // 688 + {+0.5145297050476074d, -1.2322940607922115E-8d, }, // 689 + {+0.5151132345199585d, +5.903831350855322E-8d, }, // 690 + {+0.5156965255737305d, +2.8426856726994483E-8d, }, // 691 + {+0.5162794589996338d, +1.544882070711032E-8d, }, // 692 + {+0.5168620347976685d, +2.0500353979930155E-8d, }, // 693 + {+0.5174442529678345d, +4.397691311390564E-8d, }, // 694 + {+0.5180262327194214d, -3.2936025225250634E-8d, }, // 695 + {+0.5186077356338501d, +2.857419553449673E-8d, }, // 696 + {+0.5191890001296997d, -9.51761338269325E-9d, }, // 697 + {+0.5197699069976807d, -2.7609457648450225E-8d, }, // 698 + {+0.520350456237793d, -2.5309316441333305E-8d, }, // 699 + {+0.5209306478500366d, -2.2258513086839407E-9d, }, // 700 + {+0.5215104818344116d, +4.203159541613745E-8d, }, // 701 + {+0.5220900774002075d, -1.1356287358852729E-8d, }, // 702 + {+0.5226693153381348d, -4.279090925831093E-8d, }, // 703 + {+0.5232481956481934d, -5.188364552285819E-8d, }, // 704 + {+0.5238267183303833d, -3.82465458937857E-8d, }, // 705 + {+0.5244048833847046d, -1.4923330530645769E-9d, }, // 706 + {+0.5249826908111572d, +5.8765598932137004E-8d, }, // 707 + {+0.5255602598190308d, +2.3703896609663678E-8d, }, // 708 + {+0.5261374711990356d, +1.2917117341231647E-8d, }, // 709 + {+0.5267143249511719d, +2.6789862192139226E-8d, }, // 710 + {+0.527290940284729d, -5.350322253112414E-8d, }, // 711 + {+0.5278670787811279d, +1.0839714455426386E-8d, }, // 712 + {+0.5284429788589478d, -1.821729591343314E-8d, }, // 713 + {+0.5290185213088989d, -2.1083014672301448E-8d, }, // 714 + {+0.5295937061309814d, +2.623848491704216E-9d, }, // 715 + {+0.5301685333251953d, +5.328392630534142E-8d, }, // 716 + {+0.5307431221008301d, +1.206790586971942E-8d, }, // 717 + {+0.5313173532485962d, -1.4356011804377797E-9d, }, // 718 + {+0.5318912267684937d, +1.3152074173459994E-8d, }, // 719 + {+0.5324647426605225d, +5.6208949382936426E-8d, }, // 720 + {+0.5330380201339722d, +8.90310227565917E-9d, }, // 721 + {+0.5336109399795532d, -9.179458802504127E-9d, }, // 722 + {+0.5341835021972656d, +2.337337845617735E-9d, }, // 723 + {+0.5347557067871094d, +4.3828918300477925E-8d, }, // 724 + {+0.535327672958374d, -3.5392250480081715E-9d, }, // 725 + {+0.53589928150177d, -2.0183663375378704E-8d, }, // 726 + {+0.5364705324172974d, -5.730898606435436E-9d, }, // 727 + {+0.537041425704956d, +4.0191927599879235E-8d, }, // 728 + {+0.5376120805740356d, -1.2522542401353875E-9d, }, // 729 + {+0.5381823778152466d, -1.0482571326594316E-8d, }, // 730 + {+0.5387523174285889d, +1.2871924223480165E-8d, }, // 731 + {+0.539322018623352d, -5.002774317612589E-8d, }, // 732 + {+0.539891242980957d, +3.960668706590162E-8d, }, // 733 + {+0.5404602289199829d, +4.372568630242375E-8d, }, // 734 + {+0.5410289764404297d, -3.730232461206926E-8d, }, // 735 + {+0.5415972471237183d, +3.5309026109857795E-8d, }, // 736 + {+0.5421652793884277d, +2.3508325311148225E-8d, }, // 737 + {+0.5427329540252686d, +4.6871403168921666E-8d, }, // 738 + {+0.5433003902435303d, -1.3445113140270216E-8d, }, // 739 + {+0.5438674688339233d, -3.786663982218041E-8d, }, // 740 + {+0.5444341897964478d, -2.602850370608209E-8d, }, // 741 + {+0.5450005531311035d, +2.2433348713144506E-8d, }, // 742 + {+0.5455666780471802d, -1.1326936872620137E-8d, }, // 743 + {+0.5461324453353882d, -7.737252533211342E-9d, }, // 744 + {+0.5466978549957275d, +3.3564604642699844E-8d, }, // 745 + {+0.5472630262374878d, -6.269066061111782E-9d, }, // 746 + {+0.5478278398513794d, -7.667998948729528E-9d, }, // 747 + {+0.5483922958374023d, +2.9728170818998143E-8d, }, // 748 + {+0.5489565134048462d, -1.2930091396008281E-8d, }, // 749 + {+0.5495203733444214d, -1.607434968107079E-8d, }, // 750 + {+0.5500838756561279d, +2.0653935146671156E-8d, }, // 751 + {+0.5506471395492554d, -2.1596593091833788E-8d, }, // 752 + {+0.5512100458145142d, -2.3259315921149476E-8d, }, // 753 + {+0.5517725944519043d, +1.6022492496522704E-8d, }, // 754 + {+0.5523349046707153d, -2.260433328226171E-8d, }, // 755 + {+0.5528968572616577d, -1.957497997726303E-8d, }, // 756 + {+0.5534584522247314d, +2.5465477111883854E-8d, }, // 757 + {+0.5540198087692261d, -6.33792454933092E-9d, }, // 758 + {+0.554580807685852d, +4.577835263278281E-9d, }, // 759 + {+0.5551414489746094d, +5.856589221771548E-8d, }, // 760 + {+0.5557018518447876d, +3.6769498759522324E-8d, }, // 761 + {+0.5562618970870972d, +5.874989409410614E-8d, }, // 762 + {+0.5568217039108276d, +5.649147309876989E-9d, }, // 763 + {+0.5573811531066895d, -2.9726830960751796E-9d, }, // 764 + {+0.5579402446746826d, +3.323458344853057E-8d, }, // 765 + {+0.5584990978240967d, -4.588749093664028E-9d, }, // 766 + {+0.5590575933456421d, +3.115616594184543E-9d, }, // 767 + {+0.5596157312393188d, +5.6696103838614634E-8d, }, // 768 + {+0.5601736307144165d, +3.7291263280048303E-8d, }, // 769 + {+0.5607312917709351d, -5.4751646725093355E-8d, }, // 770 + {+0.5612884759902954d, +1.9332630743320287E-8d, }, // 771 + {+0.5618454217910767d, +2.147161515775941E-8d, }, // 772 + {+0.5624021291732788d, -4.7989172862560625E-8d, }, // 773 + {+0.5629583597183228d, +4.971378973445109E-8d, }, // 774 + {+0.5635144710540771d, -4.2702997139152675E-8d, }, // 775 + {+0.5640701055526733d, +3.273212962622764E-8d, }, // 776 + {+0.5646255016326904d, +3.79438125545842E-8d, }, // 777 + {+0.5651806592941284d, -2.6725298288329835E-8d, }, // 778 + {+0.5657354593276978d, -4.1723833577410244E-8d, }, // 779 + {+0.5662899017333984d, -6.71028256490915E-9d, }, // 780 + {+0.56684410572052d, -4.055299181908475E-8d, }, // 781 + {+0.567397952079773d, -2.3702295314000405E-8d, }, // 782 + {+0.5679514408111572d, +4.4181618172507453E-8d, }, // 783 + {+0.5685046911239624d, +4.4228706309734985E-8d, }, // 784 + {+0.5690577030181885d, -2.3222346436879016E-8d, }, // 785 + {+0.5696103572845459d, -3.862412756175274E-8d, }, // 786 + {+0.5701626539230347d, -1.6390743801589046E-9d, }, // 787 + {+0.5707147121429443d, -3.1139472791083883E-8d, }, // 788 + {+0.5712664127349854d, -7.579587391156013E-9d, }, // 789 + {+0.5718178749084473d, -4.983281844744412E-8d, }, // 790 + {+0.5723689794540405d, -3.835454246739619E-8d, }, // 791 + {+0.5729197263717651d, +2.7190020372374008E-8d, }, // 792 + {+0.5734702348709106d, +2.7925807446276126E-8d, }, // 793 + {+0.574020504951477d, -3.5813506001861646E-8d, }, // 794 + {+0.5745704174041748d, -4.448550564530588E-8d, }, // 795 + {+0.5751199722290039d, +2.2423840341717488E-9d, }, // 796 + {+0.5756692886352539d, -1.450709904687712E-8d, }, // 797 + {+0.5762182474136353d, +2.4806815282282017E-8d, }, // 798 + {+0.5767669677734375d, +1.3057724436551892E-9d, }, // 799 + {+0.5773153305053711d, +3.4529452510568104E-8d, }, // 800 + {+0.5778634548187256d, +5.598413198183808E-9d, }, // 801 + {+0.5784112215042114d, +3.405124925700107E-8d, }, // 802 + {+0.5789587497711182d, +1.0074354568442952E-9d, }, // 803 + {+0.5795059204101562d, +2.600448597385527E-8d, }, // 804 + {+0.5800528526306152d, -9.83920263200211E-9d, }, // 805 + {+0.5805994272232056d, +1.3012807963586057E-8d, }, // 806 + {+0.5811457633972168d, -2.432215917965441E-8d, }, // 807 + {+0.5816917419433594d, -2.308736892479391E-9d, }, // 808 + {+0.5822374820709229d, -3.983067093146514E-8d, }, // 809 + {+0.5827828645706177d, -1.735366061128156E-8d, }, // 810 + {+0.5833280086517334d, -5.376251584638963E-8d, }, // 811 + {+0.5838727951049805d, -2.952399778965259E-8d, }, // 812 + {+0.5844172239303589d, +5.5685313670430624E-8d, }, // 813 + {+0.5849615335464478d, -3.6230268489088716E-8d, }, // 814 + {+0.5855053663253784d, +5.267948957869391E-8d, }, // 815 + {+0.5860490798950195d, -3.489144132234588E-8d, }, // 816 + {+0.5865923166275024d, +5.9006122320612716E-8d, }, // 817 + {+0.5871354341506958d, -2.2934896740542648E-8d, }, // 818 + {+0.5876781940460205d, -4.1975650319859075E-8d, }, // 819 + {+0.5882205963134766d, +2.2036094805348692E-9d, }, // 820 + {+0.5887627601623535d, -9.287179048539306E-9d, }, // 821 + {+0.5893045663833618d, +4.3079982556221595E-8d, }, // 822 + {+0.589846134185791d, +4.041399585161321E-8d, }, // 823 + {+0.5903874635696411d, -1.696746473863933E-8d, }, // 824 + {+0.5909284353256226d, -9.53795080582038E-9d, }, // 825 + {+0.5914691686630249d, -5.619010749352923E-8d, }, // 826 + {+0.5920095443725586d, -3.7398514182529506E-8d, }, // 827 + {+0.5925495624542236d, +4.71524479659295E-8d, }, // 828 + {+0.5930894613265991d, -4.0640692434639215E-8d, }, // 829 + {+0.5936288833618164d, +5.716453096255401E-8d, }, // 830 + {+0.5941681861877441d, -1.6745661720946737E-8d, }, // 831 + {+0.5947071313858032d, -2.3639110433141897E-8d, }, // 832 + {+0.5952457189559937d, +3.67972590471072E-8d, }, // 833 + {+0.595784068107605d, +4.566672575206695E-8d, }, // 834 + {+0.5963221788406372d, +3.2813537149653483E-9d, }, // 835 + {+0.5968599319458008d, +2.916199305533732E-8d, }, // 836 + {+0.5973974466323853d, +4.410412409109416E-9d, }, // 837 + {+0.5979346036911011d, +4.85464582112459E-8d, }, // 838 + {+0.5984715223312378d, +4.267089756924666E-8d, }, // 839 + {+0.5990082025527954d, -1.2906712010774655E-8d, }, // 840 + {+0.5995445251464844d, +1.3319784467641742E-9d, }, // 841 + {+0.6000806093215942d, -3.35137581974451E-8d, }, // 842 + {+0.6006163358688354d, +2.0734340706476473E-9d, }, // 843 + {+0.6011518239974976d, -1.0808162722402073E-8d, }, // 844 + {+0.601686954498291d, +4.735781872502109E-8d, }, // 845 + {+0.6022218465805054d, +5.76686738430634E-8d, }, // 846 + {+0.6027565002441406d, +2.043049589651736E-8d, }, // 847 + {+0.6032907962799072d, +5.515817703577808E-8d, }, // 848 + {+0.6038248538970947d, +4.2947540692649586E-8d, }, // 849 + {+0.6043586730957031d, -1.589678872195875E-8d, }, // 850 + {+0.6048921346664429d, -1.8613847754677912E-9d, }, // 851 + {+0.6054253578186035d, -3.3851886626187444E-8d, }, // 852 + {+0.6059582233428955d, +7.64416021682279E-9d, }, // 853 + {+0.6064908504486084d, +3.7201467248814224E-9d, }, // 854 + {+0.6070232391357422d, -4.532172996647129E-8d, }, // 855 + {+0.6075552701950073d, -1.997046552871766E-8d, }, // 856 + {+0.6080870628356934d, -3.913411606668587E-8d, }, // 857 + {+0.6086184978485107d, +1.6697361107868944E-8d, }, // 858 + {+0.609149694442749d, +2.8614950293715483E-8d, }, // 859 + {+0.6096806526184082d, -3.081552929643174E-9d, }, // 860 + {+0.6102112531661987d, +4.111645931319645E-8d, }, // 861 + {+0.6107416152954102d, +4.2298539553668435E-8d, }, // 862 + {+0.6112717390060425d, +7.630546413718035E-10d, }, // 863 + {+0.6118015050888062d, +3.601718675118614E-8d, }, // 864 + {+0.6123310327529907d, +2.914906573537692E-8d, }, // 865 + {+0.6128603219985962d, -1.9544361222269494E-8d, }, // 866 + {+0.613389253616333d, +9.442671392695732E-9d, }, // 867 + {+0.6139179468154907d, -2.8031202304593286E-9d, }, // 868 + {+0.6144464015960693d, -5.598619958143586E-8d, }, // 869 + {+0.6149744987487793d, -3.060220883766096E-8d, }, // 870 + {+0.6155023574829102d, -4.556583652800433E-8d, }, // 871 + {+0.6160298585891724d, +1.8626341656366314E-8d, }, // 872 + {+0.6165571212768555d, +4.305870564227991E-8d, }, // 873 + {+0.6170841455459595d, +2.8024460607734262E-8d, }, // 874 + {+0.6176109313964844d, -2.6183651590639875E-8d, }, // 875 + {+0.6181373596191406d, -6.406189112730307E-11d, }, // 876 + {+0.6186635494232178d, -1.2534241706168776E-8d, }, // 877 + {+0.6191893815994263d, +5.5906456251308664E-8d, }, // 878 + {+0.6197150945663452d, -3.286964881802063E-8d, }, // 879 + {+0.6202404499053955d, -4.0153537978961E-8d, }, // 880 + {+0.6207654476165771d, +3.434477109643361E-8d, }, // 881 + {+0.6212903261184692d, -4.750377491075032E-8d, }, // 882 + {+0.6218148469924927d, -4.699152670372743E-8d, }, // 883 + {+0.6223390102386475d, +3.617013128065961E-8d, }, // 884 + {+0.6228630542755127d, -3.6149218175202596E-8d, }, // 885 + {+0.6233867406845093d, -2.5243286814648133E-8d, }, // 886 + {+0.6239101886749268d, -5.003410681432538E-8d, }, // 887 + {+0.6244332790374756d, +8.974417915105033E-9d, }, // 888 + {+0.6249561309814453d, +3.285935446876949E-8d, }, // 889 + {+0.6254787445068359d, +2.190661054038537E-8d, }, // 890 + {+0.6260011196136475d, -2.3598354190515998E-8d, }, // 891 + {+0.6265231370925903d, +1.5838762427747586E-8d, }, // 892 + {+0.6270449161529541d, +2.129323729978037E-8d, }, // 893 + {+0.6275664567947388d, -6.950808333865794E-9d, }, // 894 + {+0.6280876398086548d, +5.059959203156465E-8d, }, // 895 + {+0.6286087036132812d, -4.41909071122557E-8d, }, // 896 + {+0.6291294097900391d, -5.262093550784066E-8d, }, // 897 + {+0.6296497583389282d, +2.559185648444699E-8d, }, // 898 + {+0.6301699876785278d, -4.768920119497491E-8d, }, // 899 + {+0.6306898593902588d, -3.376406008397877E-8d, }, // 900 + {+0.6312094926834106d, -5.156097914033476E-8d, }, // 901 + {+0.6317287683486938d, +1.840992392368355E-8d, }, // 902 + {+0.632247805595398d, +5.721951534729663E-8d, }, // 903 + {+0.6327667236328125d, -5.406177467045421E-8d, }, // 904 + {+0.6332851648330688d, +4.247320713683124E-8d, }, // 905 + {+0.6338034868240356d, -1.0524557502830645E-8d, }, // 906 + {+0.6343214511871338d, +2.5641927558519502E-8d, }, // 907 + {+0.6348391771316528d, +3.204135737993823E-8d, }, // 908 + {+0.6353566646575928d, +8.951285029786536E-9d, }, // 909 + {+0.6358739137649536d, -4.335116707228395E-8d, }, // 910 + {+0.6363908052444458d, -5.380016714089483E-9d, }, // 911 + {+0.6369074583053589d, +3.931710344901743E-9d, }, // 912 + {+0.6374238729476929d, -1.5140150088220166E-8d, }, // 913 + {+0.6379399299621582d, +5.688910024377372E-8d, }, // 914 + {+0.638455867767334d, -1.8124135273572568E-8d, }, // 915 + {+0.6389714479446411d, -1.486720391901626E-9d, }, // 916 + {+0.6394867897033691d, -1.2133811978747018E-8d, }, // 917 + {+0.6400018930435181d, -4.9791700939901716E-8d, }, // 918 + {+0.6405166387557983d, +5.022188652837274E-9d, }, // 919 + {+0.6410311460494995d, +3.337143177933685E-8d, }, // 920 + {+0.6415454149246216d, +3.55284719912458E-8d, }, // 921 + {+0.6420594453811646d, +1.1765332726757802E-8d, }, // 922 + {+0.6425732374191284d, -3.7646381826067834E-8d, }, // 923 + {+0.6430866718292236d, +6.773803682579552E-9d, }, // 924 + {+0.6435998678207397d, +2.608736797081283E-8d, }, // 925 + {+0.6441128253936768d, +2.056466263408266E-8d, }, // 926 + {+0.6446255445480347d, -9.524376551107945E-9d, }, // 927 + {+0.6451379060745239d, +5.5299060775883977E-8d, }, // 928 + {+0.6456501483917236d, -2.3114497793159813E-8d, }, // 929 + {+0.6461620330810547d, -6.077779731902102E-9d, }, // 930 + {+0.6466736793518066d, -1.2531793589140273E-8d, }, // 931 + {+0.6471850872039795d, -4.220866994206517E-8d, }, // 932 + {+0.6476961374282837d, +2.4368339445199057E-8d, }, // 933 + {+0.6482070684432983d, -5.095229574221907E-8d, }, // 934 + {+0.6487176418304443d, -2.9485356677301627E-8d, }, // 935 + {+0.6492279767990112d, -3.0173901411577916E-8d, }, // 936 + {+0.649738073348999d, -5.275210583909726E-8d, }, // 937 + {+0.6502478122711182d, +2.2254737134350224E-8d, }, // 938 + {+0.6507574319839478d, -4.330693978322885E-8d, }, // 939 + {+0.6512666940689087d, -1.0753950588009912E-8d, }, // 940 + {+0.6517757177352905d, +9.686179886293545E-10d, }, // 941 + {+0.6522845029830933d, -7.875434494414498E-9d, }, // 942 + {+0.6527930498123169d, -3.702271091849158E-8d, }, // 943 + {+0.6533012390136719d, +3.2999073763758614E-8d, }, // 944 + {+0.6538093090057373d, -3.5966064858620067E-8d, }, // 945 + {+0.6543170213699341d, -5.23735298540578E-9d, }, // 946 + {+0.6548244953155518d, +6.237715351293023E-9d, }, // 947 + {+0.6553317308425903d, -1.279462699936282E-9d, }, // 948 + {+0.6558387279510498d, -2.7527887552743672E-8d, }, // 949 + {+0.6563453674316406d, +4.696233317356646E-8d, }, // 950 + {+0.6568518877029419d, -1.5967172745329108E-8d, }, // 951 + {+0.6573580503463745d, +2.2361985518423144E-8d, }, // 952 + {+0.657863974571228d, +4.2999935789083046E-8d, }, // 953 + {+0.6583696603775024d, +4.620570188811826E-8d, }, // 954 + {+0.6588751077651978d, +3.223791487908353E-8d, }, // 955 + {+0.659380316734314d, +1.3548138612715822E-9d, }, // 956 + {+0.6598852872848511d, -4.618575323863973E-8d, }, // 957 + {+0.6603899002075195d, +9.082960673843353E-9d, }, // 958 + {+0.6608942747116089d, +4.820873399634487E-8d, }, // 959 + {+0.6613985300064087d, -4.776104368314602E-8d, }, // 960 + {+0.6619024276733398d, -4.0151502150238136E-8d, }, // 961 + {+0.6624060869216919d, -4.791602708710648E-8d, }, // 962 + {+0.6629093885421753d, +4.8410188461165925E-8d, }, // 963 + {+0.6634125709533691d, +1.0663697110471944E-8d, }, // 964 + {+0.6639155149459839d, -4.1691464781797555E-8d, }, // 965 + {+0.66441810131073d, +1.080835500478704E-8d, }, // 966 + {+0.664920449256897d, +4.920784622407246E-8d, }, // 967 + {+0.6654226779937744d, -4.544868396511241E-8d, }, // 968 + {+0.6659245491027832d, -3.448944157854234E-8d, }, // 969 + {+0.6664261817932129d, -3.6870882345139385E-8d, }, // 970 + {+0.6669275760650635d, -5.234055273962444E-8d, }, // 971 + {+0.6674286127090454d, +3.856291077979099E-8d, }, // 972 + {+0.6679295301437378d, -2.327375671320742E-9d, }, // 973 + {+0.6684302091598511d, -5.555080534042001E-8d, }, // 974 + {+0.6689305305480957d, -1.6471487337453832E-9d, }, // 975 + {+0.6694306135177612d, +4.042486803683015E-8d, }, // 976 + {+0.6699305772781372d, -4.8293856891818295E-8d, }, // 977 + {+0.6704301834106445d, -2.9134931730784303E-8d, }, // 978 + {+0.6709295511245728d, -2.1058207594753368E-8d, }, // 979 + {+0.6714286804199219d, -2.3814619551682855E-8d, }, // 980 + {+0.6719275712966919d, -3.7155475428252136E-8d, }, // 981 + {+0.6724261045455933d, +5.8376834484391746E-8d, }, // 982 + {+0.6729245185852051d, +2.4611679969129262E-8d, }, // 983 + {+0.6734226942062378d, -1.899407107267079E-8d, }, // 984 + {+0.6739205121994019d, +4.7016079464436395E-8d, }, // 985 + {+0.6744182109832764d, -1.5529608026276525E-8d, }, // 986 + {+0.6749155521392822d, +3.203391672602453E-8d, }, // 987 + {+0.6754127740859985d, -4.8465821804075345E-8d, }, // 988 + {+0.6759096384048462d, -1.8364507801369988E-8d, }, // 989 + {+0.6764062643051147d, +3.3739397633046517E-9d, }, // 990 + {+0.6769026517868042d, +1.6994526063192333E-8d, }, // 991 + {+0.6773988008499146d, +2.2741891590028428E-8d, }, // 992 + {+0.6778947114944458d, +2.0860312877435047E-8d, }, // 993 + {+0.678390383720398d, +1.1593703222523284E-8d, }, // 994 + {+0.678885817527771d, -4.814386594291911E-9d, }, // 995 + {+0.6793810129165649d, -2.812076759125914E-8d, }, // 996 + {+0.6798759698867798d, -5.808261186903479E-8d, }, // 997 + {+0.680370569229126d, +2.4751837654582522E-8d, }, // 998 + {+0.6808650493621826d, -1.7793890245755405E-8d, }, // 999 + {+0.6813591718673706d, +5.294053246347931E-8d, }, // 1000 + {+0.681853175163269d, -1.2220826223585654E-9d, }, // 1001 + {+0.6823468208312988d, +5.8377876767612725E-8d, }, // 1002 + {+0.6828403472900391d, -6.437492120743254E-9d, }, // 1003 + {+0.6833335161209106d, +4.2990710043633113E-8d, }, // 1004 + {+0.6838265657424927d, -3.1516131027023284E-8d, }, // 1005 + {+0.684319257736206d, +8.70017386744679E-9d, }, // 1006 + {+0.6848117113113403d, +4.466959125843237E-8d, }, // 1007 + {+0.6853040456771851d, -4.25782656420497E-8d, }, // 1008 + {+0.6857960224151611d, -1.4386267593671393E-8d, }, // 1009 + {+0.6862877607345581d, +1.0274494061148778E-8d, }, // 1010 + {+0.686779260635376d, +3.164186629229597E-8d, }, // 1011 + {+0.6872705221176147d, +4.995334552140326E-8d, }, // 1012 + {+0.687761664390564d, -5.3763211240398744E-8d, }, // 1013 + {+0.6882524490356445d, -4.0852427502515625E-8d, }, // 1014 + {+0.688742995262146d, -3.0287143914420064E-8d, }, // 1015 + {+0.6892333030700684d, -2.183125937905008E-8d, }, // 1016 + {+0.6897233724594116d, -1.524901992178814E-8d, }, // 1017 + {+0.6902132034301758d, -1.0305018010328949E-8d, }, // 1018 + {+0.6907027959823608d, -6.764191876212205E-9d, }, // 1019 + {+0.6911921501159668d, -4.391824838015402E-9d, }, // 1020 + {+0.6916812658309937d, -2.9535446262017846E-9d, }, // 1021 + {+0.6921701431274414d, -2.2153227096187463E-9d, }, // 1022 + {+0.6926587820053101d, -1.943473623641502E-9d, }, // 1023 + }; + + + /** + * Class contains only static methods. + */ + private AccurateMathLiteralArrays() {} + + /** + * Load "EXP_INT_A". + * + * @return a clone of the data array. + */ + static double[] loadExpIntA() { + return EXP_INT_A.clone(); + } + /** + * Load "EXP_INT_B". + * + * @return a clone of the data array. + */ + static double[] loadExpIntB() { + return EXP_INT_B.clone(); + } + /** + * Load "EXP_FRAC_A". + * + * @return a clone of the data array. + */ + static double[] loadExpFracA() { + return EXP_FRAC_A.clone(); + } + /** + * Load "EXP_FRAC_B". + * + * @return a clone of the data array. + */ + static double[] loadExpFracB() { + return EXP_FRAC_B.clone(); + } + /** + * Load "LN_MANT". + * + * @return a clone of the data array. + */ + static double[][] loadLnMant() { + return LN_MANT.clone(); + } +} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMathLiteralArrays.java b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathLiteralArrays.java.bak similarity index 99% rename from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMathLiteralArrays.java rename to commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathLiteralArrays.java.bak index d4cc666e7..1767ddf84 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/FastMathLiteralArrays.java +++ b/commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathLiteralArrays.java.bak @@ -18,10 +18,10 @@ package org.apache.commons.math4.legacy.util; /** - * Utility class for loading tabulated data used by {@link FastMath}. + * Utility class for loading tabulated data used by {@link AccurateMath}. * */ -class FastMathLiteralArrays { +class AccurateMathLiteralArrays { /** Exponential evaluated at integer values, * exp(x) = expIntTableA[x + EXP_INT_TABLE_MAX_INDEX] + expIntTableB[x+EXP_INT_TABLE_MAX_INDEX]. */ @@ -6130,7 +6130,7 @@ class FastMathLiteralArrays { /** * Class contains only static methods. */ - private FastMathLiteralArrays() {} + private AccurateMathLiteralArrays() {} /** * Load "EXP_INT_A". diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/ExtendedFieldElementAbstractTest.java b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/ExtendedFieldElementAbstractTest.java similarity index 83% rename from commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/ExtendedFieldElementAbstractTest.java rename to commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/ExtendedFieldElementAbstractTest.java index dde0c5b92..7f5087ca7 100644 --- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/ExtendedFieldElementAbstractTest.java +++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/ExtendedFieldElementAbstractTest.java @@ -14,15 +14,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.commons.math4.legacy; +package org.apache.commons.math4.legacy.core; + +import org.junit.Assert; +import org.junit.Test; import org.apache.commons.numbers.arrays.LinearCombination; import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.simple.RandomSource; -import org.apache.commons.math4.legacy.util.FastMath; -import org.apache.commons.math4.legacy.util.MathArrays; -import org.junit.Assert; -import org.junit.Test; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; public abstract class ExtendedFieldElementAbstractTest> { @@ -113,7 +113,7 @@ public abstract class ExtendedFieldElementAbstractTest MathArithmeticException double[] zeroSum = new double[] {-1, 1}; diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/Decimal10.java b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/Decimal10.java similarity index 98% rename from commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/Decimal10.java rename to commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/Decimal10.java index b9e84f6a4..05bc1dceb 100644 --- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/Decimal10.java +++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/Decimal10.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.commons.math4.legacy.dfp; +package org.apache.commons.math4.legacy.core.dfp; public class Decimal10 extends DfpDec { diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/DfpDecTest.java b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/DfpDecTest.java similarity index 99% rename from commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/DfpDecTest.java rename to commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/DfpDecTest.java index 33c42e721..55351da8d 100644 --- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/DfpDecTest.java +++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/DfpDecTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.commons.math4.legacy.dfp; +package org.apache.commons.math4.legacy.core.dfp; import org.junit.After; import org.junit.Assert; diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/DfpMathTest.java b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/DfpMathTest.java similarity index 99% rename from commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/DfpMathTest.java rename to commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/DfpMathTest.java index 227d914fb..94a068687 100644 --- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/DfpMathTest.java +++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/DfpMathTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.commons.math4.legacy.dfp; +package org.apache.commons.math4.legacy.core.dfp; import org.junit.After; import org.junit.Assert; diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/DfpTest.java b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/DfpTest.java similarity index 99% rename from commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/DfpTest.java rename to commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/DfpTest.java index ca2360e68..c8bbe86b1 100644 --- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/dfp/DfpTest.java +++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/DfpTest.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package org.apache.commons.math4.legacy.dfp; +package org.apache.commons.math4.legacy.core.dfp; -import org.apache.commons.math4.legacy.ExtendedFieldElementAbstractTest; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.ExtendedFieldElementAbstractTest; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.numbers.core.Precision; import org.junit.After; import org.junit.Assert; @@ -1566,8 +1566,8 @@ public class DfpTest extends ExtendedFieldElementAbstractTest { DfpField field = new DfpField(100); Assert.assertEquals(0.0, field.getZero().toDouble(), Precision.SAFE_MIN); Assert.assertEquals(0.0, field.newDfp(0.0).toDouble(), Precision.SAFE_MIN); - Assert.assertEquals(-1, FastMath.copySign(1, field.newDfp(-0.0).toDouble()), Precision.EPSILON); - Assert.assertEquals(+1, FastMath.copySign(1, field.newDfp(+0.0).toDouble()), Precision.EPSILON); + Assert.assertEquals(-1, AccurateMath.copySign(1, field.newDfp(-0.0).toDouble()), Precision.EPSILON); + Assert.assertEquals(+1, AccurateMath.copySign(1, field.newDfp(+0.0).toDouble()), Precision.EPSILON); } @Test diff --git a/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/DfpTest.java.bak b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/DfpTest.java.bak new file mode 100644 index 000000000..cf0fc82c1 --- /dev/null +++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/dfp/DfpTest.java.bak @@ -0,0 +1,1674 @@ +/* + * 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.legacy.core.dfp; + +import org.apache.commons.math4.legacy.ExtendedFieldElementAbstractTest; +import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.numbers.core.Precision; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class DfpTest extends ExtendedFieldElementAbstractTest { + + @Override + protected Dfp build(final double x) { + return field.newDfp(x); + } + + private DfpField field; + private Dfp pinf; + private Dfp ninf; + private Dfp nan; + private Dfp snan; + private Dfp qnan; + + @Before + public void setUp() { + // Some basic setup. Define some constants and clear the status flags + field = new DfpField(20); + pinf = field.newDfp("1").divide(field.newDfp("0")); + ninf = field.newDfp("-1").divide(field.newDfp("0")); + nan = field.newDfp("0").divide(field.newDfp("0")); + snan = field.newDfp((byte)1, Dfp.SNAN); + qnan = field.newDfp((byte)1, Dfp.QNAN); + ninf.getField().clearIEEEFlags(); + } + + @After + public void tearDown() { + field = null; + pinf = null; + ninf = null; + nan = null; + snan = null; + qnan = null; + } + + // Generic test function. Takes params x and y and tests them for + // equality. Then checks the status flags against the flags argument. + // If the test fail, it prints the desc string + private void test(Dfp x, Dfp y, int flags, String desc) { + boolean b = x.equals(y); + + if (!x.equals(y) && !x.unequal(y)) // NaNs involved + b = (x.toString().equals(y.toString())); + + if (x.equals(field.newDfp("0"))) // distinguish +/- zero + b = (b && (x.toString().equals(y.toString()))); + + b = (b && x.getField().getIEEEFlags() == flags); + + if (!b) + Assert.assertTrue("assertion failed "+desc+" x = "+x.toString()+" flags = "+x.getField().getIEEEFlags(), b); + + x.getField().clearIEEEFlags(); + } + + @Test + public void testByteConstructor() { + Assert.assertEquals("0.", new Dfp(field, (byte) 0).toString()); + Assert.assertEquals("1.", new Dfp(field, (byte) 1).toString()); + Assert.assertEquals("-1.", new Dfp(field, (byte) -1).toString()); + Assert.assertEquals("-128.", new Dfp(field, Byte.MIN_VALUE).toString()); + Assert.assertEquals("127.", new Dfp(field, Byte.MAX_VALUE).toString()); + } + + @Test + public void testIntConstructor() { + Assert.assertEquals("0.", new Dfp(field, 0).toString()); + Assert.assertEquals("1.", new Dfp(field, 1).toString()); + Assert.assertEquals("-1.", new Dfp(field, -1).toString()); + Assert.assertEquals("1234567890.", new Dfp(field, 1234567890).toString()); + Assert.assertEquals("-1234567890.", new Dfp(field, -1234567890).toString()); + Assert.assertEquals("-2147483648.", new Dfp(field, Integer.MIN_VALUE).toString()); + Assert.assertEquals("2147483647.", new Dfp(field, Integer.MAX_VALUE).toString()); + } + + @Test + public void testLongConstructor() { + Assert.assertEquals("0.", new Dfp(field, 0l).toString()); + Assert.assertEquals("1.", new Dfp(field, 1l).toString()); + Assert.assertEquals("-1.", new Dfp(field, -1l).toString()); + Assert.assertEquals("1234567890.", new Dfp(field, 1234567890l).toString()); + Assert.assertEquals("-1234567890.", new Dfp(field, -1234567890l).toString()); + Assert.assertEquals("-9223372036854775808.", new Dfp(field, Long.MIN_VALUE).toString()); + Assert.assertEquals("9223372036854775807.", new Dfp(field, Long.MAX_VALUE).toString()); + } + + /* + * Test addition + */ + @Test + public void testAdd() { + test(field.newDfp("1").add(field.newDfp("1")), // Basic tests 1+1 = 2 + field.newDfp("2"), + 0, "Add #1"); + + test(field.newDfp("1").add(field.newDfp("-1")), // 1 + (-1) = 0 + field.newDfp("0"), + 0, "Add #2"); + + test(field.newDfp("-1").add(field.newDfp("1")), // (-1) + 1 = 0 + field.newDfp("0"), + 0, "Add #3"); + + test(field.newDfp("-1").add(field.newDfp("-1")), // (-1) + (-1) = -2 + field.newDfp("-2"), + 0, "Add #4"); + + // rounding mode is round half even + + test(field.newDfp("1").add(field.newDfp("1e-16")), // rounding on add + field.newDfp("1.0000000000000001"), + 0, "Add #5"); + + test(field.newDfp("1").add(field.newDfp("1e-17")), // rounding on add + field.newDfp("1"), + DfpField.FLAG_INEXACT, "Add #6"); + + test(field.newDfp("0.90999999999999999999").add(field.newDfp("0.1")), // rounding on add + field.newDfp("1.01"), + DfpField.FLAG_INEXACT, "Add #7"); + + test(field.newDfp(".10000000000000005000").add(field.newDfp(".9")), // rounding on add + field.newDfp("1."), + DfpField.FLAG_INEXACT, "Add #8"); + + test(field.newDfp(".10000000000000015000").add(field.newDfp(".9")), // rounding on add + field.newDfp("1.0000000000000002"), + DfpField.FLAG_INEXACT, "Add #9"); + + test(field.newDfp(".10000000000000014999").add(field.newDfp(".9")), // rounding on add + field.newDfp("1.0000000000000001"), + DfpField.FLAG_INEXACT, "Add #10"); + + test(field.newDfp(".10000000000000015001").add(field.newDfp(".9")), // rounding on add + field.newDfp("1.0000000000000002"), + DfpField.FLAG_INEXACT, "Add #11"); + + test(field.newDfp(".11111111111111111111").add(field.newDfp("11.1111111111111111")), // rounding on add + field.newDfp("11.22222222222222222222"), + DfpField.FLAG_INEXACT, "Add #12"); + + test(field.newDfp(".11111111111111111111").add(field.newDfp("1111111111111111.1111")), // rounding on add + field.newDfp("1111111111111111.2222"), + DfpField.FLAG_INEXACT, "Add #13"); + + test(field.newDfp(".11111111111111111111").add(field.newDfp("11111111111111111111")), // rounding on add + field.newDfp("11111111111111111111"), + DfpField.FLAG_INEXACT, "Add #14"); + + test(field.newDfp("9.9999999999999999999e131071").add(field.newDfp("-1e131052")), // overflow on add + field.newDfp("9.9999999999999999998e131071"), + 0, "Add #15"); + + test(field.newDfp("9.9999999999999999999e131071").add(field.newDfp("1e131052")), // overflow on add + pinf, + DfpField.FLAG_OVERFLOW, "Add #16"); + + test(field.newDfp("-9.9999999999999999999e131071").add(field.newDfp("-1e131052")), // overflow on add + ninf, + DfpField.FLAG_OVERFLOW, "Add #17"); + + test(field.newDfp("-9.9999999999999999999e131071").add(field.newDfp("1e131052")), // overflow on add + field.newDfp("-9.9999999999999999998e131071"), + 0, "Add #18"); + + test(field.newDfp("1e-131072").add(field.newDfp("1e-131072")), // underflow on add + field.newDfp("2e-131072"), + 0, "Add #19"); + + test(field.newDfp("1.0000000000000001e-131057").add(field.newDfp("-1e-131057")), // underflow on add + field.newDfp("1e-131073"), + DfpField.FLAG_UNDERFLOW, "Add #20"); + + test(field.newDfp("1.1e-131072").add(field.newDfp("-1e-131072")), // underflow on add + field.newDfp("1e-131073"), + DfpField.FLAG_UNDERFLOW, "Add #21"); + + test(field.newDfp("1.0000000000000001e-131072").add(field.newDfp("-1e-131072")), // underflow on add + field.newDfp("1e-131088"), + DfpField.FLAG_UNDERFLOW, "Add #22"); + + test(field.newDfp("1.0000000000000001e-131078").add(field.newDfp("-1e-131078")), // underflow on add + field.newDfp("0"), + DfpField.FLAG_UNDERFLOW, "Add #23"); + + test(field.newDfp("1.0").add(field.newDfp("-1e-20")), // loss of precision on alignment? + field.newDfp("0.99999999999999999999"), + 0, "Add #23.1"); + + test(field.newDfp("-0.99999999999999999999").add(field.newDfp("1")), // proper normalization? + field.newDfp("0.00000000000000000001"), + 0, "Add #23.2"); + + test(field.newDfp("1").add(field.newDfp("0")), // adding zeros + field.newDfp("1"), + 0, "Add #24"); + + test(field.newDfp("0").add(field.newDfp("0")), // adding zeros + field.newDfp("0"), + 0, "Add #25"); + + test(field.newDfp("-0").add(field.newDfp("0")), // adding zeros + field.newDfp("0"), + 0, "Add #26"); + + test(field.newDfp("0").add(field.newDfp("-0")), // adding zeros + field.newDfp("0"), + 0, "Add #27"); + + test(field.newDfp("-0").add(field.newDfp("-0")), // adding zeros + field.newDfp("-0"), + 0, "Add #28"); + + test(field.newDfp("1e-20").add(field.newDfp("0")), // adding zeros + field.newDfp("1e-20"), + 0, "Add #29"); + + test(field.newDfp("1e-40").add(field.newDfp("0")), // adding zeros + field.newDfp("1e-40"), + 0, "Add #30"); + + test(pinf.add(ninf), // adding infinities + nan, + DfpField.FLAG_INVALID, "Add #31"); + + test(ninf.add(pinf), // adding infinities + nan, + DfpField.FLAG_INVALID, "Add #32"); + + test(ninf.add(ninf), // adding infinities + ninf, + 0, "Add #33"); + + test(pinf.add(pinf), // adding infinities + pinf, + 0, "Add #34"); + + test(pinf.add(field.newDfp("0")), // adding infinities + pinf, + 0, "Add #35"); + + test(pinf.add(field.newDfp("-1e131071")), // adding infinities + pinf, + 0, "Add #36"); + + test(pinf.add(field.newDfp("1e131071")), // adding infinities + pinf, + 0, "Add #37"); + + test(field.newDfp("0").add(pinf), // adding infinities + pinf, + 0, "Add #38"); + + test(field.newDfp("-1e131071").add(pinf), // adding infinities + pinf, + 0, "Add #39"); + + test(field.newDfp("1e131071").add(pinf), // adding infinities + pinf, + 0, "Add #40"); + + test(ninf.add(field.newDfp("0")), // adding infinities + ninf, + 0, "Add #41"); + + test(ninf.add(field.newDfp("-1e131071")), // adding infinities + ninf, + 0, "Add #42"); + + test(ninf.add(field.newDfp("1e131071")), // adding infinities + ninf, + 0, "Add #43"); + + test(field.newDfp("0").add(ninf), // adding infinities + ninf, + 0, "Add #44"); + + test(field.newDfp("-1e131071").add(ninf), // adding infinities + ninf, + 0, "Add #45"); + + test(field.newDfp("1e131071").add(ninf), // adding infinities + ninf, + 0, "Add #46"); + + test(field.newDfp("9.9999999999999999999e131071").add(field.newDfp("5e131051")), // overflow + pinf, + DfpField.FLAG_OVERFLOW, "Add #47"); + + test(field.newDfp("9.9999999999999999999e131071").add(field.newDfp("4.9999999999999999999e131051")), // overflow + field.newDfp("9.9999999999999999999e131071"), + DfpField.FLAG_INEXACT, "Add #48"); + + test(nan.add(field.newDfp("1")), + nan, + 0, "Add #49"); + + test(field.newDfp("1").add(nan), + nan, + 0, "Add #50"); + + test(field.newDfp("12345678123456781234").add(field.newDfp("0.12345678123456781234")), + field.newDfp("12345678123456781234"), + DfpField.FLAG_INEXACT, "Add #51"); + + test(field.newDfp("12345678123456781234").add(field.newDfp("123.45678123456781234")), + field.newDfp("12345678123456781357"), + DfpField.FLAG_INEXACT, "Add #52"); + + test(field.newDfp("123.45678123456781234").add(field.newDfp("12345678123456781234")), + field.newDfp("12345678123456781357"), + DfpField.FLAG_INEXACT, "Add #53"); + + test(field.newDfp("12345678123456781234").add(field.newDfp(".00001234567812345678")), + field.newDfp("12345678123456781234"), + DfpField.FLAG_INEXACT, "Add #54"); + + test(field.newDfp("12345678123456781234").add(field.newDfp(".00000000123456781234")), + field.newDfp("12345678123456781234"), + DfpField.FLAG_INEXACT, "Add #55"); + + test(field.newDfp("-0").add(field.newDfp("-0")), + field.newDfp("-0"), + 0, "Add #56"); + + test(field.newDfp("0").add(field.newDfp("-0")), + field.newDfp("0"), + 0, "Add #57"); + + test(field.newDfp("-0").add(field.newDfp("0")), + field.newDfp("0"), + 0, "Add #58"); + + test(field.newDfp("0").add(field.newDfp("0")), + field.newDfp("0"), + 0, "Add #59"); + } + + //////////////////////////////////////////////////////////////////////////////////////////////////////// + + // Test comparisons + + // utility function to help test comparisons + private void cmptst(Dfp a, Dfp b, String op, boolean result, double num) { + if (op == "equal") { + if (a.equals(b) != result) { + assertionFailOpNum(op, num); + } + } + + if (op == "unequal") { + if (a.unequal(b) != result) { + assertionFailOpNum(op, num); + } + } + + if (op == "lessThan") { + if (a.lessThan(b) != result) { + assertionFailOpNum(op, num); + } + } + + if (op == "greaterThan") { + if (a.greaterThan(b) != result) { + assertionFailOpNum(op, num); + } + } + } + + @Test + public void testCompare() { + // test equal() comparison + // check zero vs. zero + field.clearIEEEFlags(); + + cmptst(field.newDfp("0"), field.newDfp("0"), "equal", true, 1); // 0 == 0 + cmptst(field.newDfp("0"), field.newDfp("-0"), "equal", true, 2); // 0 == -0 + cmptst(field.newDfp("-0"), field.newDfp("-0"), "equal", true, 3); // -0 == -0 + cmptst(field.newDfp("-0"), field.newDfp("0"), "equal", true, 4); // -0 == 0 + + // check zero vs normal numbers + + cmptst(field.newDfp("0"), field.newDfp("1"), "equal", false, 5); // 0 == 1 + cmptst(field.newDfp("1"), field.newDfp("0"), "equal", false, 6); // 1 == 0 + cmptst(field.newDfp("-1"), field.newDfp("0"), "equal", false, 7); // -1 == 0 + cmptst(field.newDfp("0"), field.newDfp("-1"), "equal", false, 8); // 0 == -1 + cmptst(field.newDfp("0"), field.newDfp("1e-131072"), "equal", false, 9); // 0 == 1e-131072 + // check flags + if (field.getIEEEFlags() != 0) { + assertionFailDfpField(field); + } + + cmptst(field.newDfp("0"), field.newDfp("1e-131078"), "equal", false, 10); // 0 == 1e-131078 + + // check flags -- underflow should be set + if (field.getIEEEFlags() != DfpField.FLAG_UNDERFLOW) { + assertionFailDfpField(field); + } + + field.clearIEEEFlags(); + + cmptst(field.newDfp("0"), field.newDfp("1e+131071"), "equal", false, 11); // 0 == 1e+131071 + + // check zero vs infinities + + cmptst(field.newDfp("0"), pinf, "equal", false, 12); // 0 == pinf + cmptst(field.newDfp("0"), ninf, "equal", false, 13); // 0 == ninf + cmptst(field.newDfp("-0"), pinf, "equal", false, 14); // -0 == pinf + cmptst(field.newDfp("-0"), ninf, "equal", false, 15); // -0 == ninf + cmptst(pinf, field.newDfp("0"), "equal", false, 16); // pinf == 0 + cmptst(ninf, field.newDfp("0"), "equal", false, 17); // ninf == 0 + cmptst(pinf, field.newDfp("-0"), "equal", false, 18); // pinf == -0 + cmptst(ninf, field.newDfp("-0"), "equal", false, 19); // ninf == -0 + cmptst(ninf, pinf, "equal", false, 19.10); // ninf == pinf + cmptst(pinf, ninf, "equal", false, 19.11); // pinf == ninf + cmptst(pinf, pinf, "equal", true, 19.12); // pinf == pinf + cmptst(ninf, ninf, "equal", true, 19.13); // ninf == ninf + + // check some normal numbers + cmptst(field.newDfp("1"), field.newDfp("1"), "equal", true, 20); // 1 == 1 + cmptst(field.newDfp("1"), field.newDfp("-1"), "equal", false, 21); // 1 == -1 + cmptst(field.newDfp("-1"), field.newDfp("-1"), "equal", true, 22); // -1 == -1 + cmptst(field.newDfp("1"), field.newDfp("1.0000000000000001"), "equal", false, 23); // 1 == 1.0000000000000001 + + // The tests below checks to ensure that comparisons don't set FLAG_INEXACT + // 100000 == 1.0000000000000001 + cmptst(field.newDfp("1e20"), field.newDfp("1.0000000000000001"), "equal", false, 24); + if (field.getIEEEFlags() != 0) { + assertionFailDfpField(field); + } + + cmptst(field.newDfp("0.000001"), field.newDfp("1e-6"), "equal", true, 25); + + // check some nans -- nans shouldn't equal anything + + cmptst(snan, snan, "equal", false, 27); + cmptst(qnan, qnan, "equal", false, 28); + cmptst(snan, qnan, "equal", false, 29); + cmptst(qnan, snan, "equal", false, 30); + cmptst(qnan, field.newDfp("0"), "equal", false, 31); + cmptst(snan, field.newDfp("0"), "equal", false, 32); + cmptst(field.newDfp("0"), snan, "equal", false, 33); + cmptst(field.newDfp("0"), qnan, "equal", false, 34); + cmptst(qnan, pinf, "equal", false, 35); + cmptst(snan, pinf, "equal", false, 36); + cmptst(pinf, snan, "equal", false, 37); + cmptst(pinf, qnan, "equal", false, 38); + cmptst(qnan, ninf, "equal", false, 39); + cmptst(snan, ninf, "equal", false, 40); + cmptst(ninf, snan, "equal", false, 41); + cmptst(ninf, qnan, "equal", false, 42); + cmptst(qnan, field.newDfp("-1"), "equal", false, 43); + cmptst(snan, field.newDfp("-1"), "equal", false, 44); + cmptst(field.newDfp("-1"), snan, "equal", false, 45); + cmptst(field.newDfp("-1"), qnan, "equal", false, 46); + cmptst(qnan, field.newDfp("1"), "equal", false, 47); + cmptst(snan, field.newDfp("1"), "equal", false, 48); + cmptst(field.newDfp("1"), snan, "equal", false, 49); + cmptst(field.newDfp("1"), qnan, "equal", false, 50); + cmptst(snan.negate(), snan, "equal", false, 51); + cmptst(qnan.negate(), qnan, "equal", false, 52); + + // + // Tests for un equal -- do it all over again + // + + cmptst(field.newDfp("0"), field.newDfp("0"), "unequal", false, 1); // 0 == 0 + cmptst(field.newDfp("0"), field.newDfp("-0"), "unequal", false, 2); // 0 == -0 + cmptst(field.newDfp("-0"), field.newDfp("-0"), "unequal", false, 3); // -0 == -0 + cmptst(field.newDfp("-0"), field.newDfp("0"), "unequal", false, 4); // -0 == 0 + + // check zero vs normal numbers + + cmptst(field.newDfp("0"), field.newDfp("1"), "unequal", true, 5); // 0 == 1 + cmptst(field.newDfp("1"), field.newDfp("0"), "unequal", true, 6); // 1 == 0 + cmptst(field.newDfp("-1"), field.newDfp("0"), "unequal", true, 7); // -1 == 0 + cmptst(field.newDfp("0"), field.newDfp("-1"), "unequal", true, 8); // 0 == -1 + cmptst(field.newDfp("0"), field.newDfp("1e-131072"), "unequal", true, 9); // 0 == 1e-131072 + // check flags + if (field.getIEEEFlags() != 0) { + assertionFailDfpField(field); + } + + cmptst(field.newDfp("0"), field.newDfp("1e-131078"), "unequal", true, 10); // 0 == 1e-131078 + + // check flags -- underflow should be set + if (field.getIEEEFlags() != DfpField.FLAG_UNDERFLOW) { + assertionFailDfpField(field); + } + + field.clearIEEEFlags(); + + cmptst(field.newDfp("0"), field.newDfp("1e+131071"), "unequal", true, 11); // 0 == 1e+131071 + + // check zero vs infinities + + cmptst(field.newDfp("0"), pinf, "unequal", true, 12); // 0 == pinf + cmptst(field.newDfp("0"), ninf, "unequal", true, 13); // 0 == ninf + cmptst(field.newDfp("-0"), pinf, "unequal", true, 14); // -0 == pinf + cmptst(field.newDfp("-0"), ninf, "unequal", true, 15); // -0 == ninf + cmptst(pinf, field.newDfp("0"), "unequal", true, 16); // pinf == 0 + cmptst(ninf, field.newDfp("0"), "unequal", true, 17); // ninf == 0 + cmptst(pinf, field.newDfp("-0"), "unequal", true, 18); // pinf == -0 + cmptst(ninf, field.newDfp("-0"), "unequal", true, 19); // ninf == -0 + cmptst(ninf, pinf, "unequal", true, 19.10); // ninf == pinf + cmptst(pinf, ninf, "unequal", true, 19.11); // pinf == ninf + cmptst(pinf, pinf, "unequal", false, 19.12); // pinf == pinf + cmptst(ninf, ninf, "unequal", false, 19.13); // ninf == ninf + + // check some normal numbers + cmptst(field.newDfp("1"), field.newDfp("1"), "unequal", false, 20); // 1 == 1 + cmptst(field.newDfp("1"), field.newDfp("-1"), "unequal", true, 21); // 1 == -1 + cmptst(field.newDfp("-1"), field.newDfp("-1"), "unequal", false, 22); // -1 == -1 + cmptst(field.newDfp("1"), field.newDfp("1.0000000000000001"), "unequal", true, 23); // 1 == 1.0000000000000001 + + // The tests below checks to ensure that comparisons don't set FLAG_INEXACT + // 100000 == 1.0000000000000001 + cmptst(field.newDfp("1e20"), field.newDfp("1.0000000000000001"), "unequal", true, 24); + if (field.getIEEEFlags() != 0) { + assertionFailDfpField(field); + } + + cmptst(field.newDfp("0.000001"), field.newDfp("1e-6"), "unequal", false, 25); + + // check some nans -- nans shouldn't be unequal to anything + + cmptst(snan, snan, "unequal", false, 27); + cmptst(qnan, qnan, "unequal", false, 28); + cmptst(snan, qnan, "unequal", false, 29); + cmptst(qnan, snan, "unequal", false, 30); + cmptst(qnan, field.newDfp("0"), "unequal", false, 31); + cmptst(snan, field.newDfp("0"), "unequal", false, 32); + cmptst(field.newDfp("0"), snan, "unequal", false, 33); + cmptst(field.newDfp("0"), qnan, "unequal", false, 34); + cmptst(qnan, pinf, "unequal", false, 35); + cmptst(snan, pinf, "unequal", false, 36); + cmptst(pinf, snan, "unequal", false, 37); + cmptst(pinf, qnan, "unequal", false, 38); + cmptst(qnan, ninf, "unequal", false, 39); + cmptst(snan, ninf, "unequal", false, 40); + cmptst(ninf, snan, "unequal", false, 41); + cmptst(ninf, qnan, "unequal", false, 42); + cmptst(qnan, field.newDfp("-1"), "unequal", false, 43); + cmptst(snan, field.newDfp("-1"), "unequal", false, 44); + cmptst(field.newDfp("-1"), snan, "unequal", false, 45); + cmptst(field.newDfp("-1"), qnan, "unequal", false, 46); + cmptst(qnan, field.newDfp("1"), "unequal", false, 47); + cmptst(snan, field.newDfp("1"), "unequal", false, 48); + cmptst(field.newDfp("1"), snan, "unequal", false, 49); + cmptst(field.newDfp("1"), qnan, "unequal", false, 50); + cmptst(snan.negate(), snan, "unequal", false, 51); + cmptst(qnan.negate(), qnan, "unequal", false, 52); + + if (field.getIEEEFlags() != 0) { + assertionFail("compare unequal flags = "+field.getIEEEFlags()); + } + + // + // Tests for lessThan -- do it all over again + // + + cmptst(field.newDfp("0"), field.newDfp("0"), "lessThan", false, 1); // 0 < 0 + cmptst(field.newDfp("0"), field.newDfp("-0"), "lessThan", false, 2); // 0 < -0 + cmptst(field.newDfp("-0"), field.newDfp("-0"), "lessThan", false, 3); // -0 < -0 + cmptst(field.newDfp("-0"), field.newDfp("0"), "lessThan", false, 4); // -0 < 0 + + // check zero vs normal numbers + + cmptst(field.newDfp("0"), field.newDfp("1"), "lessThan", true, 5); // 0 < 1 + cmptst(field.newDfp("1"), field.newDfp("0"), "lessThan", false, 6); // 1 < 0 + cmptst(field.newDfp("-1"), field.newDfp("0"), "lessThan", true, 7); // -1 < 0 + cmptst(field.newDfp("0"), field.newDfp("-1"), "lessThan", false, 8); // 0 < -1 + cmptst(field.newDfp("0"), field.newDfp("1e-131072"), "lessThan", true, 9); // 0 < 1e-131072 + // check flags + if (field.getIEEEFlags() != 0) { + assertionFailDfpField(field); + } + + cmptst(field.newDfp("0"), field.newDfp("1e-131078"), "lessThan", true, 10); // 0 < 1e-131078 + + // check flags -- underflow should be set + if (field.getIEEEFlags() != DfpField.FLAG_UNDERFLOW) { + assertionFailDfpField(field); + } + field.clearIEEEFlags(); + + cmptst(field.newDfp("0"), field.newDfp("1e+131071"), "lessThan", true, 11); // 0 < 1e+131071 + + // check zero vs infinities + + cmptst(field.newDfp("0"), pinf, "lessThan", true, 12); // 0 < pinf + cmptst(field.newDfp("0"), ninf, "lessThan", false, 13); // 0 < ninf + cmptst(field.newDfp("-0"), pinf, "lessThan", true, 14); // -0 < pinf + cmptst(field.newDfp("-0"), ninf, "lessThan", false, 15); // -0 < ninf + cmptst(pinf, field.newDfp("0"), "lessThan", false, 16); // pinf < 0 + cmptst(ninf, field.newDfp("0"), "lessThan", true, 17); // ninf < 0 + cmptst(pinf, field.newDfp("-0"), "lessThan", false, 18); // pinf < -0 + cmptst(ninf, field.newDfp("-0"), "lessThan", true, 19); // ninf < -0 + cmptst(ninf, pinf, "lessThan", true, 19.10); // ninf < pinf + cmptst(pinf, ninf, "lessThan", false, 19.11); // pinf < ninf + cmptst(pinf, pinf, "lessThan", false, 19.12); // pinf < pinf + cmptst(ninf, ninf, "lessThan", false, 19.13); // ninf < ninf + + // check some normal numbers + cmptst(field.newDfp("1"), field.newDfp("1"), "lessThan", false, 20); // 1 < 1 + cmptst(field.newDfp("1"), field.newDfp("-1"), "lessThan", false, 21); // 1 < -1 + cmptst(field.newDfp("-1"), field.newDfp("-1"), "lessThan", false, 22); // -1 < -1 + cmptst(field.newDfp("1"), field.newDfp("1.0000000000000001"), "lessThan", true, 23); // 1 < 1.0000000000000001 + + // The tests below checks to ensure that comparisons don't set FLAG_INEXACT + // 100000 < 1.0000000000000001 + cmptst(field.newDfp("1e20"), field.newDfp("1.0000000000000001"), "lessThan", false, 24); + if (field.getIEEEFlags() != 0) { + assertionFailDfpField(field); + } + + cmptst(field.newDfp("0.000001"), field.newDfp("1e-6"), "lessThan", false, 25); + + // check some nans -- nans shouldn't be lessThan to anything + cmptst(snan, snan, "lessThan", false, 27); + cmptst(qnan, qnan, "lessThan", false, 28); + cmptst(snan, qnan, "lessThan", false, 29); + cmptst(qnan, snan, "lessThan", false, 30); + cmptst(qnan, field.newDfp("0"), "lessThan", false, 31); + cmptst(snan, field.newDfp("0"), "lessThan", false, 32); + cmptst(field.newDfp("0"), snan, "lessThan", false, 33); + cmptst(field.newDfp("0"), qnan, "lessThan", false, 34); + cmptst(qnan, pinf, "lessThan", false, 35); + cmptst(snan, pinf, "lessThan", false, 36); + cmptst(pinf, snan, "lessThan", false, 37); + cmptst(pinf, qnan, "lessThan", false, 38); + cmptst(qnan, ninf, "lessThan", false, 39); + cmptst(snan, ninf, "lessThan", false, 40); + cmptst(ninf, snan, "lessThan", false, 41); + cmptst(ninf, qnan, "lessThan", false, 42); + cmptst(qnan, field.newDfp("-1"), "lessThan", false, 43); + cmptst(snan, field.newDfp("-1"), "lessThan", false, 44); + cmptst(field.newDfp("-1"), snan, "lessThan", false, 45); + cmptst(field.newDfp("-1"), qnan, "lessThan", false, 46); + cmptst(qnan, field.newDfp("1"), "lessThan", false, 47); + cmptst(snan, field.newDfp("1"), "lessThan", false, 48); + cmptst(field.newDfp("1"), snan, "lessThan", false, 49); + cmptst(field.newDfp("1"), qnan, "lessThan", false, 50); + cmptst(snan.negate(), snan, "lessThan", false, 51); + cmptst(qnan.negate(), qnan, "lessThan", false, 52); + + //lessThan compares with nans should raise FLAG_INVALID + if (field.getIEEEFlags() != DfpField.FLAG_INVALID) { + assertionFail("compare lessThan flags = "+field.getIEEEFlags()); + } + field.clearIEEEFlags(); + + // + // Tests for greaterThan -- do it all over again + // + + cmptst(field.newDfp("0"), field.newDfp("0"), "greaterThan", false, 1); // 0 > 0 + cmptst(field.newDfp("0"), field.newDfp("-0"), "greaterThan", false, 2); // 0 > -0 + cmptst(field.newDfp("-0"), field.newDfp("-0"), "greaterThan", false, 3); // -0 > -0 + cmptst(field.newDfp("-0"), field.newDfp("0"), "greaterThan", false, 4); // -0 > 0 + + // check zero vs normal numbers + + cmptst(field.newDfp("0"), field.newDfp("1"), "greaterThan", false, 5); // 0 > 1 + cmptst(field.newDfp("1"), field.newDfp("0"), "greaterThan", true, 6); // 1 > 0 + cmptst(field.newDfp("-1"), field.newDfp("0"), "greaterThan", false, 7); // -1 > 0 + cmptst(field.newDfp("0"), field.newDfp("-1"), "greaterThan", true, 8); // 0 > -1 + cmptst(field.newDfp("0"), field.newDfp("1e-131072"), "greaterThan", false, 9); // 0 > 1e-131072 + // check flags + if (field.getIEEEFlags() != 0) { + assertionFailDfpField(field); + } + + cmptst(field.newDfp("0"), field.newDfp("1e-131078"), "greaterThan", false, 10); // 0 > 1e-131078 + + // check flags -- underflow should be set + if (field.getIEEEFlags() != DfpField.FLAG_UNDERFLOW) { + assertionFailDfpField(field); + } + field.clearIEEEFlags(); + + cmptst(field.newDfp("0"), field.newDfp("1e+131071"), "greaterThan", false, 11); // 0 > 1e+131071 + + // check zero vs infinities + + cmptst(field.newDfp("0"), pinf, "greaterThan", false, 12); // 0 > pinf + cmptst(field.newDfp("0"), ninf, "greaterThan", true, 13); // 0 > ninf + cmptst(field.newDfp("-0"), pinf, "greaterThan", false, 14); // -0 > pinf + cmptst(field.newDfp("-0"), ninf, "greaterThan", true, 15); // -0 > ninf + cmptst(pinf, field.newDfp("0"), "greaterThan", true, 16); // pinf > 0 + cmptst(ninf, field.newDfp("0"), "greaterThan", false, 17); // ninf > 0 + cmptst(pinf, field.newDfp("-0"), "greaterThan", true, 18); // pinf > -0 + cmptst(ninf, field.newDfp("-0"), "greaterThan", false, 19); // ninf > -0 + cmptst(ninf, pinf, "greaterThan", false, 19.10); // ninf > pinf + cmptst(pinf, ninf, "greaterThan", true, 19.11); // pinf > ninf + cmptst(pinf, pinf, "greaterThan", false, 19.12); // pinf > pinf + cmptst(ninf, ninf, "greaterThan", false, 19.13); // ninf > ninf + + // check some normal numbers + cmptst(field.newDfp("1"), field.newDfp("1"), "greaterThan", false, 20); // 1 > 1 + cmptst(field.newDfp("1"), field.newDfp("-1"), "greaterThan", true, 21); // 1 > -1 + cmptst(field.newDfp("-1"), field.newDfp("-1"), "greaterThan", false, 22); // -1 > -1 + cmptst(field.newDfp("1"), field.newDfp("1.0000000000000001"), "greaterThan", false, 23); // 1 > 1.0000000000000001 + + // The tests below checks to ensure that comparisons don't set FLAG_INEXACT + // 100000 > 1.0000000000000001 + cmptst(field.newDfp("1e20"), field.newDfp("1.0000000000000001"), "greaterThan", true, 24); + if (field.getIEEEFlags() != 0) { + assertionFailDfpField(field); + } + + cmptst(field.newDfp("0.000001"), field.newDfp("1e-6"), "greaterThan", false, 25); + + // check some nans -- nans shouldn't be greaterThan to anything + cmptst(snan, snan, "greaterThan", false, 27); + cmptst(qnan, qnan, "greaterThan", false, 28); + cmptst(snan, qnan, "greaterThan", false, 29); + cmptst(qnan, snan, "greaterThan", false, 30); + cmptst(qnan, field.newDfp("0"), "greaterThan", false, 31); + cmptst(snan, field.newDfp("0"), "greaterThan", false, 32); + cmptst(field.newDfp("0"), snan, "greaterThan", false, 33); + cmptst(field.newDfp("0"), qnan, "greaterThan", false, 34); + cmptst(qnan, pinf, "greaterThan", false, 35); + cmptst(snan, pinf, "greaterThan", false, 36); + cmptst(pinf, snan, "greaterThan", false, 37); + cmptst(pinf, qnan, "greaterThan", false, 38); + cmptst(qnan, ninf, "greaterThan", false, 39); + cmptst(snan, ninf, "greaterThan", false, 40); + cmptst(ninf, snan, "greaterThan", false, 41); + cmptst(ninf, qnan, "greaterThan", false, 42); + cmptst(qnan, field.newDfp("-1"), "greaterThan", false, 43); + cmptst(snan, field.newDfp("-1"), "greaterThan", false, 44); + cmptst(field.newDfp("-1"), snan, "greaterThan", false, 45); + cmptst(field.newDfp("-1"), qnan, "greaterThan", false, 46); + cmptst(qnan, field.newDfp("1"), "greaterThan", false, 47); + cmptst(snan, field.newDfp("1"), "greaterThan", false, 48); + cmptst(field.newDfp("1"), snan, "greaterThan", false, 49); + cmptst(field.newDfp("1"), qnan, "greaterThan", false, 50); + cmptst(snan.negate(), snan, "greaterThan", false, 51); + cmptst(qnan.negate(), qnan, "greaterThan", false, 52); + + //greaterThan compares with nans should raise FLAG_INVALID + if (field.getIEEEFlags() != DfpField.FLAG_INVALID) { + assertionFail("compare greaterThan flags = "+field.getIEEEFlags()); + } + field.clearIEEEFlags(); + } + + // + // Test multiplication + // + @Test + public void testMultiply() { + test(field.newDfp("1").multiply(field.newDfp("1")), // Basic tests 1*1 = 1 + field.newDfp("1"), + 0, "Multiply #1"); + + test(field.newDfp("1").multiply(1), // Basic tests 1*1 = 1 + field.newDfp("1"), + 0, "Multiply #2"); + + test(field.newDfp("-1").multiply(field.newDfp("1")), // Basic tests -1*1 = -1 + field.newDfp("-1"), + 0, "Multiply #3"); + + test(field.newDfp("-1").multiply(1), // Basic tests -1*1 = -1 + field.newDfp("-1"), + 0, "Multiply #4"); + + // basic tests with integers + test(field.newDfp("2").multiply(field.newDfp("3")), + field.newDfp("6"), + 0, "Multiply #5"); + + test(field.newDfp("2").multiply(3), + field.newDfp("6"), + 0, "Multiply #6"); + + test(field.newDfp("-2").multiply(field.newDfp("3")), + field.newDfp("-6"), + 0, "Multiply #7"); + + test(field.newDfp("-2").multiply(3), + field.newDfp("-6"), + 0, "Multiply #8"); + + test(field.newDfp("2").multiply(field.newDfp("-3")), + field.newDfp("-6"), + 0, "Multiply #9"); + + test(field.newDfp("-2").multiply(field.newDfp("-3")), + field.newDfp("6"), + 0, "Multiply #10"); + + //multiply by zero + + test(field.newDfp("-2").multiply(field.newDfp("0")), + field.newDfp("-0"), + 0, "Multiply #11"); + + test(field.newDfp("-2").multiply(0), + field.newDfp("-0"), + 0, "Multiply #12"); + + test(field.newDfp("2").multiply(field.newDfp("0")), + field.newDfp("0"), + 0, "Multiply #13"); + + test(field.newDfp("2").multiply(0), + field.newDfp("0"), + 0, "Multiply #14"); + + test(field.newDfp("2").multiply(pinf), + pinf, + 0, "Multiply #15"); + + test(field.newDfp("2").multiply(ninf), + ninf, + 0, "Multiply #16"); + + test(field.newDfp("-2").multiply(pinf), + ninf, + 0, "Multiply #17"); + + test(field.newDfp("-2").multiply(ninf), + pinf, + 0, "Multiply #18"); + + test(ninf.multiply(field.newDfp("-2")), + pinf, + 0, "Multiply #18.1"); + + test(field.newDfp("5e131071").multiply(2), + pinf, + DfpField.FLAG_OVERFLOW, "Multiply #19"); + + test(field.newDfp("5e131071").multiply(field.newDfp("1.999999999999999")), + field.newDfp("9.9999999999999950000e131071"), + 0, "Multiply #20"); + + test(field.newDfp("-5e131071").multiply(2), + ninf, + DfpField.FLAG_OVERFLOW, "Multiply #22"); + + test(field.newDfp("-5e131071").multiply(field.newDfp("1.999999999999999")), + field.newDfp("-9.9999999999999950000e131071"), + 0, "Multiply #23"); + + test(field.newDfp("1e-65539").multiply(field.newDfp("1e-65539")), + field.newDfp("1e-131078"), + DfpField.FLAG_UNDERFLOW, "Multiply #24"); + + test(field.newDfp("1").multiply(nan), + nan, + 0, "Multiply #25"); + + test(nan.multiply(field.newDfp("1")), + nan, + 0, "Multiply #26"); + + test(nan.multiply(pinf), + nan, + 0, "Multiply #27"); + + test(pinf.multiply(nan), + nan, + 0, "Multiply #27"); + + test(pinf.multiply(field.newDfp("0")), + nan, + DfpField.FLAG_INVALID, "Multiply #28"); + + test(field.newDfp("0").multiply(pinf), + nan, + DfpField.FLAG_INVALID, "Multiply #29"); + + test(pinf.multiply(pinf), + pinf, + 0, "Multiply #30"); + + test(ninf.multiply(pinf), + ninf, + 0, "Multiply #31"); + + test(pinf.multiply(ninf), + ninf, + 0, "Multiply #32"); + + test(ninf.multiply(ninf), + pinf, + 0, "Multiply #33"); + + test(pinf.multiply(1), + pinf, + 0, "Multiply #34"); + + test(pinf.multiply(0), + nan, + DfpField.FLAG_INVALID, "Multiply #35"); + + test(nan.multiply(1), + nan, + 0, "Multiply #36"); + + test(field.newDfp("1").multiply(10000), + field.newDfp("10000"), + 0, "Multiply #37"); + + test(field.newDfp("2").multiply(1000000), + field.newDfp("2000000"), + 0, "Multiply #38"); + + test(field.newDfp("1").multiply(-1), + field.newDfp("-1"), + 0, "Multiply #39"); + } + + @Test + public void testDivide() { + test(field.newDfp("1").divide(nan), // divide by NaN = NaN + nan, + 0, "Divide #1"); + + test(nan.divide(field.newDfp("1")), // NaN / number = NaN + nan, + 0, "Divide #2"); + + test(pinf.divide(field.newDfp("1")), + pinf, + 0, "Divide #3"); + + test(pinf.divide(field.newDfp("-1")), + ninf, + 0, "Divide #4"); + + test(pinf.divide(pinf), + nan, + DfpField.FLAG_INVALID, "Divide #5"); + + test(ninf.divide(pinf), + nan, + DfpField.FLAG_INVALID, "Divide #6"); + + test(pinf.divide(ninf), + nan, + DfpField.FLAG_INVALID, "Divide #7"); + + test(ninf.divide(ninf), + nan, + DfpField.FLAG_INVALID, "Divide #8"); + + test(field.newDfp("0").divide(field.newDfp("0")), + nan, + DfpField.FLAG_DIV_ZERO, "Divide #9"); + + test(field.newDfp("1").divide(field.newDfp("0")), + pinf, + DfpField.FLAG_DIV_ZERO, "Divide #10"); + + test(field.newDfp("1").divide(field.newDfp("-0")), + ninf, + DfpField.FLAG_DIV_ZERO, "Divide #11"); + + test(field.newDfp("-1").divide(field.newDfp("0")), + ninf, + DfpField.FLAG_DIV_ZERO, "Divide #12"); + + test(field.newDfp("-1").divide(field.newDfp("-0")), + pinf, + DfpField.FLAG_DIV_ZERO, "Divide #13"); + + test(field.newDfp("1").divide(field.newDfp("3")), + field.newDfp("0.33333333333333333333"), + DfpField.FLAG_INEXACT, "Divide #14"); + + test(field.newDfp("1").divide(field.newDfp("6")), + field.newDfp("0.16666666666666666667"), + DfpField.FLAG_INEXACT, "Divide #15"); + + test(field.newDfp("10").divide(field.newDfp("6")), + field.newDfp("1.6666666666666667"), + DfpField.FLAG_INEXACT, "Divide #16"); + + test(field.newDfp("100").divide(field.newDfp("6")), + field.newDfp("16.6666666666666667"), + DfpField.FLAG_INEXACT, "Divide #17"); + + test(field.newDfp("1000").divide(field.newDfp("6")), + field.newDfp("166.6666666666666667"), + DfpField.FLAG_INEXACT, "Divide #18"); + + test(field.newDfp("10000").divide(field.newDfp("6")), + field.newDfp("1666.6666666666666667"), + DfpField.FLAG_INEXACT, "Divide #19"); + + test(field.newDfp("1").divide(field.newDfp("1")), + field.newDfp("1"), + 0, "Divide #20"); + + test(field.newDfp("1").divide(field.newDfp("-1")), + field.newDfp("-1"), + 0, "Divide #21"); + + test(field.newDfp("-1").divide(field.newDfp("1")), + field.newDfp("-1"), + 0, "Divide #22"); + + test(field.newDfp("-1").divide(field.newDfp("-1")), + field.newDfp("1"), + 0, "Divide #23"); + + test(field.newDfp("1e-65539").divide(field.newDfp("1e65539")), + field.newDfp("1e-131078"), + DfpField.FLAG_UNDERFLOW, "Divide #24"); + + test(field.newDfp("1e65539").divide(field.newDfp("1e-65539")), + pinf, + DfpField.FLAG_OVERFLOW, "Divide #24"); + + test(field.newDfp("2").divide(field.newDfp("1.5")), // test trial-divisor too high + field.newDfp("1.3333333333333333"), + DfpField.FLAG_INEXACT, "Divide #25"); + + test(field.newDfp("2").divide(pinf), + field.newDfp("0"), + 0, "Divide #26"); + + test(field.newDfp("2").divide(ninf), + field.newDfp("-0"), + 0, "Divide #27"); + + test(field.newDfp("0").divide(field.newDfp("1")), + field.newDfp("0"), + 0, "Divide #28"); + } + + @Test + public void testReciprocal() { + test(nan.reciprocal(), + nan, + 0, "Reciprocal #1"); + + test(field.newDfp("0").reciprocal(), + pinf, + DfpField.FLAG_DIV_ZERO, "Reciprocal #2"); + + test(field.newDfp("-0").reciprocal(), + ninf, + DfpField.FLAG_DIV_ZERO, "Reciprocal #3"); + + test(field.newDfp("3").reciprocal(), + field.newDfp("0.33333333333333333333"), + DfpField.FLAG_INEXACT, "Reciprocal #4"); + + test(field.newDfp("6").reciprocal(), + field.newDfp("0.16666666666666666667"), + DfpField.FLAG_INEXACT, "Reciprocal #5"); + + test(field.newDfp("1").reciprocal(), + field.newDfp("1"), + 0, "Reciprocal #6"); + + test(field.newDfp("-1").reciprocal(), + field.newDfp("-1"), + 0, "Reciprocal #7"); + + test(pinf.reciprocal(), + field.newDfp("0"), + 0, "Reciprocal #8"); + + test(ninf.reciprocal(), + field.newDfp("-0"), + 0, "Reciprocal #9"); + } + + @Test + public void testDivideInt() { + test(nan.divide(1), // NaN / number = NaN + nan, + 0, "DivideInt #1"); + + test(pinf.divide(1), + pinf, + 0, "DivideInt #2"); + + test(field.newDfp("0").divide(0), + nan, + DfpField.FLAG_DIV_ZERO, "DivideInt #3"); + + test(field.newDfp("1").divide(0), + pinf, + DfpField.FLAG_DIV_ZERO, "DivideInt #4"); + + test(field.newDfp("-1").divide(0), + ninf, + DfpField.FLAG_DIV_ZERO, "DivideInt #5"); + + test(field.newDfp("1").divide(3), + field.newDfp("0.33333333333333333333"), + DfpField.FLAG_INEXACT, "DivideInt #6"); + + test(field.newDfp("1").divide(6), + field.newDfp("0.16666666666666666667"), + DfpField.FLAG_INEXACT, "DivideInt #7"); + + test(field.newDfp("10").divide(6), + field.newDfp("1.6666666666666667"), + DfpField.FLAG_INEXACT, "DivideInt #8"); + + test(field.newDfp("100").divide(6), + field.newDfp("16.6666666666666667"), + DfpField.FLAG_INEXACT, "DivideInt #9"); + + test(field.newDfp("1000").divide(6), + field.newDfp("166.6666666666666667"), + DfpField.FLAG_INEXACT, "DivideInt #10"); + + test(field.newDfp("10000").divide(6), + field.newDfp("1666.6666666666666667"), + DfpField.FLAG_INEXACT, "DivideInt #20"); + + test(field.newDfp("1").divide(1), + field.newDfp("1"), + 0, "DivideInt #21"); + + test(field.newDfp("1e-131077").divide(10), + field.newDfp("1e-131078"), + DfpField.FLAG_UNDERFLOW, "DivideInt #22"); + + test(field.newDfp("0").divide(1), + field.newDfp("0"), + 0, "DivideInt #23"); + + test(field.newDfp("1").divide(10000), + nan, + DfpField.FLAG_INVALID, "DivideInt #24"); + + test(field.newDfp("1").divide(-1), + nan, + DfpField.FLAG_INVALID, "DivideInt #25"); + } + + @Test + public void testNextAfter() { + test(field.newDfp("1").nextAfter(pinf), + field.newDfp("1.0000000000000001"), + 0, "NextAfter #1"); + + test(field.newDfp("1.0000000000000001").nextAfter(ninf), + field.newDfp("1"), + 0, "NextAfter #1.5"); + + test(field.newDfp("1").nextAfter(ninf), + field.newDfp("0.99999999999999999999"), + 0, "NextAfter #2"); + + test(field.newDfp("0.99999999999999999999").nextAfter(field.newDfp("2")), + field.newDfp("1"), + 0, "NextAfter #3"); + + test(field.newDfp("-1").nextAfter(ninf), + field.newDfp("-1.0000000000000001"), + 0, "NextAfter #4"); + + test(field.newDfp("-1").nextAfter(pinf), + field.newDfp("-0.99999999999999999999"), + 0, "NextAfter #5"); + + test(field.newDfp("-0.99999999999999999999").nextAfter(field.newDfp("-2")), + field.newDfp("-1"), + 0, "NextAfter #6"); + + test(field.newDfp("2").nextAfter(field.newDfp("2")), + field.newDfp("2"), + 0, "NextAfter #7"); + + test(field.newDfp("0").nextAfter(field.newDfp("0")), + field.newDfp("0"), + 0, "NextAfter #8"); + + test(field.newDfp("-2").nextAfter(field.newDfp("-2")), + field.newDfp("-2"), + 0, "NextAfter #9"); + + test(field.newDfp("0").nextAfter(field.newDfp("1")), + field.newDfp("1e-131092"), + DfpField.FLAG_UNDERFLOW, "NextAfter #10"); + + test(field.newDfp("0").nextAfter(field.newDfp("-1")), + field.newDfp("-1e-131092"), + DfpField.FLAG_UNDERFLOW, "NextAfter #11"); + + test(field.newDfp("-1e-131092").nextAfter(pinf), + field.newDfp("-0"), + DfpField.FLAG_UNDERFLOW|DfpField.FLAG_INEXACT, "Next After #12"); + + test(field.newDfp("1e-131092").nextAfter(ninf), + field.newDfp("0"), + DfpField.FLAG_UNDERFLOW|DfpField.FLAG_INEXACT, "Next After #13"); + + test(field.newDfp("9.9999999999999999999e131078").nextAfter(pinf), + pinf, + DfpField.FLAG_OVERFLOW|DfpField.FLAG_INEXACT, "Next After #14"); + } + + @Test + public void testToString() { + Assert.assertEquals("toString #1", "Infinity", pinf.toString()); + Assert.assertEquals("toString #2", "-Infinity", ninf.toString()); + Assert.assertEquals("toString #3", "NaN", nan.toString()); + Assert.assertEquals("toString #4", "NaN", field.newDfp((byte) 1, Dfp.QNAN).toString()); + Assert.assertEquals("toString #5", "NaN", field.newDfp((byte) 1, Dfp.SNAN).toString()); + Assert.assertEquals("toString #6", "1.2300000000000000e100", field.newDfp("1.23e100").toString()); + Assert.assertEquals("toString #7", "-1.2300000000000000e100", field.newDfp("-1.23e100").toString()); + Assert.assertEquals("toString #8", "12345678.1234", field.newDfp("12345678.1234").toString()); + Assert.assertEquals("toString #9", "0.00001234", field.newDfp("0.00001234").toString()); + } + + @Override + @Test + public void testRound() { + field.setRoundingMode(DfpField.RoundingMode.ROUND_DOWN); + + // Round down + test(field.newDfp("12345678901234567890").add(field.newDfp("0.9")), + field.newDfp("12345678901234567890"), + DfpField.FLAG_INEXACT, "Round #1"); + + test(field.newDfp("12345678901234567890").add(field.newDfp("0.99999999")), + field.newDfp("12345678901234567890"), + DfpField.FLAG_INEXACT, "Round #2"); + + test(field.newDfp("-12345678901234567890").add(field.newDfp("-0.99999999")), + field.newDfp("-12345678901234567890"), + DfpField.FLAG_INEXACT, "Round #3"); + + field.setRoundingMode(DfpField.RoundingMode.ROUND_UP); + + // Round up + test(field.newDfp("12345678901234567890").add(field.newDfp("0.1")), + field.newDfp("12345678901234567891"), + DfpField.FLAG_INEXACT, "Round #4"); + + test(field.newDfp("12345678901234567890").add(field.newDfp("0.0001")), + field.newDfp("12345678901234567891"), + DfpField.FLAG_INEXACT, "Round #5"); + + test(field.newDfp("-12345678901234567890").add(field.newDfp("-0.1")), + field.newDfp("-12345678901234567891"), + DfpField.FLAG_INEXACT, "Round #6"); + + test(field.newDfp("-12345678901234567890").add(field.newDfp("-0.0001")), + field.newDfp("-12345678901234567891"), + DfpField.FLAG_INEXACT, "Round #7"); + + field.setRoundingMode(DfpField.RoundingMode.ROUND_HALF_UP); + + // Round half up + test(field.newDfp("12345678901234567890").add(field.newDfp("0.4999")), + field.newDfp("12345678901234567890"), + DfpField.FLAG_INEXACT, "Round #8"); + + test(field.newDfp("12345678901234567890").add(field.newDfp("0.5000")), + field.newDfp("12345678901234567891"), + DfpField.FLAG_INEXACT, "Round #9"); + + test(field.newDfp("-12345678901234567890").add(field.newDfp("-0.4999")), + field.newDfp("-12345678901234567890"), + DfpField.FLAG_INEXACT, "Round #10"); + + test(field.newDfp("-12345678901234567890").add(field.newDfp("-0.5000")), + field.newDfp("-12345678901234567891"), + DfpField.FLAG_INEXACT, "Round #11"); + + field.setRoundingMode(DfpField.RoundingMode.ROUND_HALF_DOWN); + + // Round half down + test(field.newDfp("12345678901234567890").add(field.newDfp("0.5001")), + field.newDfp("12345678901234567891"), + DfpField.FLAG_INEXACT, "Round #12"); + + test(field.newDfp("12345678901234567890").add(field.newDfp("0.5000")), + field.newDfp("12345678901234567890"), + DfpField.FLAG_INEXACT, "Round #13"); + + test(field.newDfp("-12345678901234567890").add(field.newDfp("-0.5001")), + field.newDfp("-12345678901234567891"), + DfpField.FLAG_INEXACT, "Round #14"); + + test(field.newDfp("-12345678901234567890").add(field.newDfp("-0.5000")), + field.newDfp("-12345678901234567890"), + DfpField.FLAG_INEXACT, "Round #15"); + + field.setRoundingMode(DfpField.RoundingMode.ROUND_HALF_ODD); + + // Round half odd + test(field.newDfp("12345678901234567890").add(field.newDfp("0.5000")), + field.newDfp("12345678901234567891"), + DfpField.FLAG_INEXACT, "Round #16"); + + test(field.newDfp("12345678901234567891").add(field.newDfp("0.5000")), + field.newDfp("12345678901234567891"), + DfpField.FLAG_INEXACT, "Round #17"); + + test(field.newDfp("-12345678901234567890").add(field.newDfp("-0.5000")), + field.newDfp("-12345678901234567891"), + DfpField.FLAG_INEXACT, "Round #18"); + + test(field.newDfp("-12345678901234567891").add(field.newDfp("-0.5000")), + field.newDfp("-12345678901234567891"), + DfpField.FLAG_INEXACT, "Round #19"); + + field.setRoundingMode(DfpField.RoundingMode.ROUND_CEIL); + + // Round ceil + test(field.newDfp("12345678901234567890").add(field.newDfp("0.0001")), + field.newDfp("12345678901234567891"), + DfpField.FLAG_INEXACT, "Round #20"); + + test(field.newDfp("-12345678901234567890").add(field.newDfp("-0.9999")), + field.newDfp("-12345678901234567890"), + DfpField.FLAG_INEXACT, "Round #21"); + + field.setRoundingMode(DfpField.RoundingMode.ROUND_FLOOR); + + // Round floor + test(field.newDfp("12345678901234567890").add(field.newDfp("0.9999")), + field.newDfp("12345678901234567890"), + DfpField.FLAG_INEXACT, "Round #22"); + + test(field.newDfp("-12345678901234567890").add(field.newDfp("-0.0001")), + field.newDfp("-12345678901234567891"), + DfpField.FLAG_INEXACT, "Round #23"); + + field.setRoundingMode(DfpField.RoundingMode.ROUND_HALF_EVEN); // reset + } + + @Override + @Test + public void testCeil() { + test(field.newDfp("1234.0000000000000001").ceil(), + field.newDfp("1235"), + DfpField.FLAG_INEXACT, "Ceil #1"); + } + + @Override + @Test + public void testFloor() { + test(field.newDfp("1234.9999999999999999").floor(), + field.newDfp("1234"), + DfpField.FLAG_INEXACT, "Floor #1"); + } + + @Override + @Test + public void testRint() { + test(field.newDfp("1234.50000000001").rint(), + field.newDfp("1235"), + DfpField.FLAG_INEXACT, "Rint #1"); + + test(field.newDfp("1234.5000").rint(), + field.newDfp("1234"), + DfpField.FLAG_INEXACT, "Rint #2"); + + test(field.newDfp("1235.5000").rint(), + field.newDfp("1236"), + DfpField.FLAG_INEXACT, "Rint #3"); + } + + @Test + public void testCopySign() { + test(Dfp.copysign(field.newDfp("1234."), field.newDfp("-1")), + field.newDfp("-1234"), + 0, "CopySign #1"); + + test(Dfp.copysign(field.newDfp("-1234."), field.newDfp("-1")), + field.newDfp("-1234"), + 0, "CopySign #2"); + + test(Dfp.copysign(field.newDfp("-1234."), field.newDfp("1")), + field.newDfp("1234"), + 0, "CopySign #3"); + + test(Dfp.copysign(field.newDfp("1234."), field.newDfp("1")), + field.newDfp("1234"), + 0, "CopySign #4"); + } + + @Test + public void testIntValue() { + Assert.assertEquals("intValue #1", 1234, field.newDfp("1234").intValue()); + Assert.assertEquals("intValue #2", -1234, field.newDfp("-1234").intValue()); + Assert.assertEquals("intValue #3", 1234, field.newDfp("1234.5").intValue()); + Assert.assertEquals("intValue #4", 1235, field.newDfp("1234.500001").intValue()); + Assert.assertEquals("intValue #5", 2147483647, field.newDfp("1e1000").intValue()); + Assert.assertEquals("intValue #6", -2147483648, field.newDfp("-1e1000").intValue()); + } + + @Test + public void testLog10K() { + Assert.assertEquals("log10K #1", 1, field.newDfp("123456").log10K()); + Assert.assertEquals("log10K #2", 2, field.newDfp("123456789").log10K()); + Assert.assertEquals("log10K #3", 0, field.newDfp("2").log10K()); + Assert.assertEquals("log10K #3", 0, field.newDfp("1").log10K()); + Assert.assertEquals("log10K #4", -1, field.newDfp("0.1").log10K()); + } + + @Test + public void testPower10K() { + Dfp d = field.newDfp(); + + test(d.power10K(0), field.newDfp("1"), 0, "Power10 #1"); + test(d.power10K(1), field.newDfp("10000"), 0, "Power10 #2"); + test(d.power10K(2), field.newDfp("100000000"), 0, "Power10 #3"); + + test(d.power10K(-1), field.newDfp("0.0001"), 0, "Power10 #4"); + test(d.power10K(-2), field.newDfp("0.00000001"), 0, "Power10 #5"); + test(d.power10K(-3), field.newDfp("0.000000000001"), 0, "Power10 #6"); + } + + @Test + public void testLog10() { + Assert.assertEquals("log10 #1", 1, field.newDfp("12").intLog10()); + Assert.assertEquals("log10 #2", 2, field.newDfp("123").intLog10()); + Assert.assertEquals("log10 #3", 3, field.newDfp("1234").intLog10()); + Assert.assertEquals("log10 #4", 4, field.newDfp("12345").intLog10()); + Assert.assertEquals("log10 #5", 5, field.newDfp("123456").intLog10()); + Assert.assertEquals("log10 #6", 6, field.newDfp("1234567").intLog10()); + Assert.assertEquals("log10 #6", 7, field.newDfp("12345678").intLog10()); + Assert.assertEquals("log10 #7", 8, field.newDfp("123456789").intLog10()); + Assert.assertEquals("log10 #8", 9, field.newDfp("1234567890").intLog10()); + Assert.assertEquals("log10 #9", 10, field.newDfp("12345678901").intLog10()); + Assert.assertEquals("log10 #10", 11, field.newDfp("123456789012").intLog10()); + Assert.assertEquals("log10 #11", 12, field.newDfp("1234567890123").intLog10()); + + Assert.assertEquals("log10 #12", 0, field.newDfp("2").intLog10()); + Assert.assertEquals("log10 #13", 0, field.newDfp("1").intLog10()); + Assert.assertEquals("log10 #14", -1, field.newDfp("0.12").intLog10()); + Assert.assertEquals("log10 #15", -2, field.newDfp("0.012").intLog10()); + } + + @Test + public void testPower10() { + Dfp d = field.newDfp(); + + test(d.power10(0), field.newDfp("1"), 0, "Power10 #1"); + test(d.power10(1), field.newDfp("10"), 0, "Power10 #2"); + test(d.power10(2), field.newDfp("100"), 0, "Power10 #3"); + test(d.power10(3), field.newDfp("1000"), 0, "Power10 #4"); + test(d.power10(4), field.newDfp("10000"), 0, "Power10 #5"); + test(d.power10(5), field.newDfp("100000"), 0, "Power10 #6"); + test(d.power10(6), field.newDfp("1000000"), 0, "Power10 #7"); + test(d.power10(7), field.newDfp("10000000"), 0, "Power10 #8"); + test(d.power10(8), field.newDfp("100000000"), 0, "Power10 #9"); + test(d.power10(9), field.newDfp("1000000000"), 0, "Power10 #10"); + + test(d.power10(-1), field.newDfp(".1"), 0, "Power10 #11"); + test(d.power10(-2), field.newDfp(".01"), 0, "Power10 #12"); + test(d.power10(-3), field.newDfp(".001"), 0, "Power10 #13"); + test(d.power10(-4), field.newDfp(".0001"), 0, "Power10 #14"); + test(d.power10(-5), field.newDfp(".00001"), 0, "Power10 #15"); + test(d.power10(-6), field.newDfp(".000001"), 0, "Power10 #16"); + test(d.power10(-7), field.newDfp(".0000001"), 0, "Power10 #17"); + test(d.power10(-8), field.newDfp(".00000001"), 0, "Power10 #18"); + test(d.power10(-9), field.newDfp(".000000001"), 0, "Power10 #19"); + test(d.power10(-10), field.newDfp(".0000000001"), 0, "Power10 #20"); + } + + @Test + public void testRemainder() { + test(field.newDfp("10").remainder(field.newDfp("3")), + field.newDfp("1"), + DfpField.FLAG_INEXACT, "Remainder #1"); + + test(field.newDfp("9").remainder(field.newDfp("3")), + field.newDfp("0"), + 0, "Remainder #2"); + + test(field.newDfp("-9").remainder(field.newDfp("3")), + field.newDfp("-0"), + 0, "Remainder #3"); + } + + @Override + @Test + public void testSqrt() { + test(field.newDfp("0").sqrt(), + field.newDfp("0"), + 0, "Sqrt #1"); + + test(field.newDfp("-0").sqrt(), + field.newDfp("-0"), + 0, "Sqrt #2"); + + test(field.newDfp("1").sqrt(), + field.newDfp("1"), + 0, "Sqrt #3"); + + test(field.newDfp("2").sqrt(), + field.newDfp("1.4142135623730950"), + DfpField.FLAG_INEXACT, "Sqrt #4"); + + test(field.newDfp("3").sqrt(), + field.newDfp("1.7320508075688773"), + DfpField.FLAG_INEXACT, "Sqrt #5"); + + test(field.newDfp("5").sqrt(), + field.newDfp("2.2360679774997897"), + DfpField.FLAG_INEXACT, "Sqrt #6"); + + test(field.newDfp("500").sqrt(), + field.newDfp("22.3606797749978970"), + DfpField.FLAG_INEXACT, "Sqrt #6.2"); + + test(field.newDfp("50000").sqrt(), + field.newDfp("223.6067977499789696"), + DfpField.FLAG_INEXACT, "Sqrt #6.3"); + + test(field.newDfp("-1").sqrt(), + nan, + DfpField.FLAG_INVALID, "Sqrt #7"); + + test(pinf.sqrt(), + pinf, + 0, "Sqrt #8"); + + test(field.newDfp((byte) 1, Dfp.QNAN).sqrt(), + nan, + 0, "Sqrt #9"); + + test(field.newDfp((byte) 1, Dfp.SNAN).sqrt(), + nan, + DfpField.FLAG_INVALID, "Sqrt #9"); + } + + @Test + public void testIssue567() { + DfpField field = new DfpField(100); + Assert.assertEquals(0.0, field.getZero().toDouble(), Precision.SAFE_MIN); + Assert.assertEquals(0.0, field.newDfp(0.0).toDouble(), Precision.SAFE_MIN); + Assert.assertEquals(-1, FastMath.copySign(1, field.newDfp(-0.0).toDouble()), Precision.EPSILON); + Assert.assertEquals(+1, FastMath.copySign(1, field.newDfp(+0.0).toDouble()), Precision.EPSILON); + } + + @Test + public void testIsZero() { + Assert.assertTrue(field.getZero().isZero()); + Assert.assertTrue(field.getZero().negate().isZero()); + Assert.assertTrue(field.newDfp(+0.0).isZero()); + Assert.assertTrue(field.newDfp(-0.0).isZero()); + Assert.assertFalse(field.newDfp(1.0e-90).isZero()); + Assert.assertFalse(nan.isZero()); + Assert.assertFalse(nan.negate().isZero()); + Assert.assertFalse(pinf.isZero()); + Assert.assertFalse(pinf.negate().isZero()); + Assert.assertFalse(ninf.isZero()); + Assert.assertFalse(ninf.negate().isZero()); + } + + @Test + public void testSignPredicates() { + + Assert.assertTrue(field.getZero().negativeOrNull()); + Assert.assertTrue(field.getZero().positiveOrNull()); + Assert.assertFalse(field.getZero().strictlyNegative()); + Assert.assertFalse(field.getZero().strictlyPositive()); + + Assert.assertTrue(field.getZero().negate().negativeOrNull()); + Assert.assertTrue(field.getZero().negate().positiveOrNull()); + Assert.assertFalse(field.getZero().negate().strictlyNegative()); + Assert.assertFalse(field.getZero().negate().strictlyPositive()); + + Assert.assertFalse(field.getOne().negativeOrNull()); + Assert.assertTrue(field.getOne().positiveOrNull()); + Assert.assertFalse(field.getOne().strictlyNegative()); + Assert.assertTrue(field.getOne().strictlyPositive()); + + Assert.assertTrue(field.getOne().negate().negativeOrNull()); + Assert.assertFalse(field.getOne().negate().positiveOrNull()); + Assert.assertTrue(field.getOne().negate().strictlyNegative()); + Assert.assertFalse(field.getOne().negate().strictlyPositive()); + + Assert.assertFalse(nan.negativeOrNull()); + Assert.assertFalse(nan.positiveOrNull()); + Assert.assertFalse(nan.strictlyNegative()); + Assert.assertFalse(nan.strictlyPositive()); + + Assert.assertFalse(nan.negate().negativeOrNull()); + Assert.assertFalse(nan.negate().positiveOrNull()); + Assert.assertFalse(nan.negate().strictlyNegative()); + Assert.assertFalse(nan.negate().strictlyPositive()); + + Assert.assertFalse(pinf.negativeOrNull()); + Assert.assertTrue(pinf.positiveOrNull()); + Assert.assertFalse(pinf.strictlyNegative()); + Assert.assertTrue(pinf.strictlyPositive()); + + Assert.assertTrue(pinf.negate().negativeOrNull()); + Assert.assertFalse(pinf.negate().positiveOrNull()); + Assert.assertTrue(pinf.negate().strictlyNegative()); + Assert.assertFalse(pinf.negate().strictlyPositive()); + + Assert.assertTrue(ninf.negativeOrNull()); + Assert.assertFalse(ninf.positiveOrNull()); + Assert.assertTrue(ninf.strictlyNegative()); + Assert.assertFalse(ninf.strictlyPositive()); + + Assert.assertFalse(ninf.negate().negativeOrNull()); + Assert.assertTrue(ninf.negate().positiveOrNull()); + Assert.assertFalse(ninf.negate().strictlyNegative()); + Assert.assertTrue(ninf.negate().strictlyPositive()); + + } + + @Test + public void testSpecialConstructors() { + Assert.assertEquals(ninf, field.newDfp(Double.NEGATIVE_INFINITY)); + Assert.assertEquals(ninf, field.newDfp("-Infinity")); + Assert.assertEquals(pinf, field.newDfp(Double.POSITIVE_INFINITY)); + Assert.assertEquals(pinf, field.newDfp("Infinity")); + Assert.assertTrue(field.newDfp(Double.NaN).isNaN()); + Assert.assertTrue(field.newDfp("NaN").isNaN()); + } + + @Test + public void testEqualsHashcodeContract() { + DfpField var1 = new DfpField(1); + Dfp var6 = var1.newDfp(-0.0d); + Dfp var5 = var1.newDfp(0L); + + // Checks the contract: equals-hashcode on var5 and var6 + Assert.assertTrue(var5.equals(var6) ? var5.hashCode() == var6.hashCode() : true); + } + + private static void assertionFail(String content){ + Assert.fail("assertion failed: " + content); + } + + private static void assertionFailOpNum(String op, double num){ + assertionFail(op + " compare #" + num); + } + + private static final void assertionFailDfpField(DfpField field){ + assertionFail("compare flags = " + field.getIEEEFlags()); + } +} diff --git a/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathStrictComparisonTest.java b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathStrictComparisonTest.java new file mode 100644 index 000000000..7f12c1989 --- /dev/null +++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathStrictComparisonTest.java @@ -0,0 +1,262 @@ +/* + * 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.legacy.core.jdkmath; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.apache.commons.math4.legacy.exception.MathArithmeticException; +import org.apache.commons.numbers.core.Precision; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** + * Test to compare AccurateMath results against StrictMath results for boundary values. + *

+ * Running all tests independently:
+ * {@code mvn test -Dtest=AccurateMathStrictComparisonTest}
+ * or just run tests against a single method (e.g. scalb):
+ * {@code mvn test -Dtest=AccurateMathStrictComparisonTest -DargLine="-DtestMethod=scalb"} + */ +@SuppressWarnings("boxing") +@RunWith(Parameterized.class) +public class AccurateMathStrictComparisonTest { + + // Values which often need special handling + private static final Double[] DOUBLE_SPECIAL_VALUES = { + -0.0, +0.0, // 1,2 + Double.NaN, // 3 + Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, // 4,5 + -Double.MAX_VALUE, Double.MAX_VALUE, // 6,7 + // decreasing order of absolute value to help catch first failure + -Precision.EPSILON, Precision.EPSILON, // 8,9 + -Precision.SAFE_MIN, Precision.SAFE_MIN, // 10,11 + -Double.MIN_VALUE, Double.MIN_VALUE, // 12,13 + }; + + private static final Float [] FLOAT_SPECIAL_VALUES = { + -0.0f, +0.0f, // 1,2 + Float.NaN, // 3 + Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, // 4,5 + Float.MIN_VALUE, Float.MAX_VALUE, // 6,7 + -Float.MIN_VALUE, -Float.MAX_VALUE, // 8,9 + }; + + private static final Object [] LONG_SPECIAL_VALUES = { + -1,0,1, // 1,2,3 + Long.MIN_VALUE, Long.MAX_VALUE, // 4,5 + }; + + private static final Object[] INT_SPECIAL_VALUES = { + -1,0,1, // 1,2,3 + Integer.MIN_VALUE, Integer.MAX_VALUE, // 4,5 + }; + + private final Method mathMethod; + private final Method fastMethod; + private final Type[] types; + private final Object[][] valueArrays; + + public AccurateMathStrictComparisonTest(Method m, Method f, Type[] types, Object[][] data) throws Exception{ + this.mathMethod=m; + this.fastMethod=f; + this.types=types; + this.valueArrays=data; + } + + @Test + public void test1() throws Exception{ + setupMethodCall(mathMethod, fastMethod, types, valueArrays); + } + private static boolean isNumber(Double d) { + return !(d.isInfinite() || d.isNaN()); + } + + private static boolean isNumber(Float f) { + return !(f.isInfinite() || f.isNaN()); + } + + private static void reportFailedResults(Method mathMethod, Object[] params, Object expected, Object actual, int[] entries){ + final String methodName = mathMethod.getName(); + String format = null; + long actL=0; + long expL=0; + if (expected instanceof Double) { + Double exp = (Double) expected; + Double act = (Double) actual; + if (isNumber(exp) && isNumber(act) && exp != 0) { // show difference as hex + actL = Double.doubleToLongBits(act); + expL = Double.doubleToLongBits(exp); + if (Math.abs(actL-expL)==1) { + // Not 100% sure off-by-one errors are allowed everywhere, so only allow for these methods + if (methodName.equals("toRadians") || methodName.equals("atan2")) { + return; + } + } + format = "%016x"; + } + } else if (expected instanceof Float ){ + Float exp = (Float) expected; + Float act = (Float) actual; + if (isNumber(exp) && isNumber(act) && exp != 0) { // show difference as hex + actL = Float.floatToIntBits(act); + expL = Float.floatToIntBits(exp); + format = "%08x"; + } + } + StringBuilder sb = new StringBuilder(); + sb.append(mathMethod.getReturnType().getSimpleName()); + sb.append(" "); + sb.append(methodName); + sb.append("("); + String sep = ""; + for(Object o : params){ + sb.append(sep); + sb.append(o); + sep=", "; + } + sb.append(") expected "); + if (format != null){ + sb.append(String.format(format, expL)); + } else { + sb.append(expected); + } + sb.append(" actual "); + if (format != null){ + sb.append(String.format(format, actL)); + } else { + sb.append(actual); + } + sb.append(" entries "); + sb.append(Arrays.toString(entries)); + String message = sb.toString(); + final boolean fatal = true; + if (fatal) { + Assert.fail(message); + } else { + System.out.println(message); + } + } + + private static void callMethods(Method mathMethod, Method fastMethod, + Object[] params, int[] entries) throws IllegalAccessException { + try { + Object expected; + try { + expected = mathMethod.invoke(mathMethod, params); + } catch (InvocationTargetException ite) { + expected = ite.getCause(); + } + Object actual; + try { + actual = fastMethod.invoke(mathMethod, params); + } catch (InvocationTargetException ite) { + actual = ite.getCause(); + } + if (expected instanceof ArithmeticException) { + Assert.assertEquals(MathArithmeticException.class, actual.getClass()); + } else if (!expected.equals(actual)) { + reportFailedResults(mathMethod, params, expected, actual, entries); + } + } catch (IllegalArgumentException e) { + Assert.fail(mathMethod+" "+e); + } + } + + private static void setupMethodCall(Method mathMethod, Method fastMethod, + Type[] types, Object[][] valueArrays) throws Exception { + Object[] params = new Object[types.length]; + int entry1 = 0; + int[] entries = new int[types.length]; + for(Object d : valueArrays[0]) { + entry1++; + params[0] = d; + entries[0] = entry1; + if (params.length > 1){ + int entry2 = 0; + for(Object d1 : valueArrays[1]) { + entry2++; + params[1] = d1; + entries[1] = entry2; + callMethods(mathMethod, fastMethod, params, entries); + } + } else { + callMethods(mathMethod, fastMethod, params, entries); + } + } + } + + @Parameters + public static List data() throws Exception { + String singleMethod = System.getProperty("testMethod"); + List list = new ArrayList<>(); + for(Method mathMethod : StrictMath.class.getDeclaredMethods()) { + method: + if (Modifier.isPublic(mathMethod.getModifiers())){// Only test public methods + Type []types = mathMethod.getGenericParameterTypes(); + if (types.length >=1) { // Only check methods with at least one parameter + try { + // Get the corresponding AccurateMath method + Method fastMethod = AccurateMath.class.getDeclaredMethod(mathMethod.getName(), (Class[]) types); + if (Modifier.isPublic(fastMethod.getModifiers())) { // It must be public too + if (singleMethod != null && !fastMethod.getName().equals(singleMethod)) { + break method; + } + Object [][] values = new Object[types.length][]; + int index = 0; + for(Type t : types) { + if (t.equals(double.class)){ + values[index]=DOUBLE_SPECIAL_VALUES; + } else if (t.equals(float.class)) { + values[index]=FLOAT_SPECIAL_VALUES; + } else if (t.equals(long.class)) { + values[index]=LONG_SPECIAL_VALUES; + } else if (t.equals(int.class)) { + values[index]=INT_SPECIAL_VALUES; + } else { + System.out.println("Cannot handle class "+t+" for "+mathMethod); + break method; + } + index++; + } +// System.out.println(fastMethod); + /* + * The current implementation runs each method as a separate test. + * Could be amended to run each value as a separate test + */ + list.add(new Object[]{mathMethod, fastMethod, types, values}); +// setupMethodCall(mathMethod, fastMethod, params, data); + } else { + System.out.println("Cannot find public AccurateMath method corresponding to: "+mathMethod); + } + } catch (NoSuchMethodException e) { + System.out.println("Cannot find AccurateMath method corresponding to: "+mathMethod); + } + } + } + } + return list; + } +} diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/FastMathStrictComparisonTest.java b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathStrictComparisonTest.java.bak similarity index 93% rename from commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/FastMathStrictComparisonTest.java rename to commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathStrictComparisonTest.java.bak index 4a99fb325..64f455727 100644 --- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/FastMathStrictComparisonTest.java +++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathStrictComparisonTest.java.bak @@ -33,16 +33,16 @@ import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; /** - * Test to compare FastMath results against StrictMath results for boundary values. + * Test to compare AccurateMath results against StrictMath results for boundary values. *

* Running all tests independently:
- * {@code mvn test -Dtest=FastMathStrictComparisonTest}
+ * {@code mvn test -Dtest=AccurateMathStrictComparisonTest}
* or just run tests against a single method (e.g. scalb):
- * {@code mvn test -Dtest=FastMathStrictComparisonTest -DargLine="-DtestMethod=scalb"} + * {@code mvn test -Dtest=AccurateMathStrictComparisonTest -DargLine="-DtestMethod=scalb"} */ @SuppressWarnings("boxing") @RunWith(Parameterized.class) -public class FastMathStrictComparisonTest { +public class AccurateMathStrictComparisonTest { // Values which often need special handling private static final Double[] DOUBLE_SPECIAL_VALUES = { @@ -79,7 +79,7 @@ public class FastMathStrictComparisonTest { private final Type[] types; private final Object[][] valueArrays; - public FastMathStrictComparisonTest(Method m, Method f, Type[] types, Object[][] data) throws Exception{ + public AccurateMathStrictComparisonTest(Method m, Method f, Type[] types, Object[][] data) throws Exception{ this.mathMethod=m; this.fastMethod=f; this.types=types; @@ -218,8 +218,8 @@ public class FastMathStrictComparisonTest { Type []types = mathMethod.getGenericParameterTypes(); if (types.length >=1) { // Only check methods with at least one parameter try { - // Get the corresponding FastMath method - Method fastMethod = FastMath.class.getDeclaredMethod(mathMethod.getName(), (Class[]) types); + // Get the corresponding AccurateMath method + Method fastMethod = AccurateMath.class.getDeclaredMethod(mathMethod.getName(), (Class[]) types); if (Modifier.isPublic(fastMethod.getModifiers())) { // It must be public too if (singleMethod != null && !fastMethod.getName().equals(singleMethod)) { break method; @@ -249,10 +249,10 @@ public class FastMathStrictComparisonTest { list.add(new Object[]{mathMethod, fastMethod, types, values}); // setupMethodCall(mathMethod, fastMethod, params, data); } else { - System.out.println("Cannot find public FastMath method corresponding to: "+mathMethod); + System.out.println("Cannot find public AccurateMath method corresponding to: "+mathMethod); } } catch (NoSuchMethodException e) { - System.out.println("Cannot find FastMath method corresponding to: "+mathMethod); + System.out.println("Cannot find AccurateMath method corresponding to: "+mathMethod); } } } diff --git a/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathTest.java b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathTest.java new file mode 100644 index 000000000..6a8ff2728 --- /dev/null +++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathTest.java @@ -0,0 +1,1965 @@ +/* + * 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.legacy.core.jdkmath; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.lang.reflect.Type; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.math.RoundingMode; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import org.apache.commons.numbers.core.ArithmeticUtils; +import org.apache.commons.numbers.core.Precision; +import org.apache.commons.math4.legacy.core.dfp.Dfp; +import org.apache.commons.math4.legacy.core.dfp.DfpField; +import org.apache.commons.math4.legacy.core.dfp.DfpMath; +import org.apache.commons.math4.legacy.exception.MathArithmeticException; +import org.apache.commons.rng.UniformRandomProvider; +import org.apache.commons.rng.simple.RandomSource; + +public class AccurateMathTest { + + private static final double MAX_ERROR_ULP = 0.51; + private static final int NUMBER_OF_TRIALS = 1000; + + private DfpField field; + private UniformRandomProvider generator; + + @Before + public void setUp() { + field = new DfpField(40); + generator = RandomSource.create(RandomSource.MT, 6176597458463500194l); + } + + @Test + public void testMinMaxDouble() { + double[][] pairs = { + { -50.0, 50.0 }, + { Double.POSITIVE_INFINITY, 1.0 }, + { Double.NEGATIVE_INFINITY, 1.0 }, + { Double.NaN, 1.0 }, + { Double.POSITIVE_INFINITY, 0.0 }, + { Double.NEGATIVE_INFINITY, 0.0 }, + { Double.NaN, 0.0 }, + { Double.NaN, Double.NEGATIVE_INFINITY }, + { Double.NaN, Double.POSITIVE_INFINITY }, + { Precision.SAFE_MIN, Precision.EPSILON } + }; + for (double[] pair : pairs) { + assertEquals("min(" + pair[0] + ", " + pair[1] + ")", + Math.min(pair[0], pair[1]), + AccurateMath.min(pair[0], pair[1]), + Precision.EPSILON); + assertEquals("min(" + pair[1] + ", " + pair[0] + ")", + Math.min(pair[1], pair[0]), + AccurateMath.min(pair[1], pair[0]), + Precision.EPSILON); + assertEquals("max(" + pair[0] + ", " + pair[1] + ")", + Math.max(pair[0], pair[1]), + AccurateMath.max(pair[0], pair[1]), + Precision.EPSILON); + assertEquals("max(" + pair[1] + ", " + pair[0] + ")", + Math.max(pair[1], pair[0]), + AccurateMath.max(pair[1], pair[0]), + Precision.EPSILON); + } + } + + @Test + public void testMinMaxFloat() { + float[][] pairs = { + { -50.0f, 50.0f }, + { Float.POSITIVE_INFINITY, 1.0f }, + { Float.NEGATIVE_INFINITY, 1.0f }, + { Float.NaN, 1.0f }, + { Float.POSITIVE_INFINITY, 0.0f }, + { Float.NEGATIVE_INFINITY, 0.0f }, + { Float.NaN, 0.0f }, + { Float.NaN, Float.NEGATIVE_INFINITY }, + { Float.NaN, Float.POSITIVE_INFINITY } + }; + for (float[] pair : pairs) { + assertEquals("min(" + pair[0] + ", " + pair[1] + ")", + Math.min(pair[0], pair[1]), + AccurateMath.min(pair[0], pair[1]), + Precision.EPSILON); + assertEquals("min(" + pair[1] + ", " + pair[0] + ")", + Math.min(pair[1], pair[0]), + AccurateMath.min(pair[1], pair[0]), + Precision.EPSILON); + assertEquals("max(" + pair[0] + ", " + pair[1] + ")", + Math.max(pair[0], pair[1]), + AccurateMath.max(pair[0], pair[1]), + Precision.EPSILON); + assertEquals("max(" + pair[1] + ", " + pair[0] + ")", + Math.max(pair[1], pair[0]), + AccurateMath.max(pair[1], pair[0]), + Precision.EPSILON); + } + } + + @Test + public void testConstants() { + assertEquals(Math.PI, AccurateMath.PI, 1.0e-20); + assertEquals(Math.E, AccurateMath.E, 1.0e-20); + } + + @Test + public void testAtan2() { + double y1 = 1.2713504628280707e10; + double x1 = -5.674940885228782e-10; + assertEquals(Math.atan2(y1, x1), AccurateMath.atan2(y1, x1), 2 * Precision.EPSILON); + double y2 = 0.0; + double x2 = Double.POSITIVE_INFINITY; + assertEquals(Math.atan2(y2, x2), AccurateMath.atan2(y2, x2), Precision.SAFE_MIN); + } + + @Test + public void testHyperbolic() { + double maxErr = 0; + for (double x = -30; x < 30; x += 0.001) { + double tst = AccurateMath.sinh(x); + double ref = Math.sinh(x); + maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref)); + } + assertEquals(0, maxErr, 2); + + maxErr = 0; + for (double x = -30; x < 30; x += 0.001) { + double tst = AccurateMath.cosh(x); + double ref = Math.cosh(x); + maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref)); + } + assertEquals(0, maxErr, 2); + + maxErr = 0; + for (double x = -0.5; x < 0.5; x += 0.001) { + double tst = AccurateMath.tanh(x); + double ref = Math.tanh(x); + maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref)); + } + assertEquals(0, maxErr, 4); + + } + + @Test + public void testMath904() { + final double x = -1; + final double y = (5 + 1e-15) * 1e15; + assertEquals(Math.pow(x, y), + AccurateMath.pow(x, y), 0); + assertEquals(Math.pow(x, -y), + AccurateMath.pow(x, -y), 0); + } + + @Test + public void testMath905LargePositive() { + final double start = StrictMath.log(Double.MAX_VALUE); + final double endT = StrictMath.sqrt(2) * StrictMath.sqrt(Double.MAX_VALUE); + final double end = 2 * StrictMath.log(endT); + + double maxErr = 0; + for (double x = start; x < end; x += 1e-3) { + final double tst = AccurateMath.cosh(x); + final double ref = Math.cosh(x); + maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref)); + } + assertEquals(0, maxErr, 3); + + for (double x = start; x < end; x += 1e-3) { + final double tst = AccurateMath.sinh(x); + final double ref = Math.sinh(x); + maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref)); + } + assertEquals(0, maxErr, 3); + } + + @Test + public void testMath905LargeNegative() { + final double start = -StrictMath.log(Double.MAX_VALUE); + final double endT = StrictMath.sqrt(2) * StrictMath.sqrt(Double.MAX_VALUE); + final double end = -2 * StrictMath.log(endT); + + double maxErr = 0; + for (double x = start; x > end; x -= 1e-3) { + final double tst = AccurateMath.cosh(x); + final double ref = Math.cosh(x); + maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref)); + } + assertEquals(0, maxErr, 3); + + for (double x = start; x > end; x -= 1e-3) { + final double tst = AccurateMath.sinh(x); + final double ref = Math.sinh(x); + maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref)); + } + assertEquals(0, maxErr, 3); + } + + @Test + public void testMath1269() { + final double arg = 709.8125; + final double vM = Math.exp(arg); + final double vFM = AccurateMath.exp(arg); + assertTrue("exp(" + arg + ") is " + vFM + " instead of " + vM, + Precision.equalsIncludingNaN(vM, vFM)); + } + + @Test + public void testHyperbolicInverses() { + double maxErr = 0; + for (double x = -30; x < 30; x += 0.01) { + maxErr = AccurateMath.max(maxErr, AccurateMath.abs(x - AccurateMath.sinh(AccurateMath.asinh(x))) / (2 * AccurateMath.ulp(x))); + } + assertEquals(0, maxErr, 3); + + maxErr = 0; + for (double x = 1; x < 30; x += 0.01) { + maxErr = AccurateMath.max(maxErr, AccurateMath.abs(x - AccurateMath.cosh(AccurateMath.acosh(x))) / (2 * AccurateMath.ulp(x))); + } + assertEquals(0, maxErr, 2); + + maxErr = 0; + for (double x = -1 + Precision.EPSILON; x < 1 - Precision.EPSILON; x += 0.0001) { + maxErr = AccurateMath.max(maxErr, AccurateMath.abs(x - AccurateMath.tanh(AccurateMath.atanh(x))) / (2 * AccurateMath.ulp(x))); + } + assertEquals(0, maxErr, 2); + } + + @Test + public void testLogAccuracy() { + double maxerrulp = 0.0; + + for (int i = 0; i < NUMBER_OF_TRIALS; i++) { + double x = Math.exp(generator.nextDouble() * 1416.0 - 708.0) * generator.nextDouble(); + // double x = generator.nextDouble()*2.0; + double tst = AccurateMath.log(x); + double ref = DfpMath.log(field.newDfp(x)).toDouble(); + double err = (tst - ref) / ref; + + if (err != 0.0) { + double ulp = Math.abs(ref - + Double.longBitsToDouble((Double.doubleToLongBits(ref) ^ 1))); + double errulp = field.newDfp(tst).subtract(DfpMath.log(field.newDfp(x))).divide(field.newDfp(ulp)).toDouble(); +// System.out.println(x + "\t" + tst + "\t" + ref + "\t" + err + "\t" + errulp); + + maxerrulp = Math.max(maxerrulp, Math.abs(errulp)); + } + } + + assertTrue("log() had errors in excess of " + MAX_ERROR_ULP + " ULP", maxerrulp < MAX_ERROR_ULP); + } + + @Test + public void testLog10Accuracy() { + double maxerrulp = 0.0; + + for (int i = 0; i < NUMBER_OF_TRIALS; i++) { + double x = Math.exp(generator.nextDouble() * 1416.0 - 708.0) * generator.nextDouble(); + // double x = generator.nextDouble()*2.0; + double tst = AccurateMath.log10(x); + double ref = DfpMath.log(field.newDfp(x)).divide(DfpMath.log(field.newDfp("10"))).toDouble(); + double err = (tst - ref) / ref; + + if (err != 0.0) { + double ulp = Math.abs(ref - + Double.longBitsToDouble((Double.doubleToLongBits(ref) ^ 1))); + double errulp = field.newDfp(tst).subtract(DfpMath.log(field.newDfp(x)).divide(DfpMath.log(field.newDfp("10")))).divide(field.newDfp(ulp)).toDouble(); +// System.out.println(x + "\t" + tst + "\t" + ref + "\t" + err + "\t" + errulp); + + maxerrulp = Math.max(maxerrulp, Math.abs(errulp)); + } + } + + assertTrue("log10() had errors in excess of " + MAX_ERROR_ULP + " ULP", maxerrulp < MAX_ERROR_ULP); + } + + @Test + public void testLog1pAccuracy() { + double maxerrulp = 0.0; + + for (int i = 0; i < NUMBER_OF_TRIALS; i++) { + double x = Math.exp(generator.nextDouble() * 10.0 - 5.0) * generator.nextDouble(); + // double x = generator.nextDouble()*2.0; + double tst = AccurateMath.log1p(x); + double ref = DfpMath.log(field.newDfp(x).add(field.getOne())).toDouble(); + double err = (tst - ref) / ref; + + if (err != 0.0) { + double ulp = Math.abs(ref - + Double.longBitsToDouble((Double.doubleToLongBits(ref) ^ 1))); + double errulp = field.newDfp(tst).subtract(DfpMath.log(field.newDfp(x).add(field.getOne()))).divide(field.newDfp(ulp)).toDouble(); +// System.out.println(x + "\t" + tst + "\t" + ref + "\t" + err + "\t" + errulp); + + maxerrulp = Math.max(maxerrulp, Math.abs(errulp)); + } + } + + assertTrue("log1p() had errors in excess of " + MAX_ERROR_ULP + " ULP", maxerrulp < MAX_ERROR_ULP); + } + + @Test + public void testLog1pSpecialCases() { + assertTrue("Logp of -1.0 should be -Inf", Double.isInfinite(AccurateMath.log1p(-1.0))); + } + + @Test + public void testLogSpecialCases() { + assertEquals("Log of zero should be -Inf", Double.NEGATIVE_INFINITY, AccurateMath.log(0.0), 1.0); + assertEquals("Log of -zero should be -Inf", Double.NEGATIVE_INFINITY, AccurateMath.log(-0.0), 1.0); + assertTrue("Log of NaN should be NaN", Double.isNaN(AccurateMath.log(Double.NaN))); + assertTrue("Log of negative number should be NaN", Double.isNaN(AccurateMath.log(-1.0))); + assertEquals("Log of Double.MIN_VALUE should be -744.4400719213812", -744.4400719213812, AccurateMath.log(Double.MIN_VALUE), Precision.EPSILON); + assertEquals("Log of infinity should be infinity", Double.POSITIVE_INFINITY, AccurateMath.log(Double.POSITIVE_INFINITY), 1.0); + } + + @Test + public void testExpSpecialCases() { + // Smallest value that will round up to Double.MIN_VALUE + assertEquals(Double.MIN_VALUE, AccurateMath.exp(-745.1332191019411), Precision.EPSILON); + assertEquals("exp(-745.1332191019412) should be 0.0", 0.0, AccurateMath.exp(-745.1332191019412), Precision.EPSILON); + assertTrue("exp of NaN should be NaN", Double.isNaN(AccurateMath.exp(Double.NaN))); + assertEquals("exp of infinity should be infinity", Double.POSITIVE_INFINITY, AccurateMath.exp(Double.POSITIVE_INFINITY), 1.0); + assertEquals("exp of -infinity should be 0.0", 0.0, AccurateMath.exp(Double.NEGATIVE_INFINITY), Precision.EPSILON); + assertEquals("exp(1) should be Math.E", Math.E, AccurateMath.exp(1.0), Precision.EPSILON); + } + + @Test + public void testPowSpecialCases() { + final double EXACT = -1.0; + + assertEquals("pow(-1, 0) should be 1.0", 1.0, AccurateMath.pow(-1.0, 0.0), Precision.EPSILON); + assertEquals("pow(-1, -0) should be 1.0", 1.0, AccurateMath.pow(-1.0, -0.0), Precision.EPSILON); + assertEquals("pow(PI, 1.0) should be PI", AccurateMath.PI, AccurateMath.pow(AccurateMath.PI, 1.0), Precision.EPSILON); + assertEquals("pow(-PI, 1.0) should be -PI", -AccurateMath.PI, AccurateMath.pow(-AccurateMath.PI, 1.0), Precision.EPSILON); + assertTrue("pow(PI, NaN) should be NaN", Double.isNaN(AccurateMath.pow(Math.PI, Double.NaN))); + assertTrue("pow(NaN, PI) should be NaN", Double.isNaN(AccurateMath.pow(Double.NaN, Math.PI))); + assertEquals("pow(2.0, Infinity) should be Infinity", Double.POSITIVE_INFINITY, AccurateMath.pow(2.0, Double.POSITIVE_INFINITY), 1.0); + assertEquals("pow(0.5, -Infinity) should be Infinity", Double.POSITIVE_INFINITY, AccurateMath.pow(0.5, Double.NEGATIVE_INFINITY), 1.0); + assertEquals("pow(0.5, Infinity) should be 0.0", 0.0, AccurateMath.pow(0.5, Double.POSITIVE_INFINITY), Precision.EPSILON); + assertEquals("pow(2.0, -Infinity) should be 0.0", 0.0, AccurateMath.pow(2.0, Double.NEGATIVE_INFINITY), Precision.EPSILON); + assertEquals("pow(0.0, 0.5) should be 0.0", 0.0, AccurateMath.pow(0.0, 0.5), Precision.EPSILON); + assertEquals("pow(Infinity, -0.5) should be 0.0", 0.0, AccurateMath.pow(Double.POSITIVE_INFINITY, -0.5), Precision.EPSILON); + assertEquals("pow(0.0, -0.5) should be Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(0.0, -0.5), 1.0); + assertEquals("pow(Inf, 0.5) should be Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(Double.POSITIVE_INFINITY, 0.5), 1.0); + assertEquals("pow(-0.0, -3.0) should be -Inf", Double.NEGATIVE_INFINITY, AccurateMath.pow(-0.0, -3.0), 1.0); + assertEquals("pow(-0.0, Infinity) should be 0.0", 0.0, AccurateMath.pow(-0.0, Double.POSITIVE_INFINITY), Precision.EPSILON); + assertTrue("pow(-0.0, NaN) should be NaN", Double.isNaN(AccurateMath.pow(-0.0, Double.NaN))); + assertEquals("pow(-0.0, -tiny) should be Infinity", Double.POSITIVE_INFINITY, AccurateMath.pow(-0.0, -Double.MIN_VALUE), 1.0); + assertEquals("pow(-0.0, -huge) should be Infinity", Double.POSITIVE_INFINITY, AccurateMath.pow(-0.0, -Double.MAX_VALUE), 1.0); + assertEquals("pow(-Inf, 3.0) should be -Inf", Double.NEGATIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, 3.0), 1.0); + assertEquals("pow(-Inf, -3.0) should be -0.0", -0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, -3.0), EXACT); + assertEquals("pow(-0.0, -3.5) should be Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(-0.0, -3.5), 1.0); + assertEquals("pow(Inf, 3.5) should be Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(Double.POSITIVE_INFINITY, 3.5), 1.0); + assertEquals("pow(-2.0, 3.0) should be -8.0", -8.0, AccurateMath.pow(-2.0, 3.0), Precision.EPSILON); + assertTrue("pow(-2.0, 3.5) should be NaN", Double.isNaN(AccurateMath.pow(-2.0, 3.5))); + assertTrue("pow(NaN, -Infinity) should be NaN", Double.isNaN(AccurateMath.pow(Double.NaN, Double.NEGATIVE_INFINITY))); + assertEquals("pow(NaN, 0.0) should be 1.0", 1.0, AccurateMath.pow(Double.NaN, 0.0), Precision.EPSILON); + assertEquals("pow(-Infinity, -Infinity) should be 0.0", 0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON); + assertEquals("pow(-huge, -huge) should be 0.0", 0.0, AccurateMath.pow(-Double.MAX_VALUE, -Double.MAX_VALUE), Precision.EPSILON); + assertTrue("pow(-huge, huge) should be +Inf", Double.isInfinite(AccurateMath.pow(-Double.MAX_VALUE, Double.MAX_VALUE))); + assertTrue("pow(NaN, -Infinity) should be NaN", Double.isNaN(AccurateMath.pow(Double.NaN, Double.NEGATIVE_INFINITY))); + assertEquals("pow(NaN, -0.0) should be 1.0", 1.0, AccurateMath.pow(Double.NaN, -0.0), Precision.EPSILON); + assertEquals("pow(-Infinity, -Infinity) should be 0.0", 0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON); + assertEquals("pow(-huge, -huge) should be 0.0", 0.0, AccurateMath.pow(-Double.MAX_VALUE, -Double.MAX_VALUE), Precision.EPSILON); + assertEquals("pow(-huge, huge) should be +Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(-Double.MAX_VALUE, Double.MAX_VALUE), 1.0); + + // Added tests for a 100% coverage + + assertTrue("pow(+Inf, NaN) should be NaN", Double.isNaN(AccurateMath.pow(Double.POSITIVE_INFINITY, Double.NaN))); + assertTrue("pow(1.0, +Inf) should be NaN", Double.isNaN(AccurateMath.pow(1.0, Double.POSITIVE_INFINITY))); + assertTrue("pow(-Inf, NaN) should be NaN", Double.isNaN(AccurateMath.pow(Double.NEGATIVE_INFINITY, Double.NaN))); + assertEquals("pow(-Inf, -1.0) should be -0.0", -0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, -1.0), EXACT); + assertEquals("pow(-Inf, -2.0) should be 0.0", 0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, -2.0), EXACT); + assertEquals("pow(-Inf, 1.0) should be -Inf", Double.NEGATIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, 1.0), 1.0); + assertEquals("pow(-Inf, 2.0) should be +Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, 2.0), 1.0); + assertTrue("pow(1.0, -Inf) should be NaN", Double.isNaN(AccurateMath.pow(1.0, Double.NEGATIVE_INFINITY))); + assertEquals("pow(-0.0, 1.0) should be -0.0", -0.0, AccurateMath.pow(-0.0, 1.0), EXACT); + assertEquals("pow(0.0, 1.0) should be 0.0", 0.0, AccurateMath.pow(0.0, 1.0), EXACT); + assertEquals("pow(0.0, +Inf) should be 0.0", 0.0, AccurateMath.pow(0.0, Double.POSITIVE_INFINITY), EXACT); + assertEquals("pow(-0.0, even) should be 0.0", 0.0, AccurateMath.pow(-0.0, 6.0), EXACT); + assertEquals("pow(-0.0, odd) should be -0.0", -0.0, AccurateMath.pow(-0.0, 13.0), EXACT); + assertEquals("pow(-0.0, -even) should be +Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(-0.0, -6.0), EXACT); + assertEquals("pow(-0.0, -odd) should be -Inf", Double.NEGATIVE_INFINITY, AccurateMath.pow(-0.0, -13.0), EXACT); + assertEquals("pow(-2.0, 4.0) should be 16.0", 16.0, AccurateMath.pow(-2.0, 4.0), EXACT); + assertEquals("pow(-2.0, 4.5) should be NaN", Double.NaN, AccurateMath.pow(-2.0, 4.5), EXACT); + assertEquals("pow(-0.0, -0.0) should be 1.0", 1.0, AccurateMath.pow(-0.0, -0.0), EXACT); + assertEquals("pow(-0.0, 0.0) should be 1.0", 1.0, AccurateMath.pow(-0.0, 0.0), EXACT); + assertEquals("pow(0.0, -0.0) should be 1.0", 1.0, AccurateMath.pow(0.0, -0.0), EXACT); + assertEquals("pow(0.0, 0.0) should be 1.0", 1.0, AccurateMath.pow(0.0, 0.0), EXACT); + } + + @Test(timeout=20000L) + public void testPowAllSpecialCases() { + final double EXACT = -1.0; + final double DOUBLES[] = new double[] + { + Double.NEGATIVE_INFINITY, -0.0, Double.NaN, 0.0, Double.POSITIVE_INFINITY, + Long.MIN_VALUE, Integer.MIN_VALUE, Short.MIN_VALUE, Byte.MIN_VALUE, + -(double)Long.MIN_VALUE, -(double)Integer.MIN_VALUE, -(double)Short.MIN_VALUE, -(double)Byte.MIN_VALUE, + Byte.MAX_VALUE, Short.MAX_VALUE, Integer.MAX_VALUE, Long.MAX_VALUE, + -Byte.MAX_VALUE, -Short.MAX_VALUE, -Integer.MAX_VALUE, -Long.MAX_VALUE, + Float.MAX_VALUE, Double.MAX_VALUE, Double.MIN_VALUE, Float.MIN_VALUE, + -Float.MAX_VALUE, -Double.MAX_VALUE, -Double.MIN_VALUE, -Float.MIN_VALUE, + 0.5, 0.1, 0.2, 0.8, 1.1, 1.2, 1.5, 1.8, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 1.3, 2.2, 2.5, 2.8, 33.0, 33.1, 33.5, 33.8, 10.0, 300.0, 400.0, 500.0, + -0.5, -0.1, -0.2, -0.8, -1.1, -1.2, -1.5, -1.8, -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -1.3, -2.2, -2.5, -2.8, -33.0, -33.1, -33.5, -33.8, -10.0, -300.0, -400.0, -500.0 + }; + + // Special cases from Math.pow javadoc: + // If the second argument is positive or negative zero, then the result is 1.0. + for (double d : DOUBLES) { + assertEquals(1.0, AccurateMath.pow(d, 0.0), EXACT); + } + for (double d : DOUBLES) { + assertEquals(1.0, AccurateMath.pow(d, -0.0), EXACT); + } + // If the second argument is 1.0, then the result is the same as the first argument. + for (double d : DOUBLES) { + assertEquals(d, AccurateMath.pow(d, 1.0), EXACT); + } + // If the second argument is NaN, then the result is NaN. + for (double d : DOUBLES) { + assertEquals(Double.NaN, AccurateMath.pow(d, Double.NaN), EXACT); + } + // If the first argument is NaN and the second argument is nonzero, then the result is NaN. + for (double i : DOUBLES) { + if (i != 0.0) { + assertEquals(Double.NaN, AccurateMath.pow(Double.NaN, i), EXACT); + } + } + // If the absolute value of the first argument is greater than 1 and the second argument is positive infinity, or + // the absolute value of the first argument is less than 1 and the second argument is negative infinity, then the result is positive infinity. + for (double d : DOUBLES) { + if (Math.abs(d) > 1.0) { + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(d, Double.POSITIVE_INFINITY), EXACT); + } + } + for (double d : DOUBLES) { + if (Math.abs(d) < 1.0) { + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(d, Double.NEGATIVE_INFINITY), EXACT); + } + } + // If the absolute value of the first argument is greater than 1 and the second argument is negative infinity, or + // the absolute value of the first argument is less than 1 and the second argument is positive infinity, then the result is positive zero. + for (double d : DOUBLES) { + if (Math.abs(d) > 1.0) { + assertEquals(0.0, AccurateMath.pow(d, Double.NEGATIVE_INFINITY), EXACT); + } + } + for (double d : DOUBLES) { + if (Math.abs(d) < 1.0) { + assertEquals(0.0, AccurateMath.pow(d, Double.POSITIVE_INFINITY), EXACT); + } + } + // If the absolute value of the first argument equals 1 and the second argument is infinite, then the result is NaN. + assertEquals(Double.NaN, AccurateMath.pow(1.0, Double.POSITIVE_INFINITY), EXACT); + assertEquals(Double.NaN, AccurateMath.pow(1.0, Double.NEGATIVE_INFINITY), EXACT); + assertEquals(Double.NaN, AccurateMath.pow(-1.0, Double.POSITIVE_INFINITY), EXACT); + assertEquals(Double.NaN, AccurateMath.pow(-1.0, Double.NEGATIVE_INFINITY), EXACT); + // If the first argument is positive zero and the second argument is greater than zero, or + // the first argument is positive infinity and the second argument is less than zero, then the result is positive zero. + for (double i : DOUBLES) { + if (i > 0.0) { + assertEquals(0.0, AccurateMath.pow(0.0, i), EXACT); + } + } + for (double i : DOUBLES) { + if (i < 0.0) { + assertEquals(0.0, AccurateMath.pow(Double.POSITIVE_INFINITY, i), EXACT); + } + } + // If the first argument is positive zero and the second argument is less than zero, or + // the first argument is positive infinity and the second argument is greater than zero, then the result is positive infinity. + for (double i : DOUBLES) { + if (i < 0.0) { + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(0.0, i), EXACT); + } + } + for (double i : DOUBLES) { + if (i > 0.0) { + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(Double.POSITIVE_INFINITY, i), EXACT); + } + } + // If the first argument is negative zero and the second argument is greater than zero but not a finite odd integer, or + // the first argument is negative infinity and the second argument is less than zero but not a finite odd integer, then the result is positive zero. + for (double i : DOUBLES) { + if (i > 0.0 && (Double.isInfinite(i) || i % 2.0 == 0.0)) { + assertEquals(0.0, AccurateMath.pow(-0.0, i), EXACT); + } + } + for (double i : DOUBLES) { + if (i < 0.0 && (Double.isInfinite(i) || i % 2.0 == 0.0)) { + assertEquals(0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT); + } + } + // If the first argument is negative zero and the second argument is a positive finite odd integer, or + // the first argument is negative infinity and the second argument is a negative finite odd integer, then the result is negative zero. + for (double i : DOUBLES) { + if (i > 0.0 && i % 2.0 == 1.0) { + assertEquals(-0.0, AccurateMath.pow(-0.0, i), EXACT); + } + } + for (double i : DOUBLES) { + if (i < 0.0 && i % 2.0 == -1.0) { + assertEquals(-0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT); + } + } + // If the first argument is negative zero and the second argument is less than zero but not a finite odd integer, or + // the first argument is negative infinity and the second argument is greater than zero but not a finite odd integer, then the result is positive infinity. + for (double i : DOUBLES) { + if (i > 0.0 && (Double.isInfinite(i) || i % 2.0 == 0.0)) { + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT); + } + } + for (double i : DOUBLES) { + if (i < 0.0 && (Double.isInfinite(i) || i % 2.0 == 0.0)) { + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(-0.0, i), EXACT); + } + } + // If the first argument is negative zero and the second argument is a negative finite odd integer, or + // the first argument is negative infinity and the second argument is a positive finite odd integer, then the result is negative infinity. + for (double i : DOUBLES) { + if (i > 0.0 && i % 2.0 == 1.0) { + assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT); + } + } + for (double i : DOUBLES) { + if (i < 0.0 && i % 2.0 == -1.0) { + assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.pow(-0.0, i), EXACT); + } + } + for (double d : DOUBLES) { + // If the first argument is finite and less than zero + if (d < 0.0 && Math.abs(d) <= Double.MAX_VALUE) { + for (double i : DOUBLES) { + if (Math.abs(i) <= Double.MAX_VALUE) { + // if the second argument is a finite even integer, the result is equal to the result of raising the absolute value of the first argument to the power of the second argument + if (i % 2.0 == 0.0) assertEquals(AccurateMath.pow(-d, i), AccurateMath.pow(d, i), EXACT); + // if the second argument is a finite odd integer, the result is equal to the negative of the result of raising the absolute value of the first argument to the power of the second argument + else if (Math.abs(i) % 2.0 == 1.0) assertEquals(-AccurateMath.pow(-d, i), AccurateMath.pow(d, i), EXACT); + // if the second argument is finite and not an integer, then the result is NaN. + else assertEquals(Double.NaN, AccurateMath.pow(d, i), EXACT); + } + } + } + } + // If both arguments are integers, then the result is exactly equal to the mathematical result of raising the first argument to the power + // of the second argument if that result can in fact be represented exactly as a double value. + final int TOO_BIG_TO_CALCULATE = 18; // This value is empirical: 2^18 > 200.000 resulting bits after raising d to power i. + for (double d : DOUBLES) { + if (d % 1.0 == 0.0) { + boolean dNegative = Double.doubleToRawLongBits( d ) < 0L; + for (double i : DOUBLES) { + if (i % 1.0 == 0.0) { + BigInteger bd = BigDecimal.valueOf(d).toBigInteger().abs(); + BigInteger bi = BigDecimal.valueOf(i).toBigInteger().abs(); + double expected; + if (bd.bitLength() > 1 && bi.bitLength() > 1 && 32 - Integer.numberOfLeadingZeros(bd.bitLength()) + bi.bitLength() > TOO_BIG_TO_CALCULATE) { + // Result would be too big. + expected = i < 0.0 ? 0.0 : Double.POSITIVE_INFINITY; + } else { + BigInteger res = ArithmeticUtils.pow(bd, bi); + if (i >= 0.0) { + expected = res.doubleValue(); + } else if (res.signum() == 0) { + expected = Double.POSITIVE_INFINITY; + } else { + expected = BigDecimal.ONE.divide( new BigDecimal( res ), 1024, RoundingMode.HALF_UP ).doubleValue(); + } + } + if (dNegative && bi.testBit( 0 )) { + expected = -expected; + } + assertEquals(d + "^" + i + "=" + expected + ", Math.pow=" + Math.pow(d, i), expected, AccurateMath.pow(d, i), expected == 0.0 || Double.isInfinite(expected) || Double.isNaN(expected) ? EXACT : 2.0 * Math.ulp(expected)); + } + } + } + } + } + + @Test + public void testPowLargeIntegralDouble() { + double y = AccurateMath.scalb(1.0, 65); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(AccurateMath.nextUp(1.0), y), 1.0); + assertEquals(1.0, AccurateMath.pow(1.0, y), 1.0); + assertEquals(0.0, AccurateMath.pow(AccurateMath.nextDown(1.0), y), 1.0); + assertEquals(0.0, AccurateMath.pow(AccurateMath.nextUp(-1.0), y), 1.0); + assertEquals(1.0, AccurateMath.pow(-1.0, y), 1.0); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(AccurateMath.nextDown(-1.0), y), 1.0); + } + + @Test + public void testAtan2SpecialCases() { + + assertTrue("atan2(NaN, 0.0) should be NaN", Double.isNaN(AccurateMath.atan2(Double.NaN, 0.0))); + assertTrue("atan2(0.0, NaN) should be NaN", Double.isNaN(AccurateMath.atan2(0.0, Double.NaN))); + assertEquals("atan2(0.0, 0.0) should be 0.0", 0.0, AccurateMath.atan2(0.0, 0.0), Precision.EPSILON); + assertEquals("atan2(0.0, 0.001) should be 0.0", 0.0, AccurateMath.atan2(0.0, 0.001), Precision.EPSILON); + assertEquals("atan2(0.1, +Inf) should be 0.0", 0.0, AccurateMath.atan2(0.1, Double.POSITIVE_INFINITY), Precision.EPSILON); + assertEquals("atan2(-0.0, 0.0) should be -0.0", -0.0, AccurateMath.atan2(-0.0, 0.0), Precision.EPSILON); + assertEquals("atan2(-0.0, 0.001) should be -0.0", -0.0, AccurateMath.atan2(-0.0, 0.001), Precision.EPSILON); + assertEquals("atan2(-0.0, +Inf) should be -0.0", -0.0, AccurateMath.atan2(-0.1, Double.POSITIVE_INFINITY), Precision.EPSILON); + assertEquals("atan2(0.0, -0.0) should be PI", AccurateMath.PI, AccurateMath.atan2(0.0, -0.0), Precision.EPSILON); + assertEquals("atan2(0.1, -Inf) should be PI", AccurateMath.PI, AccurateMath.atan2(0.1, Double.NEGATIVE_INFINITY), Precision.EPSILON); + assertEquals("atan2(-0.0, -0.0) should be -PI", -AccurateMath.PI, AccurateMath.atan2(-0.0, -0.0), Precision.EPSILON); + assertEquals("atan2(0.1, -Inf) should be -PI", -AccurateMath.PI, AccurateMath.atan2(-0.1, Double.NEGATIVE_INFINITY), Precision.EPSILON); + assertEquals("atan2(0.1, 0.0) should be PI/2", AccurateMath.PI / 2.0, AccurateMath.atan2(0.1, 0.0), Precision.EPSILON); + assertEquals("atan2(0.1, -0.0) should be PI/2", AccurateMath.PI / 2.0, AccurateMath.atan2(0.1, -0.0), Precision.EPSILON); + assertEquals("atan2(Inf, 0.1) should be PI/2", AccurateMath.PI / 2.0, AccurateMath.atan2(Double.POSITIVE_INFINITY, 0.1), Precision.EPSILON); + assertEquals("atan2(Inf, -0.1) should be PI/2", AccurateMath.PI / 2.0, AccurateMath.atan2(Double.POSITIVE_INFINITY, -0.1), Precision.EPSILON); + assertEquals("atan2(-0.1, 0.0) should be -PI/2", -AccurateMath.PI / 2.0, AccurateMath.atan2(-0.1, 0.0), Precision.EPSILON); + assertEquals("atan2(-0.1, -0.0) should be -PI/2", -AccurateMath.PI / 2.0, AccurateMath.atan2(-0.1, -0.0), Precision.EPSILON); + assertEquals("atan2(-Inf, 0.1) should be -PI/2", -AccurateMath.PI / 2.0, AccurateMath.atan2(Double.NEGATIVE_INFINITY, 0.1), Precision.EPSILON); + assertEquals("atan2(-Inf, -0.1) should be -PI/2", -AccurateMath.PI / 2.0, AccurateMath.atan2(Double.NEGATIVE_INFINITY, -0.1), Precision.EPSILON); + assertEquals("atan2(Inf, Inf) should be PI/4", AccurateMath.PI / 4.0, AccurateMath.atan2(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY), + Precision.EPSILON); + assertEquals("atan2(Inf, -Inf) should be PI * 3/4", AccurateMath.PI * 3.0 / 4.0, + AccurateMath.atan2(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON); + assertEquals("atan2(-Inf, Inf) should be -PI/4", -AccurateMath.PI / 4.0, AccurateMath.atan2(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY), + Precision.EPSILON); + assertEquals("atan2(-Inf, -Inf) should be -PI * 3/4", - AccurateMath.PI * 3.0 / 4.0, + AccurateMath.atan2(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON); + } + + @Test + public void testPowAccuracy() { + double maxerrulp = 0.0; + + for (int i = 0; i < NUMBER_OF_TRIALS; i++) { + double x = (generator.nextDouble() * 2.0 + 0.25); + double y = (generator.nextDouble() * 1200.0 - 600.0) * generator.nextDouble(); + /* + * double x = AccurateMath.floor(generator.nextDouble()*1024.0 - 512.0); double + * y; if (x != 0) y = AccurateMath.floor(512.0 / AccurateMath.abs(x)); else + * y = generator.nextDouble()*1200.0; y = y - y/2; x = AccurateMath.pow(2.0, x) * + * generator.nextDouble(); y = y * generator.nextDouble(); + */ + + // double x = generator.nextDouble()*2.0; + double tst = AccurateMath.pow(x, y); + double ref = DfpMath.pow(field.newDfp(x), field.newDfp(y)).toDouble(); + double err = (tst - ref) / ref; + + if (err != 0) { + double ulp = Math.abs(ref - + Double.longBitsToDouble((Double.doubleToLongBits(ref) ^ 1))); + double errulp = field.newDfp(tst).subtract(DfpMath.pow(field.newDfp(x), field.newDfp(y))).divide(field.newDfp(ulp)).toDouble(); +// System.out.println(x + "\t" + y + "\t" + tst + "\t" + ref + "\t" + err + "\t" + errulp); + + maxerrulp = Math.max(maxerrulp, Math.abs(errulp)); + } + } + + assertTrue("pow() had errors in excess of " + MAX_ERROR_ULP + " ULP", maxerrulp < MAX_ERROR_ULP); + } + + @Test + public void testExpAccuracy() { + double maxerrulp = 0.0; + + for (int i = 0; i < NUMBER_OF_TRIALS; i++) { + /* double x = 1.0 + i/1024.0/2.0; */ + double x = ((generator.nextDouble() * 1416.0) - 708.0) * generator.nextDouble(); + // double x = (generator.nextDouble() * 20.0) - 10.0; + // double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble(); + /* double x = 3.0 / 512.0 * i - 3.0; */ + double tst = AccurateMath.exp(x); + double ref = DfpMath.exp(field.newDfp(x)).toDouble(); + double err = (tst - ref) / ref; + + if (err != 0) { + double ulp = Math.abs(ref - + Double.longBitsToDouble((Double.doubleToLongBits(ref) ^ 1))); + double errulp = field.newDfp(tst).subtract(DfpMath.exp(field.newDfp(x))).divide(field.newDfp(ulp)).toDouble(); +// System.out.println(x + "\t" + tst + "\t" + ref + "\t" + err + "\t" + errulp); + + maxerrulp = Math.max(maxerrulp, Math.abs(errulp)); + } + } + + assertTrue("exp() had errors in excess of " + MAX_ERROR_ULP + " ULP", maxerrulp < MAX_ERROR_ULP); + } + + @Test + public void testSinAccuracy() { + double maxerrulp = 0.0; + + for (int i = 0; i < NUMBER_OF_TRIALS; i++) { + /* double x = 1.0 + i/1024.0/2.0; */ + // double x = ((generator.nextDouble() * 1416.0) - 708.0) * generator.nextDouble(); + double x = ((generator.nextDouble() * Math.PI) - Math.PI / 2.0) * + Math.pow(2, 21) * generator.nextDouble(); + // double x = (generator.nextDouble() * 20.0) - 10.0; + // double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble(); + /* double x = 3.0 / 512.0 * i - 3.0; */ + double tst = AccurateMath.sin(x); + double ref = DfpMath.sin(field.newDfp(x)).toDouble(); + double err = (tst - ref) / ref; + + if (err != 0) { + double ulp = Math.abs(ref - + Double.longBitsToDouble((Double.doubleToLongBits(ref) ^ 1))); + double errulp = field.newDfp(tst).subtract(DfpMath.sin(field.newDfp(x))).divide(field.newDfp(ulp)).toDouble(); +// System.out.println(x + "\t" + tst + "\t" + ref + "\t" + err + "\t" + errulp); + + maxerrulp = Math.max(maxerrulp, Math.abs(errulp)); + } + } + + assertTrue("sin() had errors in excess of " + MAX_ERROR_ULP + " ULP", maxerrulp < MAX_ERROR_ULP); + } + + @Test + public void testCosAccuracy() { + double maxerrulp = 0.0; + + for (int i = 0; i < NUMBER_OF_TRIALS; i++) { + /* double x = 1.0 + i/1024.0/2.0; */ + // double x = ((generator.nextDouble() * 1416.0) - 708.0) * generator.nextDouble(); + double x = ((generator.nextDouble() * Math.PI) - Math.PI / 2.0) * + Math.pow(2, 21) * generator.nextDouble(); + // double x = (generator.nextDouble() * 20.0) - 10.0; + // double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble(); + /* double x = 3.0 / 512.0 * i - 3.0; */ + double tst = AccurateMath.cos(x); + double ref = DfpMath.cos(field.newDfp(x)).toDouble(); + double err = (tst - ref) / ref; + + if (err != 0) { + double ulp = Math.abs(ref - + Double.longBitsToDouble((Double.doubleToLongBits(ref) ^ 1))); + double errulp = field.newDfp(tst).subtract(DfpMath.cos(field.newDfp(x))).divide(field.newDfp(ulp)).toDouble(); +// System.out.println(x + "\t" + tst + "\t" + ref + "\t" + err + "\t" + errulp); + + maxerrulp = Math.max(maxerrulp, Math.abs(errulp)); + } + } + + assertTrue("cos() had errors in excess of " + MAX_ERROR_ULP + " ULP", maxerrulp < MAX_ERROR_ULP); + } + + @Test + public void testTanAccuracy() { + double maxerrulp = 0.0; + + for (int i = 0; i < NUMBER_OF_TRIALS; i++) { + /* double x = 1.0 + i/1024.0/2.0; */ + // double x = ((generator.nextDouble() * 1416.0) - 708.0) * generator.nextDouble(); + double x = ((generator.nextDouble() * Math.PI) - Math.PI / 2.0) * + Math.pow(2, 12) * generator.nextDouble(); + // double x = (generator.nextDouble() * 20.0) - 10.0; + // double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble(); + /* double x = 3.0 / 512.0 * i - 3.0; */ + double tst = AccurateMath.tan(x); + double ref = DfpMath.tan(field.newDfp(x)).toDouble(); + double err = (tst - ref) / ref; + + if (err != 0) { + double ulp = Math.abs(ref - + Double.longBitsToDouble((Double.doubleToLongBits(ref) ^ 1))); + double errulp = field.newDfp(tst).subtract(DfpMath.tan(field.newDfp(x))).divide(field.newDfp(ulp)).toDouble(); +// System.out.println(x + "\t" + tst + "\t" + ref + "\t" + err + "\t" + errulp); + + maxerrulp = Math.max(maxerrulp, Math.abs(errulp)); + } + } + + assertTrue("tan() had errors in excess of " + MAX_ERROR_ULP + " ULP", maxerrulp < MAX_ERROR_ULP); + } + + @Test + public void testAtanAccuracy() { + double maxerrulp = 0.0; + + for (int i = 0; i < NUMBER_OF_TRIALS; i++) { + /* double x = 1.0 + i/1024.0/2.0; */ + // double x = ((generator.nextDouble() * 1416.0) - 708.0) * generator.nextDouble(); + // double x = ((generator.nextDouble() * Math.PI) - Math.PI/2.0) * + // generator.nextDouble(); + double x = ((generator.nextDouble() * 16.0) - 8.0) * generator.nextDouble(); + + // double x = (generator.nextDouble() * 20.0) - 10.0; + // double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble(); + /* double x = 3.0 / 512.0 * i - 3.0; */ + double tst = AccurateMath.atan(x); + double ref = DfpMath.atan(field.newDfp(x)).toDouble(); + double err = (tst - ref) / ref; + + if (err != 0) { + double ulp = Math.abs(ref - + Double.longBitsToDouble((Double.doubleToLongBits(ref) ^ 1))); + double errulp = field.newDfp(tst).subtract(DfpMath.atan(field.newDfp(x))).divide(field.newDfp(ulp)).toDouble(); +// System.out.println(x + "\t" + tst + "\t" + ref + "\t" + err + "\t" + errulp); + + maxerrulp = Math.max(maxerrulp, Math.abs(errulp)); + } + } + + assertTrue("atan() had errors in excess of " + MAX_ERROR_ULP + " ULP", maxerrulp < MAX_ERROR_ULP); + } + + @Test + public void testAtan2Accuracy() { + double maxerrulp = 0.0; + + for (int i = 0; i < NUMBER_OF_TRIALS; i++) { + /* double x = 1.0 + i/1024.0/2.0; */ + // double x = ((generator.nextDouble() * 1416.0) - 708.0) * generator.nextDouble(); + double x = generator.nextDouble() - 0.5; + double y = generator.nextDouble() - 0.5; + // double x = (generator.nextDouble() * 20.0) - 10.0; + // double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble(); + /* double x = 3.0 / 512.0 * i - 3.0; */ + double tst = AccurateMath.atan2(y, x); + Dfp refdfp = DfpMath.atan(field.newDfp(y).divide(field.newDfp(x))); + /* Make adjustments for sign */ + if (x < 0.0) { + if (y > 0.0) { + refdfp = field.getPi().add(refdfp); + } else { + refdfp = refdfp.subtract(field.getPi()); + } + } + + double ref = refdfp.toDouble(); + double err = (tst - ref) / ref; + + if (err != 0) { + double ulp = Math.abs(ref - + Double.longBitsToDouble((Double.doubleToLongBits(ref) ^ 1))); + double errulp = field.newDfp(tst).subtract(refdfp).divide(field.newDfp(ulp)).toDouble(); +// System.out.println(x + "\t" + y + "\t" + tst + "\t" + ref + "\t" + errulp); + + maxerrulp = Math.max(maxerrulp, Math.abs(errulp)); + } + } + + assertTrue("atan2() had errors in excess of " + MAX_ERROR_ULP + " ULP", maxerrulp < MAX_ERROR_ULP); + } + + @Test + public void testExpm1Accuracy() { + double maxerrulp = 0.0; + + for (int i = 0; i < NUMBER_OF_TRIALS; i++) { + /* double x = 1.0 + i/1024.0/2.0; */ + // double x = (generator.nextDouble() * 20.0) - 10.0; + double x = ((generator.nextDouble() * 16.0) - 8.0) * generator.nextDouble(); + /* double x = 3.0 / 512.0 * i - 3.0; */ + double tst = AccurateMath.expm1(x); + double ref = DfpMath.exp(field.newDfp(x)).subtract(field.getOne()).toDouble(); + double err = (tst - ref) / ref; + + if (err != 0) { + double ulp = Math.abs(ref - + Double.longBitsToDouble((Double.doubleToLongBits(ref) ^ 1))); + double errulp = field.newDfp(tst).subtract(DfpMath.exp(field.newDfp(x)).subtract(field.getOne())).divide(field.newDfp(ulp)).toDouble(); +// System.out.println(x + "\t" + tst + "\t" + ref + "\t" + err + "\t" + errulp); + + maxerrulp = Math.max(maxerrulp, Math.abs(errulp)); + } + } + + assertTrue("expm1() had errors in excess of " + MAX_ERROR_ULP + " ULP", maxerrulp < MAX_ERROR_ULP); + } + + @Test + public void testAsinAccuracy() { + double maxerrulp = 0.0; + + for (int i=0; i<10000; i++) { + double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble(); + + double tst = AccurateMath.asin(x); + double ref = DfpMath.asin(field.newDfp(x)).toDouble(); + double err = (tst - ref) / ref; + + if (err != 0) { + double ulp = Math.abs(ref - Double.longBitsToDouble((Double.doubleToLongBits(ref) ^ 1))); + double errulp = field.newDfp(tst).subtract(DfpMath.asin(field.newDfp(x))).divide(field.newDfp(ulp)).toDouble(); + //System.out.println(x+"\t"+tst+"\t"+ref+"\t"+err+"\t"+errulp); + + maxerrulp = Math.max(maxerrulp, Math.abs(errulp)); + } + } + + assertTrue("asin() had errors in excess of " + MAX_ERROR_ULP + " ULP", maxerrulp < MAX_ERROR_ULP); + } + + @Test + public void testAcosAccuracy() { + double maxerrulp = 0.0; + + for (int i=0; i<10000; i++) { + double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble(); + + double tst = AccurateMath.acos(x); + double ref = DfpMath.acos(field.newDfp(x)).toDouble(); + double err = (tst - ref) / ref; + + if (err != 0) { + double ulp = Math.abs(ref - Double.longBitsToDouble((Double.doubleToLongBits(ref) ^ 1))); + double errulp = field.newDfp(tst).subtract(DfpMath.acos(field.newDfp(x))).divide(field.newDfp(ulp)).toDouble(); + //System.out.println(x+"\t"+tst+"\t"+ref+"\t"+err+"\t"+errulp); + + maxerrulp = Math.max(maxerrulp, Math.abs(errulp)); + } + } + + assertTrue("acos() had errors in excess of " + MAX_ERROR_ULP + " ULP", maxerrulp < MAX_ERROR_ULP); + } + + /** + * Added tests for a 100% coverage of acos(). + */ + @Test + public void testAcosSpecialCases() { + + assertTrue("acos(NaN) should be NaN", Double.isNaN(AccurateMath.acos(Double.NaN))); + assertTrue("acos(-1.1) should be NaN", Double.isNaN(AccurateMath.acos(-1.1))); + assertTrue("acos(-1.1) should be NaN", Double.isNaN(AccurateMath.acos(1.1))); + assertEquals("acos(-1.0) should be PI", AccurateMath.acos(-1.0), AccurateMath.PI, Precision.EPSILON); + assertEquals("acos(1.0) should be 0.0", AccurateMath.acos(1.0), 0.0, Precision.EPSILON); + assertEquals("acos(0.0) should be PI/2", AccurateMath.acos(0.0), AccurateMath.PI / 2.0, Precision.EPSILON); + } + + /** + * Added tests for a 100% coverage of asin(). + */ + @Test + public void testAsinSpecialCases() { + + assertTrue("asin(NaN) should be NaN", Double.isNaN(AccurateMath.asin(Double.NaN))); + assertTrue("asin(1.1) should be NaN", Double.isNaN(AccurateMath.asin(1.1))); + assertTrue("asin(-1.1) should be NaN", Double.isNaN(AccurateMath.asin(-1.1))); + assertEquals("asin(1.0) should be PI/2", AccurateMath.asin(1.0), AccurateMath.PI / 2.0, Precision.EPSILON); + assertEquals("asin(-1.0) should be -PI/2", AccurateMath.asin(-1.0), -AccurateMath.PI / 2.0, Precision.EPSILON); + assertEquals("asin(0.0) should be 0.0", AccurateMath.asin(0.0), 0.0, Precision.EPSILON); + } + + private Dfp cosh(Dfp x) { + return DfpMath.exp(x).add(DfpMath.exp(x.negate())).divide(2); + } + + private Dfp sinh(Dfp x) { + return DfpMath.exp(x).subtract(DfpMath.exp(x.negate())).divide(2); + } + + private Dfp tanh(Dfp x) { + return sinh(x).divide(cosh(x)); + } + + @Test + public void testSinhAccuracy() { + double maxerrulp = 0.0; + + for (int i=0; i<10000; i++) { + double x = ((generator.nextDouble() * 16.0) - 8.0) * generator.nextDouble(); + + double tst = AccurateMath.sinh(x); + double ref = sinh(field.newDfp(x)).toDouble(); + double err = (tst - ref) / ref; + + if (err != 0) { + double ulp = Math.abs(ref - Double.longBitsToDouble((Double.doubleToLongBits(ref) ^ 1))); + double errulp = field.newDfp(tst).subtract(sinh(field.newDfp(x))).divide(field.newDfp(ulp)).toDouble(); + //System.out.println(x+"\t"+tst+"\t"+ref+"\t"+err+"\t"+errulp); + maxerrulp = Math.max(maxerrulp, Math.abs(errulp)); + } + } + + assertTrue("sinh() had errors in excess of " + MAX_ERROR_ULP + " ULP", maxerrulp < MAX_ERROR_ULP); + } + + @Test + public void testCoshAccuracy() { + double maxerrulp = 0.0; + + for (int i=0; i<10000; i++) { + double x = ((generator.nextDouble() * 16.0) - 8.0) * generator.nextDouble(); + + double tst = AccurateMath.cosh(x); + double ref = cosh(field.newDfp(x)).toDouble(); + double err = (tst - ref) / ref; + + if (err != 0) { + double ulp = Math.abs(ref - Double.longBitsToDouble((Double.doubleToLongBits(ref) ^ 1))); + double errulp = field.newDfp(tst).subtract(cosh(field.newDfp(x))).divide(field.newDfp(ulp)).toDouble(); + //System.out.println(x+"\t"+tst+"\t"+ref+"\t"+err+"\t"+errulp); + maxerrulp = Math.max(maxerrulp, Math.abs(errulp)); + } + } + + assertTrue("cosh() had errors in excess of " + MAX_ERROR_ULP + " ULP", maxerrulp < MAX_ERROR_ULP); + } + + @Test + public void testTanhAccuracy() { + double maxerrulp = 0.0; + + for (int i=0; i<10000; i++) { + double x = ((generator.nextDouble() * 16.0) - 8.0) * generator.nextDouble(); + + double tst = AccurateMath.tanh(x); + double ref = tanh(field.newDfp(x)).toDouble(); + double err = (tst - ref) / ref; + + if (err != 0) { + double ulp = Math.abs(ref - Double.longBitsToDouble((Double.doubleToLongBits(ref) ^ 1))); + double errulp = field.newDfp(tst).subtract(tanh(field.newDfp(x))).divide(field.newDfp(ulp)).toDouble(); + //System.out.println(x+"\t"+tst+"\t"+ref+"\t"+err+"\t"+errulp); + maxerrulp = Math.max(maxerrulp, Math.abs(errulp)); + } + } + + assertTrue("tanh() had errors in excess of " + MAX_ERROR_ULP + " ULP", maxerrulp < MAX_ERROR_ULP); + } + + @Test + public void testCbrtAccuracy() { + double maxerrulp = 0.0; + + for (int i=0; i<10000; i++) { + double x = ((generator.nextDouble() * 200.0) - 100.0) * generator.nextDouble(); + + double tst = AccurateMath.cbrt(x); + double ref = cbrt(field.newDfp(x)).toDouble(); + double err = (tst - ref) / ref; + + if (err != 0) { + double ulp = Math.abs(ref - Double.longBitsToDouble((Double.doubleToLongBits(ref) ^ 1))); + double errulp = field.newDfp(tst).subtract(cbrt(field.newDfp(x))).divide(field.newDfp(ulp)).toDouble(); + //System.out.println(x+"\t"+tst+"\t"+ref+"\t"+err+"\t"+errulp); + maxerrulp = Math.max(maxerrulp, Math.abs(errulp)); + } + } + + assertTrue("cbrt() had errors in excess of " + MAX_ERROR_ULP + " ULP", maxerrulp < MAX_ERROR_ULP); + } + + private Dfp cbrt(Dfp x) { + boolean negative=false; + + if (x.lessThan(field.getZero())) { + negative = true; + x = x.negate(); + } + + Dfp y = DfpMath.pow(x, field.getOne().divide(3)); + + if (negative) { + y = y.negate(); + } + + return y; + } + + @Test + public void testToDegrees() { + double maxerrulp = 0.0; + for (int i = 0; i < NUMBER_OF_TRIALS; i++) { + double x = generator.nextDouble(); + double tst = field.newDfp(x).multiply(180).divide(field.getPi()).toDouble(); + double ref = AccurateMath.toDegrees(x); + double err = (tst - ref) / ref; + + if (err != 0) { + double ulp = Math.abs(ref - + Double.longBitsToDouble((Double.doubleToLongBits(ref) ^ 1))); + double errulp = field.newDfp(tst).subtract(DfpMath.exp(field.newDfp(x)).subtract(field.getOne())).divide(field.newDfp(ulp)).toDouble(); +// System.out.println(x + "\t" + tst + "\t" + ref + "\t" + err + "\t" + errulp); + + maxerrulp = Math.max(maxerrulp, Math.abs(errulp)); + } + } + assertTrue("toDegrees() had errors in excess of " + MAX_ERROR_ULP + " ULP", maxerrulp < MAX_ERROR_ULP); + } + + @Test + public void testToRadians() { + double maxerrulp = 0.0; + for (int i = 0; i < NUMBER_OF_TRIALS; i++) { + double x = generator.nextDouble(); + double tst = field.newDfp(x).multiply(field.getPi()).divide(180).toDouble(); + double ref = AccurateMath.toRadians(x); + double err = (tst - ref) / ref; + + if (err != 0) { + double ulp = Math.abs(ref - + Double.longBitsToDouble((Double.doubleToLongBits(ref) ^ 1))); + double errulp = field.newDfp(tst).subtract(DfpMath.exp(field.newDfp(x)).subtract(field.getOne())).divide(field.newDfp(ulp)).toDouble(); +// System.out.println(x + "\t" + tst + "\t" + ref + "\t" + err + "\t" + errulp); + + maxerrulp = Math.max(maxerrulp, Math.abs(errulp)); + } + } + + assertTrue("toRadians() had errors in excess of " + MAX_ERROR_ULP + " ULP", maxerrulp < MAX_ERROR_ULP); + } + + @Test + public void testNextAfter() { + // 0x402fffffffffffff 0x404123456789abcd -> 4030000000000000 + assertEquals(16.0, AccurateMath.nextUp(15.999999999999998), 0.0); + + // 0xc02fffffffffffff 0x404123456789abcd -> c02ffffffffffffe + assertEquals(-15.999999999999996, AccurateMath.nextAfter(-15.999999999999998, 34.27555555555555), 0.0); + + // 0x402fffffffffffff 0x400123456789abcd -> 402ffffffffffffe + assertEquals(15.999999999999996, AccurateMath.nextDown(15.999999999999998), 0.0); + + // 0xc02fffffffffffff 0x400123456789abcd -> c02ffffffffffffe + assertEquals(-15.999999999999996, AccurateMath.nextAfter(-15.999999999999998, 2.142222222222222), 0.0); + + // 0x4020000000000000 0x404123456789abcd -> 4020000000000001 + assertEquals(8.000000000000002, AccurateMath.nextAfter(8.0, 34.27555555555555), 0.0); + + // 0xc020000000000000 0x404123456789abcd -> c01fffffffffffff + assertEquals(-7.999999999999999, AccurateMath.nextAfter(-8.0, 34.27555555555555), 0.0); + + // 0x4020000000000000 0x400123456789abcd -> 401fffffffffffff + assertEquals(7.999999999999999, AccurateMath.nextAfter(8.0, 2.142222222222222), 0.0); + + // 0xc020000000000000 0x400123456789abcd -> c01fffffffffffff + assertEquals(-7.999999999999999, AccurateMath.nextAfter(-8.0, 2.142222222222222), 0.0); + + // 0x3f2e43753d36a223 0x3f2e43753d36a224 -> 3f2e43753d36a224 + assertEquals(2.308922399667661E-4, AccurateMath.nextAfter(2.3089223996676606E-4, 2.308922399667661E-4), 0.0); + + // 0x3f2e43753d36a223 0x3f2e43753d36a223 -> 3f2e43753d36a223 + assertEquals(2.3089223996676606E-4, AccurateMath.nextAfter(2.3089223996676606E-4, 2.3089223996676606E-4), 0.0); + + // 0x3f2e43753d36a223 0x3f2e43753d36a222 -> 3f2e43753d36a222 + assertEquals(2.3089223996676603E-4, AccurateMath.nextAfter(2.3089223996676606E-4, 2.3089223996676603E-4), 0.0); + + // 0x3f2e43753d36a223 0xbf2e43753d36a224 -> 3f2e43753d36a222 + assertEquals(2.3089223996676603E-4, AccurateMath.nextAfter(2.3089223996676606E-4, -2.308922399667661E-4), 0.0); + + // 0x3f2e43753d36a223 0xbf2e43753d36a223 -> 3f2e43753d36a222 + assertEquals(2.3089223996676603E-4, AccurateMath.nextAfter(2.3089223996676606E-4, -2.3089223996676606E-4), 0.0); + + // 0x3f2e43753d36a223 0xbf2e43753d36a222 -> 3f2e43753d36a222 + assertEquals(2.3089223996676603E-4, AccurateMath.nextAfter(2.3089223996676606E-4, -2.3089223996676603E-4), 0.0); + + // 0xbf2e43753d36a223 0x3f2e43753d36a224 -> bf2e43753d36a222 + assertEquals(-2.3089223996676603E-4, AccurateMath.nextAfter(-2.3089223996676606E-4, 2.308922399667661E-4), 0.0); + + // 0xbf2e43753d36a223 0x3f2e43753d36a223 -> bf2e43753d36a222 + assertEquals(-2.3089223996676603E-4, AccurateMath.nextAfter(-2.3089223996676606E-4, 2.3089223996676606E-4), 0.0); + + // 0xbf2e43753d36a223 0x3f2e43753d36a222 -> bf2e43753d36a222 + assertEquals(-2.3089223996676603E-4, AccurateMath.nextAfter(-2.3089223996676606E-4, 2.3089223996676603E-4), 0.0); + + // 0xbf2e43753d36a223 0xbf2e43753d36a224 -> bf2e43753d36a224 + assertEquals(-2.308922399667661E-4, AccurateMath.nextAfter(-2.3089223996676606E-4, -2.308922399667661E-4), 0.0); + + // 0xbf2e43753d36a223 0xbf2e43753d36a223 -> bf2e43753d36a223 + assertEquals(-2.3089223996676606E-4, AccurateMath.nextAfter(-2.3089223996676606E-4, -2.3089223996676606E-4), 0.0); + + // 0xbf2e43753d36a223 0xbf2e43753d36a222 -> bf2e43753d36a222 + assertEquals(-2.3089223996676603E-4, AccurateMath.nextAfter(-2.3089223996676606E-4, -2.3089223996676603E-4), 0.0); + + } + + @Test + public void testDoubleNextAfterSpecialCases() { + assertEquals(-Double.MAX_VALUE,AccurateMath.nextAfter(Double.NEGATIVE_INFINITY, 0D), 0D); + assertEquals(Double.MAX_VALUE,AccurateMath.nextAfter(Double.POSITIVE_INFINITY, 0D), 0D); + assertEquals(Double.NaN,AccurateMath.nextAfter(Double.NaN, 0D), 0D); + assertEquals(Double.POSITIVE_INFINITY,AccurateMath.nextAfter(Double.MAX_VALUE, Double.POSITIVE_INFINITY), 0D); + assertEquals(Double.NEGATIVE_INFINITY,AccurateMath.nextAfter(-Double.MAX_VALUE, Double.NEGATIVE_INFINITY), 0D); + assertEquals(Double.MIN_VALUE, AccurateMath.nextAfter(0D, 1D), 0D); + assertEquals(-Double.MIN_VALUE, AccurateMath.nextAfter(0D, -1D), 0D); + assertEquals(0D, AccurateMath.nextAfter(Double.MIN_VALUE, -1), 0D); + assertEquals(0D, AccurateMath.nextAfter(-Double.MIN_VALUE, 1), 0D); + } + + @Test + public void testFloatNextAfterSpecialCases() { + assertEquals(-Float.MAX_VALUE, AccurateMath.nextAfter(Float.NEGATIVE_INFINITY, 0F), 0F); + assertEquals(Float.MAX_VALUE, AccurateMath.nextAfter(Float.POSITIVE_INFINITY, 0F), 0F); + assertEquals(Float.NaN, AccurateMath.nextAfter(Float.NaN, 0F), 0F); + assertEquals(Float.POSITIVE_INFINITY, AccurateMath.nextUp(Float.MAX_VALUE), 0F); + assertEquals(Float.NEGATIVE_INFINITY, AccurateMath.nextDown(-Float.MAX_VALUE), 0F); + assertEquals(Float.MIN_VALUE, AccurateMath.nextAfter(0F, 1F), 0F); + assertEquals(-Float.MIN_VALUE, AccurateMath.nextAfter(0F, -1F), 0F); + assertEquals(0F, AccurateMath.nextAfter(Float.MIN_VALUE, -1F), 0F); + assertEquals(0F, AccurateMath.nextAfter(-Float.MIN_VALUE, 1F), 0F); + } + + @Test + public void testDoubleScalbSpecialCases() { + assertEquals(2.5269841324701218E-175, AccurateMath.scalb(2.2250738585072014E-308, 442), 0D); + assertEquals(1.307993905256674E297, AccurateMath.scalb(1.1102230246251565E-16, 1040), 0D); + assertEquals(7.2520887996488946E-217, AccurateMath.scalb(Double.MIN_VALUE, 356), 0D); + assertEquals(8.98846567431158E307, AccurateMath.scalb(Double.MIN_VALUE, 2097), 0D); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.scalb(Double.MIN_VALUE, 2098), 0D); + assertEquals(1.1125369292536007E-308, AccurateMath.scalb(2.225073858507201E-308, -1), 0D); + assertEquals(1.0E-323, AccurateMath.scalb(Double.MAX_VALUE, -2097), 0D); + assertEquals(Double.MIN_VALUE, AccurateMath.scalb(Double.MAX_VALUE, -2098), 0D); + assertEquals(0, AccurateMath.scalb(Double.MAX_VALUE, -2099), 0D); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.scalb(Double.POSITIVE_INFINITY, -1000000), 0D); + assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-1.1102230246251565E-16, 1078), 0D); + assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-1.1102230246251565E-16, 1079), 0D); + assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-2.2250738585072014E-308, 2047), 0D); + assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-2.2250738585072014E-308, 2048), 0D); + assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-1.7976931348623157E308, 2147483647), 0D); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.scalb( 1.7976931348623157E308, 2147483647), 0D); + assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-1.1102230246251565E-16, 2147483647), 0D); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.scalb( 1.1102230246251565E-16, 2147483647), 0D); + assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-2.2250738585072014E-308, 2147483647), 0D); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.scalb( 2.2250738585072014E-308, 2147483647), 0D); + } + + @Test + public void testFloatScalbSpecialCases() { + assertEquals(0f, AccurateMath.scalb(Float.MIN_VALUE, -30), 0F); + assertEquals(2 * Float.MIN_VALUE, AccurateMath.scalb(Float.MIN_VALUE, 1), 0F); + assertEquals(7.555786e22f, AccurateMath.scalb(Float.MAX_VALUE, -52), 0F); + assertEquals(1.7014118e38f, AccurateMath.scalb(Float.MIN_VALUE, 276), 0F); + assertEquals(Float.POSITIVE_INFINITY, AccurateMath.scalb(Float.MIN_VALUE, 277), 0F); + assertEquals(5.8774718e-39f, AccurateMath.scalb(1.1754944e-38f, -1), 0F); + assertEquals(2 * Float.MIN_VALUE, AccurateMath.scalb(Float.MAX_VALUE, -276), 0F); + assertEquals(Float.MIN_VALUE, AccurateMath.scalb(Float.MAX_VALUE, -277), 0F); + assertEquals(0, AccurateMath.scalb(Float.MAX_VALUE, -278), 0F); + assertEquals(Float.POSITIVE_INFINITY, AccurateMath.scalb(Float.POSITIVE_INFINITY, -1000000), 0F); + assertEquals(-3.13994498e38f, AccurateMath.scalb(-1.1e-7f, 151), 0F); + assertEquals(Float.NEGATIVE_INFINITY, AccurateMath.scalb(-1.1e-7f, 152), 0F); + assertEquals(Float.POSITIVE_INFINITY, AccurateMath.scalb(3.4028235E38f, 2147483647), 0F); + assertEquals(Float.NEGATIVE_INFINITY, AccurateMath.scalb(-3.4028235E38f, 2147483647), 0F); + } + + private boolean compareClassMethods(Class class1, Class class2){ + boolean allfound = true; + for(Method method1 : class1.getDeclaredMethods()){ + if (Modifier.isPublic(method1.getModifiers())){ + Type []params = method1.getGenericParameterTypes(); + try { + class2.getDeclaredMethod(method1.getName(), (Class[]) params); + } catch (NoSuchMethodException e) { + allfound = false; + System.out.println(class2.getSimpleName()+" does not implement: "+method1); + } + } + } + return allfound; + } + + @Test + public void checkMissingAccurateMathClasses() { + boolean ok = compareClassMethods(StrictMath.class, AccurateMath.class); + assertTrue("AccurateMath should implement all StrictMath methods", ok); + } + + @Ignore + @Test + public void checkExtraAccurateMathClasses() { + compareClassMethods(AccurateMath.class, StrictMath.class); + } + + @Test + public void testSignumDouble() { + final double delta = 0.0; + assertEquals(1.0, AccurateMath.signum(2.0), delta); + assertEquals(0.0, AccurateMath.signum(0.0), delta); + assertEquals(-1.0, AccurateMath.signum(-2.0), delta); + Assert.assertTrue(Double.isNaN(AccurateMath.signum(Double.NaN))); + } + + @Test + public void testSignumFloat() { + final float delta = 0.0F; + assertEquals(1.0F, AccurateMath.signum(2.0F), delta); + assertEquals(0.0F, AccurateMath.signum(0.0F), delta); + assertEquals(-1.0F, AccurateMath.signum(-2.0F), delta); + Assert.assertTrue(Double.isNaN(AccurateMath.signum(Float.NaN))); + } + + @Test + public void testLogWithBase() { + assertEquals(2.0, AccurateMath.log(2, 4), 0); + assertEquals(3.0, AccurateMath.log(2, 8), 0); + assertTrue(Double.isNaN(AccurateMath.log(-1, 1))); + assertTrue(Double.isNaN(AccurateMath.log(1, -1))); + assertTrue(Double.isNaN(AccurateMath.log(0, 0))); + assertEquals(0, AccurateMath.log(0, 10), 0); + assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.log(10, 0), 0); + } + + @Test + public void testIndicatorDouble() { + double delta = 0.0; + assertEquals(1.0, AccurateMath.copySign(1d, 2.0), delta); + assertEquals(1.0, AccurateMath.copySign(1d, 0.0), delta); + assertEquals(-1.0, AccurateMath.copySign(1d, -0.0), delta); + assertEquals(1.0, AccurateMath.copySign(1d, Double.POSITIVE_INFINITY), delta); + assertEquals(-1.0, AccurateMath.copySign(1d, Double.NEGATIVE_INFINITY), delta); + assertEquals(1.0, AccurateMath.copySign(1d, Double.NaN), delta); + assertEquals(-1.0, AccurateMath.copySign(1d, -2.0), delta); + } + + @Test + public void testIndicatorFloat() { + float delta = 0.0F; + assertEquals(1.0F, AccurateMath.copySign(1d, 2.0F), delta); + assertEquals(1.0F, AccurateMath.copySign(1d, 0.0F), delta); + assertEquals(-1.0F, AccurateMath.copySign(1d, -0.0F), delta); + assertEquals(1.0F, AccurateMath.copySign(1d, Float.POSITIVE_INFINITY), delta); + assertEquals(-1.0F, AccurateMath.copySign(1d, Float.NEGATIVE_INFINITY), delta); + assertEquals(1.0F, AccurateMath.copySign(1d, Float.NaN), delta); + assertEquals(-1.0F, AccurateMath.copySign(1d, -2.0F), delta); + } + + @Test + public void testIntPow() { + final int maxExp = 300; + DfpField field = new DfpField(40); + final double base = 1.23456789; + Dfp baseDfp = field.newDfp(base); + Dfp dfpPower = field.getOne(); + for (int i = 0; i < maxExp; i++) { + assertEquals("exp=" + i, dfpPower.toDouble(), AccurateMath.pow(base, i), + 0.6 * AccurateMath.ulp(dfpPower.toDouble())); + dfpPower = dfpPower.multiply(baseDfp); + } + } + + @Test + public void testIntPowHuge() { + assertTrue(Double.isInfinite(AccurateMath.pow(AccurateMath.scalb(1.0, 500), 4))); + } + + @Test(timeout=5000L) // This test must finish in finite time. + public void testIntPowLongMinValue() { + assertEquals(1.0, AccurateMath.pow(1.0, Long.MIN_VALUE), -1.0); + } + + @Test(timeout=5000L) + public void testIntPowSpecialCases() { + final double EXACT = -1.0; + final double DOUBLES[] = new double[] + { + Double.NEGATIVE_INFINITY, -0.0, Double.NaN, 0.0, Double.POSITIVE_INFINITY, + Long.MIN_VALUE, Integer.MIN_VALUE, Short.MIN_VALUE, Byte.MIN_VALUE, + -(double)Long.MIN_VALUE, -(double)Integer.MIN_VALUE, -(double)Short.MIN_VALUE, -(double)Byte.MIN_VALUE, + Byte.MAX_VALUE, Short.MAX_VALUE, Integer.MAX_VALUE, Long.MAX_VALUE, + -Byte.MAX_VALUE, -Short.MAX_VALUE, -Integer.MAX_VALUE, -Long.MAX_VALUE, + Float.MAX_VALUE, Double.MAX_VALUE, Double.MIN_VALUE, Float.MIN_VALUE, + -Float.MAX_VALUE, -Double.MAX_VALUE, -Double.MIN_VALUE, -Float.MIN_VALUE, + 0.5, 0.1, 0.2, 0.8, 1.1, 1.2, 1.5, 1.8, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 1.3, 2.2, 2.5, 2.8, 33.0, 33.1, 33.5, 33.8, 10.0, 300.0, 400.0, 500.0, + -0.5, -0.1, -0.2, -0.8, -1.1, -1.2, -1.5, -1.8, -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -1.3, -2.2, -2.5, -2.8, -33.0, -33.1, -33.5, -33.8, -10.0, -300.0, -400.0, -500.0 + }; + + final long INTS[] = new long[]{Long.MAX_VALUE, Long.MAX_VALUE - 1, Long.MIN_VALUE, Long.MIN_VALUE + 1, Long.MIN_VALUE + 2, Integer.MAX_VALUE, Integer.MAX_VALUE - 1, Integer.MIN_VALUE, Integer.MIN_VALUE + 1, Integer.MIN_VALUE + 2, 0, 1, 2, 3, 5, 8, 10, 20, 100, 300, 500, -1, -2, -3, -5, -8, -10, -20, -100, -300, -500}; + // Special cases from Math.pow javadoc: + // If the second argument is positive or negative zero, then the result is 1.0. + for (double d : DOUBLES) { + assertEquals(1.0, AccurateMath.pow(d, 0L), EXACT); + } + // If the second argument is 1.0, then the result is the same as the first argument. + for (double d : DOUBLES) { + assertEquals(d, AccurateMath.pow(d, 1L), EXACT); + } + // If the second argument is NaN, then the result is NaN. <- Impossible with int. + // If the first argument is NaN and the second argument is nonzero, then the result is NaN. + for (long i : INTS) { + if (i != 0L) { + assertEquals(Double.NaN, AccurateMath.pow(Double.NaN, i), EXACT); + } + } + // If the absolute value of the first argument is greater than 1 and the second argument is positive infinity, or + // the absolute value of the first argument is less than 1 and the second argument is negative infinity, then the result is positive infinity. + for (double d : DOUBLES) { + if (Math.abs(d) > 1.0) { + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(d, Long.MAX_VALUE - 1L), EXACT); + } + } + for (double d : DOUBLES) { + if (Math.abs(d) < 1.0) { + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(d, Long.MIN_VALUE), EXACT); + } + } + // Note: Long.MAX_VALUE isn't actually an infinity, so its parity affects the sign of resulting infinity. + for (double d : DOUBLES) { + if (Math.abs(d) > 1.0) { + assertTrue(Double.isInfinite(AccurateMath.pow(d, Long.MAX_VALUE))); + } + } + for (double d : DOUBLES) { + if (Math.abs(d) < 1.0) { + assertTrue(Double.isInfinite(AccurateMath.pow(d, Long.MIN_VALUE + 1L))); + } + } + // If the absolute value of the first argument is greater than 1 and the second argument is negative infinity, or + // the absolute value of the first argument is less than 1 and the second argument is positive infinity, then the result is positive zero. + for (double d : DOUBLES) { + if (Math.abs(d) > 1.0) { + assertEquals(0.0, AccurateMath.pow(d, Long.MIN_VALUE), EXACT); + } + } + for (double d : DOUBLES) { + if (Math.abs(d) < 1.0) { + assertEquals(0.0, AccurateMath.pow(d, Long.MAX_VALUE - 1L), EXACT); + } + } + // Note: Long.MAX_VALUE isn't actually an infinity, so its parity affects the sign of resulting zero. + for (double d : DOUBLES) { + if (Math.abs(d) > 1.0) { + assertTrue(AccurateMath.pow(d, Long.MIN_VALUE + 1L) == 0.0); + } + } + for (double d : DOUBLES) { + if (Math.abs(d) < 1.0) { + assertTrue(AccurateMath.pow(d, Long.MAX_VALUE) == 0.0); + } + } + // If the absolute value of the first argument equals 1 and the second argument is infinite, then the result is NaN. <- Impossible with int. + // If the first argument is positive zero and the second argument is greater than zero, or + // the first argument is positive infinity and the second argument is less than zero, then the result is positive zero. + for (long i : INTS) { + if (i > 0L) { + assertEquals(0.0, AccurateMath.pow(0.0, i), EXACT); + } + } + for (long i : INTS) { + if (i < 0L) { + assertEquals(0.0, AccurateMath.pow(Double.POSITIVE_INFINITY, i), EXACT); + } + } + // If the first argument is positive zero and the second argument is less than zero, or + // the first argument is positive infinity and the second argument is greater than zero, then the result is positive infinity. + for (long i : INTS) { + if (i < 0L) { + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(0.0, i), EXACT); + } + } + for (long i : INTS) { + if (i > 0L) { + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(Double.POSITIVE_INFINITY, i), EXACT); + } + } + // If the first argument is negative zero and the second argument is greater than zero but not a finite odd integer, or + // the first argument is negative infinity and the second argument is less than zero but not a finite odd integer, then the result is positive zero. + for (long i : INTS) { + if (i > 0L && (i & 1L) == 0L) { + assertEquals(0.0, AccurateMath.pow(-0.0, i), EXACT); + } + } + for (long i : INTS) { + if (i < 0L && (i & 1L) == 0L) { + assertEquals(0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT); + } + } + // If the first argument is negative zero and the second argument is a positive finite odd integer, or + // the first argument is negative infinity and the second argument is a negative finite odd integer, then the result is negative zero. + for (long i : INTS) { + if (i > 0L && (i & 1L) == 1L) { + assertEquals(-0.0, AccurateMath.pow(-0.0, i), EXACT); + } + } + for (long i : INTS) { + if (i < 0L && (i & 1L) == 1L) { + assertEquals(-0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT); + } + } + // If the first argument is negative zero and the second argument is less than zero but not a finite odd integer, or + // the first argument is negative infinity and the second argument is greater than zero but not a finite odd integer, then the result is positive infinity. + for (long i : INTS) { + if (i > 0L && (i & 1L) == 0L) { + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT); + } + } + for (long i : INTS) { + if (i < 0L && (i & 1L) == 0L) { + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(-0.0, i), EXACT); + } + } + // If the first argument is negative zero and the second argument is a negative finite odd integer, or + // the first argument is negative infinity and the second argument is a positive finite odd integer, then the result is negative infinity. + for (long i : INTS) { + if (i > 0L && (i & 1L) == 1L) { + assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT); + } + } + for (long i : INTS) { + if (i < 0L && (i & 1L) == 1L) { + assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.pow(-0.0, i), EXACT); + } + } + for (double d : DOUBLES) { + // If the first argument is finite and less than zero + if (d < 0.0 && Math.abs(d) <= Double.MAX_VALUE) { + for (long i : INTS) { + // if the second argument is a finite even integer, the result is equal to the result of raising the absolute value of the first argument to the power of the second argument + if ((i & 1L) == 0L) assertEquals(AccurateMath.pow(-d, i), AccurateMath.pow(d, i), EXACT); + // if the second argument is a finite odd integer, the result is equal to the negative of the result of raising the absolute value of the first argument to the power of the second argument + else assertEquals(-AccurateMath.pow(-d, i), AccurateMath.pow(d, i), EXACT); + // if the second argument is finite and not an integer, then the result is NaN. <- Impossible with int. + } + } + } + // If both arguments are integers, then the result is exactly equal to the mathematical result of raising the first argument to the power + // of the second argument if that result can in fact be represented exactly as a double value. <- Other tests. + } + + @Test + public void testIncrementExactInt() { + int[] specialValues = new int[] { + Integer.MIN_VALUE, Integer.MIN_VALUE + 1, Integer.MIN_VALUE + 2, + Integer.MAX_VALUE, Integer.MAX_VALUE - 1, Integer.MAX_VALUE - 2, + -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + -1 - (Integer.MIN_VALUE / 2), 0 - (Integer.MIN_VALUE / 2), 1 - (Integer.MIN_VALUE / 2), + -1 + (Integer.MAX_VALUE / 2), 0 + (Integer.MAX_VALUE / 2), 1 + (Integer.MAX_VALUE / 2), + }; + for (int a : specialValues) { + BigInteger bdA = BigInteger.valueOf(a); + BigInteger bdSum = bdA.add(BigInteger.ONE); + if (bdSum.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0 || + bdSum.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) { + try { + AccurateMath.incrementExact(a); + Assert.fail("an exception should have been thrown"); + } catch (MathArithmeticException mae) { + // expected + } + } else { + assertEquals(bdSum, BigInteger.valueOf(AccurateMath.incrementExact(a))); + } + } + } + + @Test + public void testDecrementExactInt() { + int[] specialValues = new int[] { + Integer.MIN_VALUE, Integer.MIN_VALUE + 1, Integer.MIN_VALUE + 2, + Integer.MAX_VALUE, Integer.MAX_VALUE - 1, Integer.MAX_VALUE - 2, + -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + -1 - (Integer.MIN_VALUE / 2), 0 - (Integer.MIN_VALUE / 2), 1 - (Integer.MIN_VALUE / 2), + -1 + (Integer.MAX_VALUE / 2), 0 + (Integer.MAX_VALUE / 2), 1 + (Integer.MAX_VALUE / 2), + }; + for (int a : specialValues) { + BigInteger bdA = BigInteger.valueOf(a); + BigInteger bdSub = bdA.subtract(BigInteger.ONE); + if (bdSub.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0 || + bdSub.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) { + try { + AccurateMath.decrementExact(a); + fail("an exception should have been thrown"); + } catch (MathArithmeticException mae) { + // expected + } + } else { + assertEquals(bdSub, BigInteger.valueOf(AccurateMath.decrementExact(a))); + } + } + } + + @Test + public void testAddExactInt() { + int[] specialValues = new int[] { + Integer.MIN_VALUE, Integer.MIN_VALUE + 1, Integer.MIN_VALUE + 2, + Integer.MAX_VALUE, Integer.MAX_VALUE - 1, Integer.MAX_VALUE - 2, + -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + -1 - (Integer.MIN_VALUE / 2), 0 - (Integer.MIN_VALUE / 2), 1 - (Integer.MIN_VALUE / 2), + -1 + (Integer.MAX_VALUE / 2), 0 + (Integer.MAX_VALUE / 2), 1 + (Integer.MAX_VALUE / 2), + }; + for (int a : specialValues) { + for (int b : specialValues) { + BigInteger bdA = BigInteger.valueOf(a); + BigInteger bdB = BigInteger.valueOf(b); + BigInteger bdSum = bdA.add(bdB); + if (bdSum.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0 || + bdSum.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) { + try { + AccurateMath.addExact(a, b); + fail("an exception should have been thrown"); + } catch (MathArithmeticException mae) { + // expected + } + } else { + assertEquals(bdSum, BigInteger.valueOf(AccurateMath.addExact(a, b))); + } + } + } + } + + @Test + public void testAddExactLong() { + long[] specialValues = new long[] { + Long.MIN_VALUE, Long.MIN_VALUE + 1, Long.MIN_VALUE + 2, + Long.MAX_VALUE, Long.MAX_VALUE - 1, Long.MAX_VALUE - 2, + -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + -1 - (Long.MIN_VALUE / 2), 0 - (Long.MIN_VALUE / 2), 1 - (Long.MIN_VALUE / 2), + -1 + (Long.MAX_VALUE / 2), 0 + (Long.MAX_VALUE / 2), 1 + (Long.MAX_VALUE / 2), + }; + for (long a : specialValues) { + for (long b : specialValues) { + BigInteger bdA = BigInteger.valueOf(a); + BigInteger bdB = BigInteger.valueOf(b); + BigInteger bdSum = bdA.add(bdB); + if (bdSum.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < 0 || + bdSum.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) { + try { + AccurateMath.addExact(a, b); + fail("an exception should have been thrown"); + } catch (MathArithmeticException mae) { + // expected + } + } else { + assertEquals(bdSum, BigInteger.valueOf(AccurateMath.addExact(a, b))); + } + } + } + } + + @Test + public void testSubtractExactInt() { + int[] specialValues = new int[] { + Integer.MIN_VALUE, Integer.MIN_VALUE + 1, Integer.MIN_VALUE + 2, + Integer.MAX_VALUE, Integer.MAX_VALUE - 1, Integer.MAX_VALUE - 2, + -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + -1 - (Integer.MIN_VALUE / 2), 0 - (Integer.MIN_VALUE / 2), 1 - (Integer.MIN_VALUE / 2), + -1 + (Integer.MAX_VALUE / 2), 0 + (Integer.MAX_VALUE / 2), 1 + (Integer.MAX_VALUE / 2), + }; + for (int a : specialValues) { + for (int b : specialValues) { + BigInteger bdA = BigInteger.valueOf(a); + BigInteger bdB = BigInteger.valueOf(b); + BigInteger bdSub = bdA.subtract(bdB); + if (bdSub.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0 || + bdSub.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) { + try { + AccurateMath.subtractExact(a, b); + fail("an exception should have been thrown"); + } catch (MathArithmeticException mae) { + // expected + } + } else { + assertEquals(bdSub, BigInteger.valueOf(AccurateMath.subtractExact(a, b))); + } + } + } + } + + @Test + public void testSubtractExactLong() { + long[] specialValues = new long[] { + Long.MIN_VALUE, Long.MIN_VALUE + 1, Long.MIN_VALUE + 2, + Long.MAX_VALUE, Long.MAX_VALUE - 1, Long.MAX_VALUE - 2, + -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + -1 - (Long.MIN_VALUE / 2), 0 - (Long.MIN_VALUE / 2), 1 - (Long.MIN_VALUE / 2), + -1 + (Long.MAX_VALUE / 2), 0 + (Long.MAX_VALUE / 2), 1 + (Long.MAX_VALUE / 2), + }; + for (long a : specialValues) { + for (long b : specialValues) { + BigInteger bdA = BigInteger.valueOf(a); + BigInteger bdB = BigInteger.valueOf(b); + BigInteger bdSub = bdA.subtract(bdB); + if (bdSub.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < 0 || + bdSub.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) { + try { + AccurateMath.subtractExact(a, b); + fail("an exception should have been thrown"); + } catch (MathArithmeticException mae) { + // expected + } + } else { + assertEquals(bdSub, BigInteger.valueOf(AccurateMath.subtractExact(a, b))); + } + } + } + } + + @Test + public void testMultiplyExactInt() { + int[] specialValues = new int[] { + Integer.MIN_VALUE, Integer.MIN_VALUE + 1, Integer.MIN_VALUE + 2, + Integer.MAX_VALUE, Integer.MAX_VALUE - 1, Integer.MAX_VALUE - 2, + -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + -1 - (Integer.MIN_VALUE / 2), 0 - (Integer.MIN_VALUE / 2), 1 - (Integer.MIN_VALUE / 2), + -1 + (Integer.MAX_VALUE / 2), 0 + (Integer.MAX_VALUE / 2), 1 + (Integer.MAX_VALUE / 2), + }; + for (int a : specialValues) { + for (int b : specialValues) { + BigInteger bdA = BigInteger.valueOf(a); + BigInteger bdB = BigInteger.valueOf(b); + BigInteger bdMul = bdA.multiply(bdB); + if (bdMul.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0 || + bdMul.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) { + try { + AccurateMath.multiplyExact(a, b); + fail("an exception should have been thrown " + a + b); + } catch (MathArithmeticException mae) { + // expected + } + } else { + assertEquals(bdMul, BigInteger.valueOf(AccurateMath.multiplyExact(a, b))); + } + } + } + } + + @Test + public void testMultiplyExactLong() { + long[] specialValues = new long[] { + Long.MIN_VALUE, Long.MIN_VALUE + 1, Long.MIN_VALUE + 2, + Long.MAX_VALUE, Long.MAX_VALUE - 1, Long.MAX_VALUE - 2, + -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + -1 - (Long.MIN_VALUE / 2), 0 - (Long.MIN_VALUE / 2), 1 - (Long.MIN_VALUE / 2), + -1 + (Long.MAX_VALUE / 2), 0 + (Long.MAX_VALUE / 2), 1 + (Long.MAX_VALUE / 2), + }; + for (long a : specialValues) { + for (long b : specialValues) { + BigInteger bdA = BigInteger.valueOf(a); + BigInteger bdB = BigInteger.valueOf(b); + BigInteger bdMul = bdA.multiply(bdB); + if (bdMul.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < 0 || + bdMul.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) { + try { + AccurateMath.multiplyExact(a, b); + fail("an exception should have been thrown " + a + b); + } catch (MathArithmeticException mae) { + // expected + } + } else { + assertEquals(bdMul, BigInteger.valueOf(AccurateMath.multiplyExact(a, b))); + } + } + } + } + + @Test(expected=MathArithmeticException.class) + public void testToIntExactTooLow() { + AccurateMath.toIntExact(-1l + Integer.MIN_VALUE); + } + + @Test(expected=MathArithmeticException.class) + public void testToIntExactTooHigh() { + AccurateMath.toIntExact(+1l + Integer.MAX_VALUE); + } + + @Test + public void testToIntExact() { + for (int n = -1000; n < 1000; ++n) { + assertEquals(n, AccurateMath.toIntExact(0l + n)); + } + assertEquals(Integer.MIN_VALUE, AccurateMath.toIntExact(0l + Integer.MIN_VALUE)); + assertEquals(Integer.MAX_VALUE, AccurateMath.toIntExact(0l + Integer.MAX_VALUE)); + } + + @Test + public void testFloorDivInt() { + assertEquals(+1, AccurateMath.floorDiv(+4, +3)); + assertEquals(-2, AccurateMath.floorDiv(-4, +3)); + assertEquals(-2, AccurateMath.floorDiv(+4, -3)); + assertEquals(+1, AccurateMath.floorDiv(-4, -3)); + try { + AccurateMath.floorDiv(1, 0); + fail("an exception should have been thrown"); + } catch (MathArithmeticException mae) { + // expected + } + for (int a = -100; a <= 100; ++a) { + for (int b = -100; b <= 100; ++b) { + if (b != 0) { + assertEquals(poorManFloorDiv(a, b), AccurateMath.floorDiv(a, b)); + } + } + } + } + + @Test + public void testFloorModInt() { + assertEquals(+1, AccurateMath.floorMod(+4, +3)); + assertEquals(+2, AccurateMath.floorMod(-4, +3)); + assertEquals(-2, AccurateMath.floorMod(+4, -3)); + assertEquals(-1, AccurateMath.floorMod(-4, -3)); + try { + AccurateMath.floorMod(1, 0); + fail("an exception should have been thrown"); + } catch (MathArithmeticException mae) { + // expected + } + for (int a = -100; a <= 100; ++a) { + for (int b = -100; b <= 100; ++b) { + if (b != 0) { + assertEquals(poorManFloorMod(a, b), AccurateMath.floorMod(a, b)); + } + } + } + } + + @Test + public void testFloorDivModInt() { + UniformRandomProvider generator = RandomSource.create(RandomSource.WELL_1024_A, + 0x7ccab45edeaab90al); + for (int i = 0; i < 10000; ++i) { + int a = generator.nextInt(); + int b = generator.nextInt(); + if (b == 0) { + try { + AccurateMath.floorDiv(a, b); + fail("an exception should have been thrown"); + } catch (MathArithmeticException mae) { + // expected + } + } else { + int d = AccurateMath.floorDiv(a, b); + int m = AccurateMath.floorMod(a, b); + assertEquals(AccurateMath.toIntExact(poorManFloorDiv(a, b)), d); + assertEquals(AccurateMath.toIntExact(poorManFloorMod(a, b)), m); + assertEquals(a, d * b + m); + if (b < 0) { + assertTrue(m <= 0); + assertTrue(-m < -b); + } else { + assertTrue(m >= 0); + assertTrue(m < b); + } + } + } + } + + @Test + public void testFloorDivLong() { + assertEquals(+1l, AccurateMath.floorDiv(+4l, +3l)); + assertEquals(-2l, AccurateMath.floorDiv(-4l, +3l)); + assertEquals(-2l, AccurateMath.floorDiv(+4l, -3l)); + assertEquals(+1l, AccurateMath.floorDiv(-4l, -3l)); + try { + AccurateMath.floorDiv(1l, 0l); + fail("an exception should have been thrown"); + } catch (MathArithmeticException mae) { + // expected + } + for (long a = -100l; a <= 100l; ++a) { + for (long b = -100l; b <= 100l; ++b) { + if (b != 0) { + assertEquals(poorManFloorDiv(a, b), AccurateMath.floorDiv(a, b)); + } + } + } + } + + @Test + public void testFloorModLong() { + assertEquals(+1l, AccurateMath.floorMod(+4l, +3l)); + assertEquals(+2l, AccurateMath.floorMod(-4l, +3l)); + assertEquals(-2l, AccurateMath.floorMod(+4l, -3l)); + assertEquals(-1l, AccurateMath.floorMod(-4l, -3l)); + try { + AccurateMath.floorMod(1l, 0l); + fail("an exception should have been thrown"); + } catch (MathArithmeticException mae) { + // expected + } + for (long a = -100l; a <= 100l; ++a) { + for (long b = -100l; b <= 100l; ++b) { + if (b != 0) { + assertEquals(poorManFloorMod(a, b), AccurateMath.floorMod(a, b)); + } + } + } + } + + @Test + public void testFloorDivModLong() { + UniformRandomProvider generator = RandomSource.create(RandomSource.WELL_1024_A, + 0xb87b9bc14c96ccd5l); + for (int i = 0; i < 10000; ++i) { + long a = generator.nextLong(); + long b = generator.nextLong(); + if (b == 0) { + try { + AccurateMath.floorDiv(a, b); + fail("an exception should have been thrown"); + } catch (MathArithmeticException mae) { + // expected + } + } else { + long d = AccurateMath.floorDiv(a, b); + long m = AccurateMath.floorMod(a, b); + assertEquals(poorManFloorDiv(a, b), d); + assertEquals(poorManFloorMod(a, b), m); + assertEquals(a, d * b + m); + if (b < 0) { + assertTrue(m <= 0); + assertTrue(-m < -b); + } else { + assertTrue(m >= 0); + assertTrue(m < b); + } + } + } + } + + private long poorManFloorDiv(long a, long b) { + + // find q0, r0 such that a = q0 b + r0 + BigInteger q0 = BigInteger.valueOf(a / b); + BigInteger r0 = BigInteger.valueOf(a % b); + BigInteger fd = BigInteger.valueOf(Integer.MIN_VALUE); + BigInteger bigB = BigInteger.valueOf(b); + + for (int k = -2; k < 2; ++k) { + // find another pair q, r such that a = q b + r + BigInteger bigK = BigInteger.valueOf(k); + BigInteger q = q0.subtract(bigK); + BigInteger r = r0.add(bigK.multiply(bigB)); + if (r.abs().compareTo(bigB.abs()) < 0 && + (r.longValue() == 0l || ((r.longValue() ^ b) & 0x8000000000000000l) == 0)) { + if (fd.compareTo(q) < 0) { + fd = q; + } + } + } + + return fd.longValue(); + + } + + private long poorManFloorMod(long a, long b) { + return a - b * poorManFloorDiv(a, b); + } + + /** + * http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6430675 + */ + @Test + public void testRoundDown() { + double x = 0x1.fffffffffffffp-2; // greatest floating point value less than 0.5 + assertTrue(x < 0.5d); + assertEquals(0, AccurateMath.round(x)); + + x = 4503599627370497.0; // x = Math.pow(2, 52) + 1; + assertEquals("4503599627370497", new BigDecimal(x).toString()); + assertTrue(x == Math.rint(x)); + assertTrue(x == AccurateMath.round(x)); + //assertTrue(x == Math.round(x)); // fails with Java 7, fixed in Java 8 + } + +} diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/FastMathTest.java b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathTest.java.bak similarity index 67% rename from commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/FastMathTest.java rename to commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathTest.java.bak index b37623996..52b58f07e 100644 --- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/FastMathTest.java +++ b/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/jdkmath/AccurateMathTest.java.bak @@ -41,7 +41,7 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Test; -public class FastMathTest { +public class AccurateMathTest { private static final double MAX_ERROR_ULP = 0.51; private static final int NUMBER_OF_TRIALS = 1000; @@ -72,19 +72,19 @@ public class FastMathTest { for (double[] pair : pairs) { assertEquals("min(" + pair[0] + ", " + pair[1] + ")", Math.min(pair[0], pair[1]), - FastMath.min(pair[0], pair[1]), + AccurateMath.min(pair[0], pair[1]), Precision.EPSILON); assertEquals("min(" + pair[1] + ", " + pair[0] + ")", Math.min(pair[1], pair[0]), - FastMath.min(pair[1], pair[0]), + AccurateMath.min(pair[1], pair[0]), Precision.EPSILON); assertEquals("max(" + pair[0] + ", " + pair[1] + ")", Math.max(pair[0], pair[1]), - FastMath.max(pair[0], pair[1]), + AccurateMath.max(pair[0], pair[1]), Precision.EPSILON); assertEquals("max(" + pair[1] + ", " + pair[0] + ")", Math.max(pair[1], pair[0]), - FastMath.max(pair[1], pair[0]), + AccurateMath.max(pair[1], pair[0]), Precision.EPSILON); } } @@ -105,62 +105,62 @@ public class FastMathTest { for (float[] pair : pairs) { assertEquals("min(" + pair[0] + ", " + pair[1] + ")", Math.min(pair[0], pair[1]), - FastMath.min(pair[0], pair[1]), + AccurateMath.min(pair[0], pair[1]), Precision.EPSILON); assertEquals("min(" + pair[1] + ", " + pair[0] + ")", Math.min(pair[1], pair[0]), - FastMath.min(pair[1], pair[0]), + AccurateMath.min(pair[1], pair[0]), Precision.EPSILON); assertEquals("max(" + pair[0] + ", " + pair[1] + ")", Math.max(pair[0], pair[1]), - FastMath.max(pair[0], pair[1]), + AccurateMath.max(pair[0], pair[1]), Precision.EPSILON); assertEquals("max(" + pair[1] + ", " + pair[0] + ")", Math.max(pair[1], pair[0]), - FastMath.max(pair[1], pair[0]), + AccurateMath.max(pair[1], pair[0]), Precision.EPSILON); } } @Test public void testConstants() { - assertEquals(Math.PI, FastMath.PI, 1.0e-20); - assertEquals(Math.E, FastMath.E, 1.0e-20); + assertEquals(Math.PI, AccurateMath.PI, 1.0e-20); + assertEquals(Math.E, AccurateMath.E, 1.0e-20); } @Test public void testAtan2() { double y1 = 1.2713504628280707e10; double x1 = -5.674940885228782e-10; - assertEquals(Math.atan2(y1, x1), FastMath.atan2(y1, x1), 2 * Precision.EPSILON); + assertEquals(Math.atan2(y1, x1), AccurateMath.atan2(y1, x1), 2 * Precision.EPSILON); double y2 = 0.0; double x2 = Double.POSITIVE_INFINITY; - assertEquals(Math.atan2(y2, x2), FastMath.atan2(y2, x2), Precision.SAFE_MIN); + assertEquals(Math.atan2(y2, x2), AccurateMath.atan2(y2, x2), Precision.SAFE_MIN); } @Test public void testHyperbolic() { double maxErr = 0; for (double x = -30; x < 30; x += 0.001) { - double tst = FastMath.sinh(x); + double tst = AccurateMath.sinh(x); double ref = Math.sinh(x); - maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref)); + maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref)); } assertEquals(0, maxErr, 2); maxErr = 0; for (double x = -30; x < 30; x += 0.001) { - double tst = FastMath.cosh(x); + double tst = AccurateMath.cosh(x); double ref = Math.cosh(x); - maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref)); + maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref)); } assertEquals(0, maxErr, 2); maxErr = 0; for (double x = -0.5; x < 0.5; x += 0.001) { - double tst = FastMath.tanh(x); + double tst = AccurateMath.tanh(x); double ref = Math.tanh(x); - maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref)); + maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref)); } assertEquals(0, maxErr, 4); @@ -171,9 +171,9 @@ public class FastMathTest { final double x = -1; final double y = (5 + 1e-15) * 1e15; assertEquals(Math.pow(x, y), - FastMath.pow(x, y), 0); + AccurateMath.pow(x, y), 0); assertEquals(Math.pow(x, -y), - FastMath.pow(x, -y), 0); + AccurateMath.pow(x, -y), 0); } @Test @@ -184,16 +184,16 @@ public class FastMathTest { double maxErr = 0; for (double x = start; x < end; x += 1e-3) { - final double tst = FastMath.cosh(x); + final double tst = AccurateMath.cosh(x); final double ref = Math.cosh(x); - maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref)); + maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref)); } assertEquals(0, maxErr, 3); for (double x = start; x < end; x += 1e-3) { - final double tst = FastMath.sinh(x); + final double tst = AccurateMath.sinh(x); final double ref = Math.sinh(x); - maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref)); + maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref)); } assertEquals(0, maxErr, 3); } @@ -206,16 +206,16 @@ public class FastMathTest { double maxErr = 0; for (double x = start; x > end; x -= 1e-3) { - final double tst = FastMath.cosh(x); + final double tst = AccurateMath.cosh(x); final double ref = Math.cosh(x); - maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref)); + maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref)); } assertEquals(0, maxErr, 3); for (double x = start; x > end; x -= 1e-3) { - final double tst = FastMath.sinh(x); + final double tst = AccurateMath.sinh(x); final double ref = Math.sinh(x); - maxErr = FastMath.max(maxErr, FastMath.abs(ref - tst) / FastMath.ulp(ref)); + maxErr = AccurateMath.max(maxErr, AccurateMath.abs(ref - tst) / AccurateMath.ulp(ref)); } assertEquals(0, maxErr, 3); } @@ -224,7 +224,7 @@ public class FastMathTest { public void testMath1269() { final double arg = 709.8125; final double vM = Math.exp(arg); - final double vFM = FastMath.exp(arg); + final double vFM = AccurateMath.exp(arg); assertTrue("exp(" + arg + ") is " + vFM + " instead of " + vM, Precision.equalsIncludingNaN(vM, vFM)); } @@ -233,19 +233,19 @@ public class FastMathTest { public void testHyperbolicInverses() { double maxErr = 0; for (double x = -30; x < 30; x += 0.01) { - maxErr = FastMath.max(maxErr, FastMath.abs(x - FastMath.sinh(FastMath.asinh(x))) / (2 * FastMath.ulp(x))); + maxErr = AccurateMath.max(maxErr, AccurateMath.abs(x - AccurateMath.sinh(AccurateMath.asinh(x))) / (2 * AccurateMath.ulp(x))); } assertEquals(0, maxErr, 3); maxErr = 0; for (double x = 1; x < 30; x += 0.01) { - maxErr = FastMath.max(maxErr, FastMath.abs(x - FastMath.cosh(FastMath.acosh(x))) / (2 * FastMath.ulp(x))); + maxErr = AccurateMath.max(maxErr, AccurateMath.abs(x - AccurateMath.cosh(AccurateMath.acosh(x))) / (2 * AccurateMath.ulp(x))); } assertEquals(0, maxErr, 2); maxErr = 0; for (double x = -1 + Precision.EPSILON; x < 1 - Precision.EPSILON; x += 0.0001) { - maxErr = FastMath.max(maxErr, FastMath.abs(x - FastMath.tanh(FastMath.atanh(x))) / (2 * FastMath.ulp(x))); + maxErr = AccurateMath.max(maxErr, AccurateMath.abs(x - AccurateMath.tanh(AccurateMath.atanh(x))) / (2 * AccurateMath.ulp(x))); } assertEquals(0, maxErr, 2); } @@ -257,7 +257,7 @@ public class FastMathTest { for (int i = 0; i < NUMBER_OF_TRIALS; i++) { double x = Math.exp(generator.nextDouble() * 1416.0 - 708.0) * generator.nextDouble(); // double x = generator.nextDouble()*2.0; - double tst = FastMath.log(x); + double tst = AccurateMath.log(x); double ref = DfpMath.log(field.newDfp(x)).toDouble(); double err = (tst - ref) / ref; @@ -281,7 +281,7 @@ public class FastMathTest { for (int i = 0; i < NUMBER_OF_TRIALS; i++) { double x = Math.exp(generator.nextDouble() * 1416.0 - 708.0) * generator.nextDouble(); // double x = generator.nextDouble()*2.0; - double tst = FastMath.log10(x); + double tst = AccurateMath.log10(x); double ref = DfpMath.log(field.newDfp(x)).divide(DfpMath.log(field.newDfp("10"))).toDouble(); double err = (tst - ref) / ref; @@ -305,7 +305,7 @@ public class FastMathTest { for (int i = 0; i < NUMBER_OF_TRIALS; i++) { double x = Math.exp(generator.nextDouble() * 10.0 - 5.0) * generator.nextDouble(); // double x = generator.nextDouble()*2.0; - double tst = FastMath.log1p(x); + double tst = AccurateMath.log1p(x); double ref = DfpMath.log(field.newDfp(x).add(field.getOne())).toDouble(); double err = (tst - ref) / ref; @@ -324,93 +324,93 @@ public class FastMathTest { @Test public void testLog1pSpecialCases() { - assertTrue("Logp of -1.0 should be -Inf", Double.isInfinite(FastMath.log1p(-1.0))); + assertTrue("Logp of -1.0 should be -Inf", Double.isInfinite(AccurateMath.log1p(-1.0))); } @Test public void testLogSpecialCases() { - assertEquals("Log of zero should be -Inf", Double.NEGATIVE_INFINITY, FastMath.log(0.0), 1.0); - assertEquals("Log of -zero should be -Inf", Double.NEGATIVE_INFINITY, FastMath.log(-0.0), 1.0); - assertTrue("Log of NaN should be NaN", Double.isNaN(FastMath.log(Double.NaN))); - assertTrue("Log of negative number should be NaN", Double.isNaN(FastMath.log(-1.0))); - assertEquals("Log of Double.MIN_VALUE should be -744.4400719213812", -744.4400719213812, FastMath.log(Double.MIN_VALUE), Precision.EPSILON); - assertEquals("Log of infinity should be infinity", Double.POSITIVE_INFINITY, FastMath.log(Double.POSITIVE_INFINITY), 1.0); + assertEquals("Log of zero should be -Inf", Double.NEGATIVE_INFINITY, AccurateMath.log(0.0), 1.0); + assertEquals("Log of -zero should be -Inf", Double.NEGATIVE_INFINITY, AccurateMath.log(-0.0), 1.0); + assertTrue("Log of NaN should be NaN", Double.isNaN(AccurateMath.log(Double.NaN))); + assertTrue("Log of negative number should be NaN", Double.isNaN(AccurateMath.log(-1.0))); + assertEquals("Log of Double.MIN_VALUE should be -744.4400719213812", -744.4400719213812, AccurateMath.log(Double.MIN_VALUE), Precision.EPSILON); + assertEquals("Log of infinity should be infinity", Double.POSITIVE_INFINITY, AccurateMath.log(Double.POSITIVE_INFINITY), 1.0); } @Test public void testExpSpecialCases() { // Smallest value that will round up to Double.MIN_VALUE - assertEquals(Double.MIN_VALUE, FastMath.exp(-745.1332191019411), Precision.EPSILON); - assertEquals("exp(-745.1332191019412) should be 0.0", 0.0, FastMath.exp(-745.1332191019412), Precision.EPSILON); - assertTrue("exp of NaN should be NaN", Double.isNaN(FastMath.exp(Double.NaN))); - assertEquals("exp of infinity should be infinity", Double.POSITIVE_INFINITY, FastMath.exp(Double.POSITIVE_INFINITY), 1.0); - assertEquals("exp of -infinity should be 0.0", 0.0, FastMath.exp(Double.NEGATIVE_INFINITY), Precision.EPSILON); - assertEquals("exp(1) should be Math.E", Math.E, FastMath.exp(1.0), Precision.EPSILON); + assertEquals(Double.MIN_VALUE, AccurateMath.exp(-745.1332191019411), Precision.EPSILON); + assertEquals("exp(-745.1332191019412) should be 0.0", 0.0, AccurateMath.exp(-745.1332191019412), Precision.EPSILON); + assertTrue("exp of NaN should be NaN", Double.isNaN(AccurateMath.exp(Double.NaN))); + assertEquals("exp of infinity should be infinity", Double.POSITIVE_INFINITY, AccurateMath.exp(Double.POSITIVE_INFINITY), 1.0); + assertEquals("exp of -infinity should be 0.0", 0.0, AccurateMath.exp(Double.NEGATIVE_INFINITY), Precision.EPSILON); + assertEquals("exp(1) should be Math.E", Math.E, AccurateMath.exp(1.0), Precision.EPSILON); } @Test public void testPowSpecialCases() { final double EXACT = -1.0; - assertEquals("pow(-1, 0) should be 1.0", 1.0, FastMath.pow(-1.0, 0.0), Precision.EPSILON); - assertEquals("pow(-1, -0) should be 1.0", 1.0, FastMath.pow(-1.0, -0.0), Precision.EPSILON); - assertEquals("pow(PI, 1.0) should be PI", FastMath.PI, FastMath.pow(FastMath.PI, 1.0), Precision.EPSILON); - assertEquals("pow(-PI, 1.0) should be -PI", -FastMath.PI, FastMath.pow(-FastMath.PI, 1.0), Precision.EPSILON); - assertTrue("pow(PI, NaN) should be NaN", Double.isNaN(FastMath.pow(Math.PI, Double.NaN))); - assertTrue("pow(NaN, PI) should be NaN", Double.isNaN(FastMath.pow(Double.NaN, Math.PI))); - assertEquals("pow(2.0, Infinity) should be Infinity", Double.POSITIVE_INFINITY, FastMath.pow(2.0, Double.POSITIVE_INFINITY), 1.0); - assertEquals("pow(0.5, -Infinity) should be Infinity", Double.POSITIVE_INFINITY, FastMath.pow(0.5, Double.NEGATIVE_INFINITY), 1.0); - assertEquals("pow(0.5, Infinity) should be 0.0", 0.0, FastMath.pow(0.5, Double.POSITIVE_INFINITY), Precision.EPSILON); - assertEquals("pow(2.0, -Infinity) should be 0.0", 0.0, FastMath.pow(2.0, Double.NEGATIVE_INFINITY), Precision.EPSILON); - assertEquals("pow(0.0, 0.5) should be 0.0", 0.0, FastMath.pow(0.0, 0.5), Precision.EPSILON); - assertEquals("pow(Infinity, -0.5) should be 0.0", 0.0, FastMath.pow(Double.POSITIVE_INFINITY, -0.5), Precision.EPSILON); - assertEquals("pow(0.0, -0.5) should be Inf", Double.POSITIVE_INFINITY, FastMath.pow(0.0, -0.5), 1.0); - assertEquals("pow(Inf, 0.5) should be Inf", Double.POSITIVE_INFINITY, FastMath.pow(Double.POSITIVE_INFINITY, 0.5), 1.0); - assertEquals("pow(-0.0, -3.0) should be -Inf", Double.NEGATIVE_INFINITY, FastMath.pow(-0.0, -3.0), 1.0); - assertEquals("pow(-0.0, Infinity) should be 0.0", 0.0, FastMath.pow(-0.0, Double.POSITIVE_INFINITY), Precision.EPSILON); - assertTrue("pow(-0.0, NaN) should be NaN", Double.isNaN(FastMath.pow(-0.0, Double.NaN))); - assertEquals("pow(-0.0, -tiny) should be Infinity", Double.POSITIVE_INFINITY, FastMath.pow(-0.0, -Double.MIN_VALUE), 1.0); - assertEquals("pow(-0.0, -huge) should be Infinity", Double.POSITIVE_INFINITY, FastMath.pow(-0.0, -Double.MAX_VALUE), 1.0); - assertEquals("pow(-Inf, 3.0) should be -Inf", Double.NEGATIVE_INFINITY, FastMath.pow(Double.NEGATIVE_INFINITY, 3.0), 1.0); - assertEquals("pow(-Inf, -3.0) should be -0.0", -0.0, FastMath.pow(Double.NEGATIVE_INFINITY, -3.0), EXACT); - assertEquals("pow(-0.0, -3.5) should be Inf", Double.POSITIVE_INFINITY, FastMath.pow(-0.0, -3.5), 1.0); - assertEquals("pow(Inf, 3.5) should be Inf", Double.POSITIVE_INFINITY, FastMath.pow(Double.POSITIVE_INFINITY, 3.5), 1.0); - assertEquals("pow(-2.0, 3.0) should be -8.0", -8.0, FastMath.pow(-2.0, 3.0), Precision.EPSILON); - assertTrue("pow(-2.0, 3.5) should be NaN", Double.isNaN(FastMath.pow(-2.0, 3.5))); - assertTrue("pow(NaN, -Infinity) should be NaN", Double.isNaN(FastMath.pow(Double.NaN, Double.NEGATIVE_INFINITY))); - assertEquals("pow(NaN, 0.0) should be 1.0", 1.0, FastMath.pow(Double.NaN, 0.0), Precision.EPSILON); - assertEquals("pow(-Infinity, -Infinity) should be 0.0", 0.0, FastMath.pow(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON); - assertEquals("pow(-huge, -huge) should be 0.0", 0.0, FastMath.pow(-Double.MAX_VALUE, -Double.MAX_VALUE), Precision.EPSILON); - assertTrue("pow(-huge, huge) should be +Inf", Double.isInfinite(FastMath.pow(-Double.MAX_VALUE, Double.MAX_VALUE))); - assertTrue("pow(NaN, -Infinity) should be NaN", Double.isNaN(FastMath.pow(Double.NaN, Double.NEGATIVE_INFINITY))); - assertEquals("pow(NaN, -0.0) should be 1.0", 1.0, FastMath.pow(Double.NaN, -0.0), Precision.EPSILON); - assertEquals("pow(-Infinity, -Infinity) should be 0.0", 0.0, FastMath.pow(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON); - assertEquals("pow(-huge, -huge) should be 0.0", 0.0, FastMath.pow(-Double.MAX_VALUE, -Double.MAX_VALUE), Precision.EPSILON); - assertEquals("pow(-huge, huge) should be +Inf", Double.POSITIVE_INFINITY, FastMath.pow(-Double.MAX_VALUE, Double.MAX_VALUE), 1.0); + assertEquals("pow(-1, 0) should be 1.0", 1.0, AccurateMath.pow(-1.0, 0.0), Precision.EPSILON); + assertEquals("pow(-1, -0) should be 1.0", 1.0, AccurateMath.pow(-1.0, -0.0), Precision.EPSILON); + assertEquals("pow(PI, 1.0) should be PI", AccurateMath.PI, AccurateMath.pow(AccurateMath.PI, 1.0), Precision.EPSILON); + assertEquals("pow(-PI, 1.0) should be -PI", -AccurateMath.PI, AccurateMath.pow(-AccurateMath.PI, 1.0), Precision.EPSILON); + assertTrue("pow(PI, NaN) should be NaN", Double.isNaN(AccurateMath.pow(Math.PI, Double.NaN))); + assertTrue("pow(NaN, PI) should be NaN", Double.isNaN(AccurateMath.pow(Double.NaN, Math.PI))); + assertEquals("pow(2.0, Infinity) should be Infinity", Double.POSITIVE_INFINITY, AccurateMath.pow(2.0, Double.POSITIVE_INFINITY), 1.0); + assertEquals("pow(0.5, -Infinity) should be Infinity", Double.POSITIVE_INFINITY, AccurateMath.pow(0.5, Double.NEGATIVE_INFINITY), 1.0); + assertEquals("pow(0.5, Infinity) should be 0.0", 0.0, AccurateMath.pow(0.5, Double.POSITIVE_INFINITY), Precision.EPSILON); + assertEquals("pow(2.0, -Infinity) should be 0.0", 0.0, AccurateMath.pow(2.0, Double.NEGATIVE_INFINITY), Precision.EPSILON); + assertEquals("pow(0.0, 0.5) should be 0.0", 0.0, AccurateMath.pow(0.0, 0.5), Precision.EPSILON); + assertEquals("pow(Infinity, -0.5) should be 0.0", 0.0, AccurateMath.pow(Double.POSITIVE_INFINITY, -0.5), Precision.EPSILON); + assertEquals("pow(0.0, -0.5) should be Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(0.0, -0.5), 1.0); + assertEquals("pow(Inf, 0.5) should be Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(Double.POSITIVE_INFINITY, 0.5), 1.0); + assertEquals("pow(-0.0, -3.0) should be -Inf", Double.NEGATIVE_INFINITY, AccurateMath.pow(-0.0, -3.0), 1.0); + assertEquals("pow(-0.0, Infinity) should be 0.0", 0.0, AccurateMath.pow(-0.0, Double.POSITIVE_INFINITY), Precision.EPSILON); + assertTrue("pow(-0.0, NaN) should be NaN", Double.isNaN(AccurateMath.pow(-0.0, Double.NaN))); + assertEquals("pow(-0.0, -tiny) should be Infinity", Double.POSITIVE_INFINITY, AccurateMath.pow(-0.0, -Double.MIN_VALUE), 1.0); + assertEquals("pow(-0.0, -huge) should be Infinity", Double.POSITIVE_INFINITY, AccurateMath.pow(-0.0, -Double.MAX_VALUE), 1.0); + assertEquals("pow(-Inf, 3.0) should be -Inf", Double.NEGATIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, 3.0), 1.0); + assertEquals("pow(-Inf, -3.0) should be -0.0", -0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, -3.0), EXACT); + assertEquals("pow(-0.0, -3.5) should be Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(-0.0, -3.5), 1.0); + assertEquals("pow(Inf, 3.5) should be Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(Double.POSITIVE_INFINITY, 3.5), 1.0); + assertEquals("pow(-2.0, 3.0) should be -8.0", -8.0, AccurateMath.pow(-2.0, 3.0), Precision.EPSILON); + assertTrue("pow(-2.0, 3.5) should be NaN", Double.isNaN(AccurateMath.pow(-2.0, 3.5))); + assertTrue("pow(NaN, -Infinity) should be NaN", Double.isNaN(AccurateMath.pow(Double.NaN, Double.NEGATIVE_INFINITY))); + assertEquals("pow(NaN, 0.0) should be 1.0", 1.0, AccurateMath.pow(Double.NaN, 0.0), Precision.EPSILON); + assertEquals("pow(-Infinity, -Infinity) should be 0.0", 0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON); + assertEquals("pow(-huge, -huge) should be 0.0", 0.0, AccurateMath.pow(-Double.MAX_VALUE, -Double.MAX_VALUE), Precision.EPSILON); + assertTrue("pow(-huge, huge) should be +Inf", Double.isInfinite(AccurateMath.pow(-Double.MAX_VALUE, Double.MAX_VALUE))); + assertTrue("pow(NaN, -Infinity) should be NaN", Double.isNaN(AccurateMath.pow(Double.NaN, Double.NEGATIVE_INFINITY))); + assertEquals("pow(NaN, -0.0) should be 1.0", 1.0, AccurateMath.pow(Double.NaN, -0.0), Precision.EPSILON); + assertEquals("pow(-Infinity, -Infinity) should be 0.0", 0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON); + assertEquals("pow(-huge, -huge) should be 0.0", 0.0, AccurateMath.pow(-Double.MAX_VALUE, -Double.MAX_VALUE), Precision.EPSILON); + assertEquals("pow(-huge, huge) should be +Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(-Double.MAX_VALUE, Double.MAX_VALUE), 1.0); // Added tests for a 100% coverage - assertTrue("pow(+Inf, NaN) should be NaN", Double.isNaN(FastMath.pow(Double.POSITIVE_INFINITY, Double.NaN))); - assertTrue("pow(1.0, +Inf) should be NaN", Double.isNaN(FastMath.pow(1.0, Double.POSITIVE_INFINITY))); - assertTrue("pow(-Inf, NaN) should be NaN", Double.isNaN(FastMath.pow(Double.NEGATIVE_INFINITY, Double.NaN))); - assertEquals("pow(-Inf, -1.0) should be -0.0", -0.0, FastMath.pow(Double.NEGATIVE_INFINITY, -1.0), EXACT); - assertEquals("pow(-Inf, -2.0) should be 0.0", 0.0, FastMath.pow(Double.NEGATIVE_INFINITY, -2.0), EXACT); - assertEquals("pow(-Inf, 1.0) should be -Inf", Double.NEGATIVE_INFINITY, FastMath.pow(Double.NEGATIVE_INFINITY, 1.0), 1.0); - assertEquals("pow(-Inf, 2.0) should be +Inf", Double.POSITIVE_INFINITY, FastMath.pow(Double.NEGATIVE_INFINITY, 2.0), 1.0); - assertTrue("pow(1.0, -Inf) should be NaN", Double.isNaN(FastMath.pow(1.0, Double.NEGATIVE_INFINITY))); - assertEquals("pow(-0.0, 1.0) should be -0.0", -0.0, FastMath.pow(-0.0, 1.0), EXACT); - assertEquals("pow(0.0, 1.0) should be 0.0", 0.0, FastMath.pow(0.0, 1.0), EXACT); - assertEquals("pow(0.0, +Inf) should be 0.0", 0.0, FastMath.pow(0.0, Double.POSITIVE_INFINITY), EXACT); - assertEquals("pow(-0.0, even) should be 0.0", 0.0, FastMath.pow(-0.0, 6.0), EXACT); - assertEquals("pow(-0.0, odd) should be -0.0", -0.0, FastMath.pow(-0.0, 13.0), EXACT); - assertEquals("pow(-0.0, -even) should be +Inf", Double.POSITIVE_INFINITY, FastMath.pow(-0.0, -6.0), EXACT); - assertEquals("pow(-0.0, -odd) should be -Inf", Double.NEGATIVE_INFINITY, FastMath.pow(-0.0, -13.0), EXACT); - assertEquals("pow(-2.0, 4.0) should be 16.0", 16.0, FastMath.pow(-2.0, 4.0), EXACT); - assertEquals("pow(-2.0, 4.5) should be NaN", Double.NaN, FastMath.pow(-2.0, 4.5), EXACT); - assertEquals("pow(-0.0, -0.0) should be 1.0", 1.0, FastMath.pow(-0.0, -0.0), EXACT); - assertEquals("pow(-0.0, 0.0) should be 1.0", 1.0, FastMath.pow(-0.0, 0.0), EXACT); - assertEquals("pow(0.0, -0.0) should be 1.0", 1.0, FastMath.pow(0.0, -0.0), EXACT); - assertEquals("pow(0.0, 0.0) should be 1.0", 1.0, FastMath.pow(0.0, 0.0), EXACT); + assertTrue("pow(+Inf, NaN) should be NaN", Double.isNaN(AccurateMath.pow(Double.POSITIVE_INFINITY, Double.NaN))); + assertTrue("pow(1.0, +Inf) should be NaN", Double.isNaN(AccurateMath.pow(1.0, Double.POSITIVE_INFINITY))); + assertTrue("pow(-Inf, NaN) should be NaN", Double.isNaN(AccurateMath.pow(Double.NEGATIVE_INFINITY, Double.NaN))); + assertEquals("pow(-Inf, -1.0) should be -0.0", -0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, -1.0), EXACT); + assertEquals("pow(-Inf, -2.0) should be 0.0", 0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, -2.0), EXACT); + assertEquals("pow(-Inf, 1.0) should be -Inf", Double.NEGATIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, 1.0), 1.0); + assertEquals("pow(-Inf, 2.0) should be +Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, 2.0), 1.0); + assertTrue("pow(1.0, -Inf) should be NaN", Double.isNaN(AccurateMath.pow(1.0, Double.NEGATIVE_INFINITY))); + assertEquals("pow(-0.0, 1.0) should be -0.0", -0.0, AccurateMath.pow(-0.0, 1.0), EXACT); + assertEquals("pow(0.0, 1.0) should be 0.0", 0.0, AccurateMath.pow(0.0, 1.0), EXACT); + assertEquals("pow(0.0, +Inf) should be 0.0", 0.0, AccurateMath.pow(0.0, Double.POSITIVE_INFINITY), EXACT); + assertEquals("pow(-0.0, even) should be 0.0", 0.0, AccurateMath.pow(-0.0, 6.0), EXACT); + assertEquals("pow(-0.0, odd) should be -0.0", -0.0, AccurateMath.pow(-0.0, 13.0), EXACT); + assertEquals("pow(-0.0, -even) should be +Inf", Double.POSITIVE_INFINITY, AccurateMath.pow(-0.0, -6.0), EXACT); + assertEquals("pow(-0.0, -odd) should be -Inf", Double.NEGATIVE_INFINITY, AccurateMath.pow(-0.0, -13.0), EXACT); + assertEquals("pow(-2.0, 4.0) should be 16.0", 16.0, AccurateMath.pow(-2.0, 4.0), EXACT); + assertEquals("pow(-2.0, 4.5) should be NaN", Double.NaN, AccurateMath.pow(-2.0, 4.5), EXACT); + assertEquals("pow(-0.0, -0.0) should be 1.0", 1.0, AccurateMath.pow(-0.0, -0.0), EXACT); + assertEquals("pow(-0.0, 0.0) should be 1.0", 1.0, AccurateMath.pow(-0.0, 0.0), EXACT); + assertEquals("pow(0.0, -0.0) should be 1.0", 1.0, AccurateMath.pow(0.0, -0.0), EXACT); + assertEquals("pow(0.0, 0.0) should be 1.0", 1.0, AccurateMath.pow(0.0, 0.0), EXACT); } @Test(timeout=20000L) @@ -432,124 +432,124 @@ public class FastMathTest { // Special cases from Math.pow javadoc: // If the second argument is positive or negative zero, then the result is 1.0. for (double d : DOUBLES) { - assertEquals(1.0, FastMath.pow(d, 0.0), EXACT); + assertEquals(1.0, AccurateMath.pow(d, 0.0), EXACT); } for (double d : DOUBLES) { - assertEquals(1.0, FastMath.pow(d, -0.0), EXACT); + assertEquals(1.0, AccurateMath.pow(d, -0.0), EXACT); } // If the second argument is 1.0, then the result is the same as the first argument. for (double d : DOUBLES) { - assertEquals(d, FastMath.pow(d, 1.0), EXACT); + assertEquals(d, AccurateMath.pow(d, 1.0), EXACT); } // If the second argument is NaN, then the result is NaN. for (double d : DOUBLES) { - assertEquals(Double.NaN, FastMath.pow(d, Double.NaN), EXACT); + assertEquals(Double.NaN, AccurateMath.pow(d, Double.NaN), EXACT); } // If the first argument is NaN and the second argument is nonzero, then the result is NaN. for (double i : DOUBLES) { if (i != 0.0) { - assertEquals(Double.NaN, FastMath.pow(Double.NaN, i), EXACT); + assertEquals(Double.NaN, AccurateMath.pow(Double.NaN, i), EXACT); } } // If the absolute value of the first argument is greater than 1 and the second argument is positive infinity, or // the absolute value of the first argument is less than 1 and the second argument is negative infinity, then the result is positive infinity. for (double d : DOUBLES) { if (Math.abs(d) > 1.0) { - assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(d, Double.POSITIVE_INFINITY), EXACT); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(d, Double.POSITIVE_INFINITY), EXACT); } } for (double d : DOUBLES) { if (Math.abs(d) < 1.0) { - assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(d, Double.NEGATIVE_INFINITY), EXACT); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(d, Double.NEGATIVE_INFINITY), EXACT); } } // If the absolute value of the first argument is greater than 1 and the second argument is negative infinity, or // the absolute value of the first argument is less than 1 and the second argument is positive infinity, then the result is positive zero. for (double d : DOUBLES) { if (Math.abs(d) > 1.0) { - assertEquals(0.0, FastMath.pow(d, Double.NEGATIVE_INFINITY), EXACT); + assertEquals(0.0, AccurateMath.pow(d, Double.NEGATIVE_INFINITY), EXACT); } } for (double d : DOUBLES) { if (Math.abs(d) < 1.0) { - assertEquals(0.0, FastMath.pow(d, Double.POSITIVE_INFINITY), EXACT); + assertEquals(0.0, AccurateMath.pow(d, Double.POSITIVE_INFINITY), EXACT); } } // If the absolute value of the first argument equals 1 and the second argument is infinite, then the result is NaN. - assertEquals(Double.NaN, FastMath.pow(1.0, Double.POSITIVE_INFINITY), EXACT); - assertEquals(Double.NaN, FastMath.pow(1.0, Double.NEGATIVE_INFINITY), EXACT); - assertEquals(Double.NaN, FastMath.pow(-1.0, Double.POSITIVE_INFINITY), EXACT); - assertEquals(Double.NaN, FastMath.pow(-1.0, Double.NEGATIVE_INFINITY), EXACT); + assertEquals(Double.NaN, AccurateMath.pow(1.0, Double.POSITIVE_INFINITY), EXACT); + assertEquals(Double.NaN, AccurateMath.pow(1.0, Double.NEGATIVE_INFINITY), EXACT); + assertEquals(Double.NaN, AccurateMath.pow(-1.0, Double.POSITIVE_INFINITY), EXACT); + assertEquals(Double.NaN, AccurateMath.pow(-1.0, Double.NEGATIVE_INFINITY), EXACT); // If the first argument is positive zero and the second argument is greater than zero, or // the first argument is positive infinity and the second argument is less than zero, then the result is positive zero. for (double i : DOUBLES) { if (i > 0.0) { - assertEquals(0.0, FastMath.pow(0.0, i), EXACT); + assertEquals(0.0, AccurateMath.pow(0.0, i), EXACT); } } for (double i : DOUBLES) { if (i < 0.0) { - assertEquals(0.0, FastMath.pow(Double.POSITIVE_INFINITY, i), EXACT); + assertEquals(0.0, AccurateMath.pow(Double.POSITIVE_INFINITY, i), EXACT); } } // If the first argument is positive zero and the second argument is less than zero, or // the first argument is positive infinity and the second argument is greater than zero, then the result is positive infinity. for (double i : DOUBLES) { if (i < 0.0) { - assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(0.0, i), EXACT); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(0.0, i), EXACT); } } for (double i : DOUBLES) { if (i > 0.0) { - assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(Double.POSITIVE_INFINITY, i), EXACT); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(Double.POSITIVE_INFINITY, i), EXACT); } } // If the first argument is negative zero and the second argument is greater than zero but not a finite odd integer, or // the first argument is negative infinity and the second argument is less than zero but not a finite odd integer, then the result is positive zero. for (double i : DOUBLES) { if (i > 0.0 && (Double.isInfinite(i) || i % 2.0 == 0.0)) { - assertEquals(0.0, FastMath.pow(-0.0, i), EXACT); + assertEquals(0.0, AccurateMath.pow(-0.0, i), EXACT); } } for (double i : DOUBLES) { if (i < 0.0 && (Double.isInfinite(i) || i % 2.0 == 0.0)) { - assertEquals(0.0, FastMath.pow(Double.NEGATIVE_INFINITY, i), EXACT); + assertEquals(0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT); } } // If the first argument is negative zero and the second argument is a positive finite odd integer, or // the first argument is negative infinity and the second argument is a negative finite odd integer, then the result is negative zero. for (double i : DOUBLES) { if (i > 0.0 && i % 2.0 == 1.0) { - assertEquals(-0.0, FastMath.pow(-0.0, i), EXACT); + assertEquals(-0.0, AccurateMath.pow(-0.0, i), EXACT); } } for (double i : DOUBLES) { if (i < 0.0 && i % 2.0 == -1.0) { - assertEquals(-0.0, FastMath.pow(Double.NEGATIVE_INFINITY, i), EXACT); + assertEquals(-0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT); } } // If the first argument is negative zero and the second argument is less than zero but not a finite odd integer, or // the first argument is negative infinity and the second argument is greater than zero but not a finite odd integer, then the result is positive infinity. for (double i : DOUBLES) { if (i > 0.0 && (Double.isInfinite(i) || i % 2.0 == 0.0)) { - assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(Double.NEGATIVE_INFINITY, i), EXACT); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT); } } for (double i : DOUBLES) { if (i < 0.0 && (Double.isInfinite(i) || i % 2.0 == 0.0)) { - assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(-0.0, i), EXACT); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(-0.0, i), EXACT); } } // If the first argument is negative zero and the second argument is a negative finite odd integer, or // the first argument is negative infinity and the second argument is a positive finite odd integer, then the result is negative infinity. for (double i : DOUBLES) { if (i > 0.0 && i % 2.0 == 1.0) { - assertEquals(Double.NEGATIVE_INFINITY, FastMath.pow(Double.NEGATIVE_INFINITY, i), EXACT); + assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT); } } for (double i : DOUBLES) { if (i < 0.0 && i % 2.0 == -1.0) { - assertEquals(Double.NEGATIVE_INFINITY, FastMath.pow(-0.0, i), EXACT); + assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.pow(-0.0, i), EXACT); } } for (double d : DOUBLES) { @@ -558,11 +558,11 @@ public class FastMathTest { for (double i : DOUBLES) { if (Math.abs(i) <= Double.MAX_VALUE) { // if the second argument is a finite even integer, the result is equal to the result of raising the absolute value of the first argument to the power of the second argument - if (i % 2.0 == 0.0) assertEquals(FastMath.pow(-d, i), FastMath.pow(d, i), EXACT); + if (i % 2.0 == 0.0) assertEquals(AccurateMath.pow(-d, i), AccurateMath.pow(d, i), EXACT); // if the second argument is a finite odd integer, the result is equal to the negative of the result of raising the absolute value of the first argument to the power of the second argument - else if (Math.abs(i) % 2.0 == 1.0) assertEquals(-FastMath.pow(-d, i), FastMath.pow(d, i), EXACT); + else if (Math.abs(i) % 2.0 == 1.0) assertEquals(-AccurateMath.pow(-d, i), AccurateMath.pow(d, i), EXACT); // if the second argument is finite and not an integer, then the result is NaN. - else assertEquals(Double.NaN, FastMath.pow(d, i), EXACT); + else assertEquals(Double.NaN, AccurateMath.pow(d, i), EXACT); } } } @@ -594,7 +594,7 @@ public class FastMathTest { if (dNegative && bi.testBit( 0 )) { expected = -expected; } - assertEquals(d + "^" + i + "=" + expected + ", Math.pow=" + Math.pow(d, i), expected, FastMath.pow(d, i), expected == 0.0 || Double.isInfinite(expected) || Double.isNaN(expected) ? EXACT : 2.0 * Math.ulp(expected)); + assertEquals(d + "^" + i + "=" + expected + ", Math.pow=" + Math.pow(d, i), expected, AccurateMath.pow(d, i), expected == 0.0 || Double.isInfinite(expected) || Double.isNaN(expected) ? EXACT : 2.0 * Math.ulp(expected)); } } } @@ -603,46 +603,46 @@ public class FastMathTest { @Test public void testPowLargeIntegralDouble() { - double y = FastMath.scalb(1.0, 65); - assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(FastMath.nextUp(1.0), y), 1.0); - assertEquals(1.0, FastMath.pow(1.0, y), 1.0); - assertEquals(0.0, FastMath.pow(FastMath.nextDown(1.0), y), 1.0); - assertEquals(0.0, FastMath.pow(FastMath.nextUp(-1.0), y), 1.0); - assertEquals(1.0, FastMath.pow(-1.0, y), 1.0); - assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(FastMath.nextDown(-1.0), y), 1.0); + double y = AccurateMath.scalb(1.0, 65); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(AccurateMath.nextUp(1.0), y), 1.0); + assertEquals(1.0, AccurateMath.pow(1.0, y), 1.0); + assertEquals(0.0, AccurateMath.pow(AccurateMath.nextDown(1.0), y), 1.0); + assertEquals(0.0, AccurateMath.pow(AccurateMath.nextUp(-1.0), y), 1.0); + assertEquals(1.0, AccurateMath.pow(-1.0, y), 1.0); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(AccurateMath.nextDown(-1.0), y), 1.0); } @Test public void testAtan2SpecialCases() { - assertTrue("atan2(NaN, 0.0) should be NaN", Double.isNaN(FastMath.atan2(Double.NaN, 0.0))); - assertTrue("atan2(0.0, NaN) should be NaN", Double.isNaN(FastMath.atan2(0.0, Double.NaN))); - assertEquals("atan2(0.0, 0.0) should be 0.0", 0.0, FastMath.atan2(0.0, 0.0), Precision.EPSILON); - assertEquals("atan2(0.0, 0.001) should be 0.0", 0.0, FastMath.atan2(0.0, 0.001), Precision.EPSILON); - assertEquals("atan2(0.1, +Inf) should be 0.0", 0.0, FastMath.atan2(0.1, Double.POSITIVE_INFINITY), Precision.EPSILON); - assertEquals("atan2(-0.0, 0.0) should be -0.0", -0.0, FastMath.atan2(-0.0, 0.0), Precision.EPSILON); - assertEquals("atan2(-0.0, 0.001) should be -0.0", -0.0, FastMath.atan2(-0.0, 0.001), Precision.EPSILON); - assertEquals("atan2(-0.0, +Inf) should be -0.0", -0.0, FastMath.atan2(-0.1, Double.POSITIVE_INFINITY), Precision.EPSILON); - assertEquals("atan2(0.0, -0.0) should be PI", FastMath.PI, FastMath.atan2(0.0, -0.0), Precision.EPSILON); - assertEquals("atan2(0.1, -Inf) should be PI", FastMath.PI, FastMath.atan2(0.1, Double.NEGATIVE_INFINITY), Precision.EPSILON); - assertEquals("atan2(-0.0, -0.0) should be -PI", -FastMath.PI, FastMath.atan2(-0.0, -0.0), Precision.EPSILON); - assertEquals("atan2(0.1, -Inf) should be -PI", -FastMath.PI, FastMath.atan2(-0.1, Double.NEGATIVE_INFINITY), Precision.EPSILON); - assertEquals("atan2(0.1, 0.0) should be PI/2", FastMath.PI / 2.0, FastMath.atan2(0.1, 0.0), Precision.EPSILON); - assertEquals("atan2(0.1, -0.0) should be PI/2", FastMath.PI / 2.0, FastMath.atan2(0.1, -0.0), Precision.EPSILON); - assertEquals("atan2(Inf, 0.1) should be PI/2", FastMath.PI / 2.0, FastMath.atan2(Double.POSITIVE_INFINITY, 0.1), Precision.EPSILON); - assertEquals("atan2(Inf, -0.1) should be PI/2", FastMath.PI / 2.0, FastMath.atan2(Double.POSITIVE_INFINITY, -0.1), Precision.EPSILON); - assertEquals("atan2(-0.1, 0.0) should be -PI/2", -FastMath.PI / 2.0, FastMath.atan2(-0.1, 0.0), Precision.EPSILON); - assertEquals("atan2(-0.1, -0.0) should be -PI/2", -FastMath.PI / 2.0, FastMath.atan2(-0.1, -0.0), Precision.EPSILON); - assertEquals("atan2(-Inf, 0.1) should be -PI/2", -FastMath.PI / 2.0, FastMath.atan2(Double.NEGATIVE_INFINITY, 0.1), Precision.EPSILON); - assertEquals("atan2(-Inf, -0.1) should be -PI/2", -FastMath.PI / 2.0, FastMath.atan2(Double.NEGATIVE_INFINITY, -0.1), Precision.EPSILON); - assertEquals("atan2(Inf, Inf) should be PI/4", FastMath.PI / 4.0, FastMath.atan2(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY), + assertTrue("atan2(NaN, 0.0) should be NaN", Double.isNaN(AccurateMath.atan2(Double.NaN, 0.0))); + assertTrue("atan2(0.0, NaN) should be NaN", Double.isNaN(AccurateMath.atan2(0.0, Double.NaN))); + assertEquals("atan2(0.0, 0.0) should be 0.0", 0.0, AccurateMath.atan2(0.0, 0.0), Precision.EPSILON); + assertEquals("atan2(0.0, 0.001) should be 0.0", 0.0, AccurateMath.atan2(0.0, 0.001), Precision.EPSILON); + assertEquals("atan2(0.1, +Inf) should be 0.0", 0.0, AccurateMath.atan2(0.1, Double.POSITIVE_INFINITY), Precision.EPSILON); + assertEquals("atan2(-0.0, 0.0) should be -0.0", -0.0, AccurateMath.atan2(-0.0, 0.0), Precision.EPSILON); + assertEquals("atan2(-0.0, 0.001) should be -0.0", -0.0, AccurateMath.atan2(-0.0, 0.001), Precision.EPSILON); + assertEquals("atan2(-0.0, +Inf) should be -0.0", -0.0, AccurateMath.atan2(-0.1, Double.POSITIVE_INFINITY), Precision.EPSILON); + assertEquals("atan2(0.0, -0.0) should be PI", AccurateMath.PI, AccurateMath.atan2(0.0, -0.0), Precision.EPSILON); + assertEquals("atan2(0.1, -Inf) should be PI", AccurateMath.PI, AccurateMath.atan2(0.1, Double.NEGATIVE_INFINITY), Precision.EPSILON); + assertEquals("atan2(-0.0, -0.0) should be -PI", -AccurateMath.PI, AccurateMath.atan2(-0.0, -0.0), Precision.EPSILON); + assertEquals("atan2(0.1, -Inf) should be -PI", -AccurateMath.PI, AccurateMath.atan2(-0.1, Double.NEGATIVE_INFINITY), Precision.EPSILON); + assertEquals("atan2(0.1, 0.0) should be PI/2", AccurateMath.PI / 2.0, AccurateMath.atan2(0.1, 0.0), Precision.EPSILON); + assertEquals("atan2(0.1, -0.0) should be PI/2", AccurateMath.PI / 2.0, AccurateMath.atan2(0.1, -0.0), Precision.EPSILON); + assertEquals("atan2(Inf, 0.1) should be PI/2", AccurateMath.PI / 2.0, AccurateMath.atan2(Double.POSITIVE_INFINITY, 0.1), Precision.EPSILON); + assertEquals("atan2(Inf, -0.1) should be PI/2", AccurateMath.PI / 2.0, AccurateMath.atan2(Double.POSITIVE_INFINITY, -0.1), Precision.EPSILON); + assertEquals("atan2(-0.1, 0.0) should be -PI/2", -AccurateMath.PI / 2.0, AccurateMath.atan2(-0.1, 0.0), Precision.EPSILON); + assertEquals("atan2(-0.1, -0.0) should be -PI/2", -AccurateMath.PI / 2.0, AccurateMath.atan2(-0.1, -0.0), Precision.EPSILON); + assertEquals("atan2(-Inf, 0.1) should be -PI/2", -AccurateMath.PI / 2.0, AccurateMath.atan2(Double.NEGATIVE_INFINITY, 0.1), Precision.EPSILON); + assertEquals("atan2(-Inf, -0.1) should be -PI/2", -AccurateMath.PI / 2.0, AccurateMath.atan2(Double.NEGATIVE_INFINITY, -0.1), Precision.EPSILON); + assertEquals("atan2(Inf, Inf) should be PI/4", AccurateMath.PI / 4.0, AccurateMath.atan2(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY), Precision.EPSILON); - assertEquals("atan2(Inf, -Inf) should be PI * 3/4", FastMath.PI * 3.0 / 4.0, - FastMath.atan2(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON); - assertEquals("atan2(-Inf, Inf) should be -PI/4", -FastMath.PI / 4.0, FastMath.atan2(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY), + assertEquals("atan2(Inf, -Inf) should be PI * 3/4", AccurateMath.PI * 3.0 / 4.0, + AccurateMath.atan2(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON); + assertEquals("atan2(-Inf, Inf) should be -PI/4", -AccurateMath.PI / 4.0, AccurateMath.atan2(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY), Precision.EPSILON); - assertEquals("atan2(-Inf, -Inf) should be -PI * 3/4", - FastMath.PI * 3.0 / 4.0, - FastMath.atan2(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON); + assertEquals("atan2(-Inf, -Inf) should be -PI * 3/4", - AccurateMath.PI * 3.0 / 4.0, + AccurateMath.atan2(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), Precision.EPSILON); } @Test @@ -653,14 +653,14 @@ public class FastMathTest { double x = (generator.nextDouble() * 2.0 + 0.25); double y = (generator.nextDouble() * 1200.0 - 600.0) * generator.nextDouble(); /* - * double x = FastMath.floor(generator.nextDouble()*1024.0 - 512.0); double - * y; if (x != 0) y = FastMath.floor(512.0 / FastMath.abs(x)); else - * y = generator.nextDouble()*1200.0; y = y - y/2; x = FastMath.pow(2.0, x) * + * double x = AccurateMath.floor(generator.nextDouble()*1024.0 - 512.0); double + * y; if (x != 0) y = AccurateMath.floor(512.0 / AccurateMath.abs(x)); else + * y = generator.nextDouble()*1200.0; y = y - y/2; x = AccurateMath.pow(2.0, x) * * generator.nextDouble(); y = y * generator.nextDouble(); */ // double x = generator.nextDouble()*2.0; - double tst = FastMath.pow(x, y); + double tst = AccurateMath.pow(x, y); double ref = DfpMath.pow(field.newDfp(x), field.newDfp(y)).toDouble(); double err = (tst - ref) / ref; @@ -687,7 +687,7 @@ public class FastMathTest { // double x = (generator.nextDouble() * 20.0) - 10.0; // double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble(); /* double x = 3.0 / 512.0 * i - 3.0; */ - double tst = FastMath.exp(x); + double tst = AccurateMath.exp(x); double ref = DfpMath.exp(field.newDfp(x)).toDouble(); double err = (tst - ref) / ref; @@ -716,7 +716,7 @@ public class FastMathTest { // double x = (generator.nextDouble() * 20.0) - 10.0; // double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble(); /* double x = 3.0 / 512.0 * i - 3.0; */ - double tst = FastMath.sin(x); + double tst = AccurateMath.sin(x); double ref = DfpMath.sin(field.newDfp(x)).toDouble(); double err = (tst - ref) / ref; @@ -745,7 +745,7 @@ public class FastMathTest { // double x = (generator.nextDouble() * 20.0) - 10.0; // double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble(); /* double x = 3.0 / 512.0 * i - 3.0; */ - double tst = FastMath.cos(x); + double tst = AccurateMath.cos(x); double ref = DfpMath.cos(field.newDfp(x)).toDouble(); double err = (tst - ref) / ref; @@ -774,7 +774,7 @@ public class FastMathTest { // double x = (generator.nextDouble() * 20.0) - 10.0; // double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble(); /* double x = 3.0 / 512.0 * i - 3.0; */ - double tst = FastMath.tan(x); + double tst = AccurateMath.tan(x); double ref = DfpMath.tan(field.newDfp(x)).toDouble(); double err = (tst - ref) / ref; @@ -805,7 +805,7 @@ public class FastMathTest { // double x = (generator.nextDouble() * 20.0) - 10.0; // double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble(); /* double x = 3.0 / 512.0 * i - 3.0; */ - double tst = FastMath.atan(x); + double tst = AccurateMath.atan(x); double ref = DfpMath.atan(field.newDfp(x)).toDouble(); double err = (tst - ref) / ref; @@ -834,7 +834,7 @@ public class FastMathTest { // double x = (generator.nextDouble() * 20.0) - 10.0; // double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble(); /* double x = 3.0 / 512.0 * i - 3.0; */ - double tst = FastMath.atan2(y, x); + double tst = AccurateMath.atan2(y, x); Dfp refdfp = DfpMath.atan(field.newDfp(y).divide(field.newDfp(x))); /* Make adjustments for sign */ if (x < 0.0) { @@ -870,7 +870,7 @@ public class FastMathTest { // double x = (generator.nextDouble() * 20.0) - 10.0; double x = ((generator.nextDouble() * 16.0) - 8.0) * generator.nextDouble(); /* double x = 3.0 / 512.0 * i - 3.0; */ - double tst = FastMath.expm1(x); + double tst = AccurateMath.expm1(x); double ref = DfpMath.exp(field.newDfp(x)).subtract(field.getOne()).toDouble(); double err = (tst - ref) / ref; @@ -894,7 +894,7 @@ public class FastMathTest { for (int i=0; i<10000; i++) { double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble(); - double tst = FastMath.asin(x); + double tst = AccurateMath.asin(x); double ref = DfpMath.asin(field.newDfp(x)).toDouble(); double err = (tst - ref) / ref; @@ -917,7 +917,7 @@ public class FastMathTest { for (int i=0; i<10000; i++) { double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble(); - double tst = FastMath.acos(x); + double tst = AccurateMath.acos(x); double ref = DfpMath.acos(field.newDfp(x)).toDouble(); double err = (tst - ref) / ref; @@ -939,12 +939,12 @@ public class FastMathTest { @Test public void testAcosSpecialCases() { - assertTrue("acos(NaN) should be NaN", Double.isNaN(FastMath.acos(Double.NaN))); - assertTrue("acos(-1.1) should be NaN", Double.isNaN(FastMath.acos(-1.1))); - assertTrue("acos(-1.1) should be NaN", Double.isNaN(FastMath.acos(1.1))); - assertEquals("acos(-1.0) should be PI", FastMath.acos(-1.0), FastMath.PI, Precision.EPSILON); - assertEquals("acos(1.0) should be 0.0", FastMath.acos(1.0), 0.0, Precision.EPSILON); - assertEquals("acos(0.0) should be PI/2", FastMath.acos(0.0), FastMath.PI / 2.0, Precision.EPSILON); + assertTrue("acos(NaN) should be NaN", Double.isNaN(AccurateMath.acos(Double.NaN))); + assertTrue("acos(-1.1) should be NaN", Double.isNaN(AccurateMath.acos(-1.1))); + assertTrue("acos(-1.1) should be NaN", Double.isNaN(AccurateMath.acos(1.1))); + assertEquals("acos(-1.0) should be PI", AccurateMath.acos(-1.0), AccurateMath.PI, Precision.EPSILON); + assertEquals("acos(1.0) should be 0.0", AccurateMath.acos(1.0), 0.0, Precision.EPSILON); + assertEquals("acos(0.0) should be PI/2", AccurateMath.acos(0.0), AccurateMath.PI / 2.0, Precision.EPSILON); } /** @@ -953,12 +953,12 @@ public class FastMathTest { @Test public void testAsinSpecialCases() { - assertTrue("asin(NaN) should be NaN", Double.isNaN(FastMath.asin(Double.NaN))); - assertTrue("asin(1.1) should be NaN", Double.isNaN(FastMath.asin(1.1))); - assertTrue("asin(-1.1) should be NaN", Double.isNaN(FastMath.asin(-1.1))); - assertEquals("asin(1.0) should be PI/2", FastMath.asin(1.0), FastMath.PI / 2.0, Precision.EPSILON); - assertEquals("asin(-1.0) should be -PI/2", FastMath.asin(-1.0), -FastMath.PI / 2.0, Precision.EPSILON); - assertEquals("asin(0.0) should be 0.0", FastMath.asin(0.0), 0.0, Precision.EPSILON); + assertTrue("asin(NaN) should be NaN", Double.isNaN(AccurateMath.asin(Double.NaN))); + assertTrue("asin(1.1) should be NaN", Double.isNaN(AccurateMath.asin(1.1))); + assertTrue("asin(-1.1) should be NaN", Double.isNaN(AccurateMath.asin(-1.1))); + assertEquals("asin(1.0) should be PI/2", AccurateMath.asin(1.0), AccurateMath.PI / 2.0, Precision.EPSILON); + assertEquals("asin(-1.0) should be -PI/2", AccurateMath.asin(-1.0), -AccurateMath.PI / 2.0, Precision.EPSILON); + assertEquals("asin(0.0) should be 0.0", AccurateMath.asin(0.0), 0.0, Precision.EPSILON); } private Dfp cosh(Dfp x) { @@ -980,7 +980,7 @@ public class FastMathTest { for (int i=0; i<10000; i++) { double x = ((generator.nextDouble() * 16.0) - 8.0) * generator.nextDouble(); - double tst = FastMath.sinh(x); + double tst = AccurateMath.sinh(x); double ref = sinh(field.newDfp(x)).toDouble(); double err = (tst - ref) / ref; @@ -1002,7 +1002,7 @@ public class FastMathTest { for (int i=0; i<10000; i++) { double x = ((generator.nextDouble() * 16.0) - 8.0) * generator.nextDouble(); - double tst = FastMath.cosh(x); + double tst = AccurateMath.cosh(x); double ref = cosh(field.newDfp(x)).toDouble(); double err = (tst - ref) / ref; @@ -1024,7 +1024,7 @@ public class FastMathTest { for (int i=0; i<10000; i++) { double x = ((generator.nextDouble() * 16.0) - 8.0) * generator.nextDouble(); - double tst = FastMath.tanh(x); + double tst = AccurateMath.tanh(x); double ref = tanh(field.newDfp(x)).toDouble(); double err = (tst - ref) / ref; @@ -1046,7 +1046,7 @@ public class FastMathTest { for (int i=0; i<10000; i++) { double x = ((generator.nextDouble() * 200.0) - 100.0) * generator.nextDouble(); - double tst = FastMath.cbrt(x); + double tst = AccurateMath.cbrt(x); double ref = cbrt(field.newDfp(x)).toDouble(); double err = (tst - ref) / ref; @@ -1084,7 +1084,7 @@ public class FastMathTest { for (int i = 0; i < NUMBER_OF_TRIALS; i++) { double x = generator.nextDouble(); double tst = field.newDfp(x).multiply(180).divide(field.getPi()).toDouble(); - double ref = FastMath.toDegrees(x); + double ref = AccurateMath.toDegrees(x); double err = (tst - ref) / ref; if (err != 0) { @@ -1105,7 +1105,7 @@ public class FastMathTest { for (int i = 0; i < NUMBER_OF_TRIALS; i++) { double x = generator.nextDouble(); double tst = field.newDfp(x).multiply(field.getPi()).divide(180).toDouble(); - double ref = FastMath.toRadians(x); + double ref = AccurateMath.toRadians(x); double err = (tst - ref) / ref; if (err != 0) { @@ -1124,133 +1124,133 @@ public class FastMathTest { @Test public void testNextAfter() { // 0x402fffffffffffff 0x404123456789abcd -> 4030000000000000 - assertEquals(16.0, FastMath.nextUp(15.999999999999998), 0.0); + assertEquals(16.0, AccurateMath.nextUp(15.999999999999998), 0.0); // 0xc02fffffffffffff 0x404123456789abcd -> c02ffffffffffffe - assertEquals(-15.999999999999996, FastMath.nextAfter(-15.999999999999998, 34.27555555555555), 0.0); + assertEquals(-15.999999999999996, AccurateMath.nextAfter(-15.999999999999998, 34.27555555555555), 0.0); // 0x402fffffffffffff 0x400123456789abcd -> 402ffffffffffffe - assertEquals(15.999999999999996, FastMath.nextDown(15.999999999999998), 0.0); + assertEquals(15.999999999999996, AccurateMath.nextDown(15.999999999999998), 0.0); // 0xc02fffffffffffff 0x400123456789abcd -> c02ffffffffffffe - assertEquals(-15.999999999999996, FastMath.nextAfter(-15.999999999999998, 2.142222222222222), 0.0); + assertEquals(-15.999999999999996, AccurateMath.nextAfter(-15.999999999999998, 2.142222222222222), 0.0); // 0x4020000000000000 0x404123456789abcd -> 4020000000000001 - assertEquals(8.000000000000002, FastMath.nextAfter(8.0, 34.27555555555555), 0.0); + assertEquals(8.000000000000002, AccurateMath.nextAfter(8.0, 34.27555555555555), 0.0); // 0xc020000000000000 0x404123456789abcd -> c01fffffffffffff - assertEquals(-7.999999999999999, FastMath.nextAfter(-8.0, 34.27555555555555), 0.0); + assertEquals(-7.999999999999999, AccurateMath.nextAfter(-8.0, 34.27555555555555), 0.0); // 0x4020000000000000 0x400123456789abcd -> 401fffffffffffff - assertEquals(7.999999999999999, FastMath.nextAfter(8.0, 2.142222222222222), 0.0); + assertEquals(7.999999999999999, AccurateMath.nextAfter(8.0, 2.142222222222222), 0.0); // 0xc020000000000000 0x400123456789abcd -> c01fffffffffffff - assertEquals(-7.999999999999999, FastMath.nextAfter(-8.0, 2.142222222222222), 0.0); + assertEquals(-7.999999999999999, AccurateMath.nextAfter(-8.0, 2.142222222222222), 0.0); // 0x3f2e43753d36a223 0x3f2e43753d36a224 -> 3f2e43753d36a224 - assertEquals(2.308922399667661E-4, FastMath.nextAfter(2.3089223996676606E-4, 2.308922399667661E-4), 0.0); + assertEquals(2.308922399667661E-4, AccurateMath.nextAfter(2.3089223996676606E-4, 2.308922399667661E-4), 0.0); // 0x3f2e43753d36a223 0x3f2e43753d36a223 -> 3f2e43753d36a223 - assertEquals(2.3089223996676606E-4, FastMath.nextAfter(2.3089223996676606E-4, 2.3089223996676606E-4), 0.0); + assertEquals(2.3089223996676606E-4, AccurateMath.nextAfter(2.3089223996676606E-4, 2.3089223996676606E-4), 0.0); // 0x3f2e43753d36a223 0x3f2e43753d36a222 -> 3f2e43753d36a222 - assertEquals(2.3089223996676603E-4, FastMath.nextAfter(2.3089223996676606E-4, 2.3089223996676603E-4), 0.0); + assertEquals(2.3089223996676603E-4, AccurateMath.nextAfter(2.3089223996676606E-4, 2.3089223996676603E-4), 0.0); // 0x3f2e43753d36a223 0xbf2e43753d36a224 -> 3f2e43753d36a222 - assertEquals(2.3089223996676603E-4, FastMath.nextAfter(2.3089223996676606E-4, -2.308922399667661E-4), 0.0); + assertEquals(2.3089223996676603E-4, AccurateMath.nextAfter(2.3089223996676606E-4, -2.308922399667661E-4), 0.0); // 0x3f2e43753d36a223 0xbf2e43753d36a223 -> 3f2e43753d36a222 - assertEquals(2.3089223996676603E-4, FastMath.nextAfter(2.3089223996676606E-4, -2.3089223996676606E-4), 0.0); + assertEquals(2.3089223996676603E-4, AccurateMath.nextAfter(2.3089223996676606E-4, -2.3089223996676606E-4), 0.0); // 0x3f2e43753d36a223 0xbf2e43753d36a222 -> 3f2e43753d36a222 - assertEquals(2.3089223996676603E-4, FastMath.nextAfter(2.3089223996676606E-4, -2.3089223996676603E-4), 0.0); + assertEquals(2.3089223996676603E-4, AccurateMath.nextAfter(2.3089223996676606E-4, -2.3089223996676603E-4), 0.0); // 0xbf2e43753d36a223 0x3f2e43753d36a224 -> bf2e43753d36a222 - assertEquals(-2.3089223996676603E-4, FastMath.nextAfter(-2.3089223996676606E-4, 2.308922399667661E-4), 0.0); + assertEquals(-2.3089223996676603E-4, AccurateMath.nextAfter(-2.3089223996676606E-4, 2.308922399667661E-4), 0.0); // 0xbf2e43753d36a223 0x3f2e43753d36a223 -> bf2e43753d36a222 - assertEquals(-2.3089223996676603E-4, FastMath.nextAfter(-2.3089223996676606E-4, 2.3089223996676606E-4), 0.0); + assertEquals(-2.3089223996676603E-4, AccurateMath.nextAfter(-2.3089223996676606E-4, 2.3089223996676606E-4), 0.0); // 0xbf2e43753d36a223 0x3f2e43753d36a222 -> bf2e43753d36a222 - assertEquals(-2.3089223996676603E-4, FastMath.nextAfter(-2.3089223996676606E-4, 2.3089223996676603E-4), 0.0); + assertEquals(-2.3089223996676603E-4, AccurateMath.nextAfter(-2.3089223996676606E-4, 2.3089223996676603E-4), 0.0); // 0xbf2e43753d36a223 0xbf2e43753d36a224 -> bf2e43753d36a224 - assertEquals(-2.308922399667661E-4, FastMath.nextAfter(-2.3089223996676606E-4, -2.308922399667661E-4), 0.0); + assertEquals(-2.308922399667661E-4, AccurateMath.nextAfter(-2.3089223996676606E-4, -2.308922399667661E-4), 0.0); // 0xbf2e43753d36a223 0xbf2e43753d36a223 -> bf2e43753d36a223 - assertEquals(-2.3089223996676606E-4, FastMath.nextAfter(-2.3089223996676606E-4, -2.3089223996676606E-4), 0.0); + assertEquals(-2.3089223996676606E-4, AccurateMath.nextAfter(-2.3089223996676606E-4, -2.3089223996676606E-4), 0.0); // 0xbf2e43753d36a223 0xbf2e43753d36a222 -> bf2e43753d36a222 - assertEquals(-2.3089223996676603E-4, FastMath.nextAfter(-2.3089223996676606E-4, -2.3089223996676603E-4), 0.0); + assertEquals(-2.3089223996676603E-4, AccurateMath.nextAfter(-2.3089223996676606E-4, -2.3089223996676603E-4), 0.0); } @Test public void testDoubleNextAfterSpecialCases() { - assertEquals(-Double.MAX_VALUE,FastMath.nextAfter(Double.NEGATIVE_INFINITY, 0D), 0D); - assertEquals(Double.MAX_VALUE,FastMath.nextAfter(Double.POSITIVE_INFINITY, 0D), 0D); - assertEquals(Double.NaN,FastMath.nextAfter(Double.NaN, 0D), 0D); - assertEquals(Double.POSITIVE_INFINITY,FastMath.nextAfter(Double.MAX_VALUE, Double.POSITIVE_INFINITY), 0D); - assertEquals(Double.NEGATIVE_INFINITY,FastMath.nextAfter(-Double.MAX_VALUE, Double.NEGATIVE_INFINITY), 0D); - assertEquals(Double.MIN_VALUE, FastMath.nextAfter(0D, 1D), 0D); - assertEquals(-Double.MIN_VALUE, FastMath.nextAfter(0D, -1D), 0D); - assertEquals(0D, FastMath.nextAfter(Double.MIN_VALUE, -1), 0D); - assertEquals(0D, FastMath.nextAfter(-Double.MIN_VALUE, 1), 0D); + assertEquals(-Double.MAX_VALUE,AccurateMath.nextAfter(Double.NEGATIVE_INFINITY, 0D), 0D); + assertEquals(Double.MAX_VALUE,AccurateMath.nextAfter(Double.POSITIVE_INFINITY, 0D), 0D); + assertEquals(Double.NaN,AccurateMath.nextAfter(Double.NaN, 0D), 0D); + assertEquals(Double.POSITIVE_INFINITY,AccurateMath.nextAfter(Double.MAX_VALUE, Double.POSITIVE_INFINITY), 0D); + assertEquals(Double.NEGATIVE_INFINITY,AccurateMath.nextAfter(-Double.MAX_VALUE, Double.NEGATIVE_INFINITY), 0D); + assertEquals(Double.MIN_VALUE, AccurateMath.nextAfter(0D, 1D), 0D); + assertEquals(-Double.MIN_VALUE, AccurateMath.nextAfter(0D, -1D), 0D); + assertEquals(0D, AccurateMath.nextAfter(Double.MIN_VALUE, -1), 0D); + assertEquals(0D, AccurateMath.nextAfter(-Double.MIN_VALUE, 1), 0D); } @Test public void testFloatNextAfterSpecialCases() { - assertEquals(-Float.MAX_VALUE, FastMath.nextAfter(Float.NEGATIVE_INFINITY, 0F), 0F); - assertEquals(Float.MAX_VALUE, FastMath.nextAfter(Float.POSITIVE_INFINITY, 0F), 0F); - assertEquals(Float.NaN, FastMath.nextAfter(Float.NaN, 0F), 0F); - assertEquals(Float.POSITIVE_INFINITY, FastMath.nextUp(Float.MAX_VALUE), 0F); - assertEquals(Float.NEGATIVE_INFINITY, FastMath.nextDown(-Float.MAX_VALUE), 0F); - assertEquals(Float.MIN_VALUE, FastMath.nextAfter(0F, 1F), 0F); - assertEquals(-Float.MIN_VALUE, FastMath.nextAfter(0F, -1F), 0F); - assertEquals(0F, FastMath.nextAfter(Float.MIN_VALUE, -1F), 0F); - assertEquals(0F, FastMath.nextAfter(-Float.MIN_VALUE, 1F), 0F); + assertEquals(-Float.MAX_VALUE, AccurateMath.nextAfter(Float.NEGATIVE_INFINITY, 0F), 0F); + assertEquals(Float.MAX_VALUE, AccurateMath.nextAfter(Float.POSITIVE_INFINITY, 0F), 0F); + assertEquals(Float.NaN, AccurateMath.nextAfter(Float.NaN, 0F), 0F); + assertEquals(Float.POSITIVE_INFINITY, AccurateMath.nextUp(Float.MAX_VALUE), 0F); + assertEquals(Float.NEGATIVE_INFINITY, AccurateMath.nextDown(-Float.MAX_VALUE), 0F); + assertEquals(Float.MIN_VALUE, AccurateMath.nextAfter(0F, 1F), 0F); + assertEquals(-Float.MIN_VALUE, AccurateMath.nextAfter(0F, -1F), 0F); + assertEquals(0F, AccurateMath.nextAfter(Float.MIN_VALUE, -1F), 0F); + assertEquals(0F, AccurateMath.nextAfter(-Float.MIN_VALUE, 1F), 0F); } @Test public void testDoubleScalbSpecialCases() { - assertEquals(2.5269841324701218E-175, FastMath.scalb(2.2250738585072014E-308, 442), 0D); - assertEquals(1.307993905256674E297, FastMath.scalb(1.1102230246251565E-16, 1040), 0D); - assertEquals(7.2520887996488946E-217, FastMath.scalb(Double.MIN_VALUE, 356), 0D); - assertEquals(8.98846567431158E307, FastMath.scalb(Double.MIN_VALUE, 2097), 0D); - assertEquals(Double.POSITIVE_INFINITY, FastMath.scalb(Double.MIN_VALUE, 2098), 0D); - assertEquals(1.1125369292536007E-308, FastMath.scalb(2.225073858507201E-308, -1), 0D); - assertEquals(1.0E-323, FastMath.scalb(Double.MAX_VALUE, -2097), 0D); - assertEquals(Double.MIN_VALUE, FastMath.scalb(Double.MAX_VALUE, -2098), 0D); - assertEquals(0, FastMath.scalb(Double.MAX_VALUE, -2099), 0D); - assertEquals(Double.POSITIVE_INFINITY, FastMath.scalb(Double.POSITIVE_INFINITY, -1000000), 0D); - assertEquals(Double.NEGATIVE_INFINITY, FastMath.scalb(-1.1102230246251565E-16, 1078), 0D); - assertEquals(Double.NEGATIVE_INFINITY, FastMath.scalb(-1.1102230246251565E-16, 1079), 0D); - assertEquals(Double.NEGATIVE_INFINITY, FastMath.scalb(-2.2250738585072014E-308, 2047), 0D); - assertEquals(Double.NEGATIVE_INFINITY, FastMath.scalb(-2.2250738585072014E-308, 2048), 0D); - assertEquals(Double.NEGATIVE_INFINITY, FastMath.scalb(-1.7976931348623157E308, 2147483647), 0D); - assertEquals(Double.POSITIVE_INFINITY, FastMath.scalb( 1.7976931348623157E308, 2147483647), 0D); - assertEquals(Double.NEGATIVE_INFINITY, FastMath.scalb(-1.1102230246251565E-16, 2147483647), 0D); - assertEquals(Double.POSITIVE_INFINITY, FastMath.scalb( 1.1102230246251565E-16, 2147483647), 0D); - assertEquals(Double.NEGATIVE_INFINITY, FastMath.scalb(-2.2250738585072014E-308, 2147483647), 0D); - assertEquals(Double.POSITIVE_INFINITY, FastMath.scalb( 2.2250738585072014E-308, 2147483647), 0D); + assertEquals(2.5269841324701218E-175, AccurateMath.scalb(2.2250738585072014E-308, 442), 0D); + assertEquals(1.307993905256674E297, AccurateMath.scalb(1.1102230246251565E-16, 1040), 0D); + assertEquals(7.2520887996488946E-217, AccurateMath.scalb(Double.MIN_VALUE, 356), 0D); + assertEquals(8.98846567431158E307, AccurateMath.scalb(Double.MIN_VALUE, 2097), 0D); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.scalb(Double.MIN_VALUE, 2098), 0D); + assertEquals(1.1125369292536007E-308, AccurateMath.scalb(2.225073858507201E-308, -1), 0D); + assertEquals(1.0E-323, AccurateMath.scalb(Double.MAX_VALUE, -2097), 0D); + assertEquals(Double.MIN_VALUE, AccurateMath.scalb(Double.MAX_VALUE, -2098), 0D); + assertEquals(0, AccurateMath.scalb(Double.MAX_VALUE, -2099), 0D); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.scalb(Double.POSITIVE_INFINITY, -1000000), 0D); + assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-1.1102230246251565E-16, 1078), 0D); + assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-1.1102230246251565E-16, 1079), 0D); + assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-2.2250738585072014E-308, 2047), 0D); + assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-2.2250738585072014E-308, 2048), 0D); + assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-1.7976931348623157E308, 2147483647), 0D); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.scalb( 1.7976931348623157E308, 2147483647), 0D); + assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-1.1102230246251565E-16, 2147483647), 0D); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.scalb( 1.1102230246251565E-16, 2147483647), 0D); + assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.scalb(-2.2250738585072014E-308, 2147483647), 0D); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.scalb( 2.2250738585072014E-308, 2147483647), 0D); } @Test public void testFloatScalbSpecialCases() { - assertEquals(0f, FastMath.scalb(Float.MIN_VALUE, -30), 0F); - assertEquals(2 * Float.MIN_VALUE, FastMath.scalb(Float.MIN_VALUE, 1), 0F); - assertEquals(7.555786e22f, FastMath.scalb(Float.MAX_VALUE, -52), 0F); - assertEquals(1.7014118e38f, FastMath.scalb(Float.MIN_VALUE, 276), 0F); - assertEquals(Float.POSITIVE_INFINITY, FastMath.scalb(Float.MIN_VALUE, 277), 0F); - assertEquals(5.8774718e-39f, FastMath.scalb(1.1754944e-38f, -1), 0F); - assertEquals(2 * Float.MIN_VALUE, FastMath.scalb(Float.MAX_VALUE, -276), 0F); - assertEquals(Float.MIN_VALUE, FastMath.scalb(Float.MAX_VALUE, -277), 0F); - assertEquals(0, FastMath.scalb(Float.MAX_VALUE, -278), 0F); - assertEquals(Float.POSITIVE_INFINITY, FastMath.scalb(Float.POSITIVE_INFINITY, -1000000), 0F); - assertEquals(-3.13994498e38f, FastMath.scalb(-1.1e-7f, 151), 0F); - assertEquals(Float.NEGATIVE_INFINITY, FastMath.scalb(-1.1e-7f, 152), 0F); - assertEquals(Float.POSITIVE_INFINITY, FastMath.scalb(3.4028235E38f, 2147483647), 0F); - assertEquals(Float.NEGATIVE_INFINITY, FastMath.scalb(-3.4028235E38f, 2147483647), 0F); + assertEquals(0f, AccurateMath.scalb(Float.MIN_VALUE, -30), 0F); + assertEquals(2 * Float.MIN_VALUE, AccurateMath.scalb(Float.MIN_VALUE, 1), 0F); + assertEquals(7.555786e22f, AccurateMath.scalb(Float.MAX_VALUE, -52), 0F); + assertEquals(1.7014118e38f, AccurateMath.scalb(Float.MIN_VALUE, 276), 0F); + assertEquals(Float.POSITIVE_INFINITY, AccurateMath.scalb(Float.MIN_VALUE, 277), 0F); + assertEquals(5.8774718e-39f, AccurateMath.scalb(1.1754944e-38f, -1), 0F); + assertEquals(2 * Float.MIN_VALUE, AccurateMath.scalb(Float.MAX_VALUE, -276), 0F); + assertEquals(Float.MIN_VALUE, AccurateMath.scalb(Float.MAX_VALUE, -277), 0F); + assertEquals(0, AccurateMath.scalb(Float.MAX_VALUE, -278), 0F); + assertEquals(Float.POSITIVE_INFINITY, AccurateMath.scalb(Float.POSITIVE_INFINITY, -1000000), 0F); + assertEquals(-3.13994498e38f, AccurateMath.scalb(-1.1e-7f, 151), 0F); + assertEquals(Float.NEGATIVE_INFINITY, AccurateMath.scalb(-1.1e-7f, 152), 0F); + assertEquals(Float.POSITIVE_INFINITY, AccurateMath.scalb(3.4028235E38f, 2147483647), 0F); + assertEquals(Float.NEGATIVE_INFINITY, AccurateMath.scalb(-3.4028235E38f, 2147483647), 0F); } private boolean compareClassMethods(Class class1, Class class2){ @@ -1270,68 +1270,68 @@ public class FastMathTest { } @Test - public void checkMissingFastMathClasses() { - boolean ok = compareClassMethods(StrictMath.class, FastMath.class); - assertTrue("FastMath should implement all StrictMath methods", ok); + public void checkMissingAccurateMathClasses() { + boolean ok = compareClassMethods(StrictMath.class, AccurateMath.class); + assertTrue("AccurateMath should implement all StrictMath methods", ok); } @Ignore @Test - public void checkExtraFastMathClasses() { - compareClassMethods(FastMath.class, StrictMath.class); + public void checkExtraAccurateMathClasses() { + compareClassMethods(AccurateMath.class, StrictMath.class); } @Test public void testSignumDouble() { final double delta = 0.0; - assertEquals(1.0, FastMath.signum(2.0), delta); - assertEquals(0.0, FastMath.signum(0.0), delta); - assertEquals(-1.0, FastMath.signum(-2.0), delta); - TestUtils.assertSame(-0. / 0., FastMath.signum(Double.NaN)); + assertEquals(1.0, AccurateMath.signum(2.0), delta); + assertEquals(0.0, AccurateMath.signum(0.0), delta); + assertEquals(-1.0, AccurateMath.signum(-2.0), delta); + TestUtils.assertSame(-0. / 0., AccurateMath.signum(Double.NaN)); } @Test public void testSignumFloat() { final float delta = 0.0F; - assertEquals(1.0F, FastMath.signum(2.0F), delta); - assertEquals(0.0F, FastMath.signum(0.0F), delta); - assertEquals(-1.0F, FastMath.signum(-2.0F), delta); - TestUtils.assertSame(Float.NaN, FastMath.signum(Float.NaN)); + assertEquals(1.0F, AccurateMath.signum(2.0F), delta); + assertEquals(0.0F, AccurateMath.signum(0.0F), delta); + assertEquals(-1.0F, AccurateMath.signum(-2.0F), delta); + TestUtils.assertSame(Float.NaN, AccurateMath.signum(Float.NaN)); } @Test public void testLogWithBase() { - assertEquals(2.0, FastMath.log(2, 4), 0); - assertEquals(3.0, FastMath.log(2, 8), 0); - assertTrue(Double.isNaN(FastMath.log(-1, 1))); - assertTrue(Double.isNaN(FastMath.log(1, -1))); - assertTrue(Double.isNaN(FastMath.log(0, 0))); - assertEquals(0, FastMath.log(0, 10), 0); - assertEquals(Double.NEGATIVE_INFINITY, FastMath.log(10, 0), 0); + assertEquals(2.0, AccurateMath.log(2, 4), 0); + assertEquals(3.0, AccurateMath.log(2, 8), 0); + assertTrue(Double.isNaN(AccurateMath.log(-1, 1))); + assertTrue(Double.isNaN(AccurateMath.log(1, -1))); + assertTrue(Double.isNaN(AccurateMath.log(0, 0))); + assertEquals(0, AccurateMath.log(0, 10), 0); + assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.log(10, 0), 0); } @Test public void testIndicatorDouble() { double delta = 0.0; - assertEquals(1.0, FastMath.copySign(1d, 2.0), delta); - assertEquals(1.0, FastMath.copySign(1d, 0.0), delta); - assertEquals(-1.0, FastMath.copySign(1d, -0.0), delta); - assertEquals(1.0, FastMath.copySign(1d, Double.POSITIVE_INFINITY), delta); - assertEquals(-1.0, FastMath.copySign(1d, Double.NEGATIVE_INFINITY), delta); - assertEquals(1.0, FastMath.copySign(1d, Double.NaN), delta); - assertEquals(-1.0, FastMath.copySign(1d, -2.0), delta); + assertEquals(1.0, AccurateMath.copySign(1d, 2.0), delta); + assertEquals(1.0, AccurateMath.copySign(1d, 0.0), delta); + assertEquals(-1.0, AccurateMath.copySign(1d, -0.0), delta); + assertEquals(1.0, AccurateMath.copySign(1d, Double.POSITIVE_INFINITY), delta); + assertEquals(-1.0, AccurateMath.copySign(1d, Double.NEGATIVE_INFINITY), delta); + assertEquals(1.0, AccurateMath.copySign(1d, Double.NaN), delta); + assertEquals(-1.0, AccurateMath.copySign(1d, -2.0), delta); } @Test public void testIndicatorFloat() { float delta = 0.0F; - assertEquals(1.0F, FastMath.copySign(1d, 2.0F), delta); - assertEquals(1.0F, FastMath.copySign(1d, 0.0F), delta); - assertEquals(-1.0F, FastMath.copySign(1d, -0.0F), delta); - assertEquals(1.0F, FastMath.copySign(1d, Float.POSITIVE_INFINITY), delta); - assertEquals(-1.0F, FastMath.copySign(1d, Float.NEGATIVE_INFINITY), delta); - assertEquals(1.0F, FastMath.copySign(1d, Float.NaN), delta); - assertEquals(-1.0F, FastMath.copySign(1d, -2.0F), delta); + assertEquals(1.0F, AccurateMath.copySign(1d, 2.0F), delta); + assertEquals(1.0F, AccurateMath.copySign(1d, 0.0F), delta); + assertEquals(-1.0F, AccurateMath.copySign(1d, -0.0F), delta); + assertEquals(1.0F, AccurateMath.copySign(1d, Float.POSITIVE_INFINITY), delta); + assertEquals(-1.0F, AccurateMath.copySign(1d, Float.NEGATIVE_INFINITY), delta); + assertEquals(1.0F, AccurateMath.copySign(1d, Float.NaN), delta); + assertEquals(-1.0F, AccurateMath.copySign(1d, -2.0F), delta); } @Test @@ -1342,20 +1342,20 @@ public class FastMathTest { Dfp baseDfp = field.newDfp(base); Dfp dfpPower = field.getOne(); for (int i = 0; i < maxExp; i++) { - assertEquals("exp=" + i, dfpPower.toDouble(), FastMath.pow(base, i), - 0.6 * FastMath.ulp(dfpPower.toDouble())); + assertEquals("exp=" + i, dfpPower.toDouble(), AccurateMath.pow(base, i), + 0.6 * AccurateMath.ulp(dfpPower.toDouble())); dfpPower = dfpPower.multiply(baseDfp); } } @Test public void testIntPowHuge() { - assertTrue(Double.isInfinite(FastMath.pow(FastMath.scalb(1.0, 500), 4))); + assertTrue(Double.isInfinite(AccurateMath.pow(AccurateMath.scalb(1.0, 500), 4))); } @Test(timeout=5000L) // This test must finish in finite time. public void testIntPowLongMinValue() { - assertEquals(1.0, FastMath.pow(1.0, Long.MIN_VALUE), -1.0); + assertEquals(1.0, AccurateMath.pow(1.0, Long.MIN_VALUE), -1.0); } @Test(timeout=5000L) @@ -1378,63 +1378,63 @@ public class FastMathTest { // Special cases from Math.pow javadoc: // If the second argument is positive or negative zero, then the result is 1.0. for (double d : DOUBLES) { - assertEquals(1.0, FastMath.pow(d, 0L), EXACT); + assertEquals(1.0, AccurateMath.pow(d, 0L), EXACT); } // If the second argument is 1.0, then the result is the same as the first argument. for (double d : DOUBLES) { - assertEquals(d, FastMath.pow(d, 1L), EXACT); + assertEquals(d, AccurateMath.pow(d, 1L), EXACT); } // If the second argument is NaN, then the result is NaN. <- Impossible with int. // If the first argument is NaN and the second argument is nonzero, then the result is NaN. for (long i : INTS) { if (i != 0L) { - assertEquals(Double.NaN, FastMath.pow(Double.NaN, i), EXACT); + assertEquals(Double.NaN, AccurateMath.pow(Double.NaN, i), EXACT); } } // If the absolute value of the first argument is greater than 1 and the second argument is positive infinity, or // the absolute value of the first argument is less than 1 and the second argument is negative infinity, then the result is positive infinity. for (double d : DOUBLES) { if (Math.abs(d) > 1.0) { - assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(d, Long.MAX_VALUE - 1L), EXACT); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(d, Long.MAX_VALUE - 1L), EXACT); } } for (double d : DOUBLES) { if (Math.abs(d) < 1.0) { - assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(d, Long.MIN_VALUE), EXACT); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(d, Long.MIN_VALUE), EXACT); } } // Note: Long.MAX_VALUE isn't actually an infinity, so its parity affects the sign of resulting infinity. for (double d : DOUBLES) { if (Math.abs(d) > 1.0) { - assertTrue(Double.isInfinite(FastMath.pow(d, Long.MAX_VALUE))); + assertTrue(Double.isInfinite(AccurateMath.pow(d, Long.MAX_VALUE))); } } for (double d : DOUBLES) { if (Math.abs(d) < 1.0) { - assertTrue(Double.isInfinite(FastMath.pow(d, Long.MIN_VALUE + 1L))); + assertTrue(Double.isInfinite(AccurateMath.pow(d, Long.MIN_VALUE + 1L))); } } // If the absolute value of the first argument is greater than 1 and the second argument is negative infinity, or // the absolute value of the first argument is less than 1 and the second argument is positive infinity, then the result is positive zero. for (double d : DOUBLES) { if (Math.abs(d) > 1.0) { - assertEquals(0.0, FastMath.pow(d, Long.MIN_VALUE), EXACT); + assertEquals(0.0, AccurateMath.pow(d, Long.MIN_VALUE), EXACT); } } for (double d : DOUBLES) { if (Math.abs(d) < 1.0) { - assertEquals(0.0, FastMath.pow(d, Long.MAX_VALUE - 1L), EXACT); + assertEquals(0.0, AccurateMath.pow(d, Long.MAX_VALUE - 1L), EXACT); } } // Note: Long.MAX_VALUE isn't actually an infinity, so its parity affects the sign of resulting zero. for (double d : DOUBLES) { if (Math.abs(d) > 1.0) { - assertTrue(FastMath.pow(d, Long.MIN_VALUE + 1L) == 0.0); + assertTrue(AccurateMath.pow(d, Long.MIN_VALUE + 1L) == 0.0); } } for (double d : DOUBLES) { if (Math.abs(d) < 1.0) { - assertTrue(FastMath.pow(d, Long.MAX_VALUE) == 0.0); + assertTrue(AccurateMath.pow(d, Long.MAX_VALUE) == 0.0); } } // If the absolute value of the first argument equals 1 and the second argument is infinite, then the result is NaN. <- Impossible with int. @@ -1442,72 +1442,72 @@ public class FastMathTest { // the first argument is positive infinity and the second argument is less than zero, then the result is positive zero. for (long i : INTS) { if (i > 0L) { - assertEquals(0.0, FastMath.pow(0.0, i), EXACT); + assertEquals(0.0, AccurateMath.pow(0.0, i), EXACT); } } for (long i : INTS) { if (i < 0L) { - assertEquals(0.0, FastMath.pow(Double.POSITIVE_INFINITY, i), EXACT); + assertEquals(0.0, AccurateMath.pow(Double.POSITIVE_INFINITY, i), EXACT); } } // If the first argument is positive zero and the second argument is less than zero, or // the first argument is positive infinity and the second argument is greater than zero, then the result is positive infinity. for (long i : INTS) { if (i < 0L) { - assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(0.0, i), EXACT); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(0.0, i), EXACT); } } for (long i : INTS) { if (i > 0L) { - assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(Double.POSITIVE_INFINITY, i), EXACT); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(Double.POSITIVE_INFINITY, i), EXACT); } } // If the first argument is negative zero and the second argument is greater than zero but not a finite odd integer, or // the first argument is negative infinity and the second argument is less than zero but not a finite odd integer, then the result is positive zero. for (long i : INTS) { if (i > 0L && (i & 1L) == 0L) { - assertEquals(0.0, FastMath.pow(-0.0, i), EXACT); + assertEquals(0.0, AccurateMath.pow(-0.0, i), EXACT); } } for (long i : INTS) { if (i < 0L && (i & 1L) == 0L) { - assertEquals(0.0, FastMath.pow(Double.NEGATIVE_INFINITY, i), EXACT); + assertEquals(0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT); } } // If the first argument is negative zero and the second argument is a positive finite odd integer, or // the first argument is negative infinity and the second argument is a negative finite odd integer, then the result is negative zero. for (long i : INTS) { if (i > 0L && (i & 1L) == 1L) { - assertEquals(-0.0, FastMath.pow(-0.0, i), EXACT); + assertEquals(-0.0, AccurateMath.pow(-0.0, i), EXACT); } } for (long i : INTS) { if (i < 0L && (i & 1L) == 1L) { - assertEquals(-0.0, FastMath.pow(Double.NEGATIVE_INFINITY, i), EXACT); + assertEquals(-0.0, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT); } } // If the first argument is negative zero and the second argument is less than zero but not a finite odd integer, or // the first argument is negative infinity and the second argument is greater than zero but not a finite odd integer, then the result is positive infinity. for (long i : INTS) { if (i > 0L && (i & 1L) == 0L) { - assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(Double.NEGATIVE_INFINITY, i), EXACT); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT); } } for (long i : INTS) { if (i < 0L && (i & 1L) == 0L) { - assertEquals(Double.POSITIVE_INFINITY, FastMath.pow(-0.0, i), EXACT); + assertEquals(Double.POSITIVE_INFINITY, AccurateMath.pow(-0.0, i), EXACT); } } // If the first argument is negative zero and the second argument is a negative finite odd integer, or // the first argument is negative infinity and the second argument is a positive finite odd integer, then the result is negative infinity. for (long i : INTS) { if (i > 0L && (i & 1L) == 1L) { - assertEquals(Double.NEGATIVE_INFINITY, FastMath.pow(Double.NEGATIVE_INFINITY, i), EXACT); + assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.pow(Double.NEGATIVE_INFINITY, i), EXACT); } } for (long i : INTS) { if (i < 0L && (i & 1L) == 1L) { - assertEquals(Double.NEGATIVE_INFINITY, FastMath.pow(-0.0, i), EXACT); + assertEquals(Double.NEGATIVE_INFINITY, AccurateMath.pow(-0.0, i), EXACT); } } for (double d : DOUBLES) { @@ -1515,9 +1515,9 @@ public class FastMathTest { if (d < 0.0 && Math.abs(d) <= Double.MAX_VALUE) { for (long i : INTS) { // if the second argument is a finite even integer, the result is equal to the result of raising the absolute value of the first argument to the power of the second argument - if ((i & 1L) == 0L) assertEquals(FastMath.pow(-d, i), FastMath.pow(d, i), EXACT); + if ((i & 1L) == 0L) assertEquals(AccurateMath.pow(-d, i), AccurateMath.pow(d, i), EXACT); // if the second argument is a finite odd integer, the result is equal to the negative of the result of raising the absolute value of the first argument to the power of the second argument - else assertEquals(-FastMath.pow(-d, i), FastMath.pow(d, i), EXACT); + else assertEquals(-AccurateMath.pow(-d, i), AccurateMath.pow(d, i), EXACT); // if the second argument is finite and not an integer, then the result is NaN. <- Impossible with int. } } @@ -1541,13 +1541,13 @@ public class FastMathTest { if (bdSum.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0 || bdSum.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) { try { - FastMath.incrementExact(a); + AccurateMath.incrementExact(a); Assert.fail("an exception should have been thrown"); } catch (MathArithmeticException mae) { // expected } } else { - assertEquals(bdSum, BigInteger.valueOf(FastMath.incrementExact(a))); + assertEquals(bdSum, BigInteger.valueOf(AccurateMath.incrementExact(a))); } } } @@ -1567,13 +1567,13 @@ public class FastMathTest { if (bdSub.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0 || bdSub.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) { try { - FastMath.decrementExact(a); + AccurateMath.decrementExact(a); fail("an exception should have been thrown"); } catch (MathArithmeticException mae) { // expected } } else { - assertEquals(bdSub, BigInteger.valueOf(FastMath.decrementExact(a))); + assertEquals(bdSub, BigInteger.valueOf(AccurateMath.decrementExact(a))); } } } @@ -1595,13 +1595,13 @@ public class FastMathTest { if (bdSum.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0 || bdSum.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) { try { - FastMath.addExact(a, b); + AccurateMath.addExact(a, b); fail("an exception should have been thrown"); } catch (MathArithmeticException mae) { // expected } } else { - assertEquals(bdSum, BigInteger.valueOf(FastMath.addExact(a, b))); + assertEquals(bdSum, BigInteger.valueOf(AccurateMath.addExact(a, b))); } } } @@ -1624,13 +1624,13 @@ public class FastMathTest { if (bdSum.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < 0 || bdSum.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) { try { - FastMath.addExact(a, b); + AccurateMath.addExact(a, b); fail("an exception should have been thrown"); } catch (MathArithmeticException mae) { // expected } } else { - assertEquals(bdSum, BigInteger.valueOf(FastMath.addExact(a, b))); + assertEquals(bdSum, BigInteger.valueOf(AccurateMath.addExact(a, b))); } } } @@ -1653,13 +1653,13 @@ public class FastMathTest { if (bdSub.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0 || bdSub.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) { try { - FastMath.subtractExact(a, b); + AccurateMath.subtractExact(a, b); fail("an exception should have been thrown"); } catch (MathArithmeticException mae) { // expected } } else { - assertEquals(bdSub, BigInteger.valueOf(FastMath.subtractExact(a, b))); + assertEquals(bdSub, BigInteger.valueOf(AccurateMath.subtractExact(a, b))); } } } @@ -1682,13 +1682,13 @@ public class FastMathTest { if (bdSub.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < 0 || bdSub.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) { try { - FastMath.subtractExact(a, b); + AccurateMath.subtractExact(a, b); fail("an exception should have been thrown"); } catch (MathArithmeticException mae) { // expected } } else { - assertEquals(bdSub, BigInteger.valueOf(FastMath.subtractExact(a, b))); + assertEquals(bdSub, BigInteger.valueOf(AccurateMath.subtractExact(a, b))); } } } @@ -1711,13 +1711,13 @@ public class FastMathTest { if (bdMul.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0 || bdMul.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) { try { - FastMath.multiplyExact(a, b); + AccurateMath.multiplyExact(a, b); fail("an exception should have been thrown " + a + b); } catch (MathArithmeticException mae) { // expected } } else { - assertEquals(bdMul, BigInteger.valueOf(FastMath.multiplyExact(a, b))); + assertEquals(bdMul, BigInteger.valueOf(AccurateMath.multiplyExact(a, b))); } } } @@ -1740,13 +1740,13 @@ public class FastMathTest { if (bdMul.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < 0 || bdMul.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) { try { - FastMath.multiplyExact(a, b); + AccurateMath.multiplyExact(a, b); fail("an exception should have been thrown " + a + b); } catch (MathArithmeticException mae) { // expected } } else { - assertEquals(bdMul, BigInteger.valueOf(FastMath.multiplyExact(a, b))); + assertEquals(bdMul, BigInteger.valueOf(AccurateMath.multiplyExact(a, b))); } } } @@ -1754,31 +1754,31 @@ public class FastMathTest { @Test(expected=MathArithmeticException.class) public void testToIntExactTooLow() { - FastMath.toIntExact(-1l + Integer.MIN_VALUE); + AccurateMath.toIntExact(-1l + Integer.MIN_VALUE); } @Test(expected=MathArithmeticException.class) public void testToIntExactTooHigh() { - FastMath.toIntExact(+1l + Integer.MAX_VALUE); + AccurateMath.toIntExact(+1l + Integer.MAX_VALUE); } @Test public void testToIntExact() { for (int n = -1000; n < 1000; ++n) { - assertEquals(n, FastMath.toIntExact(0l + n)); + assertEquals(n, AccurateMath.toIntExact(0l + n)); } - assertEquals(Integer.MIN_VALUE, FastMath.toIntExact(0l + Integer.MIN_VALUE)); - assertEquals(Integer.MAX_VALUE, FastMath.toIntExact(0l + Integer.MAX_VALUE)); + assertEquals(Integer.MIN_VALUE, AccurateMath.toIntExact(0l + Integer.MIN_VALUE)); + assertEquals(Integer.MAX_VALUE, AccurateMath.toIntExact(0l + Integer.MAX_VALUE)); } @Test public void testFloorDivInt() { - assertEquals(+1, FastMath.floorDiv(+4, +3)); - assertEquals(-2, FastMath.floorDiv(-4, +3)); - assertEquals(-2, FastMath.floorDiv(+4, -3)); - assertEquals(+1, FastMath.floorDiv(-4, -3)); + assertEquals(+1, AccurateMath.floorDiv(+4, +3)); + assertEquals(-2, AccurateMath.floorDiv(-4, +3)); + assertEquals(-2, AccurateMath.floorDiv(+4, -3)); + assertEquals(+1, AccurateMath.floorDiv(-4, -3)); try { - FastMath.floorDiv(1, 0); + AccurateMath.floorDiv(1, 0); fail("an exception should have been thrown"); } catch (MathArithmeticException mae) { // expected @@ -1786,7 +1786,7 @@ public class FastMathTest { for (int a = -100; a <= 100; ++a) { for (int b = -100; b <= 100; ++b) { if (b != 0) { - assertEquals(poorManFloorDiv(a, b), FastMath.floorDiv(a, b)); + assertEquals(poorManFloorDiv(a, b), AccurateMath.floorDiv(a, b)); } } } @@ -1794,12 +1794,12 @@ public class FastMathTest { @Test public void testFloorModInt() { - assertEquals(+1, FastMath.floorMod(+4, +3)); - assertEquals(+2, FastMath.floorMod(-4, +3)); - assertEquals(-2, FastMath.floorMod(+4, -3)); - assertEquals(-1, FastMath.floorMod(-4, -3)); + assertEquals(+1, AccurateMath.floorMod(+4, +3)); + assertEquals(+2, AccurateMath.floorMod(-4, +3)); + assertEquals(-2, AccurateMath.floorMod(+4, -3)); + assertEquals(-1, AccurateMath.floorMod(-4, -3)); try { - FastMath.floorMod(1, 0); + AccurateMath.floorMod(1, 0); fail("an exception should have been thrown"); } catch (MathArithmeticException mae) { // expected @@ -1807,7 +1807,7 @@ public class FastMathTest { for (int a = -100; a <= 100; ++a) { for (int b = -100; b <= 100; ++b) { if (b != 0) { - assertEquals(poorManFloorMod(a, b), FastMath.floorMod(a, b)); + assertEquals(poorManFloorMod(a, b), AccurateMath.floorMod(a, b)); } } } @@ -1822,16 +1822,16 @@ public class FastMathTest { int b = generator.nextInt(); if (b == 0) { try { - FastMath.floorDiv(a, b); + AccurateMath.floorDiv(a, b); fail("an exception should have been thrown"); } catch (MathArithmeticException mae) { // expected } } else { - int d = FastMath.floorDiv(a, b); - int m = FastMath.floorMod(a, b); - assertEquals(FastMath.toIntExact(poorManFloorDiv(a, b)), d); - assertEquals(FastMath.toIntExact(poorManFloorMod(a, b)), m); + int d = AccurateMath.floorDiv(a, b); + int m = AccurateMath.floorMod(a, b); + assertEquals(AccurateMath.toIntExact(poorManFloorDiv(a, b)), d); + assertEquals(AccurateMath.toIntExact(poorManFloorMod(a, b)), m); assertEquals(a, d * b + m); if (b < 0) { assertTrue(m <= 0); @@ -1846,12 +1846,12 @@ public class FastMathTest { @Test public void testFloorDivLong() { - assertEquals(+1l, FastMath.floorDiv(+4l, +3l)); - assertEquals(-2l, FastMath.floorDiv(-4l, +3l)); - assertEquals(-2l, FastMath.floorDiv(+4l, -3l)); - assertEquals(+1l, FastMath.floorDiv(-4l, -3l)); + assertEquals(+1l, AccurateMath.floorDiv(+4l, +3l)); + assertEquals(-2l, AccurateMath.floorDiv(-4l, +3l)); + assertEquals(-2l, AccurateMath.floorDiv(+4l, -3l)); + assertEquals(+1l, AccurateMath.floorDiv(-4l, -3l)); try { - FastMath.floorDiv(1l, 0l); + AccurateMath.floorDiv(1l, 0l); fail("an exception should have been thrown"); } catch (MathArithmeticException mae) { // expected @@ -1859,7 +1859,7 @@ public class FastMathTest { for (long a = -100l; a <= 100l; ++a) { for (long b = -100l; b <= 100l; ++b) { if (b != 0) { - assertEquals(poorManFloorDiv(a, b), FastMath.floorDiv(a, b)); + assertEquals(poorManFloorDiv(a, b), AccurateMath.floorDiv(a, b)); } } } @@ -1867,12 +1867,12 @@ public class FastMathTest { @Test public void testFloorModLong() { - assertEquals(+1l, FastMath.floorMod(+4l, +3l)); - assertEquals(+2l, FastMath.floorMod(-4l, +3l)); - assertEquals(-2l, FastMath.floorMod(+4l, -3l)); - assertEquals(-1l, FastMath.floorMod(-4l, -3l)); + assertEquals(+1l, AccurateMath.floorMod(+4l, +3l)); + assertEquals(+2l, AccurateMath.floorMod(-4l, +3l)); + assertEquals(-2l, AccurateMath.floorMod(+4l, -3l)); + assertEquals(-1l, AccurateMath.floorMod(-4l, -3l)); try { - FastMath.floorMod(1l, 0l); + AccurateMath.floorMod(1l, 0l); fail("an exception should have been thrown"); } catch (MathArithmeticException mae) { // expected @@ -1880,7 +1880,7 @@ public class FastMathTest { for (long a = -100l; a <= 100l; ++a) { for (long b = -100l; b <= 100l; ++b) { if (b != 0) { - assertEquals(poorManFloorMod(a, b), FastMath.floorMod(a, b)); + assertEquals(poorManFloorMod(a, b), AccurateMath.floorMod(a, b)); } } } @@ -1895,14 +1895,14 @@ public class FastMathTest { long b = generator.nextLong(); if (b == 0) { try { - FastMath.floorDiv(a, b); + AccurateMath.floorDiv(a, b); fail("an exception should have been thrown"); } catch (MathArithmeticException mae) { // expected } } else { - long d = FastMath.floorDiv(a, b); - long m = FastMath.floorMod(a, b); + long d = AccurateMath.floorDiv(a, b); + long m = AccurateMath.floorMod(a, b); assertEquals(poorManFloorDiv(a, b), d); assertEquals(poorManFloorMod(a, b), m); assertEquals(a, d * b + m); @@ -1953,12 +1953,12 @@ public class FastMathTest { public void testRoundDown() { double x = 0x1.fffffffffffffp-2; // greatest floating point value less than 0.5 assertTrue(x < 0.5d); - assertEquals(0, FastMath.round(x)); + assertEquals(0, AccurateMath.round(x)); x = 4503599627370497.0; // x = Math.pow(2, 52) + 1; assertEquals("4503599627370497", new BigDecimal(x).toString()); assertTrue(x == Math.rint(x)); - assertTrue(x == FastMath.round(x)); + assertTrue(x == AccurateMath.round(x)); //assertTrue(x == Math.round(x)); // fails with Java 7, fixed in Java 8 } diff --git a/commons-math-legacy/pom.xml b/commons-math-legacy/pom.xml index 56876b380..33504221b 100644 --- a/commons-math-legacy/pom.xml +++ b/commons-math-legacy/pom.xml @@ -116,12 +116,12 @@ org.apache.commons - commons-rng-sampling + commons-math4-legacy-exception org.apache.commons - commons-math4-legacy-exception + commons-math4-legacy-core diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/RealFieldUnivariateFunction.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/RealFieldUnivariateFunction.java index e08744c17..5c0a9a390 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/RealFieldUnivariateFunction.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/RealFieldUnivariateFunction.java @@ -16,7 +16,7 @@ */ package org.apache.commons.math4.legacy.analysis; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.RealFieldElement; /** * An interface representing a univariate real function. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/DSCompiler.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/DSCompiler.java index 6310c1fe8..646d85549 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/DSCompiler.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/DSCompiler.java @@ -28,7 +28,7 @@ import org.apache.commons.math4.legacy.exception.MathInternalError; import org.apache.commons.math4.legacy.exception.NotPositiveException; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; import org.apache.commons.numbers.combinatorics.FactorialDouble; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** Class holding "compiled" computation rules for derivative structures. *

This class implements the computation rules described in Dan Kalman's paper 0; --i) { function[i] = xk; xk *= operand[operandOffset]; @@ -946,8 +946,8 @@ public class DSCompiler { if (n > 0) { // strictly positive power - final int maxOrder = FastMath.min(order, n); - double xk = FastMath.pow(operand[operandOffset], n - maxOrder); + final int maxOrder = AccurateMath.min(order, n); + double xk = AccurateMath.pow(operand[operandOffset], n - maxOrder); for (int i = maxOrder; i > 0; --i) { function[i] = xk; xk *= operand[operandOffset]; @@ -956,7 +956,7 @@ public class DSCompiler { } else { // strictly negative power final double inv = 1.0 / operand[operandOffset]; - double xk = FastMath.pow(inv, -n); + double xk = AccurateMath.pow(inv, -n); for (int i = 0; i <= order; ++i) { function[i] = xk; xk *= inv; @@ -1011,14 +1011,14 @@ public class DSCompiler { double[] function = new double[1 + order]; double xk; if (n == 2) { - function[0] = FastMath.sqrt(operand[operandOffset]); + function[0] = AccurateMath.sqrt(operand[operandOffset]); xk = 0.5 / function[0]; } else if (n == 3) { - function[0] = FastMath.cbrt(operand[operandOffset]); + function[0] = AccurateMath.cbrt(operand[operandOffset]); xk = 1.0 / (3.0 * function[0] * function[0]); } else { - function[0] = FastMath.pow(operand[operandOffset], 1.0 / n); - xk = 1.0 / (n * FastMath.pow(function[0], n - 1)); + function[0] = AccurateMath.pow(operand[operandOffset], 1.0 / n); + xk = 1.0 / (n * AccurateMath.pow(function[0], n - 1)); } final double nReciprocal = 1.0 / n; final double xReciprocal = 1.0 / operand[operandOffset]; @@ -1045,7 +1045,7 @@ public class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; - Arrays.fill(function, FastMath.exp(operand[operandOffset])); + Arrays.fill(function, AccurateMath.exp(operand[operandOffset])); // apply function composition compose(operand, operandOffset, function, result, resultOffset); @@ -1065,8 +1065,8 @@ public class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; - function[0] = FastMath.expm1(operand[operandOffset]); - Arrays.fill(function, 1, 1 + order, FastMath.exp(operand[operandOffset])); + function[0] = AccurateMath.expm1(operand[operandOffset]); + Arrays.fill(function, 1, 1 + order, AccurateMath.exp(operand[operandOffset])); // apply function composition compose(operand, operandOffset, function, result, resultOffset); @@ -1086,7 +1086,7 @@ public class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; - function[0] = FastMath.log(operand[operandOffset]); + function[0] = AccurateMath.log(operand[operandOffset]); if (order > 0) { double inv = 1.0 / operand[operandOffset]; double xk = inv; @@ -1113,7 +1113,7 @@ public class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; - function[0] = FastMath.log1p(operand[operandOffset]); + function[0] = AccurateMath.log1p(operand[operandOffset]); if (order > 0) { double inv = 1.0 / (1.0 + operand[operandOffset]); double xk = inv; @@ -1140,10 +1140,10 @@ public class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; - function[0] = FastMath.log10(operand[operandOffset]); + function[0] = AccurateMath.log10(operand[operandOffset]); if (order > 0) { double inv = 1.0 / operand[operandOffset]; - double xk = inv / FastMath.log(10.0); + double xk = inv / AccurateMath.log(10.0); for (int i = 1; i <= order; ++i) { function[i] = xk; xk *= -i * inv; @@ -1168,9 +1168,9 @@ public class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; - function[0] = FastMath.cos(operand[operandOffset]); + function[0] = AccurateMath.cos(operand[operandOffset]); if (order > 0) { - function[1] = -FastMath.sin(operand[operandOffset]); + function[1] = -AccurateMath.sin(operand[operandOffset]); for (int i = 2; i <= order; ++i) { function[i] = -function[i - 2]; } @@ -1194,9 +1194,9 @@ public class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; - function[0] = FastMath.sin(operand[operandOffset]); + function[0] = AccurateMath.sin(operand[operandOffset]); if (order > 0) { - function[1] = FastMath.cos(operand[operandOffset]); + function[1] = AccurateMath.cos(operand[operandOffset]); for (int i = 2; i <= order; ++i) { function[i] = -function[i - 2]; } @@ -1220,7 +1220,7 @@ public class DSCompiler { // create the function value and derivatives final double[] function = new double[1 + order]; - final double t = FastMath.tan(operand[operandOffset]); + final double t = AccurateMath.tan(operand[operandOffset]); function[0] = t; if (order > 0) { @@ -1276,7 +1276,7 @@ public class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; final double x = operand[operandOffset]; - function[0] = FastMath.acos(x); + function[0] = AccurateMath.acos(x); if (order > 0) { // the nth order derivative of acos has the form: // dn(acos(x)/dxn = P_n(x) / [1 - x^2]^((2n-1)/2) @@ -1289,7 +1289,7 @@ public class DSCompiler { p[0] = -1; final double x2 = x * x; final double f = 1.0 / (1 - x2); - double coeff = FastMath.sqrt(f); + double coeff = AccurateMath.sqrt(f); function[1] = coeff * p[0]; for (int n = 2; n <= order; ++n) { @@ -1333,7 +1333,7 @@ public class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; final double x = operand[operandOffset]; - function[0] = FastMath.asin(x); + function[0] = AccurateMath.asin(x); if (order > 0) { // the nth order derivative of asin has the form: // dn(asin(x)/dxn = P_n(x) / [1 - x^2]^((2n-1)/2) @@ -1346,7 +1346,7 @@ public class DSCompiler { p[0] = 1; final double x2 = x * x; final double f = 1.0 / (1 - x2); - double coeff = FastMath.sqrt(f); + double coeff = AccurateMath.sqrt(f); function[1] = coeff * p[0]; for (int n = 2; n <= order; ++n) { @@ -1390,7 +1390,7 @@ public class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; final double x = operand[operandOffset]; - function[0] = FastMath.atan(x); + function[0] = AccurateMath.atan(x); if (order > 0) { // the nth order derivative of atan has the form: // dn(atan(x)/dxn = Q_n(x) / (1 + x^2)^n @@ -1472,7 +1472,7 @@ public class DSCompiler { divide(y, yOffset, tmp2, 0, tmp1, 0); // y /(r - x) atan(tmp1, 0, tmp2, 0); // atan(y / (r - x)) result[resultOffset] = - ((tmp2[0] <= 0) ? -FastMath.PI : FastMath.PI) - 2 * tmp2[0]; // +/-pi - 2 * atan(y / (r - x)) + ((tmp2[0] <= 0) ? -AccurateMath.PI : AccurateMath.PI) - 2 * tmp2[0]; // +/-pi - 2 * atan(y / (r - x)) for (int i = 1; i < tmp2.length; ++i) { result[resultOffset + i] = -2 * tmp2[i]; // +/-pi - 2 * atan(y / (r - x)) } @@ -1480,7 +1480,7 @@ public class DSCompiler { } // fix value to take special cases (+0/+0, +0/-0, -0/+0, -0/-0, +/-infinity) correctly - result[resultOffset] = FastMath.atan2(y[yOffset], x[xOffset]); + result[resultOffset] = AccurateMath.atan2(y[yOffset], x[xOffset]); } @@ -1497,9 +1497,9 @@ public class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; - function[0] = FastMath.cosh(operand[operandOffset]); + function[0] = AccurateMath.cosh(operand[operandOffset]); if (order > 0) { - function[1] = FastMath.sinh(operand[operandOffset]); + function[1] = AccurateMath.sinh(operand[operandOffset]); for (int i = 2; i <= order; ++i) { function[i] = function[i - 2]; } @@ -1523,9 +1523,9 @@ public class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; - function[0] = FastMath.sinh(operand[operandOffset]); + function[0] = AccurateMath.sinh(operand[operandOffset]); if (order > 0) { - function[1] = FastMath.cosh(operand[operandOffset]); + function[1] = AccurateMath.cosh(operand[operandOffset]); for (int i = 2; i <= order; ++i) { function[i] = function[i - 2]; } @@ -1549,7 +1549,7 @@ public class DSCompiler { // create the function value and derivatives final double[] function = new double[1 + order]; - final double t = FastMath.tanh(operand[operandOffset]); + final double t = AccurateMath.tanh(operand[operandOffset]); function[0] = t; if (order > 0) { @@ -1605,7 +1605,7 @@ public class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; final double x = operand[operandOffset]; - function[0] = FastMath.acosh(x); + function[0] = AccurateMath.acosh(x); if (order > 0) { // the nth order derivative of acosh has the form: // dn(acosh(x)/dxn = P_n(x) / [x^2 - 1]^((2n-1)/2) @@ -1618,7 +1618,7 @@ public class DSCompiler { p[0] = 1; final double x2 = x * x; final double f = 1.0 / (x2 - 1); - double coeff = FastMath.sqrt(f); + double coeff = AccurateMath.sqrt(f); function[1] = coeff * p[0]; for (int n = 2; n <= order; ++n) { @@ -1662,7 +1662,7 @@ public class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; final double x = operand[operandOffset]; - function[0] = FastMath.asinh(x); + function[0] = AccurateMath.asinh(x); if (order > 0) { // the nth order derivative of asinh has the form: // dn(asinh(x)/dxn = P_n(x) / [x^2 + 1]^((2n-1)/2) @@ -1675,7 +1675,7 @@ public class DSCompiler { p[0] = 1; final double x2 = x * x; final double f = 1.0 / (1 + x2); - double coeff = FastMath.sqrt(f); + double coeff = AccurateMath.sqrt(f); function[1] = coeff * p[0]; for (int n = 2; n <= order; ++n) { @@ -1719,7 +1719,7 @@ public class DSCompiler { // create the function value and derivatives double[] function = new double[1 + order]; final double x = operand[operandOffset]; - function[0] = FastMath.atanh(x); + function[0] = AccurateMath.atanh(x); if (order > 0) { // the nth order derivative of atanh has the form: // dn(atanh(x)/dxn = Q_n(x) / (1 - x^2)^n @@ -1805,7 +1805,7 @@ public class DSCompiler { for (int k = 0; k < orders.length; ++k) { if (orders[k] > 0) { try { - term *= FastMath.pow(delta[k], orders[k]) / FACTORIAL.value(orders[k]); + term *= AccurateMath.pow(delta[k], orders[k]) / FACTORIAL.value(orders[k]); } catch (NotPositiveException e) { // this cannot happen throw new MathInternalError(e); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/DerivativeStructure.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/DerivativeStructure.java index db3d15202..36c13f638 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/DerivativeStructure.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/DerivativeStructure.java @@ -20,14 +20,14 @@ import java.util.Arrays; import java.io.Serializable; import org.apache.commons.numbers.arrays.LinearCombination; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.FieldElement; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.FieldElement; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.MathArithmeticException; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; -import org.apache.commons.math4.legacy.util.FastMath; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.legacy.core.MathArrays; /** Class representing both the value and the differentials of a function. *

This class is the workhorse of the differentiation package.

@@ -389,7 +389,7 @@ public class DerivativeStructure implements RealFieldElement @@ -156,7 +156,7 @@ public class FiniteDifferencesDifferentiator if (2 * halfSampleSpan >= tUpper - tLower) { throw new NumberIsTooLargeException(2 * halfSampleSpan, tUpper - tLower, false); } - final double safety = FastMath.ulp(halfSampleSpan); + final double safety = AccurateMath.ulp(halfSampleSpan); this.tMin = tLower + halfSampleSpan + safety; this.tMax = tUpper - halfSampleSpan - safety; @@ -262,7 +262,7 @@ public class FiniteDifferencesDifferentiator } // compute sample position, trying to be centered if possible - final double t0 = FastMath.max(FastMath.min(t.getValue(), tMax), tMin) - halfSampleSpan; + final double t0 = AccurateMath.max(AccurateMath.min(t.getValue(), tMax), tMin) - halfSampleSpan; // compute sample points final double[] y = new double[nbPoints]; @@ -305,7 +305,7 @@ public class FiniteDifferencesDifferentiator } // compute sample position, trying to be centered if possible - final double t0 = FastMath.max(FastMath.min(t.getValue(), tMax), tMin) - halfSampleSpan; + final double t0 = AccurateMath.max(AccurateMath.min(t.getValue(), tMax), tMin) - halfSampleSpan; // compute sample points double[][] y = null; @@ -359,7 +359,7 @@ public class FiniteDifferencesDifferentiator } // compute sample position, trying to be centered if possible - final double t0 = FastMath.max(FastMath.min(t.getValue(), tMax), tMin) - halfSampleSpan; + final double t0 = AccurateMath.max(AccurateMath.min(t.getValue(), tMax), tMin) - halfSampleSpan; // compute sample points double[][][] y = null; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/SparseGradient.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/SparseGradient.java index 84a23206a..bb5999785 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/SparseGradient.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/SparseGradient.java @@ -23,11 +23,11 @@ import java.util.Map; import org.apache.commons.numbers.arrays.LinearCombination; import org.apache.commons.numbers.core.Precision; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.FieldElement; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.FieldElement; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * First derivative computation with large number of variables. @@ -330,7 +330,7 @@ public class SparseGradient implements RealFieldElement, Seriali /** {@inheritDoc} */ @Override public SparseGradient remainder(final double a) { - return new SparseGradient(FastMath.IEEEremainder(value, a), derivatives); + return new SparseGradient(AccurateMath.IEEEremainder(value, a), derivatives); } /** {@inheritDoc} */ @@ -338,8 +338,8 @@ public class SparseGradient implements RealFieldElement, Seriali public SparseGradient remainder(final SparseGradient a) { // compute k such that lhs % rhs = lhs - k rhs - final double rem = FastMath.IEEEremainder(value, a.value); - final double k = FastMath.rint((value - rem) / a.value); + final double rem = AccurateMath.IEEEremainder(value, a.value); + final double k = AccurateMath.rint((value - rem) / a.value); return subtract(a.multiply(k)); @@ -359,31 +359,31 @@ public class SparseGradient implements RealFieldElement, Seriali /** {@inheritDoc} */ @Override public SparseGradient ceil() { - return createConstant(FastMath.ceil(value)); + return createConstant(AccurateMath.ceil(value)); } /** {@inheritDoc} */ @Override public SparseGradient floor() { - return createConstant(FastMath.floor(value)); + return createConstant(AccurateMath.floor(value)); } /** {@inheritDoc} */ @Override public SparseGradient rint() { - return createConstant(FastMath.rint(value)); + return createConstant(AccurateMath.rint(value)); } /** {@inheritDoc} */ @Override public long round() { - return FastMath.round(value); + return AccurateMath.round(value); } /** {@inheritDoc} */ @Override public SparseGradient signum() { - return createConstant(FastMath.signum(value)); + return createConstant(AccurateMath.signum(value)); } /** {@inheritDoc} */ @@ -411,9 +411,9 @@ public class SparseGradient implements RealFieldElement, Seriali /** {@inheritDoc} */ @Override public SparseGradient scalb(final int n) { - final SparseGradient out = new SparseGradient(FastMath.scalb(value, n), Collections. emptyMap()); + final SparseGradient out = new SparseGradient(AccurateMath.scalb(value, n), Collections. emptyMap()); for (Map.Entry entry : derivatives.entrySet()) { - out.derivatives.put(entry.getKey(), FastMath.scalb(entry.getValue(), n)); + out.derivatives.put(entry.getKey(), AccurateMath.scalb(entry.getValue(), n)); } return out; } @@ -427,8 +427,8 @@ public class SparseGradient implements RealFieldElement, Seriali return createConstant(Double.NaN); } else { - final int expX = FastMath.getExponent(value); - final int expY = FastMath.getExponent(y.value); + final int expX = AccurateMath.getExponent(value); + final int expY = AccurateMath.getExponent(y.value); if (expX > expY + 27) { // y is negligible with respect to x return abs(); @@ -483,14 +483,14 @@ public class SparseGradient implements RealFieldElement, Seriali /** {@inheritDoc} */ @Override public SparseGradient sqrt() { - final double sqrt = FastMath.sqrt(value); + final double sqrt = AccurateMath.sqrt(value); return new SparseGradient(sqrt, 0.5 / sqrt, derivatives); } /** {@inheritDoc} */ @Override public SparseGradient cbrt() { - final double cbrt = FastMath.cbrt(value); + final double cbrt = AccurateMath.cbrt(value); return new SparseGradient(cbrt, 1.0 / (3 * cbrt * cbrt), derivatives); } @@ -502,15 +502,15 @@ public class SparseGradient implements RealFieldElement, Seriali } else if (n == 3) { return cbrt(); } else { - final double root = FastMath.pow(value, 1.0 / n); - return new SparseGradient(root, 1.0 / (n * FastMath.pow(root, n - 1)), derivatives); + final double root = AccurateMath.pow(value, 1.0 / n); + return new SparseGradient(root, 1.0 / (n * AccurateMath.pow(root, n - 1)), derivatives); } } /** {@inheritDoc} */ @Override public SparseGradient pow(final double p) { - return new SparseGradient(FastMath.pow(value, p), p * FastMath.pow(value, p - 1), derivatives); + return new SparseGradient(AccurateMath.pow(value, p), p * AccurateMath.pow(value, p - 1), derivatives); } /** {@inheritDoc} */ @@ -519,7 +519,7 @@ public class SparseGradient implements RealFieldElement, Seriali if (n == 0) { return getField().getOne(); } else { - final double valueNm1 = FastMath.pow(value, n - 1); + final double valueNm1 = AccurateMath.pow(value, n - 1); return new SparseGradient(value * valueNm1, n * valueNm1, derivatives); } } @@ -545,28 +545,28 @@ public class SparseGradient implements RealFieldElement, Seriali return x.getField().getZero(); } } else { - final double ax = FastMath.pow(a, x.value); - return new SparseGradient(ax, ax * FastMath.log(a), x.derivatives); + final double ax = AccurateMath.pow(a, x.value); + return new SparseGradient(ax, ax * AccurateMath.log(a), x.derivatives); } } /** {@inheritDoc} */ @Override public SparseGradient exp() { - final double e = FastMath.exp(value); + final double e = AccurateMath.exp(value); return new SparseGradient(e, e, derivatives); } /** {@inheritDoc} */ @Override public SparseGradient expm1() { - return new SparseGradient(FastMath.expm1(value), FastMath.exp(value), derivatives); + return new SparseGradient(AccurateMath.expm1(value), AccurateMath.exp(value), derivatives); } /** {@inheritDoc} */ @Override public SparseGradient log() { - return new SparseGradient(FastMath.log(value), 1.0 / value, derivatives); + return new SparseGradient(AccurateMath.log(value), 1.0 / value, derivatives); } /** Base 10 logarithm. @@ -574,50 +574,50 @@ public class SparseGradient implements RealFieldElement, Seriali */ @Override public SparseGradient log10() { - return new SparseGradient(FastMath.log10(value), 1.0 / (FastMath.log(10.0) * value), derivatives); + return new SparseGradient(AccurateMath.log10(value), 1.0 / (AccurateMath.log(10.0) * value), derivatives); } /** {@inheritDoc} */ @Override public SparseGradient log1p() { - return new SparseGradient(FastMath.log1p(value), 1.0 / (1.0 + value), derivatives); + return new SparseGradient(AccurateMath.log1p(value), 1.0 / (1.0 + value), derivatives); } /** {@inheritDoc} */ @Override public SparseGradient cos() { - return new SparseGradient(FastMath.cos(value), -FastMath.sin(value), derivatives); + return new SparseGradient(AccurateMath.cos(value), -AccurateMath.sin(value), derivatives); } /** {@inheritDoc} */ @Override public SparseGradient sin() { - return new SparseGradient(FastMath.sin(value), FastMath.cos(value), derivatives); + return new SparseGradient(AccurateMath.sin(value), AccurateMath.cos(value), derivatives); } /** {@inheritDoc} */ @Override public SparseGradient tan() { - final double t = FastMath.tan(value); + final double t = AccurateMath.tan(value); return new SparseGradient(t, 1 + t * t, derivatives); } /** {@inheritDoc} */ @Override public SparseGradient acos() { - return new SparseGradient(FastMath.acos(value), -1.0 / FastMath.sqrt(1 - value * value), derivatives); + return new SparseGradient(AccurateMath.acos(value), -1.0 / AccurateMath.sqrt(1 - value * value), derivatives); } /** {@inheritDoc} */ @Override public SparseGradient asin() { - return new SparseGradient(FastMath.asin(value), 1.0 / FastMath.sqrt(1 - value * value), derivatives); + return new SparseGradient(AccurateMath.asin(value), 1.0 / AccurateMath.sqrt(1 - value * value), derivatives); } /** {@inheritDoc} */ @Override public SparseGradient atan() { - return new SparseGradient(FastMath.atan(value), 1.0 / (1 + value * value), derivatives); + return new SparseGradient(AccurateMath.atan(value), 1.0 / (1 + value * value), derivatives); } /** {@inheritDoc} */ @@ -637,12 +637,12 @@ public class SparseGradient implements RealFieldElement, Seriali // compute atan2(y, x) = +/- pi - 2 atan(y / (r - x)) final SparseGradient tmp = divide(r.subtract(x)).atan().multiply(-2); - a = tmp.add(tmp.value <= 0 ? -FastMath.PI : FastMath.PI); + a = tmp.add(tmp.value <= 0 ? -AccurateMath.PI : AccurateMath.PI); } // fix value to take special cases (+0/+0, +0/-0, -0/+0, -0/-0, +/-infinity) correctly - a.value = FastMath.atan2(value, x.value); + a.value = AccurateMath.atan2(value, x.value); return a; @@ -660,52 +660,52 @@ public class SparseGradient implements RealFieldElement, Seriali /** {@inheritDoc} */ @Override public SparseGradient cosh() { - return new SparseGradient(FastMath.cosh(value), FastMath.sinh(value), derivatives); + return new SparseGradient(AccurateMath.cosh(value), AccurateMath.sinh(value), derivatives); } /** {@inheritDoc} */ @Override public SparseGradient sinh() { - return new SparseGradient(FastMath.sinh(value), FastMath.cosh(value), derivatives); + return new SparseGradient(AccurateMath.sinh(value), AccurateMath.cosh(value), derivatives); } /** {@inheritDoc} */ @Override public SparseGradient tanh() { - final double t = FastMath.tanh(value); + final double t = AccurateMath.tanh(value); return new SparseGradient(t, 1 - t * t, derivatives); } /** {@inheritDoc} */ @Override public SparseGradient acosh() { - return new SparseGradient(FastMath.acosh(value), 1.0 / FastMath.sqrt(value * value - 1.0), derivatives); + return new SparseGradient(AccurateMath.acosh(value), 1.0 / AccurateMath.sqrt(value * value - 1.0), derivatives); } /** {@inheritDoc} */ @Override public SparseGradient asinh() { - return new SparseGradient(FastMath.asinh(value), 1.0 / FastMath.sqrt(value * value + 1.0), derivatives); + return new SparseGradient(AccurateMath.asinh(value), 1.0 / AccurateMath.sqrt(value * value + 1.0), derivatives); } /** {@inheritDoc} */ @Override public SparseGradient atanh() { - return new SparseGradient(FastMath.atanh(value), 1.0 / (1.0 - value * value), derivatives); + return new SparseGradient(AccurateMath.atanh(value), 1.0 / (1.0 - value * value), derivatives); } /** Convert radians to degrees, with error of less than 0.5 ULP * @return instance converted into degrees */ public SparseGradient toDegrees() { - return new SparseGradient(FastMath.toDegrees(value), FastMath.toDegrees(1.0), derivatives); + return new SparseGradient(AccurateMath.toDegrees(value), AccurateMath.toDegrees(1.0), derivatives); } /** Convert degrees to radians, with error of less than 0.5 ULP * @return instance converted into radians */ public SparseGradient toRadians() { - return new SparseGradient(FastMath.toRadians(value), FastMath.toRadians(1.0), derivatives); + return new SparseGradient(AccurateMath.toRadians(value), AccurateMath.toRadians(1.0), derivatives); } /** Evaluate Taylor expansion of a sparse gradient. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Abs.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Abs.java index 098973638..668a8869d 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Abs.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Abs.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.UnivariateFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Absolute value function. @@ -29,6 +29,6 @@ public class Abs implements UnivariateFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.abs(x); + return AccurateMath.abs(x); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Acos.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Acos.java index ffaaeb428..fcfde56b0 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Acos.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Acos.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Arc-cosine function. @@ -30,7 +30,7 @@ public class Acos implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.acos(x); + return AccurateMath.acos(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Acosh.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Acosh.java index 215697c1b..3f8569619 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Acosh.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Acosh.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Hyperbolic arc-cosine function. @@ -30,7 +30,7 @@ public class Acosh implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.acosh(x); + return AccurateMath.acosh(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Asin.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Asin.java index 4cf92d45e..fc9459101 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Asin.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Asin.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Arc-sine function. @@ -30,7 +30,7 @@ public class Asin implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.asin(x); + return AccurateMath.asin(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Asinh.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Asinh.java index c7e3833a6..98e38ce0d 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Asinh.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Asinh.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Hyperbolic arc-sine function. @@ -30,7 +30,7 @@ public class Asinh implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.asinh(x); + return AccurateMath.asinh(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atan.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atan.java index df53ea5bf..c52d68605 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atan.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atan.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Arc-tangent function. @@ -30,7 +30,7 @@ public class Atan implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.atan(x); + return AccurateMath.atan(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atan2.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atan2.java index bc95323c1..927787bdd 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atan2.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atan2.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.BivariateFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Arc-tangent function. @@ -29,6 +29,6 @@ public class Atan2 implements BivariateFunction { /** {@inheritDoc} */ @Override public double value(double y, double x) { - return FastMath.atan2(y, x); + return AccurateMath.atan2(y, x); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atanh.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atanh.java index e48625fda..6061dd1a8 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atanh.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Atanh.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Hyperbolic arc-tangent function. @@ -30,7 +30,7 @@ public class Atanh implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.atanh(x); + return AccurateMath.atanh(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cbrt.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cbrt.java index 622ffaff0..ed9784471 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cbrt.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cbrt.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Cube root function. @@ -30,7 +30,7 @@ public class Cbrt implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.cbrt(x); + return AccurateMath.cbrt(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Ceil.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Ceil.java index 11423e1db..5ec6b3686 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Ceil.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Ceil.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.UnivariateFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * {@code ceil} function. @@ -29,6 +29,6 @@ public class Ceil implements UnivariateFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.ceil(x); + return AccurateMath.ceil(x); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cos.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cos.java index c816c1954..c82e2375b 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cos.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cos.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Cosine function. @@ -30,7 +30,7 @@ public class Cos implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.cos(x); + return AccurateMath.cos(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cosh.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cosh.java index a54342f03..32aa17e8d 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cosh.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Cosh.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Hyperbolic cosine function. @@ -30,7 +30,7 @@ public class Cosh implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.cosh(x); + return AccurateMath.cosh(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Exp.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Exp.java index 4ae9373db..bc8530e8a 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Exp.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Exp.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Exponential function. @@ -30,7 +30,7 @@ public class Exp implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.exp(x); + return AccurateMath.exp(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Expm1.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Expm1.java index 4a430f8ee..1d683e249 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Expm1.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Expm1.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * ex-1 function. @@ -30,7 +30,7 @@ public class Expm1 implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.expm1(x); + return AccurateMath.expm1(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Floor.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Floor.java index 9f8f99643..26267cead 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Floor.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Floor.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.UnivariateFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * {@code floor} function. @@ -29,6 +29,6 @@ public class Floor implements UnivariateFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.floor(x); + return AccurateMath.floor(x); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Gaussian.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Gaussian.java index 0c6d46f8a..b5c6af4e4 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Gaussian.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Gaussian.java @@ -25,7 +25,7 @@ import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDiffer import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.NullArgumentException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.numbers.core.Precision; /** @@ -76,7 +76,7 @@ public class Gaussian implements UnivariateDifferentiableFunction { public Gaussian(double mean, double sigma) throws NotStrictlyPositiveException { - this(1 / (sigma * FastMath.sqrt(2 * Math.PI)), mean, sigma); + this(1 / (sigma * AccurateMath.sqrt(2 * Math.PI)), mean, sigma); } /** @@ -194,7 +194,7 @@ public class Gaussian implements UnivariateDifferentiableFunction { private static double value(double xMinusMean, double norm, double i2s2) { - return norm * FastMath.exp(-xMinusMean * xMinusMean * i2s2); + return norm * AccurateMath.exp(-xMinusMean * xMinusMean * i2s2); } /** {@inheritDoc} @@ -217,7 +217,7 @@ public class Gaussian implements UnivariateDifferentiableFunction { final double[] p = new double[f.length]; p[0] = 1; final double u2 = u * u; - double coeff = norm * FastMath.exp(-0.5 * u2); + double coeff = norm * AccurateMath.exp(-0.5 * u2); if (coeff <= Precision.SAFE_MIN) { Arrays.fill(f, 0.0); } else { diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/HarmonicOscillator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/HarmonicOscillator.java index b8fac67b5..4c8a29e42 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/HarmonicOscillator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/HarmonicOscillator.java @@ -22,7 +22,7 @@ import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStruct import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NullArgumentException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * @@ -112,7 +112,7 @@ public class HarmonicOscillator implements UnivariateDifferentiableFunction { final double xTimesOmegaPlusPhase = omega * x + phase; final double a = HarmonicOscillator.value(xTimesOmegaPlusPhase, 1); - final double p = -amplitude * FastMath.sin(xTimesOmegaPlusPhase); + final double p = -amplitude * AccurateMath.sin(xTimesOmegaPlusPhase); final double w = p * x; return new double[] { a, w, p }; @@ -147,7 +147,7 @@ public class HarmonicOscillator implements UnivariateDifferentiableFunction { */ private static double value(double xTimesOmegaPlusPhase, double amplitude) { - return amplitude * FastMath.cos(xTimesOmegaPlusPhase); + return amplitude * AccurateMath.cos(xTimesOmegaPlusPhase); } /** {@inheritDoc} @@ -160,9 +160,9 @@ public class HarmonicOscillator implements UnivariateDifferentiableFunction { double[] f = new double[t.getOrder() + 1]; final double alpha = omega * x + phase; - f[0] = amplitude * FastMath.cos(alpha); + f[0] = amplitude * AccurateMath.cos(alpha); if (f.length > 1) { - f[1] = -amplitude * omega * FastMath.sin(alpha); + f[1] = -amplitude * omega * AccurateMath.sin(alpha); final double mo2 = - omega * omega; for (int i = 2; i < f.length; ++i) { f[i] = mo2 * f[i - 2]; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log.java index 0db005b19..6dfdb21f1 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Natural logarithm function. @@ -30,7 +30,7 @@ public class Log implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.log(x); + return AccurateMath.log(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log10.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log10.java index c0b36ae12..e7228a365 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log10.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log10.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Base 10 logarithm function. @@ -31,7 +31,7 @@ public class Log10 implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.log10(x); + return AccurateMath.log10(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log1p.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log1p.java index d6f0b146c..1f244046e 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log1p.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Log1p.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * log(1 + p) function. @@ -30,7 +30,7 @@ public class Log1p implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.log1p(x); + return AccurateMath.log1p(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logistic.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logistic.java index e5bfe7b7e..18c27702d 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logistic.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logistic.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDiffer import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.NullArgumentException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * @@ -147,10 +147,10 @@ public class Logistic implements UnivariateDifferentiableFunction { final double mMinusX = param[1] - x; final double oneOverN = 1 / param[5]; - final double exp = FastMath.exp(b * mMinusX); + final double exp = AccurateMath.exp(b * mMinusX); final double qExp = q * exp; final double qExp1 = qExp + 1; - final double factor1 = (param[0] - param[4]) * oneOverN / FastMath.pow(qExp1, oneOverN); + final double factor1 = (param[0] - param[4]) * oneOverN / AccurateMath.pow(qExp1, oneOverN); final double factor2 = -factor1 / qExp1; // Components of the gradient. @@ -159,7 +159,7 @@ public class Logistic implements UnivariateDifferentiableFunction { final double gb = factor2 * mMinusX * qExp; final double gq = factor2 * exp; final double ga = Logistic.value(mMinusX, 0, b, q, 1, oneOverN); - final double gn = factor1 * FastMath.log(qExp1) * oneOverN; + final double gn = factor1 * AccurateMath.log(qExp1) * oneOverN; return new double[] { gk, gm, gb, gq, ga, gn }; } @@ -207,7 +207,7 @@ public class Logistic implements UnivariateDifferentiableFunction { double q, double a, double oneOverN) { - return a + (k - a) / FastMath.pow(1 + q * FastMath.exp(b * mMinusX), oneOverN); + return a + (k - a) / AccurateMath.pow(1 + q * AccurateMath.exp(b * mMinusX), oneOverN); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logit.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logit.java index 2d0c7203c..c04baf665 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logit.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logit.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDiffer import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * @@ -153,7 +153,7 @@ public class Logit implements UnivariateDifferentiableFunction { if (x < lo || x > hi) { throw new OutOfRangeException(x, lo, hi); } - return FastMath.log((x - lo) / (hi - x)); + return AccurateMath.log((x - lo) / (hi - x)); } /** {@inheritDoc} @@ -170,7 +170,7 @@ public class Logit implements UnivariateDifferentiableFunction { double[] f = new double[t.getOrder() + 1]; // function value - f[0] = FastMath.log((x - lo) / (hi - x)); + f[0] = AccurateMath.log((x - lo) / (hi - x)); if (Double.isInfinite(f[0])) { diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Max.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Max.java index 023fd25ad..f338b8138 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Max.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Max.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.BivariateFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Maximum function. @@ -29,6 +29,6 @@ public class Max implements BivariateFunction { /** {@inheritDoc} */ @Override public double value(double x, double y) { - return FastMath.max(x, y); + return AccurateMath.max(x, y); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Min.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Min.java index b9d49608b..90eba84a6 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Min.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Min.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.BivariateFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Minimum function. @@ -29,6 +29,6 @@ public class Min implements BivariateFunction { /** {@inheritDoc} */ @Override public double value(double x, double y) { - return FastMath.min(x, y); + return AccurateMath.min(x, y); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Pow.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Pow.java index 1452c80ec..70b691544 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Pow.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Pow.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.BivariateFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Power function. @@ -29,6 +29,6 @@ public class Pow implements BivariateFunction { /** {@inheritDoc} */ @Override public double value(double x, double y) { - return FastMath.pow(x, y); + return AccurateMath.pow(x, y); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Power.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Power.java index 584b801a4..91cfc58ad 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Power.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Power.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Power function. @@ -40,7 +40,7 @@ public class Power implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.pow(x, p); + return AccurateMath.pow(x, p); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Rint.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Rint.java index 90c812c85..7b81161a9 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Rint.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Rint.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.UnivariateFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * {@code rint} function. @@ -29,6 +29,6 @@ public class Rint implements UnivariateFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.rint(x); + return AccurateMath.rint(x); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sigmoid.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sigmoid.java index 1f298c456..811fb8a4e 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sigmoid.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sigmoid.java @@ -24,7 +24,7 @@ import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStruct import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NullArgumentException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * @@ -114,7 +114,7 @@ public class Sigmoid implements UnivariateDifferentiableFunction { DimensionMismatchException { validateParameters(param); - final double invExp1 = 1 / (1 + FastMath.exp(-x)); + final double invExp1 = 1 / (1 + AccurateMath.exp(-x)); return new double[] { 1 - invExp1, invExp1 }; } @@ -150,7 +150,7 @@ public class Sigmoid implements UnivariateDifferentiableFunction { private static double value(double x, double lo, double hi) { - return lo + (hi - lo) / (1 + FastMath.exp(-x)); + return lo + (hi - lo) / (1 + AccurateMath.exp(-x)); } /** {@inheritDoc} @@ -161,7 +161,7 @@ public class Sigmoid implements UnivariateDifferentiableFunction { throws DimensionMismatchException { double[] f = new double[t.getOrder() + 1]; - final double exp = FastMath.exp(-t.getValue()); + final double exp = AccurateMath.exp(-t.getValue()); if (Double.isInfinite(exp)) { // special handling near lower boundary, to avoid NaN diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Signum.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Signum.java index 858a48b7d..067eac336 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Signum.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Signum.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.UnivariateFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * {@code signum} function. @@ -29,6 +29,6 @@ public class Signum implements UnivariateFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.signum(x); + return AccurateMath.signum(x); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sin.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sin.java index ee722853f..81aaedde4 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sin.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sin.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Sine function. @@ -30,7 +30,7 @@ public class Sin implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.sin(x); + return AccurateMath.sin(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sinc.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sinc.java index f23c542cc..a33e0da5d 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sinc.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sinc.java @@ -20,7 +20,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Sinc function, @@ -81,14 +81,14 @@ public class Sinc implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(final double x) { - final double scaledX = normalized ? FastMath.PI * x : x; - if (FastMath.abs(scaledX) <= SHORTCUT) { + final double scaledX = normalized ? AccurateMath.PI * x : x; + if (AccurateMath.abs(scaledX) <= SHORTCUT) { // use Taylor series final double scaledX2 = scaledX * scaledX; return ((scaledX2 - 20) * scaledX2 + 120) / 120; } else { // use definition expression - return FastMath.sin(scaledX) / scaledX; + return AccurateMath.sin(scaledX) / scaledX; } } @@ -99,12 +99,12 @@ public class Sinc implements UnivariateDifferentiableFunction { public DerivativeStructure value(final DerivativeStructure t) throws DimensionMismatchException { - final double scaledX = (normalized ? FastMath.PI : 1) * t.getValue(); + final double scaledX = (normalized ? AccurateMath.PI : 1) * t.getValue(); final double scaledX2 = scaledX * scaledX; double[] f = new double[t.getOrder() + 1]; - if (FastMath.abs(scaledX) <= SHORTCUT) { + if (AccurateMath.abs(scaledX) <= SHORTCUT) { for (int i = 0; i < f.length; ++i) { final int k = i / 2; @@ -122,8 +122,8 @@ public class Sinc implements UnivariateDifferentiableFunction { } else { final double inv = 1 / scaledX; - final double cos = FastMath.cos(scaledX); - final double sin = FastMath.sin(scaledX); + final double cos = AccurateMath.cos(scaledX); + final double sin = AccurateMath.sin(scaledX); f[0] = inv * sin; @@ -182,10 +182,10 @@ public class Sinc implements UnivariateDifferentiableFunction { } if (normalized) { - double scale = FastMath.PI; + double scale = AccurateMath.PI; for (int i = 1; i < f.length; ++i) { f[i] *= scale; - scale *= FastMath.PI; + scale *= AccurateMath.PI; } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sinh.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sinh.java index 98e11d92c..4a9a51580 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sinh.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sinh.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Hyperbolic sine function. @@ -30,7 +30,7 @@ public class Sinh implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.sinh(x); + return AccurateMath.sinh(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sqrt.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sqrt.java index 3a3da21d7..f8146aa4f 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sqrt.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Sqrt.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Square-root function. @@ -30,7 +30,7 @@ public class Sqrt implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.sqrt(x); + return AccurateMath.sqrt(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/StepFunction.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/StepFunction.java index edb5e642d..d4fb09f6b 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/StepFunction.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/StepFunction.java @@ -24,7 +24,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NoDataException; import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException; import org.apache.commons.math4.legacy.exception.NullArgumentException; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Tan.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Tan.java index b79bbbe35..5fa6f4f45 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Tan.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Tan.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Tangent function. @@ -30,7 +30,7 @@ public class Tan implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.tan(x); + return AccurateMath.tan(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Tanh.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Tanh.java index 697262632..26f801607 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Tanh.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Tanh.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Hyperbolic tangent function. @@ -30,7 +30,7 @@ public class Tanh implements UnivariateDifferentiableFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.tanh(x); + return AccurateMath.tanh(x); } /** {@inheritDoc} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Ulp.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Ulp.java index 5a193c902..840024049 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Ulp.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Ulp.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.function; import org.apache.commons.math4.legacy.analysis.UnivariateFunction; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * {@code ulp} function. @@ -29,6 +29,6 @@ public class Ulp implements UnivariateFunction { /** {@inheritDoc} */ @Override public double value(double x) { - return FastMath.ulp(x); + return AccurateMath.ulp(x); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/IterativeLegendreGaussIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/IterativeLegendreGaussIntegrator.java index e768c6e74..e9011bc66 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/IterativeLegendreGaussIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/IterativeLegendreGaussIntegrator.java @@ -22,7 +22,7 @@ import org.apache.commons.math4.legacy.analysis.integration.gauss.GaussIntegrato import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * This algorithm divides the integration interval into equally-sized @@ -122,10 +122,10 @@ public class IterativeLegendreGaussIntegrator final double t = stage(n); // Estimate the error. - final double delta = FastMath.abs(t - oldt); + final double delta = AccurateMath.abs(t - oldt); final double limit = - FastMath.max(getAbsoluteAccuracy(), - getRelativeAccuracy() * (FastMath.abs(oldt) + FastMath.abs(t)) * 0.5); + AccurateMath.max(getAbsoluteAccuracy(), + getRelativeAccuracy() * (AccurateMath.abs(oldt) + AccurateMath.abs(t)) * 0.5); // check convergence if (iterations.getCount() + 1 >= getMinimalIterationCount() && @@ -134,8 +134,8 @@ public class IterativeLegendreGaussIntegrator } // Prepare next iteration. - final double ratio = FastMath.min(4, FastMath.pow(delta / limit, 0.5 / numberOfPoints)); - n = FastMath.max((int) (ratio * n), n + 1); + final double ratio = AccurateMath.min(4, AccurateMath.pow(delta / limit, 0.5 / numberOfPoints)); + n = AccurateMath.max((int) (ratio * n), n + 1); oldt = t; iterations.increment(); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/MidPointIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/MidPointIntegrator.java index e748425f2..30668512c 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/MidPointIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/MidPointIntegrator.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.analysis.integration; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Implements the @@ -113,7 +113,7 @@ public class MidPointIntegrator extends BaseAbstractUnivariateIntegrator { double diffMaxMin) { // number of points in the previous stage. This stage will contribute // 2*3^{n-1} more points. - final long np = (long) FastMath.pow(3, n - 1); + final long np = (long) AccurateMath.pow(3, n - 1); double sum = 0; // spacing between adjacent new points @@ -151,9 +151,9 @@ public class MidPointIntegrator extends BaseAbstractUnivariateIntegrator { final int i = iterations.getCount(); final double t = stage(i, oldt, min, diff); if (i >= getMinimalIterationCount()) { - final double delta = FastMath.abs(t - oldt); + final double delta = AccurateMath.abs(t - oldt); final double rLimit = - getRelativeAccuracy() * (FastMath.abs(oldt) + FastMath.abs(t)) * 0.5; + getRelativeAccuracy() * (AccurateMath.abs(oldt) + AccurateMath.abs(t)) * 0.5; if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) { return t; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/RombergIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/RombergIntegrator.java index c2c6aa62b..771a7b803 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/RombergIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/RombergIntegrator.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.analysis.integration; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Implements the @@ -120,8 +120,8 @@ public class RombergIntegrator extends BaseAbstractUnivariateIntegrator { } final double s = currentRow[i]; if (i >= getMinimalIterationCount()) { - final double delta = FastMath.abs(s - olds); - final double rLimit = getRelativeAccuracy() * (FastMath.abs(olds) + FastMath.abs(s)) * 0.5; + final double delta = AccurateMath.abs(s - olds); + final double rLimit = getRelativeAccuracy() * (AccurateMath.abs(olds) + AccurateMath.abs(s)) * 0.5; if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) { return s; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/SimpsonIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/SimpsonIntegrator.java index caf36d757..26630aa21 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/SimpsonIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/SimpsonIntegrator.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.analysis.integration; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Implements @@ -106,8 +106,8 @@ public class SimpsonIntegrator extends BaseAbstractUnivariateIntegrator { final double t = qtrap.stage(this, i + 1); // 1-stage ahead of the iteration final double s = (4 * t - oldt) / 3.0; if (i >= getMinimalIterationCount()) { - final double delta = FastMath.abs(s - olds); - final double rLimit = getRelativeAccuracy() * (FastMath.abs(olds) + FastMath.abs(s)) * 0.5; + final double delta = AccurateMath.abs(s - olds); + final double rLimit = getRelativeAccuracy() * (AccurateMath.abs(olds) + AccurateMath.abs(s)) * 0.5; if (delta <= rLimit || delta <= getAbsoluteAccuracy()) { return s; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/TrapezoidIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/TrapezoidIntegrator.java index 7f7fa6e53..ed1176fa5 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/TrapezoidIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/TrapezoidIntegrator.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.analysis.integration; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Implements the @@ -139,9 +139,9 @@ public class TrapezoidIntegrator extends BaseAbstractUnivariateIntegrator { final int i = iterations.getCount(); final double t = stage(this, i); if (i >= getMinimalIterationCount()) { - final double delta = FastMath.abs(t - oldt); + final double delta = AccurateMath.abs(t - oldt); final double rLimit = - getRelativeAccuracy() * (FastMath.abs(oldt) + FastMath.abs(t)) * 0.5; + getRelativeAccuracy() * (AccurateMath.abs(oldt) + AccurateMath.abs(t)) * 0.5; if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) { return t; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/gauss/GaussIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/gauss/GaussIntegrator.java index 967ca875f..616b48b47 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/gauss/GaussIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/gauss/GaussIntegrator.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.integration.gauss; import org.apache.commons.math4.legacy.analysis.UnivariateFunction; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; import org.apache.commons.math4.legacy.util.Pair; /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/gauss/HermiteRuleFactory.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/gauss/HermiteRuleFactory.java index 76cd4caf5..edc5a9438 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/gauss/HermiteRuleFactory.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/integration/gauss/HermiteRuleFactory.java @@ -16,7 +16,7 @@ */ package org.apache.commons.math4.legacy.analysis.integration.gauss; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.math4.legacy.util.Pair; /** @@ -74,8 +74,8 @@ public class HermiteRuleFactory extends BaseRuleFactory { final Double[] points = new Double[numberOfPoints]; final Double[] weights = new Double[numberOfPoints]; - final double sqrtTwoTimesLastNumPoints = FastMath.sqrt(2 * lastNumPoints); - final double sqrtTwoTimesNumPoints = FastMath.sqrt(2 * numberOfPoints); + final double sqrtTwoTimesLastNumPoints = AccurateMath.sqrt(2 * lastNumPoints); + final double sqrtTwoTimesNumPoints = AccurateMath.sqrt(2 * numberOfPoints); // Find i-th root of H[n+1] by bracketing. final int iMax = numberOfPoints / 2; @@ -96,8 +96,8 @@ public class HermiteRuleFactory extends BaseRuleFactory { for (int j = 1; j < numberOfPoints; j++) { // Compute H[j+1](a) and H[j+1](b) final double jp1 = j + 1; - final double s = FastMath.sqrt(2 / jp1); - final double sm = FastMath.sqrt(j / jp1); + final double s = AccurateMath.sqrt(2 / jp1); + final double sm = AccurateMath.sqrt(j / jp1); final double hpa = s * a * ha - sm * hma; final double hpb = s * b * hb - sm * hmb; hma = ha; @@ -121,8 +121,8 @@ public class HermiteRuleFactory extends BaseRuleFactory { for (int j = 1; j < numberOfPoints; j++) { // Compute H[j+1](c) final double jp1 = j + 1; - final double s = FastMath.sqrt(2 / jp1); - final double sm = FastMath.sqrt(j / jp1); + final double s = AccurateMath.sqrt(2 / jp1); + final double sm = AccurateMath.sqrt(j / jp1); final double hpc = s * c * hc - sm * hmc; hmc = hc; hc = hpc; @@ -160,7 +160,7 @@ public class HermiteRuleFactory extends BaseRuleFactory { double hm = H0; for (int j = 1; j < numberOfPoints; j += 2) { final double jp1 = j + 1; - hm = -FastMath.sqrt(j / jp1) * hm; + hm = -AccurateMath.sqrt(j / jp1) * hm; } final double d = sqrtTwoTimesNumPoints * hm; final double w = 2 / (d * d); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/AkimaSplineInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/AkimaSplineInterpolator.java index d24e45df4..2d1520d29 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/AkimaSplineInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/AkimaSplineInterpolator.java @@ -23,8 +23,8 @@ import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.FastMath; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.legacy.core.MathArrays; import org.apache.commons.numbers.core.Precision; /** @@ -123,11 +123,11 @@ public class AkimaSplineInterpolator for (int i = 1; i < weights.length; i++) { final double a = differences[i]; final double b = differences[i - 1]; - weights[i] = FastMath.abs(a - b) + 0.5 * FastMath.abs(a + b); + weights[i] = AccurateMath.abs(a - b) + 0.5 * AccurateMath.abs(a + b); } } else { for (int i = 1; i < weights.length; i++) { - weights[i] = FastMath.abs(differences[i] - differences[i - 1]); + weights[i] = AccurateMath.abs(differences[i] - differences[i - 1]); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/BicubicInterpolatingFunction.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/BicubicInterpolatingFunction.java index 62c986181..faf4ce5a6 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/BicubicInterpolatingFunction.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/BicubicInterpolatingFunction.java @@ -24,7 +24,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NoDataException; import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Function that implements the diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/BicubicInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/BicubicInterpolator.java index 60016a587..97a6b896e 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/BicubicInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/BicubicInterpolator.java @@ -20,7 +20,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NoDataException; import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Generates a {@link BicubicInterpolatingFunction bicubic interpolating diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/FieldHermiteInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/FieldHermiteInterpolator.java index b5c352815..587bedd21 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/FieldHermiteInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/FieldHermiteInterpolator.java @@ -19,14 +19,14 @@ package org.apache.commons.math4.legacy.analysis.interpolation; import java.util.ArrayList; import java.util.List; -import org.apache.commons.math4.legacy.FieldElement; +import org.apache.commons.math4.legacy.core.FieldElement; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.MathArithmeticException; import org.apache.commons.math4.legacy.exception.NoDataException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.ZeroException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** Polynomial interpolator using both sample values and sample derivatives. *

diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere.java index 9134d0d21..525cc210a 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere.java @@ -26,8 +26,8 @@ import org.apache.commons.math4.legacy.exception.NotPositiveException; import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; -import org.apache.commons.math4.legacy.util.FastMath; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Utility class for the {@link MicrosphereProjectionInterpolator} algorithm. @@ -224,13 +224,13 @@ public class InterpolatingMicrosphere { final double[] diff = MathArrays.ebeSubtract(samplePoints[i], point); final double diffNorm = SafeNorm.value(diff); - if (FastMath.abs(diffNorm) < noInterpolationTolerance) { + if (AccurateMath.abs(diffNorm) < noInterpolationTolerance) { // No need to interpolate, as the interpolation point is // actually (very close to) one of the sampled points. return sampleValues[i]; } - final double weight = FastMath.pow(diffNorm, -exponent); + final double weight = AccurateMath.pow(diffNorm, -exponent); illuminate(diff, sampleValues[i], weight); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere2D.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere2D.java index 64af4fc3f..e0db5d634 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere2D.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere2D.java @@ -16,7 +16,7 @@ */ package org.apache.commons.math4.legacy.analysis.interpolation; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.numbers.angle.PlaneAngleRadians; /** @@ -60,8 +60,8 @@ public class InterpolatingMicrosphere2D extends InterpolatingMicrosphere { for (int i = 0; i < size; i++) { final double angle = i * PlaneAngleRadians.TWO_PI / size; - add(new double[] { FastMath.cos(angle), - FastMath.sin(angle) }, + add(new double[] { AccurateMath.cos(angle), + AccurateMath.sin(angle) }, false); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/LinearInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/LinearInterpolator.java index aece38885..a2679df4f 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/LinearInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/LinearInterpolator.java @@ -22,7 +22,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Implements a linear function for interpolation of real univariate functions. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/LoessInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/LoessInterpolator.java index c56955c71..37557aaab 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/LoessInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/LoessInterpolator.java @@ -28,8 +28,8 @@ import org.apache.commons.math4.legacy.exception.NotPositiveException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.FastMath; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Implements the @@ -296,7 +296,7 @@ public class LoessInterpolator double sumXSquared = 0; double sumY = 0; double sumXY = 0; - double denom = FastMath.abs(1.0 / (xval[edge] - x)); + double denom = AccurateMath.abs(1.0 / (xval[edge] - x)); for (int k = ileft; k <= iright; ++k) { final double xk = xval[k]; final double yk = yval[k]; @@ -316,7 +316,7 @@ public class LoessInterpolator final double meanXSquared = sumXSquared / sumWeights; final double beta; - if (FastMath.sqrt(FastMath.abs(meanXSquared - meanX * meanX)) < accuracy) { + if (AccurateMath.sqrt(AccurateMath.abs(meanXSquared - meanX * meanX)) < accuracy) { beta = 0; } else { beta = (meanXY - meanX * meanY) / (meanXSquared - meanX * meanX); @@ -325,7 +325,7 @@ public class LoessInterpolator final double alpha = meanY - beta * meanX; res[i] = beta * x + alpha; - residuals[i] = FastMath.abs(yval[i] - res[i]); + residuals[i] = AccurateMath.abs(yval[i] - res[i]); } // No need to recompute the robustness weights at the last @@ -343,7 +343,7 @@ public class LoessInterpolator Arrays.sort(sortedResiduals); final double medianResidual = sortedResiduals[n / 2]; - if (FastMath.abs(medianResidual) < accuracy) { + if (AccurateMath.abs(medianResidual) < accuracy) { break; } @@ -450,7 +450,7 @@ public class LoessInterpolator * @return (1 - |x|3)3 for |x| < 1, 0 otherwise. */ private static double tricube(final double x) { - final double absX = FastMath.abs(x); + final double absX = AccurateMath.abs(x); if (absX >= 1.0) { return 0.0; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/PiecewiseBicubicSplineInterpolatingFunction.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/PiecewiseBicubicSplineInterpolatingFunction.java index 26d040dfd..31e0c5268 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/PiecewiseBicubicSplineInterpolatingFunction.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/PiecewiseBicubicSplineInterpolatingFunction.java @@ -26,7 +26,7 @@ import org.apache.commons.math4.legacy.exception.NoDataException; import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Function that implements the diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/PiecewiseBicubicSplineInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/PiecewiseBicubicSplineInterpolator.java index 09797ccbf..09f91a36c 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/PiecewiseBicubicSplineInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/PiecewiseBicubicSplineInterpolator.java @@ -20,7 +20,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NoDataException; import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException; import org.apache.commons.math4.legacy.exception.NullArgumentException; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Generates a piecewise-bicubic interpolating function. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/SplineInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/SplineInterpolator.java index 499921937..be313dd61 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/SplineInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/SplineInterpolator.java @@ -22,7 +22,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Computes a natural (also known as "free", "unclamped") cubic spline interpolation for the data set. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/TricubicInterpolatingFunction.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/TricubicInterpolatingFunction.java index 94f0a46d3..0977eb89b 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/TricubicInterpolatingFunction.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/TricubicInterpolatingFunction.java @@ -21,7 +21,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NoDataException; import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Function that implements the diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/TricubicInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/TricubicInterpolator.java index 2159c4bad..0ff84ebbd 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/TricubicInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/TricubicInterpolator.java @@ -20,7 +20,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NoDataException; import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Generates a tricubic interpolating function. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/UnivariatePeriodicInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/UnivariatePeriodicInterpolator.java index 3b6bdec67..ee1618a24 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/UnivariatePeriodicInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/UnivariatePeriodicInterpolator.java @@ -22,7 +22,7 @@ import org.apache.commons.math4.legacy.analysis.UnivariateFunction; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Adapter for classes implementing the {@link UnivariateInterpolator} diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunction.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunction.java index 9d8068f84..29f7dc6c1 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunction.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunction.java @@ -25,7 +25,7 @@ import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDiffer import org.apache.commons.math4.legacy.exception.NoDataException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Immutable representation of a real polynomial function with real coefficients. @@ -167,8 +167,8 @@ public class PolynomialFunction implements UnivariateDifferentiableFunction, Ser */ public PolynomialFunction add(final PolynomialFunction p) { // identify the lowest degree polynomial - final int lowLength = FastMath.min(coefficients.length, p.coefficients.length); - final int highLength = FastMath.max(coefficients.length, p.coefficients.length); + final int lowLength = AccurateMath.min(coefficients.length, p.coefficients.length); + final int highLength = AccurateMath.max(coefficients.length, p.coefficients.length); // build the coefficients array double[] newCoefficients = new double[highLength]; @@ -192,8 +192,8 @@ public class PolynomialFunction implements UnivariateDifferentiableFunction, Ser */ public PolynomialFunction subtract(final PolynomialFunction p) { // identify the lowest degree polynomial - int lowLength = FastMath.min(coefficients.length, p.coefficients.length); - int highLength = FastMath.max(coefficients.length, p.coefficients.length); + int lowLength = AccurateMath.min(coefficients.length, p.coefficients.length); + int highLength = AccurateMath.max(coefficients.length, p.coefficients.length); // build the coefficients array double[] newCoefficients = new double[highLength]; @@ -236,8 +236,8 @@ public class PolynomialFunction implements UnivariateDifferentiableFunction, Ser for (int i = 0; i < newCoefficients.length; ++i) { newCoefficients[i] = 0.0; - for (int j = FastMath.max(0, i + 1 - p.coefficients.length); - j < FastMath.min(coefficients.length, i + 1); + for (int j = AccurateMath.max(0, i + 1 - p.coefficients.length); + j < AccurateMath.min(coefficients.length, i + 1); ++j) { newCoefficients[i] += coefficients[j] * p.coefficients[i-j]; } @@ -320,7 +320,7 @@ public class PolynomialFunction implements UnivariateDifferentiableFunction, Ser } } - double absAi = FastMath.abs(coefficients[i]); + double absAi = AccurateMath.abs(coefficients[i]); if ((absAi - 1) != 0) { s.append(toString(absAi)); s.append(' '); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunctionLagrangeForm.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunctionLagrangeForm.java index 55f70c031..e376e2f3f 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunctionLagrangeForm.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialFunctionLagrangeForm.java @@ -21,8 +21,8 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.FastMath; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Implements the representation of a real polynomial function in @@ -215,7 +215,7 @@ public class PolynomialFunctionLagrangeForm implements UnivariateFunction { c[i] = y[i]; d[i] = y[i]; // find out the abscissa closest to z - final double dist = FastMath.abs(z - x[i]); + final double dist = AccurateMath.abs(z - x[i]); if (dist < min_dist) { nearest = i; min_dist = dist; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialSplineFunction.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialSplineFunction.java index 89f576da6..e232c97b0 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialSplineFunction.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialSplineFunction.java @@ -26,7 +26,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Represents a polynomial spline function. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialsUtils.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialsUtils.java index 2a1958a49..6497c739d 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialsUtils.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/polynomials/PolynomialsUtils.java @@ -23,7 +23,7 @@ import java.util.Map; import org.apache.commons.numbers.fraction.BigFraction; import org.apache.commons.numbers.combinatorics.BinomialCoefficient; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * A collection of static methods that operate on or return polynomials. @@ -341,7 +341,7 @@ public class PolynomialsUtils { // First polynomial coefficient. for (int i = 0; i < dp1; i++){ - newCoefficients[0] += coefficients[i] * FastMath.pow(shift, i); + newCoefficients[0] += coefficients[i] * AccurateMath.pow(shift, i); } // Superior order. @@ -349,7 +349,7 @@ public class PolynomialsUtils { for (int i = 0; i < d; i++) { for (int j = i; j < d; j++){ newCoefficients[i + 1] += coeff[j + 1][j - i] * - coefficients[j + 1] * FastMath.pow(shift, j - i); + coefficients[j + 1] * AccurateMath.pow(shift, j - i); } } @@ -368,7 +368,7 @@ public class PolynomialsUtils { final RecurrenceCoefficientsGenerator generator) { synchronized (coefficients) { - final int maxDegree = (int) FastMath.floor(FastMath.sqrt(2 * coefficients.size())) - 1; + final int maxDegree = (int) AccurateMath.floor(AccurateMath.sqrt(2 * coefficients.size())) - 1; if (degree > maxDegree) { computeUpToDegree(degree, maxDegree, generator, coefficients); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BaseSecantSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BaseSecantSolver.java index a9e81f32b..8f952e144 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BaseSecantSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BaseSecantSolver.java @@ -20,7 +20,7 @@ package org.apache.commons.math4.legacy.analysis.solvers; import org.apache.commons.math4.legacy.analysis.UnivariateFunction; import org.apache.commons.math4.legacy.exception.ConvergenceException; import org.apache.commons.math4.legacy.exception.MathInternalError; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Base class for all bracketing Secant-based methods for root-finding @@ -210,7 +210,7 @@ public abstract class BaseSecantSolver // If the function value of the last approximation is too small, // given the function value accuracy, then we can't get closer to // the root than we already are. - if (FastMath.abs(f1) <= ftol) { + if (AccurateMath.abs(f1) <= ftol) { switch (allowed) { case ANY_SIDE: return x1; @@ -241,7 +241,7 @@ public abstract class BaseSecantSolver // If the current interval is within the given accuracies, we // are satisfied with the current approximation. - if (FastMath.abs(x1 - x0) < FastMath.max(rtol * FastMath.abs(x1), + if (AccurateMath.abs(x1 - x0) < AccurateMath.max(rtol * AccurateMath.abs(x1), atol)) { switch (allowed) { case ANY_SIDE: diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BisectionSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BisectionSolver.java index 8799e4f8b..ff0290c71 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BisectionSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BisectionSolver.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.analysis.solvers; import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Implements the @@ -82,7 +82,7 @@ public class BisectionSolver extends AbstractUnivariateSolver { max = m; } - if (FastMath.abs(max - min) <= absoluteAccuracy) { + if (AccurateMath.abs(max - min) <= absoluteAccuracy) { m = UnivariateSolverUtils.midpoint(min, max); return m; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BracketedRealFieldUnivariateSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BracketedRealFieldUnivariateSolver.java index 4e3cdd9e2..623dee7e0 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BracketedRealFieldUnivariateSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BracketedRealFieldUnivariateSolver.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.analysis.solvers; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.analysis.RealFieldUnivariateFunction; /** Interface for {@link UnivariateSolver (univariate real) root-finding diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BracketingNthOrderBrentSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BracketingNthOrderBrentSolver.java index cb54e982f..3bad26297 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BracketingNthOrderBrentSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/BracketingNthOrderBrentSolver.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.exception.NoBracketingException; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.numbers.core.Precision; /** @@ -199,11 +199,11 @@ public class BracketingNthOrderBrentSolver // current tightest bracketing of the root double xA = x[signChangeIndex - 1]; double yA = y[signChangeIndex - 1]; - double absYA = FastMath.abs(yA); + double absYA = AccurateMath.abs(yA); int agingA = 0; double xB = x[signChangeIndex]; double yB = y[signChangeIndex]; - double absYB = FastMath.abs(yB); + double absYB = AccurateMath.abs(yB); int agingB = 0; // search loop @@ -211,8 +211,8 @@ public class BracketingNthOrderBrentSolver // check convergence of bracketing interval final double xTol = getAbsoluteAccuracy() + - getRelativeAccuracy() * FastMath.max(FastMath.abs(xA), FastMath.abs(xB)); - if (((xB - xA) <= xTol) || (FastMath.max(absYA, absYB) < getFunctionValueAccuracy())) { + getRelativeAccuracy() * AccurateMath.max(AccurateMath.abs(xA), AccurateMath.abs(xB)); + if (((xB - xA) <= xTol) || (AccurateMath.max(absYA, absYB) < getFunctionValueAccuracy())) { switch (allowed) { case ANY_SIDE : return absYA < absYB ? xA : xB; @@ -332,14 +332,14 @@ public class BracketingNthOrderBrentSolver // the sign change occurs before the inserted point xB = nextX; yB = nextY; - absYB = FastMath.abs(yB); + absYB = AccurateMath.abs(yB); ++agingA; agingB = 0; } else { // the sign change occurs after the inserted point xA = nextX; yA = nextY; - absYA = FastMath.abs(yA); + absYA = AccurateMath.abs(yA); agingA = 0; ++agingB; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/FieldBracketingNthOrderBrentSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/FieldBracketingNthOrderBrentSolver.java index 9d5de5e63..05d0ef017 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/FieldBracketingNthOrderBrentSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/FieldBracketingNthOrderBrentSolver.java @@ -17,15 +17,15 @@ package org.apache.commons.math4.legacy.analysis.solvers; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.analysis.RealFieldUnivariateFunction; import org.apache.commons.math4.legacy.exception.MathInternalError; import org.apache.commons.math4.legacy.exception.NoBracketingException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.util.IntegerSequence; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; import org.apache.commons.numbers.core.Precision; /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/LaguerreSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/LaguerreSolver.java index 4de3ca1fe..0f8b4adb7 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/LaguerreSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/LaguerreSolver.java @@ -25,7 +25,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Implements the @@ -101,13 +101,13 @@ public class LaguerreSolver extends AbstractPolynomialSolver { // Return the initial guess if it is good enough. final double yInitial = computeObjectiveValue(initial); - if (FastMath.abs(yInitial) <= functionValueAccuracy) { + if (AccurateMath.abs(yInitial) <= functionValueAccuracy) { return initial; } // Return the first endpoint if it is good enough. final double yMin = computeObjectiveValue(min); - if (FastMath.abs(yMin) <= functionValueAccuracy) { + if (AccurateMath.abs(yMin) <= functionValueAccuracy) { return min; } @@ -118,7 +118,7 @@ public class LaguerreSolver extends AbstractPolynomialSolver { // Return the second endpoint if it is good enough. final double yMax = computeObjectiveValue(max); - if (FastMath.abs(yMax) <= functionValueAccuracy) { + if (AccurateMath.abs(yMax) <= functionValueAccuracy) { return max; } @@ -242,8 +242,8 @@ public class LaguerreSolver extends AbstractPolynomialSolver { */ public boolean isRoot(double min, double max, Complex z) { if (isSequence(min, z.getReal(), max)) { - double tolerance = FastMath.max(getRelativeAccuracy() * z.abs(), getAbsoluteAccuracy()); - return (FastMath.abs(z.getImaginary()) <= tolerance) || + double tolerance = AccurateMath.max(getRelativeAccuracy() * z.abs(), getAbsoluteAccuracy()); + return (AccurateMath.abs(z.getImaginary()) <= tolerance) || (z.abs() <= getFunctionValueAccuracy()); } return false; @@ -348,7 +348,7 @@ public class LaguerreSolver extends AbstractPolynomialSolver { d2v = d2v.multiply(Complex.ofCartesian(2.0, 0.0)); // Check for convergence. - final double tolerance = FastMath.max(relativeAccuracy * z.abs(), + final double tolerance = AccurateMath.max(relativeAccuracy * z.abs(), absoluteAccuracy); if ((z.subtract(oldz)).abs() <= tolerance) { return z; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/MullerSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/MullerSolver.java index f8ae70e77..ac262cca5 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/MullerSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/MullerSolver.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.solvers; import org.apache.commons.math4.legacy.exception.NoBracketingException; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * This class implements the @@ -94,15 +94,15 @@ public class MullerSolver extends AbstractUnivariateSolver { // check for zeros before verifying bracketing final double fMin = computeObjectiveValue(min); - if (FastMath.abs(fMin) < functionValueAccuracy) { + if (AccurateMath.abs(fMin) < functionValueAccuracy) { return min; } final double fMax = computeObjectiveValue(max); - if (FastMath.abs(fMax) < functionValueAccuracy) { + if (AccurateMath.abs(fMax) < functionValueAccuracy) { return max; } final double fInitial = computeObjectiveValue(initial); - if (FastMath.abs(fInitial) < functionValueAccuracy) { + if (AccurateMath.abs(fInitial) < functionValueAccuracy) { return initial; } @@ -156,17 +156,17 @@ public class MullerSolver extends AbstractUnivariateSolver { final double d012 = (d12 - d01) / (x2 - x0); final double c1 = d01 + (x1 - x0) * d012; final double delta = c1 * c1 - 4 * y1 * d012; - final double xplus = x1 + (-2.0 * y1) / (c1 + FastMath.sqrt(delta)); - final double xminus = x1 + (-2.0 * y1) / (c1 - FastMath.sqrt(delta)); + final double xplus = x1 + (-2.0 * y1) / (c1 + AccurateMath.sqrt(delta)); + final double xminus = x1 + (-2.0 * y1) / (c1 - AccurateMath.sqrt(delta)); // xplus and xminus are two roots of parabola and at least // one of them should lie in (x0, x2) final double x = isSequence(x0, xplus, x2) ? xplus : xminus; final double y = computeObjectiveValue(x); // check for convergence - final double tolerance = FastMath.max(relativeAccuracy * FastMath.abs(x), absoluteAccuracy); - if (FastMath.abs(x - oldx) <= tolerance || - FastMath.abs(y) <= functionValueAccuracy) { + final double tolerance = AccurateMath.max(relativeAccuracy * AccurateMath.abs(x), absoluteAccuracy); + if (AccurateMath.abs(x - oldx) <= tolerance || + AccurateMath.abs(y) <= functionValueAccuracy) { return x; } @@ -188,7 +188,7 @@ public class MullerSolver extends AbstractUnivariateSolver { } else { double xm = 0.5 * (x0 + x2); double ym = computeObjectiveValue(xm); - if (FastMath.signum(y0) + FastMath.signum(ym) == 0.0) { + if (AccurateMath.signum(y0) + AccurateMath.signum(ym) == 0.0) { x2 = xm; y2 = ym; } else { x0 = xm; y0 = ym; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/MullerSolver2.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/MullerSolver2.java index 9ab450e29..e137ef822 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/MullerSolver2.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/MullerSolver2.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.solvers; import org.apache.commons.math4.legacy.exception.NoBracketingException; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * This class implements the @@ -99,12 +99,12 @@ public class MullerSolver2 extends AbstractUnivariateSolver { double x0 = min; double y0 = computeObjectiveValue(x0); - if (FastMath.abs(y0) < functionValueAccuracy) { + if (AccurateMath.abs(y0) < functionValueAccuracy) { return x0; } double x1 = max; double y1 = computeObjectiveValue(x1); - if (FastMath.abs(y1) < functionValueAccuracy) { + if (AccurateMath.abs(y1) < functionValueAccuracy) { return x1; } @@ -127,12 +127,12 @@ public class MullerSolver2 extends AbstractUnivariateSolver { final double denominator; if (delta >= 0.0) { // choose a denominator larger in magnitude - double dplus = b + FastMath.sqrt(delta); - double dminus = b - FastMath.sqrt(delta); - denominator = FastMath.abs(dplus) > FastMath.abs(dminus) ? dplus : dminus; + double dplus = b + AccurateMath.sqrt(delta); + double dminus = b - AccurateMath.sqrt(delta); + denominator = AccurateMath.abs(dplus) > AccurateMath.abs(dminus) ? dplus : dminus; } else { - // take the modulus of (B +/- FastMath.sqrt(delta)) - denominator = FastMath.sqrt(b * b - delta); + // take the modulus of (B +/- AccurateMath.sqrt(delta)) + denominator = AccurateMath.sqrt(b * b - delta); } if (denominator != 0) { x = x2 - 2.0 * c * (x2 - x1) / denominator; @@ -143,15 +143,15 @@ public class MullerSolver2 extends AbstractUnivariateSolver { } } else { // extremely rare case, get a random number to skip it - x = min + FastMath.random() * (max - min); + x = min + AccurateMath.random() * (max - min); oldx = Double.POSITIVE_INFINITY; } final double y = computeObjectiveValue(x); // check for convergence - final double tolerance = FastMath.max(relativeAccuracy * FastMath.abs(x), absoluteAccuracy); - if (FastMath.abs(x - oldx) <= tolerance || - FastMath.abs(y) <= functionValueAccuracy) { + final double tolerance = AccurateMath.max(relativeAccuracy * AccurateMath.abs(x), absoluteAccuracy); + if (AccurateMath.abs(x - oldx) <= tolerance || + AccurateMath.abs(y) <= functionValueAccuracy) { return x; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/NewtonRaphsonSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/NewtonRaphsonSolver.java index be3c27d46..4b2982635 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/NewtonRaphsonSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/NewtonRaphsonSolver.java @@ -20,7 +20,7 @@ package org.apache.commons.math4.legacy.analysis.solvers; import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction; import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Implements @@ -82,7 +82,7 @@ public class NewtonRaphsonSolver extends AbstractUnivariateDifferentiableSolver while (true) { final DerivativeStructure y0 = computeObjectiveValueAndDerivative(x0); x1 = x0 - (y0.getValue() / y0.getPartialDerivative(1)); - if (FastMath.abs(x1 - x0) <= absoluteAccuracy) { + if (AccurateMath.abs(x1 - x0) <= absoluteAccuracy) { return x1; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/RiddersSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/RiddersSolver.java index 40f268063..8b059750f 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/RiddersSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/RiddersSolver.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.analysis.solvers; import org.apache.commons.math4.legacy.exception.NoBracketingException; import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Implements the @@ -95,28 +95,28 @@ public class RiddersSolver extends AbstractUnivariateSolver { // calculate the new root approximation final double x3 = 0.5 * (x1 + x2); final double y3 = computeObjectiveValue(x3); - if (FastMath.abs(y3) <= functionValueAccuracy) { + if (AccurateMath.abs(y3) <= functionValueAccuracy) { return x3; } final double delta = 1 - (y1 * y2) / (y3 * y3); // delta > 1 due to bracketing - final double correction = (FastMath.signum(y2) * FastMath.signum(y3)) * - (x3 - x1) / FastMath.sqrt(delta); + final double correction = (AccurateMath.signum(y2) * AccurateMath.signum(y3)) * + (x3 - x1) / AccurateMath.sqrt(delta); final double x = x3 - correction; // correction != 0 final double y = computeObjectiveValue(x); // check for convergence - final double tolerance = FastMath.max(relativeAccuracy * FastMath.abs(x), absoluteAccuracy); - if (FastMath.abs(x - oldx) <= tolerance) { + final double tolerance = AccurateMath.max(relativeAccuracy * AccurateMath.abs(x), absoluteAccuracy); + if (AccurateMath.abs(x - oldx) <= tolerance) { return x; } - if (FastMath.abs(y) <= functionValueAccuracy) { + if (AccurateMath.abs(y) <= functionValueAccuracy) { return x; } // prepare the new interval for next iteration // Ridders' method guarantees x1 < x < x2 if (correction > 0.0) { // x1 < x < x3 - if (FastMath.signum(y1) + FastMath.signum(y) == 0.0) { + if (AccurateMath.signum(y1) + AccurateMath.signum(y) == 0.0) { x2 = x; y2 = y; } else { @@ -126,7 +126,7 @@ public class RiddersSolver extends AbstractUnivariateSolver { y2 = y3; } } else { // x3 < x < x2 - if (FastMath.signum(y2) + FastMath.signum(y) == 0.0) { + if (AccurateMath.signum(y2) + AccurateMath.signum(y) == 0.0) { x1 = x; y1 = y; } else { diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/SecantSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/SecantSolver.java index 0f42598cd..5c1e24143 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/SecantSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/SecantSolver.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.solvers; import org.apache.commons.math4.legacy.exception.NoBracketingException; import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Implements the Secant method for root-finding (approximating a @@ -120,13 +120,13 @@ public class SecantSolver extends AbstractUnivariateSolver { // If the function value of the last approximation is too small, // given the function value accuracy, then we can't get closer to // the root than we already are. - if (FastMath.abs(f1) <= ftol) { + if (AccurateMath.abs(f1) <= ftol) { return x1; } // If the current interval is within the given accuracies, we // are satisfied with the current approximation. - if (FastMath.abs(x1 - x0) < FastMath.max(rtol * FastMath.abs(x1), atol)) { + if (AccurateMath.abs(x1 - x0) < AccurateMath.max(rtol * AccurateMath.abs(x1), atol)) { return x1; } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/UnivariateSolverUtils.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/UnivariateSolverUtils.java index d03c41f19..d734345e9 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/UnivariateSolverUtils.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/UnivariateSolverUtils.java @@ -22,7 +22,7 @@ import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Utility routines for {@link UnivariateSolver} objects. @@ -111,11 +111,11 @@ public class UnivariateSolverUtils { } // find a very small interval bracketing the root - final double step = FastMath.max(bracketing.getAbsoluteAccuracy(), - FastMath.abs(baseRoot * bracketing.getRelativeAccuracy())); - double xLo = FastMath.max(min, baseRoot - step); + final double step = AccurateMath.max(bracketing.getAbsoluteAccuracy(), + AccurateMath.abs(baseRoot * bracketing.getRelativeAccuracy())); + double xLo = AccurateMath.max(min, baseRoot - step); double fLo = f.value(xLo); - double xHi = FastMath.min(max, baseRoot + step); + double xHi = AccurateMath.min(max, baseRoot + step); double fHi = f.value(xHi); int remainingEval = maxEval - 2; while (remainingEval > 0) { @@ -150,14 +150,14 @@ public class UnivariateSolverUtils { // update the lower bound if (changeLo) { - xLo = FastMath.max(min, xLo - step); + xLo = AccurateMath.max(min, xLo - step); fLo = f.value(xLo); remainingEval--; } // update the higher bound if (changeHi) { - xHi = FastMath.min(max, xHi + step); + xHi = AccurateMath.min(max, xHi + step); fHi = f.value(xHi); remainingEval--; } @@ -325,8 +325,8 @@ public class UnivariateSolverUtils { final double previousFb = fb; delta = r * delta + q; - a = FastMath.max(initial - delta, lowerBound); - b = FastMath.min(initial + delta, upperBound); + a = AccurateMath.max(initial - delta, lowerBound); + b = AccurateMath.min(initial + delta, upperBound); fa = function.value(a); fb = function.value(b); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractIntegerDistribution.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractIntegerDistribution.java index ab71159d4..78e81c65e 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractIntegerDistribution.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractIntegerDistribution.java @@ -27,7 +27,7 @@ import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.sampling.distribution.InverseTransformDiscreteSampler; import org.apache.commons.rng.sampling.distribution.DiscreteInverseCumulativeProbabilityFunction; import org.apache.commons.rng.sampling.distribution.DiscreteSampler; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Base class for integer-valued discrete distributions. Default @@ -94,19 +94,19 @@ public abstract class AbstractIntegerDistribution implements DiscreteDistributio // use the one-sided Chebyshev inequality to narrow the bracket // cf. AbstractRealDistribution.inverseCumulativeProbability(double) final double mu = getMean(); - final double sigma = FastMath.sqrt(getVariance()); + final double sigma = AccurateMath.sqrt(getVariance()); final boolean chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) || Double.isInfinite(sigma) || Double.isNaN(sigma) || sigma == 0.0); if (chebyshevApplies) { - double k = FastMath.sqrt((1.0 - p) / p); + double k = AccurateMath.sqrt((1.0 - p) / p); double tmp = mu - k * sigma; if (tmp > lower) { - lower = ((int) FastMath.ceil(tmp)) - 1; + lower = ((int) AccurateMath.ceil(tmp)) - 1; } k = 1.0 / k; tmp = mu + k * sigma; if (tmp < upper) { - upper = ((int) FastMath.ceil(tmp)) - 1; + upper = ((int) AccurateMath.ceil(tmp)) - 1; } } @@ -175,7 +175,7 @@ public abstract class AbstractIntegerDistribution implements DiscreteDistributio */ @Override public double logProbability(int x) { - return FastMath.log(probability(x)); + return AccurateMath.log(probability(x)); } /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractRealDistribution.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractRealDistribution.java index 069565d04..23cb7be08 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractRealDistribution.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractRealDistribution.java @@ -28,7 +28,7 @@ import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.sampling.distribution.InverseTransformContinuousSampler; import org.apache.commons.rng.sampling.distribution.ContinuousInverseCumulativeProbabilityFunction; import org.apache.commons.rng.sampling.distribution.ContinuousSampler; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Base class for probability distributions on the reals. @@ -134,14 +134,14 @@ public abstract class AbstractRealDistribution } final double mu = getMean(); - final double sig = FastMath.sqrt(getVariance()); + final double sig = AccurateMath.sqrt(getVariance()); final boolean chebyshevApplies; chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) || Double.isInfinite(sig) || Double.isNaN(sig)); if (lowerBound == Double.NEGATIVE_INFINITY) { if (chebyshevApplies) { - lowerBound = mu - sig * FastMath.sqrt((1. - p) / p); + lowerBound = mu - sig * AccurateMath.sqrt((1. - p) / p); } else { lowerBound = -1.0; while (cumulativeProbability(lowerBound) >= p) { @@ -152,7 +152,7 @@ public abstract class AbstractRealDistribution if (upperBound == Double.POSITIVE_INFINITY) { if (chebyshevApplies) { - upperBound = mu + sig * FastMath.sqrt(p / (1. - p)); + upperBound = mu + sig * AccurateMath.sqrt(p / (1. - p)); } else { upperBound = 1.0; while (cumulativeProbability(upperBound) < p) { @@ -225,7 +225,7 @@ public abstract class AbstractRealDistribution */ @Override public double logDensity(double x) { - return FastMath.log(density(x)); + return AccurateMath.log(density(x)); } /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EmpiricalDistribution.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EmpiricalDistribution.java index 63da838f0..47814f9d8 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EmpiricalDistribution.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EmpiricalDistribution.java @@ -42,7 +42,7 @@ import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; import org.apache.commons.math4.legacy.stat.descriptive.StatisticalSummary; import org.apache.commons.math4.legacy.stat.descriptive.SummaryStatistics; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** *

Represents an @@ -399,8 +399,8 @@ public class EmpiricalDistribution extends AbstractRealDistribution * @return the index of the bin containing the value */ private int findBin(double value) { - return FastMath.min( - FastMath.max((int) FastMath.ceil((value - min) / delta) - 1, 0), + return AccurateMath.min( + AccurateMath.max((int) AccurateMath.ceil((value - min) / delta) - 1, 0), binCount - 1); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EnumeratedDistribution.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EnumeratedDistribution.java index 8c032a044..a7d4d9358 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EnumeratedDistribution.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EnumeratedDistribution.java @@ -30,7 +30,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.sampling.DiscreteProbabilityCollectionSampler; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; import org.apache.commons.math4.legacy.util.Pair; /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/MultivariateNormalDistribution.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/MultivariateNormalDistribution.java index e220d1069..6a72dbb85 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/MultivariateNormalDistribution.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/MultivariateNormalDistribution.java @@ -26,7 +26,7 @@ import org.apache.commons.math4.legacy.linear.NonPositiveDefiniteMatrixException import org.apache.commons.math4.legacy.linear.RealMatrix; import org.apache.commons.math4.legacy.linear.SingularMatrixException; import org.apache.commons.rng.UniformRandomProvider; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Implementation of the multivariate normal (Gaussian) distribution. @@ -120,7 +120,7 @@ public class MultivariateNormalDistribution // Scale each eigenvector by the square root of its eigenvalue. for (int row = 0; row < dim; row++) { - final double factor = FastMath.sqrt(covMatEigenvalues[row]); + final double factor = AccurateMath.sqrt(covMatEigenvalues[row]); for (int col = 0; col < dim; col++) { tmpMatrix.multiplyEntry(row, col, factor); } @@ -155,8 +155,8 @@ public class MultivariateNormalDistribution throw new DimensionMismatchException(vals.length, dim); } - return FastMath.pow(2 * FastMath.PI, -0.5 * dim) * - FastMath.pow(covarianceMatrixDeterminant, -0.5) * + return AccurateMath.pow(2 * AccurateMath.PI, -0.5 * dim) * + AccurateMath.pow(covarianceMatrixDeterminant, -0.5) * getExponentTerm(vals); } @@ -171,7 +171,7 @@ public class MultivariateNormalDistribution final double[] std = new double[dim]; final double[][] s = covarianceMatrix.getData(); for (int i = 0; i < dim; i++) { - std[i] = FastMath.sqrt(s[i][i]); + std[i] = AccurateMath.sqrt(s[i][i]); } return std; } @@ -220,6 +220,6 @@ public class MultivariateNormalDistribution for (int i = 0; i < preMultiplied.length; i++) { sum += preMultiplied[i] * centered[i]; } - return FastMath.exp(-0.5 * sum); + return AccurateMath.exp(-0.5 * sum); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/fitting/MultivariateNormalMixtureExpectationMaximization.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/fitting/MultivariateNormalMixtureExpectationMaximization.java index f2de4aa44..c5b2c3abd 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/fitting/MultivariateNormalMixtureExpectationMaximization.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/fitting/MultivariateNormalMixtureExpectationMaximization.java @@ -32,8 +32,8 @@ import org.apache.commons.math4.legacy.linear.Array2DRowRealMatrix; import org.apache.commons.math4.legacy.linear.RealMatrix; import org.apache.commons.math4.legacy.linear.SingularMatrixException; import org.apache.commons.math4.legacy.stat.correlation.Covariance; -import org.apache.commons.math4.legacy.util.FastMath; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.legacy.core.MathArrays; import org.apache.commons.math4.legacy.util.Pair; /** @@ -166,7 +166,7 @@ public class MultivariateNormalMixtureExpectationMaximization { fittedModel = new MixtureMultivariateNormalDistribution(initialMixture.getComponents()); while (numIterations++ <= maxIterations && - FastMath.abs(previousLogLikelihood - logLikelihood) > threshold) { + AccurateMath.abs(previousLogLikelihood - logLikelihood) > threshold) { previousLogLikelihood = logLikelihood; double sumLogLikelihood = 0d; @@ -198,7 +198,7 @@ public class MultivariateNormalMixtureExpectationMaximization { for (int i = 0; i < n; i++) { final double rowDensity = fittedModel.density(data[i]); - sumLogLikelihood += FastMath.log(rowDensity); + sumLogLikelihood += AccurateMath.log(rowDensity); for (int j = 0; j < k; j++) { gamma[i][j] = weights[j] * mvns[j].density(data[i]) / rowDensity; @@ -252,7 +252,7 @@ public class MultivariateNormalMixtureExpectationMaximization { newCovMatArrays); } - if (FastMath.abs(previousLogLikelihood - logLikelihood) > threshold) { + if (AccurateMath.abs(previousLogLikelihood - logLikelihood) > threshold) { // Did not converge before the maximum number of iterations throw new ConvergenceException(); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/GaussianCurveFitter.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/GaussianCurveFitter.java index 69a4802af..e2d8897d2 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/GaussianCurveFitter.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/GaussianCurveFitter.java @@ -25,7 +25,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Fits points to a {@link @@ -173,7 +173,7 @@ public class GaussianCurveFitter extends SimpleCurveFitter { // TODO: Exceptions should not be used for flow control. fwhmApprox = points[points.length - 1].getX() - points[0].getX(); } - final double s = fwhmApprox / (2 * FastMath.sqrt(2 * FastMath.log(2))); + final double s = fwhmApprox / (2 * AccurateMath.sqrt(2 * AccurateMath.log(2))); return new double[] { n, points[maxYIdx].getX(), s }; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/HarmonicCurveFitter.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/HarmonicCurveFitter.java index 51c6b6761..5642113e3 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/HarmonicCurveFitter.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/HarmonicCurveFitter.java @@ -25,7 +25,7 @@ import org.apache.commons.math4.legacy.exception.MathIllegalStateException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.ZeroException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Fits points to a {@link @@ -290,8 +290,8 @@ public class HarmonicCurveFitter extends SimpleCurveFitter { throw new MathIllegalStateException(LocalizedFormats.ZERO_DENOMINATOR); } - aOmega[0] = FastMath.sqrt(c1 / c2); - aOmega[1] = FastMath.sqrt(c2 / c3); + aOmega[0] = AccurateMath.sqrt(c1 / c2); + aOmega[1] = AccurateMath.sqrt(c2 / c3); } return aOmega; @@ -321,13 +321,13 @@ public class HarmonicCurveFitter extends SimpleCurveFitter { final double currentYPrime = (currentY - previousY) / (currentX - previousX); double omegaX = omega * currentX; - double cosine = FastMath.cos(omegaX); - double sine = FastMath.sin(omegaX); + double cosine = AccurateMath.cos(omegaX); + double sine = AccurateMath.sin(omegaX); fcMean += omega * currentY * cosine - currentYPrime * sine; fsMean += omega * currentY * sine + currentYPrime * cosine; } - return FastMath.atan2(-fsMean, fcMean); + return AccurateMath.atan2(-fsMean, fcMean); } } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/AbstractEvaluation.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/AbstractEvaluation.java index b7516dc12..d65f10030 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/AbstractEvaluation.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/AbstractEvaluation.java @@ -22,7 +22,7 @@ import org.apache.commons.math4.legacy.linear.DecompositionSolver; import org.apache.commons.math4.legacy.linear.QRDecomposition; import org.apache.commons.math4.legacy.linear.RealMatrix; import org.apache.commons.math4.legacy.linear.RealVector; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * An implementation of {@link Evaluation} that is designed for extension. All of the @@ -69,7 +69,7 @@ public abstract class AbstractEvaluation implements Evaluation { final int nC = cov.getColumnDimension(); final RealVector sig = new ArrayRealVector(nC); for (int i = 0; i < nC; ++i) { - sig.setEntry(i, FastMath.sqrt(cov.getEntry(i,i))); + sig.setEntry(i, AccurateMath.sqrt(cov.getEntry(i,i))); } return sig; } @@ -77,13 +77,13 @@ public abstract class AbstractEvaluation implements Evaluation { /** {@inheritDoc} */ @Override public double getRMS() { - return FastMath.sqrt(getReducedChiSquare(1)); + return AccurateMath.sqrt(getReducedChiSquare(1)); } /** {@inheritDoc} */ @Override public double getCost() { - return FastMath.sqrt(getChiSquare()); + return AccurateMath.sqrt(getChiSquare()); } /** {@inheritDoc} */ diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LeastSquaresFactory.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LeastSquaresFactory.java index d8153ffb5..07af54297 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LeastSquaresFactory.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LeastSquaresFactory.java @@ -30,7 +30,7 @@ import org.apache.commons.math4.legacy.linear.RealVector; import org.apache.commons.math4.legacy.optim.AbstractOptimizationProblem; import org.apache.commons.math4.legacy.optim.ConvergenceChecker; import org.apache.commons.math4.legacy.optim.PointVectorValuePair; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.math4.legacy.util.IntegerSequence; import org.apache.commons.math4.legacy.util.Pair; @@ -278,7 +278,7 @@ public class LeastSquaresFactory { final int dim = m.getRowDimension(); final RealMatrix sqrtM = new DiagonalMatrix(dim); for (int i = 0; i < dim; i++) { - sqrtM.setEntry(i, i, FastMath.sqrt(m.getEntry(i, i))); + sqrtM.setEntry(i, i, AccurateMath.sqrt(m.getEntry(i, i))); } return sqrtM; } else { diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LevenbergMarquardtOptimizer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LevenbergMarquardtOptimizer.java index 7bd1749b8..a44caad2c 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LevenbergMarquardtOptimizer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/fitting/leastsquares/LevenbergMarquardtOptimizer.java @@ -24,7 +24,7 @@ import org.apache.commons.math4.legacy.fitting.leastsquares.LeastSquaresProblem. import org.apache.commons.math4.legacy.linear.ArrayRealVector; import org.apache.commons.math4.legacy.linear.RealMatrix; import org.apache.commons.math4.legacy.optim.ConvergenceChecker; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.math4.legacy.util.IntegerSequence; import org.apache.commons.numbers.core.Precision; @@ -305,7 +305,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { final ConvergenceChecker checker = problem.getConvergenceChecker(); // arrays shared with the other private methods - final int solvedCols = FastMath.min(nR, nC); + final int solvedCols = AccurateMath.min(nR, nC); /* Parameters evolution direction associated with lmPar. */ double[] lmDir = new double[nC]; /* Levenberg-Marquardt parameter. */ @@ -375,7 +375,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { xNorm += xk * xk; diag[k] = dk; } - xNorm = FastMath.sqrt(xNorm); + xNorm = AccurateMath.sqrt(xNorm); // initialize the step bound delta delta = (xNorm == 0) ? initialStepBoundFactor : (initialStepBoundFactor * xNorm); @@ -392,7 +392,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { for (int i = 0; i <= j; ++i) { sum += weightedJacobian[i][pj] * qtf[i]; } - maxCosine = FastMath.max(maxCosine, FastMath.abs(sum) / (s * currentCost)); + maxCosine = AccurateMath.max(maxCosine, AccurateMath.abs(sum) / (s * currentCost)); } } } @@ -406,7 +406,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { // rescale if necessary for (int j = 0; j < nC; ++j) { - diag[j] = FastMath.max(diag[j], jacNorm[j]); + diag[j] = AccurateMath.max(diag[j], jacNorm[j]); } // Inner loop. @@ -436,10 +436,10 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { double s = diag[pj] * lmDir[pj]; lmNorm += s * s; } - lmNorm = FastMath.sqrt(lmNorm); + lmNorm = AccurateMath.sqrt(lmNorm); // on the first iteration, adjust the initial step bound. if (firstIteration) { - delta = FastMath.min(delta, lmNorm); + delta = AccurateMath.min(delta, lmNorm); } // Evaluate the function at x + p and calculate its norm. @@ -486,7 +486,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { if ((0.1 * currentCost >= previousCost) || (tmp < 0.1)) { tmp = 0.1; } - delta = tmp * FastMath.min(delta, 10.0 * lmNorm); + delta = tmp * AccurateMath.min(delta, 10.0 * lmNorm); lmPar /= tmp; } else if ((lmPar == 0) || (ratio >= 0.75)) { delta = 2 * lmNorm; @@ -502,7 +502,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { double xK = diag[k] * currentPoint[k]; xNorm += xK * xK; } - xNorm = FastMath.sqrt(xNorm); + xNorm = AccurateMath.sqrt(xNorm); // tests for convergence. if (checker != null && checker.converged(iterationCounter.getCount(), previous, current)) { @@ -523,7 +523,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { } // Default convergence criteria. - if ((FastMath.abs(actRed) <= costRelativeTolerance && + if ((AccurateMath.abs(actRed) <= costRelativeTolerance && preRed <= costRelativeTolerance && ratio <= 2.0) || delta <= parRelativeTolerance * xNorm) { @@ -531,7 +531,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { } // tests for termination and stringent tolerances - if (FastMath.abs(actRed) <= TWO_EPS && + if (AccurateMath.abs(actRed) <= TWO_EPS && preRed <= TWO_EPS && ratio <= 2.0) { throw new ConvergenceException(LocalizedFormats.TOO_SMALL_COST_RELATIVE_TOLERANCE, @@ -655,7 +655,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { work1[pj] = s; dxNorm += s * s; } - dxNorm = FastMath.sqrt(dxNorm); + dxNorm = AccurateMath.sqrt(dxNorm); double fp = dxNorm - delta; if (fp <= 0.1 * delta) { lmPar = 0; @@ -697,15 +697,15 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { sum /= diag[pj]; sum2 += sum * sum; } - double gNorm = FastMath.sqrt(sum2); + double gNorm = AccurateMath.sqrt(sum2); double paru = gNorm / delta; if (paru == 0) { - paru = Precision.SAFE_MIN / FastMath.min(delta, 0.1); + paru = Precision.SAFE_MIN / AccurateMath.min(delta, 0.1); } // if the input par lies outside of the interval (parl,paru), // set par to the closer endpoint - lmPar = FastMath.min(paru, FastMath.max(lmPar, parl)); + lmPar = AccurateMath.min(paru, AccurateMath.max(lmPar, parl)); if (lmPar == 0) { lmPar = gNorm / dxNorm; } @@ -714,9 +714,9 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { // evaluate the function at the current value of lmPar if (lmPar == 0) { - lmPar = FastMath.max(Precision.SAFE_MIN, 0.001 * paru); + lmPar = AccurateMath.max(Precision.SAFE_MIN, 0.001 * paru); } - double sPar = FastMath.sqrt(lmPar); + double sPar = AccurateMath.sqrt(lmPar); for (int j = 0; j < solvedCols; ++j) { int pj = permutation[j]; work1[pj] = sPar * diag[pj]; @@ -730,13 +730,13 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { work3[pj] = s; dxNorm += s * s; } - dxNorm = FastMath.sqrt(dxNorm); + dxNorm = AccurateMath.sqrt(dxNorm); double previousFP = fp; fp = dxNorm - delta; // if the function is small enough, accept the current value // of lmPar, also test for the exceptional cases where parl is zero - if (FastMath.abs(fp) <= 0.1 * delta || + if (AccurateMath.abs(fp) <= 0.1 * delta || (parl == 0 && fp <= previousFP && previousFP < 0)) { @@ -765,13 +765,13 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { // depending on the sign of the function, update parl or paru. if (fp > 0) { - parl = FastMath.max(parl, lmPar); + parl = AccurateMath.max(parl, lmPar); } else if (fp < 0) { - paru = FastMath.min(paru, lmPar); + paru = AccurateMath.min(paru, lmPar); } // compute an improved estimate for lmPar - lmPar = FastMath.max(parl, lmPar + correction); + lmPar = AccurateMath.max(parl, lmPar + correction); } return lmPar; @@ -847,13 +847,13 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { final double sin; final double cos; double rkk = weightedJacobian[k][pk]; - if (FastMath.abs(rkk) < FastMath.abs(lmDiag[k])) { + if (AccurateMath.abs(rkk) < AccurateMath.abs(lmDiag[k])) { final double cotan = rkk / lmDiag[k]; - sin = 1.0 / FastMath.sqrt(1.0 + cotan * cotan); + sin = 1.0 / AccurateMath.sqrt(1.0 + cotan * cotan); cos = sin * cotan; } else { final double tan = lmDiag[k] / rkk; - cos = 1.0 / FastMath.sqrt(1.0 + tan * tan); + cos = 1.0 / AccurateMath.sqrt(1.0 + tan * tan); sin = cos * tan; } @@ -956,7 +956,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { double akk = weightedJacobian[i][k]; norm2 += akk * akk; } - jacNorm[k] = FastMath.sqrt(norm2); + jacNorm[k] = AccurateMath.sqrt(norm2); } // transform the matrix column after column @@ -989,7 +989,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { // choose alpha such that Hk.u = alpha ek double akk = weightedJacobian[k][pk]; - double alpha = (akk > 0) ? -FastMath.sqrt(ak2) : FastMath.sqrt(ak2); + double alpha = (akk > 0) ? -AccurateMath.sqrt(ak2) : AccurateMath.sqrt(ak2); double betak = 1.0 / (ak2 - akk * alpha); beta[pk] = betak; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/ElitisticListPopulation.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/ElitisticListPopulation.java index 716af3a95..1bb7822dd 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/ElitisticListPopulation.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/ElitisticListPopulation.java @@ -24,7 +24,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Population of chromosomes which uses elitism (certain percentage of the best @@ -87,7 +87,7 @@ public class ElitisticListPopulation extends ListPopulation { Collections.sort(oldChromosomes); // index of the last "not good enough" chromosome - int boundIndex = (int) FastMath.ceil((1.0 - getElitismRate()) * oldChromosomes.size()); + int boundIndex = (int) AccurateMath.ceil((1.0 - getElitismRate()) * oldChromosomes.size()); for (int i = boundIndex; i < oldChromosomes.size(); i++) { nextGeneration.addChromosome(oldChromosomes.get(i)); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/OrderedCrossover.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/OrderedCrossover.java index b1451988a..c28c253f0 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/OrderedCrossover.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/genetics/OrderedCrossover.java @@ -26,7 +26,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; import org.apache.commons.rng.UniformRandomProvider; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Order 1 Crossover [OX1] builds offspring from ordered chromosomes by copying a @@ -111,8 +111,8 @@ public class OrderedCrossover implements CrossoverPolicy { b = random.nextInt(length); } while (a == b); // determine the lower and upper bounds - final int lb = FastMath.min(a, b); - final int ub = FastMath.max(a, b); + final int lb = AccurateMath.min(a, b); + final int ub = AccurateMath.max(a, b); // add the subLists that are between lb and ub child1.addAll(parent1Rep.subList(lb, ub + 1)); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/AbstractFieldMatrix.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/AbstractFieldMatrix.java index f5c21b57d..80423454b 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/AbstractFieldMatrix.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/AbstractFieldMatrix.java @@ -19,8 +19,8 @@ package org.apache.commons.math4.legacy.linear; import java.util.ArrayList; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.FieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.FieldElement; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NoDataException; import org.apache.commons.math4.legacy.exception.NotPositiveException; @@ -29,7 +29,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Basic implementation of {@link FieldMatrix} methods regardless of the underlying storage. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/AbstractRealMatrix.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/AbstractRealMatrix.java index c1539b8da..264cbcb87 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/AbstractRealMatrix.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/AbstractRealMatrix.java @@ -28,7 +28,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Basic implementation of RealMatrix methods regardless of the underlying storage. @@ -270,9 +270,9 @@ public abstract class AbstractRealMatrix /** {@inheritDoc} */ @Override public void visit(final int row, final int column, final double value) { - columnSum += FastMath.abs(value); + columnSum += AccurateMath.abs(value); if (row == endRow) { - maxColSum = FastMath.max(maxColSum, columnSum); + maxColSum = AccurateMath.max(maxColSum, columnSum); columnSum = 0; } } @@ -310,7 +310,7 @@ public abstract class AbstractRealMatrix /** {@inheritDoc} */ @Override public double end() { - return FastMath.sqrt(sum); + return AccurateMath.sqrt(sum); } }); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/Array2DRowFieldMatrix.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/Array2DRowFieldMatrix.java index 474a6cbaa..215ee16f2 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/Array2DRowFieldMatrix.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/Array2DRowFieldMatrix.java @@ -19,8 +19,8 @@ package org.apache.commons.math4.legacy.linear; import java.io.Serializable; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.FieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.FieldElement; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.MathIllegalStateException; import org.apache.commons.math4.legacy.exception.NoDataException; @@ -29,7 +29,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Implementation of {@code FieldMatrix} using a {@link FieldElement}[][] array to store entries. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/ArrayFieldVector.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/ArrayFieldVector.java index 9d8944f3f..46789ddab 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/ArrayFieldVector.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/ArrayFieldVector.java @@ -19,8 +19,8 @@ package org.apache.commons.math4.legacy.linear; import java.io.Serializable; import java.util.Arrays; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.FieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.FieldElement; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.MathArithmeticException; import org.apache.commons.math4.legacy.exception.NotPositiveException; @@ -30,7 +30,7 @@ import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.ZeroException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * This class implements the {@link FieldVector} interface with a {@link FieldElement} array. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/ArrayRealVector.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/ArrayRealVector.java index 95b8f7b5b..0858c86eb 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/ArrayRealVector.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/ArrayRealVector.java @@ -28,7 +28,7 @@ import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * This class implements the {@link RealVector} interface with a double array. @@ -470,7 +470,7 @@ public class ArrayRealVector extends RealVector implements Serializable { for (double a : data) { sum += a * a; } - return FastMath.sqrt(sum); + return AccurateMath.sqrt(sum); } /** {@inheritDoc} */ @@ -478,7 +478,7 @@ public class ArrayRealVector extends RealVector implements Serializable { public double getL1Norm() { double sum = 0; for (double a : data) { - sum += FastMath.abs(a); + sum += AccurateMath.abs(a); } return sum; } @@ -488,7 +488,7 @@ public class ArrayRealVector extends RealVector implements Serializable { public double getLInfNorm() { double max = 0; for (double a : data) { - max = FastMath.max(max, FastMath.abs(a)); + max = AccurateMath.max(max, AccurateMath.abs(a)); } return max; } @@ -504,7 +504,7 @@ public class ArrayRealVector extends RealVector implements Serializable { final double delta = data[i] - vData[i]; sum += delta * delta; } - return FastMath.sqrt(sum); + return AccurateMath.sqrt(sum); } else { checkVectorDimensions(v); double sum = 0; @@ -512,7 +512,7 @@ public class ArrayRealVector extends RealVector implements Serializable { final double delta = data[i] - v.getEntry(i); sum += delta * delta; } - return FastMath.sqrt(sum); + return AccurateMath.sqrt(sum); } } @@ -526,7 +526,7 @@ public class ArrayRealVector extends RealVector implements Serializable { double sum = 0; for (int i = 0; i < data.length; ++i) { final double delta = data[i] - vData[i]; - sum += FastMath.abs(delta); + sum += AccurateMath.abs(delta); } return sum; } else { @@ -534,7 +534,7 @@ public class ArrayRealVector extends RealVector implements Serializable { double sum = 0; for (int i = 0; i < data.length; ++i) { final double delta = data[i] - v.getEntry(i); - sum += FastMath.abs(delta); + sum += AccurateMath.abs(delta); } return sum; } @@ -550,7 +550,7 @@ public class ArrayRealVector extends RealVector implements Serializable { double max = 0; for (int i = 0; i < data.length; ++i) { final double delta = data[i] - vData[i]; - max = FastMath.max(max, FastMath.abs(delta)); + max = AccurateMath.max(max, AccurateMath.abs(delta)); } return max; } else { @@ -558,7 +558,7 @@ public class ArrayRealVector extends RealVector implements Serializable { double max = 0; for (int i = 0; i < data.length; ++i) { final double delta = data[i] - v.getEntry(i); - max = FastMath.max(max, FastMath.abs(delta)); + max = AccurateMath.max(max, AccurateMath.abs(delta)); } return max; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BiDiagonalTransformer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BiDiagonalTransformer.java index 8e185d5a5..e0630a031 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BiDiagonalTransformer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BiDiagonalTransformer.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.linear; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** @@ -62,7 +62,7 @@ class BiDiagonalTransformer { final int m = matrix.getRowDimension(); final int n = matrix.getColumnDimension(); - final int p = FastMath.min(m, n); + final int p = AccurateMath.min(m, n); householderVectors = matrix.getData(); main = new double[p]; secondary = new double[p - 1]; @@ -266,7 +266,7 @@ class BiDiagonalTransformer { xNormSqr += c * c; } final double[] hK = householderVectors[k]; - final double a = (hK[k] > 0) ? -FastMath.sqrt(xNormSqr) : FastMath.sqrt(xNormSqr); + final double a = (hK[k] > 0) ? -AccurateMath.sqrt(xNormSqr) : AccurateMath.sqrt(xNormSqr); main[k] = a; if (a != 0.0) { hK[k] -= a; @@ -291,7 +291,7 @@ class BiDiagonalTransformer { final double c = hK[j]; xNormSqr += c * c; } - final double b = (hK[k + 1] > 0) ? -FastMath.sqrt(xNormSqr) : FastMath.sqrt(xNormSqr); + final double b = (hK[k + 1] > 0) ? -AccurateMath.sqrt(xNormSqr) : AccurateMath.sqrt(xNormSqr); secondary[k] = b; if (b != 0.0) { hK[k + 1] -= b; @@ -330,7 +330,7 @@ class BiDiagonalTransformer { final double c = hK[j]; xNormSqr += c * c; } - final double a = (hK[k] > 0) ? -FastMath.sqrt(xNormSqr) : FastMath.sqrt(xNormSqr); + final double a = (hK[k] > 0) ? -AccurateMath.sqrt(xNormSqr) : AccurateMath.sqrt(xNormSqr); main[k] = a; if (a != 0.0) { hK[k] -= a; @@ -355,7 +355,7 @@ class BiDiagonalTransformer { final double c = householderVectors[i][k]; xNormSqr += c * c; } - final double b = (hKp1[k] > 0) ? -FastMath.sqrt(xNormSqr) : FastMath.sqrt(xNormSqr); + final double b = (hKp1[k] > 0) ? -AccurateMath.sqrt(xNormSqr) : AccurateMath.sqrt(xNormSqr); secondary[k] = b; if (b != 0.0) { hKp1[k] -= b; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BigReal.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BigReal.java index ec22ccad3..807854464 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BigReal.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BigReal.java @@ -23,8 +23,8 @@ import java.math.BigInteger; import java.math.MathContext; import java.math.RoundingMode; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.FieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.FieldElement; import org.apache.commons.math4.legacy.exception.MathArithmeticException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BigRealField.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BigRealField.java index 71755bb69..cddfe6821 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BigRealField.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BigRealField.java @@ -19,8 +19,8 @@ package org.apache.commons.math4.legacy.linear; import java.io.Serializable; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.FieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.FieldElement; /** * Representation of real numbers with arbitrary precision field. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockFieldMatrix.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockFieldMatrix.java index b255b9cd9..3caf51ea5 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockFieldMatrix.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockFieldMatrix.java @@ -19,8 +19,8 @@ package org.apache.commons.math4.legacy.linear; import java.io.Serializable; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.FieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.FieldElement; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NoDataException; import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; @@ -28,8 +28,8 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.FastMath; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Cache-friendly implementation of FieldMatrix using a flat arrays to store @@ -224,11 +224,11 @@ public class BlockFieldMatrix> extends AbstractFieldMa int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); final int iHeight = pEnd - pStart; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); final int jWidth = qEnd - qStart; // allocate new block @@ -273,11 +273,11 @@ public class BlockFieldMatrix> extends AbstractFieldMa int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); final int iHeight = pEnd - pStart; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); final int jWidth = qEnd - qStart; blocks[blockIndex] = MathArrays.buildArray(field, iHeight * jWidth); ++blockIndex; @@ -333,9 +333,9 @@ public class BlockFieldMatrix> extends AbstractFieldMa final T[] outBlock = out.blocks[blockIndex]; final T[] tBlock = blocks[blockIndex]; final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); int k = 0; for (int p = pStart; p < pEnd; ++p) { for (int q = qStart; q < qEnd; ++q) { @@ -404,9 +404,9 @@ public class BlockFieldMatrix> extends AbstractFieldMa final T[] outBlock = out.blocks[blockIndex]; final T[] tBlock = blocks[blockIndex]; final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); int k = 0; for (int p = pStart; p < pEnd; ++p) { for (int q = qStart; q < qEnd; ++q) { @@ -505,12 +505,12 @@ public class BlockFieldMatrix> extends AbstractFieldMa for (int iBlock = 0; iBlock < out.blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < out.blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = FastMath.min(qStart + BLOCK_SIZE, m.getColumnDimension()); + final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, m.getColumnDimension()); // select current block final T[] outBlock = out.blocks[blockIndex]; @@ -567,7 +567,7 @@ public class BlockFieldMatrix> extends AbstractFieldMa for (int iBlock = 0; iBlock < out.blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < out.blockColumns; ++jBlock) { final int jWidth = out.blockWidth(jBlock); @@ -627,7 +627,7 @@ public class BlockFieldMatrix> extends AbstractFieldMa for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); int regularPos = 0; int lastPos = 0; for (int p = pStart; p < pEnd; ++p) { @@ -804,14 +804,14 @@ public class BlockFieldMatrix> extends AbstractFieldMa for (int iBlock = blockStartRow; iBlock < blockEndRow; ++iBlock) { final int iHeight = blockHeight(iBlock); final int firstRow = iBlock * BLOCK_SIZE; - final int iStart = FastMath.max(row, firstRow); - final int iEnd = FastMath.min(endRow + 1, firstRow + iHeight); + final int iStart = AccurateMath.max(row, firstRow); + final int iEnd = AccurateMath.min(endRow + 1, firstRow + iHeight); for (int jBlock = blockStartColumn; jBlock < blockEndColumn; ++jBlock) { final int jWidth = blockWidth(jBlock); final int firstColumn = jBlock * BLOCK_SIZE; - final int jStart = FastMath.max(column, firstColumn); - final int jEnd = FastMath.min(endColumn + 1, firstColumn + jWidth); + final int jStart = AccurateMath.max(column, firstColumn); + final int jEnd = AccurateMath.min(endColumn + 1, firstColumn + jWidth); final int jLength = jEnd - jStart; // handle one block, row by row @@ -1226,9 +1226,9 @@ public class BlockFieldMatrix> extends AbstractFieldMa final T[] outBlock = out.blocks[blockIndex]; final T[] tBlock = blocks[jBlock * blockColumns + iBlock]; final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, columns); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, columns); final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = FastMath.min(qStart + BLOCK_SIZE, rows); + final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, rows); int k = 0; for (int p = pStart; p < pEnd; ++p) { final int lInc = pEnd - pStart; @@ -1273,11 +1273,11 @@ public class BlockFieldMatrix> extends AbstractFieldMa // perform multiplication block-wise, to ensure good cache behavior for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final T[] block = blocks[iBlock * blockColumns + jBlock]; final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); int k = 0; for (int p = pStart; p < pEnd; ++p) { T sum = zero; @@ -1319,11 +1319,11 @@ public class BlockFieldMatrix> extends AbstractFieldMa final int jWidth3 = jWidth2 + jWidth; final int jWidth4 = jWidth3 + jWidth; final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final T[] block = blocks[iBlock * blockColumns + jBlock]; final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); for (int q = qStart; q < qEnd; ++q) { int k = q - qStart; T sum = zero; @@ -1355,12 +1355,12 @@ public class BlockFieldMatrix> extends AbstractFieldMa visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); for (int p = pStart; p < pEnd; ++p) { for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); final T[] block = blocks[iBlock * blockColumns + jBlock]; int k = (p - pStart) * jWidth; for (int q = qStart; q < qEnd; ++q) { @@ -1379,12 +1379,12 @@ public class BlockFieldMatrix> extends AbstractFieldMa visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); for (int p = pStart; p < pEnd; ++p) { for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); final T[] block = blocks[iBlock * blockColumns + jBlock]; int k = (p - pStart) * jWidth; for (int q = qStart; q < qEnd; ++q) { @@ -1407,14 +1407,14 @@ public class BlockFieldMatrix> extends AbstractFieldMa visitor.start(rows, columns, startRow, endRow, startColumn, endColumn); for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) { final int p0 = iBlock * BLOCK_SIZE; - final int pStart = FastMath.max(startRow, p0); - final int pEnd = FastMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); + final int pStart = AccurateMath.max(startRow, p0); + final int pEnd = AccurateMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); for (int p = pStart; p < pEnd; ++p) { for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) { final int jWidth = blockWidth(jBlock); final int q0 = jBlock * BLOCK_SIZE; - final int qStart = FastMath.max(startColumn, q0); - final int qEnd = FastMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); + final int qStart = AccurateMath.max(startColumn, q0); + final int qEnd = AccurateMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); final T[] block = blocks[iBlock * blockColumns + jBlock]; int k = (p - p0) * jWidth + qStart - q0; for (int q = qStart; q < qEnd; ++q) { @@ -1437,14 +1437,14 @@ public class BlockFieldMatrix> extends AbstractFieldMa visitor.start(rows, columns, startRow, endRow, startColumn, endColumn); for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) { final int p0 = iBlock * BLOCK_SIZE; - final int pStart = FastMath.max(startRow, p0); - final int pEnd = FastMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); + final int pStart = AccurateMath.max(startRow, p0); + final int pEnd = AccurateMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); for (int p = pStart; p < pEnd; ++p) { for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) { final int jWidth = blockWidth(jBlock); final int q0 = jBlock * BLOCK_SIZE; - final int qStart = FastMath.max(startColumn, q0); - final int qEnd = FastMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); + final int qStart = AccurateMath.max(startColumn, q0); + final int qEnd = AccurateMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); final T[] block = blocks[iBlock * blockColumns + jBlock]; int k = (p - p0) * jWidth + qStart - q0; for (int q = qStart; q < qEnd; ++q) { @@ -1464,10 +1464,10 @@ public class BlockFieldMatrix> extends AbstractFieldMa int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); final T[] block = blocks[blockIndex]; int k = 0; for (int p = pStart; p < pEnd; ++p) { @@ -1489,10 +1489,10 @@ public class BlockFieldMatrix> extends AbstractFieldMa int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); final T[] block = blocks[blockIndex]; int k = 0; for (int p = pStart; p < pEnd; ++p) { @@ -1517,13 +1517,13 @@ public class BlockFieldMatrix> extends AbstractFieldMa visitor.start(rows, columns, startRow, endRow, startColumn, endColumn); for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) { final int p0 = iBlock * BLOCK_SIZE; - final int pStart = FastMath.max(startRow, p0); - final int pEnd = FastMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); + final int pStart = AccurateMath.max(startRow, p0); + final int pEnd = AccurateMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) { final int jWidth = blockWidth(jBlock); final int q0 = jBlock * BLOCK_SIZE; - final int qStart = FastMath.max(startColumn, q0); - final int qEnd = FastMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); + final int qStart = AccurateMath.max(startColumn, q0); + final int qEnd = AccurateMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); final T[] block = blocks[iBlock * blockColumns + jBlock]; for (int p = pStart; p < pEnd; ++p) { int k = (p - p0) * jWidth + qStart - q0; @@ -1547,13 +1547,13 @@ public class BlockFieldMatrix> extends AbstractFieldMa visitor.start(rows, columns, startRow, endRow, startColumn, endColumn); for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) { final int p0 = iBlock * BLOCK_SIZE; - final int pStart = FastMath.max(startRow, p0); - final int pEnd = FastMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); + final int pStart = AccurateMath.max(startRow, p0); + final int pEnd = AccurateMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) { final int jWidth = blockWidth(jBlock); final int q0 = jBlock * BLOCK_SIZE; - final int qStart = FastMath.max(startColumn, q0); - final int qEnd = FastMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); + final int qStart = AccurateMath.max(startColumn, q0); + final int qEnd = AccurateMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); final T[] block = blocks[iBlock * blockColumns + jBlock]; for (int p = pStart; p < pEnd; ++p) { int k = (p - p0) * jWidth + qStart - q0; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockRealMatrix.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockRealMatrix.java index 7dd1dd518..3ccd94a8d 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockRealMatrix.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BlockRealMatrix.java @@ -27,7 +27,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Cache-friendly implementation of RealMatrix using a flat arrays to store @@ -215,11 +215,11 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); final int iHeight = pEnd - pStart; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); final int jWidth = qEnd - qStart; // allocate new block @@ -259,11 +259,11 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); final int iHeight = pEnd - pStart; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); final int jWidth = qEnd - qStart; blocks[blockIndex] = new double[iHeight * jWidth]; ++blockIndex; @@ -317,9 +317,9 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable final double[] outBlock = out.blocks[blockIndex]; final double[] tBlock = blocks[blockIndex]; final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); int k = 0; for (int p = pStart; p < pEnd; ++p) { for (int q = qStart; q < qEnd; ++q) { @@ -385,9 +385,9 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable final double[] outBlock = out.blocks[blockIndex]; final double[] tBlock = blocks[blockIndex]; final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); int k = 0; for (int p = pStart; p < pEnd; ++p) { for (int q = qStart; q < qEnd; ++q) { @@ -483,11 +483,11 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable int blockIndex = 0; for (int iBlock = 0; iBlock < out.blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < out.blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = FastMath.min(qStart + BLOCK_SIZE, m.getColumnDimension()); + final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, m.getColumnDimension()); // select current block final double[] outBlock = out.blocks[blockIndex]; @@ -540,7 +540,7 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable for (int iBlock = 0; iBlock < out.blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < out.blockColumns; ++jBlock) { final int jWidth = out.blockWidth(jBlock); @@ -597,7 +597,7 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); int regularPos = 0; int lastPos = 0; for (int p = pStart; p < pEnd; ++p) { @@ -631,13 +631,13 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable for (int j = 0; j < jWidth; ++j) { double sum = 0; for (int i = 0; i < iHeight; ++i) { - sum += FastMath.abs(block[i * jWidth + j]); + sum += AccurateMath.abs(block[i * jWidth + j]); } colSums[j] += sum; } } for (int j = 0; j < jWidth; ++j) { - maxColSum = FastMath.max(maxColSum, colSums[j]); + maxColSum = AccurateMath.max(maxColSum, colSums[j]); } } return maxColSum; @@ -652,7 +652,7 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable sum2 += entry * entry; } } - return FastMath.sqrt(sum2); + return AccurateMath.sqrt(sum2); } /** {@inheritDoc} */ @@ -812,14 +812,14 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable for (int iBlock = blockStartRow; iBlock < blockEndRow; ++iBlock) { final int iHeight = blockHeight(iBlock); final int firstRow = iBlock * BLOCK_SIZE; - final int iStart = FastMath.max(row, firstRow); - final int iEnd = FastMath.min(endRow + 1, firstRow + iHeight); + final int iStart = AccurateMath.max(row, firstRow); + final int iEnd = AccurateMath.min(endRow + 1, firstRow + iHeight); for (int jBlock = blockStartColumn; jBlock < blockEndColumn; ++jBlock) { final int jWidth = blockWidth(jBlock); final int firstColumn = jBlock * BLOCK_SIZE; - final int jStart = FastMath.max(column, firstColumn); - final int jEnd = FastMath.min(endColumn + 1, firstColumn + jWidth); + final int jStart = AccurateMath.max(column, firstColumn); + final int jEnd = AccurateMath.min(endColumn + 1, firstColumn + jWidth); final int jLength = jEnd - jStart; // handle one block, row by row @@ -1221,9 +1221,9 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable final double[] outBlock = out.blocks[blockIndex]; final double[] tBlock = blocks[jBlock * blockColumns + iBlock]; final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, columns); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, columns); final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = FastMath.min(qStart + BLOCK_SIZE, rows); + final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, rows); int k = 0; for (int p = pStart; p < pEnd; ++p) { final int lInc = pEnd - pStart; @@ -1266,11 +1266,11 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable // perform multiplication block-wise, to ensure good cache behavior for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final double[] block = blocks[iBlock * blockColumns + jBlock]; final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); int k = 0; for (int p = pStart; p < pEnd; ++p) { double sum = 0; @@ -1310,11 +1310,11 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable final int jWidth3 = jWidth2 + jWidth; final int jWidth4 = jWidth3 + jWidth; final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final double[] block = blocks[iBlock * blockColumns + jBlock]; final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); for (int q = qStart; q < qEnd; ++q) { int k = q - qStart; double sum = 0; @@ -1345,12 +1345,12 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); for (int p = pStart; p < pEnd; ++p) { for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); final double[] block = blocks[iBlock * blockColumns + jBlock]; int k = (p - pStart) * jWidth; for (int q = qStart; q < qEnd; ++q) { @@ -1369,12 +1369,12 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); for (int p = pStart; p < pEnd; ++p) { for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); final double[] block = blocks[iBlock * blockColumns + jBlock]; int k = (p - pStart) * jWidth; for (int q = qStart; q < qEnd; ++q) { @@ -1397,14 +1397,14 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable visitor.start(rows, columns, startRow, endRow, startColumn, endColumn); for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) { final int p0 = iBlock * BLOCK_SIZE; - final int pStart = FastMath.max(startRow, p0); - final int pEnd = FastMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); + final int pStart = AccurateMath.max(startRow, p0); + final int pEnd = AccurateMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); for (int p = pStart; p < pEnd; ++p) { for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) { final int jWidth = blockWidth(jBlock); final int q0 = jBlock * BLOCK_SIZE; - final int qStart = FastMath.max(startColumn, q0); - final int qEnd = FastMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); + final int qStart = AccurateMath.max(startColumn, q0); + final int qEnd = AccurateMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); final double[] block = blocks[iBlock * blockColumns + jBlock]; int k = (p - p0) * jWidth + qStart - q0; for (int q = qStart; q < qEnd; ++q) { @@ -1427,14 +1427,14 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable visitor.start(rows, columns, startRow, endRow, startColumn, endColumn); for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) { final int p0 = iBlock * BLOCK_SIZE; - final int pStart = FastMath.max(startRow, p0); - final int pEnd = FastMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); + final int pStart = AccurateMath.max(startRow, p0); + final int pEnd = AccurateMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); for (int p = pStart; p < pEnd; ++p) { for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) { final int jWidth = blockWidth(jBlock); final int q0 = jBlock * BLOCK_SIZE; - final int qStart = FastMath.max(startColumn, q0); - final int qEnd = FastMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); + final int qStart = AccurateMath.max(startColumn, q0); + final int qEnd = AccurateMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); final double[] block = blocks[iBlock * blockColumns + jBlock]; int k = (p - p0) * jWidth + qStart - q0; for (int q = qStart; q < qEnd; ++q) { @@ -1454,10 +1454,10 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); final double[] block = blocks[blockIndex]; int k = 0; for (int p = pStart; p < pEnd; ++p) { @@ -1479,10 +1479,10 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; - final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); + final int pEnd = AccurateMath.min(pStart + BLOCK_SIZE, rows); for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; - final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); + final int qEnd = AccurateMath.min(qStart + BLOCK_SIZE, columns); final double[] block = blocks[blockIndex]; int k = 0; for (int p = pStart; p < pEnd; ++p) { @@ -1508,13 +1508,13 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable visitor.start(rows, columns, startRow, endRow, startColumn, endColumn); for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) { final int p0 = iBlock * BLOCK_SIZE; - final int pStart = FastMath.max(startRow, p0); - final int pEnd = FastMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); + final int pStart = AccurateMath.max(startRow, p0); + final int pEnd = AccurateMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) { final int jWidth = blockWidth(jBlock); final int q0 = jBlock * BLOCK_SIZE; - final int qStart = FastMath.max(startColumn, q0); - final int qEnd = FastMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); + final int qStart = AccurateMath.max(startColumn, q0); + final int qEnd = AccurateMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); final double[] block = blocks[iBlock * blockColumns + jBlock]; for (int p = pStart; p < pEnd; ++p) { int k = (p - p0) * jWidth + qStart - q0; @@ -1539,13 +1539,13 @@ public class BlockRealMatrix extends AbstractRealMatrix implements Serializable visitor.start(rows, columns, startRow, endRow, startColumn, endColumn); for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) { final int p0 = iBlock * BLOCK_SIZE; - final int pStart = FastMath.max(startRow, p0); - final int pEnd = FastMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); + final int pStart = AccurateMath.max(startRow, p0); + final int pEnd = AccurateMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow); for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) { final int jWidth = blockWidth(jBlock); final int q0 = jBlock * BLOCK_SIZE; - final int qStart = FastMath.max(startColumn, q0); - final int qEnd = FastMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); + final int qStart = AccurateMath.max(startColumn, q0); + final int qEnd = AccurateMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn); final double[] block = blocks[iBlock * blockColumns + jBlock]; for (int p = pStart; p < pEnd; ++p) { int k = (p - p0) * jWidth + qStart - q0; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/CholeskyDecomposition.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/CholeskyDecomposition.java index 157a23047..262e2b93a 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/CholeskyDecomposition.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/CholeskyDecomposition.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.linear; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** @@ -123,8 +123,8 @@ public class CholeskyDecomposition { final double lIJ = lI[j]; final double lJI = lJ[i]; final double maxDelta = - relativeSymmetryThreshold * FastMath.max(FastMath.abs(lIJ), FastMath.abs(lJI)); - if (FastMath.abs(lIJ - lJI) > maxDelta) { + relativeSymmetryThreshold * AccurateMath.max(AccurateMath.abs(lIJ), AccurateMath.abs(lJI)); + if (AccurateMath.abs(lIJ - lJI) > maxDelta) { throw new NonSymmetricMatrixException(i, j, relativeSymmetryThreshold); } lJ[i] = 0; @@ -141,7 +141,7 @@ public class CholeskyDecomposition { throw new NonPositiveDefiniteMatrixException(ltI[i], i, absolutePositivityThreshold); } - ltI[i] = FastMath.sqrt(ltI[i]); + ltI[i] = AccurateMath.sqrt(ltI[i]); final double inverse = 1.0 / ltI[i]; for (int q = order - 1; q > i; --q) { diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/DefaultFieldMatrixChangingVisitor.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/DefaultFieldMatrixChangingVisitor.java index 91b3c26e5..d05ef2984 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/DefaultFieldMatrixChangingVisitor.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/DefaultFieldMatrixChangingVisitor.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.linear; -import org.apache.commons.math4.legacy.FieldElement; +import org.apache.commons.math4.legacy.core.FieldElement; /** * Default implementation of the {@link FieldMatrixChangingVisitor} interface. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/DefaultFieldMatrixPreservingVisitor.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/DefaultFieldMatrixPreservingVisitor.java index 44c464290..0fe7b62d1 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/DefaultFieldMatrixPreservingVisitor.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/DefaultFieldMatrixPreservingVisitor.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.linear; -import org.apache.commons.math4.legacy.FieldElement; +import org.apache.commons.math4.legacy.core.FieldElement; /** * Default implementation of the {@link FieldMatrixPreservingVisitor} interface. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/DiagonalMatrix.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/DiagonalMatrix.java index c0d766aa9..49306911b 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/DiagonalMatrix.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/DiagonalMatrix.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.numbers.core.Precision; /** @@ -313,7 +313,7 @@ public class DiagonalMatrix extends AbstractRealMatrix */ private void ensureZero(final double value) throws NumberIsTooLargeException { if (!Precision.equals(0.0, value, 1)) { - throw new NumberIsTooLargeException(FastMath.abs(value), 0, true); + throw new NumberIsTooLargeException(AccurateMath.abs(value), 0, true); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/EigenDecomposition.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/EigenDecomposition.java index ec21577c5..3dbad74f5 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/EigenDecomposition.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/EigenDecomposition.java @@ -24,7 +24,7 @@ import org.apache.commons.math4.legacy.exception.MathArithmeticException; import org.apache.commons.math4.legacy.exception.MathUnsupportedOperationException; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Calculates the eigen decomposition of a real matrix. @@ -349,7 +349,7 @@ public class EigenDecomposition { if (eigen <= 0) { throw new MathUnsupportedOperationException(); } - sqrtEigenValues[i] = FastMath.sqrt(eigen); + sqrtEigenValues[i] = AccurateMath.sqrt(eigen); } final RealMatrix sqrtEigen = MatrixUtils.createRealDiagonalMatrix(sqrtEigenValues); final RealMatrix v = getV(); @@ -487,7 +487,7 @@ public class EigenDecomposition { // Looping over all values (in case they are not sorted in decreasing // order of their norm). for (int i = 0; i < realEigenvalues.length; ++i) { - largestEigenvalueNorm = FastMath.max(largestEigenvalueNorm, eigenvalueNorm(i)); + largestEigenvalueNorm = AccurateMath.max(largestEigenvalueNorm, eigenvalueNorm(i)); } // Corner case: zero matrix, all exactly 0 eigenvalues if (largestEigenvalueNorm == 0.0) { @@ -510,7 +510,7 @@ public class EigenDecomposition { private double eigenvalueNorm(int i) { final double re = realEigenvalues[i]; final double im = imagEigenvalues[i]; - return FastMath.sqrt(re * re + im * im); + return AccurateMath.sqrt(re * re + im * im); } /** @@ -577,20 +577,20 @@ public class EigenDecomposition { // Determine the largest main and secondary value in absolute term. double maxAbsoluteValue = 0; for (int i = 0; i < n; i++) { - if (FastMath.abs(realEigenvalues[i]) > maxAbsoluteValue) { - maxAbsoluteValue = FastMath.abs(realEigenvalues[i]); + if (AccurateMath.abs(realEigenvalues[i]) > maxAbsoluteValue) { + maxAbsoluteValue = AccurateMath.abs(realEigenvalues[i]); } - if (FastMath.abs(e[i]) > maxAbsoluteValue) { - maxAbsoluteValue = FastMath.abs(e[i]); + if (AccurateMath.abs(e[i]) > maxAbsoluteValue) { + maxAbsoluteValue = AccurateMath.abs(e[i]); } } // Make null any main and secondary value too small to be significant if (maxAbsoluteValue != 0) { for (int i=0; i < n; i++) { - if (FastMath.abs(realEigenvalues[i]) <= Precision.EPSILON * maxAbsoluteValue) { + if (AccurateMath.abs(realEigenvalues[i]) <= Precision.EPSILON * maxAbsoluteValue) { realEigenvalues[i] = 0; } - if (FastMath.abs(e[i]) <= Precision.EPSILON * maxAbsoluteValue) { + if (AccurateMath.abs(e[i]) <= Precision.EPSILON * maxAbsoluteValue) { e[i]=0; } } @@ -601,9 +601,9 @@ public class EigenDecomposition { int m; do { for (m = j; m < n - 1; m++) { - double delta = FastMath.abs(realEigenvalues[m]) + - FastMath.abs(realEigenvalues[m + 1]); - if (FastMath.abs(e[m]) + delta == delta) { + double delta = AccurateMath.abs(realEigenvalues[m]) + + AccurateMath.abs(realEigenvalues[m + 1]); + if (AccurateMath.abs(e[m]) + delta == delta) { break; } } @@ -614,7 +614,7 @@ public class EigenDecomposition { } its++; double q = (realEigenvalues[j + 1] - realEigenvalues[j]) / (2 * e[j]); - double t = FastMath.sqrt(1 + q * q); + double t = AccurateMath.sqrt(1 + q * q); if (q < 0.0) { q = realEigenvalues[m] - realEigenvalues[j] + e[j] / (q - t); } else { @@ -627,15 +627,15 @@ public class EigenDecomposition { for (i = m - 1; i >= j; i--) { double p = s * e[i]; double h = c * e[i]; - if (FastMath.abs(p) >= FastMath.abs(q)) { + if (AccurateMath.abs(p) >= AccurateMath.abs(q)) { c = q / p; - t = FastMath.sqrt(c * c + 1.0); + t = AccurateMath.sqrt(c * c + 1.0); e[i + 1] = p * t; s = 1.0 / t; c *= s; } else { s = p / q; - t = FastMath.sqrt(s * s + 1.0); + t = AccurateMath.sqrt(s * s + 1.0); e[i + 1] = q * t; c = 1.0 / t; s *= c; @@ -690,14 +690,14 @@ public class EigenDecomposition { // Determine the largest eigen value in absolute term. maxAbsoluteValue = 0; for (int i = 0; i < n; i++) { - if (FastMath.abs(realEigenvalues[i]) > maxAbsoluteValue) { - maxAbsoluteValue=FastMath.abs(realEigenvalues[i]); + if (AccurateMath.abs(realEigenvalues[i]) > maxAbsoluteValue) { + maxAbsoluteValue=AccurateMath.abs(realEigenvalues[i]); } } // Make null any eigen value too small to be significant if (maxAbsoluteValue != 0.0) { for (int i=0; i < n; i++) { - if (FastMath.abs(realEigenvalues[i]) < Precision.EPSILON * maxAbsoluteValue) { + if (AccurateMath.abs(realEigenvalues[i]) < Precision.EPSILON * maxAbsoluteValue) { realEigenvalues[i] = 0; } } @@ -732,7 +732,7 @@ public class EigenDecomposition { } else { final double x = matT[i + 1][i + 1]; final double p = 0.5 * (matT[i][i] - x); - final double z = FastMath.sqrt(FastMath.abs(p * p + matT[i + 1][i] * matT[i][i + 1])); + final double z = AccurateMath.sqrt(AccurateMath.abs(p * p + matT[i + 1][i] * matT[i][i + 1])); realEigenvalues[i] = x + p; imagEigenvalues[i] = z; realEigenvalues[i + 1] = x + p; @@ -773,8 +773,8 @@ public class EigenDecomposition { // compute matrix norm double norm = 0.0; for (int i = 0; i < n; i++) { - for (int j = FastMath.max(i - 1, 0); j < n; j++) { - norm += FastMath.abs(matrixT[i][j]); + for (int j = AccurateMath.max(i - 1, 0); j < n; j++) { + norm += AccurateMath.abs(matrixT[i][j]); } } @@ -822,7 +822,7 @@ public class EigenDecomposition { imagEigenvalues[i] * imagEigenvalues[i]; double t = (x * s - z * r) / q; matrixT[i][idx] = t; - if (FastMath.abs(x) > FastMath.abs(z)) { + if (AccurateMath.abs(x) > AccurateMath.abs(z)) { matrixT[i + 1][idx] = (-r - w * t) / x; } else { matrixT[i + 1][idx] = (-s - y * t) / z; @@ -830,7 +830,7 @@ public class EigenDecomposition { } // Overflow control - double t = FastMath.abs(matrixT[i][idx]); + double t = AccurateMath.abs(matrixT[i][idx]); if ((Precision.EPSILON * t) * t > 1) { for (int j = i; j <= idx; j++) { matrixT[j][idx] /= t; @@ -843,7 +843,7 @@ public class EigenDecomposition { int l = idx - 1; // Last vector component imaginary so matrix is triangular - if (FastMath.abs(matrixT[idx][idx - 1]) > FastMath.abs(matrixT[idx - 1][idx])) { + if (AccurateMath.abs(matrixT[idx][idx - 1]) > AccurateMath.abs(matrixT[idx - 1][idx])) { matrixT[idx - 1][idx - 1] = q / matrixT[idx][idx - 1]; matrixT[idx - 1][idx] = -(matrixT[idx][idx] - p) / matrixT[idx][idx - 1]; } else { @@ -884,15 +884,15 @@ public class EigenDecomposition { final double vi = (realEigenvalues[i] - p) * 2.0 * q; if (Precision.equals(vr, 0.0) && Precision.equals(vi, 0.0)) { vr = Precision.EPSILON * norm * - (FastMath.abs(w) + FastMath.abs(q) + FastMath.abs(x) + - FastMath.abs(y) + FastMath.abs(z)); + (AccurateMath.abs(w) + AccurateMath.abs(q) + AccurateMath.abs(x) + + AccurateMath.abs(y) + AccurateMath.abs(z)); } final Complex c = cdiv(x * r - z * ra + q * sa, x * s - z * sa - q * ra, vr, vi); matrixT[i][idx - 1] = c.getReal(); matrixT[i][idx] = c.getImaginary(); - if (FastMath.abs(x) > (FastMath.abs(z) + FastMath.abs(q))) { + if (AccurateMath.abs(x) > (AccurateMath.abs(z) + AccurateMath.abs(q))) { matrixT[i + 1][idx - 1] = (-ra - w * matrixT[i][idx - 1] + q * matrixT[i][idx]) / x; matrixT[i + 1][idx] = (-sa - w * matrixT[i][idx] - @@ -906,8 +906,8 @@ public class EigenDecomposition { } // Overflow control - double t = FastMath.max(FastMath.abs(matrixT[i][idx - 1]), - FastMath.abs(matrixT[i][idx])); + double t = AccurateMath.max(AccurateMath.abs(matrixT[i][idx - 1]), + AccurateMath.abs(matrixT[i][idx])); if ((Precision.EPSILON * t) * t > 1) { for (int j = i; j <= idx; j++) { matrixT[j][idx - 1] /= t; @@ -923,7 +923,7 @@ public class EigenDecomposition { for (int j = n - 1; j >= 0; j--) { for (int i = 0; i <= n - 1; i++) { z = 0.0; - for (int k = 0; k <= FastMath.min(j, n - 1); k++) { + for (int k = 0; k <= AccurateMath.min(j, n - 1); k++) { z += matrixP[i][k] * matrixT[k][j]; } matrixP[i][j] = z; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldDecompositionSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldDecompositionSolver.java index fd2d003c9..7193bc1c5 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldDecompositionSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldDecompositionSolver.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.linear; -import org.apache.commons.math4.legacy.FieldElement; +import org.apache.commons.math4.legacy.core.FieldElement; /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldLUDecomposition.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldLUDecomposition.java index efe7f1389..24e95318b 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldLUDecomposition.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldLUDecomposition.java @@ -17,10 +17,10 @@ package org.apache.commons.math4.legacy.linear; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.FieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.FieldElement; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Calculates the LUP-decomposition of a square matrix. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldMatrix.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldMatrix.java index aa3fa92af..c0d01ffad 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldMatrix.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldMatrix.java @@ -18,8 +18,8 @@ package org.apache.commons.math4.legacy.linear; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.FieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.FieldElement; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NoDataException; import org.apache.commons.math4.legacy.exception.NotPositiveException; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldMatrixChangingVisitor.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldMatrixChangingVisitor.java index 2d8d1247c..f78f944be 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldMatrixChangingVisitor.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldMatrixChangingVisitor.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.linear; -import org.apache.commons.math4.legacy.FieldElement; +import org.apache.commons.math4.legacy.core.FieldElement; /** * Interface defining a visitor for matrix entries. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldMatrixPreservingVisitor.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldMatrixPreservingVisitor.java index 95911fbb8..72a237246 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldMatrixPreservingVisitor.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldMatrixPreservingVisitor.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.linear; -import org.apache.commons.math4.legacy.FieldElement; +import org.apache.commons.math4.legacy.core.FieldElement; /** * Interface defining a visitor for matrix entries. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldVector.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldVector.java index da0df340c..cc917a5a3 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldVector.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldVector.java @@ -16,8 +16,8 @@ */ package org.apache.commons.math4.legacy.linear; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.FieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.FieldElement; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.MathArithmeticException; import org.apache.commons.math4.legacy.exception.NotPositiveException; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldVectorChangingVisitor.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldVectorChangingVisitor.java index 26618d4c2..514bb7d4c 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldVectorChangingVisitor.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldVectorChangingVisitor.java @@ -16,7 +16,7 @@ */ package org.apache.commons.math4.legacy.linear; -import org.apache.commons.math4.legacy.FieldElement; +import org.apache.commons.math4.legacy.core.FieldElement; /** * This interface defines a visitor for the entries of a vector. Visitors diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldVectorPreservingVisitor.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldVectorPreservingVisitor.java index ec98c7cc9..0c85cde0c 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldVectorPreservingVisitor.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/FieldVectorPreservingVisitor.java @@ -16,7 +16,7 @@ */ package org.apache.commons.math4.legacy.linear; -import org.apache.commons.math4.legacy.FieldElement; +import org.apache.commons.math4.legacy.core.FieldElement; /** * This interface defines a visitor for the entries of a vector. Visitors diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/HessenbergTransformer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/HessenbergTransformer.java index c87e4a47f..240d73194 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/HessenbergTransformer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/HessenbergTransformer.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.linear; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.numbers.core.Precision; /** @@ -184,7 +184,7 @@ class HessenbergTransformer { // Scale column. double scale = 0; for (int i = m; i <= high; i++) { - scale += FastMath.abs(householderVectors[i][m - 1]); + scale += AccurateMath.abs(householderVectors[i][m - 1]); } if (!Precision.equals(scale, 0)) { @@ -194,7 +194,7 @@ class HessenbergTransformer { ort[i] = householderVectors[i][m - 1] / scale; h += ort[i] * ort[i]; } - final double g = (ort[m] > 0) ? -FastMath.sqrt(h) : FastMath.sqrt(h); + final double g = (ort[m] > 0) ? -AccurateMath.sqrt(h) : AccurateMath.sqrt(h); h -= ort[m] * g; ort[m] -= g; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/JacobiPreconditioner.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/JacobiPreconditioner.java index ea498f794..0752b3f57 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/JacobiPreconditioner.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/JacobiPreconditioner.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.linear; import org.apache.commons.math4.legacy.analysis.function.Sqrt; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * This class implements the standard Jacobi (diagonal) preconditioner. For a diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/LUDecomposition.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/LUDecomposition.java index e89660647..9db7b66fe 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/LUDecomposition.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/LUDecomposition.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.linear; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Calculates the LUP-decomposition of a square matrix. @@ -127,14 +127,14 @@ public class LUDecomposition { luRow[col] = sum; // maintain best permutation choice - if (FastMath.abs(sum) > largest) { - largest = FastMath.abs(sum); + if (AccurateMath.abs(sum) > largest) { + largest = AccurateMath.abs(sum); max = row; } } // Singularity check - if (FastMath.abs(lu[max][col]) < singularityThreshold) { + if (AccurateMath.abs(lu[max][col]) < singularityThreshold) { singular = true; return; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/MatrixUtils.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/MatrixUtils.java index 8f074ae63..5f78d4a3e 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/MatrixUtils.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/MatrixUtils.java @@ -22,8 +22,8 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.Arrays; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.FieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.FieldElement; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.MathArithmeticException; import org.apache.commons.math4.legacy.exception.NoDataException; @@ -32,8 +32,8 @@ import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.ZeroException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.FastMath; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.legacy.core.MathArrays; import org.apache.commons.numbers.core.Precision; /** @@ -412,8 +412,8 @@ public class MatrixUtils { for (int j = i + 1; j < rows; j++) { final double mij = matrix.getEntry(i, j); final double mji = matrix.getEntry(j, i); - if (FastMath.abs(mij - mji) > - FastMath.max(FastMath.abs(mij), FastMath.abs(mji)) * relativeTolerance) { + if (AccurateMath.abs(mij - mji) > + AccurateMath.max(AccurateMath.abs(mij), AccurateMath.abs(mji)) * relativeTolerance) { if (raiseException) { throw new NonSymmetricMatrixException(i, j, relativeTolerance); } else { @@ -845,7 +845,7 @@ public class MatrixUtils { int rows = rm.getRowDimension(); for( int i = 0 ; i < rows ; i++ ){ double diag = rm.getEntry(i, i); - if( FastMath.abs(diag) < Precision.SAFE_MIN ){ + if( AccurateMath.abs(diag) < Precision.SAFE_MIN ){ throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR); } double bi = b.getEntry(i)/diag; @@ -890,7 +890,7 @@ public class MatrixUtils { int rows = rm.getRowDimension(); for( int i = rows-1 ; i >-1 ; i-- ){ double diag = rm.getEntry(i, i); - if( FastMath.abs(diag) < Precision.SAFE_MIN ){ + if( AccurateMath.abs(diag) < Precision.SAFE_MIN ){ throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR); } double bi = b.getEntry(i)/diag; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/OpenIntToDoubleHashMap.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/OpenIntToDoubleHashMap.java index 533ca68b3..6241230ce 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/OpenIntToDoubleHashMap.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/OpenIntToDoubleHashMap.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.linear; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import java.io.IOException; import java.io.ObjectInputStream; @@ -151,7 +151,7 @@ class OpenIntToDoubleHashMap implements Serializable { // Not in public API. if (expectedSize == 0) { return 1; } - final int capacity = (int) FastMath.ceil(expectedSize / LOAD_FACTOR); + final int capacity = (int) AccurateMath.ceil(expectedSize / LOAD_FACTOR); final int powerOfTwo = Integer.highestOneBit(capacity); if (powerOfTwo == capacity) { return capacity; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/OpenIntToFieldHashMap.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/OpenIntToFieldHashMap.java index 7460e2272..348d3d8b7 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/OpenIntToFieldHashMap.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/OpenIntToFieldHashMap.java @@ -23,9 +23,9 @@ import java.lang.reflect.Array; import java.util.ConcurrentModificationException; import java.util.NoSuchElementException; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.FieldElement; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.FieldElement; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Open addressed map from int to FieldElement. @@ -163,7 +163,7 @@ class OpenIntToFieldHashMap> implements Serializable { if (expectedSize == 0) { return 1; } - final int capacity = (int) FastMath.ceil(expectedSize / LOAD_FACTOR); + final int capacity = (int) AccurateMath.ceil(expectedSize / LOAD_FACTOR); final int powerOfTwo = Integer.highestOneBit(capacity); if (powerOfTwo == capacity) { return capacity; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/OpenMapRealVector.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/OpenMapRealVector.java index 9cc813d49..4d4a55c66 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/OpenMapRealVector.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/OpenMapRealVector.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.exception.MathArithmeticException; import org.apache.commons.math4.legacy.exception.NotPositiveException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.math4.legacy.linear.OpenIntToDoubleHashMap.Iterator; /** @@ -225,7 +225,7 @@ public class OpenMapRealVector extends SparseRealVector * @since 2.1 */ protected boolean isDefaultValue(double value) { - return FastMath.abs(value) < epsilon; + return AccurateMath.abs(value) < epsilon; } /** {@inheritDoc} */ @@ -401,7 +401,7 @@ public class OpenMapRealVector extends SparseRealVector res += value * value; } } - return FastMath.sqrt(res); + return AccurateMath.sqrt(res); } /** {@inheritDoc} */ @@ -439,7 +439,7 @@ public class OpenMapRealVector extends SparseRealVector Iterator iter = entries.iterator(); while (iter.hasNext()) { iter.advance(); - double delta = FastMath.abs(iter.value() - v.getEntry(iter.key())); + double delta = AccurateMath.abs(iter.value() - v.getEntry(iter.key())); max += delta; } iter = v.getEntries().iterator(); @@ -447,8 +447,8 @@ public class OpenMapRealVector extends SparseRealVector iter.advance(); int key = iter.key(); if (!entries.containsKey(key)) { - double delta = FastMath.abs(iter.value()); - max += FastMath.abs(delta); + double delta = AccurateMath.abs(iter.value()); + max += AccurateMath.abs(delta); } } return max; @@ -480,7 +480,7 @@ public class OpenMapRealVector extends SparseRealVector Iterator iter = entries.iterator(); while (iter.hasNext()) { iter.advance(); - double delta = FastMath.abs(iter.value() - v.getEntry(iter.key())); + double delta = AccurateMath.abs(iter.value() - v.getEntry(iter.key())); if (delta > max) { max = delta; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/QRDecomposition.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/QRDecomposition.java index acfa44dc5..d44b3ec12 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/QRDecomposition.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/QRDecomposition.java @@ -20,7 +20,7 @@ package org.apache.commons.math4.legacy.linear; import java.util.Arrays; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; @@ -97,7 +97,7 @@ public class QRDecomposition { final int m = matrix.getRowDimension(); final int n = matrix.getColumnDimension(); qrt = matrix.transpose().getData(); - rDiag = new double[FastMath.min(m, n)]; + rDiag = new double[AccurateMath.min(m, n)]; cachedQ = null; cachedQT = null; cachedR = null; @@ -112,7 +112,7 @@ public class QRDecomposition { * @since 3.2 */ protected void decompose(double[][] matrix) { - for (int minor = 0; minor < FastMath.min(matrix.length, matrix[0].length); minor++) { + for (int minor = 0; minor < AccurateMath.min(matrix.length, matrix[0].length); minor++) { performHouseholderReflection(minor, matrix); } } @@ -138,7 +138,7 @@ public class QRDecomposition { final double c = qrtMinor[row]; xNormSqr += c * c; } - final double a = (qrtMinor[minor] > 0) ? -FastMath.sqrt(xNormSqr) : FastMath.sqrt(xNormSqr); + final double a = (qrtMinor[minor] > 0) ? -AccurateMath.sqrt(xNormSqr) : AccurateMath.sqrt(xNormSqr); rDiag[minor] = a; if (a != 0.0) { @@ -196,7 +196,7 @@ public class QRDecomposition { final int m = qrt[0].length; double[][] ra = new double[m][n]; // copy the diagonal from rDiag and the upper triangle of qr - for (int row = FastMath.min(m, n) - 1; row >= 0; row--) { + for (int row = AccurateMath.min(m, n) - 1; row >= 0; row--) { ra[row][row] = rDiag[row]; for (int col = row + 1; col < n; col++) { ra[row][col] = qrt[col][row]; @@ -239,11 +239,11 @@ public class QRDecomposition { * applying the Householder transformations Q_(m-1),Q_(m-2),...,Q1 in * succession to the result */ - for (int minor = m - 1; minor >= FastMath.min(m, n); minor--) { + for (int minor = m - 1; minor >= AccurateMath.min(m, n); minor--) { qta[minor][minor] = 1.0d; } - for (int minor = FastMath.min(m, n)-1; minor >= 0; minor--){ + for (int minor = AccurateMath.min(m, n)-1; minor >= 0; minor--){ final double[] qrtMinor = qrt[minor]; qta[minor][minor] = 1.0d; if (qrtMinor[minor] != 0.0) { @@ -281,7 +281,7 @@ public class QRDecomposition { final int m = qrt[0].length; double[][] ha = new double[m][n]; for (int i = 0; i < m; ++i) { - for (int j = 0; j < FastMath.min(i + 1, n); ++j) { + for (int j = 0; j < AccurateMath.min(i + 1, n); ++j) { ha[i][j] = qrt[j][i] / -rDiag[j]; } } @@ -357,7 +357,7 @@ public class QRDecomposition { final double[] y = b.toArray(); // apply Householder transforms to solve Q.y = b - for (int minor = 0; minor < FastMath.min(m, n); minor++) { + for (int minor = 0; minor < AccurateMath.min(m, n); minor++) { final double[] qrtMinor = qrt[minor]; double dotProduct = 0; @@ -404,14 +404,14 @@ public class QRDecomposition { for (int kBlock = 0; kBlock < cBlocks; ++kBlock) { final int kStart = kBlock * blockSize; - final int kEnd = FastMath.min(kStart + blockSize, columns); + final int kEnd = AccurateMath.min(kStart + blockSize, columns); final int kWidth = kEnd - kStart; // get the right hand side vector b.copySubMatrix(0, m - 1, kStart, kEnd - 1, y); // apply Householder transforms to solve Q.y = b - for (int minor = 0; minor < FastMath.min(m, n); minor++) { + for (int minor = 0; minor < AccurateMath.min(m, n); minor++) { final double[] qrtMinor = qrt[minor]; final double factor = 1.0 / (rDiag[minor] * qrtMinor[minor]); @@ -490,7 +490,7 @@ public class QRDecomposition { final int len = diag.length; for (int i = 0; i < len; i++) { final double d = diag[i]; - if (FastMath.abs(d) <= min) { + if (AccurateMath.abs(d) <= min) { if (raise) { final SingularMatrixException e = new SingularMatrixException(); e.getContext().addMessage(LocalizedFormats.NUMBER_TOO_SMALL, d, min); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/RRQRDecomposition.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/RRQRDecomposition.java index f61dc2064..f3fd0affd 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/RRQRDecomposition.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/RRQRDecomposition.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.linear; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** @@ -169,7 +169,7 @@ public class RRQRDecomposition extends QRDecomposition { int rank = 1; double lastNorm = r.getFrobeniusNorm(); double rNorm = lastNorm; - while (rank < FastMath.min(rows, columns)) { + while (rank < AccurateMath.min(rows, columns)) { double thisNorm = r.getSubMatrix(rank, rows - 1, rank, columns - 1).getFrobeniusNorm(); if (thisNorm == 0 || (thisNorm / lastNorm) * rNorm < dropThreshold) { break; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/RealVector.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/RealVector.java index 7a4711391..fbeea9b88 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/RealVector.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/RealVector.java @@ -32,7 +32,7 @@ import org.apache.commons.math4.legacy.exception.NotPositiveException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Class defining a real-valued vector with basic algebraic operations. @@ -380,7 +380,7 @@ public abstract class RealVector { final double diff = e.getValue() - v.getEntry(e.getIndex()); d += diff * diff; } - return FastMath.sqrt(d); + return AccurateMath.sqrt(d); } /** @@ -401,7 +401,7 @@ public abstract class RealVector { final double value = e.getValue(); sum += value * value; } - return FastMath.sqrt(sum); + return AccurateMath.sqrt(sum); } /** @@ -419,7 +419,7 @@ public abstract class RealVector { Iterator it = iterator(); while (it.hasNext()) { final Entry e = it.next(); - norm += FastMath.abs(e.getValue()); + norm += AccurateMath.abs(e.getValue()); } return norm; } @@ -439,7 +439,7 @@ public abstract class RealVector { Iterator it = iterator(); while (it.hasNext()) { final Entry e = it.next(); - norm = FastMath.max(norm, FastMath.abs(e.getValue())); + norm = AccurateMath.max(norm, AccurateMath.abs(e.getValue())); } return norm; } @@ -462,7 +462,7 @@ public abstract class RealVector { Iterator it = iterator(); while (it.hasNext()) { final Entry e = it.next(); - d += FastMath.abs(e.getValue() - v.getEntry(e.getIndex())); + d += AccurateMath.abs(e.getValue() - v.getEntry(e.getIndex())); } return d; } @@ -488,7 +488,7 @@ public abstract class RealVector { Iterator it = iterator(); while (it.hasNext()) { final Entry e = it.next(); - d = FastMath.max(FastMath.abs(e.getValue() - v.getEntry(e.getIndex())), d); + d = AccurateMath.max(AccurateMath.abs(e.getValue() - v.getEntry(e.getIndex())), d); } return d; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/RectangularCholeskyDecomposition.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/RectangularCholeskyDecomposition.java index 451944e65..6614cf15f 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/RectangularCholeskyDecomposition.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/RectangularCholeskyDecomposition.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.linear; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Calculates the rectangular Cholesky decomposition of a matrix. @@ -138,7 +138,7 @@ public class RectangularCholeskyDecomposition { } else { // transform the matrix - final double sqrt = FastMath.sqrt(c[ir][ir]); + final double sqrt = AccurateMath.sqrt(c[ir][ir]); b[r][r] = sqrt; final double inverse = 1 / sqrt; final double inverse2 = 1 / c[ir][ir]; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SchurTransformer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SchurTransformer.java index da309336a..0d5cbe8cd 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SchurTransformer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SchurTransformer.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.linear; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.numbers.core.Precision; /** @@ -159,17 +159,17 @@ class SchurTransformer { matrixT[iu - 1][iu - 1] += shift.exShift; if (q >= 0) { - double z = FastMath.sqrt(FastMath.abs(q)); + double z = AccurateMath.sqrt(AccurateMath.abs(q)); if (p >= 0) { z = p + z; } else { z = p - z; } final double x = matrixT[iu][iu - 1]; - final double s = FastMath.abs(x) + FastMath.abs(z); + final double s = AccurateMath.abs(x) + AccurateMath.abs(z); p = x / s; q = z / s; - final double r = FastMath.sqrt(p * p + q * q); + final double r = AccurateMath.sqrt(p * p + q * q); p /= r; q /= r; @@ -224,8 +224,8 @@ class SchurTransformer { double norm = 0.0; for (int i = 0; i < matrixT.length; i++) { // as matrix T is (quasi-)triangular, also take the sub-diagonal element into account - for (int j = FastMath.max(i - 1, 0); j < matrixT.length; j++) { - norm += FastMath.abs(matrixT[i][j]); + for (int j = AccurateMath.max(i - 1, 0); j < matrixT.length; j++) { + norm += AccurateMath.abs(matrixT[i][j]); } } return norm; @@ -241,11 +241,11 @@ class SchurTransformer { private int findSmallSubDiagonalElement(final int startIdx, final double norm) { int l = startIdx; while (l > 0) { - double s = FastMath.abs(matrixT[l - 1][l - 1]) + FastMath.abs(matrixT[l][l]); + double s = AccurateMath.abs(matrixT[l - 1][l - 1]) + AccurateMath.abs(matrixT[l][l]); if (s == 0.0) { s = norm; } - if (FastMath.abs(matrixT[l][l - 1]) < epsilon * s) { + if (AccurateMath.abs(matrixT[l][l - 1]) < epsilon * s) { break; } l--; @@ -276,7 +276,7 @@ class SchurTransformer { for (int i = 0; i <= idx; i++) { matrixT[i][i] -= shift.x; } - final double s = FastMath.abs(matrixT[idx][idx - 1]) + FastMath.abs(matrixT[idx - 1][idx - 2]); + final double s = AccurateMath.abs(matrixT[idx][idx - 1]) + AccurateMath.abs(matrixT[idx - 1][idx - 2]); shift.x = 0.75 * s; shift.y = 0.75 * s; shift.w = -0.4375 * s * s; @@ -287,7 +287,7 @@ class SchurTransformer { double s = (shift.y - shift.x) / 2.0; s = s * s + shift.w; if (s > 0.0) { - s = FastMath.sqrt(s); + s = AccurateMath.sqrt(s); if (shift.y < shift.x) { s = -s; } @@ -325,10 +325,10 @@ class SchurTransformer { break; } - final double lhs = FastMath.abs(matrixT[im][im - 1]) * (FastMath.abs(hVec[1]) + FastMath.abs(hVec[2])); - final double rhs = FastMath.abs(hVec[0]) * (FastMath.abs(matrixT[im - 1][im - 1]) + - FastMath.abs(z) + - FastMath.abs(matrixT[im + 1][im + 1])); + final double lhs = AccurateMath.abs(matrixT[im][im - 1]) * (AccurateMath.abs(hVec[1]) + AccurateMath.abs(hVec[2])); + final double rhs = AccurateMath.abs(hVec[0]) * (AccurateMath.abs(matrixT[im - 1][im - 1]) + + AccurateMath.abs(z) + + AccurateMath.abs(matrixT[im + 1][im + 1])); if (lhs < epsilon * rhs) { break; @@ -362,7 +362,7 @@ class SchurTransformer { p = matrixT[k][k - 1]; q = matrixT[k + 1][k - 1]; r = notlast ? matrixT[k + 2][k - 1] : 0.0; - shift.x = FastMath.abs(p) + FastMath.abs(q) + FastMath.abs(r); + shift.x = AccurateMath.abs(p) + AccurateMath.abs(q) + AccurateMath.abs(r); if (Precision.equals(shift.x, 0.0, epsilon)) { continue; } @@ -370,7 +370,7 @@ class SchurTransformer { q /= shift.x; r /= shift.x; } - double s = FastMath.sqrt(p * p + q * q + r * r); + double s = AccurateMath.sqrt(p * p + q * q + r * r); if (p < 0.0) { s = -s; } @@ -399,7 +399,7 @@ class SchurTransformer { } // Column modification - for (int i = 0; i <= FastMath.min(iu, k + 3); i++) { + for (int i = 0; i <= AccurateMath.min(iu, k + 3); i++) { p = shift.x * matrixT[i][k] + shift.y * matrixT[i][k + 1]; if (notlast) { p += z * matrixT[i][k + 2]; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SingularValueDecomposition.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SingularValueDecomposition.java index 4a1494403..e98738162 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SingularValueDecomposition.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SingularValueDecomposition.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.linear; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.numbers.core.Precision; /** @@ -107,16 +107,16 @@ public class SingularValueDecomposition { final double[] work = new double[m]; // Reduce A to bidiagonal form, storing the diagonal elements // in s and the super-diagonal elements in e. - final int nct = FastMath.min(m - 1, n); - final int nrt = FastMath.max(0, n - 2); - for (int k = 0; k < FastMath.max(nct, nrt); k++) { + final int nct = AccurateMath.min(m - 1, n); + final int nrt = AccurateMath.max(0, n - 2); + for (int k = 0; k < AccurateMath.max(nct, nrt); k++) { if (k < nct) { // Compute the transformation for the k-th column and // place the k-th diagonal in s[k]. // Compute 2-norm of k-th column without under/overflow. singularValues[k] = 0; for (int i = k; i < m; i++) { - singularValues[k] = FastMath.hypot(singularValues[k], A[i][k]); + singularValues[k] = AccurateMath.hypot(singularValues[k], A[i][k]); } if (singularValues[k] != 0) { if (A[k][k] < 0) { @@ -159,7 +159,7 @@ public class SingularValueDecomposition { // Compute 2-norm without under/overflow. e[k] = 0; for (int i = k + 1; i < n; i++) { - e[k] = FastMath.hypot(e[k], e[i]); + e[k] = AccurateMath.hypot(e[k], e[i]); } if (e[k] != 0) { if (e[k + 1] < 0) { @@ -281,16 +281,16 @@ public class SingularValueDecomposition { // kase = 4 if e(p-1) is negligible (convergence). for (k = p - 2; k >= 0; k--) { final double threshold - = TINY + EPS * (FastMath.abs(singularValues[k]) + - FastMath.abs(singularValues[k + 1])); + = TINY + EPS * (AccurateMath.abs(singularValues[k]) + + AccurateMath.abs(singularValues[k + 1])); // the following condition is written this way in order // to break out of the loop when NaN occurs, writing it - // as "if (FastMath.abs(e[k]) <= threshold)" would loop + // as "if (AccurateMath.abs(e[k]) <= threshold)" would loop // indefinitely in case of NaNs because comparison on NaNs // always return false, regardless of what is checked // see issue MATH-947 - if (!(FastMath.abs(e[k]) > threshold)) { + if (!(AccurateMath.abs(e[k]) > threshold)) { e[k] = 0; break; } @@ -305,9 +305,9 @@ public class SingularValueDecomposition { if (ks == k) { break; } - final double t = (ks != p ? FastMath.abs(e[ks]) : 0) + - (ks != k + 1 ? FastMath.abs(e[ks - 1]) : 0); - if (FastMath.abs(singularValues[ks]) <= TINY + EPS * t) { + final double t = (ks != p ? AccurateMath.abs(e[ks]) : 0) + + (ks != k + 1 ? AccurateMath.abs(e[ks - 1]) : 0); + if (AccurateMath.abs(singularValues[ks]) <= TINY + EPS * t) { singularValues[ks] = 0; break; } @@ -329,7 +329,7 @@ public class SingularValueDecomposition { double f = e[p - 2]; e[p - 2] = 0; for (int j = p - 2; j >= k; j--) { - double t = FastMath.hypot(singularValues[j], f); + double t = AccurateMath.hypot(singularValues[j], f); final double cs = singularValues[j] / t; final double sn = f / t; singularValues[j] = t; @@ -351,7 +351,7 @@ public class SingularValueDecomposition { double f = e[k - 1]; e[k - 1] = 0; for (int j = k; j < p; j++) { - double t = FastMath.hypot(singularValues[j], f); + double t = AccurateMath.hypot(singularValues[j], f); final double cs = singularValues[j] / t; final double sn = f / t; singularValues[j] = t; @@ -369,12 +369,12 @@ public class SingularValueDecomposition { // Perform one qr step. case 3: { // Calculate the shift. - final double maxPm1Pm2 = FastMath.max(FastMath.abs(singularValues[p - 1]), - FastMath.abs(singularValues[p - 2])); - final double scale = FastMath.max(FastMath.max(FastMath.max(maxPm1Pm2, - FastMath.abs(e[p - 2])), - FastMath.abs(singularValues[k])), - FastMath.abs(e[k])); + final double maxPm1Pm2 = AccurateMath.max(AccurateMath.abs(singularValues[p - 1]), + AccurateMath.abs(singularValues[p - 2])); + final double scale = AccurateMath.max(AccurateMath.max(AccurateMath.max(maxPm1Pm2, + AccurateMath.abs(e[p - 2])), + AccurateMath.abs(singularValues[k])), + AccurateMath.abs(e[k])); final double sp = singularValues[p - 1] / scale; final double spm1 = singularValues[p - 2] / scale; final double epm1 = e[p - 2] / scale; @@ -385,7 +385,7 @@ public class SingularValueDecomposition { double shift = 0; if (b != 0 || c != 0) { - shift = FastMath.sqrt(b * b + c); + shift = AccurateMath.sqrt(b * b + c); if (b < 0) { shift = -shift; } @@ -395,7 +395,7 @@ public class SingularValueDecomposition { double g = sk * ek; // Chase zeros. for (int j = k; j < p - 1; j++) { - double t = FastMath.hypot(f, g); + double t = AccurateMath.hypot(f, g); double cs = f / t; double sn = g / t; if (j != k) { @@ -411,7 +411,7 @@ public class SingularValueDecomposition { V[i][j + 1] = -sn * V[i][j] + cs * V[i][j + 1]; V[i][j] = t; } - t = FastMath.hypot(f, g); + t = AccurateMath.hypot(f, g); cs = f / t; sn = g / t; singularValues[j] = t; @@ -471,8 +471,8 @@ public class SingularValueDecomposition { } // Set the small value tolerance used to calculate rank and pseudo-inverse - tol = FastMath.max(m * singularValues[0] * EPS, - FastMath.sqrt(Precision.SAFE_MIN)); + tol = AccurateMath.max(m * singularValues[0] * EPS, + AccurateMath.sqrt(Precision.SAFE_MIN)); if (!transposed) { cachedU = MatrixUtils.createRealMatrix(U); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SparseFieldMatrix.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SparseFieldMatrix.java index d69741b5d..c14397cc2 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SparseFieldMatrix.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SparseFieldMatrix.java @@ -16,8 +16,8 @@ */ package org.apache.commons.math4.legacy.linear; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.FieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.FieldElement; /** * Sparse matrix implementation based on an open addressed map. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SparseFieldVector.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SparseFieldVector.java index 62b6644a3..fd62ba624 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SparseFieldVector.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SparseFieldVector.java @@ -18,8 +18,8 @@ package org.apache.commons.math4.legacy.linear; import java.io.Serializable; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.FieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.FieldElement; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.MathArithmeticException; import org.apache.commons.math4.legacy.exception.NotPositiveException; @@ -27,7 +27,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * This class implements the {@link FieldVector} interface with a {@link OpenIntToFieldHashMap} backing store. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SymmLQ.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SymmLQ.java index 308d90b75..ce31ce3f7 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SymmLQ.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/SymmLQ.java @@ -20,7 +20,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.util.ExceptionContext; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.math4.legacy.util.IntegerSequence; /** @@ -361,8 +361,8 @@ public class SymmLQ private boolean bIsNull; static { - MACH_PREC = FastMath.ulp(1.); - CBRT_MACH_PREC = FastMath.cbrt(MACH_PREC); + MACH_PREC = AccurateMath.ulp(1.); + CBRT_MACH_PREC = AccurateMath.cbrt(MACH_PREC); } /** @@ -417,7 +417,7 @@ public class SymmLQ final double s = y.dotProduct(y); final double t = x.dotProduct(z); final double epsa = (s + MACH_PREC) * CBRT_MACH_PREC; - if (FastMath.abs(s - t) > epsa) { + if (AccurateMath.abs(s - t) > epsa) { final NonSelfAdjointOperatorException e; e = new NonSelfAdjointOperatorException(); final ExceptionContext context = e.getContext(); @@ -512,11 +512,11 @@ public class SymmLQ } } } else { - final double anorm = FastMath.sqrt(tnorm); + final double anorm = AccurateMath.sqrt(tnorm); final double diag = gbar == 0. ? anorm * MACH_PREC : gbar; final double zbar = gammaZeta / diag; final double step = (bstep + snprod * zbar) / beta1; - // ynorm = FastMath.sqrt(ynorm2 + zbar * zbar); + // ynorm = AccurateMath.sqrt(ynorm2 + zbar * zbar); if (!goodb) { for (int i = 0; i < n; i++) { final double xi = this.xL.getEntry(i); @@ -561,7 +561,7 @@ public class SymmLQ return; } this.bIsNull = false; - this.beta1 = FastMath.sqrt(this.beta1); + this.beta1 = AccurateMath.sqrt(this.beta1); /* At this point * r1 = b, * y = M * b, @@ -597,7 +597,7 @@ public class SymmLQ if (this.beta < 0.) { throwNPDLOException(this.m, this.y); } - this.beta = FastMath.sqrt(this.beta); + this.beta = AccurateMath.sqrt(this.beta); /* * At this point * oldb = beta[1] @@ -614,7 +614,7 @@ public class SymmLQ this.snprod = 1.; this.tnorm = alpha * alpha + this.beta * this.beta; this.ynorm2 = 0.; - this.gmax = FastMath.abs(alpha) + MACH_PREC; + this.gmax = AccurateMath.abs(alpha) + MACH_PREC; this.gmin = this.gmax; if (this.goodb) { @@ -671,7 +671,7 @@ public class SymmLQ if (beta < 0.) { throwNPDLOException(m, y); } - beta = FastMath.sqrt(beta); + beta = AccurateMath.sqrt(beta); /* * At this point * r1 = beta[k] * M^(-1) * P' * v[k], @@ -688,7 +688,7 @@ public class SymmLQ * c = c[k-1], * s = s[k-1]. */ - final double gamma = FastMath.sqrt(gbar * gbar + oldb * oldb); + final double gamma = AccurateMath.sqrt(gbar * gbar + oldb * oldb); final double c = gbar / gamma; final double s = oldb / gamma; /* @@ -731,8 +731,8 @@ public class SymmLQ */ bstep += snprod * c * zeta; snprod *= s; - gmax = FastMath.max(gmax, gamma); - gmin = FastMath.min(gmin, gamma); + gmax = AccurateMath.max(gmax, gamma); + gmin = AccurateMath.min(gmin, gamma); ynorm2 += zeta * zeta; gammaZeta = minusEpsZeta - deltak * zeta; minusEpsZeta = -eps * zeta; @@ -756,16 +756,16 @@ public class SymmLQ * Updates {@link #lqnorm} and {@link #cgnorm}. */ private void updateNorms() { - final double anorm = FastMath.sqrt(tnorm); - final double ynorm = FastMath.sqrt(ynorm2); + final double anorm = AccurateMath.sqrt(tnorm); + final double ynorm = AccurateMath.sqrt(ynorm2); final double epsa = anorm * MACH_PREC; final double epsx = anorm * ynorm * MACH_PREC; final double epsr = anorm * ynorm * delta; final double diag = gbar == 0. ? epsa : gbar; - lqnorm = FastMath.sqrt(gammaZeta * gammaZeta + + lqnorm = AccurateMath.sqrt(gammaZeta * gammaZeta + minusEpsZeta * minusEpsZeta); final double qrnorm = snprod * beta1; - cgnorm = qrnorm * beta / FastMath.abs(diag); + cgnorm = qrnorm * beta / AccurateMath.abs(diag); /* * Estimate cond(A). In this version we look at the diagonals of L @@ -777,7 +777,7 @@ public class SymmLQ if (lqnorm <= cgnorm) { acond = gmax / gmin; } else { - acond = gmax / FastMath.min(gmin, FastMath.abs(diag)); + acond = gmax / AccurateMath.min(gmin, AccurateMath.abs(diag)); } if (acond * MACH_PREC >= 0.1) { throw new IllConditionedOperatorException(acond); @@ -789,7 +789,7 @@ public class SymmLQ */ throw new SingularOperatorException(); } - rnorm = FastMath.min(cgnorm, lqnorm); + rnorm = AccurateMath.min(cgnorm, lqnorm); hasConverged = (cgnorm <= epsx) || (cgnorm <= epsr); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/TriDiagonalTransformer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/TriDiagonalTransformer.java index 8d24da0cc..f57ba2ba3 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/TriDiagonalTransformer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/TriDiagonalTransformer.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.linear; import java.util.Arrays; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** @@ -201,7 +201,7 @@ class TriDiagonalTransformer { final double c = hK[j]; xNormSqr += c * c; } - final double a = (hK[k + 1] > 0) ? -FastMath.sqrt(xNormSqr) : FastMath.sqrt(xNormSqr); + final double a = (hK[k + 1] > 0) ? -AccurateMath.sqrt(xNormSqr) : AccurateMath.sqrt(xNormSqr); secondary[k] = a; if (a != 0.0) { // apply Householder transform from left and right simultaneously diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/FuzzyKMeansClusterer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/FuzzyKMeansClusterer.java index b5cc1b2f1..3eeb225d3 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/FuzzyKMeansClusterer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/FuzzyKMeansClusterer.java @@ -30,8 +30,8 @@ import org.apache.commons.math4.legacy.ml.distance.DistanceMeasure; import org.apache.commons.math4.legacy.ml.distance.EuclideanDistance; import org.apache.commons.rng.simple.RandomSource; import org.apache.commons.rng.UniformRandomProvider; -import org.apache.commons.math4.legacy.util.FastMath; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Fuzzy K-Means clustering algorithm. @@ -244,7 +244,7 @@ public class FuzzyKMeansClusterer extends Clusterer { int j = 0; for (final CentroidCluster cluster : clusters) { final double dist = distance(point, cluster.getCenter()); - objFunction += (dist * dist) * FastMath.pow(membershipMatrix[i][j], fuzziness); + objFunction += (dist * dist) * AccurateMath.pow(membershipMatrix[i][j], fuzziness); j++; } i++; @@ -318,7 +318,7 @@ public class FuzzyKMeansClusterer extends Clusterer { double[] arr = new double[center.getPoint().length]; double sum = 0.0; for (final T point : points) { - final double u = FastMath.pow(membershipMatrix[i][j], fuzziness); + final double u = AccurateMath.pow(membershipMatrix[i][j], fuzziness); final double[] pointArr = point.getPoint(); for (int idx = 0; idx < arr.length; idx++) { arr[idx] += u * pointArr[idx]; @@ -345,16 +345,16 @@ public class FuzzyKMeansClusterer extends Clusterer { int newCluster = -1; for (int j = 0; j < clusters.size(); j++) { double sum = 0.0; - final double distA = FastMath.abs(distance(point, clusters.get(j).getCenter())); + final double distA = AccurateMath.abs(distance(point, clusters.get(j).getCenter())); if (distA != 0.0) { for (final CentroidCluster c : clusters) { - final double distB = FastMath.abs(distance(point, c.getCenter())); + final double distB = AccurateMath.abs(distance(point, c.getCenter())); if (distB == 0.0) { sum = Double.POSITIVE_INFINITY; break; } - sum += FastMath.pow(distA / distB, 2.0 / (fuzziness - 1.0)); + sum += AccurateMath.pow(distA / distB, 2.0 / (fuzziness - 1.0)); } } @@ -400,8 +400,8 @@ public class FuzzyKMeansClusterer extends Clusterer { double maxMembership = 0.0; for (int i = 0; i < points.size(); i++) { for (int j = 0; j < clusters.size(); j++) { - double v = FastMath.abs(membershipMatrix[i][j] - matrix[i][j]); - maxMembership = FastMath.max(v, maxMembership); + double v = AccurateMath.abs(membershipMatrix[i][j] - matrix[i][j]); + maxMembership = AccurateMath.max(v, maxMembership); } } return maxMembership; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/evaluation/CalinskiHarabasz.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/evaluation/CalinskiHarabasz.java index 3fe410271..5fab367e4 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/evaluation/CalinskiHarabasz.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/clustering/evaluation/CalinskiHarabasz.java @@ -21,7 +21,7 @@ import org.apache.commons.math4.legacy.exception.InsufficientDataException; import org.apache.commons.math4.legacy.ml.clustering.Cluster; import org.apache.commons.math4.legacy.ml.clustering.ClusterEvaluator; import org.apache.commons.math4.legacy.ml.clustering.Clusterable; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; import java.util.Collection; import java.util.List; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/CanberraDistance.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/CanberraDistance.java index 919e49488..628ee6d0a 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/CanberraDistance.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/CanberraDistance.java @@ -17,8 +17,8 @@ package org.apache.commons.math4.legacy.ml.distance; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; -import org.apache.commons.math4.legacy.util.FastMath; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Calculates the Canberra distance between two points. @@ -37,8 +37,8 @@ public class CanberraDistance implements DistanceMeasure { MathArrays.checkEqualLength(a, b); double sum = 0; for (int i = 0; i < a.length; i++) { - final double num = FastMath.abs(a[i] - b[i]); - final double denom = FastMath.abs(a[i]) + FastMath.abs(b[i]); + final double num = AccurateMath.abs(a[i] - b[i]); + final double denom = AccurateMath.abs(a[i]) + AccurateMath.abs(b[i]); sum += num == 0.0 && denom == 0.0 ? 0.0 : num / denom; } return sum; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/ChebyshevDistance.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/ChebyshevDistance.java index 5e8873d84..94ed8ad8a 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/ChebyshevDistance.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/ChebyshevDistance.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.ml.distance; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Calculates the L (max of abs) distance between two points. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/EarthMoversDistance.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/EarthMoversDistance.java index 4b7071f0e..fd72d469c 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/EarthMoversDistance.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/EarthMoversDistance.java @@ -17,8 +17,8 @@ package org.apache.commons.math4.legacy.ml.distance; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; -import org.apache.commons.math4.legacy.util.FastMath; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Calculates the Earh Mover's distance (also known as Wasserstein metric) between two distributions. @@ -41,7 +41,7 @@ public class EarthMoversDistance implements DistanceMeasure { double totalDistance = 0; for (int i = 0; i < a.length; i++) { final double currentDistance = (a[i] + lastDistance) - b[i]; - totalDistance += FastMath.abs(currentDistance); + totalDistance += AccurateMath.abs(currentDistance); lastDistance = currentDistance; } return totalDistance; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/EuclideanDistance.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/EuclideanDistance.java index c784bd7f0..4690d0ff6 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/EuclideanDistance.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/EuclideanDistance.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.ml.distance; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Calculates the L2 (Euclidean) distance between two points. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/ManhattanDistance.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/ManhattanDistance.java index 7bf22aa57..d5cbc0e01 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/ManhattanDistance.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ml/distance/ManhattanDistance.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.ml.distance; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Calculates the L1 (sum of abs) distance between two points. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/AbstractFieldIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/AbstractFieldIntegrator.java index 0a0df5bb8..0781387d7 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/AbstractFieldIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/AbstractFieldIntegrator.java @@ -26,8 +26,8 @@ import java.util.List; import java.util.SortedSet; import java.util.TreeSet; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.analysis.solvers.BracketedRealFieldUnivariateSolver; import org.apache.commons.math4.legacy.analysis.solvers.FieldBracketingNthOrderBrentSolver; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; @@ -39,7 +39,7 @@ import org.apache.commons.math4.legacy.ode.events.FieldEventHandler; import org.apache.commons.math4.legacy.ode.events.FieldEventState; import org.apache.commons.math4.legacy.ode.sampling.AbstractFieldStepInterpolator; import org.apache.commons.math4.legacy.ode.sampling.FieldStepHandler; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.math4.legacy.util.IntegerSequence; /** @@ -385,7 +385,7 @@ public abstract class AbstractFieldIntegrator> imp state.stepAccepted(currentState); isLastStep = isLastStep || state.stop(); } - isLastStep = isLastStep || currentState.getTime().subtract(tEnd).abs().getReal() <= FastMath.ulp(tEnd.getReal()); + isLastStep = isLastStep || currentState.getTime().subtract(tEnd).abs().getReal() <= AccurateMath.ulp(tEnd.getReal()); // handle the remaining part of the step, after all events if any for (FieldStepHandler handler : stepHandlers) { @@ -406,8 +406,8 @@ public abstract class AbstractFieldIntegrator> imp protected void sanityChecks(final FieldODEState eqn, final T t) throws NumberIsTooSmallException, DimensionMismatchException { - final double threshold = 1000 * FastMath.ulp(FastMath.max(FastMath.abs(eqn.getTime().getReal()), - FastMath.abs(t.getReal()))); + final double threshold = 1000 * AccurateMath.ulp(AccurateMath.max(AccurateMath.abs(eqn.getTime().getReal()), + AccurateMath.abs(t.getReal()))); final double dt = eqn.getTime().subtract(t).abs().getReal(); if (dt <= threshold) { throw new NumberIsTooSmallException(LocalizedFormats.TOO_SMALL_INTEGRATION_INTERVAL, diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/AbstractIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/AbstractIntegrator.java index ad8a157c7..af2e3a350 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/AbstractIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/AbstractIntegrator.java @@ -37,7 +37,7 @@ import org.apache.commons.math4.legacy.ode.events.EventHandler; import org.apache.commons.math4.legacy.ode.events.EventState; import org.apache.commons.math4.legacy.ode.sampling.AbstractStepInterpolator; import org.apache.commons.math4.legacy.ode.sampling.StepHandler; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.math4.legacy.util.IntegerSequence; import org.apache.commons.numbers.core.Precision; @@ -458,9 +458,9 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator { protected void sanityChecks(final ExpandableStatefulODE equations, final double t) throws NumberIsTooSmallException, DimensionMismatchException { - final double threshold = 1000 * FastMath.ulp(FastMath.max(FastMath.abs(equations.getTime()), - FastMath.abs(t))); - final double dt = FastMath.abs(equations.getTime() - t); + final double threshold = 1000 * AccurateMath.ulp(AccurateMath.max(AccurateMath.abs(equations.getTime()), + AccurateMath.abs(t))); + final double dt = AccurateMath.abs(equations.getTime() - t); if (dt <= threshold) { throw new NumberIsTooSmallException(LocalizedFormats.TOO_SMALL_INTEGRATION_INTERVAL, dt, threshold, false); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/ContinuousOutputFieldModel.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/ContinuousOutputFieldModel.java index 58abf847a..b2656a1b7 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/ContinuousOutputFieldModel.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/ContinuousOutputFieldModel.java @@ -20,14 +20,14 @@ package org.apache.commons.math4.legacy.ode; import java.util.ArrayList; import java.util.List; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; import org.apache.commons.math4.legacy.ode.sampling.FieldStepHandler; import org.apache.commons.math4.legacy.ode.sampling.FieldStepInterpolator; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * This class stores all information provided by an ODE integrator @@ -292,12 +292,12 @@ public class ContinuousOutputFieldModel> subtract(dt1.multiply(dt3).multiply(d13).multiply(iMed)). add( dt1.multiply(dt2).multiply(d12).multiply(iMin)). divide(d12.multiply(d23).multiply(d13)); - index = (int) FastMath.rint(iLagrange.getReal()); + index = (int) AccurateMath.rint(iLagrange.getReal()); } // force the next size reduction to be at least one tenth - final int low = FastMath.max(iMin + 1, (9 * iMin + iMax) / 10); - final int high = FastMath.min(iMax - 1, (iMin + 9 * iMax) / 10); + final int low = AccurateMath.max(iMin + 1, (9 * iMin + iMax) / 10); + final int high = AccurateMath.min(iMax - 1, (iMin + 9 * iMax) / 10); if (index < low) { index = low; } else if (index > high) { diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/ContinuousOutputModel.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/ContinuousOutputModel.java index 22bba0556..2acd4e144 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/ContinuousOutputModel.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/ContinuousOutputModel.java @@ -27,7 +27,7 @@ import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; import org.apache.commons.math4.legacy.ode.sampling.StepHandler; import org.apache.commons.math4.legacy.ode.sampling.StepInterpolator; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * This class stores all information provided by an ODE integrator @@ -152,9 +152,9 @@ public class ContinuousOutputModel final double previous = lastInterpolator.getPreviousTime(); final double step = current - previous; final double gap = model.getInitialTime() - current; - if (FastMath.abs(gap) > 1.0e-3 * FastMath.abs(step)) { + if (AccurateMath.abs(gap) > 1.0e-3 * AccurateMath.abs(step)) { throw new MathIllegalArgumentException(LocalizedFormats.HOLE_BETWEEN_MODELS_TIME_RANGES, - FastMath.abs(gap)); + AccurateMath.abs(gap)); } } @@ -296,7 +296,7 @@ public void handleStep(final StepInterpolator interpolator, final boolean isLast final StepInterpolator sMed = steps.get(iMed); final double tMed = 0.5 * (sMed.getPreviousTime() + sMed.getCurrentTime()); - if ((FastMath.abs(tMed - tMin) < 1e-6) || (FastMath.abs(tMax - tMed) < 1e-6)) { + if ((AccurateMath.abs(tMed - tMin) < 1e-6) || (AccurateMath.abs(tMax - tMed) < 1e-6)) { // too close to the bounds, we estimate using a simple dichotomy index = iMed; } else { @@ -313,12 +313,12 @@ public void handleStep(final StepInterpolator interpolator, final boolean isLast (dt1 * dt3 * d13) * iMed + (dt1 * dt2 * d12) * iMin) / (d12 * d23 * d13); - index = (int) FastMath.rint(iLagrange); + index = (int) AccurateMath.rint(iLagrange); } // force the next size reduction to be at least one tenth - final int low = FastMath.max(iMin + 1, (9 * iMin + iMax) / 10); - final int high = FastMath.min(iMax - 1, (iMin + 9 * iMax) / 10); + final int low = AccurateMath.max(iMin + 1, (9 * iMin + iMax) / 10); + final int high = AccurateMath.min(iMax - 1, (iMin + 9 * iMax) / 10); if (index < low) { index = low; } else if (index > high) { diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FieldEquationsMapper.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FieldEquationsMapper.java index ae93dbd85..32d33077e 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FieldEquationsMapper.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FieldEquationsMapper.java @@ -19,11 +19,11 @@ package org.apache.commons.math4.legacy.ode; import java.io.Serializable; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Class mapping the part of a complete state or derivative that pertains diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FieldExpandableODE.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FieldExpandableODE.java index ac052f66c..784c6f97e 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FieldExpandableODE.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FieldExpandableODE.java @@ -19,10 +19,10 @@ package org.apache.commons.math4.legacy.ode; import java.util.ArrayList; import java.util.List; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FieldODEState.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FieldODEState.java index 832ab73b8..e4988902e 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FieldODEState.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FieldODEState.java @@ -17,9 +17,9 @@ package org.apache.commons.math4.legacy.ode; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.RealFieldElement; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.RealFieldElement; +import org.apache.commons.math4.legacy.core.MathArrays; /** Container for time, main and secondary state vectors. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FieldODEStateAndDerivative.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FieldODEStateAndDerivative.java index ef33feba8..a67c72199 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FieldODEStateAndDerivative.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FieldODEStateAndDerivative.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.ode; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.RealFieldElement; /** Container for time, main and secondary state vectors as well as their derivatives. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FieldSecondaryEquations.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FieldSecondaryEquations.java index 9441b84c7..69a3e5bea 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FieldSecondaryEquations.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FieldSecondaryEquations.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.ode; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FirstOrderFieldDifferentialEquations.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FirstOrderFieldDifferentialEquations.java index fb0b83a14..2fc0082e7 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FirstOrderFieldDifferentialEquations.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FirstOrderFieldDifferentialEquations.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.ode; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.RealFieldElement; /** This interface represents a first order differential equations set. * diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FirstOrderFieldIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FirstOrderFieldIntegrator.java index 8bd47244e..5fa16771e 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FirstOrderFieldIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/FirstOrderFieldIntegrator.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.ode; import java.util.Collection; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.analysis.solvers.BracketedRealFieldUnivariateSolver; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.exception.NoBracketingException; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/JacobianMatrices.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/JacobianMatrices.java index 8c7ed5d65..e326611e6 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/JacobianMatrices.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/JacobianMatrices.java @@ -198,7 +198,7 @@ public class JacobianMatrices { *

*

* Given a non zero parameter value pval for the parameter, a reasonable value - * for such a step is {@code pval * FastMath.sqrt(Precision.EPSILON)}. + * for such a step is {@code pval * AccurateMath.sqrt(Precision.EPSILON)}. *

*

* A zero value for such a step doesn't enable to compute the parameter Jacobian matrix. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/MultistepFieldIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/MultistepFieldIntegrator.java index c65b03219..f0c9e4385 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/MultistepFieldIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/MultistepFieldIntegrator.java @@ -17,8 +17,8 @@ package org.apache.commons.math4.legacy.ode; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.MathIllegalStateException; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; @@ -30,8 +30,8 @@ import org.apache.commons.math4.legacy.ode.nonstiff.AdaptiveStepsizeFieldIntegra import org.apache.commons.math4.legacy.ode.nonstiff.DormandPrince853FieldIntegrator; import org.apache.commons.math4.legacy.ode.sampling.FieldStepHandler; import org.apache.commons.math4.legacy.ode.sampling.FieldStepInterpolator; -import org.apache.commons.math4.legacy.util.FastMath; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.legacy.core.MathArrays; /** * This class is the base class for multistep integrators for Ordinary @@ -139,7 +139,7 @@ public abstract class MultistepFieldIntegrator> // set the default values of the algorithm control parameters setSafety(0.9); setMinReduction(0.2); - setMaxGrowth(FastMath.pow(2.0, -exp)); + setMaxGrowth(AccurateMath.pow(2.0, -exp)); } @@ -179,7 +179,7 @@ public abstract class MultistepFieldIntegrator> // set the default values of the algorithm control parameters setSafety(0.9); setMinReduction(0.2); - setMaxGrowth(FastMath.pow(2.0, -exp)); + setMaxGrowth(AccurateMath.pow(2.0, -exp)); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/MultistepIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/MultistepIntegrator.java index 33af97aff..378406b58 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/MultistepIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/MultistepIntegrator.java @@ -28,7 +28,7 @@ import org.apache.commons.math4.legacy.ode.nonstiff.AdaptiveStepsizeIntegrator; import org.apache.commons.math4.legacy.ode.nonstiff.DormandPrince853Integrator; import org.apache.commons.math4.legacy.ode.sampling.StepHandler; import org.apache.commons.math4.legacy.ode.sampling.StepInterpolator; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * This class is the base class for multistep integrators for Ordinary @@ -133,7 +133,7 @@ public abstract class MultistepIntegrator extends AdaptiveStepsizeIntegrator { // set the default values of the algorithm control parameters setSafety(0.9); setMinReduction(0.2); - setMaxGrowth(FastMath.pow(2.0, -exp)); + setMaxGrowth(AccurateMath.pow(2.0, -exp)); } @@ -172,7 +172,7 @@ public abstract class MultistepIntegrator extends AdaptiveStepsizeIntegrator { // set the default values of the algorithm control parameters setSafety(0.9); setMinReduction(0.2); - setMaxGrowth(FastMath.pow(2.0, -exp)); + setMaxGrowth(AccurateMath.pow(2.0, -exp)); } @@ -331,7 +331,7 @@ public abstract class MultistepIntegrator extends AdaptiveStepsizeIntegrator { * @return grow/shrink factor for next step */ protected double computeStepGrowShrinkFactor(final double error) { - return FastMath.min(maxGrowth, FastMath.max(minReduction, safety * FastMath.pow(error, exp))); + return AccurateMath.min(maxGrowth, AccurateMath.max(minReduction, safety * AccurateMath.pow(error, exp))); } /** Transformer used to convert the first step to Nordsieck representation. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/EventState.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/EventState.java index 5323eda08..832067abd 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/EventState.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/EventState.java @@ -28,7 +28,7 @@ import org.apache.commons.math4.legacy.exception.NoBracketingException; import org.apache.commons.math4.legacy.ode.EquationsMapper; import org.apache.commons.math4.legacy.ode.ExpandableStatefulODE; import org.apache.commons.math4.legacy.ode.sampling.StepInterpolator; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** This class handles the state for one {@link EventHandler * event handler} during integration steps. @@ -106,7 +106,7 @@ public class EventState { final UnivariateSolver solver) { this.handler = handler; this.maxCheckInterval = maxCheckInterval; - this.convergence = FastMath.abs(convergence); + this.convergence = AccurateMath.abs(convergence); this.maxIterationCount = maxIterationCount; this.solver = solver; @@ -183,8 +183,8 @@ public class EventState { // extremely rare case: there is a zero EXACTLY at interval start // we will use the sign slightly after step beginning to force ignoring this zero - final double epsilon = FastMath.max(solver.getAbsoluteAccuracy(), - FastMath.abs(solver.getRelativeAccuracy() * t0)); + final double epsilon = AccurateMath.max(solver.getAbsoluteAccuracy(), + AccurateMath.abs(solver.getRelativeAccuracy() * t0)); final double tStart = t0 + 0.5 * epsilon; interpolator.setInterpolatedTime(tStart); g0 = handler.g(tStart, getCompleteState(interpolator)); @@ -228,11 +228,11 @@ public class EventState { forward = interpolator.isForward(); final double t1 = interpolator.getCurrentTime(); final double dt = t1 - t0; - if (FastMath.abs(dt) < convergence) { + if (AccurateMath.abs(dt) < convergence) { // we cannot do anything on such a small step, don't trigger any events return false; } - final int n = FastMath.max(1, (int) FastMath.ceil(FastMath.abs(dt) / maxCheckInterval)); + final int n = AccurateMath.max(1, (int) AccurateMath.ceil(AccurateMath.abs(dt) / maxCheckInterval)); final double h = dt / n; final UnivariateFunction f = new UnivariateFunction() { @@ -288,8 +288,8 @@ public class EventState { } if ((!Double.isNaN(previousEventTime)) && - (FastMath.abs(root - ta) <= convergence) && - (FastMath.abs(root - previousEventTime) <= convergence)) { + (AccurateMath.abs(root - ta) <= convergence) && + (AccurateMath.abs(root - previousEventTime) <= convergence)) { // we have either found nothing or found (again ?) a past event, // retry the substep excluding this value, and taking care to have the // required sign in case the g function is noisy around its zero and @@ -311,7 +311,7 @@ public class EventState { return true; } } else if (Double.isNaN(previousEventTime) || - (FastMath.abs(previousEventTime - root) > convergence)) { + (AccurateMath.abs(previousEventTime - root) > convergence)) { pendingEventTime = root; pendingEvent = true; return true; @@ -361,7 +361,7 @@ public class EventState { t0 = t; g0 = handler.g(t, y); - if (pendingEvent && (FastMath.abs(pendingEventTime - t) <= convergence)) { + if (pendingEvent && (AccurateMath.abs(pendingEventTime - t) <= convergence)) { // force the sign to its value "just after the event" previousEventTime = t; g0Positive = increasing; @@ -389,7 +389,7 @@ public class EventState { */ public boolean reset(final double t, final double[] y) { - if (!(pendingEvent && (FastMath.abs(pendingEventTime - t) <= convergence))) { + if (!(pendingEvent && (AccurateMath.abs(pendingEventTime - t) <= convergence))) { return false; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/FieldEventHandler.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/FieldEventHandler.java index 2b283b334..3442d4c7b 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/FieldEventHandler.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/FieldEventHandler.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.ode.events; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.ode.FieldODEState; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/FieldEventState.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/FieldEventState.java index 8a9360fca..3bf39e7a7 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/FieldEventState.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/FieldEventState.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.ode.events; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.analysis.RealFieldUnivariateFunction; import org.apache.commons.math4.legacy.analysis.solvers.AllowedSolution; import org.apache.commons.math4.legacy.analysis.solvers.BracketedRealFieldUnivariateSolver; @@ -26,7 +26,7 @@ import org.apache.commons.math4.legacy.exception.NoBracketingException; import org.apache.commons.math4.legacy.ode.FieldODEState; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; import org.apache.commons.math4.legacy.ode.sampling.FieldStepInterpolator; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** This class handles the state for one {@link EventHandler * event handler} during integration steps. @@ -171,8 +171,8 @@ public class FieldEventState> { // extremely rare case: there is a zero EXACTLY at interval start // we will use the sign slightly after step beginning to force ignoring this zero - final double epsilon = FastMath.max(solver.getAbsoluteAccuracy().getReal(), - FastMath.abs(solver.getRelativeAccuracy().multiply(t0).getReal())); + final double epsilon = AccurateMath.max(solver.getAbsoluteAccuracy().getReal(), + AccurateMath.abs(solver.getRelativeAccuracy().multiply(t0).getReal())); final T tStart = t0.add(0.5 * epsilon); g0 = handler.g(interpolator.getInterpolatedState(tStart)); } @@ -199,7 +199,7 @@ public class FieldEventState> { // we cannot do anything on such a small step, don't trigger any events return false; } - final int n = FastMath.max(1, (int) FastMath.ceil(FastMath.abs(dt.getReal()) / maxCheckInterval)); + final int n = AccurateMath.max(1, (int) AccurateMath.ceil(AccurateMath.abs(dt.getReal()) / maxCheckInterval)); final T h = dt.divide(n); final RealFieldUnivariateFunction f = new RealFieldUnivariateFunction() { diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/Transformer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/Transformer.java index bc2f995f0..c2e005fa2 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/Transformer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/events/Transformer.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.ode.events; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.numbers.core.Precision; @@ -80,7 +80,7 @@ enum Transformer { /** {@inheritDoc} */ @Override protected double transformed(final double g) { - return FastMath.min(-Precision.SAFE_MIN, FastMath.min(-g, +g)); + return AccurateMath.min(-Precision.SAFE_MIN, AccurateMath.min(-g, +g)); } }, @@ -94,7 +94,7 @@ enum Transformer { /** {@inheritDoc} */ @Override protected double transformed(final double g) { - return FastMath.max(+Precision.SAFE_MIN, FastMath.max(-g, +g)); + return AccurateMath.max(+Precision.SAFE_MIN, AccurateMath.max(-g, +g)); } }; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsBashforthFieldIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsBashforthFieldIntegrator.java index 74276df5a..e85095f7d 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsBashforthFieldIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsBashforthFieldIntegrator.java @@ -17,8 +17,8 @@ package org.apache.commons.math4.legacy.ode.nonstiff; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.exception.NoBracketingException; @@ -28,7 +28,7 @@ import org.apache.commons.math4.legacy.linear.FieldMatrix; import org.apache.commons.math4.legacy.ode.FieldExpandableODE; import org.apache.commons.math4.legacy.ode.FieldODEState; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsBashforthIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsBashforthIntegrator.java index 38f7a0d0c..2cd9ea03f 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsBashforthIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsBashforthIntegrator.java @@ -26,7 +26,7 @@ import org.apache.commons.math4.legacy.linear.RealMatrix; import org.apache.commons.math4.legacy.ode.EquationsMapper; import org.apache.commons.math4.legacy.ode.ExpandableStatefulODE; import org.apache.commons.math4.legacy.ode.sampling.NordsieckStepInterpolator; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** @@ -207,7 +207,7 @@ public class AdamsBashforthIntegrator extends AdamsIntegrator { double error = 0; for (int i = 0; i < mainSetDimension; ++i) { - final double yScale = FastMath.abs(predictedState[i]); + final double yScale = AccurateMath.abs(predictedState[i]); final double tol = (vecAbsoluteTolerance == null) ? (scalAbsoluteTolerance + scalRelativeTolerance * yScale) : (vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * yScale); @@ -227,7 +227,7 @@ public class AdamsBashforthIntegrator extends AdamsIntegrator { } - return FastMath.sqrt(error / mainSetDimension); + return AccurateMath.sqrt(error / mainSetDimension); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsFieldIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsFieldIntegrator.java index 3ab291ee7..aca29b15e 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsFieldIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsFieldIntegrator.java @@ -17,8 +17,8 @@ package org.apache.commons.math4.legacy.ode.nonstiff; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.exception.NoBracketingException; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsFieldStepInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsFieldStepInterpolator.java index cd2d91056..13d25e9ed 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsFieldStepInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsFieldStepInterpolator.java @@ -19,12 +19,12 @@ package org.apache.commons.math4.legacy.ode.nonstiff; import java.util.Arrays; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.linear.Array2DRowFieldMatrix; import org.apache.commons.math4.legacy.ode.FieldEquationsMapper; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; import org.apache.commons.math4.legacy.ode.sampling.AbstractFieldStepInterpolator; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * This class implements an interpolator for Adams integrators using Nordsieck representation. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsMoultonFieldIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsMoultonFieldIntegrator.java index 1aee5f4a0..32ceee121 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsMoultonFieldIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsMoultonFieldIntegrator.java @@ -19,8 +19,8 @@ package org.apache.commons.math4.legacy.ode.nonstiff; import java.util.Arrays; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.exception.NoBracketingException; @@ -30,7 +30,7 @@ import org.apache.commons.math4.legacy.linear.FieldMatrixPreservingVisitor; import org.apache.commons.math4.legacy.ode.FieldExpandableODE; import org.apache.commons.math4.legacy.ode.FieldODEState; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsMoultonIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsMoultonIntegrator.java index 2af7db522..ed6be4678 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsMoultonIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsMoultonIntegrator.java @@ -28,7 +28,7 @@ import org.apache.commons.math4.legacy.linear.RealMatrixPreservingVisitor; import org.apache.commons.math4.legacy.ode.EquationsMapper; import org.apache.commons.math4.legacy.ode.ExpandableStatefulODE; import org.apache.commons.math4.legacy.ode.sampling.NordsieckStepInterpolator; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** @@ -406,7 +406,7 @@ public class AdamsMoultonIntegrator extends AdamsIntegrator { for (int i = 0; i < after.length; ++i) { after[i] += previous[i] + scaled[i]; if (i < mainSetDimension) { - final double yScale = FastMath.max(FastMath.abs(previous[i]), FastMath.abs(after[i])); + final double yScale = AccurateMath.max(AccurateMath.abs(previous[i]), AccurateMath.abs(after[i])); final double tol = (vecAbsoluteTolerance == null) ? (scalAbsoluteTolerance + scalRelativeTolerance * yScale) : (vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * yScale); @@ -415,7 +415,7 @@ public class AdamsMoultonIntegrator extends AdamsIntegrator { } } - return FastMath.sqrt(error / mainSetDimension); + return AccurateMath.sqrt(error / mainSetDimension); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsNordsieckFieldTransformer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsNordsieckFieldTransformer.java index 1fd61af5a..2f1194f37 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsNordsieckFieldTransformer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsNordsieckFieldTransformer.java @@ -21,14 +21,14 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.linear.Array2DRowFieldMatrix; import org.apache.commons.math4.legacy.linear.ArrayFieldVector; import org.apache.commons.math4.legacy.linear.FieldDecompositionSolver; import org.apache.commons.math4.legacy.linear.FieldLUDecomposition; import org.apache.commons.math4.legacy.linear.FieldMatrix; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** Transformer to Nordsieck vectors for Adams integrators. *

This class is used by {@link AdamsBashforthIntegrator Adams-Bashforth} and diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdaptiveStepsizeFieldIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdaptiveStepsizeFieldIntegrator.java index 94648d04d..c13624561 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdaptiveStepsizeFieldIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdaptiveStepsizeFieldIntegrator.java @@ -17,8 +17,8 @@ package org.apache.commons.math4.legacy.ode.nonstiff; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; @@ -27,8 +27,8 @@ import org.apache.commons.math4.legacy.ode.AbstractFieldIntegrator; import org.apache.commons.math4.legacy.ode.FieldEquationsMapper; import org.apache.commons.math4.legacy.ode.FieldODEState; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; -import org.apache.commons.math4.legacy.util.FastMath; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.legacy.core.MathArrays; /** * This abstract class holds the common part of all adaptive @@ -159,8 +159,8 @@ public abstract class AdaptiveStepsizeFieldIntegrator= 1.0) { // reject the step and attempt to reduce error by stepsize control final double factor = - FastMath.min(maxGrowth, - FastMath.max(minReduction, safety * FastMath.pow(error, exp))); + AccurateMath.min(maxGrowth, + AccurateMath.max(minReduction, safety * AccurateMath.pow(error, exp))); hNew = filterStep(stepSize * factor, forward, false); } @@ -313,7 +313,7 @@ public abstract class EmbeddedRungeKuttaIntegrator // stepsize control for next step final double factor = - FastMath.min(maxGrowth, FastMath.max(minReduction, safety * FastMath.pow(error, exp))); + AccurateMath.min(maxGrowth, AccurateMath.max(minReduction, safety * AccurateMath.pow(error, exp))); final double scaledH = stepSize * factor; final double nextT = stepStart + scaledH; final boolean nextIsLast = forward ? (nextT >= t) : (nextT <= t); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/EulerFieldIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/EulerFieldIntegrator.java index 8984a267f..18f5634db 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/EulerFieldIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/EulerFieldIntegrator.java @@ -17,11 +17,11 @@ package org.apache.commons.math4.legacy.ode.nonstiff; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.ode.FieldEquationsMapper; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * This class implements a simple Euler integrator for Ordinary diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/EulerFieldStepInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/EulerFieldStepInterpolator.java index 223abd585..15535b0ba 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/EulerFieldStepInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/EulerFieldStepInterpolator.java @@ -17,8 +17,8 @@ package org.apache.commons.math4.legacy.ode.nonstiff; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.ode.FieldEquationsMapper; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/FieldButcherArrayProvider.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/FieldButcherArrayProvider.java index 02ea967f6..dd3c07588 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/FieldButcherArrayProvider.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/FieldButcherArrayProvider.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.ode.nonstiff; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.RealFieldElement; /** This interface represents an integrator based on Butcher arrays. * @see RungeKuttaFieldIntegrator diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GillFieldIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GillFieldIntegrator.java index bcdeb362a..d46e08ec8 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GillFieldIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GillFieldIntegrator.java @@ -17,11 +17,11 @@ package org.apache.commons.math4.legacy.ode.nonstiff; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.ode.FieldEquationsMapper; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GillFieldStepInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GillFieldStepInterpolator.java index 10d68d9d6..11b337ff7 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GillFieldStepInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GillFieldStepInterpolator.java @@ -17,8 +17,8 @@ package org.apache.commons.math4.legacy.ode.nonstiff; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.ode.FieldEquationsMapper; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GillIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GillIntegrator.java index 73ca40285..7c584edfb 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GillIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GillIntegrator.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.ode.nonstiff; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** @@ -54,13 +54,13 @@ public class GillIntegrator extends RungeKuttaIntegrator { /** Internal weights Butcher array. */ private static final double[][] STATIC_A = { { 1.0 / 2.0 }, - { (FastMath.sqrt(2.0) - 1.0) / 2.0, (2.0 - FastMath.sqrt(2.0)) / 2.0 }, - { 0.0, -FastMath.sqrt(2.0) / 2.0, (2.0 + FastMath.sqrt(2.0)) / 2.0 } + { (AccurateMath.sqrt(2.0) - 1.0) / 2.0, (2.0 - AccurateMath.sqrt(2.0)) / 2.0 }, + { 0.0, -AccurateMath.sqrt(2.0) / 2.0, (2.0 + AccurateMath.sqrt(2.0)) / 2.0 } }; /** Propagation weights Butcher array. */ private static final double[] STATIC_B = { - 1.0 / 6.0, (2.0 - FastMath.sqrt(2.0)) / 6.0, (2.0 + FastMath.sqrt(2.0)) / 6.0, 1.0 / 6.0 + 1.0 / 6.0, (2.0 - AccurateMath.sqrt(2.0)) / 6.0, (2.0 + AccurateMath.sqrt(2.0)) / 6.0, 1.0 / 6.0 }; /** Simple constructor. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GillStepInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GillStepInterpolator.java index cd7a1f46a..87b82aa67 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GillStepInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GillStepInterpolator.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.ode.nonstiff; import org.apache.commons.math4.legacy.ode.sampling.StepInterpolator; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * This class implements a step interpolator for the Gill fourth @@ -55,10 +55,10 @@ class GillStepInterpolator extends RungeKuttaStepInterpolator { /** First Gill coefficient. */ - private static final double ONE_MINUS_INV_SQRT_2 = 1 - FastMath.sqrt(0.5); + private static final double ONE_MINUS_INV_SQRT_2 = 1 - AccurateMath.sqrt(0.5); /** Second Gill coefficient. */ - private static final double ONE_PLUS_INV_SQRT_2 = 1 + FastMath.sqrt(0.5); + private static final double ONE_PLUS_INV_SQRT_2 = 1 + AccurateMath.sqrt(0.5); /** Serializable version identifier. */ private static final long serialVersionUID = 20111120L; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GraggBulirschStoerIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GraggBulirschStoerIntegrator.java index c5166eab4..decfb261c 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GraggBulirschStoerIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GraggBulirschStoerIntegrator.java @@ -26,7 +26,7 @@ import org.apache.commons.math4.legacy.ode.ExpandableStatefulODE; import org.apache.commons.math4.legacy.ode.events.EventHandler; import org.apache.commons.math4.legacy.ode.sampling.AbstractStepInterpolator; import org.apache.commons.math4.legacy.ode.sampling.StepHandler; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * This class implements a Gragg-Bulirsch-Stoer integrator for @@ -425,12 +425,12 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator { private void rescale(final double[] y1, final double[] y2, final double[] scale) { if (vecAbsoluteTolerance == null) { for (int i = 0; i < scale.length; ++i) { - final double yi = FastMath.max(FastMath.abs(y1[i]), FastMath.abs(y2[i])); + final double yi = AccurateMath.max(AccurateMath.abs(y1[i]), AccurateMath.abs(y2[i])); scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * yi; } } else { for (int i = 0; i < scale.length; ++i) { - final double yi = FastMath.max(FastMath.abs(y1[i]), FastMath.abs(y2[i])); + final double yi = AccurateMath.max(AccurateMath.abs(y1[i]), AccurateMath.abs(y2[i])); scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * yi; } } @@ -500,7 +500,7 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator { final double ratio = (f[j+1][l] - f[0][l]) / scale[l]; deltaNorm += ratio * ratio; } - if (deltaNorm > 4 * FastMath.max(1.0e-15, initialNorm)) { + if (deltaNorm > 4 * AccurateMath.max(1.0e-15, initialNorm)) { return false; } } @@ -595,10 +595,10 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator { // initial order selection final double tol = (vecRelativeTolerance == null) ? scalRelativeTolerance : vecRelativeTolerance[0]; - final double log10R = FastMath.log10(FastMath.max(1.0e-10, tol)); - int targetIter = FastMath.max(1, - FastMath.min(sequence.length - 2, - (int) FastMath.floor(0.5 - 0.6 * log10R))); + final double log10R = AccurateMath.log10(AccurateMath.max(1.0e-10, tol)); + int targetIter = AccurateMath.max(1, + AccurateMath.min(sequence.length - 2, + (int) AccurateMath.floor(0.5 - 0.6 * log10R))); // set up an interpolator sharing the integrator arrays final AbstractStepInterpolator interpolator = @@ -665,7 +665,7 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator { yTmp)) { // the stability check failed, we reduce the global step - hNew = FastMath.abs(filterStep(stepSize * stabilityReduction, forward, false)); + hNew = AccurateMath.abs(filterStep(stepSize * stabilityReduction, forward, false)); reject = true; loop = false; @@ -682,26 +682,26 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator { // estimate the error at the end of the step. error = 0; for (int j = 0; j < mainSetDimension; ++j) { - final double e = FastMath.abs(y1[j] - y1Diag[0][j]) / scale[j]; + final double e = AccurateMath.abs(y1[j] - y1Diag[0][j]) / scale[j]; error += e * e; } - error = FastMath.sqrt(error / mainSetDimension); + error = AccurateMath.sqrt(error / mainSetDimension); if ((error > 1.0e15) || ((k > 1) && (error > maxError))) { // error is too big, we reduce the global step - hNew = FastMath.abs(filterStep(stepSize * stabilityReduction, forward, false)); + hNew = AccurateMath.abs(filterStep(stepSize * stabilityReduction, forward, false)); reject = true; loop = false; } else { - maxError = FastMath.max(4 * error, 1.0); + maxError = AccurateMath.max(4 * error, 1.0); // compute optimal stepsize for this order final double exp = 1.0 / (2 * k + 1); - double fac = stepControl2 / FastMath.pow(error / stepControl1, exp); - final double pow = FastMath.pow(stepControl3, exp); - fac = FastMath.max(pow / stepControl4, FastMath.min(1 / pow, fac)); - optimalStep[k] = FastMath.abs(filterStep(stepSize * fac, forward, true)); + double fac = stepControl2 / AccurateMath.pow(error / stepControl1, exp); + final double pow = AccurateMath.pow(stepControl3, exp); + fac = AccurateMath.max(pow / stepControl4, AccurateMath.min(1 / pow, fac)); + optimalStep[k] = AccurateMath.abs(filterStep(stepSize * fac, forward, true)); costPerTimeUnit[k] = costPerStep[k] / optimalStep[k]; // check convergence @@ -807,13 +807,13 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator { // derivative at middle point of the step final int l2 = l / 2; - double factor = FastMath.pow(0.5 * sequence[l2], l); + double factor = AccurateMath.pow(0.5 * sequence[l2], l); int middleIndex = fk[l2].length / 2; for (int i = 0; i < y0.length; ++i) { yMidDots[l+1][i] = factor * fk[l2][middleIndex + l][i]; } for (int j = 1; j <= k - l2; ++j) { - factor = FastMath.pow(0.5 * sequence[j + l2], l); + factor = AccurateMath.pow(0.5 * sequence[j + l2], l); middleIndex = fk[l2+j].length / 2; for (int i = 0; i < y0.length; ++i) { diagonal[j-1][i] = factor * fk[l2+j][middleIndex+l][i]; @@ -845,7 +845,7 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator { if (useInterpolationError) { // use the interpolation error to limit stepsize final double interpError = gbsInterpolator.estimateError(scale); - hInt = FastMath.abs(stepSize / FastMath.max(FastMath.pow(interpError, 1.0 / (mu+4)), + hInt = AccurateMath.abs(stepSize / AccurateMath.max(AccurateMath.pow(interpError, 1.0 / (mu+4)), 0.01)); if (interpError > 10.0) { hNew = hInt; @@ -880,7 +880,7 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator { if (costPerTimeUnit[k-1] < orderControl1 * costPerTimeUnit[k]) { optimalIter = k-1; } else if (costPerTimeUnit[k] < orderControl2 * costPerTimeUnit[k-1]) { - optimalIter = FastMath.min(k+1, sequence.length - 2); + optimalIter = AccurateMath.min(k+1, sequence.length - 2); } } else { optimalIter = k - 1; @@ -889,15 +889,15 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator { optimalIter = k - 2; } if (costPerTimeUnit[k] < orderControl2 * costPerTimeUnit[optimalIter]) { - optimalIter = FastMath.min(k, sequence.length - 2); + optimalIter = AccurateMath.min(k, sequence.length - 2); } } if (previousRejected) { // after a rejected step neither order nor stepsize // should increase - targetIter = FastMath.min(optimalIter, k); - hNew = FastMath.min(FastMath.abs(stepSize), optimalStep[targetIter]); + targetIter = AccurateMath.min(optimalIter, k); + hNew = AccurateMath.min(AccurateMath.abs(stepSize), optimalStep[targetIter]); } else { // stepsize control if (optimalIter <= k) { @@ -921,7 +921,7 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator { } - hNew = FastMath.min(hNew, hInt); + hNew = AccurateMath.min(hNew, hInt); if (! forward) { hNew = -hNew; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GraggBulirschStoerStepInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GraggBulirschStoerStepInterpolator.java index 9eb014b02..3b0963b37 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GraggBulirschStoerStepInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/GraggBulirschStoerStepInterpolator.java @@ -24,7 +24,7 @@ import java.io.ObjectOutput; import org.apache.commons.math4.legacy.ode.EquationsMapper; import org.apache.commons.math4.legacy.ode.sampling.AbstractStepInterpolator; import org.apache.commons.math4.legacy.ode.sampling.StepInterpolator; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * This class implements an interpolator for the Gragg-Bulirsch-Stoer @@ -216,7 +216,7 @@ class GraggBulirschStoerStepInterpolator for (int i = 0; i < errfac.length; ++i) { final int ip5 = i + 5; errfac[i] = 1.0 / (ip5 * ip5); - final double e = 0.5 * FastMath.sqrt (((double) (i + 1)) / ip5); + final double e = 0.5 * AccurateMath.sqrt (((double) (i + 1)) / ip5); for (int j = 0; j <= i; ++j) { errfac[i] *= e / (j + 1); } @@ -306,7 +306,7 @@ class GraggBulirschStoerStepInterpolator final double e = polynomials[currentDegree][i] / scale[i]; error += e * e; } - error = FastMath.sqrt(error / scale.length) * errfac[currentDegree - 5]; + error = AccurateMath.sqrt(error / scale.length) * errfac[currentDegree - 5]; } return error; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/HighamHall54FieldIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/HighamHall54FieldIntegrator.java index e48e10b91..7a8b5fe31 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/HighamHall54FieldIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/HighamHall54FieldIntegrator.java @@ -17,11 +17,11 @@ package org.apache.commons.math4.legacy.ode.nonstiff; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.ode.FieldEquationsMapper; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/HighamHall54FieldStepInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/HighamHall54FieldStepInterpolator.java index 95b9cf21e..7ae3c5645 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/HighamHall54FieldStepInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/HighamHall54FieldStepInterpolator.java @@ -17,8 +17,8 @@ package org.apache.commons.math4.legacy.ode.nonstiff; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.ode.FieldEquationsMapper; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/HighamHall54Integrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/HighamHall54Integrator.java index 9a7e0cee5..c0a10b95e 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/HighamHall54Integrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/HighamHall54Integrator.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.ode.nonstiff; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** @@ -119,7 +119,7 @@ public class HighamHall54Integrator extends EmbeddedRungeKuttaIntegrator { errSum += STATIC_E[l] * yDotK[l][j]; } - final double yScale = FastMath.max(FastMath.abs(y0[j]), FastMath.abs(y1[j])); + final double yScale = AccurateMath.max(AccurateMath.abs(y0[j]), AccurateMath.abs(y1[j])); final double tol = (vecAbsoluteTolerance == null) ? (scalAbsoluteTolerance + scalRelativeTolerance * yScale) : (vecAbsoluteTolerance[j] + vecRelativeTolerance[j] * yScale); @@ -128,7 +128,7 @@ public class HighamHall54Integrator extends EmbeddedRungeKuttaIntegrator { } - return FastMath.sqrt(error / mainSetDimension); + return AccurateMath.sqrt(error / mainSetDimension); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/LutherFieldIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/LutherFieldIntegrator.java index 598d39223..4050d4a5b 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/LutherFieldIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/LutherFieldIntegrator.java @@ -17,11 +17,11 @@ package org.apache.commons.math4.legacy.ode.nonstiff; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.ode.FieldEquationsMapper; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/LutherFieldStepInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/LutherFieldStepInterpolator.java index ef894e633..caafb32f6 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/LutherFieldStepInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/LutherFieldStepInterpolator.java @@ -17,8 +17,8 @@ package org.apache.commons.math4.legacy.ode.nonstiff; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.ode.FieldEquationsMapper; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/LutherIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/LutherIntegrator.java index 664ade2c9..d5388831b 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/LutherIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/LutherIntegrator.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.ode.nonstiff; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** @@ -56,7 +56,7 @@ import org.apache.commons.math4.legacy.util.FastMath; public class LutherIntegrator extends RungeKuttaIntegrator { /** Square root. */ - private static final double Q = FastMath.sqrt(21); + private static final double Q = AccurateMath.sqrt(21); /** Time steps Butcher array. */ private static final double[] STATIC_C = { diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/LutherStepInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/LutherStepInterpolator.java index 16d866316..23e67c151 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/LutherStepInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/LutherStepInterpolator.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.ode.nonstiff; import org.apache.commons.math4.legacy.ode.sampling.StepInterpolator; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * This class represents an interpolator over the last step during an @@ -38,7 +38,7 @@ class LutherStepInterpolator extends RungeKuttaStepInterpolator { private static final long serialVersionUID = 20140416L; /** Square root. */ - private static final double Q = FastMath.sqrt(21); + private static final double Q = AccurateMath.sqrt(21); /** Simple constructor. * This constructor builds an instance that is not usable yet, the diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/MidpointFieldIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/MidpointFieldIntegrator.java index ca3e86210..5e2fff9f7 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/MidpointFieldIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/MidpointFieldIntegrator.java @@ -17,11 +17,11 @@ package org.apache.commons.math4.legacy.ode.nonstiff; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.ode.FieldEquationsMapper; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * This class implements a second order Runge-Kutta integrator for diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/MidpointFieldStepInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/MidpointFieldStepInterpolator.java index cf18e268d..e135ba4e6 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/MidpointFieldStepInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/MidpointFieldStepInterpolator.java @@ -17,8 +17,8 @@ package org.apache.commons.math4.legacy.ode.nonstiff; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.ode.FieldEquationsMapper; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/RungeKuttaFieldIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/RungeKuttaFieldIntegrator.java index d249dec0c..58ba02651 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/RungeKuttaFieldIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/RungeKuttaFieldIntegrator.java @@ -18,8 +18,8 @@ package org.apache.commons.math4.legacy.ode.nonstiff; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.exception.NoBracketingException; @@ -30,7 +30,7 @@ import org.apache.commons.math4.legacy.ode.FieldExpandableODE; import org.apache.commons.math4.legacy.ode.FirstOrderFieldDifferentialEquations; import org.apache.commons.math4.legacy.ode.FieldODEState; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * This class implements the common part of all fixed step Runge-Kutta diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/RungeKuttaFieldStepInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/RungeKuttaFieldStepInterpolator.java index 01a22e7b6..a2e796d9b 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/RungeKuttaFieldStepInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/RungeKuttaFieldStepInterpolator.java @@ -17,12 +17,12 @@ package org.apache.commons.math4.legacy.ode.nonstiff; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.ode.FieldEquationsMapper; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; import org.apache.commons.math4.legacy.ode.sampling.AbstractFieldStepInterpolator; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** This class represents an interpolator over the last step during an * ODE integration for Runge-Kutta and embedded Runge-Kutta integrators. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/RungeKuttaIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/RungeKuttaIntegrator.java index daca1f15b..229ed4d0e 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/RungeKuttaIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/RungeKuttaIntegrator.java @@ -25,7 +25,7 @@ import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.ode.AbstractIntegrator; import org.apache.commons.math4.legacy.ode.ExpandableStatefulODE; import org.apache.commons.math4.legacy.ode.FirstOrderDifferentialEquations; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * This class implements the common part of all fixed step Runge-Kutta @@ -86,7 +86,7 @@ public abstract class RungeKuttaIntegrator extends AbstractIntegrator { this.a = a; this.b = b; this.prototype = prototype; - this.step = FastMath.abs(step); + this.step = AccurateMath.abs(step); } /** {@inheritDoc} */ diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/ThreeEighthesFieldIntegrator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/ThreeEighthesFieldIntegrator.java index 080e2d63a..7a024f6b5 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/ThreeEighthesFieldIntegrator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/ThreeEighthesFieldIntegrator.java @@ -17,11 +17,11 @@ package org.apache.commons.math4.legacy.ode.nonstiff; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.ode.FieldEquationsMapper; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * This class implements the 3/8 fourth order Runge-Kutta diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/ThreeEighthesFieldStepInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/ThreeEighthesFieldStepInterpolator.java index b8968b9ca..6b79b421f 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/ThreeEighthesFieldStepInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/ThreeEighthesFieldStepInterpolator.java @@ -17,8 +17,8 @@ package org.apache.commons.math4.legacy.ode.nonstiff; -import org.apache.commons.math4.legacy.Field; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.Field; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.ode.FieldEquationsMapper; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/AbstractFieldStepInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/AbstractFieldStepInterpolator.java index 73a5aad59..9792178a8 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/AbstractFieldStepInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/AbstractFieldStepInterpolator.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.ode.sampling; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.ode.FieldEquationsMapper; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/FieldFixedStepHandler.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/FieldFixedStepHandler.java index 6798a3b6a..4fbdbe630 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/FieldFixedStepHandler.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/FieldFixedStepHandler.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.ode.sampling; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/FieldStepHandler.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/FieldStepHandler.java index ea89c8cae..c233bead9 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/FieldStepHandler.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/FieldStepHandler.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.ode.sampling; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/FieldStepInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/FieldStepInterpolator.java index 56cf20201..72fce8b36 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/FieldStepInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/FieldStepInterpolator.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.ode.sampling; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; /** This interface represents an interpolator over the last step diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/FieldStepNormalizer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/FieldStepNormalizer.java index 953915366..a5d3aeea8 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/FieldStepNormalizer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/FieldStepNormalizer.java @@ -17,10 +17,10 @@ package org.apache.commons.math4.legacy.ode.sampling; -import org.apache.commons.math4.legacy.RealFieldElement; +import org.apache.commons.math4.legacy.core.RealFieldElement; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.numbers.core.Precision; /** @@ -156,7 +156,7 @@ public class FieldStepNormalizer> implements Field */ public FieldStepNormalizer(final double h, final FieldFixedStepHandler handler, final StepNormalizerMode mode, final StepNormalizerBounds bounds) { - this.h = FastMath.abs(h); + this.h = AccurateMath.abs(h); this.handler = handler; this.mode = mode; this.bounds = bounds; @@ -210,7 +210,7 @@ public class FieldStepNormalizer> implements Field // Calculate next normalized step time. T nextTime = (mode == StepNormalizerMode.INCREMENT) ? last.getTime().add(h) : - last.getTime().getField().getZero().add((FastMath.floor(last.getTime().getReal() / h) + 1) * h); + last.getTime().getField().getZero().add((AccurateMath.floor(last.getTime().getReal() / h) + 1) * h); if (mode == StepNormalizerMode.MULTIPLES && Precision.equals(nextTime.getReal(), last.getTime().getReal(), 1)) { nextTime = nextTime.add(h); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/NordsieckStepInterpolator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/NordsieckStepInterpolator.java index 6289575ff..034436cac 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/NordsieckStepInterpolator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/NordsieckStepInterpolator.java @@ -25,7 +25,7 @@ import java.util.Arrays; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.linear.Array2DRowRealMatrix; import org.apache.commons.math4.legacy.ode.EquationsMapper; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * This class implements an interpolator for integrators using Nordsieck representation. @@ -200,7 +200,7 @@ public class NordsieckStepInterpolator extends AbstractStepInterpolator { for (int i = nData.length - 1; i >= 0; --i) { final int order = i + 2; final double[] nDataI = nData[i]; - final double power = FastMath.pow(normalizedAbscissa, order); + final double power = AccurateMath.pow(normalizedAbscissa, order); for (int j = 0; j < nDataI.length; ++j) { final double d = nDataI[j] * power; stateVariation[j] += d; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/StepNormalizer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/StepNormalizer.java index fdaeea9af..1a65517be 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/StepNormalizer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/sampling/StepNormalizer.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.ode.sampling; import org.apache.commons.math4.legacy.exception.MaxCountExceededException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.numbers.core.Precision; /** @@ -159,7 +159,7 @@ public class StepNormalizer implements StepHandler { public StepNormalizer(final double h, final FixedStepHandler handler, final StepNormalizerMode mode, final StepNormalizerBounds bounds) { - this.h = FastMath.abs(h); + this.h = AccurateMath.abs(h); this.handler = handler; this.mode = mode; this.bounds = bounds; @@ -219,7 +219,7 @@ public class StepNormalizer implements StepHandler { // Calculate next normalized step time. double nextTime = (mode == StepNormalizerMode.INCREMENT) ? lastTime + h : - (FastMath.floor(lastTime / h) + 1) * h; + (AccurateMath.floor(lastTime / h) + 1) * h; if (mode == StepNormalizerMode.MULTIPLES && Precision.equals(nextTime, lastTime, 1)) { nextTime += h; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/SimplePointChecker.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/SimplePointChecker.java index f136ba7cd..d6125d195 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/SimplePointChecker.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/SimplePointChecker.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.optim; import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.math4.legacy.util.Pair; /** @@ -121,8 +121,8 @@ public class SimplePointChecker> for (int i = 0; i < p.length; ++i) { final double pi = p[i]; final double ci = c[i]; - final double difference = FastMath.abs(pi - ci); - final double size = FastMath.max(FastMath.abs(pi), FastMath.abs(ci)); + final double difference = AccurateMath.abs(pi - ci); + final double size = AccurateMath.max(AccurateMath.abs(pi), AccurateMath.abs(ci)); if (difference > size * getRelativeThreshold() && difference > getAbsoluteThreshold()) { return false; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/SimpleValueChecker.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/SimpleValueChecker.java index 51f254006..e621d3625 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/SimpleValueChecker.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/SimpleValueChecker.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.optim; import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Simple implementation of the {@link ConvergenceChecker} interface using @@ -117,8 +117,8 @@ public class SimpleValueChecker final double p = previous.getValue(); final double c = current.getValue(); - final double difference = FastMath.abs(p - c); - final double size = FastMath.max(FastMath.abs(p), FastMath.abs(c)); + final double difference = AccurateMath.abs(p - c); + final double size = AccurateMath.max(AccurateMath.abs(p), AccurateMath.abs(c)); return difference <= size * getRelativeThreshold() || difference <= getAbsoluteThreshold(); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/SimpleVectorValueChecker.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/SimpleVectorValueChecker.java index 908b7bc15..200711c2a 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/SimpleVectorValueChecker.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/SimpleVectorValueChecker.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.optim; import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Simple implementation of the {@link ConvergenceChecker} interface using @@ -122,8 +122,8 @@ public class SimpleVectorValueChecker for (int i = 0; i < p.length; ++i) { final double pi = p[i]; final double ci = c[i]; - final double difference = FastMath.abs(pi - ci); - final double size = FastMath.max(FastMath.abs(pi), FastMath.abs(ci)); + final double difference = AccurateMath.abs(pi - ci); + final double size = AccurateMath.max(AccurateMath.abs(pi), AccurateMath.abs(ci)); if (difference > size * getRelativeThreshold() && difference > getAbsoluteThreshold()) { return false; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/linear/SimplexSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/linear/SimplexSolver.java index fe1318642..b72971048 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/linear/SimplexSolver.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/linear/SimplexSolver.java @@ -22,7 +22,7 @@ import java.util.List; import org.apache.commons.math4.legacy.exception.TooManyIterationsException; import org.apache.commons.math4.legacy.optim.OptimizationData; import org.apache.commons.math4.legacy.optim.PointValuePair; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.numbers.core.Precision; /** @@ -256,7 +256,7 @@ public class SimplexSolver extends LinearOptimizer { // only consider pivot elements larger than the cutOff threshold // selecting others may lead to degeneracy or numerical instabilities if (Precision.compareTo(entry, 0d, cutOff) > 0) { - final double ratio = FastMath.abs(rhs / entry); + final double ratio = AccurateMath.abs(rhs / entry); // check if the entry is strictly equal to the current min ratio // do not use a ulp/epsilon check final int cmp = Double.compare(ratio, minRatio); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/MultivariateFunctionMappingAdapter.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/MultivariateFunctionMappingAdapter.java index afaff83ab..c1008ab0e 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/MultivariateFunctionMappingAdapter.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/MultivariateFunctionMappingAdapter.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.analysis.function.Sigmoid; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** *

Adapter for mapping bounded {@link MultivariateFunction} to unbounded ones.

@@ -232,13 +232,13 @@ public class MultivariateFunctionMappingAdapter /** {@inheritDoc} */ @Override public double unboundedToBounded(final double y) { - return lower + FastMath.exp(y); + return lower + AccurateMath.exp(y); } /** {@inheritDoc} */ @Override public double boundedToUnbounded(final double x) { - return FastMath.log(x - lower); + return AccurateMath.log(x - lower); } } @@ -259,13 +259,13 @@ public class MultivariateFunctionMappingAdapter /** {@inheritDoc} */ @Override public double unboundedToBounded(final double y) { - return upper - FastMath.exp(-y); + return upper - AccurateMath.exp(-y); } /** {@inheritDoc} */ @Override public double boundedToUnbounded(final double x) { - return -FastMath.log(upper - x); + return -AccurateMath.log(upper - x); } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/MultivariateFunctionPenaltyAdapter.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/MultivariateFunctionPenaltyAdapter.java index 6a3e51e48..910c36bcb 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/MultivariateFunctionPenaltyAdapter.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/MultivariateFunctionPenaltyAdapter.java @@ -20,7 +20,7 @@ import org.apache.commons.math4.legacy.analysis.MultivariateFunction; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** *

Adapter extending bounded {@link MultivariateFunction} to an unbouded @@ -174,7 +174,7 @@ public class MultivariateFunctionPenaltyAdapter } else { overshoot = 0; } - sum += FastMath.sqrt(overshoot); + sum += AccurateMath.sqrt(overshoot); } return offset + sum; } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/BOBYQAOptimizer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/BOBYQAOptimizer.java index b4e8585bd..888a44146 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/BOBYQAOptimizer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/BOBYQAOptimizer.java @@ -27,7 +27,7 @@ import org.apache.commons.math4.legacy.linear.RealVector; import org.apache.commons.math4.legacy.optim.PointValuePair; import org.apache.commons.math4.legacy.optim.nonlinear.scalar.GoalType; import org.apache.commons.math4.legacy.optim.nonlinear.scalar.MultivariateOptimizer; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Powell's BOBYQA algorithm. This implementation is translated and @@ -317,7 +317,7 @@ public class BOBYQAOptimizer lowerDifference.setEntry(j, -initialTrustRegionRadius); // Computing MAX final double deltaOne = upperBound[j] - currentBest.getEntry(j); - upperDifference.setEntry(j, FastMath.max(deltaOne, initialTrustRegionRadius)); + upperDifference.setEntry(j, AccurateMath.max(deltaOne, initialTrustRegionRadius)); } } else if (upperDifference.getEntry(j) <= initialTrustRegionRadius) { if (upperDifference.getEntry(j) <= ZERO) { @@ -329,7 +329,7 @@ public class BOBYQAOptimizer // Computing MIN final double deltaOne = lowerBound[j] - currentBest.getEntry(j); final double deltaTwo = -initialTrustRegionRadius; - lowerDifference.setEntry(j, FastMath.min(deltaOne, deltaTwo)); + lowerDifference.setEntry(j, AccurateMath.min(deltaOne, deltaTwo)); upperDifference.setEntry(j, initialTrustRegionRadius); } } @@ -501,8 +501,8 @@ public class BOBYQAOptimizer // Computing MIN double deltaOne = delta; - double deltaTwo = FastMath.sqrt(dsq); - dnorm = FastMath.min(deltaOne, deltaTwo); + double deltaTwo = AccurateMath.sqrt(dsq); + dnorm = AccurateMath.min(deltaOne, deltaTwo); if (dnorm < HALF * rho) { ntrits = -1; // Computing 2nd power @@ -519,8 +519,8 @@ public class BOBYQAOptimizer // of likely improvements to the model within distance HALF*RHO of XOPT. // Computing MAX - deltaOne = FastMath.max(diffa, diffb); - final double errbig = FastMath.max(deltaOne, diffc); + deltaOne = AccurateMath.max(diffa, diffb); + final double errbig = AccurateMath.max(deltaOne, diffc); final double frhosq = rho * ONE_OVER_EIGHT * rho; if (crvmin > ZERO && errbig > frhosq * crvmin) { @@ -794,7 +794,7 @@ public class BOBYQAOptimizer // Computing MAX // Computing 2nd power final double d4 = distsq / delsq; - final double temp = FastMath.max(ONE, d4 * d4); + final double temp = AccurateMath.max(ONE, d4 * d4); if (temp * den > scaden) { scaden = temp * den; knew = k; @@ -803,7 +803,7 @@ public class BOBYQAOptimizer // Computing MAX // Computing 2nd power final double d5 = lagrangeValuesAtNewPoint.getEntry(k); - biglsq = FastMath.max(biglsq, temp * (d5 * d5)); + biglsq = AccurateMath.max(biglsq, temp * (d5 * d5)); } } @@ -821,9 +821,9 @@ public class BOBYQAOptimizer // Computing MAX final double d3 = lowerBound[i]; final double d4 = originShift.getEntry(i) + newPoint.getEntry(i); - final double d1 = FastMath.max(d3, d4); + final double d1 = AccurateMath.max(d3, d4); final double d2 = upperBound[i]; - currentBest.setEntry(i, FastMath.min(d1, d2)); + currentBest.setEntry(i, AccurateMath.min(d1, d2)); if (newPoint.getEntry(i) == lowerDifference.getEntry(i)) { currentBest.setEntry(i, lowerBound[i]); } @@ -868,7 +868,7 @@ public class BOBYQAOptimizer final double diff = f - fopt - vquad; diffc = diffb; diffb = diffa; - diffa = FastMath.abs(diff); + diffa = AccurateMath.abs(diff); if (dnorm > rho) { nfsav = getEvaluations(); } @@ -883,13 +883,13 @@ public class BOBYQAOptimizer final double hDelta = HALF * delta; if (ratio <= ONE_OVER_TEN) { // Computing MIN - delta = FastMath.min(hDelta, dnorm); + delta = AccurateMath.min(hDelta, dnorm); } else if (ratio <= .7) { // Computing MAX - delta = FastMath.max(hDelta, dnorm); + delta = AccurateMath.max(hDelta, dnorm); } else { // Computing MAX - delta = FastMath.max(hDelta, 2 * dnorm); + delta = AccurateMath.max(hDelta, 2 * dnorm); } if (delta <= rho * 1.5) { delta = rho; @@ -923,7 +923,7 @@ public class BOBYQAOptimizer // Computing MAX // Computing 2nd power final double d3 = distsq / delsq; - final double temp = FastMath.max(ONE, d3 * d3); + final double temp = AccurateMath.max(ONE, d3 * d3); if (temp * den > scaden) { scaden = temp * den; knew = k; @@ -933,7 +933,7 @@ public class BOBYQAOptimizer // Computing 2nd power final double d4 = lagrangeValuesAtNewPoint.getEntry(k); final double d5 = temp * (d4 * d4); - biglsq = FastMath.max(biglsq, d5); + biglsq = AccurateMath.max(biglsq, d5); } if (scaden <= HALF * biglsq) { knew = ksav; @@ -1058,18 +1058,18 @@ public class BOBYQAOptimizer if (trustRegionCenterOffset.getEntry(i) == lowerDifference.getEntry(i)) { // Computing MIN // Computing 2nd power - final double d1 = FastMath.min(ZERO, gradientAtTrustRegionCenter.getEntry(i)); + final double d1 = AccurateMath.min(ZERO, gradientAtTrustRegionCenter.getEntry(i)); gqsq += d1 * d1; // Computing 2nd power - final double d2 = FastMath.min(ZERO, sum); + final double d2 = AccurateMath.min(ZERO, sum); gisq += d2 * d2; } else if (trustRegionCenterOffset.getEntry(i) == upperDifference.getEntry(i)) { // Computing MAX // Computing 2nd power - final double d1 = FastMath.max(ZERO, gradientAtTrustRegionCenter.getEntry(i)); + final double d1 = AccurateMath.max(ZERO, gradientAtTrustRegionCenter.getEntry(i)); gqsq += d1 * d1; // Computing 2nd power - final double d2 = FastMath.max(ZERO, sum); + final double d2 = AccurateMath.max(ZERO, sum); gisq += d2 * d2; } else { // Computing 2nd power @@ -1088,7 +1088,7 @@ public class BOBYQAOptimizer itest = 0; } if (itest >= 3) { - for (int i = 0, max = FastMath.max(npt, nh); i < max; i++) { + for (int i = 0, max = AccurateMath.max(npt, nh); i < max; i++) { if (i < n) { gradientAtTrustRegionCenter.setEntry(i, lagrangeValuesAtNewPoint.getEntry(npt + i)); } @@ -1122,7 +1122,7 @@ public class BOBYQAOptimizer final double d1 = TWO * delta; // Computing 2nd power final double d2 = TEN * rho; - distsq = FastMath.max(d1 * d1, d2 * d2); + distsq = AccurateMath.max(d1 * d1, d2 * d2); } case 650: { printState(650); // XXX @@ -1147,10 +1147,10 @@ public class BOBYQAOptimizer // current RHO are complete. if (knew >= 0) { - final double dist = FastMath.sqrt(distsq); + final double dist = AccurateMath.sqrt(distsq); if (ntrits == -1) { // Computing MIN - delta = FastMath.min(ONE_OVER_TEN * delta, HALF * dist); + delta = AccurateMath.min(ONE_OVER_TEN * delta, HALF * dist); if (delta <= rho * 1.5) { delta = rho; } @@ -1158,8 +1158,8 @@ public class BOBYQAOptimizer ntrits = 0; // Computing MAX // Computing MIN - final double d1 = FastMath.min(ONE_OVER_TEN * dist, delta); - adelt = FastMath.max(d1, rho); + final double d1 = AccurateMath.min(ONE_OVER_TEN * dist, delta); + adelt = AccurateMath.max(d1, rho); dsq = adelt * adelt; state = 90; break; } @@ -1169,7 +1169,7 @@ public class BOBYQAOptimizer if (ratio > ZERO) { state = 60; break; } - if (FastMath.max(delta, dnorm) > rho) { + if (AccurateMath.max(delta, dnorm) > rho) { state = 60; break; } @@ -1184,11 +1184,11 @@ public class BOBYQAOptimizer if (ratio <= SIXTEEN) { rho = stoppingTrustRegionRadius; } else if (ratio <= TWO_HUNDRED_FIFTY) { - rho = FastMath.sqrt(ratio) * stoppingTrustRegionRadius; + rho = AccurateMath.sqrt(ratio) * stoppingTrustRegionRadius; } else { rho *= ONE_OVER_TEN; } - delta = FastMath.max(delta, rho); + delta = AccurateMath.max(delta, rho); ntrits = 0; nfsav = getEvaluations(); state = 60; break; @@ -1209,9 +1209,9 @@ public class BOBYQAOptimizer // Computing MAX final double d3 = lowerBound[i]; final double d4 = originShift.getEntry(i) + trustRegionCenterOffset.getEntry(i); - final double d1 = FastMath.max(d3, d4); + final double d1 = AccurateMath.max(d3, d4); final double d2 = upperBound[i]; - currentBest.setEntry(i, FastMath.min(d1, d2)); + currentBest.setEntry(i, AccurateMath.min(d1, d2)); if (trustRegionCenterOffset.getEntry(i) == lowerDifference.getEntry(i)) { currentBest.setEntry(i, lowerBound[i]); } @@ -1328,11 +1328,11 @@ public class BOBYQAOptimizer dderiv += glag.getEntry(i) * tmp; distsq += tmp * tmp; } - double subd = adelt / FastMath.sqrt(distsq); + double subd = adelt / AccurateMath.sqrt(distsq); double slbd = -subd; int ilbd = 0; int iubd = 0; - final double sumin = FastMath.min(ONE, subd); + final double sumin = AccurateMath.min(ONE, subd); // Revise SLBD and SUBD if necessary because of the bounds in SL and SU. @@ -1345,7 +1345,7 @@ public class BOBYQAOptimizer } if (subd * tmp > upperDifference.getEntry(i) - trustRegionCenterOffset.getEntry(i)) { // Computing MAX - subd = FastMath.max(sumin, + subd = AccurateMath.max(sumin, (upperDifference.getEntry(i) - trustRegionCenterOffset.getEntry(i)) / tmp); iubd = i + 1; } @@ -1356,7 +1356,7 @@ public class BOBYQAOptimizer } if (subd * tmp < lowerDifference.getEntry(i) - trustRegionCenterOffset.getEntry(i)) { // Computing MAX - subd = FastMath.max(sumin, + subd = AccurateMath.max(sumin, (lowerDifference.getEntry(i) - trustRegionCenterOffset.getEntry(i)) / tmp); iubd = -i - 1; } @@ -1373,7 +1373,7 @@ public class BOBYQAOptimizer final double diff = dderiv - ONE; vlag = slbd * (dderiv - slbd * diff); final double d1 = subd * (dderiv - subd * diff); - if (FastMath.abs(d1) > FastMath.abs(vlag)) { + if (AccurateMath.abs(d1) > AccurateMath.abs(vlag)) { step = subd; vlag = d1; isbd = iubd; @@ -1383,7 +1383,7 @@ public class BOBYQAOptimizer final double d4 = d2 - diff * subd; if (d3 * d4 < ZERO) { final double d5 = d2 * d2 / diff; - if (FastMath.abs(d5) > FastMath.abs(vlag)) { + if (AccurateMath.abs(d5) > AccurateMath.abs(vlag)) { step = d2 / diff; vlag = d5; isbd = 0; @@ -1395,12 +1395,12 @@ public class BOBYQAOptimizer } else { vlag = slbd * (ONE - slbd); final double tmp = subd * (ONE - subd); - if (FastMath.abs(tmp) > FastMath.abs(vlag)) { + if (AccurateMath.abs(tmp) > AccurateMath.abs(vlag)) { step = subd; vlag = tmp; isbd = iubd; } - if (subd > HALF && FastMath.abs(vlag) < ONE_OVER_FOUR) { + if (subd > HALF && AccurateMath.abs(vlag) < ONE_OVER_FOUR) { step = HALF; vlag = ONE_OVER_FOUR; isbd = 0; @@ -1424,8 +1424,8 @@ public class BOBYQAOptimizer for (int i = 0; i < n; i++) { final double tmp = trustRegionCenterOffset.getEntry(i) + stpsav * (interpolationPoints.getEntry(ksav, i) - trustRegionCenterOffset.getEntry(i)); - newPoint.setEntry(i, FastMath.max(lowerDifference.getEntry(i), - FastMath.min(upperDifference.getEntry(i), tmp))); + newPoint.setEntry(i, AccurateMath.max(lowerDifference.getEntry(i), + AccurateMath.min(upperDifference.getEntry(i), tmp))); } if (ibdsav < 0) { newPoint.setEntry(-ibdsav - 1, lowerDifference.getEntry(-ibdsav - 1)); @@ -1448,8 +1448,8 @@ public class BOBYQAOptimizer for (int i = 0; i < n; i++) { final double glagValue = glag.getEntry(i); work1.setEntry(i, ZERO); - if (FastMath.min(trustRegionCenterOffset.getEntry(i) - lowerDifference.getEntry(i), glagValue) > ZERO || - FastMath.max(trustRegionCenterOffset.getEntry(i) - upperDifference.getEntry(i), glagValue) < ZERO) { + if (AccurateMath.min(trustRegionCenterOffset.getEntry(i) - lowerDifference.getEntry(i), glagValue) > ZERO || + AccurateMath.max(trustRegionCenterOffset.getEntry(i) - upperDifference.getEntry(i), glagValue) < ZERO) { work1.setEntry(i, bigstp); // Computing 2nd power ggfree += glagValue * glagValue; @@ -1462,7 +1462,7 @@ public class BOBYQAOptimizer // Investigate whether more components of W can be fixed. final double tmp1 = adelt * adelt - wfixsq; if (tmp1 > ZERO) { - step = FastMath.sqrt(tmp1 / ggfree); + step = AccurateMath.sqrt(tmp1 / ggfree); ggfree = ZERO; for (int i = 0; i < n; i++) { if (work1.getEntry(i) == bigstp) { @@ -1494,9 +1494,9 @@ public class BOBYQAOptimizer final double glagValue = glag.getEntry(i); if (work1.getEntry(i) == bigstp) { work1.setEntry(i, -step * glagValue); - final double min = FastMath.min(upperDifference.getEntry(i), + final double min = AccurateMath.min(upperDifference.getEntry(i), trustRegionCenterOffset.getEntry(i) + work1.getEntry(i)); - alternativeNewPoint.setEntry(i, FastMath.max(lowerDifference.getEntry(i), min)); + alternativeNewPoint.setEntry(i, AccurateMath.max(lowerDifference.getEntry(i), min)); } else if (work1.getEntry(i) == ZERO) { alternativeNewPoint.setEntry(i, trustRegionCenterOffset.getEntry(i)); } else if (glagValue > ZERO) { @@ -1524,12 +1524,12 @@ public class BOBYQAOptimizer curv = -curv; } if (curv > -gw && - curv < -gw * (ONE + FastMath.sqrt(TWO))) { + curv < -gw * (ONE + AccurateMath.sqrt(TWO))) { final double scale = -gw / curv; for (int i = 0; i < n; i++) { final double tmp = trustRegionCenterOffset.getEntry(i) + scale * work1.getEntry(i); - alternativeNewPoint.setEntry(i, FastMath.max(lowerDifference.getEntry(i), - FastMath.min(upperDifference.getEntry(i), tmp))); + alternativeNewPoint.setEntry(i, AccurateMath.max(lowerDifference.getEntry(i), + AccurateMath.min(upperDifference.getEntry(i), tmp))); } // Computing 2nd power final double d1 = HALF * gw * scale; @@ -1648,11 +1648,11 @@ public class BOBYQAOptimizer stepa = interpolationPoints.getEntry(nfx, nfxm); stepb = -initialTrustRegionRadius; if (lowerDifference.getEntry(nfxm) == ZERO) { - stepb = FastMath.min(TWO * initialTrustRegionRadius, upperDifference.getEntry(nfxm)); + stepb = AccurateMath.min(TWO * initialTrustRegionRadius, upperDifference.getEntry(nfxm)); // throw new PathIsExploredException(); // XXX } if (upperDifference.getEntry(nfxm) == ZERO) { - stepb = FastMath.max(-TWO * initialTrustRegionRadius, lowerDifference.getEntry(nfxm)); + stepb = AccurateMath.max(-TWO * initialTrustRegionRadius, lowerDifference.getEntry(nfxm)); // throw new PathIsExploredException(); // XXX } interpolationPoints.setEntry(nfm, nfxm, stepb); @@ -1677,7 +1677,7 @@ public class BOBYQAOptimizer // its index are required. for (int j = 0; j < n; j++) { - currentBest.setEntry(j, FastMath.min(FastMath.max(lowerBound[j], + currentBest.setEntry(j, AccurateMath.min(AccurateMath.max(lowerBound[j], originShift.getEntry(j) + interpolationPoints.getEntry(nfm, j)), upperBound[j])); if (interpolationPoints.getEntry(nfm, j) == lowerDifference.getEntry(j)) { @@ -1736,9 +1736,9 @@ public class BOBYQAOptimizer bMatrix.setEntry(nfm, nfxm, -HALF / interpolationPoints.getEntry(nfm - n, nfxm)); bMatrix.setEntry(nfm - n, nfxm, -bMatrix.getEntry(0, nfxm) - bMatrix.getEntry(nfm, nfxm)); - zMatrix.setEntry(0, nfxm, FastMath.sqrt(TWO) / (stepa * stepb)); - zMatrix.setEntry(nfm, nfxm, FastMath.sqrt(HALF) / rhosq); - // zMatrix.setEntry(nfm, nfxm, FastMath.sqrt(HALF) * recip); // XXX "testAckley" and "testDiffPow" fail. + zMatrix.setEntry(0, nfxm, AccurateMath.sqrt(TWO) / (stepa * stepb)); + zMatrix.setEntry(nfm, nfxm, AccurateMath.sqrt(HALF) / rhosq); + // zMatrix.setEntry(nfm, nfxm, AccurateMath.sqrt(HALF) * recip); // XXX "testAckley" and "testDiffPow" fail. zMatrix.setEntry(nfm - n, nfxm, -zMatrix.getEntry(0, nfxm) - zMatrix.getEntry(nfm, nfxm)); } @@ -1935,7 +1935,7 @@ public class BOBYQAOptimizer if (resid <= ZERO) { state = 90; break; } - temp = FastMath.sqrt(stepsq * resid + ds * ds); + temp = AccurateMath.sqrt(stepsq * resid + ds * ds); if (ds < ZERO) { blen = (temp - ds) / stepsq; } else { @@ -1944,7 +1944,7 @@ public class BOBYQAOptimizer stplen = blen; if (shs > ZERO) { // Computing MIN - stplen = FastMath.min(blen, gredsq / shs); + stplen = AccurateMath.min(blen, gredsq / shs); } // Reduce STPLEN if necessary in order to preserve the simple bounds, @@ -1973,7 +1973,7 @@ public class BOBYQAOptimizer ++iterc; temp = shs / stepsq; if (iact == -1 && temp > ZERO) { - crvmin = FastMath.min(crvmin,temp); + crvmin = AccurateMath.min(crvmin,temp); if (crvmin == MINUS_ONE) { crvmin = temp; } @@ -1991,7 +1991,7 @@ public class BOBYQAOptimizer } // Computing MAX final double d1 = stplen * (ggsav - HALF * stplen * shs); - sdec = FastMath.max(d1, ZERO); + sdec = AccurateMath.max(d1, ZERO); qred += sdec; } @@ -2069,7 +2069,7 @@ public class BOBYQAOptimizer if (temp <= qred * 1e-4 * qred) { state = 190; break; } - temp = FastMath.sqrt(temp); + temp = AccurateMath.sqrt(temp); for (int i = 0; i < n; i++) { if (xbdi.getEntry(i) == ZERO) { s.setEntry(i, (dredg * trialStepPoint.getEntry(i) - dredsq * gnew.getEntry(i)) / temp); @@ -2108,7 +2108,7 @@ public class BOBYQAOptimizer d1 = trustRegionCenterOffset.getEntry(i) - lowerDifference.getEntry(i); temp = ssq - d1 * d1; if (temp > ZERO) { - temp = FastMath.sqrt(temp) - s.getEntry(i); + temp = AccurateMath.sqrt(temp) - s.getEntry(i); if (angbd * temp > tempa) { angbd = tempa / temp; iact = i; @@ -2119,7 +2119,7 @@ public class BOBYQAOptimizer d1 = upperDifference.getEntry(i) - trustRegionCenterOffset.getEntry(i); temp = ssq - d1 * d1; if (temp > ZERO) { - temp = FastMath.sqrt(temp) + s.getEntry(i); + temp = AccurateMath.sqrt(temp) + s.getEntry(i); if (angbd * temp > tempb) { angbd = tempb / temp; iact = i; @@ -2224,9 +2224,9 @@ public class BOBYQAOptimizer for (int i = 0; i < n; i++) { // Computing MAX // Computing MIN - final double min = FastMath.min(trustRegionCenterOffset.getEntry(i) + trialStepPoint.getEntry(i), + final double min = AccurateMath.min(trustRegionCenterOffset.getEntry(i) + trialStepPoint.getEntry(i), upperDifference.getEntry(i)); - newPoint.setEntry(i, FastMath.max(min, lowerDifference.getEntry(i))); + newPoint.setEntry(i, AccurateMath.max(min, lowerDifference.getEntry(i))); if (xbdi.getEntry(i) == MINUS_ONE) { newPoint.setEntry(i, lowerDifference.getEntry(i)); } @@ -2315,7 +2315,7 @@ public class BOBYQAOptimizer for (int k = 0; k < npt; k++) { for (int j = 0; j < nptm; j++) { // Computing MAX - ztest = FastMath.max(ztest, FastMath.abs(zMatrix.getEntry(k, j))); + ztest = AccurateMath.max(ztest, AccurateMath.abs(zMatrix.getEntry(k, j))); } } ztest *= 1e-20; @@ -2324,12 +2324,12 @@ public class BOBYQAOptimizer for (int j = 1; j < nptm; j++) { final double d1 = zMatrix.getEntry(knew, j); - if (FastMath.abs(d1) > ztest) { + if (AccurateMath.abs(d1) > ztest) { // Computing 2nd power final double d2 = zMatrix.getEntry(knew, 0); // Computing 2nd power final double d3 = zMatrix.getEntry(knew, j); - final double d4 = FastMath.sqrt(d2 * d2 + d3 * d3); + final double d4 = AccurateMath.sqrt(d2 * d2 + d3 * d3); final double d5 = zMatrix.getEntry(knew, 0) / d4; final double d6 = zMatrix.getEntry(knew, j) / d4; for (int i = 0; i < npt; i++) { @@ -2353,7 +2353,7 @@ public class BOBYQAOptimizer // Complete the updating of ZMAT. - final double sqrtDenom = FastMath.sqrt(denom); + final double sqrtDenom = AccurateMath.sqrt(denom); final double d1 = tau / sqrtDenom; final double d2 = zMatrix.getEntry(knew, 0) / sqrtDenom; for (int i = 0; i < npt; i++) { @@ -2412,7 +2412,7 @@ public class BOBYQAOptimizer double minDiff = Double.POSITIVE_INFINITY; for (int i = 0; i < dimension; i++) { boundDifference[i] = upperBound[i] - lowerBound[i]; - minDiff = FastMath.min(minDiff, boundDifference[i]); + minDiff = AccurateMath.min(minDiff, boundDifference[i]); } if (minDiff < requiredMinDiff) { initialTrustRegionRadius = minDiff / 3.0; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java index 43575d94a..79ee03e65 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java @@ -38,7 +38,7 @@ import org.apache.commons.math4.legacy.optim.nonlinear.scalar.MultivariateOptimi import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.statistics.distribution.ContinuousDistribution; import org.apache.commons.statistics.distribution.NormalDistribution; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * An implementation of the active Covariance Matrix Adaptation Evolution Strategy (CMA-ES) @@ -443,7 +443,7 @@ public class CMAESOptimizer updateCovarianceDiagonalOnly(hsig, bestArz); } // Adapt step size sigma - Eq. (5) - sigma *= FastMath.exp(FastMath.min(1, (normps/chiN - 1) * cs / damps)); + sigma *= AccurateMath.exp(AccurateMath.min(1, (normps/chiN - 1) * cs / damps)); final double bestFitness = fitness[arindex[0]]; final double worstFitness = fitness[arindex[arindex.length - 1]]; if (bestValue > bestFitness) { @@ -464,7 +464,7 @@ public class CMAESOptimizer final double[] sqrtDiagC = sqrt(diagC).getColumn(0); final double[] pcCol = pc.getColumn(0); for (int i = 0; i < dimension; i++) { - if (sigma * FastMath.max(FastMath.abs(pcCol[i]), sqrtDiagC[i]) > stopTolX) { + if (sigma * AccurateMath.max(AccurateMath.abs(pcCol[i]), sqrtDiagC[i]) > stopTolX) { break; } if (i >= dimension - 1) { @@ -479,8 +479,8 @@ public class CMAESOptimizer final double historyBest = min(fitnessHistory); final double historyWorst = max(fitnessHistory); if (iterations > 2 && - FastMath.max(historyWorst, worstFitness) - - FastMath.min(historyBest, bestFitness) < stopTolFun) { + AccurateMath.max(historyWorst, worstFitness) - + AccurateMath.min(historyBest, bestFitness) < stopTolFun) { break generationLoop; } if (iterations > fitnessHistory.length && @@ -504,11 +504,11 @@ public class CMAESOptimizer } // Adjust step size in case of equal function values (flat fitness) if (bestValue == fitness[arindex[(int)(0.1+lambda/4.)]]) { - sigma *= FastMath.exp(0.2 + cs / damps); + sigma *= AccurateMath.exp(0.2 + cs / damps); } - if (iterations > 2 && FastMath.max(historyWorst, bestFitness) - - FastMath.min(historyBest, bestFitness) == 0) { - sigma *= FastMath.exp(0.2 + cs / damps); + if (iterations > 2 && AccurateMath.max(historyWorst, bestFitness) - + AccurateMath.min(historyBest, bestFitness) == 0) { + sigma *= AccurateMath.exp(0.2 + cs / damps); } // store best in history push(fitnessHistory,bestFitness); @@ -600,7 +600,7 @@ public class CMAESOptimizer // initialize selection strategy parameters mu = lambda / 2; // number of parents/points for recombination - logMu2 = FastMath.log(mu + 0.5); + logMu2 = AccurateMath.log(mu + 0.5); weights = log(sequence(1, mu, 1)).scalarMultiply(-1).scalarAdd(logMu2); double sumw = 0; double sumwq = 0; @@ -616,16 +616,16 @@ public class CMAESOptimizer cc = (4 + mueff / dimension) / (dimension + 4 + 2 * mueff / dimension); cs = (mueff + 2) / (dimension + mueff + 3.); - damps = (1 + 2 * FastMath.max(0, FastMath.sqrt((mueff - 1) / + damps = (1 + 2 * AccurateMath.max(0, AccurateMath.sqrt((mueff - 1) / (dimension + 1)) - 1)) * - FastMath.max(0.3, + AccurateMath.max(0.3, 1 - dimension / (1e-6 + maxIterations)) + cs; // minor increment ccov1 = 2 / ((dimension + 1.3) * (dimension + 1.3) + mueff); - ccovmu = FastMath.min(1 - ccov1, 2 * (mueff - 2 + 1 / mueff) / + ccovmu = AccurateMath.min(1 - ccov1, 2 * (mueff - 2 + 1 / mueff) / ((dimension + 2) * (dimension + 2) + mueff)); - ccov1Sep = FastMath.min(1, ccov1 * (dimension + 1.5) / 3); - ccovmuSep = FastMath.min(1 - ccov1, ccovmu * (dimension + 1.5) / 3); - chiN = FastMath.sqrt(dimension) * + ccov1Sep = AccurateMath.min(1, ccov1 * (dimension + 1.5) / 3); + ccovmuSep = AccurateMath.min(1 - ccov1, ccovmu * (dimension + 1.5) / 3); + chiN = AccurateMath.sqrt(dimension) * (1 - 1 / ((double) 4 * dimension) + 1 / ((double) 21 * dimension * dimension)); // initialize CMA internal values - updated each generation xmean = MatrixUtils.createColumnRealMatrix(guess); // objective variables @@ -657,14 +657,14 @@ public class CMAESOptimizer private boolean updateEvolutionPaths(RealMatrix zmean, RealMatrix xold) { ps = ps.scalarMultiply(1 - cs).add( B.multiply(zmean).scalarMultiply( - FastMath.sqrt(cs * (2 - cs) * mueff))); + AccurateMath.sqrt(cs * (2 - cs) * mueff))); normps = ps.getFrobeniusNorm(); final boolean hsig = normps / - FastMath.sqrt(1 - FastMath.pow(1 - cs, 2 * iterations)) / + AccurateMath.sqrt(1 - AccurateMath.pow(1 - cs, 2 * iterations)) / chiN < 1.4 + 2 / ((double) dimension + 1); pc = pc.scalarMultiply(1 - cc); if (hsig) { - pc = pc.add(xmean.subtract(xold).scalarMultiply(FastMath.sqrt(cc * (2 - cc) * mueff) / sigma)); + pc = pc.add(xmean.subtract(xold).scalarMultiply(AccurateMath.sqrt(cc * (2 - cc) * mueff) / sigma)); } return hsig; } @@ -722,7 +722,7 @@ public class CMAESOptimizer if (isActiveCMA) { // Adapt covariance matrix C active CMA negccov = (1 - ccovmu) * 0.25 * mueff / - (FastMath.pow(dimension + 2, 1.5) + 2 * mueff); + (AccurateMath.pow(dimension + 2, 1.5) + 2 * mueff); // keep at least 0.66 in all directions, small popsize are most // critical final double negminresidualvariance = 0.66; @@ -1006,7 +1006,7 @@ public class CMAESOptimizer private double penalty(final double[] x, final double[] repaired) { double penalty = 0; for (int i = 0; i < x.length; i++) { - double diff = FastMath.abs(x[i] - repaired[i]); + double diff = AccurateMath.abs(x[i] - repaired[i]); penalty += diff; } return isMinimize ? penalty : -penalty; @@ -1023,7 +1023,7 @@ public class CMAESOptimizer final double[][] d = new double[m.getRowDimension()][m.getColumnDimension()]; for (int r = 0; r < m.getRowDimension(); r++) { for (int c = 0; c < m.getColumnDimension(); c++) { - d[r][c] = FastMath.log(m.getEntry(r, c)); + d[r][c] = AccurateMath.log(m.getEntry(r, c)); } } return new Array2DRowRealMatrix(d, false); @@ -1037,7 +1037,7 @@ public class CMAESOptimizer final double[][] d = new double[m.getRowDimension()][m.getColumnDimension()]; for (int r = 0; r < m.getRowDimension(); r++) { for (int c = 0; c < m.getColumnDimension(); c++) { - d[r][c] = FastMath.sqrt(m.getEntry(r, c)); + d[r][c] = AccurateMath.sqrt(m.getEntry(r, c)); } } return new Array2DRowRealMatrix(d, false); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/PowellOptimizer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/PowellOptimizer.java index 6983bc569..5c185a6d5 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/PowellOptimizer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/PowellOptimizer.java @@ -27,7 +27,7 @@ import org.apache.commons.math4.legacy.optim.nonlinear.scalar.GoalType; import org.apache.commons.math4.legacy.optim.nonlinear.scalar.LineSearch; import org.apache.commons.math4.legacy.optim.nonlinear.scalar.MultivariateOptimizer; import org.apache.commons.math4.legacy.optim.univariate.UnivariatePointValuePair; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Powell's algorithm. @@ -59,7 +59,7 @@ public class PowellOptimizer /** * Minimum relative tolerance. */ - private static final double MIN_RELATIVE_TOLERANCE = 2 * FastMath.ulp(1d); + private static final double MIN_RELATIVE_TOLERANCE = 2 * AccurateMath.ulp(1d); /** * Relative threshold. */ @@ -90,7 +90,7 @@ public class PowellOptimizer public PowellOptimizer(double rel, double abs, ConvergenceChecker checker) { - this(rel, abs, FastMath.sqrt(rel), FastMath.sqrt(abs), checker); + this(rel, abs, AccurateMath.sqrt(rel), AccurateMath.sqrt(abs), checker); } /** @@ -210,7 +210,7 @@ public class PowellOptimizer // Default convergence check. boolean stop = 2 * (fX - fVal) <= - (relativeThreshold * (FastMath.abs(fX) + FastMath.abs(fVal)) + + (relativeThreshold * (AccurateMath.abs(fX) + AccurateMath.abs(fVal)) + absoluteThreshold); final PointValuePair previous = new PointValuePair(x1, fX); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/univariate/BracketFinder.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/univariate/BracketFinder.java index 3ff0fa5d2..4aff72ed0 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/univariate/BracketFinder.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/univariate/BracketFinder.java @@ -21,7 +21,7 @@ import org.apache.commons.math4.legacy.exception.MaxCountExceededException; import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException; import org.apache.commons.math4.legacy.optim.nonlinear.scalar.GoalType; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.math4.legacy.util.IntegerSequence.Incrementor; /** @@ -143,7 +143,7 @@ public class BracketFinder { double tmp2 = (xB - xC) * (fB - fA); double val = tmp2 - tmp1; - double denom = FastMath.abs(val) < EPS_MIN ? 2 * EPS_MIN : 2 * val; + double denom = AccurateMath.abs(val) < EPS_MIN ? 2 * EPS_MIN : 2 * val; double w = xB - ((xB - xC) * tmp2 - (xB - xA) * tmp1) / denom; double wLim = xB + growLimit * (xC - xB); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/univariate/BrentOptimizer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/univariate/BrentOptimizer.java index 112834786..8bfdf9bba 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/univariate/BrentOptimizer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/univariate/BrentOptimizer.java @@ -20,7 +20,7 @@ import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.optim.ConvergenceChecker; import org.apache.commons.math4.legacy.optim.nonlinear.scalar.GoalType; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.numbers.core.Precision; /** @@ -44,11 +44,11 @@ public class BrentOptimizer extends UnivariateOptimizer { /** * Golden section. */ - private static final double GOLDEN_SECTION = 0.5 * (3 - FastMath.sqrt(5)); + private static final double GOLDEN_SECTION = 0.5 * (3 - AccurateMath.sqrt(5)); /** * Minimum relative tolerance. */ - private static final double MIN_RELATIVE_TOLERANCE = 2 * FastMath.ulp(1d); + private static final double MIN_RELATIVE_TOLERANCE = 2 * AccurateMath.ulp(1d); /** * Relative threshold. */ @@ -151,18 +151,18 @@ public class BrentOptimizer extends UnivariateOptimizer { while (true) { final double m = 0.5 * (a + b); - final double tol1 = relativeThreshold * FastMath.abs(x) + absoluteThreshold; + final double tol1 = relativeThreshold * AccurateMath.abs(x) + absoluteThreshold; final double tol2 = 2 * tol1; // Default stopping criterion. - final boolean stop = FastMath.abs(x - m) <= tol2 - 0.5 * (b - a); + final boolean stop = AccurateMath.abs(x - m) <= tol2 - 0.5 * (b - a); if (!stop) { double p = 0; double q = 0; double r = 0; double u = 0; - if (FastMath.abs(e) > tol1) { // Fit parabola. + if (AccurateMath.abs(e) > tol1) { // Fit parabola. r = (x - w) * (fx - fv); q = (x - v) * (fx - fw); p = (x - v) * q - (x - w) * r; @@ -179,7 +179,7 @@ public class BrentOptimizer extends UnivariateOptimizer { if (p > q * (a - x) && p < q * (b - x) && - FastMath.abs(p) < FastMath.abs(0.5 * q * r)) { + AccurateMath.abs(p) < AccurateMath.abs(0.5 * q * r)) { // Parabolic interpolation step. d = p / q; u = x + d; @@ -212,7 +212,7 @@ public class BrentOptimizer extends UnivariateOptimizer { } // Update by at least "tol1". - if (FastMath.abs(d) < tol1) { + if (AccurateMath.abs(d) < tol1) { if (d >= 0) { u = x + tol1; } else { diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/univariate/SimpleUnivariateValueChecker.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/univariate/SimpleUnivariateValueChecker.java index cf4c9ee0a..b23b172f6 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/univariate/SimpleUnivariateValueChecker.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/univariate/SimpleUnivariateValueChecker.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.optim.univariate; import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.optim.AbstractConvergenceChecker; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Simple implementation of the @@ -119,8 +119,8 @@ public class SimpleUnivariateValueChecker final double p = previous.getValue(); final double c = current.getValue(); - final double difference = FastMath.abs(p - c); - final double size = FastMath.max(FastMath.abs(p), FastMath.abs(c)); + final double difference = AccurateMath.abs(p - c); + final double size = AccurateMath.max(AccurateMath.abs(p), AccurateMath.abs(c)); return difference <= size * getRelativeThreshold() || difference <= getAbsoluteThreshold(); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/RngAdaptor.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/RngAdaptor.java index 7035d0569..c16587dc0 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/RngAdaptor.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/RngAdaptor.java @@ -20,7 +20,7 @@ import java.io.Serializable; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.ObjectInputStream; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.rng.RestorableUniformRandomProvider; import org.apache.commons.rng.simple.RandomSource; import org.apache.commons.rng.core.RandomProviderDefaultState; @@ -159,10 +159,10 @@ public final class RngAdaptor // generate a new pair of gaussian numbers final double x = nextDouble(); final double y = nextDouble(); - final double alpha = 2 * FastMath.PI * x; - final double r = FastMath.sqrt(-2 * FastMath.log(y)); - random = r * FastMath.cos(alpha); - nextGaussian = r * FastMath.sin(alpha); + final double alpha = 2 * AccurateMath.PI * x; + final double r = AccurateMath.sqrt(-2 * AccurateMath.log(y)); + random = r * AccurateMath.cos(alpha); + nextGaussian = r * AccurateMath.sin(alpha); } else { // use the second element of the pair already generated random = nextGaussian; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/SobolSequenceGenerator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/SobolSequenceGenerator.java index 3bcb8ce32..c13c272ed 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/SobolSequenceGenerator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/SobolSequenceGenerator.java @@ -31,7 +31,7 @@ import org.apache.commons.math4.legacy.exception.MathParseException; import org.apache.commons.math4.legacy.exception.NotPositiveException; import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Implementation of a Sobol sequence. @@ -59,7 +59,7 @@ public class SobolSequenceGenerator implements Supplier { private static final int BITS = 52; /** The scaling factor. */ - private static final double SCALE = FastMath.pow(2, BITS); + private static final double SCALE = AccurateMath.pow(2, BITS); /** The maximum supported space dimension. */ private static final int MAX_DIMENSION = 21201; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/StableRandomGenerator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/StableRandomGenerator.java index 37ba3a66d..a842544cb 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/StableRandomGenerator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/StableRandomGenerator.java @@ -20,7 +20,7 @@ import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** *

This class provides a stable normalized random generator. It samples from a stable @@ -73,7 +73,7 @@ public class StableRandomGenerator implements NormalizedRandomGenerator { this.alpha = alpha; this.beta = beta; if (alpha < 2d && beta != 0d) { - zeta = beta * FastMath.tan(FastMath.PI * alpha / 2); + zeta = beta * AccurateMath.tan(AccurateMath.PI * alpha / 2); } else { zeta = 0d; } @@ -87,12 +87,12 @@ public class StableRandomGenerator implements NormalizedRandomGenerator { @Override public double nextNormalizedDouble() { // we need 2 uniform random numbers to calculate omega and phi - double omega = -FastMath.log(generator.nextDouble()); - double phi = FastMath.PI * (generator.nextDouble() - 0.5); + double omega = -AccurateMath.log(generator.nextDouble()); + double phi = AccurateMath.PI * (generator.nextDouble() - 0.5); // Normal distribution case (Box-Muller algorithm) if (alpha == 2d) { - return FastMath.sqrt(2d * omega) * FastMath.sin(phi); + return AccurateMath.sqrt(2d * omega) * AccurateMath.sin(phi); } double x; @@ -101,30 +101,30 @@ public class StableRandomGenerator implements NormalizedRandomGenerator { if (beta == 0d) { // Cauchy distribution case if (alpha == 1d) { - x = FastMath.tan(phi); + x = AccurateMath.tan(phi); } else { - x = FastMath.pow(omega * FastMath.cos((1 - alpha) * phi), + x = AccurateMath.pow(omega * AccurateMath.cos((1 - alpha) * phi), 1d / alpha - 1d) * - FastMath.sin(alpha * phi) / - FastMath.pow(FastMath.cos(phi), 1d / alpha); + AccurateMath.sin(alpha * phi) / + AccurateMath.pow(AccurateMath.cos(phi), 1d / alpha); } } else { // Generic stable distribution - double cosPhi = FastMath.cos(phi); + double cosPhi = AccurateMath.cos(phi); // to avoid rounding errors around alpha = 1 - if (FastMath.abs(alpha - 1d) > 1e-8) { + if (AccurateMath.abs(alpha - 1d) > 1e-8) { double alphaPhi = alpha * phi; double invAlphaPhi = phi - alphaPhi; - x = (FastMath.sin(alphaPhi) + zeta * FastMath.cos(alphaPhi)) / cosPhi * - (FastMath.cos(invAlphaPhi) + zeta * FastMath.sin(invAlphaPhi)) / - FastMath.pow(omega * cosPhi, (1 - alpha) / alpha); + x = (AccurateMath.sin(alphaPhi) + zeta * AccurateMath.cos(alphaPhi)) / cosPhi * + (AccurateMath.cos(invAlphaPhi) + zeta * AccurateMath.sin(invAlphaPhi)) / + AccurateMath.pow(omega * cosPhi, (1 - alpha) / alpha); } else { - double betaPhi = FastMath.PI / 2 + beta * phi; - x = 2d / FastMath.PI * (betaPhi * FastMath.tan(phi) - beta * - FastMath.log(FastMath.PI / 2d * omega * cosPhi / betaPhi)); + double betaPhi = AccurateMath.PI / 2 + beta * phi; + x = 2d / AccurateMath.PI * (betaPhi * AccurateMath.tan(phi) - beta * + AccurateMath.log(AccurateMath.PI / 2d * omega * cosPhi / betaPhi)); if (alpha != 1d) { - x += beta * FastMath.tan(FastMath.PI * alpha / 2); + x += beta * AccurateMath.tan(AccurateMath.PI * alpha / 2); } } } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/UniformRandomGenerator.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/UniformRandomGenerator.java index 74ddb4947..a8ef51541 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/UniformRandomGenerator.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/random/UniformRandomGenerator.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.random; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.rng.UniformRandomProvider; /** @@ -33,7 +33,7 @@ import org.apache.commons.rng.UniformRandomProvider; */ public class UniformRandomGenerator implements NormalizedRandomGenerator { /** Square root of three. */ - private static final double SQRT3 = FastMath.sqrt(3); + private static final double SQRT3 = AccurateMath.sqrt(3); /** Underlying generator. */ private final UniformRandomProvider generator; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/special/BesselJ.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/special/BesselJ.java index d2671bc47..7972f1242 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/special/BesselJ.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/special/BesselJ.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.analysis.UnivariateFunction; import org.apache.commons.math4.legacy.exception.ConvergenceException; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * This class provides computation methods related to Bessel @@ -165,7 +165,7 @@ public class BesselJ return res.vals[n]; } else if (res.nVals < 0) { throw new MathIllegalArgumentException(LocalizedFormats.BESSEL_FUNCTION_BAD_ARGUMENT,order, x); - } else if (FastMath.abs(res.vals[res.nVals - 1]) < 1e-100) { + } else if (AccurateMath.abs(res.vals[res.nVals - 1]) < 1e-100) { return res.vals[n]; // underflow; return value (will be zero) } throw new ConvergenceException(LocalizedFormats.BESSEL_FUNCTION_FAILED_CONVERGENCE, order, x); @@ -283,7 +283,7 @@ public class BesselJ halfx = 0.5 * x; } if (alpha != 0) { - tempa = FastMath.pow(halfx, alpha) / + tempa = AccurateMath.pow(halfx, alpha) / (alpha * Gamma.value(alpha)); } tempb = 0; @@ -323,7 +323,7 @@ public class BesselJ // --------------------------------------------------------------------- // Asymptotic series for X > 25 // --------------------------------------------------------------------- - final double xc = FastMath.sqrt(PI2 / x); + final double xc = AccurateMath.sqrt(PI2 / x); final double mul = 0.125 / x; final double xin = mul * mul; int m = 0; @@ -341,8 +341,8 @@ public class BesselJ // --------------------------------------------------------------------- double t = (double) ((int) ((x / TWOPI) + 0.5)); final double z = x - t * TOWPI1 - t * TWOPI2 - (alpha + 0.5) / PI2; - double vsin = FastMath.sin(z); - double vcos = FastMath.cos(z); + double vsin = AccurateMath.sin(z); + double vcos = AccurateMath.cos(z); double gnu = 2 * alpha; double capq; double capp; @@ -457,7 +457,7 @@ public class BesselJ p = plast * tover; n -= 1; en -= 2.0; - nend = FastMath.min(nb, n); + nend = AccurateMath.min(nb, n); for (int l = nstart; l <= nend; l++) { pold = psavel; psavel = psave; @@ -479,8 +479,8 @@ public class BesselJ // --------------------------------------------------------------------- // Calculate special significance test for NBMX > 2. // --------------------------------------------------------------------- - test = FastMath.max(test, FastMath.sqrt(plast * ENSIG) * - FastMath.sqrt(2 * p)); + test = AccurateMath.max(test, AccurateMath.sqrt(plast * ENSIG) * + AccurateMath.sqrt(2 * p)); } } // --------------------------------------------------------------------- @@ -620,8 +620,8 @@ public class BesselJ // Normalize. Divide all B(N) by sum. // --------------------------------------------------------------------- - if (FastMath.abs(alpha) > 1e-16) { - sum *= Gamma.value(alpha) * FastMath.pow(x * 0.5, -alpha); + if (AccurateMath.abs(alpha) > 1e-16) { + sum *= Gamma.value(alpha) * AccurateMath.pow(x * 0.5, -alpha); } tempa = ENMTEN; if (sum > 1) { @@ -629,7 +629,7 @@ public class BesselJ } for (n = 0; n < nb; n++) { - if (FastMath.abs(b[n]) < tempa) { + if (AccurateMath.abs(b[n]) < tempa) { b[n] = 0; } b[n] /= sum; @@ -642,7 +642,7 @@ public class BesselJ if (b.length > 0) { b[0] = 0; } - ncalc = FastMath.min(nb, 0) - 1; + ncalc = AccurateMath.min(nb, 0) - 1; } return new BesselJResult(Arrays.copyOf(b, b.length), ncalc); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/correlation/KendallsCorrelation.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/correlation/KendallsCorrelation.java index 4ac6d9da3..794742369 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/correlation/KendallsCorrelation.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/correlation/KendallsCorrelation.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.linear.BlockRealMatrix; import org.apache.commons.math4.legacy.linear.MatrixUtils; import org.apache.commons.math4.legacy.linear.RealMatrix; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.math4.legacy.util.Pair; /** @@ -208,9 +208,9 @@ public class KendallsCorrelation { for (int segmentSize = 1; segmentSize < n; segmentSize <<= 1) { for (int offset = 0; offset < n; offset += 2 * segmentSize) { int i = offset; - final int iEnd = FastMath.min(i + segmentSize, n); + final int iEnd = AccurateMath.min(i + segmentSize, n); int j = iEnd; - final int jEnd = FastMath.min(j + segmentSize, n); + final int jEnd = AccurateMath.min(j + segmentSize, n); int copyLocation = offset; while (i < iEnd || j < jEnd) { @@ -257,7 +257,7 @@ public class KendallsCorrelation { final long concordantMinusDiscordant = numPairs - tiedXPairs - tiedYPairs + tiedXYPairs - 2 * swaps; final double nonTiedPairsMultiplied = (numPairs - tiedXPairs) * (double) (numPairs - tiedYPairs); - return concordantMinusDiscordant / FastMath.sqrt(nonTiedPairsMultiplied); + return concordantMinusDiscordant / AccurateMath.sqrt(nonTiedPairsMultiplied); } /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/correlation/PearsonsCorrelation.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/correlation/PearsonsCorrelation.java index 08084a0e6..dc68e48af 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/correlation/PearsonsCorrelation.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/correlation/PearsonsCorrelation.java @@ -24,7 +24,7 @@ import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; import org.apache.commons.math4.legacy.linear.BlockRealMatrix; import org.apache.commons.math4.legacy.linear.RealMatrix; import org.apache.commons.math4.legacy.stat.regression.SimpleRegression; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Computes Pearson's product-moment correlation coefficients for pairs of arrays @@ -165,7 +165,7 @@ public class PearsonsCorrelation { for (int i = 0; i < nVars; i++) { for (int j = 0; j < nVars; j++) { double r = correlationMatrix.getEntry(i, j); - out[i][j] = FastMath.sqrt((1 - r * r) /(nObs - 2)); + out[i][j] = AccurateMath.sqrt((1 - r * r) /(nObs - 2)); } } return new BlockRealMatrix(out); @@ -201,7 +201,7 @@ public class PearsonsCorrelation { out[i][j] = 0d; } else { double r = correlationMatrix.getEntry(i, j); - double t = FastMath.abs(r * FastMath.sqrt((nObs - 2)/(1 - r * r))); + double t = AccurateMath.abs(r * AccurateMath.sqrt((nObs - 2)/(1 - r * r))); out[i][j] = 2 * tDistribution.cumulativeProbability(-t); } } @@ -300,11 +300,11 @@ public class PearsonsCorrelation { int nVars = covarianceMatrix.getColumnDimension(); RealMatrix outMatrix = new BlockRealMatrix(nVars, nVars); for (int i = 0; i < nVars; i++) { - double sigma = FastMath.sqrt(covarianceMatrix.getEntry(i, i)); + double sigma = AccurateMath.sqrt(covarianceMatrix.getEntry(i, i)); outMatrix.setEntry(i, i, 1d); for (int j = 0; j < i; j++) { double entry = covarianceMatrix.getEntry(i, j) / - (sigma * FastMath.sqrt(covarianceMatrix.getEntry(j, j))); + (sigma * AccurateMath.sqrt(covarianceMatrix.getEntry(j, j))); outMatrix.setEntry(i, j, entry); outMatrix.setEntry(j, i, entry); } diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/AbstractStorelessUnivariateStatistic.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/AbstractStorelessUnivariateStatistic.java index 0da1b10d8..a42f7689a 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/AbstractStorelessUnivariateStatistic.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/AbstractStorelessUnivariateStatistic.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.stat.descriptive; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; import org.apache.commons.numbers.core.Precision; /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/AbstractUnivariateStatistic.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/AbstractUnivariateStatistic.java index d13f4acc4..b5f0afb18 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/AbstractUnivariateStatistic.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/AbstractUnivariateStatistic.java @@ -21,7 +21,7 @@ import org.apache.commons.math4.legacy.exception.NotPositiveException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Abstract base class for implementations of the {@link UnivariateStatistic} interface. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/DescriptiveStatistics.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/DescriptiveStatistics.java index d95a7d08c..f54f95a9e 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/DescriptiveStatistics.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/DescriptiveStatistics.java @@ -34,7 +34,7 @@ import org.apache.commons.math4.legacy.stat.descriptive.rank.Min; import org.apache.commons.math4.legacy.stat.descriptive.rank.Percentile; import org.apache.commons.math4.legacy.stat.descriptive.summary.Sum; import org.apache.commons.math4.legacy.stat.descriptive.summary.SumOfSquares; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** @@ -272,7 +272,7 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable { double stdDev = Double.NaN; if (getN() > 0) { if (getN() > 1) { - stdDev = FastMath.sqrt(getVariance()); + stdDev = AccurateMath.sqrt(getVariance()); } else { stdDev = 0.0; } @@ -289,7 +289,7 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable { */ public double getQuadraticMean() { final long n = getN(); - return n > 0 ? FastMath.sqrt(getSumsq() / n) : Double.NaN; + return n > 0 ? AccurateMath.sqrt(getSumsq() / n) : Double.NaN; } /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/MultivariateSummaryStatistics.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/MultivariateSummaryStatistics.java index ee2471f37..30284288a 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/MultivariateSummaryStatistics.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/MultivariateSummaryStatistics.java @@ -31,8 +31,8 @@ import org.apache.commons.math4.legacy.stat.descriptive.rank.Min; import org.apache.commons.math4.legacy.stat.descriptive.summary.Sum; import org.apache.commons.math4.legacy.stat.descriptive.summary.SumOfLogs; import org.apache.commons.math4.legacy.stat.descriptive.summary.SumOfSquares; -import org.apache.commons.math4.legacy.util.FastMath; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.legacy.core.MathArrays; import org.apache.commons.numbers.core.Precision; /** @@ -255,7 +255,7 @@ public class MultivariateSummaryStatistics } else { RealMatrix matrix = covarianceImpl.getResult(); for (int i = 0; i < k; ++i) { - stdDev[i] = FastMath.sqrt(matrix.getEntry(i, i)); + stdDev[i] = AccurateMath.sqrt(matrix.getEntry(i, i)); } } return stdDev; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/ResizableDoubleArray.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/ResizableDoubleArray.java index d68ea75fe..42153d1af 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/ResizableDoubleArray.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/ResizableDoubleArray.java @@ -25,8 +25,8 @@ import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; -import org.apache.commons.math4.legacy.util.FastMath; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.legacy.core.MathArrays; /** * A variable length {@link DoubleArray} implementation that automatically @@ -540,16 +540,16 @@ class ResizableDoubleArray implements DoubleArray, Serializable { // Not in publ * after expansion will be {@code internalArray.length + expansionFactor}. */ protected void expand() { - // notice the use of FastMath.ceil(), this guarantees that we will always + // notice the use of AccurateMath.ceil(), this guarantees that we will always // have an array of at least currentSize + 1. Assume that the // current initial capacity is 1 and the expansion factor // is 1.000000000000000001. The newly calculated size will be // rounded up to 2 after the multiplication is performed. int newSize = 0; if (expansionMode == ExpansionMode.MULTIPLICATIVE) { - newSize = (int) FastMath.ceil(internalArray.length * expansionFactor); + newSize = (int) AccurateMath.ceil(internalArray.length * expansionFactor); } else { - newSize = (int) (internalArray.length + FastMath.round(expansionFactor)); + newSize = (int) (internalArray.length + AccurateMath.round(expansionFactor)); } final double[] tempArray = new double[newSize]; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/StatisticalSummaryValues.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/StatisticalSummaryValues.java index cfd81170b..6cac22d92 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/StatisticalSummaryValues.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/StatisticalSummaryValues.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.legacy.stat.descriptive; import java.io.Serializable; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.numbers.core.Precision; /** @@ -115,7 +115,7 @@ public class StatisticalSummaryValues implements Serializable, */ @Override public double getStandardDeviation() { - return FastMath.sqrt(variance); + return AccurateMath.sqrt(variance); } /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/SummaryStatistics.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/SummaryStatistics.java index 224492e79..90629f3d6 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/SummaryStatistics.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/SummaryStatistics.java @@ -30,7 +30,7 @@ import org.apache.commons.math4.legacy.stat.descriptive.rank.Min; import org.apache.commons.math4.legacy.stat.descriptive.summary.Sum; import org.apache.commons.math4.legacy.stat.descriptive.summary.SumOfLogs; import org.apache.commons.math4.legacy.stat.descriptive.summary.SumOfSquares; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; import org.apache.commons.numbers.core.Precision; /** @@ -219,7 +219,7 @@ public class SummaryStatistics implements StatisticalSummary, Serializable { double stdDev = Double.NaN; if (getN() > 0) { if (getN() > 1) { - stdDev = FastMath.sqrt(getVariance()); + stdDev = AccurateMath.sqrt(getVariance()); } else { stdDev = 0.0; } @@ -236,7 +236,7 @@ public class SummaryStatistics implements StatisticalSummary, Serializable { */ public double getQuadraticMean() { final long size = getN(); - return size > 0 ? FastMath.sqrt(getSumsq() / size) : Double.NaN; + return size > 0 ? AccurateMath.sqrt(getSumsq() / size) : Double.NaN; } /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/UnivariateStatistic.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/UnivariateStatistic.java index ab43612ac..eed0669d5 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/UnivariateStatistic.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/UnivariateStatistic.java @@ -17,7 +17,7 @@ package org.apache.commons.math4.legacy.stat.descriptive; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/GeometricMean.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/GeometricMean.java index 6a5507e3f..00dc11bd5 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/GeometricMean.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/GeometricMean.java @@ -25,7 +25,7 @@ import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; import org.apache.commons.math4.legacy.stat.descriptive.AbstractStorelessUnivariateStatistic; import org.apache.commons.math4.legacy.stat.descriptive.StorelessUnivariateStatistic; import org.apache.commons.math4.legacy.stat.descriptive.summary.SumOfLogs; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Returns the @@ -108,7 +108,7 @@ public class GeometricMean extends AbstractStorelessUnivariateStatistic implemen @Override public double getResult() { if (sumOfLogs.getN() > 0) { - return FastMath.exp(sumOfLogs.getResult() / sumOfLogs.getN()); + return AccurateMath.exp(sumOfLogs.getResult() / sumOfLogs.getN()); } else { return Double.NaN; } @@ -141,7 +141,7 @@ public class GeometricMean extends AbstractStorelessUnivariateStatistic implemen @Override public double evaluate(final double[] values, final int begin, final int length) throws MathIllegalArgumentException { - return FastMath.exp(sumOfLogs.evaluate(values, begin, length) / length); + return AccurateMath.exp(sumOfLogs.evaluate(values, begin, length) / length); } /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Kurtosis.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Kurtosis.java index 2791b9ff9..2d189461a 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Kurtosis.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Kurtosis.java @@ -21,8 +21,8 @@ import java.io.Serializable; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.stat.descriptive.AbstractStorelessUnivariateStatistic; -import org.apache.commons.math4.legacy.util.FastMath; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.legacy.core.MathArrays; /** @@ -171,15 +171,15 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic implements S Variance variance = new Variance(); variance.incrementAll(values, begin, length); double mean = variance.moment.m1; - double stdDev = FastMath.sqrt(variance.getResult()); + double stdDev = AccurateMath.sqrt(variance.getResult()); // Sum the ^4 of the distance from the mean divided by the // standard deviation double accum3 = 0.0; for (int i = begin; i < begin + length; i++) { - accum3 += FastMath.pow(values[i] - mean, 4.0); + accum3 += AccurateMath.pow(values[i] - mean, 4.0); } - accum3 /= FastMath.pow(stdDev, 4.0d); + accum3 /= AccurateMath.pow(stdDev, 4.0d); // Get N double n0 = length; @@ -187,7 +187,7 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic implements S double coefficientOne = (n0 * (n0 + 1)) / ((n0 - 1) * (n0 - 2) * (n0 - 3)); double termTwo = - (3 * FastMath.pow(n0 - 1, 2.0)) / ((n0 - 2) * (n0 - 3)); + (3 * AccurateMath.pow(n0 - 1, 2.0)) / ((n0 - 2) * (n0 - 3)); // Calculate kurtosis kurt = (coefficientOne * accum3) - termTwo; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Mean.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Mean.java index 82b23d2c7..91de459c4 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Mean.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Mean.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.stat.descriptive.AbstractStorelessUnivariateStatistic; import org.apache.commons.math4.legacy.stat.descriptive.WeightedEvaluation; import org.apache.commons.math4.legacy.stat.descriptive.summary.Sum; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Computes the arithmetic mean of a set of values. Uses the definitional diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/SemiVariance.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/SemiVariance.java index f590a841d..475a68be6 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/SemiVariance.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/SemiVariance.java @@ -22,7 +22,7 @@ import java.io.Serializable; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.stat.descriptive.AbstractUnivariateStatistic; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** *

Computes the semivariance of a set of values with respect to a given cutoff value. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Skewness.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Skewness.java index 204924517..7945614c7 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Skewness.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Skewness.java @@ -21,8 +21,8 @@ import java.io.Serializable; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.stat.descriptive.AbstractStorelessUnivariateStatistic; -import org.apache.commons.math4.legacy.util.FastMath; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Computes the skewness of the available values. @@ -120,7 +120,7 @@ public class Skewness extends AbstractStorelessUnivariateStatistic implements Se } else { double n0 = moment.getN(); return (n0 * moment.m3) / - ((n0 - 1) * (n0 -2) * FastMath.sqrt(variance) * variance); + ((n0 - 1) * (n0 -2) * AccurateMath.sqrt(variance) * variance); } } @@ -186,7 +186,7 @@ public class Skewness extends AbstractStorelessUnivariateStatistic implements Se final double d = values[i] - m; accum3 += d * d * d; } - accum3 /= variance * FastMath.sqrt(variance); + accum3 /= variance * AccurateMath.sqrt(variance); // Get N double n0 = length; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/StandardDeviation.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/StandardDeviation.java index cae7c12ec..b747f77c8 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/StandardDeviation.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/StandardDeviation.java @@ -21,7 +21,7 @@ import java.io.Serializable; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.stat.descriptive.AbstractStorelessUnivariateStatistic; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * Computes the sample standard deviation. The standard deviation @@ -125,7 +125,7 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic */ @Override public double getResult() { - return FastMath.sqrt(variance.getResult()); + return AccurateMath.sqrt(variance.getResult()); } /** @@ -152,7 +152,7 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic */ @Override public double evaluate(final double[] values) throws MathIllegalArgumentException { - return FastMath.sqrt(variance.evaluate(values)); + return AccurateMath.sqrt(variance.evaluate(values)); } /** @@ -176,7 +176,7 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic @Override public double evaluate(final double[] values, final int begin, final int length) throws MathIllegalArgumentException { - return FastMath.sqrt(variance.evaluate(values, begin, length)); + return AccurateMath.sqrt(variance.evaluate(values, begin, length)); } /** @@ -205,7 +205,7 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic */ public double evaluate(final double[] values, final double mean, final int begin, final int length) throws MathIllegalArgumentException { - return FastMath.sqrt(variance.evaluate(values, mean, begin, length)); + return AccurateMath.sqrt(variance.evaluate(values, mean, begin, length)); } /** @@ -231,7 +231,7 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic */ public double evaluate(final double[] values, final double mean) throws MathIllegalArgumentException { - return FastMath.sqrt(variance.evaluate(values, mean)); + return AccurateMath.sqrt(variance.evaluate(values, mean)); } /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Variance.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Variance.java index a58810a8b..974051863 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Variance.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/moment/Variance.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; import org.apache.commons.math4.legacy.stat.descriptive.AbstractStorelessUnivariateStatistic; import org.apache.commons.math4.legacy.stat.descriptive.WeightedEvaluation; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Computes the variance of the available values. By default, the unbiased diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/CentralPivotingStrategy.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/CentralPivotingStrategy.java index 7632e3221..e6e0d2ad4 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/CentralPivotingStrategy.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/CentralPivotingStrategy.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.stat.descriptive.rank; import java.io.Serializable; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * A mid point strategy based on the average of begin and end indices. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/KthSelector.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/KthSelector.java index 3b764a7ac..7e4877698 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/KthSelector.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/KthSelector.java @@ -20,7 +20,7 @@ import java.io.Serializable; import java.util.Arrays; import org.apache.commons.math4.legacy.exception.NullArgumentException; -import org.apache.commons.math4.legacy.util.FastMath; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; /** * A Simple Kth selector implementation to pick up the @@ -101,11 +101,11 @@ public class KthSelector implements Serializable { } else if (k < pivot) { // the element is in the left partition end = pivot; - node = FastMath.min(2 * node + 1, usePivotsHeap ? pivotsHeap.length : end); + node = AccurateMath.min(2 * node + 1, usePivotsHeap ? pivotsHeap.length : end); } else { // the element is in the right partition begin = pivot + 1; - node = FastMath.min(2 * node + 2, usePivotsHeap ? pivotsHeap.length : end); + node = AccurateMath.min(2 * node + 2, usePivotsHeap ? pivotsHeap.length : end); } } Arrays.sort(work, begin, end); diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Max.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Max.java index 0e4f85e00..b3b7a90e4 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Max.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Max.java @@ -21,7 +21,7 @@ import java.io.Serializable; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.stat.descriptive.AbstractStorelessUnivariateStatistic; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Returns the maximum of the available values. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/MedianOf3PivotingStrategy.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/MedianOf3PivotingStrategy.java index 7d2842f40..671ccca43 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/MedianOf3PivotingStrategy.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/MedianOf3PivotingStrategy.java @@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.stat.descriptive.rank; import java.io.Serializable; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Min.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Min.java index 0ce7b45d5..760ba36d3 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Min.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Min.java @@ -21,7 +21,7 @@ import java.io.Serializable; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.stat.descriptive.AbstractStorelessUnivariateStatistic; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Returns the minimum of the available values. diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/PSquarePercentile.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/PSquarePercentile.java index ee06b41b3..29a54c6d5 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/PSquarePercentile.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/PSquarePercentile.java @@ -36,7 +36,7 @@ import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; import org.apache.commons.math4.legacy.stat.descriptive.AbstractStorelessUnivariateStatistic; import org.apache.commons.math4.legacy.stat.descriptive.StorelessUnivariateStatistic; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; import org.apache.commons.numbers.core.Precision; /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Percentile.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Percentile.java index 8fe9c5136..777fce6dd 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Percentile.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Percentile.java @@ -28,8 +28,8 @@ import org.apache.commons.math4.legacy.exception.OutOfRangeException; import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; import org.apache.commons.math4.legacy.stat.descriptive.AbstractUnivariateStatistic; import org.apache.commons.math4.legacy.stat.ranking.NaNStrategy; -import org.apache.commons.math4.legacy.util.FastMath; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.legacy.core.MathArrays; import org.apache.commons.numbers.core.Precision; /** @@ -964,7 +964,7 @@ public class Percentile extends AbstractUnivariateStatistic implements Serializa protected double estimate(final double[] values, final int[] pivotsHeap, final double pos, final int length, final KthSelector selector) { - return super.estimate(values, pivotsHeap, FastMath.ceil(pos - 0.5), length, selector); + return super.estimate(values, pivotsHeap, AccurateMath.ceil(pos - 0.5), length, selector); } @Override public double evaluate(final double[] work, final double[] sampleWeights, @@ -1001,9 +1001,9 @@ public class Percentile extends AbstractUnivariateStatistic implements Serializa final int[] pivotsHeap, final double pos, final int length, final KthSelector selector) { final double low = - super.estimate(values, pivotsHeap, FastMath.ceil(pos - 0.5), length, selector); + super.estimate(values, pivotsHeap, AccurateMath.ceil(pos - 0.5), length, selector); final double high = - super.estimate(values, pivotsHeap,FastMath.floor(pos + 0.5), length, selector); + super.estimate(values, pivotsHeap,AccurateMath.floor(pos + 0.5), length, selector); return (low + high) / 2; } @Override @@ -1025,7 +1025,7 @@ public class Percentile extends AbstractUnivariateStatistic implements Serializa protected double index(final double p, final int length) { final double minLimit = 1d/2 / length; return Double.compare(p, minLimit) <= 0 ? - 0 : FastMath.rint(length * p); + 0 : AccurateMath.rint(length * p); } @Override public double evaluate(final double[] work, final double[] sampleWeights, @@ -1271,7 +1271,7 @@ public class Percentile extends AbstractUnivariateStatistic implements Serializa final double pos, final int length, final KthSelector selector) { - final double fpos = FastMath.floor(pos); + final double fpos = AccurateMath.floor(pos); final int intPos = (int) fpos; final double dif = pos - fpos; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/RandomPivotingStrategy.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/RandomPivotingStrategy.java index 279738f9e..70efe5ff1 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/RandomPivotingStrategy.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/RandomPivotingStrategy.java @@ -21,7 +21,7 @@ import java.io.IOException; import java.io.ObjectOutputStream; import java.io.ObjectInputStream; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; import org.apache.commons.rng.RestorableUniformRandomProvider; import org.apache.commons.rng.simple.RandomSource; import org.apache.commons.rng.core.RandomProviderDefaultState; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/Product.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/Product.java index 2ac140a7e..cd697fe32 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/Product.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/Product.java @@ -22,8 +22,8 @@ import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.stat.descriptive.AbstractStorelessUnivariateStatistic; import org.apache.commons.math4.legacy.stat.descriptive.WeightedEvaluation; -import org.apache.commons.math4.legacy.util.FastMath; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Returns the product of the available values. @@ -165,7 +165,7 @@ public class Product extends AbstractStorelessUnivariateStatistic implements Ser if (MathArrays.verifyValues(values, weights, begin, length, true)) { product = 1.0; for (int i = begin; i < begin + length; i++) { - product *= FastMath.pow(values[i], weights[i]); + product *= AccurateMath.pow(values[i], weights[i]); } } return product; diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/Sum.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/Sum.java index fc8b72388..ecb102bff 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/Sum.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/Sum.java @@ -21,7 +21,7 @@ import java.io.Serializable; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.stat.descriptive.AbstractStorelessUnivariateStatistic; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.MathArrays; /** diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/SumOfLogs.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/SumOfLogs.java index dd709eb73..1b8832a74 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/SumOfLogs.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/summary/SumOfLogs.java @@ -21,13 +21,13 @@ import java.io.Serializable; import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException; import org.apache.commons.math4.legacy.exception.NullArgumentException; import org.apache.commons.math4.legacy.stat.descriptive.AbstractStorelessUnivariateStatistic; -import org.apache.commons.math4.legacy.util.FastMath; -import org.apache.commons.math4.legacy.util.MathArrays; +import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath; +import org.apache.commons.math4.legacy.core.MathArrays; /** * Returns the sum of the natural logs for this collection of values. *

- * Uses {@link org.apache.commons.math4.legacy.util.FastMath#log(double)} to compute the logs. + * Uses {@link org.apache.commons.math4.legacy.core.jdkmath.AccurateMath#log(double)} to compute the logs. * Therefore, *