Added examples module with a JMH examples module.
The JMH module contains a benchmark for all operations in Complex.
The examples are currently not included in the standard build. Travis
has been configured to compile them and apply apache-rat:check and
checkstyle:check to maintain the code consistency.
diff --git a/.travis.yml b/.travis.yml
index 54e6a5b..ae385db 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -25,6 +25,7 @@
script:
- mvn
+ - mvn -P commons-numbers-examples --projects commons-numbers-examples verify apache-rat:check checkstyle:check
after_success:
- mvn jacoco:report coveralls:report
diff --git a/commons-numbers-examples/LICENSE.txt b/commons-numbers-examples/LICENSE.txt
new file mode 100644
index 0000000..261eeb9
--- /dev/null
+++ b/commons-numbers-examples/LICENSE.txt
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/commons-numbers-examples/NOTICE.txt b/commons-numbers-examples/NOTICE.txt
new file mode 100644
index 0000000..b5e797a
--- /dev/null
+++ b/commons-numbers-examples/NOTICE.txt
@@ -0,0 +1,6 @@
+Apache Commons Numbers
+Copyright 2001-2020 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/commons-numbers-examples/README.md b/commons-numbers-examples/README.md
new file mode 100644
index 0000000..db1e452
--- /dev/null
+++ b/commons-numbers-examples/README.md
@@ -0,0 +1,92 @@
+<!---
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!---
+ +======================================================================+
+ |**** ****|
+ |**** THIS FILE IS GENERATED BY THE COMMONS BUILD PLUGIN ****|
+ |**** DO NOT EDIT DIRECTLY ****|
+ |**** ****|
+ +======================================================================+
+ | TEMPLATE FILE: readme-md-template.md |
+ | commons-build-plugin/trunk/src/main/resources/commons-xdoc-templates |
+ +======================================================================+
+ | |
+ | 1) Re-generate using: mvn commons-build:readme-md |
+ | |
+ | 2) Set the following properties in the component's pom: |
+ | - commons.componentid (required, alphabetic, lower case) |
+ | - commons.release.version (required) |
+ | |
+ | 3) Example Properties |
+ | |
+ | <properties> |
+ | <commons.componentid>math</commons.componentid> |
+ | <commons.release.version>1.2</commons.release.version> |
+ | </properties> |
+ | |
+ +======================================================================+
+--->
+Apache Commons Numbers Examples
+===================
+
+Examples of use of the "Commons Numbers" library.
+ Codes in this module and its sub-modules are not part of the library.
+ They provide checking, benchmarking tools to enhance the documentation
+ and to help ensure correctness of the implementations.
+
+Documentation
+-------------
+
+More information can be found on the [Apache Commons Numbers homepage](https://commons.apache.org/proper/commons-numbers).
+Questions related to the usage of Apache Commons Numbers should be posted to the [user mailing list][ml].
+
+Where can I get the latest release?
+-----------------------------------
+You can download source and binaries from our [download page](https://commons.apache.org/proper/commons-numbers/download_numbers.cgi).
+
+Contributing
+------------
+
+We accept Pull Requests via GitHub. The [developer mailing list][ml] is the main channel of communication for contributors.
+There are some guidelines which will make applying PRs easier for us:
++ No tabs! Please use spaces for indentation.
++ Respect the code style.
++ Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change.
++ Provide JUnit tests for your changes and make sure your changes don't break any existing tests by running ```mvn clean test```.
+
+If you plan to contribute on a regular basis, please consider filing a [contributor license agreement](https://www.apache.org/licenses/#clas).
+You can learn more about contributing via GitHub in our [contribution guidelines](CONTRIBUTING.md).
+
+License
+-------
+This code is under the [Apache Licence v2](https://www.apache.org/licenses/LICENSE-2.0).
+
+See the `NOTICE.txt` file for required notices and attributions.
+
+Donations
+---------
+You like Apache Commons Numbers? Then [donate back to the ASF](https://www.apache.org/foundation/contributing.html) to support the development.
+
+Additional Resources
+--------------------
+
++ [Apache Commons Homepage](https://commons.apache.org/)
++ [Apache Issue Tracker (JIRA)](https://issues.apache.org/jira/browse/NUMBERS)
++ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons)
++ `#apache-commons` IRC channel on `irc.freenode.org`
+
+[ml]:https://commons.apache.org/mail-lists.html
diff --git a/commons-numbers-examples/examples-jmh/LICENSE.txt b/commons-numbers-examples/examples-jmh/LICENSE.txt
new file mode 100644
index 0000000..261eeb9
--- /dev/null
+++ b/commons-numbers-examples/examples-jmh/LICENSE.txt
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/commons-numbers-examples/examples-jmh/NOTICE.txt b/commons-numbers-examples/examples-jmh/NOTICE.txt
new file mode 100644
index 0000000..b5e797a
--- /dev/null
+++ b/commons-numbers-examples/examples-jmh/NOTICE.txt
@@ -0,0 +1,6 @@
+Apache Commons Numbers
+Copyright 2001-2020 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/commons-numbers-examples/examples-jmh/README.md b/commons-numbers-examples/examples-jmh/README.md
new file mode 100644
index 0000000..28ab088
--- /dev/null
+++ b/commons-numbers-examples/examples-jmh/README.md
@@ -0,0 +1,90 @@
+<!---
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!---
+ +======================================================================+
+ |**** ****|
+ |**** THIS FILE IS GENERATED BY THE COMMONS BUILD PLUGIN ****|
+ |**** DO NOT EDIT DIRECTLY ****|
+ |**** ****|
+ +======================================================================+
+ | TEMPLATE FILE: readme-md-template.md |
+ | commons-build-plugin/trunk/src/main/resources/commons-xdoc-templates |
+ +======================================================================+
+ | |
+ | 1) Re-generate using: mvn commons-build:readme-md |
+ | |
+ | 2) Set the following properties in the component's pom: |
+ | - commons.componentid (required, alphabetic, lower case) |
+ | - commons.release.version (required) |
+ | |
+ | 3) Example Properties |
+ | |
+ | <properties> |
+ | <commons.componentid>math</commons.componentid> |
+ | <commons.release.version>1.2</commons.release.version> |
+ | </properties> |
+ | |
+ +======================================================================+
+--->
+Apache Commons Numbers JMH Benchmark
+===================
+
+Code for running JMH benchmarks that assess performance.
+ Code in this module is not part of the public API.
+
+Documentation
+-------------
+
+More information can be found on the [Apache Commons Numbers homepage](https://commons.apache.org/proper/commons-numbers).
+Questions related to the usage of Apache Commons Numbers should be posted to the [user mailing list][ml].
+
+Where can I get the latest release?
+-----------------------------------
+You can download source and binaries from our [download page](https://commons.apache.org/proper/commons-numbers/download_numbers.cgi).
+
+Contributing
+------------
+
+We accept Pull Requests via GitHub. The [developer mailing list][ml] is the main channel of communication for contributors.
+There are some guidelines which will make applying PRs easier for us:
++ No tabs! Please use spaces for indentation.
++ Respect the code style.
++ Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change.
++ Provide JUnit tests for your changes and make sure your changes don't break any existing tests by running ```mvn clean test```.
+
+If you plan to contribute on a regular basis, please consider filing a [contributor license agreement](https://www.apache.org/licenses/#clas).
+You can learn more about contributing via GitHub in our [contribution guidelines](CONTRIBUTING.md).
+
+License
+-------
+This code is under the [Apache Licence v2](https://www.apache.org/licenses/LICENSE-2.0).
+
+See the `NOTICE.txt` file for required notices and attributions.
+
+Donations
+---------
+You like Apache Commons Numbers? Then [donate back to the ASF](https://www.apache.org/foundation/contributing.html) to support the development.
+
+Additional Resources
+--------------------
+
++ [Apache Commons Homepage](https://commons.apache.org/)
++ [Apache Issue Tracker (JIRA)](https://issues.apache.org/jira/browse/NUMBERS)
++ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons)
++ `#apache-commons` IRC channel on `irc.freenode.org`
+
+[ml]:https://commons.apache.org/mail-lists.html
diff --git a/commons-numbers-examples/examples-jmh/pom.xml b/commons-numbers-examples/examples-jmh/pom.xml
new file mode 100644
index 0000000..11ce26a
--- /dev/null
+++ b/commons-numbers-examples/examples-jmh/pom.xml
@@ -0,0 +1,178 @@
+<?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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-examples</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>commons-numbers-examples-jmh</artifactId>
+ <name>Apache Commons Numbers JMH Benchmark</name>
+
+ <description>Code for running JMH benchmarks that assess performance.
+ Code in this module is not part of the public API.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-complex</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.openjdk.jmh</groupId>
+ <artifactId>jmh-core</artifactId>
+ <version>${jmh.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.openjdk.jmh</groupId>
+ <artifactId>jmh-generator-annprocess</artifactId>
+ <version>${jmh.version}</version>
+ </dependency>
+ </dependencies>
+
+ <properties>
+ <!-- OSGi -->
+ <commons.osgi.symbolicName>org.apache.commons.numbers.examples.jmh</commons.osgi.symbolicName>
+ <commons.osgi.export>org.apache.commons.numbers.examples.jmh</commons.osgi.export>
+ <!-- Java 9+ -->
+ <commons.automatic.module.name>org.apache.commons.numbers.examples.jmh</commons.automatic.module.name>
+ <!-- Workaround to avoid duplicating config files. -->
+ <numbers.parent.dir>${basedir}/../..</numbers.parent.dir>
+
+ <!-- JMH Benchmark related properties: version, name of the benchmarking uber jar. -->
+ <jmh.version>1.22</jmh.version>
+ <uberjar.name>examples-jmh</uberjar.name>
+ <project.mainClass>org.openjdk.jmh.Main</project.mainClass>
+ </properties>
+
+ <profiles>
+ <profile>
+ <!-- Run a named benchmark from maven. The class to run can be specified as a property
+ using -Dbenchmark=[XXX], for example:
+ mvn test -Pbenchmark -Dbenchmark=ComplexPerformance
+ -->
+ <id>benchmark</id>
+ <properties>
+ <skipTests>true</skipTests>
+ <benchmark>org.apache</benchmark>
+ <java.cmd>java</java.cmd>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <compilerVersion>${maven.compiler.target}</compilerVersion>
+ <source>${maven.compiler.target}</source>
+ <target>${maven.compiler.target}</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>benchmark</id>
+ <phase>test</phase>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ <configuration>
+ <classpathScope>test</classpathScope>
+ <executable>${java.cmd}</executable>
+ <arguments>
+ <argument>-classpath</argument>
+ <classpath />
+ <argument>${project.mainClass}</argument>
+ <argument>-rf</argument>
+ <argument>json</argument>
+ <argument>-rff</argument>
+ <argument>target/jmh-result.${benchmark}.json</argument>
+ <argument>${benchmark}</argument>
+ </arguments>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ <profile>
+ <!-- Build an executable jar that runs JMH:
+ mvn package -Pexamples-jmh
+
+ java -jar target/examples-jmh.jar -h
+ java -jar target/examples-jmh.jar ComplexPerformance -rf json -rff out.json
+ java -jar target/examples-jmh.jar ComplexPerformance.*cos*$ -p type=cis
+ -->
+ <id>examples-jmh</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <compilerVersion>${maven.compiler.target}</compilerVersion>
+ <source>${maven.compiler.target}</source>
+ <target>${maven.compiler.target}</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <finalName>${uberjar.name}</finalName>
+ <transformers>
+ <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+ <mainClass>${project.mainClass}</mainClass>
+ </transformer>
+ </transformers>
+ <filters>
+ <filter>
+ <!-- Shading signed JARs will fail without this. http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar -->
+ <artifact>*:*</artifact>
+ <excludes>
+ <exclude>META-INF/*.SF</exclude>
+ <exclude>META-INF/*.DSA</exclude>
+ <exclude>META-INF/*.RSA</exclude>
+ </excludes>
+ </filter>
+ </filters>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+</project>
diff --git a/commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/complex/ComplexPerformance.java b/commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/complex/ComplexPerformance.java
new file mode 100644
index 0000000..b22daf7
--- /dev/null
+++ b/commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/complex/ComplexPerformance.java
@@ -0,0 +1,628 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.numbers.examples.jmh.complex;
+
+import org.apache.commons.numbers.complex.Complex;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Param;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Warmup;
+
+import java.util.Arrays;
+import java.util.SplittableRandom;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiFunction;
+import java.util.function.Predicate;
+import java.util.function.Supplier;
+import java.util.function.ToDoubleFunction;
+import java.util.function.UnaryOperator;
+import java.util.stream.Stream;
+
+/**
+ * Executes a benchmark to measure the speed of operations in the {@link Complex} class.
+ */
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.NANOSECONDS)
+@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
+@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
+@State(Scope.Benchmark)
+@Fork(value = 1, jvmArgs = {"-server", "-Xms512M", "-Xmx512M"})
+public class ComplexPerformance {
+ /**
+ * An array of edge numbers that will produce edge case results from functions:
+ * {@code +/-inf, +/-max, +/-min, +/-0, nan}.
+ */
+ private static final double[] EDGE_NUMBERS = {
+ Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.MAX_VALUE,
+ -Double.MAX_VALUE, Double.MIN_VALUE, -Double.MIN_VALUE, 0.0, -0.0, Double.NaN};
+
+ /**
+ * Contains the size of numbers.
+ */
+ @State(Scope.Benchmark)
+ public static class ComplexNumberSize {
+ /**
+ * The size of the data.
+ */
+ @Param({"1000"})
+ private int size;
+
+ /**
+ * Gets the size.
+ *
+ * @return the size
+ */
+ public int getSize() {
+ return size;
+ }
+ }
+
+ /**
+ * Contains an array of complex numbers.
+ */
+ @State(Scope.Benchmark)
+ public static class ComplexNumbers extends ComplexNumberSize {
+ /** The numbers. */
+ protected Complex[] numbers;
+
+ /**
+ * The type of the data.
+ */
+ @Param({"cis", "random", "edge"})
+ private String type;
+
+ /**
+ * Gets the numbers.
+ *
+ * @return the numbers
+ */
+ public Complex[] getNumbers() {
+ return numbers;
+ }
+
+ /**
+ * Create the complex numbers.
+ */
+ @Setup
+ public void setup() {
+ numbers = createNumbers(new SplittableRandom());
+ }
+
+ /**
+ * Creates the numbers.
+ *
+ * @param rng Random number generator.
+ * @return the random complex number
+ */
+ Complex[] createNumbers(SplittableRandom rng) {
+ Supplier<Complex> generator;
+ if ("cis".equals(type)) {
+ generator = () -> Complex.ofCis(rng.nextDouble() * 2 * Math.PI);
+ } else if ("random".equals(type)) {
+ generator = () -> Complex.ofCartesian(createRandomNumber(rng), createRandomNumber(rng));
+ } else if ("edge".equals(type)) {
+ generator = () -> Complex.ofCartesian(createEdgeNumber(rng), createEdgeNumber(rng));
+ } else {
+ throw new IllegalStateException("Unknown number type: " + type);
+ }
+ return Stream.generate(generator).limit(getSize()).toArray(Complex[]::new);
+ }
+ }
+
+ /**
+ * Contains two arrays of complex numbers.
+ */
+ @State(Scope.Benchmark)
+ public static class TwoComplexNumbers extends ComplexNumbers {
+ /** The numbers. */
+ private Complex[] numbers2;
+
+ /**
+ * Gets the second set of numbers.
+ *
+ * @return the numbers
+ */
+ public Complex[] getNumbers2() {
+ return numbers2;
+ }
+
+ /**
+ * Create the complex numbers.
+ */
+ @Override
+ @Setup
+ public void setup() {
+ // Do not call super.setup() so we recycle the RNG and avoid duplicates
+ final SplittableRandom rng = new SplittableRandom();
+ numbers = createNumbers(rng);
+ numbers2 = createNumbers(rng);
+ }
+ }
+
+ /**
+ * Contains an array of complex numbers and an array of real numbers.
+ */
+ @State(Scope.Benchmark)
+ public static class ComplexAndRealNumbers extends ComplexNumbers {
+ /** The numbers. */
+ private double[] numbers2;
+
+ /**
+ * Gets the second set of numbers.
+ *
+ * @return the numbers
+ */
+ public double[] getNumbers2() {
+ return numbers2;
+ }
+
+ /**
+ * Create the complex numbers.
+ */
+ @Override
+ @Setup
+ public void setup() {
+ // Do not call super.setup() so we recycle the RNG and avoid duplicates
+ final SplittableRandom rng = new SplittableRandom();
+ numbers = createNumbers(rng);
+ numbers2 = Arrays.stream(createNumbers(rng)).mapToDouble(Complex::real).toArray();
+ }
+ }
+
+ /**
+ * Define a function between a complex and real number.
+ */
+ private interface ComplexRealFunction {
+ /**
+ * Applies this function to the given arguments.
+ *
+ * @param z the complex argument
+ * @param x the real argument
+ * @return the function result
+ */
+ Complex apply(Complex z, double x);
+ }
+
+ /**
+ * Creates a random double number with a random sign and mantissa and a large range for
+ * the exponent. The numbers will not be uniform over the range.
+ *
+ * @param rng Random number generator.
+ * @return the random number
+ */
+ private static double createRandomNumber(SplittableRandom rng) {
+ // Create random doubles using random bits in the sign bit and the mantissa.
+ // Then create an exponent in the range -64 to 64. Thus the sum product
+ // of 4 max or min values will not over or underflow.
+ final long mask = ((1L << 52) - 1) | 1L << 63;
+ final long bits = rng.nextLong() & mask;
+ // The exponent must be unsigned so + 1023 to the signed exponent
+ final long exp = rng.nextInt(129) - 64 + 1023;
+ return Double.longBitsToDouble(bits | (exp << 52));
+ }
+
+ /**
+ * Creates a random double number that will be an edge case:
+ * {@code +/-inf, +/-max, +/-min, +/-0, nan}.
+ *
+ * @param rng Random number generator.
+ * @return the random number
+ */
+ private static double createEdgeNumber(SplittableRandom rng) {
+ return EDGE_NUMBERS[rng.nextInt(EDGE_NUMBERS.length)];
+ }
+
+ /**
+ * Apply the function to all the numbers.
+ *
+ * @param numbers Numbers.
+ * @param fun Function.
+ * @return the result of the function.
+ */
+ private static boolean[] apply(Complex[] numbers, Predicate<Complex> fun) {
+ final boolean[] result = new boolean[numbers.length];
+ for (int i = 0; i < numbers.length; i++) {
+ result[i] = fun.test(numbers[i]);
+ }
+ return result;
+ }
+
+ /**
+ * Apply the function to all the numbers.
+ *
+ * @param numbers Numbers.
+ * @param fun Function.
+ * @return the result of the function.
+ */
+ private static double[] apply(Complex[] numbers, ToDoubleFunction<Complex> fun) {
+ final double[] result = new double[numbers.length];
+ for (int i = 0; i < numbers.length; i++) {
+ result[i] = fun.applyAsDouble(numbers[i]);
+ }
+ return result;
+ }
+
+ /**
+ * Apply the function to all the numbers.
+ *
+ * @param numbers Numbers.
+ * @param fun Function.
+ * @return the result of the function.
+ */
+ private static Complex[] apply(Complex[] numbers, UnaryOperator<Complex> fun) {
+ final Complex[] result = new Complex[numbers.length];
+ for (int i = 0; i < numbers.length; i++) {
+ result[i] = fun.apply(numbers[i]);
+ }
+ return result;
+ }
+
+ /**
+ * Apply the function to the paired numbers.
+ *
+ * @param numbers First numbers of the pairs.
+ * @param numbers2 Second numbers of the pairs.
+ * @param fun Function.
+ * @return the result of the function.
+ */
+ private static Complex[] apply(Complex[] numbers, Complex[] numbers2,
+ BiFunction<Complex, Complex, Complex> fun) {
+ final Complex[] result = new Complex[numbers.length];
+ for (int i = 0; i < numbers.length; i++) {
+ result[i] = fun.apply(numbers[i], numbers2[i]);
+ }
+ return result;
+ }
+
+ /**
+ * Apply the function to the paired numbers.
+ *
+ * @param numbers First numbers of the pairs.
+ * @param numbers2 Second numbers of the pairs.
+ * @param fun Function.
+ * @return the result of the function.
+ */
+ private static Complex[] apply(Complex[] numbers, double[] numbers2,
+ ComplexRealFunction fun) {
+ final Complex[] result = new Complex[numbers.length];
+ for (int i = 0; i < numbers.length; i++) {
+ result[i] = fun.apply(numbers[i], numbers2[i]);
+ }
+ return result;
+ }
+
+ /**
+ * Identity function. This can be used to measure overhead of object array creation.
+ *
+ * @param z Complex number.
+ * @return the complex number
+ */
+ private static Complex identity(Complex z) {
+ return z;
+ }
+
+ /**
+ * Copy function. This can be used to measure overhead of object array creation plus
+ * new Complex creation.
+ *
+ * @param z Complex number.
+ * @return a copy of the complex number
+ */
+ private static Complex copy(Complex z) {
+ return Complex.ofCartesian(z.real(), z.imag());
+ }
+
+ // Benchmark methods.
+ //
+ // The methods are partially documented as the names are self-documenting.
+ // CHECKSTYLE: stop JavadocMethod
+ // CHECKSTYLE: stop DesignForExtension
+ //
+ // Benchmarks use function references to perform different operations on the complex numbers.
+ // Tests show that explicit programming of the same benchmarks run in the same time.
+ // For reference examples are provided for the fastest operations: real() and conj().
+
+ /**
+ * Explicit benchmark without using a method reference.
+ * This should run in the same time as {@link #real(ComplexNumbers)}.
+ * This is commented out as it exists for reference purposes.
+ */
+ //@Benchmark
+ public double[] real2(ComplexNumbers numbers) {
+ final Complex[] z = numbers.getNumbers();
+ final double[] result = new double[z.length];
+ for (int i = 0; i < z.length; i++) {
+ result[i] = z[i].real();
+ }
+ return result;
+ }
+
+ /**
+ * Explicit benchmark without using a method reference.
+ * This should run in the same time as {@link #conj(ComplexNumbers)}.
+ * This is commented out as it exists for reference purposes.
+ */
+ //@Benchmark
+ public Complex[] conj2(ComplexNumbers numbers) {
+ final Complex[] z = numbers.getNumbers();
+ final Complex[] result = new Complex[z.length];
+ for (int i = 0; i < z.length; i++) {
+ result[i] = z[i].conj();
+ }
+ return result;
+ }
+
+ /**
+ * Baseline the creation of the new array of numbers.
+ * This contains the baseline JMH overhead for all the benchmarks that create complex numbers.
+ * All other methods are expected to be slower than this.
+ */
+ @Benchmark
+ public Complex[] baselineNewArray(ComplexNumberSize numberSize) {
+ return new Complex[numberSize.getSize()];
+ }
+
+ /**
+ * Baseline the creation of a copy array of numbers.
+ * This is commented out as it provides no information other than to demonstrate that
+ * {@link #baselineCopy(ComplexNumbers)} is not being optimised to a single array copy
+ * operation.
+ */
+ //@Benchmark
+ public Complex[] baselineCopyArray(ComplexNumbers numbers) {
+ return Arrays.copyOf(numbers.getNumbers(), numbers.getNumbers().length);
+ }
+
+ /**
+ * Baseline the creation of the new array of numbers with the same complex number (an identity).
+ *
+ * <p>Note: This runs much faster than {@link #baselineCopy(ComplexNumbers)}. This is
+ * attributed to the identity function not requiring that the fields of the
+ * complex are accessed unlike all other methods that do computations on the real and/or
+ * imaginary parts. The method is slower than a creation of a new empty array or a
+ * copy array thus contains the loop overhead of the benchmarks that create new numbers.
+ *
+ * @see #baselineNewArray(ComplexNumberSize)
+ * @see #baselineCopyArray(ComplexNumbers)
+ */
+ @Benchmark
+ public Complex[] baselineIdentity(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), ComplexPerformance::identity);
+ }
+
+ /**
+ * Baseline the creation of the new array of numbers with a copy complex number. This
+ * measures the overhead of creation of new complex numbers including field access
+ * to the real and imaginary parts.
+ */
+ @Benchmark
+ public Complex[] baselineCopy(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), ComplexPerformance::copy);
+ }
+
+ // Unary operations that return a boolean
+
+ @Benchmark
+ public boolean[] isNaN(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::isNaN);
+ }
+
+ @Benchmark
+ public boolean[] isInfinite(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::isInfinite);
+ }
+
+ @Benchmark
+ public boolean[] isFinite(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::isFinite);
+ }
+
+ // Unary operations that return a double
+
+ @Benchmark
+ public double[] real(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::real);
+ }
+
+ @Benchmark
+ public double[] imag(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::imag);
+ }
+
+ @Benchmark
+ public double[] abs(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::abs);
+ }
+
+ @Benchmark
+ public double[] arg(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::arg);
+ }
+
+ @Benchmark
+ public double[] norm(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::norm);
+ }
+
+ // Unary operations that return a complex number
+
+ @Benchmark
+ public Complex[] conj(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::conj);
+ }
+
+ @Benchmark
+ public Complex[] negate(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::negate);
+ }
+
+ @Benchmark
+ public Complex[] proj(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::proj);
+ }
+
+ @Benchmark
+ public Complex[] cos(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::cos);
+ }
+
+ @Benchmark
+ public Complex[] cosh(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::cosh);
+ }
+
+ @Benchmark
+ public Complex[] exp(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::exp);
+ }
+
+ @Benchmark
+ public Complex[] log(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::log);
+ }
+
+ @Benchmark
+ public Complex[] log10(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::log10);
+ }
+
+ @Benchmark
+ public Complex[] sin(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::sin);
+ }
+
+ @Benchmark
+ public Complex[] sinh(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::sinh);
+ }
+
+ @Benchmark
+ public Complex[] sqrt(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::sqrt);
+ }
+
+ @Benchmark
+ public Complex[] tan(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::tan);
+ }
+
+ @Benchmark
+ public Complex[] tanh(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::tanh);
+ }
+
+ @Benchmark
+ public Complex[] acos(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::acos);
+ }
+
+ @Benchmark
+ public Complex[] acosh(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::acosh);
+ }
+
+ @Benchmark
+ public Complex[] asin(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::asin);
+ }
+
+ @Benchmark
+ public Complex[] asinh(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::asinh);
+ }
+
+ @Benchmark
+ public Complex[] atan(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::atan);
+ }
+
+ @Benchmark
+ public Complex[] atanh(ComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), Complex::atanh);
+ }
+
+ // Binary operations on two complex numbers.
+
+ @Benchmark
+ public Complex[] pow(TwoComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), numbers.getNumbers2(), Complex::pow);
+ }
+
+ @Benchmark
+ public Complex[] multiply(TwoComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), numbers.getNumbers2(), Complex::multiply);
+ }
+
+ @Benchmark
+ public Complex[] divide(TwoComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), numbers.getNumbers2(), Complex::divide);
+ }
+
+ @Benchmark
+ public Complex[] add(TwoComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), numbers.getNumbers2(), Complex::add);
+ }
+
+ @Benchmark
+ public Complex[] subtract(TwoComplexNumbers numbers) {
+ return apply(numbers.getNumbers(), numbers.getNumbers2(), Complex::subtract);
+ }
+
+ // Binary operations on a complex and a real number.
+ // These only benchmark methods on the real component as the
+ // following are expected to be the same speed as the real-only operations
+ // given the equivalent primitive operations:
+ // - multiplyImaginary
+ // - divideImaginary
+ // - addImaginary
+ // - subtractImaginary
+ // - subtractFrom
+ // - subtractFromImaginary
+
+ @Benchmark
+ public Complex[] powReal(ComplexAndRealNumbers numbers) {
+ return apply(numbers.getNumbers(), numbers.getNumbers2(), Complex::pow);
+ }
+
+ @Benchmark
+ public Complex[] multiplyReal(ComplexAndRealNumbers numbers) {
+ return apply(numbers.getNumbers(), numbers.getNumbers2(), Complex::multiply);
+ }
+
+ @Benchmark
+ public Complex[] divideReal(ComplexAndRealNumbers numbers) {
+ return apply(numbers.getNumbers(), numbers.getNumbers2(), Complex::divide);
+ }
+
+ @Benchmark
+ public Complex[] addReal(ComplexAndRealNumbers numbers) {
+ return apply(numbers.getNumbers(), numbers.getNumbers2(), Complex::add);
+ }
+
+ @Benchmark
+ public Complex[] subtractReal(ComplexAndRealNumbers numbers) {
+ return apply(numbers.getNumbers(), numbers.getNumbers2(), Complex::subtract);
+ }
+}
diff --git a/commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/complex/package-info.java b/commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/complex/package-info.java
new file mode 100644
index 0000000..cbd5687
--- /dev/null
+++ b/commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/complex/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Benchmarks for the {@code org.apache.commons.numbers.complex} components.
+ */
+
+package org.apache.commons.numbers.examples.jmh.complex;
diff --git a/commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/package-info.java b/commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/package-info.java
new file mode 100644
index 0000000..8451e6c
--- /dev/null
+++ b/commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/package-info.java
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+/**
+ * <h3>Performance benchmarks</h3>
+ *
+ * <p>
+ * This package contains code to perform a
+ * <a href="http://openjdk.java.net/projects/code-tools/jmh">JMH</a> run.
+ * </p>
+ */
+package org.apache.commons.numbers.examples.jmh;
diff --git a/commons-numbers-examples/pom.xml b/commons-numbers-examples/pom.xml
new file mode 100644
index 0000000..8366c4d
--- /dev/null
+++ b/commons-numbers-examples/pom.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-numbers-parent</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>commons-numbers-examples</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache Commons Numbers Examples</name>
+
+ <description>Examples of use of the "Commons Numbers" library.
+ Codes in this module and its sub-modules are not part of the library.
+ They provide checking, benchmarking tools to enhance the documentation
+ and to help ensure correctness of the implementations.</description>
+
+ <properties>
+ <!-- OSGi -->
+ <commons.osgi.symbolicName>org.apache.commons.numbers.examples</commons.osgi.symbolicName>
+ <commons.osgi.export>org.apache.commons.numbers.examples</commons.osgi.export>
+ <!-- Java 9+ -->
+ <commons.automatic.module.name>org.apache.commons.numbers.examples</commons.automatic.module.name>
+ <!-- Workaround to avoid duplicating config files. -->
+ <numbers.parent.dir>${basedir}/..</numbers.parent.dir>
+
+ <!-- Disable JApiCmp failures (but keep the report). The examples API is allowed to change. -->
+ <commons.japicmp.breakBuildOnBinaryIncompatibleModifications>false</commons.japicmp.breakBuildOnBinaryIncompatibleModifications>
+ <commons.japicmp.breakBuildOnSourceIncompatibleModifications>false</commons.japicmp.breakBuildOnSourceIncompatibleModifications>
+ </properties>
+
+ <modules>
+ <module>examples-jmh</module>
+ </modules>
+</project>
diff --git a/pom.xml b/pom.xml
index af4c73a..798e3d5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -654,6 +654,15 @@
</plugins>
</build>
</profile>
+ <!--
+ Profiles for modules with special requirements.
+ -->
+ <profile>
+ <id>commons-numbers-examples</id>
+ <modules>
+ <module>commons-numbers-examples</module>
+ </modules>
+ </profile>
</profiles>
<developers>