Create module "commons-math-legacy-core" for holding functionality needed by many "legacy" modules.
"FastMath" (renamed "AccurateMath") and related classes moved to "o.a.c.m.legacy.core.jdkmath".
This commit is contained in:
parent
ce65e6ba3f
commit
e85e8b53f2
|
@ -27,7 +27,7 @@
|
|||
<artifactId>commons-math-examples</artifactId>
|
||||
<version>4.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>Apache Commons Math Examples</name>
|
||||
<name>Example applications</name>
|
||||
|
||||
<description>Examples of use of the "Commons Math" library.
|
||||
Codes in this module and its sub-modules are not part of the public API.
|
||||
|
|
|
@ -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.
|
||||
===============================================================================
|
||||
|
|
@ -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
|
|
@ -0,0 +1,74 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-math-parent</artifactId>
|
||||
<version>4.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>commons-math4-legacy-core</artifactId>
|
||||
<name>Miscellaneous core classes (Legacy)</name>
|
||||
|
||||
<description>Field, Dfp, ...</description>
|
||||
|
||||
<properties>
|
||||
<!-- The Java Module System Name -->
|
||||
<commons.module.name>org.apache.commons.math4.legacy.core</commons.module.name>
|
||||
<!-- This value must reflect the current name of the base package. -->
|
||||
<commons.osgi.symbolicName>org.apache.commons.math4.legacy.core</commons.osgi.symbolicName>
|
||||
<!-- OSGi -->
|
||||
<commons.osgi.export>org.apache.commons.math4.legacy.core</commons.osgi.export>
|
||||
<!-- Workaround to avoid duplicating config files. -->
|
||||
<math.parent.dir>${basedir}/..</math.parent.dir>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-math4-legacy-exception</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-numbers-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-numbers-arrays</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-rng-client-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-rng-simple</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -14,7 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.legacy;
|
||||
package org.apache.commons.math4.legacy.core;
|
||||
|
||||
/**
|
||||
* Interface representing a <a href="http://mathworld.wolfram.com/Field.html">field</a>.
|
|
@ -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;
|
|
@ -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++];
|
|
@ -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;
|
||||
|
|
@ -15,13 +15,12 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.commons.math4.legacy.dfp;
|
||||
package org.apache.commons.math4.legacy.core.dfp;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.commons.math4.legacy.RealFieldElement;
|
||||
import org.apache.commons.math4.legacy.core.RealFieldElement;
|
||||
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math4.legacy.util.FastMath;
|
||||
|
||||
/**
|
||||
* Decimal floating point library for Java
|
||||
|
@ -625,12 +624,12 @@ public class Dfp implements RealFieldElement<Dfp> {
|
|||
return field.newDfp(sig, code);
|
||||
}
|
||||
|
||||
/** Get the {@link org.apache.commons.math4.legacy.Field Field} (really a {@link DfpField}) to which the instance belongs.
|
||||
/** Get the {@link org.apache.commons.math4.legacy.core.Field Field} (really a {@link DfpField}) to which the instance belongs.
|
||||
* <p>
|
||||
* The field is linked to the number of digits and acts as a factory
|
||||
* for {@link Dfp} instances.
|
||||
* </p>
|
||||
* @return {@link org.apache.commons.math4.legacy.Field Field} (really a {@link DfpField}) to which the instance belongs
|
||||
* @return {@link org.apache.commons.math4.legacy.core.Field Field} (really a {@link DfpField}) to which the instance belongs
|
||||
*/
|
||||
@Override
|
||||
public DfpField getField() {
|
||||
|
@ -2579,7 +2578,7 @@ public class Dfp implements RealFieldElement<Dfp> {
|
|||
*/
|
||||
@Override
|
||||
public long round() {
|
||||
return FastMath.round(toDouble());
|
||||
return Math.round(toDouble());
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
|
@ -2782,7 +2781,7 @@ public class Dfp implements RealFieldElement<Dfp> {
|
|||
|
||||
// compute atan2(y, x) = +/- pi - 2 atan(y / (r - x))
|
||||
final Dfp tmp = getTwo().multiply(divide(r.subtract(x)).atan());
|
||||
final Dfp pmPi = newInstance((tmp.sign <= 0) ? -FastMath.PI : FastMath.PI);
|
||||
final Dfp pmPi = newInstance((tmp.sign <= 0) ? -Math.PI : Math.PI);
|
||||
return pmPi.subtract(tmp);
|
||||
|
||||
}
|
|
@ -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
|
|
@ -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
|
|
@ -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}
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Decimal floating point library for Java
|
||||
*
|
||||
* <p>Another floating point class. This one is built using radix 10000
|
||||
* which is 10<sup>4</sup>, so its almost decimal.</p>
|
||||
*
|
||||
* <p>The design goals here are:
|
||||
* <ol>
|
||||
* <li>Decimal math, or close to it</li>
|
||||
* <li>Settable precision (but no mix between numbers using different settings)</li>
|
||||
* <li>Portability. Code should be keep as portable as possible.</li>
|
||||
* <li>Performance</li>
|
||||
* <li>Accuracy - Results should always be +/- 1 ULP for basic
|
||||
* algebraic operation</li>
|
||||
* <li>Comply with IEEE 854-1987 as much as possible.
|
||||
* (See IEEE 854-1987 notes below)</li>
|
||||
* </ol>
|
||||
*
|
||||
* <p>Trade offs:
|
||||
* <ol>
|
||||
* <li>Memory foot print. I'm using more memory than necessary to
|
||||
* represent numbers to get better performance.</li>
|
||||
* <li>Digits are bigger, so rounding is a greater loss. So, if you
|
||||
* really need 12 decimal digits, better use 4 base 10000 digits
|
||||
* there can be one partially filled.</li>
|
||||
* </ol>
|
||||
*
|
||||
* <p>Numbers are represented in the following form:
|
||||
* <div style="white-space: pre"><code>
|
||||
* n = sign × mant × (radix)<sup>exp</sup>;
|
||||
* </code></div>
|
||||
* where sign is ±1, mantissa represents a fractional number between
|
||||
* zero and one. mant[0] is the least significant digit.
|
||||
* exp is in the range of -32767 to 32768
|
||||
*
|
||||
* <p>IEEE 854-1987 Notes and differences</p>
|
||||
*
|
||||
* <p>IEEE 854 requires the radix to be either 2 or 10. The radix here is
|
||||
* 10000, so that requirement is not met, but it is possible that a
|
||||
* subclassed can be made to make it behave as a radix 10
|
||||
* number. It is my opinion that if it looks and behaves as a radix
|
||||
* 10 number then it is one and that requirement would be met.</p>
|
||||
*
|
||||
* <p>The radix of 10000 was chosen because it should be faster to operate
|
||||
* on 4 decimal digits at once instead of one at a time. Radix 10 behavior
|
||||
* can be realized by add an additional rounding step to ensure that
|
||||
* the number of decimal digits represented is constant.</p>
|
||||
*
|
||||
* <p>The IEEE standard specifically leaves out internal data encoding,
|
||||
* so it is reasonable to conclude that such a subclass of this radix
|
||||
* 10000 system is merely an encoding of a radix 10 system.</p>
|
||||
*
|
||||
* <p>IEEE 854 also specifies the existence of "sub-normal" numbers. This
|
||||
* class does not contain any such entities. The most significant radix
|
||||
* 10000 digit is always non-zero. Instead, we support "gradual underflow"
|
||||
* by raising the underflow flag for numbers less with exponent less than
|
||||
* expMin, but don't flush to zero until the exponent reaches MIN_EXP-digits.
|
||||
* Thus the smallest number we can represent would be:
|
||||
* 1E(-(MIN_EXP-digits-1)∗4), eg, for digits=5, MIN_EXP=-32767, that would
|
||||
* be 1e-131092.</p>
|
||||
*
|
||||
* <p>IEEE 854 defines that the implied radix point lies just to the right
|
||||
* of the most significant digit and to the left of the remaining digits.
|
||||
* This implementation puts the implied radix point to the left of all
|
||||
* digits including the most significant one. The most significant digit
|
||||
* here is the one just to the right of the radix point. This is a fine
|
||||
* detail and is really only a matter of definition. Any side effects of
|
||||
* this can be rendered invisible by a subclass.</p>
|
||||
*
|
||||
*/
|
||||
package org.apache.commons.math4.legacy.core.dfp;
|
File diff suppressed because it is too large
Load Diff
|
@ -25,36 +25,36 @@ import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
|
|||
/**
|
||||
* Portable alternative to {@link Math} and {@link StrictMath}.
|
||||
* <p>
|
||||
* Caveat: At the time of implementation, the {@code FastMath} functions
|
||||
* Caveat: At the time of implementation, the {@code AccurateMath} functions
|
||||
* were often faster and/or more accurate than their JDK equivalent.
|
||||
* Nowadays, it would not be surprising that they are always slower (due
|
||||
* to the various JVM optimizations that have appeared since Java 5).
|
||||
* However, any change to this class should ensure that the current
|
||||
* accuracy is not lost.
|
||||
* <p>
|
||||
* FastMath is a drop-in replacement for both Math and StrictMath. This
|
||||
* AccurateMath is a drop-in replacement for both Math and StrictMath. This
|
||||
* means that for any method in Math (say {@code Math.sin(x)} or
|
||||
* {@code Math.cbrt(y)}), user can directly change the class and use the
|
||||
* methods as is (using {@code FastMath.sin(x)} or {@code FastMath.cbrt(y)}
|
||||
* methods as is (using {@code AccurateMath.sin(x)} or {@code AccurateMath.cbrt(y)}
|
||||
* in the previous example).
|
||||
* </p>
|
||||
* <p>
|
||||
* FastMath speed is achieved by relying heavily on optimizing compilers
|
||||
* AccurateMath speed is achieved by relying heavily on optimizing compilers
|
||||
* to native code present in many JVMs today and use of large tables.
|
||||
* The larger tables are lazily initialized on first use, so that the setup
|
||||
* time does not penalize methods that don't need them.
|
||||
* </p>
|
||||
* <p>
|
||||
* Note that FastMath is
|
||||
* Note that AccurateMath is
|
||||
* extensively used inside Apache Commons Math, so by calling some algorithms,
|
||||
* the overhead when the tables need to be initialized will occur
|
||||
* regardless of the end-user calling FastMath methods directly or not.
|
||||
* regardless of the end-user calling AccurateMath methods directly or not.
|
||||
* Performance figures for a specific JVM and hardware can be evaluated by
|
||||
* running the FastMathTestPerformance tests in the test directory of the source
|
||||
* running the AccurateMathTestPerformance tests in the test directory of the source
|
||||
* distribution.
|
||||
* </p>
|
||||
* <p>
|
||||
* FastMath accuracy should be mostly independent of the JVM as it relies only
|
||||
* AccurateMath accuracy should be mostly independent of the JVM as it relies only
|
||||
* on IEEE-754 basic operations and on embedded tables. Almost all operations
|
||||
* are accurate to about 0.5 ulp throughout the domain range. This statement,
|
||||
* of course is only a rough global observed behavior, it is <em>not</em> a
|
||||
|
@ -63,14 +63,14 @@ import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
|
|||
* Maker's Dilemma</a>).
|
||||
* </p>
|
||||
* <p>
|
||||
* FastMath additionally implements the following methods not found in Math/StrictMath:
|
||||
* AccurateMath additionally implements the following methods not found in Math/StrictMath:
|
||||
* <ul>
|
||||
* <li>{@link #asinh(double)}</li>
|
||||
* <li>{@link #acosh(double)}</li>
|
||||
* <li>{@link #atanh(double)}</li>
|
||||
* </ul>
|
||||
* The following methods are found in Math/StrictMath since 1.6 only, they are provided
|
||||
* by FastMath even in 1.5 Java virtual machines
|
||||
* by AccurateMath even in 1.5 Java virtual machines
|
||||
* <ul>
|
||||
* <li>{@link #copySign(double, double)}</li>
|
||||
* <li>{@link #getExponent(double)}</li>
|
||||
|
@ -85,7 +85,7 @@ import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
|
|||
* </ul>
|
||||
* @since 2.2
|
||||
*/
|
||||
public class FastMath {
|
||||
public class AccurateMath {
|
||||
/** Archimede's constant PI, ratio of circle circumference to diameter. */
|
||||
public static final double PI = 105414357.0 / 33554432.0 + 1.984187159361080883e-9;
|
||||
|
||||
|
@ -371,7 +371,7 @@ public class FastMath {
|
|||
/**
|
||||
* Private Constructor
|
||||
*/
|
||||
private FastMath() {}
|
||||
private AccurateMath() {}
|
||||
|
||||
// Generic helper methods
|
||||
|
||||
|
@ -723,7 +723,7 @@ public class FastMath {
|
|||
* @return inverse hyperbolic cosine of a
|
||||
*/
|
||||
public static double acosh(final double a) {
|
||||
return FastMath.log(a + FastMath.sqrt(a * a - 1));
|
||||
return AccurateMath.log(a + AccurateMath.sqrt(a * a - 1));
|
||||
}
|
||||
|
||||
/** Compute the inverse hyperbolic sine of a number.
|
||||
|
@ -739,7 +739,7 @@ public class FastMath {
|
|||
|
||||
double absAsinh;
|
||||
if (a > 0.167) {
|
||||
absAsinh = FastMath.log(FastMath.sqrt(a * a + 1) + a);
|
||||
absAsinh = AccurateMath.log(AccurateMath.sqrt(a * a + 1) + a);
|
||||
} else {
|
||||
final double a2 = a * a;
|
||||
if (a > 0.097) {
|
||||
|
@ -769,7 +769,7 @@ public class FastMath {
|
|||
|
||||
double absAtanh;
|
||||
if (a > 0.15) {
|
||||
absAtanh = 0.5 * FastMath.log((1 + a) / (1 - a));
|
||||
absAtanh = 0.5 * AccurateMath.log((1 + a) / (1 - a));
|
||||
} else {
|
||||
final double a2 = a * a;
|
||||
if (a > 0.087) {
|
||||
|
@ -1536,13 +1536,13 @@ public class FastMath {
|
|||
if ((yFullMantissa & integralMask) == yFullMantissa) {
|
||||
// all fractional bits are 0, the number is really integral
|
||||
final long l = yFullMantissa >> (1075 - yRawExp);
|
||||
return FastMath.pow(x, (y < 0) ? -l : l);
|
||||
return AccurateMath.pow(x, (y < 0) ? -l : l);
|
||||
}
|
||||
} else {
|
||||
// normal number with positive shift, always an integral value
|
||||
// we know it fits in a primitive long because yRawExp > 1085 has been handled above
|
||||
final long l = yFullMantissa << (yRawExp - 1075);
|
||||
return FastMath.pow(x, (y < 0) ? -l : l);
|
||||
return AccurateMath.pow(x, (y < 0) ? -l : l);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1754,8 +1754,8 @@ public class FastMath {
|
|||
} else {
|
||||
// some intermediate numbers exceeded capacity,
|
||||
// and the low order bits became NaN (because infinity - infinity = NaN)
|
||||
if (FastMath.abs(full) < 1) {
|
||||
return new Split(FastMath.copySign(0.0, full), 0.0);
|
||||
if (AccurateMath.abs(full) < 1) {
|
||||
return new Split(AccurateMath.copySign(0.0, full), 0.0);
|
||||
} else if (full < 0 && (e & 0x1) == 1) {
|
||||
return Split.NEGATIVE_INFINITY;
|
||||
} else {
|
||||
|
@ -3778,9 +3778,9 @@ public class FastMath {
|
|||
}
|
||||
} else {
|
||||
// we are in the general case
|
||||
final double n = FastMath.rint(dividend / divisor);
|
||||
final double n = AccurateMath.rint(dividend / divisor);
|
||||
final double remainder = Double.isInfinite(n) ? 0.0 : dividend - divisor * n;
|
||||
return (remainder == 0) ? FastMath.copySign(remainder, dividend) : remainder;
|
||||
return (remainder == 0) ? AccurateMath.copySign(remainder, dividend) : remainder;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4174,17 +4174,17 @@ public class FastMath {
|
|||
*/
|
||||
public static void main(String[] a) {
|
||||
PrintStream out = System.out;
|
||||
FastMathCalc.printarray(out, "EXP_INT_TABLE_A", EXP_INT_TABLE_LEN, ExpIntTable.EXP_INT_TABLE_A);
|
||||
FastMathCalc.printarray(out, "EXP_INT_TABLE_B", EXP_INT_TABLE_LEN, ExpIntTable.EXP_INT_TABLE_B);
|
||||
FastMathCalc.printarray(out, "EXP_FRAC_TABLE_A", EXP_FRAC_TABLE_LEN, ExpFracTable.EXP_FRAC_TABLE_A);
|
||||
FastMathCalc.printarray(out, "EXP_FRAC_TABLE_B", EXP_FRAC_TABLE_LEN, ExpFracTable.EXP_FRAC_TABLE_B);
|
||||
FastMathCalc.printarray(out, "LN_MANT",LN_MANT_LEN, lnMant.LN_MANT);
|
||||
FastMathCalc.printarray(out, "SINE_TABLE_A", SINE_TABLE_LEN, SINE_TABLE_A);
|
||||
FastMathCalc.printarray(out, "SINE_TABLE_B", SINE_TABLE_LEN, SINE_TABLE_B);
|
||||
FastMathCalc.printarray(out, "COSINE_TABLE_A", SINE_TABLE_LEN, COSINE_TABLE_A);
|
||||
FastMathCalc.printarray(out, "COSINE_TABLE_B", SINE_TABLE_LEN, COSINE_TABLE_B);
|
||||
FastMathCalc.printarray(out, "TANGENT_TABLE_A", SINE_TABLE_LEN, TANGENT_TABLE_A);
|
||||
FastMathCalc.printarray(out, "TANGENT_TABLE_B", SINE_TABLE_LEN, TANGENT_TABLE_B);
|
||||
AccurateMathCalc.printarray(out, "EXP_INT_TABLE_A", EXP_INT_TABLE_LEN, ExpIntTable.EXP_INT_TABLE_A);
|
||||
AccurateMathCalc.printarray(out, "EXP_INT_TABLE_B", EXP_INT_TABLE_LEN, ExpIntTable.EXP_INT_TABLE_B);
|
||||
AccurateMathCalc.printarray(out, "EXP_FRAC_TABLE_A", EXP_FRAC_TABLE_LEN, ExpFracTable.EXP_FRAC_TABLE_A);
|
||||
AccurateMathCalc.printarray(out, "EXP_FRAC_TABLE_B", EXP_FRAC_TABLE_LEN, ExpFracTable.EXP_FRAC_TABLE_B);
|
||||
AccurateMathCalc.printarray(out, "LN_MANT",LN_MANT_LEN, lnMant.LN_MANT);
|
||||
AccurateMathCalc.printarray(out, "SINE_TABLE_A", SINE_TABLE_LEN, SINE_TABLE_A);
|
||||
AccurateMathCalc.printarray(out, "SINE_TABLE_B", SINE_TABLE_LEN, SINE_TABLE_B);
|
||||
AccurateMathCalc.printarray(out, "COSINE_TABLE_A", SINE_TABLE_LEN, COSINE_TABLE_A);
|
||||
AccurateMathCalc.printarray(out, "COSINE_TABLE_B", SINE_TABLE_LEN, COSINE_TABLE_B);
|
||||
AccurateMathCalc.printarray(out, "TANGENT_TABLE_A", SINE_TABLE_LEN, TANGENT_TABLE_A);
|
||||
AccurateMathCalc.printarray(out, "TANGENT_TABLE_B", SINE_TABLE_LEN, TANGENT_TABLE_B);
|
||||
}
|
||||
|
||||
/** Enclose large data table in nested static class so it's only loaded on first access. */
|
||||
|
@ -4200,28 +4200,28 @@ public class FastMath {
|
|||
|
||||
static {
|
||||
if (RECOMPUTE_TABLES_AT_RUNTIME) {
|
||||
EXP_INT_TABLE_A = new double[FastMath.EXP_INT_TABLE_LEN];
|
||||
EXP_INT_TABLE_B = new double[FastMath.EXP_INT_TABLE_LEN];
|
||||
EXP_INT_TABLE_A = new double[AccurateMath.EXP_INT_TABLE_LEN];
|
||||
EXP_INT_TABLE_B = new double[AccurateMath.EXP_INT_TABLE_LEN];
|
||||
|
||||
final double tmp[] = new double[2];
|
||||
final double recip[] = new double[2];
|
||||
|
||||
// Populate expIntTable
|
||||
for (int i = 0; i < FastMath.EXP_INT_TABLE_MAX_INDEX; i++) {
|
||||
FastMathCalc.expint(i, tmp);
|
||||
EXP_INT_TABLE_A[i + FastMath.EXP_INT_TABLE_MAX_INDEX] = tmp[0];
|
||||
EXP_INT_TABLE_B[i + FastMath.EXP_INT_TABLE_MAX_INDEX] = tmp[1];
|
||||
for (int i = 0; i < AccurateMath.EXP_INT_TABLE_MAX_INDEX; i++) {
|
||||
AccurateMathCalc.expint(i, tmp);
|
||||
EXP_INT_TABLE_A[i + AccurateMath.EXP_INT_TABLE_MAX_INDEX] = tmp[0];
|
||||
EXP_INT_TABLE_B[i + AccurateMath.EXP_INT_TABLE_MAX_INDEX] = tmp[1];
|
||||
|
||||
if (i != 0) {
|
||||
// Negative integer powers
|
||||
FastMathCalc.splitReciprocal(tmp, recip);
|
||||
EXP_INT_TABLE_A[FastMath.EXP_INT_TABLE_MAX_INDEX - i] = recip[0];
|
||||
EXP_INT_TABLE_B[FastMath.EXP_INT_TABLE_MAX_INDEX - i] = recip[1];
|
||||
AccurateMathCalc.splitReciprocal(tmp, recip);
|
||||
EXP_INT_TABLE_A[AccurateMath.EXP_INT_TABLE_MAX_INDEX - i] = recip[0];
|
||||
EXP_INT_TABLE_B[AccurateMath.EXP_INT_TABLE_MAX_INDEX - i] = recip[1];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
EXP_INT_TABLE_A = FastMathLiteralArrays.loadExpIntA();
|
||||
EXP_INT_TABLE_B = FastMathLiteralArrays.loadExpIntB();
|
||||
EXP_INT_TABLE_A = AccurateMathLiteralArrays.loadExpIntA();
|
||||
EXP_INT_TABLE_B = AccurateMathLiteralArrays.loadExpIntB();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4240,21 +4240,21 @@ public class FastMath {
|
|||
|
||||
static {
|
||||
if (RECOMPUTE_TABLES_AT_RUNTIME) {
|
||||
EXP_FRAC_TABLE_A = new double[FastMath.EXP_FRAC_TABLE_LEN];
|
||||
EXP_FRAC_TABLE_B = new double[FastMath.EXP_FRAC_TABLE_LEN];
|
||||
EXP_FRAC_TABLE_A = new double[AccurateMath.EXP_FRAC_TABLE_LEN];
|
||||
EXP_FRAC_TABLE_B = new double[AccurateMath.EXP_FRAC_TABLE_LEN];
|
||||
|
||||
final double tmp[] = new double[2];
|
||||
|
||||
// Populate expFracTable
|
||||
final double factor = 1d / (EXP_FRAC_TABLE_LEN - 1);
|
||||
for (int i = 0; i < EXP_FRAC_TABLE_A.length; i++) {
|
||||
FastMathCalc.slowexp(i * factor, tmp);
|
||||
AccurateMathCalc.slowexp(i * factor, tmp);
|
||||
EXP_FRAC_TABLE_A[i] = tmp[0];
|
||||
EXP_FRAC_TABLE_B[i] = tmp[1];
|
||||
}
|
||||
} else {
|
||||
EXP_FRAC_TABLE_A = FastMathLiteralArrays.loadExpFracA();
|
||||
EXP_FRAC_TABLE_B = FastMathLiteralArrays.loadExpFracB();
|
||||
EXP_FRAC_TABLE_A = AccurateMathLiteralArrays.loadExpFracA();
|
||||
EXP_FRAC_TABLE_B = AccurateMathLiteralArrays.loadExpFracB();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4266,15 +4266,15 @@ public class FastMath {
|
|||
|
||||
static {
|
||||
if (RECOMPUTE_TABLES_AT_RUNTIME) {
|
||||
LN_MANT = new double[FastMath.LN_MANT_LEN][];
|
||||
LN_MANT = new double[AccurateMath.LN_MANT_LEN][];
|
||||
|
||||
// Populate lnMant table
|
||||
for (int i = 0; i < LN_MANT.length; i++) {
|
||||
final double d = Double.longBitsToDouble( (((long) i) << 42) | 0x3ff0000000000000L );
|
||||
LN_MANT[i] = FastMathCalc.slowLog(d);
|
||||
LN_MANT[i] = AccurateMathCalc.slowLog(d);
|
||||
}
|
||||
} else {
|
||||
LN_MANT = FastMathLiteralArrays.loadLnMant();
|
||||
LN_MANT = AccurateMathLiteralArrays.loadLnMant();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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.
|
File diff suppressed because it is too large
Load Diff
|
@ -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".
|
|
@ -14,15 +14,15 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.legacy;
|
||||
package org.apache.commons.math4.legacy.core;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.commons.numbers.arrays.LinearCombination;
|
||||
import org.apache.commons.rng.UniformRandomProvider;
|
||||
import org.apache.commons.rng.simple.RandomSource;
|
||||
import org.apache.commons.math4.legacy.util.FastMath;
|
||||
import org.apache.commons.math4.legacy.util.MathArrays;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
|
||||
|
||||
public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElement<T>> {
|
||||
|
||||
|
@ -113,7 +113,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
|
|||
public void testRemainderField() {
|
||||
for (double x = -3; x < 3; x += 0.2) {
|
||||
for (double y = -3; y < 3; y += 0.2) {
|
||||
checkRelative(FastMath.IEEEremainder(x, y), build(x).remainder(build(y)));
|
||||
checkRelative(AccurateMath.IEEEremainder(x, y), build(x).remainder(build(y)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
|
|||
public void testRemainderDouble() {
|
||||
for (double x = -3; x < 3; x += 0.2) {
|
||||
for (double y = -3.2; y < 3.2; y += 0.25) {
|
||||
checkRelative(FastMath.IEEEremainder(x, y), build(x).remainder(y));
|
||||
checkRelative(AccurateMath.IEEEremainder(x, y), build(x).remainder(y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -130,42 +130,42 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
|
|||
@Test
|
||||
public void testCos() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
checkRelative(FastMath.cos(x), build(x).cos());
|
||||
checkRelative(AccurateMath.cos(x), build(x).cos());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAcos() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
checkRelative(FastMath.acos(x), build(x).acos());
|
||||
checkRelative(AccurateMath.acos(x), build(x).acos());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSin() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
checkRelative(FastMath.sin(x), build(x).sin());
|
||||
checkRelative(AccurateMath.sin(x), build(x).sin());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAsin() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
checkRelative(FastMath.asin(x), build(x).asin());
|
||||
checkRelative(AccurateMath.asin(x), build(x).asin());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTan() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
checkRelative(FastMath.tan(x), build(x).tan());
|
||||
checkRelative(AccurateMath.tan(x), build(x).tan());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAtan() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
checkRelative(FastMath.atan(x), build(x).atan());
|
||||
checkRelative(AccurateMath.atan(x), build(x).atan());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
|
|||
public void testAtan2() {
|
||||
for (double x = -3; x < 3; x += 0.2) {
|
||||
for (double y = -3; y < 3; y += 0.2) {
|
||||
checkRelative(FastMath.atan2(x, y), build(x).atan2(build(y)));
|
||||
checkRelative(AccurateMath.atan2(x, y), build(x).atan2(build(y)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -181,56 +181,56 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
|
|||
@Test
|
||||
public void testCosh() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
checkRelative(FastMath.cosh(x), build(x).cosh());
|
||||
checkRelative(AccurateMath.cosh(x), build(x).cosh());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAcosh() {
|
||||
for (double x = 1.1; x < 5.0; x += 0.05) {
|
||||
checkRelative(FastMath.acosh(x), build(x).acosh());
|
||||
checkRelative(AccurateMath.acosh(x), build(x).acosh());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSinh() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
checkRelative(FastMath.sinh(x), build(x).sinh());
|
||||
checkRelative(AccurateMath.sinh(x), build(x).sinh());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAsinh() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
checkRelative(FastMath.asinh(x), build(x).asinh());
|
||||
checkRelative(AccurateMath.asinh(x), build(x).asinh());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTanh() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
checkRelative(FastMath.tanh(x), build(x).tanh());
|
||||
checkRelative(AccurateMath.tanh(x), build(x).tanh());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAtanh() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
checkRelative(FastMath.atanh(x), build(x).atanh());
|
||||
checkRelative(AccurateMath.atanh(x), build(x).atanh());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSqrt() {
|
||||
for (double x = 0.01; x < 0.9; x += 0.05) {
|
||||
checkRelative(FastMath.sqrt(x), build(x).sqrt());
|
||||
checkRelative(AccurateMath.sqrt(x), build(x).sqrt());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCbrt() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
checkRelative(FastMath.cbrt(x), build(x).cbrt());
|
||||
checkRelative(AccurateMath.cbrt(x), build(x).cbrt());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -238,7 +238,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
|
|||
public void testHypot() {
|
||||
for (double x = -3; x < 3; x += 0.2) {
|
||||
for (double y = -3; y < 3; y += 0.2) {
|
||||
checkRelative(FastMath.hypot(x, y), build(x).hypot(build(y)));
|
||||
checkRelative(AccurateMath.hypot(x, y), build(x).hypot(build(y)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -249,10 +249,10 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
|
|||
for (int n = 1; n < 5; ++n) {
|
||||
if (x < 0) {
|
||||
if (n % 2 == 1) {
|
||||
checkRelative(-FastMath.pow(-x, 1.0 / n), build(x).rootN(n));
|
||||
checkRelative(-AccurateMath.pow(-x, 1.0 / n), build(x).rootN(n));
|
||||
}
|
||||
} else {
|
||||
checkRelative(FastMath.pow(x, 1.0 / n), build(x).rootN(n));
|
||||
checkRelative(AccurateMath.pow(x, 1.0 / n), build(x).rootN(n));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -262,7 +262,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
|
|||
public void testPowField() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
for (double y = 0.1; y < 4; y += 0.2) {
|
||||
checkRelative(FastMath.pow(x, y), build(x).pow(build(y)));
|
||||
checkRelative(AccurateMath.pow(x, y), build(x).pow(build(y)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -271,7 +271,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
|
|||
public void testPowDouble() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
for (double y = 0.1; y < 4; y += 0.2) {
|
||||
checkRelative(FastMath.pow(x, y), build(x).pow(y));
|
||||
checkRelative(AccurateMath.pow(x, y), build(x).pow(y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -280,7 +280,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
|
|||
public void testPowInt() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
for (int n = 0; n < 5; ++n) {
|
||||
checkRelative(FastMath.pow(x, n), build(x).pow(n));
|
||||
checkRelative(AccurateMath.pow(x, n), build(x).pow(n));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -288,28 +288,28 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
|
|||
@Test
|
||||
public void testExp() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
checkRelative(FastMath.exp(x), build(x).exp());
|
||||
checkRelative(AccurateMath.exp(x), build(x).exp());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExpm1() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
checkRelative(FastMath.expm1(x), build(x).expm1());
|
||||
checkRelative(AccurateMath.expm1(x), build(x).expm1());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLog() {
|
||||
for (double x = 0.01; x < 0.9; x += 0.05) {
|
||||
checkRelative(FastMath.log(x), build(x).log());
|
||||
checkRelative(AccurateMath.log(x), build(x).log());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLog1p() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
checkRelative(FastMath.log1p(x), build(x).log1p());
|
||||
checkRelative(AccurateMath.log1p(x), build(x).log1p());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -318,49 +318,49 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
|
|||
// @Test
|
||||
// public void testLog10() {
|
||||
// for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
// checkRelative(FastMath.log10(x), build(x).log10());
|
||||
// checkRelative(AccurateMath.log10(x), build(x).log10());
|
||||
// }
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void testAbs() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
checkRelative(FastMath.abs(x), build(x).abs());
|
||||
checkRelative(AccurateMath.abs(x), build(x).abs());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCeil() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
checkRelative(FastMath.ceil(x), build(x).ceil());
|
||||
checkRelative(AccurateMath.ceil(x), build(x).ceil());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFloor() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
checkRelative(FastMath.floor(x), build(x).floor());
|
||||
checkRelative(AccurateMath.floor(x), build(x).floor());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRint() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
checkRelative(FastMath.rint(x), build(x).rint());
|
||||
checkRelative(AccurateMath.rint(x), build(x).rint());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRound() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
Assert.assertEquals(FastMath.round(x), build(x).round());
|
||||
Assert.assertEquals(AccurateMath.round(x), build(x).round());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSignum() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
checkRelative(FastMath.signum(x), build(x).signum());
|
||||
checkRelative(AccurateMath.signum(x), build(x).signum());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -368,7 +368,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
|
|||
public void testCopySignField() {
|
||||
for (double x = -3; x < 3; x += 0.2) {
|
||||
for (double y = -3; y < 3; y += 0.2) {
|
||||
checkRelative(FastMath.copySign(x, y), build(x).copySign(build(y)));
|
||||
checkRelative(AccurateMath.copySign(x, y), build(x).copySign(build(y)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -377,7 +377,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
|
|||
public void testCopySignDouble() {
|
||||
for (double x = -3; x < 3; x += 0.2) {
|
||||
for (double y = -3; y < 3; y += 0.2) {
|
||||
checkRelative(FastMath.copySign(x, y), build(x).copySign(y));
|
||||
checkRelative(AccurateMath.copySign(x, y), build(x).copySign(y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -386,7 +386,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
|
|||
public void testScalb() {
|
||||
for (double x = -0.9; x < 0.9; x += 0.05) {
|
||||
for (int n = -100; n < 100; ++n) {
|
||||
checkRelative(FastMath.scalb(x, n), build(x).scalb(n));
|
||||
checkRelative(AccurateMath.scalb(x, n), build(x).scalb(n));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -498,7 +498,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
|
|||
}
|
||||
|
||||
private void checkRelative(double expected, T obtained) {
|
||||
Assert.assertEquals(expected, obtained.getReal(), 1.0e-15 * (1 + FastMath.abs(expected)));
|
||||
Assert.assertEquals(expected, obtained.getReal(), 1.0e-15 * (1 + AccurateMath.abs(expected)));
|
||||
}
|
||||
|
||||
@Test
|
|
@ -11,11 +11,14 @@
|
|||
* KIND, either express or implied. See the License for the specific language
|
||||
* governing permissions and limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math4.legacy.util;
|
||||
package org.apache.commons.math4.legacy.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.commons.math4.legacy.TestUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.commons.numbers.core.Precision;
|
||||
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math4.legacy.exception.MathArithmeticException;
|
||||
import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException;
|
||||
|
@ -25,13 +28,10 @@ import org.apache.commons.math4.legacy.exception.NotANumberException;
|
|||
import org.apache.commons.math4.legacy.exception.NotPositiveException;
|
||||
import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException;
|
||||
import org.apache.commons.math4.legacy.exception.NullArgumentException;
|
||||
import org.apache.commons.numbers.core.Precision;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
|
||||
|
||||
/**
|
||||
* Test cases for the {@link MathArrays} class.
|
||||
*
|
||||
*/
|
||||
public class MathArraysTest {
|
||||
|
||||
|
@ -390,7 +390,7 @@ public class MathArraysTest {
|
|||
-Double.MAX_VALUE,
|
||||
-1, 0,
|
||||
Double.MIN_VALUE,
|
||||
FastMath.ulp(1d),
|
||||
AccurateMath.ulp(1d),
|
||||
1, 3, 113, 4769,
|
||||
Double.MAX_VALUE,
|
||||
Double.POSITIVE_INFINITY };
|
||||
|
@ -399,7 +399,7 @@ public class MathArraysTest {
|
|||
-Double.MAX_VALUE,
|
||||
-1, 0,
|
||||
Double.MIN_VALUE,
|
||||
FastMath.ulp(1d),
|
||||
AccurateMath.ulp(1d),
|
||||
1, 3, 113, 4769,
|
||||
Double.MAX_VALUE,
|
||||
Double.POSITIVE_INFINITY,
|
||||
|
@ -445,25 +445,25 @@ public class MathArraysTest {
|
|||
|
||||
MathArrays.sortInPlace(x1, x2, x3);
|
||||
|
||||
Assert.assertEquals(-3, x1[0], FastMath.ulp(1d));
|
||||
Assert.assertEquals(9, x2[0], FastMath.ulp(1d));
|
||||
Assert.assertEquals(-27, x3[0], FastMath.ulp(1d));
|
||||
Assert.assertEquals(-3, x1[0], AccurateMath.ulp(1d));
|
||||
Assert.assertEquals(9, x2[0], AccurateMath.ulp(1d));
|
||||
Assert.assertEquals(-27, x3[0], AccurateMath.ulp(1d));
|
||||
|
||||
Assert.assertEquals(1, x1[1], FastMath.ulp(1d));
|
||||
Assert.assertEquals(1, x2[1], FastMath.ulp(1d));
|
||||
Assert.assertEquals(1, x3[1], FastMath.ulp(1d));
|
||||
Assert.assertEquals(1, x1[1], AccurateMath.ulp(1d));
|
||||
Assert.assertEquals(1, x2[1], AccurateMath.ulp(1d));
|
||||
Assert.assertEquals(1, x3[1], AccurateMath.ulp(1d));
|
||||
|
||||
Assert.assertEquals(2, x1[2], FastMath.ulp(1d));
|
||||
Assert.assertEquals(4, x2[2], FastMath.ulp(1d));
|
||||
Assert.assertEquals(8, x3[2], FastMath.ulp(1d));
|
||||
Assert.assertEquals(2, x1[2], AccurateMath.ulp(1d));
|
||||
Assert.assertEquals(4, x2[2], AccurateMath.ulp(1d));
|
||||
Assert.assertEquals(8, x3[2], AccurateMath.ulp(1d));
|
||||
|
||||
Assert.assertEquals(4, x1[3], FastMath.ulp(1d));
|
||||
Assert.assertEquals(16, x2[3], FastMath.ulp(1d));
|
||||
Assert.assertEquals(64, x3[3], FastMath.ulp(1d));
|
||||
Assert.assertEquals(4, x1[3], AccurateMath.ulp(1d));
|
||||
Assert.assertEquals(16, x2[3], AccurateMath.ulp(1d));
|
||||
Assert.assertEquals(64, x3[3], AccurateMath.ulp(1d));
|
||||
|
||||
Assert.assertEquals(5, x1[4], FastMath.ulp(1d));
|
||||
Assert.assertEquals(25, x2[4], FastMath.ulp(1d));
|
||||
Assert.assertEquals(125, x3[4], FastMath.ulp(1d));
|
||||
Assert.assertEquals(5, x1[4], AccurateMath.ulp(1d));
|
||||
Assert.assertEquals(25, x2[4], AccurateMath.ulp(1d));
|
||||
Assert.assertEquals(125, x3[4], AccurateMath.ulp(1d));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -476,25 +476,25 @@ public class MathArraysTest {
|
|||
MathArrays.OrderDirection.DECREASING,
|
||||
x2, x3);
|
||||
|
||||
Assert.assertEquals(-3, x1[4], FastMath.ulp(1d));
|
||||
Assert.assertEquals(9, x2[4], FastMath.ulp(1d));
|
||||
Assert.assertEquals(-27, x3[4], FastMath.ulp(1d));
|
||||
Assert.assertEquals(-3, x1[4], AccurateMath.ulp(1d));
|
||||
Assert.assertEquals(9, x2[4], AccurateMath.ulp(1d));
|
||||
Assert.assertEquals(-27, x3[4], AccurateMath.ulp(1d));
|
||||
|
||||
Assert.assertEquals(1, x1[3], FastMath.ulp(1d));
|
||||
Assert.assertEquals(1, x2[3], FastMath.ulp(1d));
|
||||
Assert.assertEquals(1, x3[3], FastMath.ulp(1d));
|
||||
Assert.assertEquals(1, x1[3], AccurateMath.ulp(1d));
|
||||
Assert.assertEquals(1, x2[3], AccurateMath.ulp(1d));
|
||||
Assert.assertEquals(1, x3[3], AccurateMath.ulp(1d));
|
||||
|
||||
Assert.assertEquals(2, x1[2], FastMath.ulp(1d));
|
||||
Assert.assertEquals(4, x2[2], FastMath.ulp(1d));
|
||||
Assert.assertEquals(8, x3[2], FastMath.ulp(1d));
|
||||
Assert.assertEquals(2, x1[2], AccurateMath.ulp(1d));
|
||||
Assert.assertEquals(4, x2[2], AccurateMath.ulp(1d));
|
||||
Assert.assertEquals(8, x3[2], AccurateMath.ulp(1d));
|
||||
|
||||
Assert.assertEquals(4, x1[1], FastMath.ulp(1d));
|
||||
Assert.assertEquals(16, x2[1], FastMath.ulp(1d));
|
||||
Assert.assertEquals(64, x3[1], FastMath.ulp(1d));
|
||||
Assert.assertEquals(4, x1[1], AccurateMath.ulp(1d));
|
||||
Assert.assertEquals(16, x2[1], AccurateMath.ulp(1d));
|
||||
Assert.assertEquals(64, x3[1], AccurateMath.ulp(1d));
|
||||
|
||||
Assert.assertEquals(5, x1[0], FastMath.ulp(1d));
|
||||
Assert.assertEquals(25, x2[0], FastMath.ulp(1d));
|
||||
Assert.assertEquals(125, x3[0], FastMath.ulp(1d));
|
||||
Assert.assertEquals(5, x1[0], AccurateMath.ulp(1d));
|
||||
Assert.assertEquals(25, x2[0], AccurateMath.ulp(1d));
|
||||
Assert.assertEquals(125, x3[0], AccurateMath.ulp(1d));
|
||||
}
|
||||
|
||||
/** Example in javadoc */
|
||||
|
@ -555,7 +555,7 @@ public class MathArraysTest {
|
|||
Assert.assertFalse(MathArrays.equals(new double[] { Double.POSITIVE_INFINITY },
|
||||
new double[] { Double.NEGATIVE_INFINITY }));
|
||||
Assert.assertFalse(MathArrays.equals(new double[] { 1d },
|
||||
new double[] { FastMath.nextAfter(FastMath.nextAfter(1d, 2d), 2d) }));
|
||||
new double[] { AccurateMath.nextAfter(AccurateMath.nextAfter(1d, 2d), 2d) }));
|
||||
|
||||
}
|
||||
|
||||
|
@ -574,26 +574,26 @@ public class MathArraysTest {
|
|||
Assert.assertFalse(MathArrays.equalsIncludingNaN(new double[] { Double.POSITIVE_INFINITY },
|
||||
new double[] { Double.NEGATIVE_INFINITY }));
|
||||
Assert.assertFalse(MathArrays.equalsIncludingNaN(new double[] { 1d },
|
||||
new double[] { FastMath.nextAfter(FastMath.nextAfter(1d, 2d), 2d) }));
|
||||
new double[] { AccurateMath.nextAfter(AccurateMath.nextAfter(1d, 2d), 2d) }));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalizeArray() {
|
||||
double[] testValues1 = new double[] {1, 1, 2};
|
||||
TestUtils.assertEquals( new double[] {.25, .25, .5},
|
||||
MathArrays.normalizeArray(testValues1, 1),
|
||||
Double.MIN_VALUE);
|
||||
Assert.assertArrayEquals(new double[] {.25, .25, .5},
|
||||
MathArrays.normalizeArray(testValues1, 1),
|
||||
Double.MIN_VALUE);
|
||||
|
||||
double[] testValues2 = new double[] {-1, -1, 1};
|
||||
TestUtils.assertEquals( new double[] {1, 1, -1},
|
||||
MathArrays.normalizeArray(testValues2, 1),
|
||||
Double.MIN_VALUE);
|
||||
Assert.assertArrayEquals(new double[] {1, 1, -1},
|
||||
MathArrays.normalizeArray(testValues2, 1),
|
||||
Double.MIN_VALUE);
|
||||
|
||||
// Ignore NaNs
|
||||
double[] testValues3 = new double[] {-1, -1, Double.NaN, 1, Double.NaN};
|
||||
TestUtils.assertEquals( new double[] {1, 1,Double.NaN, -1, Double.NaN},
|
||||
MathArrays.normalizeArray(testValues3, 1),
|
||||
Double.MIN_VALUE);
|
||||
Assert.assertArrayEquals(new double[] {1, 1,Double.NaN, -1, Double.NaN},
|
||||
MathArrays.normalizeArray(testValues3, 1),
|
||||
Double.MIN_VALUE);
|
||||
|
||||
// Zero sum -> MathArithmeticException
|
||||
double[] zeroSum = new double[] {-1, 1};
|
|
@ -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 {
|
||||
|
|
@ -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;
|
|
@ -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;
|
|
@ -15,10 +15,10 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.commons.math4.legacy.dfp;
|
||||
package org.apache.commons.math4.legacy.core.dfp;
|
||||
|
||||
import org.apache.commons.math4.legacy.ExtendedFieldElementAbstractTest;
|
||||
import org.apache.commons.math4.legacy.util.FastMath;
|
||||
import org.apache.commons.math4.legacy.core.ExtendedFieldElementAbstractTest;
|
||||
import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
|
||||
import org.apache.commons.numbers.core.Precision;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
|
@ -1566,8 +1566,8 @@ public class DfpTest extends ExtendedFieldElementAbstractTest<Dfp> {
|
|||
DfpField field = new DfpField(100);
|
||||
Assert.assertEquals(0.0, field.getZero().toDouble(), Precision.SAFE_MIN);
|
||||
Assert.assertEquals(0.0, field.newDfp(0.0).toDouble(), Precision.SAFE_MIN);
|
||||
Assert.assertEquals(-1, FastMath.copySign(1, field.newDfp(-0.0).toDouble()), Precision.EPSILON);
|
||||
Assert.assertEquals(+1, FastMath.copySign(1, field.newDfp(+0.0).toDouble()), Precision.EPSILON);
|
||||
Assert.assertEquals(-1, AccurateMath.copySign(1, field.newDfp(-0.0).toDouble()), Precision.EPSILON);
|
||||
Assert.assertEquals(+1, AccurateMath.copySign(1, field.newDfp(+0.0).toDouble()), Precision.EPSILON);
|
||||
}
|
||||
|
||||
@Test
|
File diff suppressed because it is too large
Load Diff
|
@ -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.
|
||||
* <p>
|
||||
* Running all tests independently: <br>
|
||||
* {@code mvn test -Dtest=AccurateMathStrictComparisonTest}<br>
|
||||
* or just run tests against a single method (e.g. scalb):<br>
|
||||
* {@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<Object[]> data() throws Exception {
|
||||
String singleMethod = System.getProperty("testMethod");
|
||||
List<Object[]> 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;
|
||||
}
|
||||
}
|
|
@ -33,16 +33,16 @@ import org.junit.runners.Parameterized;
|
|||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
/**
|
||||
* Test to compare FastMath results against StrictMath results for boundary values.
|
||||
* Test to compare AccurateMath results against StrictMath results for boundary values.
|
||||
* <p>
|
||||
* Running all tests independently: <br>
|
||||
* {@code mvn test -Dtest=FastMathStrictComparisonTest}<br>
|
||||
* {@code mvn test -Dtest=AccurateMathStrictComparisonTest}<br>
|
||||
* or just run tests against a single method (e.g. scalb):<br>
|
||||
* {@code mvn test -Dtest=FastMathStrictComparisonTest -DargLine="-DtestMethod=scalb"}
|
||||
* {@code mvn test -Dtest=AccurateMathStrictComparisonTest -DargLine="-DtestMethod=scalb"}
|
||||
*/
|
||||
@SuppressWarnings("boxing")
|
||||
@RunWith(Parameterized.class)
|
||||
public class FastMathStrictComparisonTest {
|
||||
public class AccurateMathStrictComparisonTest {
|
||||
|
||||
// Values which often need special handling
|
||||
private static final Double[] DOUBLE_SPECIAL_VALUES = {
|
||||
|
@ -79,7 +79,7 @@ public class FastMathStrictComparisonTest {
|
|||
private final Type[] types;
|
||||
private final Object[][] valueArrays;
|
||||
|
||||
public FastMathStrictComparisonTest(Method m, Method f, Type[] types, Object[][] data) throws Exception{
|
||||
public AccurateMathStrictComparisonTest(Method m, Method f, Type[] types, Object[][] data) throws Exception{
|
||||
this.mathMethod=m;
|
||||
this.fastMethod=f;
|
||||
this.types=types;
|
||||
|
@ -218,8 +218,8 @@ public class FastMathStrictComparisonTest {
|
|||
Type []types = mathMethod.getGenericParameterTypes();
|
||||
if (types.length >=1) { // Only check methods with at least one parameter
|
||||
try {
|
||||
// Get the corresponding FastMath method
|
||||
Method fastMethod = FastMath.class.getDeclaredMethod(mathMethod.getName(), (Class[]) types);
|
||||
// Get the corresponding AccurateMath method
|
||||
Method fastMethod = AccurateMath.class.getDeclaredMethod(mathMethod.getName(), (Class[]) types);
|
||||
if (Modifier.isPublic(fastMethod.getModifiers())) { // It must be public too
|
||||
if (singleMethod != null && !fastMethod.getName().equals(singleMethod)) {
|
||||
break method;
|
||||
|
@ -249,10 +249,10 @@ public class FastMathStrictComparisonTest {
|
|||
list.add(new Object[]{mathMethod, fastMethod, types, values});
|
||||
// setupMethodCall(mathMethod, fastMethod, params, data);
|
||||
} else {
|
||||
System.out.println("Cannot find public FastMath method corresponding to: "+mathMethod);
|
||||
System.out.println("Cannot find public AccurateMath method corresponding to: "+mathMethod);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
System.out.println("Cannot find FastMath method corresponding to: "+mathMethod);
|
||||
System.out.println("Cannot find AccurateMath method corresponding to: "+mathMethod);
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -116,12 +116,12 @@
|
|||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-rng-sampling</artifactId>
|
||||
<artifactId>commons-math4-legacy-exception</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-math4-legacy-exception</artifactId>
|
||||
<artifactId>commons-math4-legacy-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.apache.commons.math4.legacy.exception.MathInternalError;
|
|||
import org.apache.commons.math4.legacy.exception.NotPositiveException;
|
||||
import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
|
||||
import org.apache.commons.numbers.combinatorics.FactorialDouble;
|
||||
import org.apache.commons.math4.legacy.util.FastMath;
|
||||
import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
|
||||
|
||||
/** Class holding "compiled" computation rules for derivative structures.
|
||||
* <p>This class implements the computation rules described in Dan Kalman's paper <a
|
||||
|
@ -199,8 +199,8 @@ public class DSCompiler {
|
|||
}
|
||||
|
||||
// we need to create more compilers
|
||||
final int maxParameters = FastMath.max(parameters, cache == null ? 0 : cache.length);
|
||||
final int maxOrder = FastMath.max(order, cache == null ? 0 : cache[0].length);
|
||||
final int maxParameters = AccurateMath.max(parameters, cache == null ? 0 : cache.length);
|
||||
final int maxOrder = AccurateMath.max(order, cache == null ? 0 : cache[0].length);
|
||||
final DSCompiler[][] newCache = new DSCompiler[maxParameters + 1][maxOrder + 1];
|
||||
|
||||
if (cache != null) {
|
||||
|
@ -212,7 +212,7 @@ public class DSCompiler {
|
|||
|
||||
// create the array in increasing diagonal order
|
||||
for (int diag = 0; diag <= parameters + order; ++diag) {
|
||||
for (int o = FastMath.max(0, diag - parameters); o <= FastMath.min(order, diag); ++o) {
|
||||
for (int o = AccurateMath.max(0, diag - parameters); o <= AccurateMath.min(order, diag); ++o) {
|
||||
final int p = diag - o;
|
||||
if (newCache[p][o] == null) {
|
||||
final DSCompiler valueCompiler = (p == 0) ? null : newCache[p - 1][o];
|
||||
|
@ -610,7 +610,7 @@ public class DSCompiler {
|
|||
final int destP, final int destO, final int[][] destSizes)
|
||||
throws NumberIsTooLargeException {
|
||||
int[] orders = new int[destP];
|
||||
System.arraycopy(srcDerivativesIndirection[index], 0, orders, 0, FastMath.min(srcP, destP));
|
||||
System.arraycopy(srcDerivativesIndirection[index], 0, orders, 0, AccurateMath.min(srcP, destP));
|
||||
return getPartialDerivativeIndex(destP, destO, destSizes, orders);
|
||||
}
|
||||
|
||||
|
@ -821,8 +821,8 @@ public class DSCompiler {
|
|||
final double[] result, final int resultOffset) {
|
||||
|
||||
// compute k such that lhs % rhs = lhs - k rhs
|
||||
final double rem = FastMath.IEEEremainder(lhs[lhsOffset], rhs[rhsOffset]);
|
||||
final double k = FastMath.rint((lhs[lhsOffset] - rem) / rhs[rhsOffset]);
|
||||
final double rem = AccurateMath.IEEEremainder(lhs[lhsOffset], rhs[rhsOffset]);
|
||||
final double k = AccurateMath.rint((lhs[lhsOffset] - rem) / rhs[rhsOffset]);
|
||||
|
||||
// set up value
|
||||
result[resultOffset] = rem;
|
||||
|
@ -863,8 +863,8 @@ public class DSCompiler {
|
|||
Arrays.fill(function, Double.NaN);
|
||||
}
|
||||
} else {
|
||||
function[0] = FastMath.pow(a, operand[operandOffset]);
|
||||
final double lnA = FastMath.log(a);
|
||||
function[0] = AccurateMath.pow(a, operand[operandOffset]);
|
||||
final double lnA = AccurateMath.log(a);
|
||||
for (int i = 1; i < function.length; ++i) {
|
||||
function[i] = lnA * function[i - 1];
|
||||
}
|
||||
|
@ -904,7 +904,7 @@ public class DSCompiler {
|
|||
// create the function value and derivatives
|
||||
// [x^p, px^(p-1), p(p-1)x^(p-2), ... ]
|
||||
double[] function = new double[1 + order];
|
||||
double xk = FastMath.pow(operand[operandOffset], p - order);
|
||||
double xk = AccurateMath.pow(operand[operandOffset], p - order);
|
||||
for (int i = order; i > 0; --i) {
|
||||
function[i] = xk;
|
||||
xk *= operand[operandOffset];
|
||||
|
@ -946,8 +946,8 @@ public class DSCompiler {
|
|||
|
||||
if (n > 0) {
|
||||
// strictly positive power
|
||||
final int maxOrder = FastMath.min(order, n);
|
||||
double xk = FastMath.pow(operand[operandOffset], n - maxOrder);
|
||||
final int maxOrder = AccurateMath.min(order, n);
|
||||
double xk = AccurateMath.pow(operand[operandOffset], n - maxOrder);
|
||||
for (int i = maxOrder; i > 0; --i) {
|
||||
function[i] = xk;
|
||||
xk *= operand[operandOffset];
|
||||
|
@ -956,7 +956,7 @@ public class DSCompiler {
|
|||
} else {
|
||||
// strictly negative power
|
||||
final double inv = 1.0 / operand[operandOffset];
|
||||
double xk = FastMath.pow(inv, -n);
|
||||
double xk = AccurateMath.pow(inv, -n);
|
||||
for (int i = 0; i <= order; ++i) {
|
||||
function[i] = xk;
|
||||
xk *= inv;
|
||||
|
@ -1011,14 +1011,14 @@ public class DSCompiler {
|
|||
double[] function = new double[1 + order];
|
||||
double xk;
|
||||
if (n == 2) {
|
||||
function[0] = FastMath.sqrt(operand[operandOffset]);
|
||||
function[0] = AccurateMath.sqrt(operand[operandOffset]);
|
||||
xk = 0.5 / function[0];
|
||||
} else if (n == 3) {
|
||||
function[0] = FastMath.cbrt(operand[operandOffset]);
|
||||
function[0] = AccurateMath.cbrt(operand[operandOffset]);
|
||||
xk = 1.0 / (3.0 * function[0] * function[0]);
|
||||
} else {
|
||||
function[0] = FastMath.pow(operand[operandOffset], 1.0 / n);
|
||||
xk = 1.0 / (n * FastMath.pow(function[0], n - 1));
|
||||
function[0] = AccurateMath.pow(operand[operandOffset], 1.0 / n);
|
||||
xk = 1.0 / (n * AccurateMath.pow(function[0], n - 1));
|
||||
}
|
||||
final double nReciprocal = 1.0 / n;
|
||||
final double xReciprocal = 1.0 / operand[operandOffset];
|
||||
|
@ -1045,7 +1045,7 @@ public class DSCompiler {
|
|||
|
||||
// create the function value and derivatives
|
||||
double[] function = new double[1 + order];
|
||||
Arrays.fill(function, FastMath.exp(operand[operandOffset]));
|
||||
Arrays.fill(function, AccurateMath.exp(operand[operandOffset]));
|
||||
|
||||
// apply function composition
|
||||
compose(operand, operandOffset, function, result, resultOffset);
|
||||
|
@ -1065,8 +1065,8 @@ public class DSCompiler {
|
|||
|
||||
// create the function value and derivatives
|
||||
double[] function = new double[1 + order];
|
||||
function[0] = FastMath.expm1(operand[operandOffset]);
|
||||
Arrays.fill(function, 1, 1 + order, FastMath.exp(operand[operandOffset]));
|
||||
function[0] = AccurateMath.expm1(operand[operandOffset]);
|
||||
Arrays.fill(function, 1, 1 + order, AccurateMath.exp(operand[operandOffset]));
|
||||
|
||||
// apply function composition
|
||||
compose(operand, operandOffset, function, result, resultOffset);
|
||||
|
@ -1086,7 +1086,7 @@ public class DSCompiler {
|
|||
|
||||
// create the function value and derivatives
|
||||
double[] function = new double[1 + order];
|
||||
function[0] = FastMath.log(operand[operandOffset]);
|
||||
function[0] = AccurateMath.log(operand[operandOffset]);
|
||||
if (order > 0) {
|
||||
double inv = 1.0 / operand[operandOffset];
|
||||
double xk = inv;
|
||||
|
@ -1113,7 +1113,7 @@ public class DSCompiler {
|
|||
|
||||
// create the function value and derivatives
|
||||
double[] function = new double[1 + order];
|
||||
function[0] = FastMath.log1p(operand[operandOffset]);
|
||||
function[0] = AccurateMath.log1p(operand[operandOffset]);
|
||||
if (order > 0) {
|
||||
double inv = 1.0 / (1.0 + operand[operandOffset]);
|
||||
double xk = inv;
|
||||
|
@ -1140,10 +1140,10 @@ public class DSCompiler {
|
|||
|
||||
// create the function value and derivatives
|
||||
double[] function = new double[1 + order];
|
||||
function[0] = FastMath.log10(operand[operandOffset]);
|
||||
function[0] = AccurateMath.log10(operand[operandOffset]);
|
||||
if (order > 0) {
|
||||
double inv = 1.0 / operand[operandOffset];
|
||||
double xk = inv / FastMath.log(10.0);
|
||||
double xk = inv / AccurateMath.log(10.0);
|
||||
for (int i = 1; i <= order; ++i) {
|
||||
function[i] = xk;
|
||||
xk *= -i * inv;
|
||||
|
@ -1168,9 +1168,9 @@ public class DSCompiler {
|
|||
|
||||
// create the function value and derivatives
|
||||
double[] function = new double[1 + order];
|
||||
function[0] = FastMath.cos(operand[operandOffset]);
|
||||
function[0] = AccurateMath.cos(operand[operandOffset]);
|
||||
if (order > 0) {
|
||||
function[1] = -FastMath.sin(operand[operandOffset]);
|
||||
function[1] = -AccurateMath.sin(operand[operandOffset]);
|
||||
for (int i = 2; i <= order; ++i) {
|
||||
function[i] = -function[i - 2];
|
||||
}
|
||||
|
@ -1194,9 +1194,9 @@ public class DSCompiler {
|
|||
|
||||
// create the function value and derivatives
|
||||
double[] function = new double[1 + order];
|
||||
function[0] = FastMath.sin(operand[operandOffset]);
|
||||
function[0] = AccurateMath.sin(operand[operandOffset]);
|
||||
if (order > 0) {
|
||||
function[1] = FastMath.cos(operand[operandOffset]);
|
||||
function[1] = AccurateMath.cos(operand[operandOffset]);
|
||||
for (int i = 2; i <= order; ++i) {
|
||||
function[i] = -function[i - 2];
|
||||
}
|
||||
|
@ -1220,7 +1220,7 @@ public class DSCompiler {
|
|||
|
||||
// create the function value and derivatives
|
||||
final double[] function = new double[1 + order];
|
||||
final double t = FastMath.tan(operand[operandOffset]);
|
||||
final double t = AccurateMath.tan(operand[operandOffset]);
|
||||
function[0] = t;
|
||||
|
||||
if (order > 0) {
|
||||
|
@ -1276,7 +1276,7 @@ public class DSCompiler {
|
|||
// create the function value and derivatives
|
||||
double[] function = new double[1 + order];
|
||||
final double x = operand[operandOffset];
|
||||
function[0] = FastMath.acos(x);
|
||||
function[0] = AccurateMath.acos(x);
|
||||
if (order > 0) {
|
||||
// the nth order derivative of acos has the form:
|
||||
// dn(acos(x)/dxn = P_n(x) / [1 - x^2]^((2n-1)/2)
|
||||
|
@ -1289,7 +1289,7 @@ public class DSCompiler {
|
|||
p[0] = -1;
|
||||
final double x2 = x * x;
|
||||
final double f = 1.0 / (1 - x2);
|
||||
double coeff = FastMath.sqrt(f);
|
||||
double coeff = AccurateMath.sqrt(f);
|
||||
function[1] = coeff * p[0];
|
||||
for (int n = 2; n <= order; ++n) {
|
||||
|
||||
|
@ -1333,7 +1333,7 @@ public class DSCompiler {
|
|||
// create the function value and derivatives
|
||||
double[] function = new double[1 + order];
|
||||
final double x = operand[operandOffset];
|
||||
function[0] = FastMath.asin(x);
|
||||
function[0] = AccurateMath.asin(x);
|
||||
if (order > 0) {
|
||||
// the nth order derivative of asin has the form:
|
||||
// dn(asin(x)/dxn = P_n(x) / [1 - x^2]^((2n-1)/2)
|
||||
|
@ -1346,7 +1346,7 @@ public class DSCompiler {
|
|||
p[0] = 1;
|
||||
final double x2 = x * x;
|
||||
final double f = 1.0 / (1 - x2);
|
||||
double coeff = FastMath.sqrt(f);
|
||||
double coeff = AccurateMath.sqrt(f);
|
||||
function[1] = coeff * p[0];
|
||||
for (int n = 2; n <= order; ++n) {
|
||||
|
||||
|
@ -1390,7 +1390,7 @@ public class DSCompiler {
|
|||
// create the function value and derivatives
|
||||
double[] function = new double[1 + order];
|
||||
final double x = operand[operandOffset];
|
||||
function[0] = FastMath.atan(x);
|
||||
function[0] = AccurateMath.atan(x);
|
||||
if (order > 0) {
|
||||
// the nth order derivative of atan has the form:
|
||||
// dn(atan(x)/dxn = Q_n(x) / (1 + x^2)^n
|
||||
|
@ -1472,7 +1472,7 @@ public class DSCompiler {
|
|||
divide(y, yOffset, tmp2, 0, tmp1, 0); // y /(r - x)
|
||||
atan(tmp1, 0, tmp2, 0); // atan(y / (r - x))
|
||||
result[resultOffset] =
|
||||
((tmp2[0] <= 0) ? -FastMath.PI : FastMath.PI) - 2 * tmp2[0]; // +/-pi - 2 * atan(y / (r - x))
|
||||
((tmp2[0] <= 0) ? -AccurateMath.PI : AccurateMath.PI) - 2 * tmp2[0]; // +/-pi - 2 * atan(y / (r - x))
|
||||
for (int i = 1; i < tmp2.length; ++i) {
|
||||
result[resultOffset + i] = -2 * tmp2[i]; // +/-pi - 2 * atan(y / (r - x))
|
||||
}
|
||||
|
@ -1480,7 +1480,7 @@ public class DSCompiler {
|
|||
}
|
||||
|
||||
// fix value to take special cases (+0/+0, +0/-0, -0/+0, -0/-0, +/-infinity) correctly
|
||||
result[resultOffset] = FastMath.atan2(y[yOffset], x[xOffset]);
|
||||
result[resultOffset] = AccurateMath.atan2(y[yOffset], x[xOffset]);
|
||||
|
||||
}
|
||||
|
||||
|
@ -1497,9 +1497,9 @@ public class DSCompiler {
|
|||
|
||||
// create the function value and derivatives
|
||||
double[] function = new double[1 + order];
|
||||
function[0] = FastMath.cosh(operand[operandOffset]);
|
||||
function[0] = AccurateMath.cosh(operand[operandOffset]);
|
||||
if (order > 0) {
|
||||
function[1] = FastMath.sinh(operand[operandOffset]);
|
||||
function[1] = AccurateMath.sinh(operand[operandOffset]);
|
||||
for (int i = 2; i <= order; ++i) {
|
||||
function[i] = function[i - 2];
|
||||
}
|
||||
|
@ -1523,9 +1523,9 @@ public class DSCompiler {
|
|||
|
||||
// create the function value and derivatives
|
||||
double[] function = new double[1 + order];
|
||||
function[0] = FastMath.sinh(operand[operandOffset]);
|
||||
function[0] = AccurateMath.sinh(operand[operandOffset]);
|
||||
if (order > 0) {
|
||||
function[1] = FastMath.cosh(operand[operandOffset]);
|
||||
function[1] = AccurateMath.cosh(operand[operandOffset]);
|
||||
for (int i = 2; i <= order; ++i) {
|
||||
function[i] = function[i - 2];
|
||||
}
|
||||
|
@ -1549,7 +1549,7 @@ public class DSCompiler {
|
|||
|
||||
// create the function value and derivatives
|
||||
final double[] function = new double[1 + order];
|
||||
final double t = FastMath.tanh(operand[operandOffset]);
|
||||
final double t = AccurateMath.tanh(operand[operandOffset]);
|
||||
function[0] = t;
|
||||
|
||||
if (order > 0) {
|
||||
|
@ -1605,7 +1605,7 @@ public class DSCompiler {
|
|||
// create the function value and derivatives
|
||||
double[] function = new double[1 + order];
|
||||
final double x = operand[operandOffset];
|
||||
function[0] = FastMath.acosh(x);
|
||||
function[0] = AccurateMath.acosh(x);
|
||||
if (order > 0) {
|
||||
// the nth order derivative of acosh has the form:
|
||||
// dn(acosh(x)/dxn = P_n(x) / [x^2 - 1]^((2n-1)/2)
|
||||
|
@ -1618,7 +1618,7 @@ public class DSCompiler {
|
|||
p[0] = 1;
|
||||
final double x2 = x * x;
|
||||
final double f = 1.0 / (x2 - 1);
|
||||
double coeff = FastMath.sqrt(f);
|
||||
double coeff = AccurateMath.sqrt(f);
|
||||
function[1] = coeff * p[0];
|
||||
for (int n = 2; n <= order; ++n) {
|
||||
|
||||
|
@ -1662,7 +1662,7 @@ public class DSCompiler {
|
|||
// create the function value and derivatives
|
||||
double[] function = new double[1 + order];
|
||||
final double x = operand[operandOffset];
|
||||
function[0] = FastMath.asinh(x);
|
||||
function[0] = AccurateMath.asinh(x);
|
||||
if (order > 0) {
|
||||
// the nth order derivative of asinh has the form:
|
||||
// dn(asinh(x)/dxn = P_n(x) / [x^2 + 1]^((2n-1)/2)
|
||||
|
@ -1675,7 +1675,7 @@ public class DSCompiler {
|
|||
p[0] = 1;
|
||||
final double x2 = x * x;
|
||||
final double f = 1.0 / (1 + x2);
|
||||
double coeff = FastMath.sqrt(f);
|
||||
double coeff = AccurateMath.sqrt(f);
|
||||
function[1] = coeff * p[0];
|
||||
for (int n = 2; n <= order; ++n) {
|
||||
|
||||
|
@ -1719,7 +1719,7 @@ public class DSCompiler {
|
|||
// create the function value and derivatives
|
||||
double[] function = new double[1 + order];
|
||||
final double x = operand[operandOffset];
|
||||
function[0] = FastMath.atanh(x);
|
||||
function[0] = AccurateMath.atanh(x);
|
||||
if (order > 0) {
|
||||
// the nth order derivative of atanh has the form:
|
||||
// dn(atanh(x)/dxn = Q_n(x) / (1 - x^2)^n
|
||||
|
@ -1805,7 +1805,7 @@ public class DSCompiler {
|
|||
for (int k = 0; k < orders.length; ++k) {
|
||||
if (orders[k] > 0) {
|
||||
try {
|
||||
term *= FastMath.pow(delta[k], orders[k]) / FACTORIAL.value(orders[k]);
|
||||
term *= AccurateMath.pow(delta[k], orders[k]) / FACTORIAL.value(orders[k]);
|
||||
} catch (NotPositiveException e) {
|
||||
// this cannot happen
|
||||
throw new MathInternalError(e);
|
||||
|
|
|
@ -20,14 +20,14 @@ import java.util.Arrays;
|
|||
import java.io.Serializable;
|
||||
|
||||
import org.apache.commons.numbers.arrays.LinearCombination;
|
||||
import org.apache.commons.math4.legacy.Field;
|
||||
import org.apache.commons.math4.legacy.FieldElement;
|
||||
import org.apache.commons.math4.legacy.RealFieldElement;
|
||||
import org.apache.commons.math4.legacy.core.Field;
|
||||
import org.apache.commons.math4.legacy.core.FieldElement;
|
||||
import org.apache.commons.math4.legacy.core.RealFieldElement;
|
||||
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math4.legacy.exception.MathArithmeticException;
|
||||
import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
|
||||
import org.apache.commons.math4.legacy.util.FastMath;
|
||||
import org.apache.commons.math4.legacy.util.MathArrays;
|
||||
import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
|
||||
import org.apache.commons.math4.legacy.core.MathArrays;
|
||||
|
||||
/** Class representing both the value and the differentials of a function.
|
||||
* <p>This class is the workhorse of the differentiation package.</p>
|
||||
|
@ -389,7 +389,7 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
@Override
|
||||
public DerivativeStructure remainder(final double a) {
|
||||
final DerivativeStructure ds = new DerivativeStructure(this);
|
||||
ds.data[0] = FastMath.IEEEremainder(ds.data[0], a);
|
||||
ds.data[0] = AccurateMath.IEEEremainder(ds.data[0], a);
|
||||
return ds;
|
||||
}
|
||||
|
||||
|
@ -437,7 +437,7 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
public DerivativeStructure ceil() {
|
||||
return new DerivativeStructure(compiler.getFreeParameters(),
|
||||
compiler.getOrder(),
|
||||
FastMath.ceil(data[0]));
|
||||
AccurateMath.ceil(data[0]));
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
|
@ -447,7 +447,7 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
public DerivativeStructure floor() {
|
||||
return new DerivativeStructure(compiler.getFreeParameters(),
|
||||
compiler.getOrder(),
|
||||
FastMath.floor(data[0]));
|
||||
AccurateMath.floor(data[0]));
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
|
@ -457,13 +457,13 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
public DerivativeStructure rint() {
|
||||
return new DerivativeStructure(compiler.getFreeParameters(),
|
||||
compiler.getOrder(),
|
||||
FastMath.rint(data[0]));
|
||||
AccurateMath.rint(data[0]));
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public long round() {
|
||||
return FastMath.round(data[0]);
|
||||
return AccurateMath.round(data[0]);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
|
@ -473,7 +473,7 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
public DerivativeStructure signum() {
|
||||
return new DerivativeStructure(compiler.getFreeParameters(),
|
||||
compiler.getOrder(),
|
||||
FastMath.signum(data[0]));
|
||||
AccurateMath.signum(data[0]));
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
|
@ -511,7 +511,7 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
* @return exponent for instance in IEEE754 representation, without bias
|
||||
*/
|
||||
public int getExponent() {
|
||||
return FastMath.getExponent(data[0]);
|
||||
return AccurateMath.getExponent(data[0]);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
|
@ -521,7 +521,7 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
public DerivativeStructure scalb(final int n) {
|
||||
final DerivativeStructure ds = new DerivativeStructure(compiler);
|
||||
for (int i = 0; i < ds.data.length; ++i) {
|
||||
ds.data[i] = FastMath.scalb(data[i], n);
|
||||
ds.data[i] = AccurateMath.scalb(data[i], n);
|
||||
}
|
||||
return ds;
|
||||
}
|
||||
|
@ -923,7 +923,7 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
public DerivativeStructure toDegrees() {
|
||||
final DerivativeStructure ds = new DerivativeStructure(compiler);
|
||||
for (int i = 0; i < ds.data.length; ++i) {
|
||||
ds.data[i] = FastMath.toDegrees(data[i]);
|
||||
ds.data[i] = AccurateMath.toDegrees(data[i]);
|
||||
}
|
||||
return ds;
|
||||
}
|
||||
|
@ -934,7 +934,7 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
public DerivativeStructure toRadians() {
|
||||
final DerivativeStructure ds = new DerivativeStructure(compiler);
|
||||
for (int i = 0; i < ds.data.length; ++i) {
|
||||
ds.data[i] = FastMath.toRadians(data[i]);
|
||||
ds.data[i] = AccurateMath.toRadians(data[i]);
|
||||
}
|
||||
return ds;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException;
|
|||
import org.apache.commons.math4.legacy.exception.NotPositiveException;
|
||||
import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
|
||||
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
|
||||
import org.apache.commons.math4.legacy.util.FastMath;
|
||||
import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
|
||||
|
||||
/** Univariate functions differentiator using finite differences.
|
||||
* <p>
|
||||
|
@ -156,7 +156,7 @@ public class FiniteDifferencesDifferentiator
|
|||
if (2 * halfSampleSpan >= tUpper - tLower) {
|
||||
throw new NumberIsTooLargeException(2 * halfSampleSpan, tUpper - tLower, false);
|
||||
}
|
||||
final double safety = FastMath.ulp(halfSampleSpan);
|
||||
final double safety = AccurateMath.ulp(halfSampleSpan);
|
||||
this.tMin = tLower + halfSampleSpan + safety;
|
||||
this.tMax = tUpper - halfSampleSpan - safety;
|
||||
|
||||
|
@ -262,7 +262,7 @@ public class FiniteDifferencesDifferentiator
|
|||
}
|
||||
|
||||
// compute sample position, trying to be centered if possible
|
||||
final double t0 = FastMath.max(FastMath.min(t.getValue(), tMax), tMin) - halfSampleSpan;
|
||||
final double t0 = AccurateMath.max(AccurateMath.min(t.getValue(), tMax), tMin) - halfSampleSpan;
|
||||
|
||||
// compute sample points
|
||||
final double[] y = new double[nbPoints];
|
||||
|
@ -305,7 +305,7 @@ public class FiniteDifferencesDifferentiator
|
|||
}
|
||||
|
||||
// compute sample position, trying to be centered if possible
|
||||
final double t0 = FastMath.max(FastMath.min(t.getValue(), tMax), tMin) - halfSampleSpan;
|
||||
final double t0 = AccurateMath.max(AccurateMath.min(t.getValue(), tMax), tMin) - halfSampleSpan;
|
||||
|
||||
// compute sample points
|
||||
double[][] y = null;
|
||||
|
@ -359,7 +359,7 @@ public class FiniteDifferencesDifferentiator
|
|||
}
|
||||
|
||||
// compute sample position, trying to be centered if possible
|
||||
final double t0 = FastMath.max(FastMath.min(t.getValue(), tMax), tMin) - halfSampleSpan;
|
||||
final double t0 = AccurateMath.max(AccurateMath.min(t.getValue(), tMax), tMin) - halfSampleSpan;
|
||||
|
||||
// compute sample points
|
||||
double[][][] y = null;
|
||||
|
|
|
@ -23,11 +23,11 @@ import java.util.Map;
|
|||
|
||||
import org.apache.commons.numbers.arrays.LinearCombination;
|
||||
import org.apache.commons.numbers.core.Precision;
|
||||
import org.apache.commons.math4.legacy.Field;
|
||||
import org.apache.commons.math4.legacy.FieldElement;
|
||||
import org.apache.commons.math4.legacy.RealFieldElement;
|
||||
import org.apache.commons.math4.legacy.core.Field;
|
||||
import org.apache.commons.math4.legacy.core.FieldElement;
|
||||
import org.apache.commons.math4.legacy.core.RealFieldElement;
|
||||
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math4.legacy.util.FastMath;
|
||||
import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
|
||||
|
||||
/**
|
||||
* First derivative computation with large number of variables.
|
||||
|
@ -330,7 +330,7 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, Seriali
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient remainder(final double a) {
|
||||
return new SparseGradient(FastMath.IEEEremainder(value, a), derivatives);
|
||||
return new SparseGradient(AccurateMath.IEEEremainder(value, a), derivatives);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
@ -338,8 +338,8 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, Seriali
|
|||
public SparseGradient remainder(final SparseGradient a) {
|
||||
|
||||
// compute k such that lhs % rhs = lhs - k rhs
|
||||
final double rem = FastMath.IEEEremainder(value, a.value);
|
||||
final double k = FastMath.rint((value - rem) / a.value);
|
||||
final double rem = AccurateMath.IEEEremainder(value, a.value);
|
||||
final double k = AccurateMath.rint((value - rem) / a.value);
|
||||
|
||||
return subtract(a.multiply(k));
|
||||
|
||||
|
@ -359,31 +359,31 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, Seriali
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient ceil() {
|
||||
return createConstant(FastMath.ceil(value));
|
||||
return createConstant(AccurateMath.ceil(value));
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient floor() {
|
||||
return createConstant(FastMath.floor(value));
|
||||
return createConstant(AccurateMath.floor(value));
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient rint() {
|
||||
return createConstant(FastMath.rint(value));
|
||||
return createConstant(AccurateMath.rint(value));
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public long round() {
|
||||
return FastMath.round(value);
|
||||
return AccurateMath.round(value);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient signum() {
|
||||
return createConstant(FastMath.signum(value));
|
||||
return createConstant(AccurateMath.signum(value));
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
@ -411,9 +411,9 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, Seriali
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient scalb(final int n) {
|
||||
final SparseGradient out = new SparseGradient(FastMath.scalb(value, n), Collections.<Integer, Double> emptyMap());
|
||||
final SparseGradient out = new SparseGradient(AccurateMath.scalb(value, n), Collections.<Integer, Double> emptyMap());
|
||||
for (Map.Entry<Integer, Double> entry : derivatives.entrySet()) {
|
||||
out.derivatives.put(entry.getKey(), FastMath.scalb(entry.getValue(), n));
|
||||
out.derivatives.put(entry.getKey(), AccurateMath.scalb(entry.getValue(), n));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
@ -427,8 +427,8 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, Seriali
|
|||
return createConstant(Double.NaN);
|
||||
} else {
|
||||
|
||||
final int expX = FastMath.getExponent(value);
|
||||
final int expY = FastMath.getExponent(y.value);
|
||||
final int expX = AccurateMath.getExponent(value);
|
||||
final int expY = AccurateMath.getExponent(y.value);
|
||||
if (expX > expY + 27) {
|
||||
// y is negligible with respect to x
|
||||
return abs();
|
||||
|
@ -483,14 +483,14 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, Seriali
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient sqrt() {
|
||||
final double sqrt = FastMath.sqrt(value);
|
||||
final double sqrt = AccurateMath.sqrt(value);
|
||||
return new SparseGradient(sqrt, 0.5 / sqrt, derivatives);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient cbrt() {
|
||||
final double cbrt = FastMath.cbrt(value);
|
||||
final double cbrt = AccurateMath.cbrt(value);
|
||||
return new SparseGradient(cbrt, 1.0 / (3 * cbrt * cbrt), derivatives);
|
||||
}
|
||||
|
||||
|
@ -502,15 +502,15 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, Seriali
|
|||
} else if (n == 3) {
|
||||
return cbrt();
|
||||
} else {
|
||||
final double root = FastMath.pow(value, 1.0 / n);
|
||||
return new SparseGradient(root, 1.0 / (n * FastMath.pow(root, n - 1)), derivatives);
|
||||
final double root = AccurateMath.pow(value, 1.0 / n);
|
||||
return new SparseGradient(root, 1.0 / (n * AccurateMath.pow(root, n - 1)), derivatives);
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient pow(final double p) {
|
||||
return new SparseGradient(FastMath.pow(value, p), p * FastMath.pow(value, p - 1), derivatives);
|
||||
return new SparseGradient(AccurateMath.pow(value, p), p * AccurateMath.pow(value, p - 1), derivatives);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
@ -519,7 +519,7 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, Seriali
|
|||
if (n == 0) {
|
||||
return getField().getOne();
|
||||
} else {
|
||||
final double valueNm1 = FastMath.pow(value, n - 1);
|
||||
final double valueNm1 = AccurateMath.pow(value, n - 1);
|
||||
return new SparseGradient(value * valueNm1, n * valueNm1, derivatives);
|
||||
}
|
||||
}
|
||||
|
@ -545,28 +545,28 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, Seriali
|
|||
return x.getField().getZero();
|
||||
}
|
||||
} else {
|
||||
final double ax = FastMath.pow(a, x.value);
|
||||
return new SparseGradient(ax, ax * FastMath.log(a), x.derivatives);
|
||||
final double ax = AccurateMath.pow(a, x.value);
|
||||
return new SparseGradient(ax, ax * AccurateMath.log(a), x.derivatives);
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient exp() {
|
||||
final double e = FastMath.exp(value);
|
||||
final double e = AccurateMath.exp(value);
|
||||
return new SparseGradient(e, e, derivatives);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient expm1() {
|
||||
return new SparseGradient(FastMath.expm1(value), FastMath.exp(value), derivatives);
|
||||
return new SparseGradient(AccurateMath.expm1(value), AccurateMath.exp(value), derivatives);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient log() {
|
||||
return new SparseGradient(FastMath.log(value), 1.0 / value, derivatives);
|
||||
return new SparseGradient(AccurateMath.log(value), 1.0 / value, derivatives);
|
||||
}
|
||||
|
||||
/** Base 10 logarithm.
|
||||
|
@ -574,50 +574,50 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, Seriali
|
|||
*/
|
||||
@Override
|
||||
public SparseGradient log10() {
|
||||
return new SparseGradient(FastMath.log10(value), 1.0 / (FastMath.log(10.0) * value), derivatives);
|
||||
return new SparseGradient(AccurateMath.log10(value), 1.0 / (AccurateMath.log(10.0) * value), derivatives);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient log1p() {
|
||||
return new SparseGradient(FastMath.log1p(value), 1.0 / (1.0 + value), derivatives);
|
||||
return new SparseGradient(AccurateMath.log1p(value), 1.0 / (1.0 + value), derivatives);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient cos() {
|
||||
return new SparseGradient(FastMath.cos(value), -FastMath.sin(value), derivatives);
|
||||
return new SparseGradient(AccurateMath.cos(value), -AccurateMath.sin(value), derivatives);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient sin() {
|
||||
return new SparseGradient(FastMath.sin(value), FastMath.cos(value), derivatives);
|
||||
return new SparseGradient(AccurateMath.sin(value), AccurateMath.cos(value), derivatives);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient tan() {
|
||||
final double t = FastMath.tan(value);
|
||||
final double t = AccurateMath.tan(value);
|
||||
return new SparseGradient(t, 1 + t * t, derivatives);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient acos() {
|
||||
return new SparseGradient(FastMath.acos(value), -1.0 / FastMath.sqrt(1 - value * value), derivatives);
|
||||
return new SparseGradient(AccurateMath.acos(value), -1.0 / AccurateMath.sqrt(1 - value * value), derivatives);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient asin() {
|
||||
return new SparseGradient(FastMath.asin(value), 1.0 / FastMath.sqrt(1 - value * value), derivatives);
|
||||
return new SparseGradient(AccurateMath.asin(value), 1.0 / AccurateMath.sqrt(1 - value * value), derivatives);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient atan() {
|
||||
return new SparseGradient(FastMath.atan(value), 1.0 / (1 + value * value), derivatives);
|
||||
return new SparseGradient(AccurateMath.atan(value), 1.0 / (1 + value * value), derivatives);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
@ -637,12 +637,12 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, Seriali
|
|||
|
||||
// compute atan2(y, x) = +/- pi - 2 atan(y / (r - x))
|
||||
final SparseGradient tmp = divide(r.subtract(x)).atan().multiply(-2);
|
||||
a = tmp.add(tmp.value <= 0 ? -FastMath.PI : FastMath.PI);
|
||||
a = tmp.add(tmp.value <= 0 ? -AccurateMath.PI : AccurateMath.PI);
|
||||
|
||||
}
|
||||
|
||||
// fix value to take special cases (+0/+0, +0/-0, -0/+0, -0/-0, +/-infinity) correctly
|
||||
a.value = FastMath.atan2(value, x.value);
|
||||
a.value = AccurateMath.atan2(value, x.value);
|
||||
|
||||
return a;
|
||||
|
||||
|
@ -660,52 +660,52 @@ public class SparseGradient implements RealFieldElement<SparseGradient>, Seriali
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient cosh() {
|
||||
return new SparseGradient(FastMath.cosh(value), FastMath.sinh(value), derivatives);
|
||||
return new SparseGradient(AccurateMath.cosh(value), AccurateMath.sinh(value), derivatives);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient sinh() {
|
||||
return new SparseGradient(FastMath.sinh(value), FastMath.cosh(value), derivatives);
|
||||
return new SparseGradient(AccurateMath.sinh(value), AccurateMath.cosh(value), derivatives);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient tanh() {
|
||||
final double t = FastMath.tanh(value);
|
||||
final double t = AccurateMath.tanh(value);
|
||||
return new SparseGradient(t, 1 - t * t, derivatives);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient acosh() {
|
||||
return new SparseGradient(FastMath.acosh(value), 1.0 / FastMath.sqrt(value * value - 1.0), derivatives);
|
||||
return new SparseGradient(AccurateMath.acosh(value), 1.0 / AccurateMath.sqrt(value * value - 1.0), derivatives);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient asinh() {
|
||||
return new SparseGradient(FastMath.asinh(value), 1.0 / FastMath.sqrt(value * value + 1.0), derivatives);
|
||||
return new SparseGradient(AccurateMath.asinh(value), 1.0 / AccurateMath.sqrt(value * value + 1.0), derivatives);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SparseGradient atanh() {
|
||||
return new SparseGradient(FastMath.atanh(value), 1.0 / (1.0 - value * value), derivatives);
|
||||
return new SparseGradient(AccurateMath.atanh(value), 1.0 / (1.0 - value * value), derivatives);
|
||||
}
|
||||
|
||||
/** Convert radians to degrees, with error of less than 0.5 ULP
|
||||
* @return instance converted into degrees
|
||||
*/
|
||||
public SparseGradient toDegrees() {
|
||||
return new SparseGradient(FastMath.toDegrees(value), FastMath.toDegrees(1.0), derivatives);
|
||||
return new SparseGradient(AccurateMath.toDegrees(value), AccurateMath.toDegrees(1.0), derivatives);
|
||||
}
|
||||
|
||||
/** Convert degrees to radians, with error of less than 0.5 ULP
|
||||
* @return instance converted into radians
|
||||
*/
|
||||
public SparseGradient toRadians() {
|
||||
return new SparseGradient(FastMath.toRadians(value), FastMath.toRadians(1.0), derivatives);
|
||||
return new SparseGradient(AccurateMath.toRadians(value), AccurateMath.toRadians(1.0), derivatives);
|
||||
}
|
||||
|
||||
/** Evaluate Taylor expansion of a sparse gradient.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function;
|
|||
|
||||
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
|
||||
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
|
||||
import org.apache.commons.math4.legacy.util.FastMath;
|
||||
import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
|
||||
|
||||
/**
|
||||
* <code>e<sup>x</sup>-1</code> function.
|
||||
|
@ -30,7 +30,7 @@ public class Expm1 implements UnivariateDifferentiableFunction {
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public double value(double x) {
|
||||
return FastMath.expm1(x);
|
||||
return AccurateMath.expm1(x);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStruct
|
|||
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
|
||||
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math4.legacy.exception.NullArgumentException;
|
||||
import org.apache.commons.math4.legacy.util.FastMath;
|
||||
import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
|
||||
|
||||
/**
|
||||
* <a href="http://en.wikipedia.org/wiki/Harmonic_oscillator">
|
||||
|
@ -112,7 +112,7 @@ public class HarmonicOscillator implements UnivariateDifferentiableFunction {
|
|||
|
||||
final double xTimesOmegaPlusPhase = omega * x + phase;
|
||||
final double a = HarmonicOscillator.value(xTimesOmegaPlusPhase, 1);
|
||||
final double p = -amplitude * FastMath.sin(xTimesOmegaPlusPhase);
|
||||
final double p = -amplitude * AccurateMath.sin(xTimesOmegaPlusPhase);
|
||||
final double w = p * x;
|
||||
|
||||
return new double[] { a, w, p };
|
||||
|
@ -147,7 +147,7 @@ public class HarmonicOscillator implements UnivariateDifferentiableFunction {
|
|||
*/
|
||||
private static double value(double xTimesOmegaPlusPhase,
|
||||
double amplitude) {
|
||||
return amplitude * FastMath.cos(xTimesOmegaPlusPhase);
|
||||
return amplitude * AccurateMath.cos(xTimesOmegaPlusPhase);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
|
@ -160,9 +160,9 @@ public class HarmonicOscillator implements UnivariateDifferentiableFunction {
|
|||
double[] f = new double[t.getOrder() + 1];
|
||||
|
||||
final double alpha = omega * x + phase;
|
||||
f[0] = amplitude * FastMath.cos(alpha);
|
||||
f[0] = amplitude * AccurateMath.cos(alpha);
|
||||
if (f.length > 1) {
|
||||
f[1] = -amplitude * omega * FastMath.sin(alpha);
|
||||
f[1] = -amplitude * omega * AccurateMath.sin(alpha);
|
||||
final double mo2 = - omega * omega;
|
||||
for (int i = 2; i < f.length; ++i) {
|
||||
f[i] = mo2 * f[i - 2];
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.apache.commons.math4.legacy.analysis.function;
|
|||
|
||||
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
|
||||
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
|
||||
import org.apache.commons.math4.legacy.util.FastMath;
|
||||
import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
|
||||
|
||||
/**
|
||||
* <code>log(1 + p)</code> function.
|
||||
|
@ -30,7 +30,7 @@ public class Log1p implements UnivariateDifferentiableFunction {
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public double value(double x) {
|
||||
return FastMath.log1p(x);
|
||||
return AccurateMath.log1p(x);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDiffer
|
|||
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException;
|
||||
import org.apache.commons.math4.legacy.exception.NullArgumentException;
|
||||
import org.apache.commons.math4.legacy.util.FastMath;
|
||||
import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
|
||||
|
||||
/**
|
||||
* <a href="http://en.wikipedia.org/wiki/Generalised_logistic_function">
|
||||
|
@ -147,10 +147,10 @@ public class Logistic implements UnivariateDifferentiableFunction {
|
|||
|
||||
final double mMinusX = param[1] - x;
|
||||
final double oneOverN = 1 / param[5];
|
||||
final double exp = FastMath.exp(b * mMinusX);
|
||||
final double exp = AccurateMath.exp(b * mMinusX);
|
||||
final double qExp = q * exp;
|
||||
final double qExp1 = qExp + 1;
|
||||
final double factor1 = (param[0] - param[4]) * oneOverN / FastMath.pow(qExp1, oneOverN);
|
||||
final double factor1 = (param[0] - param[4]) * oneOverN / AccurateMath.pow(qExp1, oneOverN);
|
||||
final double factor2 = -factor1 / qExp1;
|
||||
|
||||
// Components of the gradient.
|
||||
|
@ -159,7 +159,7 @@ public class Logistic implements UnivariateDifferentiableFunction {
|
|||
final double gb = factor2 * mMinusX * qExp;
|
||||
final double gq = factor2 * exp;
|
||||
final double ga = Logistic.value(mMinusX, 0, b, q, 1, oneOverN);
|
||||
final double gn = factor1 * FastMath.log(qExp1) * oneOverN;
|
||||
final double gn = factor1 * AccurateMath.log(qExp1) * oneOverN;
|
||||
|
||||
return new double[] { gk, gm, gb, gq, ga, gn };
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ public class Logistic implements UnivariateDifferentiableFunction {
|
|||
double q,
|
||||
double a,
|
||||
double oneOverN) {
|
||||
return a + (k - a) / FastMath.pow(1 + q * FastMath.exp(b * mMinusX), oneOverN);
|
||||
return a + (k - a) / AccurateMath.pow(1 + q * AccurateMath.exp(b * mMinusX), oneOverN);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDiffer
|
|||
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math4.legacy.exception.NullArgumentException;
|
||||
import org.apache.commons.math4.legacy.exception.OutOfRangeException;
|
||||
import org.apache.commons.math4.legacy.util.FastMath;
|
||||
import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
|
||||
|
||||
/**
|
||||
* <a href="http://en.wikipedia.org/wiki/Logit">
|
||||
|
@ -153,7 +153,7 @@ public class Logit implements UnivariateDifferentiableFunction {
|
|||
if (x < lo || x > hi) {
|
||||
throw new OutOfRangeException(x, lo, hi);
|
||||
}
|
||||
return FastMath.log((x - lo) / (hi - x));
|
||||
return AccurateMath.log((x - lo) / (hi - x));
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
|
@ -170,7 +170,7 @@ public class Logit implements UnivariateDifferentiableFunction {
|
|||
double[] f = new double[t.getOrder() + 1];
|
||||
|
||||
// function value
|
||||
f[0] = FastMath.log((x - lo) / (hi - x));
|
||||
f[0] = AccurateMath.log((x - lo) / (hi - x));
|
||||
|
||||
if (Double.isInfinite(f[0])) {
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStruct
|
|||
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
|
||||
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math4.legacy.exception.NullArgumentException;
|
||||
import org.apache.commons.math4.legacy.util.FastMath;
|
||||
import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
|
||||
|
||||
/**
|
||||
* <a href="http://en.wikipedia.org/wiki/Sigmoid_function">
|
||||
|
@ -114,7 +114,7 @@ public class Sigmoid implements UnivariateDifferentiableFunction {
|
|||
DimensionMismatchException {
|
||||
validateParameters(param);
|
||||
|
||||
final double invExp1 = 1 / (1 + FastMath.exp(-x));
|
||||
final double invExp1 = 1 / (1 + AccurateMath.exp(-x));
|
||||
|
||||
return new double[] { 1 - invExp1, invExp1 };
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ public class Sigmoid implements UnivariateDifferentiableFunction {
|
|||
private static double value(double x,
|
||||
double lo,
|
||||
double hi) {
|
||||
return lo + (hi - lo) / (1 + FastMath.exp(-x));
|
||||
return lo + (hi - lo) / (1 + AccurateMath.exp(-x));
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
|
@ -161,7 +161,7 @@ public class Sigmoid implements UnivariateDifferentiableFunction {
|
|||
throws DimensionMismatchException {
|
||||
|
||||
double[] f = new double[t.getOrder() + 1];
|
||||
final double exp = FastMath.exp(-t.getValue());
|
||||
final double exp = AccurateMath.exp(-t.getValue());
|
||||
if (Double.isInfinite(exp)) {
|
||||
|
||||
// special handling near lower boundary, to avoid NaN
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -20,7 +20,7 @@ package org.apache.commons.math4.legacy.analysis.function;
|
|||
import org.apache.commons.math4.legacy.analysis.differentiation.DerivativeStructure;
|
||||
import org.apache.commons.math4.legacy.analysis.differentiation.UnivariateDifferentiableFunction;
|
||||
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math4.legacy.util.FastMath;
|
||||
import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
|
||||
|
||||
/**
|
||||
* <a href="http://en.wikipedia.org/wiki/Sinc_function">Sinc</a> function,
|
||||
|
@ -81,14 +81,14 @@ public class Sinc implements UnivariateDifferentiableFunction {
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public double value(final double x) {
|
||||
final double scaledX = normalized ? FastMath.PI * x : x;
|
||||
if (FastMath.abs(scaledX) <= SHORTCUT) {
|
||||
final double scaledX = normalized ? AccurateMath.PI * x : x;
|
||||
if (AccurateMath.abs(scaledX) <= SHORTCUT) {
|
||||
// use Taylor series
|
||||
final double scaledX2 = scaledX * scaledX;
|
||||
return ((scaledX2 - 20) * scaledX2 + 120) / 120;
|
||||
} else {
|
||||
// use definition expression
|
||||
return FastMath.sin(scaledX) / scaledX;
|
||||
return AccurateMath.sin(scaledX) / scaledX;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,12 +99,12 @@ public class Sinc implements UnivariateDifferentiableFunction {
|
|||
public DerivativeStructure value(final DerivativeStructure t)
|
||||
throws DimensionMismatchException {
|
||||
|
||||
final double scaledX = (normalized ? FastMath.PI : 1) * t.getValue();
|
||||
final double scaledX = (normalized ? AccurateMath.PI : 1) * t.getValue();
|
||||
final double scaledX2 = scaledX * scaledX;
|
||||
|
||||
double[] f = new double[t.getOrder() + 1];
|
||||
|
||||
if (FastMath.abs(scaledX) <= SHORTCUT) {
|
||||
if (AccurateMath.abs(scaledX) <= SHORTCUT) {
|
||||
|
||||
for (int i = 0; i < f.length; ++i) {
|
||||
final int k = i / 2;
|
||||
|
@ -122,8 +122,8 @@ public class Sinc implements UnivariateDifferentiableFunction {
|
|||
} else {
|
||||
|
||||
final double inv = 1 / scaledX;
|
||||
final double cos = FastMath.cos(scaledX);
|
||||
final double sin = FastMath.sin(scaledX);
|
||||
final double cos = AccurateMath.cos(scaledX);
|
||||
final double sin = AccurateMath.sin(scaledX);
|
||||
|
||||
f[0] = inv * sin;
|
||||
|
||||
|
@ -182,10 +182,10 @@ public class Sinc implements UnivariateDifferentiableFunction {
|
|||
}
|
||||
|
||||
if (normalized) {
|
||||
double scale = FastMath.PI;
|
||||
double scale = AccurateMath.PI;
|
||||
for (int i = 1; i < f.length; ++i) {
|
||||
f[i] *= scale;
|
||||
scale *= FastMath.PI;
|
||||
scale *= AccurateMath.PI;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
|
|||
import org.apache.commons.math4.legacy.exception.NoDataException;
|
||||
import org.apache.commons.math4.legacy.exception.NonMonotonicSequenceException;
|
||||
import org.apache.commons.math4.legacy.exception.NullArgumentException;
|
||||
import org.apache.commons.math4.legacy.util.MathArrays;
|
||||
import org.apache.commons.math4.legacy.core.MathArrays;
|
||||
|
||||
/**
|
||||
* <a href="http://en.wikipedia.org/wiki/Step_function">
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package org.apache.commons.math4.legacy.analysis.integration;
|
||||
|
||||
import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
|
||||
import org.apache.commons.math4.legacy.util.FastMath;
|
||||
import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
|
||||
|
||||
/**
|
||||
* Implements the <a href="https://en.wikipedia.org/wiki/Riemann_sum#Midpoint_rule">
|
||||
|
@ -113,7 +113,7 @@ public class MidPointIntegrator extends BaseAbstractUnivariateIntegrator {
|
|||
double diffMaxMin) {
|
||||
// number of points in the previous stage. This stage will contribute
|
||||
// 2*3^{n-1} more points.
|
||||
final long np = (long) FastMath.pow(3, n - 1);
|
||||
final long np = (long) AccurateMath.pow(3, n - 1);
|
||||
double sum = 0;
|
||||
|
||||
// spacing between adjacent new points
|
||||
|
@ -151,9 +151,9 @@ public class MidPointIntegrator extends BaseAbstractUnivariateIntegrator {
|
|||
final int i = iterations.getCount();
|
||||
final double t = stage(i, oldt, min, diff);
|
||||
if (i >= getMinimalIterationCount()) {
|
||||
final double delta = FastMath.abs(t - oldt);
|
||||
final double delta = AccurateMath.abs(t - oldt);
|
||||
final double rLimit =
|
||||
getRelativeAccuracy() * (FastMath.abs(oldt) + FastMath.abs(t)) * 0.5;
|
||||
getRelativeAccuracy() * (AccurateMath.abs(oldt) + AccurateMath.abs(t)) * 0.5;
|
||||
if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) {
|
||||
return t;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package org.apache.commons.math4.legacy.analysis.integration;
|
||||
|
||||
import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
|
||||
import org.apache.commons.math4.legacy.util.FastMath;
|
||||
import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
|
||||
|
||||
/**
|
||||
* Implements the <a href="http://mathworld.wolfram.com/RombergIntegration.html">
|
||||
|
@ -120,8 +120,8 @@ public class RombergIntegrator extends BaseAbstractUnivariateIntegrator {
|
|||
}
|
||||
final double s = currentRow[i];
|
||||
if (i >= getMinimalIterationCount()) {
|
||||
final double delta = FastMath.abs(s - olds);
|
||||
final double rLimit = getRelativeAccuracy() * (FastMath.abs(olds) + FastMath.abs(s)) * 0.5;
|
||||
final double delta = AccurateMath.abs(s - olds);
|
||||
final double rLimit = getRelativeAccuracy() * (AccurateMath.abs(olds) + AccurateMath.abs(s)) * 0.5;
|
||||
if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) {
|
||||
return s;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package org.apache.commons.math4.legacy.analysis.integration;
|
||||
|
||||
import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
|
||||
import org.apache.commons.math4.legacy.util.FastMath;
|
||||
import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
|
||||
|
||||
/**
|
||||
* Implements <a href="http://mathworld.wolfram.com/SimpsonsRule.html">
|
||||
|
@ -106,8 +106,8 @@ public class SimpsonIntegrator extends BaseAbstractUnivariateIntegrator {
|
|||
final double t = qtrap.stage(this, i + 1); // 1-stage ahead of the iteration
|
||||
final double s = (4 * t - oldt) / 3.0;
|
||||
if (i >= getMinimalIterationCount()) {
|
||||
final double delta = FastMath.abs(s - olds);
|
||||
final double rLimit = getRelativeAccuracy() * (FastMath.abs(olds) + FastMath.abs(s)) * 0.5;
|
||||
final double delta = AccurateMath.abs(s - olds);
|
||||
final double rLimit = getRelativeAccuracy() * (AccurateMath.abs(olds) + AccurateMath.abs(s)) * 0.5;
|
||||
if (delta <= rLimit ||
|
||||
delta <= getAbsoluteAccuracy()) {
|
||||
return s;
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package org.apache.commons.math4.legacy.analysis.integration;
|
||||
|
||||
import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
|
||||
import org.apache.commons.math4.legacy.util.FastMath;
|
||||
import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
|
||||
|
||||
/**
|
||||
* Implements the <a href="http://mathworld.wolfram.com/TrapezoidalRule.html">
|
||||
|
@ -139,9 +139,9 @@ public class TrapezoidIntegrator extends BaseAbstractUnivariateIntegrator {
|
|||
final int i = iterations.getCount();
|
||||
final double t = stage(this, i);
|
||||
if (i >= getMinimalIterationCount()) {
|
||||
final double delta = FastMath.abs(t - oldt);
|
||||
final double delta = AccurateMath.abs(t - oldt);
|
||||
final double rLimit =
|
||||
getRelativeAccuracy() * (FastMath.abs(oldt) + FastMath.abs(t)) * 0.5;
|
||||
getRelativeAccuracy() * (AccurateMath.abs(oldt) + AccurateMath.abs(t)) * 0.5;
|
||||
if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) {
|
||||
return t;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
package org.apache.commons.math4.legacy.analysis.integration.gauss;
|
||||
|
||||
import org.apache.commons.math4.legacy.util.FastMath;
|
||||
import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
|
||||
import org.apache.commons.math4.legacy.util.Pair;
|
||||
|
||||
/**
|
||||
|
@ -74,8 +74,8 @@ public class HermiteRuleFactory extends BaseRuleFactory<Double> {
|
|||
final Double[] points = new Double[numberOfPoints];
|
||||
final Double[] weights = new Double[numberOfPoints];
|
||||
|
||||
final double sqrtTwoTimesLastNumPoints = FastMath.sqrt(2 * lastNumPoints);
|
||||
final double sqrtTwoTimesNumPoints = FastMath.sqrt(2 * numberOfPoints);
|
||||
final double sqrtTwoTimesLastNumPoints = AccurateMath.sqrt(2 * lastNumPoints);
|
||||
final double sqrtTwoTimesNumPoints = AccurateMath.sqrt(2 * numberOfPoints);
|
||||
|
||||
// Find i-th root of H[n+1] by bracketing.
|
||||
final int iMax = numberOfPoints / 2;
|
||||
|
@ -96,8 +96,8 @@ public class HermiteRuleFactory extends BaseRuleFactory<Double> {
|
|||
for (int j = 1; j < numberOfPoints; j++) {
|
||||
// Compute H[j+1](a) and H[j+1](b)
|
||||
final double jp1 = j + 1;
|
||||
final double s = FastMath.sqrt(2 / jp1);
|
||||
final double sm = FastMath.sqrt(j / jp1);
|
||||
final double s = AccurateMath.sqrt(2 / jp1);
|
||||
final double sm = AccurateMath.sqrt(j / jp1);
|
||||
final double hpa = s * a * ha - sm * hma;
|
||||
final double hpb = s * b * hb - sm * hmb;
|
||||
hma = ha;
|
||||
|
@ -121,8 +121,8 @@ public class HermiteRuleFactory extends BaseRuleFactory<Double> {
|
|||
for (int j = 1; j < numberOfPoints; j++) {
|
||||
// Compute H[j+1](c)
|
||||
final double jp1 = j + 1;
|
||||
final double s = FastMath.sqrt(2 / jp1);
|
||||
final double sm = FastMath.sqrt(j / jp1);
|
||||
final double s = AccurateMath.sqrt(2 / jp1);
|
||||
final double sm = AccurateMath.sqrt(j / jp1);
|
||||
final double hpc = s * c * hc - sm * hmc;
|
||||
hmc = hc;
|
||||
hc = hpc;
|
||||
|
@ -160,7 +160,7 @@ public class HermiteRuleFactory extends BaseRuleFactory<Double> {
|
|||
double hm = H0;
|
||||
for (int j = 1; j < numberOfPoints; j += 2) {
|
||||
final double jp1 = j + 1;
|
||||
hm = -FastMath.sqrt(j / jp1) * hm;
|
||||
hm = -AccurateMath.sqrt(j / jp1) * hm;
|
||||
}
|
||||
final double d = sqrtTwoTimesNumPoints * hm;
|
||||
final double w = 2 / (d * d);
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -19,14 +19,14 @@ package org.apache.commons.math4.legacy.analysis.interpolation;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.math4.legacy.FieldElement;
|
||||
import org.apache.commons.math4.legacy.core.FieldElement;
|
||||
import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math4.legacy.exception.MathArithmeticException;
|
||||
import org.apache.commons.math4.legacy.exception.NoDataException;
|
||||
import org.apache.commons.math4.legacy.exception.NullArgumentException;
|
||||
import org.apache.commons.math4.legacy.exception.ZeroException;
|
||||
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
|
||||
import org.apache.commons.math4.legacy.util.MathArrays;
|
||||
import org.apache.commons.math4.legacy.core.MathArrays;
|
||||
|
||||
/** Polynomial interpolator using both sample values and sample derivatives.
|
||||
* <p>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -28,8 +28,8 @@ import org.apache.commons.math4.legacy.exception.NotPositiveException;
|
|||
import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
|
||||
import org.apache.commons.math4.legacy.exception.OutOfRangeException;
|
||||
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
|
||||
import org.apache.commons.math4.legacy.util.FastMath;
|
||||
import org.apache.commons.math4.legacy.util.MathArrays;
|
||||
import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
|
||||
import org.apache.commons.math4.legacy.core.MathArrays;
|
||||
|
||||
/**
|
||||
* Implements the <a href="http://en.wikipedia.org/wiki/Local_regression">
|
||||
|
@ -296,7 +296,7 @@ public class LoessInterpolator
|
|||
double sumXSquared = 0;
|
||||
double sumY = 0;
|
||||
double sumXY = 0;
|
||||
double denom = FastMath.abs(1.0 / (xval[edge] - x));
|
||||
double denom = AccurateMath.abs(1.0 / (xval[edge] - x));
|
||||
for (int k = ileft; k <= iright; ++k) {
|
||||
final double xk = xval[k];
|
||||
final double yk = yval[k];
|
||||
|
@ -316,7 +316,7 @@ public class LoessInterpolator
|
|||
final double meanXSquared = sumXSquared / sumWeights;
|
||||
|
||||
final double beta;
|
||||
if (FastMath.sqrt(FastMath.abs(meanXSquared - meanX * meanX)) < accuracy) {
|
||||
if (AccurateMath.sqrt(AccurateMath.abs(meanXSquared - meanX * meanX)) < accuracy) {
|
||||
beta = 0;
|
||||
} else {
|
||||
beta = (meanXY - meanX * meanY) / (meanXSquared - meanX * meanX);
|
||||
|
@ -325,7 +325,7 @@ public class LoessInterpolator
|
|||
final double alpha = meanY - beta * meanX;
|
||||
|
||||
res[i] = beta * x + alpha;
|
||||
residuals[i] = FastMath.abs(yval[i] - res[i]);
|
||||
residuals[i] = AccurateMath.abs(yval[i] - res[i]);
|
||||
}
|
||||
|
||||
// No need to recompute the robustness weights at the last
|
||||
|
@ -343,7 +343,7 @@ public class LoessInterpolator
|
|||
Arrays.sort(sortedResiduals);
|
||||
final double medianResidual = sortedResiduals[n / 2];
|
||||
|
||||
if (FastMath.abs(medianResidual) < accuracy) {
|
||||
if (AccurateMath.abs(medianResidual) < accuracy) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -450,7 +450,7 @@ public class LoessInterpolator
|
|||
* @return <code>(1 - |x|<sup>3</sup>)<sup>3</sup></code> for |x| < 1, 0 otherwise.
|
||||
*/
|
||||
private static double tricube(final double x) {
|
||||
final double absX = FastMath.abs(x);
|
||||
final double absX = AccurateMath.abs(x);
|
||||
if (absX >= 1.0) {
|
||||
return 0.0;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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(' ');
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ package org.apache.commons.math4.legacy.analysis.solvers;
|
|||
import org.apache.commons.math4.legacy.analysis.UnivariateFunction;
|
||||
import org.apache.commons.math4.legacy.exception.ConvergenceException;
|
||||
import org.apache.commons.math4.legacy.exception.MathInternalError;
|
||||
import org.apache.commons.math4.legacy.util.FastMath;
|
||||
import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
|
||||
|
||||
/**
|
||||
* Base class for all bracketing <em>Secant</em>-based methods for root-finding
|
||||
|
@ -210,7 +210,7 @@ public abstract class BaseSecantSolver
|
|||
// If the function value of the last approximation is too small,
|
||||
// given the function value accuracy, then we can't get closer to
|
||||
// the root than we already are.
|
||||
if (FastMath.abs(f1) <= ftol) {
|
||||
if (AccurateMath.abs(f1) <= ftol) {
|
||||
switch (allowed) {
|
||||
case ANY_SIDE:
|
||||
return x1;
|
||||
|
@ -241,7 +241,7 @@ public abstract class BaseSecantSolver
|
|||
|
||||
// If the current interval is within the given accuracies, we
|
||||
// are satisfied with the current approximation.
|
||||
if (FastMath.abs(x1 - x0) < FastMath.max(rtol * FastMath.abs(x1),
|
||||
if (AccurateMath.abs(x1 - x0) < AccurateMath.max(rtol * AccurateMath.abs(x1),
|
||||
atol)) {
|
||||
switch (allowed) {
|
||||
case ANY_SIDE:
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package org.apache.commons.math4.legacy.analysis.solvers;
|
||||
|
||||
import org.apache.commons.math4.legacy.exception.TooManyEvaluationsException;
|
||||
import org.apache.commons.math4.legacy.util.FastMath;
|
||||
import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
|
||||
|
||||
/**
|
||||
* Implements the <a href="http://mathworld.wolfram.com/Bisection.html">
|
||||
|
@ -82,7 +82,7 @@ public class BisectionSolver extends AbstractUnivariateSolver {
|
|||
max = m;
|
||||
}
|
||||
|
||||
if (FastMath.abs(max - min) <= absoluteAccuracy) {
|
||||
if (AccurateMath.abs(max - min) <= absoluteAccuracy) {
|
||||
m = UnivariateSolverUtils.midpoint(min, max);
|
||||
return m;
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue