pax_global_header00006660000000000000000000000064150721236630014517gustar00rootroot0000000000000052 comment=a9b332814da12ad22831979ffecf85f9df1494a2 gcem-1.18.0/000077500000000000000000000000001507212366300125215ustar00rootroot00000000000000gcem-1.18.0/.appveyor.yml000066400000000000000000000020731507212366300151710ustar00rootroot00000000000000build: false os: Visual Studio 2015 platform: - x64 - x86 environment: matrix: - MINICONDA: C:\gcem-conda init: - "ECHO %MINICONDA%" - C:\"Program Files (x86)"\"Microsoft Visual Studio 14.0"\VC\vcvarsall.bat %PLATFORM% - ps: if($env:Platform -eq "x64"){Start-FileDownload 'http://repo.continuum.io/miniconda/Miniconda3-latest-Windows-x86_64.exe' C:\Miniconda.exe; echo "Done"} - ps: if($env:Platform -eq "x86"){Start-FileDownload 'http://repo.continuum.io/miniconda/Miniconda3-latest-Windows-x86.exe' C:\Miniconda.exe; echo "Done"} - cmd: C:\Miniconda.exe /S /D=C:\gcem-conda - "set PATH=%MINICONDA%;%MINICONDA%\\Scripts;%MINICONDA%\\Library\\bin;%PATH%" install: - conda config --set always_yes yes --set changeps1 no - conda update -q conda - conda info -a - conda install cmake -c conda-forge - cmake -G "NMake Makefiles" -D GCEM_BUILD_TESTS=1 -D CMAKE_INSTALL_PREFIX=%MINICONDA%\\LIBRARY -D CMAKE_BUILD_TYPE=Release . - nmake gcem_tests build_script: - cd tests - cmd: dir - cmd: for %%f in (*.test.exe) do ( echo %%~nf && .\%%~nf ) gcem-1.18.0/.github/000077500000000000000000000000001507212366300140615ustar00rootroot00000000000000gcem-1.18.0/.github/workflows/000077500000000000000000000000001507212366300161165ustar00rootroot00000000000000gcem-1.18.0/.github/workflows/main.yml000066400000000000000000000106731507212366300175740ustar00rootroot00000000000000 # modified version of: # https://gist.github.com/NickNaso/0d478f1481686d5bcc868cac06620a60 name: CI on: [push, pull_request, release] jobs: build: name: ${{ matrix.config.name }} runs-on: ${{ matrix.config.os }} strategy: fail-fast: false matrix: config: - { name: "ubuntu_latest_gcc_cxx11", os: ubuntu-latest, build_type: "Release", cc: "gcc", cxx: "g++", cxxstd: "11" } - { name: "ubuntu_latest_gcc_cxx11_coverage", os: ubuntu-latest, build_type: "Coverage", cc: "gcc", cxx: "g++", cxxstd: "11" } - { name: "ubuntu_latest_gcc9_cxx14", os: ubuntu-latest, build_type: "Release", cc: "gcc-9", cxx: "g++-9", cxxstd: "14" } - { name: "ubuntu_latest_gcc10_cxx14", os: ubuntu-latest, build_type: "Release", cc: "gcc-10", cxx: "g++-10", cxxstd: "14" } - { name: "ubuntu_latest_gcc11_cxx17", os: ubuntu-latest, build_type: "Release", cc: "gcc-11", cxx: "g++-11", cxxstd: "17" } - { name: "ubuntu_latest_gcc11_cxx20", os: ubuntu-latest, build_type: "Release", cc: "gcc-11", cxx: "g++-11", cxxstd: "20" } - { name: "ubuntu_latest_clang11_cxx11", os: ubuntu-latest, build_type: "Release", cc: "clang-11", cxx: "clang++-11", cxxstd: "11" } - { name: "ubuntu_latest_clang11_cxx14", os: ubuntu-latest, build_type: "Release", cc: "clang-11", cxx: "clang++-11", cxxstd: "14" } - { name: "ubuntu_latest_clang12_cxx14", os: ubuntu-latest, build_type: "Release", cc: "clang-12", cxx: "clang++-12", cxxstd: "14" } - { name: "ubuntu22_clang13_cxx17", os: ubuntu-22.04, build_type: "Release", cc: "clang-13", cxx: "clang++-13", cxxstd: "17" } - { name: "ubuntu22_clang14_cxx20", os: ubuntu-22.04, build_type: "Release", cc: "clang-14", cxx: "clang++-14", cxxstd: "20" } - { name: "macos_latest_clang_cxx11", os: macos-latest, build_type: "Release", cc: "clang", cxx: "clang++", cxxstd: "11" } steps: - uses: actions/checkout@v2 - name: Print env run: | echo github.event.action: ${{ github.event.action }} echo github.event_name: ${{ github.event_name }} - name: Install dependencies on ubuntu if: startsWith(matrix.config.name, 'ubuntu') run: | sudo apt-get update sudo apt-get install ${{ matrix.config.cc }} ${{ matrix.config.cxx }} ${{ matrix.config.cc }} --version echo "CXXT=${{ matrix.config.cxxstd }}" >> $GITHUB_ENV - name: Tests shell: bash working-directory: tests run: | export CC=${{ matrix.config.cc }} export CXX=${{ matrix.config.cxx }} export GCEM_CXX_STD="-std=c++${{ matrix.config.cxxstd }}" echo "Testing CXXT: ${CXXT}" echo "Testing env.CXXT: ${{ env.CXXT }}" make ./run_tests - name: Coverage if: startsWith(matrix.config.build_type, 'Coverage') shell: bash working-directory: tests run: | export SHOULD_RUN_COVERAGE="y" ./cov_check cd .. curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --keyring trustedkeys.gpg --import curl -Os https://uploader.codecov.io/latest/linux/codecov curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig gpgv codecov.SHA256SUM.sig codecov.SHA256SUM shasum -a 256 -c codecov.SHA256SUM chmod +x codecov ./codecov gcem-1.18.0/.gitignore000066400000000000000000000002151507212366300145070ustar00rootroot00000000000000.DS_Store .ipynb_checkpoints .Rproj.user .Rhistory build docs/xml *.dll *.exe *.log *.lp *.o *.so *.test *.vscode *.gcda *.gcno *.gcov *.dSYMgcem-1.18.0/.lgtm.yml000066400000000000000000000001761507212366300142710ustar00rootroot00000000000000 path_classifiers: test: - tests extraction: cpp: index: build_command: - cd ./tests - make gcem-1.18.0/.readthedocs.requirements.txt000066400000000000000000000002141507212366300203440ustar00rootroot00000000000000sphinx == 5.1.1 breathe == 4.34.0 sphinx-rtd-theme == 1.0.0 sphinxcontrib-katex == 0.8.6 sphinxcontrib-contentui == 0.2.5 docutils == 0.17.1gcem-1.18.0/.readthedocs.yml000066400000000000000000000002151507212366300156050ustar00rootroot00000000000000version: 2 build: os: "ubuntu-22.04" tools: python: "mambaforge-22.9" formats: - pdf conda: environment: docs/environment.yml gcem-1.18.0/.travis.yml000066400000000000000000000131131507212366300146310ustar00rootroot00000000000000 language: c++ sudo: required matrix: include: - os: linux dist: bionic addons: apt: packages: - g++-5 sources: &sources - ubuntu-toolchain-r-test env: - MATRIX_EVAL="CC=gcc-5 && CXX=g++-5" compiler: gcc - os: linux dist: bionic addons: apt: packages: - g++-6 sources: &sources - ubuntu-toolchain-r-test env: - MATRIX_EVAL="CC=gcc-6 && CXX=g++-6" compiler: gcc - os: linux dist: bionic addons: apt: packages: - g++-7 sources: &sources - ubuntu-toolchain-r-test env: - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7" - CCOV=gcov-7 - SHOULD_RUN_COVERAGE="y" compiler: gcc - os: linux dist: bionic addons: apt: packages: - g++-8 sources: &sources - ubuntu-toolchain-r-test env: - MATRIX_EVAL="CC=gcc-8 && CXX=g++-8" compiler: gcc - os: linux dist: bionic addons: apt: packages: - g++-8 sources: &sources - ubuntu-toolchain-r-test env: - MATRIX_EVAL="CC=gcc-8 && CXX=g++-8" - GCEM_CXX_STD="-std=c++14" compiler: gcc - os: linux dist: bionic addons: apt: packages: - g++-8 sources: &sources - ubuntu-toolchain-r-test env: - MATRIX_EVAL="CC=gcc-8 && CXX=g++-8" - GCEM_CXX_STD="-std=c++17" compiler: gcc - os: linux dist: bionic addons: apt: packages: - g++-9 sources: &sources - ubuntu-toolchain-r-test env: - MATRIX_EVAL="CC=gcc-9 && CXX=g++-9" - GCEM_CXX_STD="-std=c++17" compiler: gcc - os: linux dist: bionic addons: apt: packages: - clang-5.0 sources: &sources - llvm-toolchain-bionic-5.0 env: - MATRIX_EVAL="CC=clang-5.0 && CXX=clang++-5.0" - TRAVIS_CLANG_BUILD="y" compiler: clang - os: linux dist: bionic addons: apt: packages: - clang-6.0 sources: &sources - llvm-toolchain-bionic-6.0 - sourceline: 'ppa:ubuntu-toolchain-r/test' env: - MATRIX_EVAL="CC=clang-6.0 && CXX=clang++-6.0" - TRAVIS_CLANG_BUILD="y" compiler: clang - os: linux dist: bionic addons: apt: packages: - clang-7 sources: &sources - llvm-toolchain-bionic-7 - sourceline: 'ppa:ubuntu-toolchain-r/test' env: - MATRIX_EVAL="CC=clang-7 && CXX=clang++-7" - TRAVIS_CLANG_BUILD="y" compiler: clang - os: linux dist: bionic addons: apt: packages: - clang-8 sources: &sources - llvm-toolchain-bionic-8 - sourceline: 'ppa:ubuntu-toolchain-r/test' env: - MATRIX_EVAL="CC=clang-8 && CXX=clang++-8" - TRAVIS_CLANG_BUILD="y" compiler: clang - os: linux dist: bionic addons: apt: packages: - clang-9 sources: &sources - llvm-toolchain-bionic-9 - sourceline: 'ppa:ubuntu-toolchain-r/test' env: - MATRIX_EVAL="CC=clang-9 && CXX=clang++-9" - TRAVIS_CLANG_BUILD="y" compiler: clang - os: linux dist: bionic addons: apt: packages: - clang-10 sources: &sources - ubuntu-toolchain-r-test - sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main' key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' env: - MATRIX_EVAL="CC=clang-10 && CXX=clang++-10" - TRAVIS_CLANG_BUILD="y" compiler: clang - os: linux dist: bionic addons: apt: packages: - clang-11 sources: &sources - ubuntu-toolchain-r-test - sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main' key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' env: - MATRIX_EVAL="CC=clang-11 && CXX=clang++-11" - TRAVIS_CLANG_BUILD="y" compiler: clang - os: linux dist: bionic addons: apt: packages: - clang-11 sources: &sources - ubuntu-toolchain-r-test - sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main' key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' env: - MATRIX_EVAL="CC=clang-11 && CXX=clang++-11" - TRAVIS_CLANG_BUILD="y" - GCEM_CXX_STD="-std=c++20" compiler: clang - os: osx osx_image: xcode9 env: - MATRIX_EVAL="CC=clang && CXX=clang++" compiler: clang before_install: - eval "${MATRIX_EVAL}" install: - | if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then sudo apt-get update # else # OSX # brew upgrade gcc || brew install gcc fi script: - cd ./tests && make - ./run_tests - ./cov_check - cd .. after_success: - | if [[ "${SHOULD_RUN_COVERAGE}" == "y" ]]; then alias gcov=$CCOV bash <(curl -s https://codecov.io/bash) -x $CCOV fi after_failure: - ./travis-tool.sh dump_logs notifications: email: on_success: change on_failure: change gcem-1.18.0/CMakeLists.txt000066400000000000000000000066401507212366300152670ustar00rootroot00000000000000################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################ cmake_minimum_required(VERSION 3.1) project(gcem) set(GCEM_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include) # file(STRINGS "${GCEM_INCLUDE_DIR}/gcem_incl/gcem_options.hpp" gcem_version_defines REGEX "#define GCEM_VERSION_(MAJOR|MINOR|PATCH)") foreach(ver ${gcem_version_defines}) if(ver MATCHES "#define GCEM_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$") set(GCEM_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "") endif() endforeach() set(${PROJECT_NAME}_VERSION ${GCEM_VERSION_MAJOR}.${GCEM_VERSION_MINOR}.${GCEM_VERSION_PATCH}) message(STATUS "GCE-Math version ${${PROJECT_NAME}_VERSION}") # if(NOT MSVC) include(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) if(COMPILER_SUPPORTS_CXX11) message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has C++11 support.") else() message(FATAL_ERROR "Unsupported compiler ${CMAKE_CXX_COMPILER} " "GCEM requires a C++11-compatible compiler.") endif() endif() # options. enable using cmake3 -DGCEM_BUILD_TESTS=ON OPTION(GCEM_BUILD_TESTS "gcem test suite" OFF) # install add_library(gcem INTERFACE) target_include_directories(gcem INTERFACE $ $) if(GCEM_BUILD_TESTS) add_subdirectory(tests) endif() # include(CMakePackageConfigHelpers) include(GNUInstallDirs) install( TARGETS gcem EXPORT ${PROJECT_NAME}-targets ) export(EXPORT ${PROJECT_NAME}-targets FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake") install(DIRECTORY ${GCEM_INCLUDE_DIR}/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) # set(GCEM_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE STRING "install path for gcemConfig.cmake") configure_package_config_file(cmake_files/${PROJECT_NAME}Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" INSTALL_DESTINATION ${GCEM_CMAKECONFIG_INSTALL_DIR}) write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake VERSION ${${PROJECT_NAME}_VERSION} COMPATIBILITY SameMajorVersion) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake DESTINATION ${GCEM_CMAKECONFIG_INSTALL_DIR}) install(EXPORT ${PROJECT_NAME}-targets FILE ${PROJECT_NAME}Targets.cmake DESTINATION ${GCEM_CMAKECONFIG_INSTALL_DIR}) gcem-1.18.0/LICENSE000066400000000000000000000261351507212366300135350ustar00rootroot00000000000000 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.gcem-1.18.0/NOTICE.txt000066400000000000000000000002651507212366300142460ustar00rootroot00000000000000GCE-Math: A C++ generalized constant expression-based math library Copyright 2016-2024 Keith O'Hara This product includes software developed by Keith O'Hara (http://www.kthohr.com)gcem-1.18.0/README.md000066400000000000000000000150721507212366300140050ustar00rootroot00000000000000# GCE-Math [![Build Status](https://github.com/kthohr/gcem/actions/workflows/main.yml/badge.svg)](https://github.com/kthohr/gcem/actions/workflows/main.yml) [![Build status](https://ci.appveyor.com/api/projects/status/5kxxkmisln1j4h6b?svg=true)](https://ci.appveyor.com/project/kthohr/gcem) [![Coverage Status](https://codecov.io/github/kthohr/gcem/coverage.svg?branch=master)](https://codecov.io/github/kthohr/gcem?branch=master) [![Documentation Status](https://readthedocs.org/projects/gcem/badge/?version=latest)](https://gcem.readthedocs.io/en/latest/?badge=latest) GCE-Math (**G**eneralized **C**onstant **E**xpression Math) is a templated C++ library enabling compile-time computation of mathematical functions. Features: * The library is written in C++11 `constexpr` format, and is C++11/14/17/20 compatible. * Continued fraction expansions and series expansions are implemented using recursive templates. * The `gcem::` syntax is identical to that of the C++ standard library (`std::`). * Tested and accurate to floating-point precision against the C++ standard library. * Released under a permissive, non-GPL license. **Author**: Keith O'Hara [![License](https://img.shields.io/badge/Licence-Apache%202.0-blue.svg)](./LICENSE) ### Contents: * [Status and Documentation](#status-and-documentation) * [Installation](#installation) * [Test Suite](#test-suite) * [Jupyter Notebook](#jupyter-notebook) * [General Syntax](#general-syntax) * [Examples](#examples) ## Status and Documentation The library is actively maintained and is still being extended. A list of features includes: * Basic library functions: - `abs`, `max`, `min`, `pow`, `sqrt`, `inv_sqrt`, - `ceil`, `floor`, `round`, `trunc`, `fmod`, - `exp`, `expm1`, `log`, `log1p`, `log2`, `log10`, and more * Trigonometric functions: - basic: `cos`, `sin`, `tan` - inverse: `acos`, `asin`, `atan`, `atan2` * Hyperbolic (area) functions: - `cosh`, `sinh`, `tanh`, `acosh`, `asinh`, `atanh` * Algorithms: - `gcd`, `lcm` * Special functions: - factorials and the binomial coefficient: `factorial`, `binomial_coef` - beta, gamma, and multivariate gamma functions: `beta`, `lbeta`, `lgamma`, `tgamma`, `lmgamma` - the Gaussian error function and inverse error function: `erf`, `erf_inv` - (regularized) incomplete beta and incomplete gamma functions: `incomplete_beta`, `incomplete_gamma` - inverse incomplete beta and incomplete gamma functions: `incomplete_beta_inv`, `incomplete_gamma_inv` Full documentation is available online: [![Documentation Status](https://readthedocs.org/projects/gcem/badge/?version=latest)](https://gcem.readthedocs.io/en/latest/?badge=latest) A PDF version of the documentation is available [here](https://buildmedia.readthedocs.org/media/pdf/gcem/latest/gcem.pdf). ## Installation GCE-Math is a header-only library and does not require any additional libraries or utilities (beyond a C++11 compatible compiler). Simply add the header files to your project using: ```cpp #include "gcem.hpp" ``` ### Conda [![Anaconda-Server Badge](https://anaconda.org/conda-forge/gcem/badges/version.svg)](https://anaconda.org/conda-forge/gcem) [![Anaconda-Server Badge](https://anaconda.org/conda-forge/gcem/badges/platforms.svg)](https://anaconda.org/conda-forge/gcem) You can install GCE-Math using the Conda package manager. ```bash conda install -c conda-forge gcem ``` ### CMake You can also install the library from source using CMake. ```bash # clone gcem from GitHub git clone https://github.com/kthohr/gcem ./gcem # make a build directory cd ./gcem mkdir build cd build # generate Makefiles and install cmake .. -DCMAKE_INSTALL_PREFIX=/gcem/install/location make install ``` For example, `/gcem/install/location` could be `/usr/local/`. ## Test Suite There are two ways to build the test suite. On Unix-alike systems, a Makefile is available under `tests/`. ```bash cd ./gcem/tests make ./run_tests ``` With CMake, the option `GCEM_BUILD_TESTS=1` generates the necessary Makefiles to build the test suite. ```bash cd ./gcem mkdir build cd build cmake ../ -DGCEM_BUILD_TESTS=1 -DCMAKE_INSTALL_PREFIX=/gcem/install/location make gcem_tests cd tests ./exp.test ``` ## Jupyter Notebook You can test the library online using an interactive Jupyter notebook: [![Binder](https://mybinder.org/badge.svg)](https://mybinder.org/v2/gh/kthohr/gcem/master?filepath=notebooks%2Fgcem.ipynb) ## General Syntax GCE-Math functions are written as C++ templates with `constexpr` specifiers, the format of which might appear confusing to users unfamiliar with template-based programming. For example, the [Gaussian error function](https://en.wikipedia.org/wiki/Error_function) (`erf`) is defined as: ```cpp template constexpr return_t erf(const T x) noexcept; ``` A set of internal templated `constexpr` functions will implement a continued fraction expansion and return a value of type `return_t`. The output type ('`return_t`') is generally determined by the input type, e.g., `int`, `float`, `double`, `long double`, etc.; when `T` is an integral type, the output will be upgraded to `return_t = double`, otherwise `return_t = T`. For types not covered by `std::is_integral`, recasts should be used. ## Examples To calculate 10!: ```cpp #include "gcem.hpp" int main() { constexpr int x = 10; constexpr int res = gcem::factorial(x); return 0; } ``` Inspecting the assembly code generated by Clang 7.0.0: ```assembly push rbp mov rbp, rsp xor eax, eax mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], 10 mov dword ptr [rbp - 12], 3628800 pop rbp ret ``` We see that a function call has been replaced by a numeric value (10! = 3628800). Similarly, to compute the log Gamma function at a point: ```cpp #include "gcem.hpp" int main() { constexpr long double x = 1.5; constexpr long double res = gcem::lgamma(x); return 0; } ``` Assembly code: ```assembly .LCPI0_0: .long 1069547520 # float 1.5 .LCPI0_1: .quad -622431863250842976 # x86_fp80 -0.120782237635245222719 .short 49147 .zero 6 main: # @main push rbp mov rbp, rsp xor eax, eax mov dword ptr [rbp - 4], 0 fld dword ptr [rip + .LCPI0_0] fstp tbyte ptr [rbp - 32] fld tbyte ptr [rip + .LCPI0_1] fstp tbyte ptr [rbp - 48] pop rbp ret ``` ## Related libraries * [StatsLib](https://github.com/kthohr/stats) is built on GCEM's compile-time functionality. gcem-1.18.0/binder/000077500000000000000000000000001507212366300137645ustar00rootroot00000000000000gcem-1.18.0/binder/environment.yml000066400000000000000000000001561507212366300170550ustar00rootroot00000000000000# For use with Binder name: statslib channels: - conda-forge dependencies: - xeus-cling=0.8.1 - notebookgcem-1.18.0/cmake_files/000077500000000000000000000000001507212366300147635ustar00rootroot00000000000000gcem-1.18.0/cmake_files/gcemConfig.cmake.in000066400000000000000000000020311507212366300204270ustar00rootroot00000000000000################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################ @PACKAGE_INIT@ if(NOT TARGET @PROJECT_NAME@) include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") get_target_property(@PROJECT_NAME@_INCLUDE_DIRS gcem INTERFACE_INCLUDE_DIRECTORIES) endif() gcem-1.18.0/contributors.txt000066400000000000000000000002221507212366300160130ustar00rootroot00000000000000External contributions to GCEM ---- 2018-08-02 @jonathansharman - atan2 implementation 2018-07-13 @cpsauer - fix bug in binomial_coef gcem-1.18.0/docs/000077500000000000000000000000001507212366300134515ustar00rootroot00000000000000gcem-1.18.0/docs/Doxyfile000066400000000000000000000004771507212366300151670ustar00rootroot00000000000000PROJECT_NAME = "gcem" XML_OUTPUT = xml INPUT = ../include GENERATE_LATEX = NO GENERATE_MAN = NO GENERATE_RTF = NO CASE_SENSE_NAMES = NO GENERATE_HTML = NO GENERATE_XML = YES RECURSIVE = YES QUIET = YES JAVADOC_AUTOBRIEF = YES WARN_IF_UNDOCUMENTED = NO gcem-1.18.0/docs/Makefile000066400000000000000000000147261507212366300151230ustar00rootroot00000000000000# You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build PAPER = BUILDDIR = build # User-friendly check for sphinx-build ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) endif # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_letter = -D latex_paper_size=letter ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source # the i18n builder cannot share the environment and doctrees with the others I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest coverage gettext api default: html help: @echo "Please use \`make ' where is one of" @echo " html to make standalone HTML files" @echo " dirhtml to make HTML files named index.html in directories" @echo " singlehtml to make a single large HTML file" @echo " pickle to make pickle files" @echo " json to make JSON files" @echo " htmlhelp to make HTML files and a HTML help project" @echo " qthelp to make HTML files and a qthelp project" @echo " applehelp to make an Apple Help Book" @echo " devhelp to make HTML files and a Devhelp project" @echo " epub to make an epub" @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" @echo " latexpdf to make LaTeX files and run them through pdflatex" @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" @echo " text to make text files" @echo " man to make manual pages" @echo " texinfo to make Texinfo files" @echo " info to make Texinfo files and run them through makeinfo" @echo " gettext to make PO message catalogs" @echo " changes to make an overview of all changed/added/deprecated items" @echo " xml to make Docutils-native XML files" @echo " pseudoxml to make pseudoxml-XML files for display purposes" @echo " linkcheck to check all external links for integrity" @echo " doctest to run all doctests embedded in the documentation (if enabled)" @echo " coverage to run coverage check of the documentation (if enabled)" clean: rm -rf $(BUILDDIR)/* html: doxygen $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." dirhtml: doxygen $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." singlehtml: doxygen $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml @echo @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." pickle: doxygen $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle @echo @echo "Build finished; now you can process the pickle files." json: doxygen $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json @echo @echo "Build finished; now you can process the JSON files." htmlhelp: doxygen $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp @echo @echo "Build finished; now you can run HTML Help Workshop with the" \ ".hhp project file in $(BUILDDIR)/htmlhelp." epub: doxygen $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub @echo @echo "Build finished. The epub file is in $(BUILDDIR)/epub." latex: doxygen $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." @echo "Run \`make' in that directory to run these through (pdf)latex" \ "(use \`make latexpdf' here to do that automatically)." latexpdf: doxygen $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through pdflatex..." $(MAKE) -C $(BUILDDIR)/latex all-pdf @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." latexpdfja: doxygen $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through platex and dvipdfmx..." $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." text: doxygen $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text @echo @echo "Build finished. The text files are in $(BUILDDIR)/text." man: doxygen $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man @echo @echo "Build finished. The manual pages are in $(BUILDDIR)/man." texinfo: doxygen $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." @echo "Run \`make' in that directory to run these through makeinfo" \ "(use \`make info' here to do that automatically)." info: doxygen $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo "Running Texinfo files through makeinfo..." make -C $(BUILDDIR)/texinfo info @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." gettext: doxygen $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale @echo @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." changes: doxygen $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes @echo @echo "The overview file is in $(BUILDDIR)/changes." linkcheck: doxygen $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck @echo @echo "Link check complete; look for any errors in the above output " \ "or in $(BUILDDIR)/linkcheck/output.txt." doctest: doxygen $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest @echo "Testing of doctests in the sources finished, look at the " \ "results in $(BUILDDIR)/doctest/output.txt." coverage: doxygen $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage @echo "Testing of coverage in the sources finished, look at the " \ "results in $(BUILDDIR)/coverage/python.txt." xml: doxygen $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml @echo @echo "Build finished. The XML files are in $(BUILDDIR)/xml." pseudoxml: doxygen $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml @echo @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." gcem-1.18.0/docs/environment.yml000066400000000000000000000003761507212366300165460ustar00rootroot00000000000000 name: optimlib-docs channels: - conda-forge dependencies: - doxygen=1.9.3 - pip: - sphinx==5.1.1 - breathe==4.34.0 - sphinx-rtd-theme==1.0.0 - sphinxcontrib-katex==0.8.6 - sphinxcontrib-contentui==0.2.5 - docutils==0.17.1gcem-1.18.0/docs/make.bat000066400000000000000000000161651507212366300150670ustar00rootroot00000000000000@ECHO OFF REM Command file for Sphinx documentation if "%SPHINXBUILD%" == "" ( set SPHINXBUILD=sphinx-build ) set BUILDDIR=build set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% source set I18NSPHINXOPTS=%SPHINXOPTS% source if NOT "%PAPER%" == "" ( set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% ) if "%1" == "" goto help if "%1" == "help" ( :help echo.Please use `make ^` where ^ is one of echo. html to make standalone HTML files echo. dirhtml to make HTML files named index.html in directories echo. singlehtml to make a single large HTML file echo. pickle to make pickle files echo. json to make JSON files echo. htmlhelp to make HTML files and a HTML help project echo. qthelp to make HTML files and a qthelp project echo. devhelp to make HTML files and a Devhelp project echo. epub to make an epub echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter echo. text to make text files echo. man to make manual pages echo. texinfo to make Texinfo files echo. gettext to make PO message catalogs echo. changes to make an overview over all changed/added/deprecated items echo. xml to make Docutils-native XML files echo. pseudoxml to make pseudoxml-XML files for display purposes echo. linkcheck to check all external links for integrity echo. doctest to run all doctests embedded in the documentation if enabled echo. coverage to run coverage check of the documentation if enabled goto end ) if "%1" == "clean" ( for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i del /q /s %BUILDDIR%\* goto end ) REM Check if sphinx-build is available and fallback to Python version if any %SPHINXBUILD% 1>NUL 2>NUL if errorlevel 9009 goto sphinx_python goto sphinx_ok :sphinx_python set SPHINXBUILD=python -m sphinx.__init__ %SPHINXBUILD% 2> nul if errorlevel 9009 ( echo. echo.The 'sphinx-build' command was not found. Make sure you have Sphinx echo.installed, then set the SPHINXBUILD environment variable to point echo.to the full path of the 'sphinx-build' executable. Alternatively you echo.may add the Sphinx directory to PATH. echo. echo.If you don't have Sphinx installed, grab it from echo.http://sphinx-doc.org/ exit /b 1 ) :sphinx_ok if "%1" == "html" ( doxygen %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/html. goto end ) if "%1" == "dirhtml" ( %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. goto end ) if "%1" == "singlehtml" ( %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. goto end ) if "%1" == "pickle" ( %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can process the pickle files. goto end ) if "%1" == "json" ( %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can process the JSON files. goto end ) if "%1" == "htmlhelp" ( %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can run HTML Help Workshop with the ^ .hhp project file in %BUILDDIR%/htmlhelp. goto end ) if "%1" == "qthelp" ( %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can run "qcollectiongenerator" with the ^ .qhcp project file in %BUILDDIR%/qthelp, like this: echo.^> qcollectiongenerator %BUILDDIR%\qthelp\packagename.qhcp echo.To view the help file: echo.^> assistant -collectionFile %BUILDDIR%\qthelp\packagename.ghc goto end ) if "%1" == "devhelp" ( %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp if errorlevel 1 exit /b 1 echo. echo.Build finished. goto end ) if "%1" == "epub" ( %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub if errorlevel 1 exit /b 1 echo. echo.Build finished. The epub file is in %BUILDDIR%/epub. goto end ) if "%1" == "latex" ( %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex if errorlevel 1 exit /b 1 echo. echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. goto end ) if "%1" == "latexpdf" ( %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex cd %BUILDDIR%/latex make all-pdf cd %~dp0 echo. echo.Build finished; the PDF files are in %BUILDDIR%/latex. goto end ) if "%1" == "latexpdfja" ( %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex cd %BUILDDIR%/latex make all-pdf-ja cd %~dp0 echo. echo.Build finished; the PDF files are in %BUILDDIR%/latex. goto end ) if "%1" == "text" ( %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text if errorlevel 1 exit /b 1 echo. echo.Build finished. The text files are in %BUILDDIR%/text. goto end ) if "%1" == "man" ( %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man if errorlevel 1 exit /b 1 echo. echo.Build finished. The manual pages are in %BUILDDIR%/man. goto end ) if "%1" == "texinfo" ( %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo if errorlevel 1 exit /b 1 echo. echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. goto end ) if "%1" == "gettext" ( %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale if errorlevel 1 exit /b 1 echo. echo.Build finished. The message catalogs are in %BUILDDIR%/locale. goto end ) if "%1" == "changes" ( %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes if errorlevel 1 exit /b 1 echo. echo.The overview file is in %BUILDDIR%/changes. goto end ) if "%1" == "linkcheck" ( %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck if errorlevel 1 exit /b 1 echo. echo.Link check complete; look for any errors in the above output ^ or in %BUILDDIR%/linkcheck/output.txt. goto end ) if "%1" == "doctest" ( %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest if errorlevel 1 exit /b 1 echo. echo.Testing of doctests in the sources finished, look at the ^ results in %BUILDDIR%/doctest/output.txt. goto end ) if "%1" == "coverage" ( %SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage if errorlevel 1 exit /b 1 echo. echo.Testing of coverage in the sources finished, look at the ^ results in %BUILDDIR%/coverage/python.txt. goto end ) if "%1" == "xml" ( %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml if errorlevel 1 exit /b 1 echo. echo.Build finished. The XML files are in %BUILDDIR%/xml. goto end ) if "%1" == "pseudoxml" ( %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml if errorlevel 1 exit /b 1 echo. echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. goto end ) :end gcem-1.18.0/docs/source/000077500000000000000000000000001507212366300147515ustar00rootroot00000000000000gcem-1.18.0/docs/source/_static/000077500000000000000000000000001507212366300163775ustar00rootroot00000000000000gcem-1.18.0/docs/source/_static/main_stylesheet.css000066400000000000000000000000741507212366300223070ustar00rootroot00000000000000.wy-nav-content{ max-width: 1000px; margin: auto; } gcem-1.18.0/docs/source/api/000077500000000000000000000000001507212366300155225ustar00rootroot00000000000000gcem-1.18.0/docs/source/api/algorithms.rst000066400000000000000000000006101507212366300204220ustar00rootroot00000000000000.. Copyright (c) 2016-2024 Keith O'Hara Distributed under the terms of the Apache License, Version 2.0. The full license is in the file LICENSE, distributed with this software. Algorithms ========== .. _gcd-function-reference: .. doxygenfunction:: gcd(const T1, const T2) :project: gcem .. _lcm-function-reference: .. doxygenfunction:: lcm(const T1, const T2) :project: gcem gcem-1.18.0/docs/source/api/basic_functions.rst000066400000000000000000000043051507212366300214270ustar00rootroot00000000000000.. Copyright (c) 2016-2024 Keith O'Hara Distributed under the terms of the Apache License, Version 2.0. The full license is in the file LICENSE, distributed with this software. Basic functions =============== .. _abs-function-reference: .. doxygenfunction:: abs(const T) :project: gcem .. _fabs-function-reference: .. doxygenfunction:: fabs(const T) :project: gcem .. _fabsf-func-ref: .. doxygenfunction:: fabsf(const T) :project: gcem .. _fabsl-func-ref: .. doxygenfunction:: fabsl(const T) :project: gcem .. _ceil-function-reference: .. doxygenfunction:: ceil(const T) :project: gcem .. _copysign-func-ref: .. doxygenfunction:: copysign(const T1, const T2) :project: gcem .. _exp-function-reference: .. doxygenfunction:: exp(const T) :project: gcem .. _expm1-func-ref: .. doxygenfunction:: expm1(const T) :project: gcem .. _factorial-func-ref: .. doxygenfunction:: factorial(const T) :project: gcem .. _floor-func-ref: .. doxygenfunction:: floor(const T) :project: gcem .. _fmod-func-ref: .. doxygenfunction:: fmod(const T1, const T2) :project: gcem .. _hypot-func-ref: .. doxygenfunction:: hypot(const T1, const T2) :project: gcem .. _log-function-reference: .. doxygenfunction:: log(const T) :project: gcem .. _log1p-func-ref: .. doxygenfunction:: log1p(const T) :project: gcem .. _log2-func-ref: .. doxygenfunction:: log2(const T) :project: gcem .. _log10-func-ref: .. doxygenfunction:: log10(const T) :project: gcem .. _max-function-reference: .. doxygenfunction:: max(const T1, const T2) :project: gcem .. _min-function-reference: .. doxygenfunction:: min(const T1, const T2) :project: gcem .. _pow-function-reference: .. doxygenfunction:: pow(const T1, const T2) :project: gcem .. _round-func-ref: .. doxygenfunction:: round(const T) :project: gcem .. _signbit-func-ref: .. doxygenfunction:: signbit(const T) :project: gcem .. _sgn-function-reference: .. doxygenfunction:: sgn(const T) :project: gcem .. _sqrt-function-reference: .. doxygenfunction:: sqrt(const T) :project: gcem .. _inv_sqrt-func-ref: .. doxygenfunction:: inv_sqrt(const T) :project: gcem .. _trunc-func-ref: .. doxygenfunction:: trunc(const T) :project: gcem gcem-1.18.0/docs/source/api/hyperbolic_functions.rst000066400000000000000000000015361507212366300225110ustar00rootroot00000000000000.. Copyright (c) 2016-2024 Keith O'Hara Distributed under the terms of the Apache License, Version 2.0. The full license is in the file LICENSE, distributed with this software. Hyperbolic functions ==================== **Table of contents** .. contents:: :local: ---- Hyperbolic functions -------------------- .. _cosh-function-reference: .. doxygenfunction:: cosh(const T) :project: gcem .. _sinh-function-reference: .. doxygenfunction:: sinh(const T) :project: gcem .. _tanh-function-reference: .. doxygenfunction:: tanh(const T) :project: gcem ---- Inverse hyperbolic functions ---------------------------- .. _acosh-func-ref: .. doxygenfunction:: acosh(const T) :project: gcem .. _asinh-func-ref: .. doxygenfunction:: asinh(const T) :project: gcem .. _atanh-func-ref: .. doxygenfunction:: atanh(const T) :project: gcem gcem-1.18.0/docs/source/api/math_index.rst000066400000000000000000000260311507212366300203760ustar00rootroot00000000000000.. Copyright (c) 2016-2024 Keith O'Hara Distributed under the terms of the Apache License, Version 2.0. The full license is in the file LICENSE, distributed with this software. .. raw:: html Mathematical functions ====================== .. toctree:: algorithms +---------------------------------------+----------------------------------------------------+ | :ref:`gcd ` | greatest common divisor | +---------------------------------------+----------------------------------------------------+ | :ref:`lcm ` | least common multiple | +---------------------------------------+----------------------------------------------------+ .. toctree:: basic_functions +---------------------------------------+----------------------------------------------------+ | :ref:`abs ` | absolute value | +---------------------------------------+----------------------------------------------------+ | :ref:`fabs ` | absolute value | +---------------------------------------+----------------------------------------------------+ | :ref:`fabsf ` | absolute value | +---------------------------------------+----------------------------------------------------+ | :ref:`fabsl ` | absolute value | +---------------------------------------+----------------------------------------------------+ | :ref:`ceil ` | ceiling function | +---------------------------------------+----------------------------------------------------+ | :ref:`copysign ` | copy sign function | +---------------------------------------+----------------------------------------------------+ | :ref:`exp ` | exponential function | +---------------------------------------+----------------------------------------------------+ | :ref:`expm1 ` | exponential minus 1 function | +---------------------------------------+----------------------------------------------------+ | :ref:`factorial ` | factorial function | +---------------------------------------+----------------------------------------------------+ | :ref:`floor ` | floor function | +---------------------------------------+----------------------------------------------------+ | :ref:`fmod ` | remainder of division function | +---------------------------------------+----------------------------------------------------+ | :ref:`hypot ` | Pythagorean addition function | +---------------------------------------+----------------------------------------------------+ | :ref:`log ` | natural logarithm function | +---------------------------------------+----------------------------------------------------+ | :ref:`log1p ` | natural logarithm 1 plus argument function | +---------------------------------------+----------------------------------------------------+ | :ref:`log2 ` | binary logarithm function | +---------------------------------------+----------------------------------------------------+ | :ref:`log10 ` | common logarithm function | +---------------------------------------+----------------------------------------------------+ | :ref:`max ` | maximum between two numbers | +---------------------------------------+----------------------------------------------------+ | :ref:`min ` | minimum between two numbers | +---------------------------------------+----------------------------------------------------+ | :ref:`pow ` | power function | +---------------------------------------+----------------------------------------------------+ | :ref:`round ` | round function | +---------------------------------------+----------------------------------------------------+ | :ref:`signbit ` | sign bit function | +---------------------------------------+----------------------------------------------------+ | :ref:`sgn ` | sign function | +---------------------------------------+----------------------------------------------------+ | :ref:`sqrt ` | square root function | +---------------------------------------+----------------------------------------------------+ | :ref:`inv_sqrt ` | inverse square root function | +---------------------------------------+----------------------------------------------------+ | :ref:`trunc ` | truncate function | +---------------------------------------+----------------------------------------------------+ .. toctree:: hyperbolic_functions +---------------------------------------+----------------------------------------------------+ | :ref:`cosh ` | hyperbolic cosine function | +---------------------------------------+----------------------------------------------------+ | :ref:`sinh ` | hyperbolic sine function | +---------------------------------------+----------------------------------------------------+ | :ref:`tanh ` | hyperbolic tangent function | +---------------------------------------+----------------------------------------------------+ | :ref:`acosh ` | inverse hyperbolic cosine function | +---------------------------------------+----------------------------------------------------+ | :ref:`asinh ` | inverse hyperbolic sine function | +---------------------------------------+----------------------------------------------------+ | :ref:`atanh ` | inverse hyperbolic tangent function | +---------------------------------------+----------------------------------------------------+ .. toctree:: special_functions +---------------------------------------+----------------------------------------------------+ | :ref:`binomial_coef ` | binomial coefficient | +---------------------------------------+----------------------------------------------------+ | :ref:`log_binomial_coef ` | log binomial coefficient | +---------------------------------------+----------------------------------------------------+ | :ref:`beta ` | beta function | +---------------------------------------+----------------------------------------------------+ | :ref:`lbeta ` | log-beta function | +---------------------------------------+----------------------------------------------------+ | :ref:`tgamma ` | gamma function | +---------------------------------------+----------------------------------------------------+ | :ref:`lgamma ` | log-gamma function | +---------------------------------------+----------------------------------------------------+ | :ref:`lmgamma ` | log-multivariate gamma function | +---------------------------------------+----------------------------------------------------+ | :ref:`erf ` | error function | +---------------------------------------+----------------------------------------------------+ | :ref:`incomplete_beta ` | incomplete beta function | +---------------------------------------+----------------------------------------------------+ | :ref:`incomplete_gamma ` | incomplete gamma function | +---------------------------------------+----------------------------------------------------+ | :ref:`erf_inv ` | inverse error function | +---------------------------------------+----------------------------------------------------+ | :ref:`incomplete_beta_inv ` | inverse incomplete beta function | +---------------------------------------+----------------------------------------------------+ | :ref:`incomplete_gamma_inv ` | inverse incomplete gamma function | +---------------------------------------+----------------------------------------------------+ .. toctree:: trigonometric_functions +---------------------------------------+----------------------------------------------------+ | :ref:`cos ` | cosine function | +---------------------------------------+----------------------------------------------------+ | :ref:`sin ` | sine function | +---------------------------------------+----------------------------------------------------+ | :ref:`tan ` | tangent function | +---------------------------------------+----------------------------------------------------+ | :ref:`acos ` | arccosine function | +---------------------------------------+----------------------------------------------------+ | :ref:`asin ` | arcsine function | +---------------------------------------+----------------------------------------------------+ | :ref:`atan ` | arctangent function | +---------------------------------------+----------------------------------------------------+ | :ref:`atan2 ` | two-argument arctangent function | +---------------------------------------+----------------------------------------------------+ gcem-1.18.0/docs/source/api/special_functions.rst000066400000000000000000000032431507212366300217660ustar00rootroot00000000000000.. Copyright (c) 2016-2024 Keith O'Hara Distributed under the terms of the Apache License, Version 2.0. The full license is in the file LICENSE, distributed with this software. Special functions ================= **Table of contents** .. contents:: :local: ---- Binomial function ----------------- .. _binom-func-ref: .. doxygenfunction:: binomial_coef(const T1, const T2) :project: gcem .. _lbinom-ref: .. doxygenfunction:: log_binomial_coef(const T1, const T2) :project: gcem ---- Beta function ------------- .. _beta-function-reference: .. doxygenfunction:: beta(const T1, const T2) :project: gcem .. _lbeta-func-ref: .. doxygenfunction:: lbeta(const T1, const T2) :project: gcem ---- Gamma function -------------- .. _tgamma-func-ref: .. doxygenfunction:: tgamma(const T) :project: gcem .. _lgamma-func-ref: .. doxygenfunction:: lgamma(const T) :project: gcem .. _lmgamma-func-ref: .. doxygenfunction:: lmgamma(const T1, const T2) :project: gcem ---- Incomplete integral functions ----------------------------- .. _erf-function-reference: .. doxygenfunction:: erf(const T) :project: gcem .. _ib-func-ref: .. doxygenfunction:: incomplete_beta(const T1, const T2, const T3) :project: gcem .. _ig-func-ref: .. doxygenfunction:: incomplete_gamma(const T1, const T2) :project: gcem ---- Inverse incomplete integral functions ------------------------------------- .. _erf_inv-func-ref: .. doxygenfunction:: erf_inv(const T) :project: gcem .. _iib-ref: .. doxygenfunction:: incomplete_beta_inv(const T1, const T2, const T3) :project: gcem .. _iig-ref: .. doxygenfunction:: incomplete_gamma_inv(const T1, const T2) :project: gcem gcem-1.18.0/docs/source/api/trigonometric_functions.rst000066400000000000000000000017301507212366300232320ustar00rootroot00000000000000.. Copyright (c) 2016-2024 Keith O'Hara Distributed under the terms of the Apache License, Version 2.0. The full license is in the file LICENSE, distributed with this software. Trigonometric functions ======================= **Table of contents** .. contents:: :local: ---- Trigonometric functions ----------------------- .. _cos-function-reference: .. doxygenfunction:: cos(const T) :project: gcem .. _sin-function-reference: .. doxygenfunction:: sin(const T) :project: gcem .. _tan-function-reference: .. doxygenfunction:: tan(const T) :project: gcem ---- Inverse trigonometric functions ------------------------------- .. _acos-function-reference: .. doxygenfunction:: acos(const T) :project: gcem .. _asin-function-reference: .. doxygenfunction:: asin(const T) :project: gcem .. _atan-function-reference: .. doxygenfunction:: atan(const T) :project: gcem .. _atan2-func-ref: .. doxygenfunction:: atan2(const T1, const T2) :project: gcem gcem-1.18.0/docs/source/conf.py000066400000000000000000000014451507212366300162540ustar00rootroot00000000000000#!/usr/bin/env python3 import os import subprocess on_rtd = os.environ.get('READTHEDOCS', None) == 'True' if on_rtd: subprocess.call('cd ..; doxygen', shell=True) import sphinx_rtd_theme html_theme = "sphinx_rtd_theme" html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] def setup(app): app.add_css_file("main_stylesheet.css") # extensions = ['breathe','sphinx.ext.mathjax'] extensions = ['breathe','sphinxcontrib.katex'] breathe_projects = { 'gcem': '../xml' } templates_path = ['_templates'] html_static_path = ['_static'] source_suffix = '.rst' master_doc = 'index' project = 'gcem' copyright = '2016-2024 Keith O\'Hara' author = 'Keith O\'Hara' exclude_patterns = [] highlight_language = 'c++' pygments_style = 'sphinx' todo_include_todos = False htmlhelp_basename = 'gcemdoc' gcem-1.18.0/docs/source/examples.rst000066400000000000000000000035341507212366300173260ustar00rootroot00000000000000.. Copyright (c) 2016-2024 Keith O'Hara Distributed under the terms of the Apache License, Version 2.0. The full license is in the file LICENSE, distributed with this software. Examples =========== To calculate 10!: .. code:: cpp #include "gcem.hpp" int main() { constexpr int x = 10; constexpr int res = gcem::factorial(x); return 0; } Inspecting the assembly code generated by Clang: .. code:: asm push rbp mov rbp, rsp xor eax, eax mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], 10 mov dword ptr [rbp - 12], 3628800 pop rbp ret We see that a function call has been replaced by a numeric value (10! = 3628800). Similarly, to compute the log-Gamma function at a point: .. code:: cpp #include "gcem.hpp" int main() { constexpr long double x = 1.5; constexpr long double res = gcem::lgamma(x); return 0; } Assembly code: .. code:: asm .LCPI0_0: .long 1069547520 # float 1.5 .LCPI0_1: .quad -622431863250842976 # x86_fp80 -0.120782237635245222719 .short 49147 .zero 6 main: # @main push rbp mov rbp, rsp xor eax, eax mov dword ptr [rbp - 4], 0 fld dword ptr [rip + .LCPI0_0] fstp tbyte ptr [rbp - 32] fld tbyte ptr [rip + .LCPI0_1] fstp tbyte ptr [rbp - 48] pop rbp ret Test suite ---------- To build the full test suite: .. code:: bash # clone gcem from GitHub git clone -b master --single-branch https://github.com/kthohr/gcem ./gcem # compile tests cd ./gcem/tests make ./run_tests gcem-1.18.0/docs/source/index.rst000066400000000000000000000055231507212366300166170ustar00rootroot00000000000000.. Copyright (c) 2016-2024 Keith O'Hara Distributed under the terms of the Apache License, Version 2.0. The full license is in the file LICENSE, distributed with this software. Introduction ============ GCE-Math (\ **G**\ eneralized **C**\ onstant **E**\ xpression Math) is a templated C++ library enabling compile-time computation of mathematical functions. * The library is written in C++11 ``constexpr`` format, and is C++11/14/17/20 compatible. * Continued fraction and series expansions are implemented using recursive templates. * The ``gcem::`` syntax is identical to that of the C++ standard library (``std::``). * Tested and accurate to floating-point precision against the C++ standard library. * Released under a permissive, non-GPL license. Author: Keith O'Hara License: Apache 2.0 Status ------ The library is actively maintained, and is still being extended. A list of features includes: * basic library functions: - ``abs``, ``max``, ``min``, ``pow``, ``sqrt``, ``inv_sqrt`` - ``ceil``, ``floor``, ``round``, ``trunc``, ``fmod``, - ``exp``, ``expm1``, ``log``, ``log1p``, ``log2``, ``log10`` and more * trigonometric functions: - basic: ``cos``, ``sin``, ``tan`` - inverse: ``acos``, ``asin``, ``atan``, ``atan2`` * hyperbolic (area) functions: - ``cosh``, ``sinh``, ``tanh``, ``acosh``, ``asinh``, ``atanh`` * algorithms: - ``gcd``, ``lcm`` * special functions: - factorials and the binomial coefficient: ``factorial``, ``binomial_coef`` - beta, gamma, and multivariate gamma functions: ``beta``, ``lbeta``, ``lgamma``, ``tgamma``, ``lmgamma`` - the Gaussian error function and inverse error function: ``erf``, ``erf_inv`` - (regularized) incomplete beta and incomplete gamma functions: ``incomplete_beta``, ``incomplete_gamma`` - inverse incomplete beta and incomplete gamma functions: ``incomplete_beta_inv``, ``incomplete_gamma_inv`` General Syntax -------------- GCE-Math functions are written as C++ templates with ``constexpr`` specifiers. For example, the `Gaussian error function `_ (``erf``) is defined as: .. code:: cpp template constexpr return_t erf(const T x) noexcept; A set of internal templated ``constexpr`` functions will implement a continued fraction expansion and return a value of type ``return_t``. The output type ('``return_t``') is generally determined by the input type, e.g., ``int``, ``float``, ``double``, ``long double``, etc; when ``T`` is an intergral type, the output will be upgraded to ``return_t = double``, otherwise ``return_t = T``. For types not covered by ``std::is_integral``, recasts should be used. Contents -------- .. toctree:: :caption: EXAMPLES :maxdepth: 2 examples .. toctree:: :titlesonly: :caption: API REFERENCE :maxdepth: 2 api/math_index gcem-1.18.0/include/000077500000000000000000000000001507212366300141445ustar00rootroot00000000000000gcem-1.18.0/include/gcem.hpp000066400000000000000000000065001507212366300155710ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #ifndef _gcem_HPP #define _gcem_HPP #include "gcem_incl/gcem_options.hpp" namespace gcem { #include "gcem_incl/quadrature/gauss_legendre_50.hpp" #include "gcem_incl/is_inf.hpp" #include "gcem_incl/is_nan.hpp" #include "gcem_incl/is_finite.hpp" #include "gcem_incl/signbit.hpp" #include "gcem_incl/copysign.hpp" #include "gcem_incl/neg_zero.hpp" #include "gcem_incl/sgn.hpp" #include "gcem_incl/abs.hpp" #include "gcem_incl/fabs.hpp" #include "gcem_incl/fabsf.hpp" #include "gcem_incl/fabsl.hpp" #include "gcem_incl/ceil.hpp" #include "gcem_incl/floor.hpp" #include "gcem_incl/trunc.hpp" #include "gcem_incl/is_odd.hpp" #include "gcem_incl/is_even.hpp" #include "gcem_incl/max.hpp" #include "gcem_incl/min.hpp" #include "gcem_incl/sqrt.hpp" #include "gcem_incl/inv_sqrt.hpp" #include "gcem_incl/hypot.hpp" #include "gcem_incl/find_exponent.hpp" #include "gcem_incl/find_fraction.hpp" #include "gcem_incl/find_whole.hpp" #include "gcem_incl/mantissa.hpp" #include "gcem_incl/round.hpp" #include "gcem_incl/fmod.hpp" #include "gcem_incl/pow_integral.hpp" #include "gcem_incl/exp.hpp" #include "gcem_incl/expm1.hpp" #include "gcem_incl/log.hpp" #include "gcem_incl/log1p.hpp" #include "gcem_incl/log2.hpp" #include "gcem_incl/log10.hpp" #include "gcem_incl/pow.hpp" #include "gcem_incl/gcd.hpp" #include "gcem_incl/lcm.hpp" #include "gcem_incl/tan.hpp" #include "gcem_incl/cos.hpp" #include "gcem_incl/sin.hpp" #include "gcem_incl/atan.hpp" #include "gcem_incl/atan2.hpp" #include "gcem_incl/acos.hpp" #include "gcem_incl/asin.hpp" #include "gcem_incl/tanh.hpp" #include "gcem_incl/cosh.hpp" #include "gcem_incl/sinh.hpp" #include "gcem_incl/atanh.hpp" #include "gcem_incl/acosh.hpp" #include "gcem_incl/asinh.hpp" #include "gcem_incl/binomial_coef.hpp" #include "gcem_incl/lgamma.hpp" #include "gcem_incl/tgamma.hpp" #include "gcem_incl/factorial.hpp" #include "gcem_incl/lbeta.hpp" #include "gcem_incl/beta.hpp" #include "gcem_incl/lmgamma.hpp" #include "gcem_incl/log_binomial_coef.hpp" #include "gcem_incl/erf.hpp" #include "gcem_incl/erf_inv.hpp" #include "gcem_incl/incomplete_beta.hpp" #include "gcem_incl/incomplete_beta_inv.hpp" #include "gcem_incl/incomplete_gamma.hpp" #include "gcem_incl/incomplete_gamma_inv.hpp" } #endif gcem-1.18.0/include/gcem_incl/000077500000000000000000000000001507212366300160645ustar00rootroot00000000000000gcem-1.18.0/include/gcem_incl/abs.hpp000066400000000000000000000025011507212366300173400ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #ifndef _gcem_abs_HPP #define _gcem_abs_HPP /** * Compile-time absolute value function * * @param x a real-valued input. * @return the absolute value of \c x, \f$ |x| \f$, where the return type is the same as the input type. */ template constexpr T abs(const T x) noexcept { return( // deal with signed-zeros x == T(0) ? \ T(0) : // else x < T(0) ? \ - x : x ); } #endif gcem-1.18.0/include/gcem_incl/acos.hpp000066400000000000000000000041251507212366300175240ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time arccosine function */ #ifndef _gcem_acos_HPP #define _gcem_acos_HPP namespace internal { template constexpr T acos_compute(const T x) noexcept { return( // only defined on [-1,1] abs(x) > T(1) ? \ GCLIM::quiet_NaN() : // indistinguishable from one or zero GCLIM::min() > abs(x - T(1)) ? \ T(0) : GCLIM::min() > abs(x) ? \ T(GCEM_HALF_PI) : // else atan( sqrt(T(1) - x*x)/x ) ); } template constexpr T acos_check(const T x) noexcept { return( // NaN check is_nan(x) ? \ GCLIM::quiet_NaN() : // x > T(0) ? \ // if acos_compute(x) : // else T(GCEM_PI) - acos_compute(-x) ); } } /** * Compile-time arccosine function * * @param x a real-valued input, where \f$ x \in [-1,1] \f$. * @return the inverse cosine function using \f[ \text{acos}(x) = \text{atan} \left( \frac{\sqrt{1-x^2}}{x} \right) \f] */ template constexpr return_t acos(const T x) noexcept { return internal::acos_check( static_cast>(x) ); } #endif gcem-1.18.0/include/gcem_incl/acosh.hpp000066400000000000000000000034441507212366300176770ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time inverse hyperbolic cosine function */ #ifndef _gcem_acosh_HPP #define _gcem_acosh_HPP namespace internal { template constexpr T acosh_compute(const T x) noexcept { return( // NaN check is_nan(x) ? \ GCLIM::quiet_NaN() : // function defined for x >= 1 x < T(1) ? \ GCLIM::quiet_NaN() : // indistinguishable from 1 GCLIM::min() > abs(x - T(1)) ? \ T(0) : // else log( x + sqrt(x*x - T(1)) ) ); } } /** * Compile-time inverse hyperbolic cosine function * * @param x a real-valued input. * @return the inverse hyperbolic cosine function using \f[ \text{acosh}(x) = \ln \left( x + \sqrt{x^2 - 1} \right) \f] */ template constexpr return_t acosh(const T x) noexcept { return internal::acosh_compute( static_cast>(x) ); } #endif gcem-1.18.0/include/gcem_incl/asin.hpp000066400000000000000000000040331507212366300175270ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time arcsine function */ #ifndef _gcem_asin_HPP #define _gcem_asin_HPP namespace internal { template constexpr T asin_compute(const T x) noexcept { return( // only defined on [-1,1] x > T(1) ? \ GCLIM::quiet_NaN() : // indistinguishable from one or zero GCLIM::min() > abs(x - T(1)) ? \ T(GCEM_HALF_PI) : GCLIM::min() > abs(x) ? \ T(0) : // else atan( x/sqrt(T(1) - x*x) ) ); } template constexpr T asin_check(const T x) noexcept { return( // NaN check is_nan(x) ? \ GCLIM::quiet_NaN() : // x < T(0) ? \ - asin_compute(-x) : asin_compute(x) ); } } /** * Compile-time arcsine function * * @param x a real-valued input, where \f$ x \in [-1,1] \f$. * @return the inverse sine function using \f[ \text{asin}(x) = \text{atan} \left( \frac{x}{\sqrt{1-x^2}} \right) \f] */ template constexpr return_t asin(const T x) noexcept { return internal::asin_check( static_cast>(x) ); } #endif gcem-1.18.0/include/gcem_incl/asinh.hpp000066400000000000000000000032571507212366300177060ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time inverse hyperbolic sine function */ #ifndef _gcem_asinh_HPP #define _gcem_asinh_HPP namespace internal { template constexpr T asinh_compute(const T x) noexcept { return( // NaN check is_nan(x) ? \ GCLIM::quiet_NaN() : // indistinguishable from zero GCLIM::min() > abs(x) ? \ T(0) : // else log( x + sqrt(x*x + T(1)) ) ); } } /** * Compile-time inverse hyperbolic sine function * * @param x a real-valued input. * @return the inverse hyperbolic sine function using \f[ \text{asinh}(x) = \ln \left( x + \sqrt{x^2 + 1} \right) \f] */ template constexpr return_t asinh(const T x) noexcept { return internal::asinh_compute( static_cast>(x) ); } #endif gcem-1.18.0/include/gcem_incl/atan.hpp000066400000000000000000000126031507212366300175220ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time arctangent function */ // see // http://functions.wolfram.com/ElementaryFunctions/ArcTan/10/0001/ // http://functions.wolfram.com/ElementaryFunctions/ArcTan/06/01/06/01/0002/ #ifndef _gcem_atan_HPP #define _gcem_atan_HPP namespace internal { // Series template constexpr T atan_series_order_calc(const T xx, const T x_pow, const uint_t order) noexcept { return( T(1)/( T((order-1)*4 - 1) * x_pow ) \ - T(1)/( T((order-1)*4 + 1) * x_pow * xx) ); } #if __cplusplus >= 201402L // C++14 version template constexpr T atan_series_order(const T x, const T x_pow, const uint_t order_begin, const uint_t max_order) noexcept { // run in reverse order to sum smallest numbers first if (max_order == 1) { return GCEM_HALF_PI - T(1)/x_pow; // use x_pow to avoid a warning } T xx = x*x; T res = atan_series_order_calc(xx, pow(x,4*max_order-5), max_order); uint_t depth = max_order - 1; while (depth > order_begin) { res += atan_series_order_calc(xx, pow(x,4*depth-5), depth); --depth; } res += GCEM_HALF_PI - T(1)/x; return res; } #else // C++11 version template constexpr T atan_series_order(const T x, const T x_pow, const uint_t order, const uint_t max_order) noexcept { return( max_order == 1 ? \ T(GCEM_HALF_PI) - T(1)/x : order == 1 ? \ T(GCEM_HALF_PI) - T(1)/x + atan_series_order(x*x,pow(x,3),order+1,max_order) : // NOTE: x changes to x*x for order > 1 order < max_order ? \ atan_series_order_calc(x,x_pow,order) \ + atan_series_order(x,x_pow*x*x,order+1,max_order) : // order == max_order atan_series_order_calc(x,x_pow,order) ); } #endif template constexpr T atan_series_main(const T x) noexcept { return( x < T(3) ? atan_series_order(x,x,1U,10U) : // O(1/x^39) x < T(4) ? atan_series_order(x,x,1U,9U) : // O(1/x^35) x < T(5) ? atan_series_order(x,x,1U,8U) : // O(1/x^31) x < T(7) ? atan_series_order(x,x,1U,7U) : // O(1/x^27) x < T(11) ? atan_series_order(x,x,1U,6U) : // O(1/x^23) x < T(25) ? atan_series_order(x,x,1U,5U) : // O(1/x^19) x < T(100) ? atan_series_order(x,x,1U,4U) : // O(1/x^15) x < T(1000) ? atan_series_order(x,x,1U,3U) : // O(1/x^11) atan_series_order(x,x,1U,2U) ); // O(1/x^7) } // CF #if __cplusplus >= 201402L // C++14 version template constexpr T atan_cf_recur(const T xx, const uint_t depth_begin, const uint_t max_depth) noexcept { uint_t depth = max_depth - 1; T res = T(2*(depth+1) - 1); while (depth > depth_begin - 1) { res = T(2*depth - 1) + T(depth*depth) * xx / res; --depth; } return res; } #else // C++11 version template constexpr T atan_cf_recur(const T xx, const uint_t depth, const uint_t max_depth) noexcept { return( depth < max_depth ? \ // if T(2*depth - 1) + T(depth*depth) * xx / atan_cf_recur(xx,depth+1,max_depth) : // else T(2*depth - 1) ); } #endif template constexpr T atan_cf_main(const T x) noexcept { return( x < T(0.5) ? x/atan_cf_recur(x*x, 1U, 15U ) : x < T(1) ? x/atan_cf_recur(x*x, 1U, 25U ) : x < T(1.5) ? x/atan_cf_recur(x*x, 1U, 35U ) : x < T(2) ? x/atan_cf_recur(x*x, 1U, 45U ) : x/atan_cf_recur(x*x, 1U, 52U ) ); } // choose between series expansion and continued fraction template constexpr T atan_begin(const T x) noexcept { return( x > T(2.5) ? atan_series_main(x) : atan_cf_main(x) ); } // check input template constexpr T atan_check(const T x) noexcept { return( // NaN check is_nan(x) ? \ GCLIM::quiet_NaN() : // indistinguishable from zero GCLIM::min() > abs(x) ? \ T(0) : // negative or positive x < T(0) ? \ - atan_begin(-x) : atan_begin( x) ); } } /** * Compile-time arctangent function * * @param x a real-valued input. * @return the inverse tangent function using \f[ \text{atan}(x) = \dfrac{x}{1 + \dfrac{x^2}{3 + \dfrac{4x^2}{5 + \dfrac{9x^2}{7 + \ddots}}}} \f] */ template constexpr return_t atan(const T x) noexcept { return internal::atan_check( static_cast>(x) ); } #endif gcem-1.18.0/include/gcem_incl/atan2.hpp000066400000000000000000000055531507212366300176120ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time two-argument arctangent function */ #ifndef _gcem_atan2_HPP #define _gcem_atan2_HPP namespace internal { template constexpr T atan2_compute(const T y, const T x) noexcept { return( // NaN check any_nan(y,x) ? \ GCLIM::quiet_NaN() : // GCLIM::min() > abs(x) ? \ // GCLIM::min() > abs(y) ? \ neg_zero(y) ? \ neg_zero(x) ? - T(GCEM_PI) : - T(0) : neg_zero(x) ? T(GCEM_PI) : T(0) : y > T(0) ? \ T(GCEM_HALF_PI) : - T(GCEM_HALF_PI) : // x < T(0) ? \ y < T(0) ? \ atan(y/x) - T(GCEM_PI) : atan(y/x) + T(GCEM_PI) : // atan(y/x) ); } template> constexpr TC atan2_type_check(const T1 y, const T2 x) noexcept { return atan2_compute(static_cast(x),static_cast(y)); } } /** * Compile-time two-argument arctangent function * * @param y a real-valued input. * @param x a real-valued input. * @return \f[ \text{atan2}(y,x) = \begin{cases} \text{atan}(y/x) & \text{ if } x > 0 \\ \text{atan}(y/x) + \pi & \text{ if } x < 0 \text{ and } y \geq 0 \\ \text{atan}(y/x) - \pi & \text{ if } x < 0 \text{ and } y < 0 \\ + \pi/2 & \text{ if } x = 0 \text{ and } y > 0 \\ - \pi/2 & \text{ if } x = 0 \text{ and } y < 0 \end{cases} \f] * The function is undefined at the origin, however the following conventions are used. * \f[ \text{atan2}(y,x) = \begin{cases} +0 & \text{ if } x = +0 \text{ and } y = +0 \\ -0 & \text{ if } x = +0 \text{ and } y = -0 \\ +\pi & \text{ if } x = -0 \text{ and } y = +0 \\ - \pi & \text{ if } x = -0 \text{ and } y = -0 \end{cases} \f] */ template constexpr common_return_t atan2(const T1 y, const T2 x) noexcept { return internal::atan2_type_check(x,y); } #endif gcem-1.18.0/include/gcem_incl/atanh.hpp000066400000000000000000000040011507212366300176630ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time inverse hyperbolic tangent function */ #ifndef _gcem_atanh_HPP #define _gcem_atanh_HPP namespace internal { template constexpr T atanh_compute(const T x) noexcept { return( log( (T(1) + x)/(T(1) - x) ) / T(2) ); } template constexpr T atanh_check(const T x) noexcept { return( // NaN check is_nan(x) ? \ GCLIM::quiet_NaN() : // function is defined for |x| < 1 T(1) < abs(x) ? \ GCLIM::quiet_NaN() : GCLIM::min() > (T(1) - abs(x)) ? \ sgn(x)*GCLIM::infinity() : // indistinguishable from zero GCLIM::min() > abs(x) ? \ T(0) : // else atanh_compute(x) ); } } /** * Compile-time inverse hyperbolic tangent function * * @param x a real-valued input. * @return the inverse hyperbolic tangent function using \f[ \text{atanh}(x) = \frac{1}{2} \ln \left( \frac{1+x}{1-x} \right) \f] */ template constexpr return_t atanh(const T x) noexcept { return internal::atanh_check( static_cast>(x) ); } #endif gcem-1.18.0/include/gcem_incl/beta.hpp000066400000000000000000000026041507212366300175120ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #ifndef _gcem_beta_HPP #define _gcem_beta_HPP /** * Compile-time beta function * * @param a a real-valued input. * @param b a real-valued input. * @return the beta function using \f[ \text{B}(\alpha,\beta) := \int_0^1 t^{\alpha - 1} (1-t)^{\beta - 1} dt = \frac{\Gamma(\alpha)\Gamma(\beta)}{\Gamma(\alpha + \beta)} \f] * where \f$ \Gamma \f$ denotes the gamma function. */ template constexpr common_return_t beta(const T1 a, const T2 b) noexcept { return exp( lbeta(a,b) ); } #endif gcem-1.18.0/include/gcem_incl/binomial_coef.hpp000066400000000000000000000050051507212366300213630ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #ifndef _gcem_binomial_coef_HPP #define _gcem_binomial_coef_HPP namespace internal { template constexpr T binomial_coef_recur(const T n, const T k) noexcept { return( // edge cases (k == T(0) || n == k) ? T(1) : // deals with 0 choose 0 case n == T(0) ? T(0) : // else binomial_coef_recur(n-1,k-1) + binomial_coef_recur(n-1,k) ); } template::value>::type* = nullptr> constexpr T binomial_coef_check(const T n, const T k) noexcept { return binomial_coef_recur(n,k); } template::value>::type* = nullptr> constexpr T binomial_coef_check(const T n, const T k) noexcept { return( // NaN check; removed due to MSVC problems; template not being ignored in cases // (is_nan(n) || is_nan(k)) ? GCLIM::quiet_NaN() : // static_cast(binomial_coef_recur(static_cast(n),static_cast(k))) ); } template> constexpr TC binomial_coef_type_check(const T1 n, const T2 k) noexcept { return binomial_coef_check(static_cast(n),static_cast(k)); } } /** * Compile-time binomial coefficient * * @param n integral-valued input. * @param k integral-valued input. * @return computes the Binomial coefficient * \f[ \binom{n}{k} = \frac{n!}{k!(n-k)!} \f] * also known as '\c n choose \c k '. */ template constexpr common_t binomial_coef(const T1 n, const T2 k) noexcept { return internal::binomial_coef_type_check(n,k); } #endifgcem-1.18.0/include/gcem_incl/ceil.hpp000066400000000000000000000053301507212366300175120ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #ifndef _gcem_ceil_HPP #define _gcem_ceil_HPP namespace internal { template constexpr int ceil_resid(const T x, const T x_whole) noexcept { return( (x > T(0)) && (x > x_whole) ); } template constexpr T ceil_int(const T x, const T x_whole) noexcept { return( x_whole + static_cast(ceil_resid(x,x_whole)) ); } template constexpr T ceil_check_internal(const T x) noexcept { return x; } template<> constexpr float ceil_check_internal(const float x) noexcept { return( abs(x) >= 8388608.f ? \ // if x : \ // else ceil_int(x, float(static_cast(x))) ); } template<> constexpr double ceil_check_internal(const double x) noexcept { return( abs(x) >= 4503599627370496. ? \ // if x : \ // else ceil_int(x, double(static_cast(x))) ); } template<> constexpr long double ceil_check_internal(const long double x) noexcept { return( abs(x) >= 9223372036854775808.l ? \ // if x : \ // else ceil_int(x, ((long double)static_cast(abs(x))) * sgn(x)) ); } template constexpr T ceil_check(const T x) noexcept { return( // NaN check is_nan(x) ? \ GCLIM::quiet_NaN() : // +/- infinite !is_finite(x) ? \ x : // signed-zero cases GCLIM::min() > abs(x) ? \ x : // else ceil_check_internal(x) ); } } /** * Compile-time ceil function * * @param x a real-valued input. * @return computes the ceiling-value of the input. */ template constexpr return_t ceil(const T x) noexcept { return internal::ceil_check( static_cast>(x) ); } #endif gcem-1.18.0/include/gcem_incl/copysign.hpp000066400000000000000000000023611507212366300204320ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #ifndef _gcem_copysign_HPP #define _gcem_copysign_HPP /** * Compile-time copy sign function * * @param x a real-valued input * @param y a real-valued input * @return replace the signbit of \c x with the signbit of \c y. */ template constexpr T1 copysign(const T1 x, const T2 y) noexcept { return( signbit(x) != signbit(y) ? -x : x ); } #endif gcem-1.18.0/include/gcem_incl/cos.hpp000066400000000000000000000041061507212366300173620ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time cosine function using tan(x/2) */ #ifndef _gcem_cos_HPP #define _gcem_cos_HPP namespace internal { template constexpr T cos_compute(const T x) noexcept { return( T(1) - x*x)/(T(1) + x*x ); } template constexpr T cos_check(const T x) noexcept { return( // NaN check is_nan(x) ? \ GCLIM::quiet_NaN() : // indistinguishable from 0 GCLIM::min() > abs(x) ? T(1) : // special cases: pi/2 and pi GCLIM::min() > abs(x - T(GCEM_HALF_PI)) ? \ T(0) : GCLIM::min() > abs(x + T(GCEM_HALF_PI)) ? \ T(0) : GCLIM::min() > abs(x - T(GCEM_PI)) ? \ - T(1) : GCLIM::min() > abs(x + T(GCEM_PI)) ? \ - T(1) : // else cos_compute( tan(x/T(2)) ) ); } } /** * Compile-time cosine function * * @param x a real-valued input. * @return the cosine function using \f[ \cos(x) = \frac{1-\tan^2(x/2)}{1+\tan^2(x/2)} \f] */ template constexpr return_t cos(const T x) noexcept { return internal::cos_check( static_cast>(x) ); } #endif gcem-1.18.0/include/gcem_incl/cosh.hpp000066400000000000000000000032061507212366300175320ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time hyperbolic cosine function */ #ifndef _gcem_cosh_HPP #define _gcem_cosh_HPP namespace internal { template constexpr T cosh_compute(const T x) noexcept { return( // NaN check is_nan(x) ? \ GCLIM::quiet_NaN() : // indistinguishable from zero GCLIM::min() > abs(x) ? \ T(1) : // else (exp(x) + exp(-x)) / T(2) ); } } /** * Compile-time hyperbolic cosine function * * @param x a real-valued input. * @return the hyperbolic cosine function using \f[ \cosh(x) = \frac{\exp(x) + \exp(-x)}{2} \f] */ template constexpr return_t cosh(const T x) noexcept { return internal::cosh_compute( static_cast>(x) ); } #endif gcem-1.18.0/include/gcem_incl/erf.hpp000066400000000000000000000100321507212366300173450ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time error function */ #ifndef _gcem_erf_HPP #define _gcem_erf_HPP namespace internal { // see // http://functions.wolfram.com/GammaBetaErf/Erf/10/01/0007/ #if __cplusplus >= 201402L // C++14 version template constexpr T erf_cf_large_recur(const T x, const int depth_end) noexcept { int depth = GCEM_ERF_MAX_ITER - 1; T res = x; while (depth > depth_end - 1) { res = x + 2 * depth / res; --depth; } return res; } #else // C++11 version template constexpr T erf_cf_large_recur(const T x, const int depth) noexcept { return( depth < GCEM_ERF_MAX_ITER ? \ // if x + 2 * depth / erf_cf_large_recur(x,depth+1) : // else x ); } #endif template constexpr T erf_cf_large_main(const T x) noexcept { return( T(1) - T(2) * ( exp(-x*x) / T(GCEM_SQRT_PI) ) \ / erf_cf_large_recur(T(2)*x,1) ); } // see // http://functions.wolfram.com/GammaBetaErf/Erf/10/01/0005/ #if __cplusplus >= 201402L // C++14 version template constexpr T erf_cf_small_recur(const T xx, const int depth_end) noexcept { int depth = GCEM_ERF_MAX_ITER - 1; T res = T(2*(depth+1) - 1) - 2 * xx; while (depth > depth_end - 1) { res = T(2*depth - 1) - 2 * xx + 4 * depth * xx / res; --depth; } return res; } #else // C++11 version template constexpr T erf_cf_small_recur(const T xx, const int depth) noexcept { return( depth < GCEM_ERF_MAX_ITER ? \ // if (2*depth - T(1)) - 2 * xx \ + 4 * depth * xx / erf_cf_small_recur(xx,depth+1) : // else (2*depth - T(1)) - 2*xx ); } #endif template constexpr T erf_cf_small_main(const T x) noexcept { return( T(2) * x * ( exp(-x*x) / T(GCEM_SQRT_PI) ) \ / erf_cf_small_recur(x*x,1) ); } // template constexpr T erf_begin(const T x) noexcept { return( x > T(2.1) ? \ // if erf_cf_large_main(x) : // else erf_cf_small_main(x) ); } template constexpr T erf_check(const T x) noexcept { return( // NaN check is_nan(x) ? \ GCLIM::quiet_NaN() : // +/-Inf is_posinf(x) ? \ T(1) : is_neginf(x) ? \ - T(1) : // indistinguishable from zero GCLIM::min() > abs(x) ? \ T(0) : // else x < T(0) ? \ - erf_begin(-x) : erf_begin( x) ); } } /** * Compile-time Gaussian error function * * @param x a real-valued input. * @return computes the Gaussian error function * \f[ \text{erf}(x) = \frac{2}{\sqrt{\pi}} \int_0^x \exp( - t^2) dt \f] * using a continued fraction representation: * \f[ \text{erf}(x) = \frac{2x}{\sqrt{\pi}} \exp(-x^2) \dfrac{1}{1 - 2x^2 + \dfrac{4x^2}{3 - 2x^2 + \dfrac{8x^2}{5 - 2x^2 + \dfrac{12x^2}{7 - 2x^2 + \ddots}}}} \f] */ template constexpr return_t erf(const T x) noexcept { return internal::erf_check( static_cast>(x) ); } #endif gcem-1.18.0/include/gcem_incl/erf_inv.hpp000066400000000000000000000154731507212366300202370ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time inverse error function * * Initial approximation based on: * 'Approximating the erfinv function' by Mike Giles */ #ifndef _gcem_erf_inv_HPP #define _gcem_erf_inv_HPP namespace internal { template constexpr T erf_inv_decision(const T value, const T p, const T direc, const int iter_count) noexcept; // // initial value // two cases: (1) a < 5; and (2) otherwise template constexpr T erf_inv_initial_val_coef_2(const T a, const T p_term, const int order) noexcept { return( order == 1 ? T(-0.000200214257L) : order == 2 ? T( 0.000100950558L) + a*p_term : order == 3 ? T( 0.00134934322L) + a*p_term : order == 4 ? T(-0.003673428440L) + a*p_term : order == 5 ? T( 0.005739507730L) + a*p_term : order == 6 ? T(-0.00762246130L) + a*p_term : order == 7 ? T( 0.009438870470L) + a*p_term : order == 8 ? T( 1.001674060000L) + a*p_term : order == 9 ? T( 2.83297682000L) + a*p_term : p_term ); } template constexpr T erf_inv_initial_val_case_2(const T a, const T p_term, const int order) noexcept { return( order == 9 ? \ // if erf_inv_initial_val_coef_2(a,p_term,order) : // else erf_inv_initial_val_case_2(a,erf_inv_initial_val_coef_2(a,p_term,order),order+1) ); } template constexpr T erf_inv_initial_val_coef_1(const T a, const T p_term, const int order) noexcept { return( order == 1 ? T( 2.81022636e-08L) : order == 2 ? T( 3.43273939e-07L) + a*p_term : order == 3 ? T(-3.5233877e-06L) + a*p_term : order == 4 ? T(-4.39150654e-06L) + a*p_term : order == 5 ? T( 0.00021858087L) + a*p_term : order == 6 ? T(-0.00125372503L) + a*p_term : order == 7 ? T(-0.004177681640L) + a*p_term : order == 8 ? T( 0.24664072700L) + a*p_term : order == 9 ? T( 1.50140941000L) + a*p_term : p_term ); } template constexpr T erf_inv_initial_val_case_1(const T a, const T p_term, const int order) noexcept { return( order == 9 ? \ // if erf_inv_initial_val_coef_1(a,p_term,order) : // else erf_inv_initial_val_case_1(a,erf_inv_initial_val_coef_1(a,p_term,order),order+1) ); } template constexpr T erf_inv_initial_val_int(const T a) noexcept { return( a < T(5) ? \ // if erf_inv_initial_val_case_1(a-T(2.5),T(0),1) : // else erf_inv_initial_val_case_2(sqrt(a)-T(3),T(0),1) ); } template constexpr T erf_inv_initial_val(const T x) noexcept { return x*erf_inv_initial_val_int( -log( (T(1) - x)*(T(1) + x) ) ); } // // Halley recursion template constexpr T erf_inv_err_val(const T value, const T p) noexcept { // err_val = f(x) return( erf(value) - p ); } template constexpr T erf_inv_deriv_1(const T value) noexcept { // derivative of the error function w.r.t. x return( exp( -value*value ) ); } template constexpr T erf_inv_deriv_2(const T value, const T deriv_1) noexcept { // second derivative of the error function w.r.t. x return( deriv_1*( -T(2)*value ) ); } template constexpr T erf_inv_ratio_val_1(const T value, const T p, const T deriv_1) noexcept { return( erf_inv_err_val(value,p) / deriv_1 ); } template constexpr T erf_inv_ratio_val_2(const T value, const T deriv_1) noexcept { return( erf_inv_deriv_2(value,deriv_1) / deriv_1 ); } template constexpr T erf_inv_halley(const T ratio_val_1, const T ratio_val_2) noexcept { return( ratio_val_1 / max( T(0.8), min( T(1.2), T(1) - T(0.5)*ratio_val_1*ratio_val_2 ) ) ); } template constexpr T erf_inv_recur(const T value, const T p, const T deriv_1, const int iter_count) noexcept { return erf_inv_decision( value, p, erf_inv_halley(erf_inv_ratio_val_1(value,p,deriv_1), erf_inv_ratio_val_2(value,deriv_1)), iter_count ); } template constexpr T erf_inv_decision(const T value, const T p, const T direc, const int iter_count) noexcept { return( iter_count < GCEM_ERF_INV_MAX_ITER ? \ // if erf_inv_recur(value-direc,p, erf_inv_deriv_1(value), iter_count+1) : // else value - direc ); } template constexpr T erf_inv_recur_begin(const T initial_val, const T p) noexcept { return erf_inv_recur(initial_val,p,erf_inv_deriv_1(initial_val),1); } template constexpr T erf_inv_begin(const T p) noexcept { return( // NaN check is_nan(p) ? \ GCLIM::quiet_NaN() : // bad values abs(p) > T(1) ? \ GCLIM::quiet_NaN() : // indistinguishable from 1 GCLIM::min() > abs(T(1) - p) ? \ GCLIM::infinity() : // indistinguishable from - 1 GCLIM::min() > abs(T(1) + p) ? \ - GCLIM::infinity() : // else erf_inv_recur_begin(erf_inv_initial_val(p),p) ); } } /** * Compile-time inverse Gaussian error function * * @param p a real-valued input with values in the unit-interval. * @return Computes the inverse Gaussian error function, a value \f$ x \f$ such that * \f[ f(x) := \text{erf}(x) - p \f] * is equal to zero, for a given \c p. * GCE-Math finds this root using Halley's method: * \f[ x_{n+1} = x_n - \frac{f(x_n)/f'(x_n)}{1 - 0.5 \frac{f(x_n)}{f'(x_n)} \frac{f''(x_n)}{f'(x_n)} } \f] * where * \f[ \frac{\partial}{\partial x} \text{erf}(x) = \exp(-x^2), \ \ \frac{\partial^2}{\partial x^2} \text{erf}(x) = -2x\exp(-x^2) \f] */ template constexpr return_t erf_inv(const T p) noexcept { return internal::erf_inv_begin( static_cast>(p) ); } #endif gcem-1.18.0/include/gcem_incl/exp.hpp000066400000000000000000000057111507212366300173750ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time exponential function */ #ifndef _gcem_exp_HPP #define _gcem_exp_HPP namespace internal { // see https://en.wikipedia.org/wiki/Euler%27s_continued_fraction_formula #if __cplusplus >= 201402L // C++14 version template constexpr T exp_cf_recur(const T x, const int depth_end) noexcept { int depth = GCEM_EXP_MAX_ITER_SMALL - 1; T res = T(1); while (depth > depth_end - 1) { res = T(1) + x/T(depth - 1) - x/depth/res; --depth; } return res; } #else // C++11 version template constexpr T exp_cf_recur(const T x, const int depth) noexcept { return( depth < GCEM_EXP_MAX_ITER_SMALL ? \ // if T(1) + x/T(depth - 1) - x/depth/exp_cf_recur(x,depth+1) : // else T(1) ); } #endif template constexpr T exp_cf(const T x) noexcept { return( T(1) / (T(1) - x / exp_cf_recur(x,2)) ); } template constexpr T exp_split(const T x) noexcept { return( static_cast(pow_integral(GCEM_E,find_whole(x))) * exp_cf(find_fraction(x)) ); } template constexpr T exp_check(const T x) noexcept { return( is_nan(x) ? \ GCLIM::quiet_NaN() : // is_neginf(x) ? \ T(0) : // indistinguishable from zero GCLIM::min() > abs(x) ? \ T(1) : // is_posinf(x) ? \ GCLIM::infinity() : // abs(x) < T(2) ? \ exp_cf(x) : \ exp_split(x) ); } } /** * Compile-time exponential function * * @param x a real-valued input. * @return \f$ \exp(x) \f$ using \f[ \exp(x) = \dfrac{1}{1-\dfrac{x}{1+x-\dfrac{\frac{1}{2}x}{1 + \frac{1}{2}x - \dfrac{\frac{1}{3}x}{1 + \frac{1}{3}x - \ddots}}}} \f] * The continued fraction argument is split into two parts: \f$ x = n + r \f$, where \f$ n \f$ is an integer and \f$ r \in [-0.5,0.5] \f$. */ template constexpr return_t exp(const T x) noexcept { return internal::exp_check( static_cast>(x) ); } #endif gcem-1.18.0/include/gcem_incl/expm1.hpp000066400000000000000000000036001507212366300176260ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time exponential function */ #ifndef _gcem_expm1_HPP #define _gcem_expm1_HPP namespace internal { template constexpr T expm1_compute(const T x) noexcept { // return x * ( T(1) + x * ( T(1)/T(2) + x * ( T(1)/T(6) + x * ( T(1)/T(24) + x/T(120) ) ) ) ); // O(x^6) return x + x * ( x/T(2) + x * ( x/T(6) + x * ( x/T(24) + x*x/T(120) ) ) ); // O(x^6) } template constexpr T expm1_check(const T x) noexcept { return( // NaN check is_nan(x) ? \ GCLIM::quiet_NaN() : // abs(x) > T(1e-04) ? \ // if exp(x) - T(1) : // else expm1_compute(x) ); } } /** * Compile-time exponential-minus-1 function * * @param x a real-valued input. * @return \f$ \exp(x) - 1 \f$ using \f[ \exp(x) = \sum_{k=0}^\infty \dfrac{x^k}{k!} \f] */ template constexpr return_t expm1(const T x) noexcept { return internal::expm1_check( static_cast>(x) ); } #endif gcem-1.18.0/include/gcem_incl/fabs.hpp000066400000000000000000000024201507212366300175060ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #ifndef _gcem_fabs_HPP #define _gcem_fabs_HPP /** * Compile-time floating-point absolute value function * * @param x a real-valued input. * @return the absolute value of \c x, \f$ |x| \f$, where the return type is a floating point number (float, double, or long double). */ template constexpr return_t fabs(const T x) noexcept { return gcem::abs( static_cast>(x) ); } #endif gcem-1.18.0/include/gcem_incl/fabsf.hpp000066400000000000000000000023641507212366300176630ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #ifndef _gcem_fabsf_HPP #define _gcem_fabsf_HPP /** * Compile-time floating-point absolute value function * * @param x a real-valued input. * @return the absolute value of \c x, \f$ |x| \f$, where the return type is a floating point number (float only). */ template constexpr float fabsf(const T x) noexcept { return gcem::abs( static_cast(x) ); } #endif gcem-1.18.0/include/gcem_incl/fabsl.hpp000066400000000000000000000024061507212366300176660ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #ifndef _gcem_fabsl_HPP #define _gcem_fabsl_HPP /** * Compile-time floating-point absolute value function * * @param x a real-valued input. * @return the absolute value of \c x, \f$ |x| \f$, where the return type is a floating point number (long double only). */ template constexpr long double fabsl(const T x) noexcept { return gcem::abs( static_cast(x) ); } #endif gcem-1.18.0/include/gcem_incl/factorial.hpp000066400000000000000000000056701507212366300205510ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time factorial function */ #ifndef _gcem_factorial_HPP #define _gcem_factorial_HPP namespace internal { // T should be int, long int, unsigned int, etc. template constexpr T factorial_table(const T x) noexcept { // table for x! when x = {0, ..., 20} return( x == T(0) ? T(1) : x == T(1) ? T(1) : x == T(2) ? T(2) : x == T(3) ? T(6) : x == T(4) ? T(24) : x == T(5) ? T(120) : x == T(6) ? T(720) : x == T(7) ? T(5040) : x == T(8) ? T(40320) : x == T(9) ? T(362880) : // x == T(10) ? T(3628800) : x == T(11) ? T(39916800) : x == T(12) ? T(479001600) : x == T(13) ? T(6227020800) : x == T(14) ? T(87178291200) : x == T(15) ? T(1307674368000) : x == T(16) ? T(20922789888000) : x == T(17) ? T(355687428096000) : x == T(18) ? T(6402373705728000) : x == T(19) ? T(121645100408832000) : T(2432902008176640000) ); } template::value>::type* = nullptr> constexpr T factorial_recur(const T x) noexcept { return( x < T(21) ? \ // if factorial_table(x) : // else (but overflow is almost guaranteed here) x * factorial_recur(x - 1) ); } template::value>::type* = nullptr> constexpr T factorial_recur(const T x) noexcept { return tgamma(x + 1); } } /** * Compile-time factorial function * * @param x a real-valued input. * @return Computes the factorial value \f$ x! \f$. * When \c x is an integral type (\c int, long int, etc.), a simple recursion method is used, along with table values. * When \c x is real-valued, factorial(x) = tgamma(x+1). */ template constexpr T factorial(const T x) noexcept { return internal::factorial_recur(x); } #endif gcem-1.18.0/include/gcem_incl/find_exponent.hpp000066400000000000000000000034011507212366300214330ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time find_exponent function */ #ifndef _gcem_find_exponent_HPP #define _gcem_find_exponent_HPP namespace internal { template constexpr llint_t find_exponent(const T x, const llint_t exponent) noexcept { return( // < 1 x < T(1e-03) ? \ find_exponent(x * T(1e+04), exponent - llint_t(4)) : x < T(1e-01) ? \ find_exponent(x * T(1e+02), exponent - llint_t(2)) : x < T(1) ? \ find_exponent(x * T(10), exponent - llint_t(1)) : // > 10 x > T(10) ? \ find_exponent(x / T(10), exponent + llint_t(1)) : x > T(1e+02) ? \ find_exponent(x / T(1e+02), exponent + llint_t(2)) : x > T(1e+04) ? \ find_exponent(x / T(1e+04), exponent + llint_t(4)) : // else exponent ); } } #endif gcem-1.18.0/include/gcem_incl/find_fraction.hpp000066400000000000000000000024561507212366300214110ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * find the fraction part of x = n + r, where -0.5 <= r <= 0.5 */ #ifndef _gcem_find_fraction_HPP #define _gcem_find_fraction_HPP namespace internal { template constexpr T find_fraction(const T x) noexcept { return( abs(x - internal::floor_check(x)) >= T(0.5) ? \ // if x - internal::floor_check(x) - sgn(x) : //else x - internal::floor_check(x) ); } } #endif gcem-1.18.0/include/gcem_incl/find_whole.hpp000066400000000000000000000025231507212366300207150ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * find the whole number part of x = n + r, where -0.5 <= r <= 0.5 */ #ifndef _gcem_find_whole_HPP #define _gcem_find_whole_HPP namespace internal { template constexpr llint_t find_whole(const T x) noexcept { return( abs(x - internal::floor_check(x)) >= T(0.5) ? \ // if static_cast(internal::floor_check(x) + sgn(x)) : // else static_cast(internal::floor_check(x)) ); } } #endif gcem-1.18.0/include/gcem_incl/floor.hpp000066400000000000000000000053471507212366300177270ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #ifndef _gcem_floor_HPP #define _gcem_floor_HPP namespace internal { template constexpr int floor_resid(const T x, const T x_whole) noexcept { return( (x < T(0)) && (x < x_whole) ); } template constexpr T floor_int(const T x, const T x_whole) noexcept { return( x_whole - static_cast(floor_resid(x,x_whole)) ); } template constexpr T floor_check_internal(const T x) noexcept { return x; } template<> constexpr float floor_check_internal(const float x) noexcept { return( abs(x) >= 8388608.f ? \ // if x : \ // else floor_int(x, float(static_cast(x))) ); } template<> constexpr double floor_check_internal(const double x) noexcept { return( abs(x) >= 4503599627370496. ? \ // if x : \ // else floor_int(x, double(static_cast(x))) ); } template<> constexpr long double floor_check_internal(const long double x) noexcept { return( abs(x) >= 9223372036854775808.l ? \ // if x : \ // else floor_int(x, ((long double)static_cast(abs(x))) * sgn(x)) ); } template constexpr T floor_check(const T x) noexcept { return( // NaN check is_nan(x) ? \ GCLIM::quiet_NaN() : // +/- infinite !is_finite(x) ? \ x : // signed-zero cases GCLIM::min() > abs(x) ? \ x : // else floor_check_internal(x) ); } } /** * Compile-time floor function * * @param x a real-valued input. * @return computes the floor-value of the input. */ template constexpr return_t floor(const T x) noexcept { return internal::floor_check( static_cast>(x) ); } #endif gcem-1.18.0/include/gcem_incl/fmod.hpp000066400000000000000000000036061507212366300175270ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #ifndef _gcem_fmod_HPP #define _gcem_fmod_HPP namespace internal { template constexpr T fmod_check(const T x, const T y) noexcept { return( // NaN check any_nan(x, y) ? \ GCLIM::quiet_NaN() : // +/- infinite !all_finite(x, y) ? \ GCLIM::quiet_NaN() : // else x - trunc(x/y)*y ); } template> constexpr TC fmod_type_check(const T1 x, const T2 y) noexcept { return fmod_check(static_cast(x),static_cast(y)); } } /** * Compile-time remainder of division function * @param x a real-valued input. * @param y a real-valued input. * @return computes the floating-point remainder of \f$ x / y \f$ (rounded towards zero) using \f[ \text{fmod}(x,y) = x - \text{trunc}(x/y) \times y \f] */ template constexpr common_return_t fmod(const T1 x, const T2 y) noexcept { return internal::fmod_type_check(x,y); } #endif gcem-1.18.0/include/gcem_incl/gcd.hpp000066400000000000000000000040521507212366300173330ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #ifndef _gcem_gcd_HPP #define _gcem_gcd_HPP namespace internal { template constexpr T gcd_recur(const T a, const T b) noexcept { return( b == T(0) ? a : gcd_recur(b, a % b) ); } template::value>::type* = nullptr> constexpr T gcd_int_check(const T a, const T b) noexcept { return gcd_recur(a,b); } template::value>::type* = nullptr> constexpr T gcd_int_check(const T a, const T b) noexcept { return gcd_recur( static_cast(a), static_cast(b) ); } template> constexpr TC gcd_type_check(const T1 a, const T2 b) noexcept { return gcd_int_check( static_cast(abs(a)), static_cast(abs(b)) ); } } /** * Compile-time greatest common divisor (GCD) function * * @param a integral-valued input. * @param b integral-valued input. * @return the greatest common divisor between integers \c a and \c b using a Euclidean algorithm. */ template constexpr common_t gcd(const T1 a, const T2 b) noexcept { return internal::gcd_type_check(a,b); } #endif gcem-1.18.0/include/gcem_incl/gcem_options.hpp000066400000000000000000000107331507212366300212670ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #include // size_t #include #include // undef some functions from math.h // see issue #29 #ifdef abs #undef abs #endif #ifdef min #undef min #endif #ifdef max #undef max #endif #ifdef round #undef round #endif #ifdef signbit #undef signbit #endif // // version #ifndef GCEM_VERSION_MAJOR #define GCEM_VERSION_MAJOR 1 #endif #ifndef GCEM_VERSION_MINOR #define GCEM_VERSION_MINOR 18 #endif #ifndef GCEM_VERSION_PATCH #define GCEM_VERSION_PATCH 0 #endif // // types namespace gcem { using uint_t = unsigned int; using ullint_t = unsigned long long int; using llint_t = long long int; template using GCLIM = std::numeric_limits; template using return_t = typename std::conditional::value,double,T>::type; template using common_t = typename std::common_type::type; template using common_return_t = return_t>; } // // constants #ifndef GCEM_LOG_2 #define GCEM_LOG_2 0.6931471805599453094172321214581765680755L #endif #ifndef GCEM_LOG_10 #define GCEM_LOG_10 2.3025850929940456840179914546843642076011L #endif #ifndef GCEM_PI #define GCEM_PI 3.1415926535897932384626433832795028841972L #endif #ifndef GCEM_LOG_PI #define GCEM_LOG_PI 1.1447298858494001741434273513530587116473L #endif #ifndef GCEM_LOG_2PI #define GCEM_LOG_2PI 1.8378770664093454835606594728112352797228L #endif #ifndef GCEM_LOG_SQRT_2PI #define GCEM_LOG_SQRT_2PI 0.9189385332046727417803297364056176398614L #endif #ifndef GCEM_SQRT_2 #define GCEM_SQRT_2 1.4142135623730950488016887242096980785697L #endif #ifndef GCEM_HALF_PI #define GCEM_HALF_PI 1.5707963267948966192313216916397514420986L #endif #ifndef GCEM_SQRT_PI #define GCEM_SQRT_PI 1.7724538509055160272981674833411451827975L #endif #ifndef GCEM_SQRT_HALF_PI #define GCEM_SQRT_HALF_PI 1.2533141373155002512078826424055226265035L #endif #ifndef GCEM_E #define GCEM_E 2.7182818284590452353602874713526624977572L #endif // // convergence settings #ifndef GCEM_ERF_MAX_ITER #define GCEM_ERF_MAX_ITER 60 #endif #ifndef GCEM_ERF_INV_MAX_ITER #define GCEM_ERF_INV_MAX_ITER 60 #endif #ifndef GCEM_EXP_MAX_ITER_SMALL #define GCEM_EXP_MAX_ITER_SMALL 25 #endif // #ifndef GCEM_LOG_TOL // #define GCEM_LOG_TOL 1E-14 // #endif #ifndef GCEM_LOG_MAX_ITER_SMALL #define GCEM_LOG_MAX_ITER_SMALL 25 #endif #ifndef GCEM_LOG_MAX_ITER_BIG #define GCEM_LOG_MAX_ITER_BIG 255 #endif #ifndef GCEM_INCML_BETA_TOL #define GCEM_INCML_BETA_TOL 1E-15 #endif #ifndef GCEM_INCML_BETA_MAX_ITER #define GCEM_INCML_BETA_MAX_ITER 205 #endif #ifndef GCEM_INCML_BETA_INV_MAX_ITER #define GCEM_INCML_BETA_INV_MAX_ITER 35 #endif #ifndef GCEM_INCML_GAMMA_MAX_ITER #define GCEM_INCML_GAMMA_MAX_ITER 55 #endif #ifndef GCEM_INCML_GAMMA_INV_MAX_ITER #define GCEM_INCML_GAMMA_INV_MAX_ITER 35 #endif #ifndef GCEM_SQRT_MAX_ITER #define GCEM_SQRT_MAX_ITER 100 #endif #ifndef GCEM_INV_SQRT_MAX_ITER #define GCEM_INV_SQRT_MAX_ITER 100 #endif #ifndef GCEM_TAN_MAX_ITER #define GCEM_TAN_MAX_ITER 35 #endif #ifndef GCEM_TANH_MAX_ITER #define GCEM_TANH_MAX_ITER 35 #endif // // Macros #ifdef _MSC_VER #ifndef GCEM_SIGNBIT #define GCEM_SIGNBIT(x) _signbit(x) #endif #ifndef GCEM_COPYSIGN #define GCEM_COPYSIGN(x,y) _copysign(x,y) #endif #else #ifndef GCEM_SIGNBIT #define GCEM_SIGNBIT(x) __builtin_signbit(x) #endif #ifndef GCEM_COPYSIGN #define GCEM_COPYSIGN(x,y) __builtin_copysign(x,y) #endif #endif gcem-1.18.0/include/gcem_incl/hypot.hpp000066400000000000000000000042741507212366300177470ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time Pythagorean addition function */ // see: https://en.wikipedia.org/wiki/Pythagorean_addition #ifndef _gcem_hypot_HPP #define _gcem_hypot_HPP namespace internal { template constexpr T hypot_compute(const T x, const T ydx) noexcept { return abs(x) * sqrt( T(1) + (ydx * ydx) ); } template constexpr T hypot_vals_check(const T x, const T y) noexcept { return( any_nan(x, y) ? \ GCLIM::quiet_NaN() : // any_inf(x,y) ? \ GCLIM::infinity() : // indistinguishable from zero or one GCLIM::min() > abs(x) ? \ abs(y) : GCLIM::min() > abs(y) ? \ abs(x) : // else hypot_compute(x, y/x) ); } template> constexpr TC hypot_type_check(const T1 x, const T2 y) noexcept { return hypot_vals_check(static_cast(x),static_cast(y)); } } /** * Compile-time Pythagorean addition function * * @param x a real-valued input. * @param y a real-valued input. * @return Computes \f$ x \oplus y = \sqrt{x^2 + y^2} \f$. */ template constexpr common_return_t hypot(const T1 x, const T2 y) noexcept { return internal::hypot_type_check(x,y); } #endif gcem-1.18.0/include/gcem_incl/incomplete_beta.hpp000066400000000000000000000135341507212366300217350ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time incomplete beta function * * see eq. 18.5.17a in the Handbook of Continued Fractions for Special Functions */ #ifndef _gcem_incomplete_beta_HPP #define _gcem_incomplete_beta_HPP namespace internal { template constexpr T incomplete_beta_cf(const T a, const T b, const T z, const T c_j, const T d_j, const T f_j, const int depth) noexcept; // // coefficients; see eq. 18.5.17b template constexpr T incomplete_beta_coef_even(const T a, const T b, const T z, const int k) noexcept { return( -z*(a + k)*(a + b + k)/( (a + 2*k)*(a + 2*k + T(1)) ) ); } template constexpr T incomplete_beta_coef_odd(const T a, const T b, const T z, const int k) noexcept { return( z*k*(b - k)/((a + 2*k - T(1))*(a + 2*k)) ); } template constexpr T incomplete_beta_coef(const T a, const T b, const T z, const int depth) noexcept { return( !is_odd(depth) ? incomplete_beta_coef_even(a,b,z,depth/2) : incomplete_beta_coef_odd(a,b,z,(depth+1)/2) ); } // // update formulae for the modified Lentz method template constexpr T incomplete_beta_c_update(const T a, const T b, const T z, const T c_j, const int depth) noexcept { return( T(1) + incomplete_beta_coef(a,b,z,depth)/c_j ); } template constexpr T incomplete_beta_d_update(const T a, const T b, const T z, const T d_j, const int depth) noexcept { return( T(1) / (T(1) + incomplete_beta_coef(a,b,z,depth)*d_j) ); } // // convergence-type condition template constexpr T incomplete_beta_decision(const T a, const T b, const T z, const T c_j, const T d_j, const T f_j, const int depth) noexcept { return( // tolerance check abs(c_j*d_j - T(1)) < GCEM_INCML_BETA_TOL ? f_j*c_j*d_j : // max_iter check depth < GCEM_INCML_BETA_MAX_ITER ? \ // if incomplete_beta_cf(a,b,z,c_j,d_j,f_j*c_j*d_j,depth+1) : // else f_j*c_j*d_j ); } template constexpr T incomplete_beta_cf(const T a, const T b, const T z, const T c_j, const T d_j, const T f_j, const int depth) noexcept { return incomplete_beta_decision(a,b,z, incomplete_beta_c_update(a,b,z,c_j,depth), incomplete_beta_d_update(a,b,z,d_j,depth), f_j,depth); } // // x^a (1-x)^{b} / (a beta(a,b)) * cf template constexpr T incomplete_beta_begin(const T a, const T b, const T z) noexcept { return ( (exp(a*log(z) + b*log(T(1)-z) - lbeta(a,b)) / a) * \ incomplete_beta_cf(a,b,z,T(1), incomplete_beta_d_update(a,b,z,T(1),0), incomplete_beta_d_update(a,b,z,T(1),0),1) ); } template constexpr T incomplete_beta_check(const T a, const T b, const T z) noexcept { return( // NaN check any_nan(a, b, z) ? \ GCLIM::quiet_NaN() : // indistinguishable from zero GCLIM::min() > z ? \ T(0) : // parameter check for performance (a + T(1))/(a + b + T(2)) > z ? \ incomplete_beta_begin(a,b,z) : T(1) - incomplete_beta_begin(b,a,T(1) - z) ); } template> constexpr TC incomplete_beta_type_check(const T1 a, const T2 b, const T3 p) noexcept { return incomplete_beta_check(static_cast(a), static_cast(b), static_cast(p)); } } /** * Compile-time regularized incomplete beta function * * @param a a real-valued, non-negative input. * @param b a real-valued, non-negative input. * @param z a real-valued, non-negative input. * * @return computes the regularized incomplete beta function, * \f[ \frac{\text{B}(z;\alpha,\beta)}{\text{B}(\alpha,\beta)} = \frac{1}{\text{B}(\alpha,\beta)}\int_0^z t^{a-1} (1-t)^{\beta-1} dt \f] * using a continued fraction representation, found in the Handbook of Continued Fractions for Special Functions, and a modified Lentz method. * \f[ \frac{\text{B}(z;\alpha,\beta)}{\text{B}(\alpha,\beta)} = \frac{z^{\alpha} (1-t)^{\beta}}{\alpha \text{B}(\alpha,\beta)} \dfrac{a_1}{1 + \dfrac{a_2}{1 + \dfrac{a_3}{1 + \dfrac{a_4}{1 + \ddots}}}} \f] * where \f$ a_1 = 1 \f$ and * \f[ a_{2m+2} = - \frac{(\alpha + m)(\alpha + \beta + m)}{(\alpha + 2m)(\alpha + 2m + 1)}, \ m \geq 0 \f] * \f[ a_{2m+1} = \frac{m(\beta - m)}{(\alpha + 2m - 1)(\alpha + 2m)}, \ m \geq 1 \f] * The Lentz method works as follows: let \f$ f_j \f$ denote the value of the continued fraction up to the first \f$ j \f$ terms; \f$ f_j \f$ is updated as follows: * \f[ c_j = 1 + a_j / c_{j-1}, \ \ d_j = 1 / (1 + a_j d_{j-1}) \f] * \f[ f_j = c_j d_j f_{j-1} \f] */ template constexpr common_return_t incomplete_beta(const T1 a, const T2 b, const T3 z) noexcept { return internal::incomplete_beta_type_check(a,b,z); } #endif gcem-1.18.0/include/gcem_incl/incomplete_beta_inv.hpp000066400000000000000000000254461507212366300226160ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * inverse of the incomplete beta function */ #ifndef _gcem_incomplete_beta_inv_HPP #define _gcem_incomplete_beta_inv_HPP namespace internal { template constexpr T incomplete_beta_inv_decision(const T value, const T alpha_par, const T beta_par, const T p, const T direc, const T lb_val, const int iter_count) noexcept; // // initial value for Halley // // a,b > 1 case template constexpr T incomplete_beta_inv_initial_val_1_tval(const T p) noexcept { // a > 1.0 return( p > T(0.5) ? \ // if sqrt(-T(2)*log(T(1) - p)) : // else sqrt(-T(2)*log(p)) ); } template constexpr T incomplete_beta_inv_initial_val_1_int_begin(const T t_val) noexcept { // internal for a > 1.0 return( t_val - ( T(2.515517) + T(0.802853)*t_val + T(0.010328)*t_val*t_val ) \ / ( T(1) + T(1.432788)*t_val + T(0.189269)*t_val*t_val + T(0.001308)*t_val*t_val*t_val ) ); } template constexpr T incomplete_beta_inv_initial_val_1_int_ab1(const T alpha_par, const T beta_par) noexcept { return( T(1)/(2*alpha_par - T(1)) + T(1)/(2*beta_par - T(1)) ); } template constexpr T incomplete_beta_inv_initial_val_1_int_ab2(const T alpha_par, const T beta_par) noexcept { return( T(1)/(2*beta_par - T(1)) - T(1)/(2*alpha_par - T(1)) ); } template constexpr T incomplete_beta_inv_initial_val_1_int_h(const T ab_term_1) noexcept { return( T(2) / ab_term_1 ); } template constexpr T incomplete_beta_inv_initial_val_1_int_w(const T value, const T ab_term_2, const T h_term) noexcept { // return( value * sqrt(h_term + lambda)/h_term - ab_term_2*(lambda + 5.0/6.0 -2.0/(3.0*h_term)) ); return( value * sqrt(h_term + (value*value - T(3))/T(6))/h_term \ - ab_term_2*((value*value - T(3))/T(6) + T(5)/T(6) - T(2)/(T(3)*h_term)) ); } template constexpr T incomplete_beta_inv_initial_val_1_int_end(const T alpha_par, const T beta_par, const T w_term) noexcept { return( alpha_par / (alpha_par + beta_par*exp(2*w_term)) ); } template constexpr T incomplete_beta_inv_initial_val_1(const T alpha_par, const T beta_par, const T t_val, const T sgn_term) noexcept { // a > 1.0 return incomplete_beta_inv_initial_val_1_int_end( alpha_par, beta_par, incomplete_beta_inv_initial_val_1_int_w( sgn_term*incomplete_beta_inv_initial_val_1_int_begin(t_val), incomplete_beta_inv_initial_val_1_int_ab2(alpha_par,beta_par), incomplete_beta_inv_initial_val_1_int_h( incomplete_beta_inv_initial_val_1_int_ab1(alpha_par,beta_par) ) ) ); } // // a,b else template constexpr T incomplete_beta_inv_initial_val_2_s1(const T alpha_par, const T beta_par) noexcept { return( pow(alpha_par/(alpha_par+beta_par),alpha_par) / alpha_par ); } template constexpr T incomplete_beta_inv_initial_val_2_s2(const T alpha_par, const T beta_par) noexcept { return( pow(beta_par/(alpha_par+beta_par),beta_par) / beta_par ); } template constexpr T incomplete_beta_inv_initial_val_2(const T alpha_par, const T beta_par, const T p, const T s_1, const T s_2) noexcept { return( p <= s_1/(s_1 + s_2) ? pow(p*(s_1+s_2)*alpha_par,T(1)/alpha_par) : T(1) - pow(p*(s_1+s_2)*beta_par,T(1)/beta_par) ); } // initial value template constexpr T incomplete_beta_inv_initial_val(const T alpha_par, const T beta_par, const T p) noexcept { return( (alpha_par > T(1) && beta_par > T(1)) ? // if incomplete_beta_inv_initial_val_1(alpha_par,beta_par, incomplete_beta_inv_initial_val_1_tval(p), p < T(0.5) ? T(1) : T(-1) ) : // else p > T(0.5) ? // if T(1) - incomplete_beta_inv_initial_val_2(beta_par,alpha_par,T(1) - p, incomplete_beta_inv_initial_val_2_s1(beta_par,alpha_par), incomplete_beta_inv_initial_val_2_s2(beta_par,alpha_par)) : // else incomplete_beta_inv_initial_val_2(alpha_par,beta_par,p, incomplete_beta_inv_initial_val_2_s1(alpha_par,beta_par), incomplete_beta_inv_initial_val_2_s2(alpha_par,beta_par)) ); } // // Halley recursion template constexpr T incomplete_beta_inv_err_val(const T value, const T alpha_par, const T beta_par, const T p) noexcept { // err_val = f(x) return( incomplete_beta(alpha_par,beta_par,value) - p ); } template constexpr T incomplete_beta_inv_deriv_1(const T value, const T alpha_par, const T beta_par, const T lb_val) noexcept { // derivative of the incomplete beta function w.r.t. x return( // indistinguishable from zero or one GCLIM::min() > abs(value) ? \ T(0) : GCLIM::min() > abs(T(1) - value) ? \ T(0) : // else exp( (alpha_par - T(1))*log(value) + (beta_par - T(1))*log(T(1) - value) - lb_val ) ); } template constexpr T incomplete_beta_inv_deriv_2(const T value, const T alpha_par, const T beta_par, const T deriv_1) noexcept { // second derivative of the incomplete beta function w.r.t. x return( deriv_1*((alpha_par - T(1))/value - (beta_par - T(1))/(T(1) - value)) ); } template constexpr T incomplete_beta_inv_ratio_val_1(const T value, const T alpha_par, const T beta_par, const T p, const T deriv_1) noexcept { return( incomplete_beta_inv_err_val(value,alpha_par,beta_par,p) / deriv_1 ); } template constexpr T incomplete_beta_inv_ratio_val_2(const T value, const T alpha_par, const T beta_par, const T deriv_1) noexcept { return( incomplete_beta_inv_deriv_2(value,alpha_par,beta_par,deriv_1) / deriv_1 ); } template constexpr T incomplete_beta_inv_halley(const T ratio_val_1, const T ratio_val_2) noexcept { return( ratio_val_1 / max( T(0.8), min( T(1.2), T(1) - T(0.5)*ratio_val_1*ratio_val_2 ) ) ); } template constexpr T incomplete_beta_inv_recur(const T value, const T alpha_par, const T beta_par, const T p, const T deriv_1, const T lb_val, const int iter_count) noexcept { return( // derivative = 0 GCLIM::min() > abs(deriv_1) ? \ incomplete_beta_inv_decision( value, alpha_par, beta_par, p, T(0), lb_val, GCEM_INCML_BETA_INV_MAX_ITER+1) : // else incomplete_beta_inv_decision( value, alpha_par, beta_par, p, incomplete_beta_inv_halley( incomplete_beta_inv_ratio_val_1(value,alpha_par,beta_par,p,deriv_1), incomplete_beta_inv_ratio_val_2(value,alpha_par,beta_par,deriv_1) ), lb_val, iter_count) ); } template constexpr T incomplete_beta_inv_decision(const T value, const T alpha_par, const T beta_par, const T p, const T direc, const T lb_val, const int iter_count) noexcept { return( iter_count <= GCEM_INCML_BETA_INV_MAX_ITER ? // if incomplete_beta_inv_recur(value-direc,alpha_par,beta_par,p, incomplete_beta_inv_deriv_1(value,alpha_par,beta_par,lb_val), lb_val, iter_count+1) : // else value - direc ); } template constexpr T incomplete_beta_inv_begin(const T initial_val, const T alpha_par, const T beta_par, const T p, const T lb_val) noexcept { return incomplete_beta_inv_recur(initial_val,alpha_par,beta_par,p, incomplete_beta_inv_deriv_1(initial_val,alpha_par,beta_par,lb_val), lb_val,1); } template constexpr T incomplete_beta_inv_check(const T alpha_par, const T beta_par, const T p) noexcept { return( // NaN check any_nan(alpha_par, beta_par, p) ? \ GCLIM::quiet_NaN() : // indistinguishable from zero or one GCLIM::min() > p ? \ T(0) : GCLIM::min() > abs(T(1) - p) ? \ T(1) : // else incomplete_beta_inv_begin(incomplete_beta_inv_initial_val(alpha_par,beta_par,p), alpha_par,beta_par,p,lbeta(alpha_par,beta_par)) ); } template> constexpr TC incomplete_beta_inv_type_check(const T1 a, const T2 b, const T3 p) noexcept { return incomplete_beta_inv_check(static_cast(a), static_cast(b), static_cast(p)); } } /** * Compile-time inverse incomplete beta function * * @param a a real-valued, non-negative input. * @param b a real-valued, non-negative input. * @param p a real-valued input with values in the unit-interval. * * @return Computes the inverse incomplete beta function, a value \f$ x \f$ such that * \f[ f(x) := \frac{\text{B}(x;\alpha,\beta)}{\text{B}(\alpha,\beta)} - p \f] * equal to zero, for a given \c p. * GCE-Math finds this root using Halley's method: * \f[ x_{n+1} = x_n - \frac{f(x_n)/f'(x_n)}{1 - 0.5 \frac{f(x_n)}{f'(x_n)} \frac{f''(x_n)}{f'(x_n)} } \f] * where * \f[ \frac{\partial}{\partial x} \left(\frac{\text{B}(x;\alpha,\beta)}{\text{B}(\alpha,\beta)}\right) = \frac{1}{\text{B}(\alpha,\beta)} x^{\alpha-1} (1-x)^{\beta-1} \f] * \f[ \frac{\partial^2}{\partial x^2} \left(\frac{\text{B}(x;\alpha,\beta)}{\text{B}(\alpha,\beta)}\right) = \frac{1}{\text{B}(\alpha,\beta)} x^{\alpha-1} (1-x)^{\beta-1} \left( \frac{\alpha-1}{x} - \frac{\beta-1}{1 - x} \right) \f] */ template constexpr common_t incomplete_beta_inv(const T1 a, const T2 b, const T3 p) noexcept { return internal::incomplete_beta_inv_type_check(a,b,p); } #endif gcem-1.18.0/include/gcem_incl/incomplete_gamma.hpp000066400000000000000000000163321507212366300221030ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time (regularized) incomplete gamma function */ #ifndef _gcem_incomplete_gamma_HPP #define _gcem_incomplete_gamma_HPP namespace internal { // 50 point Gauss-Legendre quadrature template constexpr T incomplete_gamma_quad_inp_vals(const T lb, const T ub, const int counter) noexcept { return (ub-lb) * gauss_legendre_50_points[counter] / T(2) + (ub + lb) / T(2); } template constexpr T incomplete_gamma_quad_weight_vals(const T lb, const T ub, const int counter) noexcept { return (ub-lb) * gauss_legendre_50_weights[counter] / T(2); } template constexpr T incomplete_gamma_quad_fn(const T x, const T a, const T lg_term) noexcept { return exp( -x + (a-T(1))*log(x) - lg_term ); } template constexpr T incomplete_gamma_quad_recur(const T lb, const T ub, const T a, const T lg_term, const int counter) noexcept { return( counter < 49 ? \ // if incomplete_gamma_quad_fn(incomplete_gamma_quad_inp_vals(lb,ub,counter),a,lg_term) \ * incomplete_gamma_quad_weight_vals(lb,ub,counter) \ + incomplete_gamma_quad_recur(lb,ub,a,lg_term,counter+1) : // else incomplete_gamma_quad_fn(incomplete_gamma_quad_inp_vals(lb,ub,counter),a,lg_term) \ * incomplete_gamma_quad_weight_vals(lb,ub,counter) ); } template constexpr T incomplete_gamma_quad_lb(const T a, const T z) noexcept { return( a > T(1000) ? max(T(0),min(z,a) - 11*sqrt(a)) : // break integration into ranges a > T(800) ? max(T(0),min(z,a) - 11*sqrt(a)) : a > T(500) ? max(T(0),min(z,a) - 10*sqrt(a)) : a > T(300) ? max(T(0),min(z,a) - 10*sqrt(a)) : a > T(100) ? max(T(0),min(z,a) - 9*sqrt(a)) : a > T(90) ? max(T(0),min(z,a) - 9*sqrt(a)) : a > T(70) ? max(T(0),min(z,a) - 8*sqrt(a)) : a > T(50) ? max(T(0),min(z,a) - 7*sqrt(a)) : a > T(40) ? max(T(0),min(z,a) - 6*sqrt(a)) : a > T(30) ? max(T(0),min(z,a) - 5*sqrt(a)) : // else max(T(0),min(z,a)-4*sqrt(a)) ); } template constexpr T incomplete_gamma_quad_ub(const T a, const T z) noexcept { return( a > T(1000) ? min(z, a + 10*sqrt(a)) : a > T(800) ? min(z, a + 10*sqrt(a)) : a > T(500) ? min(z, a + 9*sqrt(a)) : a > T(300) ? min(z, a + 9*sqrt(a)) : a > T(100) ? min(z, a + 8*sqrt(a)) : a > T(90) ? min(z, a + 8*sqrt(a)) : a > T(70) ? min(z, a + 7*sqrt(a)) : a > T(50) ? min(z, a + 6*sqrt(a)) : // else min(z, a + 5*sqrt(a)) ); } template constexpr T incomplete_gamma_quad(const T a, const T z) noexcept { return incomplete_gamma_quad_recur(incomplete_gamma_quad_lb(a,z), incomplete_gamma_quad_ub(a,z), a,lgamma(a),0); } // reverse cf expansion // see: https://functions.wolfram.com/GammaBetaErf/Gamma2/10/0003/ template constexpr T incomplete_gamma_cf_2_recur(const T a, const T z, const int depth) noexcept { return( depth < 100 ? \ // if (1 + (depth-1)*2 - a + z) + depth*(a - depth)/incomplete_gamma_cf_2_recur(a,z,depth+1) : // else (1 + (depth-1)*2 - a + z) ); } template constexpr T incomplete_gamma_cf_2(const T a, const T z) noexcept { // lower (regularized) incomplete gamma function return( T(1.0) - exp(a*log(z) - z - lgamma(a)) / incomplete_gamma_cf_2_recur(a,z,1) ); } // cf expansion // see: http://functions.wolfram.com/GammaBetaErf/Gamma2/10/0009/ template constexpr T incomplete_gamma_cf_1_coef(const T a, const T z, const int depth) noexcept { return( is_odd(depth) ? - (a - 1 + T(depth+1)/T(2)) * z : T(depth)/T(2) * z ); } template constexpr T incomplete_gamma_cf_1_recur(const T a, const T z, const int depth) noexcept { return( depth < GCEM_INCML_GAMMA_MAX_ITER ? \ // if (a + depth - 1) + incomplete_gamma_cf_1_coef(a,z,depth)/incomplete_gamma_cf_1_recur(a,z,depth+1) : // else (a + depth - 1) ); } template constexpr T incomplete_gamma_cf_1(const T a, const T z) noexcept { // lower (regularized) incomplete gamma function return( exp(a*log(z) - z - lgamma(a)) / incomplete_gamma_cf_1_recur(a,z,1) ); } // template constexpr T incomplete_gamma_check(const T a, const T z) noexcept { return( // NaN check any_nan(a, z) ? \ GCLIM::quiet_NaN() : // a < T(0) ? \ GCLIM::quiet_NaN() : // GCLIM::min() > z ? \ T(0) : // GCLIM::min() > a ? \ T(1) : // cf or quadrature (a < T(10)) && (z - a < T(10)) ? incomplete_gamma_cf_1(a,z) : (a < T(10)) || (z/a > T(3)) ? incomplete_gamma_cf_2(a,z) : // else incomplete_gamma_quad(a,z) ); } template> constexpr TC incomplete_gamma_type_check(const T1 a, const T2 p) noexcept { return incomplete_gamma_check(static_cast(a), static_cast(p)); } } /** * Compile-time regularized lower incomplete gamma function * * @param a a real-valued, non-negative input. * @param x a real-valued, non-negative input. * * @return the regularized lower incomplete gamma function evaluated at (\c a, \c x), * \f[ \frac{\gamma(a,x)}{\Gamma(a)} = \frac{1}{\Gamma(a)} \int_0^x t^{a-1} \exp(-t) dt \f] * When \c a is not too large, the value is computed using the continued fraction representation of the upper incomplete gamma function, \f$ \Gamma(a,x) \f$, using * \f[ \Gamma(a,x) = \Gamma(a) - \dfrac{x^a\exp(-x)}{a - \dfrac{ax}{a + 1 + \dfrac{x}{a + 2 - \dfrac{(a+1)x}{a + 3 + \dfrac{2x}{a + 4 - \ddots}}}}} \f] * where \f$ \gamma(a,x) \f$ and \f$ \Gamma(a,x) \f$ are connected via * \f[ \frac{\gamma(a,x)}{\Gamma(a)} + \frac{\Gamma(a,x)}{\Gamma(a)} = 1 \f] * When \f$ a > 10 \f$, a 50-point Gauss-Legendre quadrature scheme is employed. */ template constexpr common_return_t incomplete_gamma(const T1 a, const T2 x) noexcept { return internal::incomplete_gamma_type_check(a,x); } #endif gcem-1.18.0/include/gcem_incl/incomplete_gamma_inv.hpp000066400000000000000000000166771507212366300227730ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * inverse of the incomplete gamma function */ #ifndef _gcem_incomplete_gamma_inv_HPP #define _gcem_incomplete_gamma_inv_HPP namespace internal { template constexpr T incomplete_gamma_inv_decision(const T value, const T a, const T p, const T direc, const T lg_val, const int iter_count) noexcept; // // initial value for Halley template constexpr T incomplete_gamma_inv_t_val_1(const T p) noexcept { // a > 1.0 return( p > T(0.5) ? sqrt(-2*log(T(1) - p)) : sqrt(-2*log(p)) ); } template constexpr T incomplete_gamma_inv_t_val_2(const T a) noexcept { // a <= 1.0 return( T(1) - T(0.253) * a - T(0.12) * a*a ); } // template constexpr T incomplete_gamma_inv_initial_val_1_int_begin(const T t_val) noexcept { // internal for a > 1.0 return( t_val - (T(2.515517L) + T(0.802853L)*t_val + T(0.010328L)*t_val*t_val) \ / (T(1) + T(1.432788L)*t_val + T(0.189269L)*t_val*t_val + T(0.001308L)*t_val*t_val*t_val) ); } template constexpr T incomplete_gamma_inv_initial_val_1_int_end(const T value_inp, const T a) noexcept { // internal for a > 1.0 return max( T(1E-04), a*pow(T(1) - T(1)/(9*a) - value_inp/(3*sqrt(a)), 3) ); } template constexpr T incomplete_gamma_inv_initial_val_1(const T a, const T t_val, const T sgn_term) noexcept { // a > 1.0 return incomplete_gamma_inv_initial_val_1_int_end(sgn_term*incomplete_gamma_inv_initial_val_1_int_begin(t_val), a); } template constexpr T incomplete_gamma_inv_initial_val_2(const T a, const T p, const T t_val) noexcept { // a <= 1.0 return( p < t_val ? \ // if pow(p/t_val,T(1)/a) : // else T(1) - log(T(1) - (p - t_val)/(T(1) - t_val)) ); } // initial value template constexpr T incomplete_gamma_inv_initial_val(const T a, const T p) noexcept { return( a > T(1) ? \ // if incomplete_gamma_inv_initial_val_1(a, incomplete_gamma_inv_t_val_1(p), p > T(0.5) ? T(-1) : T(1)) : // else incomplete_gamma_inv_initial_val_2(a,p, incomplete_gamma_inv_t_val_2(a))); } // // Halley recursion template constexpr T incomplete_gamma_inv_err_val(const T value, const T a, const T p) noexcept { // err_val = f(x) return( incomplete_gamma(a,value) - p ); } template constexpr T incomplete_gamma_inv_deriv_1(const T value, const T a, const T lg_val) noexcept { // derivative of the incomplete gamma function w.r.t. x return( exp( - value + (a - T(1))*log(value) - lg_val ) ); } template constexpr T incomplete_gamma_inv_deriv_2(const T value, const T a, const T deriv_1) noexcept { // second derivative of the incomplete gamma function w.r.t. x return( deriv_1*((a - T(1))/value - T(1)) ); } template constexpr T incomplete_gamma_inv_ratio_val_1(const T value, const T a, const T p, const T deriv_1) noexcept { return( incomplete_gamma_inv_err_val(value,a,p) / deriv_1 ); } template constexpr T incomplete_gamma_inv_ratio_val_2(const T value, const T a, const T deriv_1) noexcept { return( incomplete_gamma_inv_deriv_2(value,a,deriv_1) / deriv_1 ); } template constexpr T incomplete_gamma_inv_halley(const T ratio_val_1, const T ratio_val_2) noexcept { return( ratio_val_1 / max( T(0.8), min( T(1.2), T(1) - T(0.5)*ratio_val_1*ratio_val_2 ) ) ); } template constexpr T incomplete_gamma_inv_recur(const T value, const T a, const T p, const T deriv_1, const T lg_val, const int iter_count) noexcept { return incomplete_gamma_inv_decision(value, a, p, incomplete_gamma_inv_halley(incomplete_gamma_inv_ratio_val_1(value,a,p,deriv_1), incomplete_gamma_inv_ratio_val_2(value,a,deriv_1)), lg_val, iter_count); } template constexpr T incomplete_gamma_inv_decision(const T value, const T a, const T p, const T direc, const T lg_val, const int iter_count) noexcept { // return( abs(direc) > GCEM_INCML_GAMMA_INV_TOL ? incomplete_gamma_inv_recur(value - direc, a, p, incomplete_gamma_inv_deriv_1(value,a,lg_val), lg_val) : value - direc ); return( iter_count <= GCEM_INCML_GAMMA_INV_MAX_ITER ? \ // if incomplete_gamma_inv_recur(value-direc,a,p, incomplete_gamma_inv_deriv_1(value,a,lg_val), lg_val,iter_count+1) : // else value - direc ); } template constexpr T incomplete_gamma_inv_begin(const T initial_val, const T a, const T p, const T lg_val) noexcept { return incomplete_gamma_inv_recur(initial_val,a,p, incomplete_gamma_inv_deriv_1(initial_val,a,lg_val), lg_val,1); } template constexpr T incomplete_gamma_inv_check(const T a, const T p) noexcept { return( // NaN check any_nan(a, p) ? \ GCLIM::quiet_NaN() : // GCLIM::min() > p ? \ T(0) : p > T(1) ? \ GCLIM::quiet_NaN() : GCLIM::min() > abs(T(1) - p) ? \ GCLIM::infinity() : // GCLIM::min() > a ? \ T(0) : // else incomplete_gamma_inv_begin(incomplete_gamma_inv_initial_val(a,p),a,p,lgamma(a)) ); } template> constexpr TC incomplete_gamma_inv_type_check(const T1 a, const T2 p) noexcept { return incomplete_gamma_inv_check(static_cast(a), static_cast(p)); } } /** * Compile-time inverse incomplete gamma function * * @param a a real-valued, non-negative input. * @param p a real-valued input with values in the unit-interval. * * @return Computes the inverse incomplete gamma function, a value \f$ x \f$ such that * \f[ f(x) := \frac{\gamma(a,x)}{\Gamma(a)} - p \f] * equal to zero, for a given \c p. * GCE-Math finds this root using Halley's method: * \f[ x_{n+1} = x_n - \frac{f(x_n)/f'(x_n)}{1 - 0.5 \frac{f(x_n)}{f'(x_n)} \frac{f''(x_n)}{f'(x_n)} } \f] * where * \f[ \frac{\partial}{\partial x} \left(\frac{\gamma(a,x)}{\Gamma(a)}\right) = \frac{1}{\Gamma(a)} x^{a-1} \exp(-x) \f] * \f[ \frac{\partial^2}{\partial x^2} \left(\frac{\gamma(a,x)}{\Gamma(a)}\right) = \frac{1}{\Gamma(a)} x^{a-1} \exp(-x) \left( \frac{a-1}{x} - 1 \right) \f] */ template constexpr common_return_t incomplete_gamma_inv(const T1 a, const T2 p) noexcept { return internal::incomplete_gamma_inv_type_check(a,p); } #endif gcem-1.18.0/include/gcem_incl/inv_sqrt.hpp000066400000000000000000000043161507212366300204460ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time inverse-square-root function */ #ifndef _gcem_inv_sqrt_HPP #define _gcem_inv_sqrt_HPP namespace internal { template constexpr T inv_sqrt_recur(const T x, const T xn, const int count) noexcept { return( abs( xn - T(1)/(x*xn) ) / (T(1) + xn) < GCLIM::min() ? \ // if xn : count < GCEM_INV_SQRT_MAX_ITER ? \ // else inv_sqrt_recur(x, T(0.5)*(xn + T(1)/(x*xn)), count+1) : xn ); } template constexpr T inv_sqrt_check(const T x) noexcept { return( is_nan(x) ? \ GCLIM::quiet_NaN() : // x < T(0) ? \ GCLIM::quiet_NaN() : // is_posinf(x) ? \ T(0) : // indistinguishable from zero or one GCLIM::min() > abs(x) ? \ GCLIM::infinity() : GCLIM::min() > abs(T(1) - x) ? \ x : // else inv_sqrt_recur(x, x/T(2), 0) ); } } /** * Compile-time inverse-square-root function * * @param x a real-valued input. * @return Computes \f$ 1 / \sqrt{x} \f$ using a Newton-Raphson approach. */ template constexpr return_t inv_sqrt(const T x) noexcept { return internal::inv_sqrt_check( static_cast>(x) ); } #endif gcem-1.18.0/include/gcem_incl/is_even.hpp000066400000000000000000000021051507212366300202230ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time check if integer is even */ #ifndef _gcem_is_even_HPP #define _gcem_is_even_HPP namespace internal { constexpr bool is_even(const llint_t x) noexcept { return !is_odd(x); } } #endif gcem-1.18.0/include/gcem_incl/is_finite.hpp000066400000000000000000000034161507212366300205520ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time check if a float is not NaN-valued or +/-Inf */ #ifndef _gcem_is_finite_HPP #define _gcem_is_finite_HPP namespace internal { template constexpr bool is_finite(const T x) noexcept { return (!is_nan(x)) && (!is_inf(x)); } template constexpr bool any_finite(const T1 x, const T2 y) noexcept { return( is_finite(x) || is_finite(y) ); } template constexpr bool all_finite(const T1 x, const T2 y) noexcept { return( is_finite(x) && is_finite(y) ); } template constexpr bool any_finite(const T1 x, const T2 y, const T3 z) noexcept { return( is_finite(x) || is_finite(y) || is_finite(z) ); } template constexpr bool all_finite(const T1 x, const T2 y, const T3 z) noexcept { return( is_finite(x) && is_finite(y) && is_finite(z) ); } } #endif gcem-1.18.0/include/gcem_incl/is_inf.hpp000066400000000000000000000063141507212366300200500ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time check if a float is +/-Inf */ #ifndef _gcem_is_inf_HPP #define _gcem_is_inf_HPP namespace internal { template constexpr bool is_neginf(const T x) noexcept { return x == - GCLIM::infinity(); } template constexpr bool any_neginf(const T1 x, const T2 y) noexcept { return( is_neginf(x) || is_neginf(y) ); } template constexpr bool all_neginf(const T1 x, const T2 y) noexcept { return( is_neginf(x) && is_neginf(y) ); } template constexpr bool any_neginf(const T1 x, const T2 y, const T3 z) noexcept { return( is_neginf(x) || is_neginf(y) || is_neginf(z) ); } template constexpr bool all_neginf(const T1 x, const T2 y, const T3 z) noexcept { return( is_neginf(x) && is_neginf(y) && is_neginf(z) ); } // template constexpr bool is_posinf(const T x) noexcept { return x == GCLIM::infinity(); } template constexpr bool any_posinf(const T1 x, const T2 y) noexcept { return( is_posinf(x) || is_posinf(y) ); } template constexpr bool all_posinf(const T1 x, const T2 y) noexcept { return( is_posinf(x) && is_posinf(y) ); } template constexpr bool any_posinf(const T1 x, const T2 y, const T3 z) noexcept { return( is_posinf(x) || is_posinf(y) || is_posinf(z) ); } template constexpr bool all_posinf(const T1 x, const T2 y, const T3 z) noexcept { return( is_posinf(x) && is_posinf(y) && is_posinf(z) ); } // template constexpr bool is_inf(const T x) noexcept { return( is_neginf(x) || is_posinf(x) ); } template constexpr bool any_inf(const T1 x, const T2 y) noexcept { return( is_inf(x) || is_inf(y) ); } template constexpr bool all_inf(const T1 x, const T2 y) noexcept { return( is_inf(x) && is_inf(y) ); } template constexpr bool any_inf(const T1 x, const T2 y, const T3 z) noexcept { return( is_inf(x) || is_inf(y) || is_inf(z) ); } template constexpr bool all_inf(const T1 x, const T2 y, const T3 z) noexcept { return( is_inf(x) && is_inf(y) && is_inf(z) ); } } #endif gcem-1.18.0/include/gcem_incl/is_nan.hpp000066400000000000000000000033471507212366300200530ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time check if a float is NaN-valued */ #ifndef _gcem_is_nan_HPP #define _gcem_is_nan_HPP namespace internal { // future: consider using __builtin_isnan(__x) template constexpr bool is_nan(const T x) noexcept { return x != x; } template constexpr bool any_nan(const T1 x, const T2 y) noexcept { return( is_nan(x) || is_nan(y) ); } template constexpr bool all_nan(const T1 x, const T2 y) noexcept { return( is_nan(x) && is_nan(y) ); } template constexpr bool any_nan(const T1 x, const T2 y, const T3 z) noexcept { return( is_nan(x) || is_nan(y) || is_nan(z) ); } template constexpr bool all_nan(const T1 x, const T2 y, const T3 z) noexcept { return( is_nan(x) && is_nan(y) && is_nan(z) ); } } #endif gcem-1.18.0/include/gcem_incl/is_odd.hpp000066400000000000000000000022021507212366300200320ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time check if integer is odd */ #ifndef _gcem_is_odd_HPP #define _gcem_is_odd_HPP namespace internal { constexpr bool is_odd(const llint_t x) noexcept { // return( x % llint_t(2) == llint_t(0) ? false : true ); return (x & 1U) != 0; } } #endif gcem-1.18.0/include/gcem_incl/lbeta.hpp000066400000000000000000000026671507212366300176770ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #ifndef _gcem_lbeta_HPP #define _gcem_lbeta_HPP /** * Compile-time log-beta function * * @param a a real-valued input. * @param b a real-valued input. * @return the log-beta function using \f[ \ln \text{B}(\alpha,\beta) := \ln \int_0^1 t^{\alpha - 1} (1-t)^{\beta - 1} dt = \ln \Gamma(\alpha) + \ln \Gamma(\beta) - \ln \Gamma(\alpha + \beta) \f] * where \f$ \Gamma \f$ denotes the gamma function. */ template constexpr common_return_t lbeta(const T1 a, const T2 b) noexcept { return( (lgamma(a) + lgamma(b)) - lgamma(a+b) ); } #endif gcem-1.18.0/include/gcem_incl/lcm.hpp000066400000000000000000000034151507212366300173530ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #ifndef _gcem_lcm_HPP #define _gcem_lcm_HPP namespace internal { template constexpr T lcm_compute(const T a, const T b) noexcept { return abs(a * (b / gcd(a,b))); } template> constexpr TC lcm_type_check(const T1 a, const T2 b) noexcept { return lcm_compute(static_cast(a),static_cast(b)); } } /** * Compile-time least common multiple (LCM) function * * @param a integral-valued input. * @param b integral-valued input. * @return the least common multiple between integers \c a and \c b using the representation \f[ \text{lcm}(a,b) = \dfrac{| a b |}{\text{gcd}(a,b)} \f] * where \f$ \text{gcd}(a,b) \f$ denotes the greatest common divisor between \f$ a \f$ and \f$ b \f$. */ template constexpr common_t lcm(const T1 a, const T2 b) noexcept { return internal::lcm_type_check(a,b); } #endif gcem-1.18.0/include/gcem_incl/lgamma.hpp000066400000000000000000000075301507212366300200400ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time log-gamma function * * for coefficient values, see: * http://my.fit.edu/~gabdo/gamma.txt */ #ifndef _gcem_lgamma_HPP #define _gcem_lgamma_HPP namespace internal { // P. Godfrey's coefficients: // // 0.99999999999999709182 // 57.156235665862923517 // -59.597960355475491248 // 14.136097974741747174 // -0.49191381609762019978 // .33994649984811888699e-4 // .46523628927048575665e-4 // -.98374475304879564677e-4 // .15808870322491248884e-3 // -.21026444172410488319e-3 // .21743961811521264320e-3 // -.16431810653676389022e-3 // .84418223983852743293e-4 // -.26190838401581408670e-4 // .36899182659531622704e-5 constexpr long double lgamma_coef_term(const long double x) noexcept { return( 0.99999999999999709182L + 57.156235665862923517L / (x+1) \ - 59.597960355475491248L / (x+2) + 14.136097974741747174L / (x+3) \ - 0.49191381609762019978L / (x+4) + .33994649984811888699e-4L / (x+5) \ + .46523628927048575665e-4L / (x+6) - .98374475304879564677e-4L / (x+7) \ + .15808870322491248884e-3L / (x+8) - .21026444172410488319e-3L / (x+9) \ + .21743961811521264320e-3L / (x+10) - .16431810653676389022e-3L / (x+11) \ + .84418223983852743293e-4L / (x+12) - .26190838401581408670e-4L / (x+13) \ + .36899182659531622704e-5L / (x+14) ); } template constexpr T lgamma_term_2(const T x) noexcept { // return( T(GCEM_LOG_SQRT_2PI) + log(T(lgamma_coef_term(x))) ); } template constexpr T lgamma_term_1(const T x) noexcept { // note: 607/128 + 0.5 = 5.2421875 return( (x + T(0.5))*log(x + T(5.2421875L)) - (x + T(5.2421875L)) ); } template constexpr T lgamma_begin(const T x) noexcept { // returns lngamma(x+1) return( lgamma_term_1(x) + lgamma_term_2(x) ); } template constexpr T lgamma_check(const T x) noexcept { return( // NaN check is_nan(x) ? \ GCLIM::quiet_NaN() : // indistinguishable from one or <= zero GCLIM::min() > abs(x - T(1)) ? \ T(0) : GCLIM::min() > x ? \ GCLIM::infinity() : // else lgamma_begin(x - T(1)) ); } } /** * Compile-time log-gamma function * * @param x a real-valued input. * @return computes the log-gamma function * \f[ \ln \Gamma(x) = \ln \int_0^\infty y^{x-1} \exp(-y) dy \f] * using a polynomial form: * \f[ \Gamma(x+1) \approx (x+g+0.5)^{x+0.5} \exp(-x-g-0.5) \sqrt{2 \pi} \left[ c_0 + \frac{c_1}{x+1} + \frac{c_2}{x+2} + \cdots + \frac{c_n}{x+n} \right] \f] * where the value \f$ g \f$ and the coefficients \f$ (c_0, c_1, \ldots, c_n) \f$ * are taken from Paul Godfrey, whose note can be found here: http://my.fit.edu/~gabdo/gamma.txt */ template constexpr return_t lgamma(const T x) noexcept { return internal::lgamma_check( static_cast>(x) ); } #endif gcem-1.18.0/include/gcem_incl/lmgamma.hpp000066400000000000000000000037561507212366300202230ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * log multivariate gamma function */ #ifndef _gcem_lmgamma_HPP #define _gcem_lmgamma_HPP namespace internal { // see https://en.wikipedia.org/wiki/Multivariate_gamma_function template constexpr T1 lmgamma_recur(const T1 a, const T2 p) noexcept { return( // NaN check is_nan(a) ? \ GCLIM::quiet_NaN() : // p == T2(1) ? \ lgamma(a) : p < T2(1) ? \ GCLIM::quiet_NaN() : // else T1(GCEM_LOG_PI) * (p - T1(1))/T1(2) \ + lgamma(a) + lmgamma_recur(a - T1(0.5),p-T2(1)) ); } } /** * Compile-time log multivariate gamma function * * @param a a real-valued input. * @param p integral-valued input. * @return computes log-multivariate gamma function via recursion * \f[ \Gamma_p(a) = \pi^{(p-1)/2} \Gamma(a) \Gamma_{p-1}(a-0.5) \f] * where \f$ \Gamma_1(a) = \Gamma(a) \f$. */ template constexpr return_t lmgamma(const T1 a, const T2 p) noexcept { return internal::lmgamma_recur(static_cast>(a),p); } #endif gcem-1.18.0/include/gcem_incl/log.hpp000066400000000000000000000113251507212366300173600ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time natural logarithm function */ #ifndef _gcem_log_HPP #define _gcem_log_HPP namespace internal { // continued fraction seems to be a better approximation for small x // see http://functions.wolfram.com/ElementaryFunctions/Log/10/0005/ #if __cplusplus >= 201402L // C++14 version template constexpr T log_cf_main(const T xx, const int depth_end) noexcept { int depth = GCEM_LOG_MAX_ITER_SMALL - 1; T res = T(2*(depth+1) - 1); while (depth > depth_end - 1) { res = T(2*depth - 1) - T(depth*depth) * xx / res; --depth; } return res; } #else // C++11 version template constexpr T log_cf_main(const T xx, const int depth) noexcept { return( depth < GCEM_LOG_MAX_ITER_SMALL ? \ // if T(2*depth - 1) - T(depth*depth) * xx / log_cf_main(xx,depth+1) : // else T(2*depth - 1) ); } #endif template constexpr T log_cf_begin(const T x) noexcept { return( T(2)*x/log_cf_main(x*x,1) ); } template constexpr T log_main(const T x) noexcept { return( log_cf_begin((x - T(1))/(x + T(1))) ); } constexpr long double log_mantissa_integer(const int x) noexcept { return( x == 2 ? 0.6931471805599453094172321214581765680755L : x == 3 ? 1.0986122886681096913952452369225257046475L : x == 4 ? 1.3862943611198906188344642429163531361510L : x == 5 ? 1.6094379124341003746007593332261876395256L : x == 6 ? 1.7917594692280550008124773583807022727230L : x == 7 ? 1.9459101490553133051053527434431797296371L : x == 8 ? 2.0794415416798359282516963643745297042265L : x == 9 ? 2.1972245773362193827904904738450514092950L : x == 10 ? 2.3025850929940456840179914546843642076011L : 0.0L ); } template constexpr T log_mantissa(const T x) noexcept { // divide by the integer part of x, which will be in [1,10], then adjust using tables return( log_main(x/T(static_cast(x))) + T(log_mantissa_integer(static_cast(x))) ); } template constexpr T log_breakup(const T x) noexcept { // x = a*b, where b = 10^c return( log_mantissa(mantissa(x)) + T(GCEM_LOG_10) * T(find_exponent(x,0)) ); } template constexpr T log_check(const T x) noexcept { return( is_nan(x) ? \ GCLIM::quiet_NaN() : // x < 0 x < T(0) ? \ GCLIM::quiet_NaN() : // x ~= 0 GCLIM::min() > x ? \ - GCLIM::infinity() : // indistinguishable from 1 GCLIM::min() > abs(x - T(1)) ? \ T(0) : // x == GCLIM::infinity() ? \ GCLIM::infinity() : // else (x < T(0.5) || x > T(1.5)) ? // if log_breakup(x) : // else log_main(x) ); } template constexpr return_t log_integral_check(const T x) noexcept { return( std::is_integral::value ? \ x == T(0) ? \ - GCLIM>::infinity() : x > T(1) ? \ log_check( static_cast>(x) ) : static_cast>(0) : log_check( static_cast>(x) ) ); } } /** * Compile-time natural logarithm function * * @param x a real-valued input. * @return \f$ \log_e(x) \f$ using \f[ \log\left(\frac{1+x}{1-x}\right) = \dfrac{2x}{1-\dfrac{x^2}{3-\dfrac{4x^2}{5 - \dfrac{9x^3}{7 - \ddots}}}}, \ \ x \in [-1,1] \f] * The continued fraction argument is split into two parts: \f$ x = a \times 10^c \f$, where \f$ c \f$ is an integer. */ template constexpr return_t log(const T x) noexcept { return internal::log_integral_check( x ); } #endif gcem-1.18.0/include/gcem_incl/log10.hpp000066400000000000000000000026701507212366300175240ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time common logarithm function */ #ifndef _gcem_log10_HPP #define _gcem_log10_HPP namespace internal { template constexpr return_t log10_check(const T x) noexcept { // log_10(x) = ln(x) / ln(10) return return_t(log(x) / GCEM_LOG_10); } } /** * Compile-time common logarithm function * * @param x a real-valued input. * @return \f$ \log_{10}(x) \f$ using \f[ \log_{10}(x) = \frac{\log_e(x)}{\log_e(10)} \f] */ template constexpr return_t log10(const T x) noexcept { return internal::log10_check( x ); } #endif gcem-1.18.0/include/gcem_incl/log1p.hpp000066400000000000000000000037751507212366300176330ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time natural logarithm(x+1) function */ #ifndef _gcem_log1p_HPP #define _gcem_log1p_HPP namespace internal { // see: // http://functions.wolfram.com/ElementaryFunctions/Log/06/01/04/01/0003/ template constexpr T log1p_compute(const T x) noexcept { // return x * ( T(1) + x * ( -T(1)/T(2) + x * ( T(1)/T(3) + x * ( -T(1)/T(4) + x/T(5) ) ) ) ); // O(x^6) return x + x * ( - x/T(2) + x * ( x/T(3) + x * ( -x/T(4) + x*x/T(5) ) ) ); // O(x^6) } template constexpr T log1p_check(const T x) noexcept { return( // NaN check is_nan(x) ? \ GCLIM::quiet_NaN() : // abs(x) > T(1e-04) ? \ // if log(T(1) + x) : // else log1p_compute(x) ); } } /** * Compile-time natural-logarithm-plus-1 function * * @param x a real-valued input. * @return \f$ \log_e(x+1) \f$ using \f[ \log(x+1) = \sum_{k=1}^\infty \dfrac{(-1)^{k-1}x^k}{k}, \ \ |x| < 1 \f] */ template constexpr return_t log1p(const T x) noexcept { return internal::log1p_check( static_cast>(x) ); } #endif gcem-1.18.0/include/gcem_incl/log2.hpp000066400000000000000000000026531507212366300174460ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time binary logarithm function */ #ifndef _gcem_log2_HPP #define _gcem_log2_HPP namespace internal { template constexpr return_t log2_check(const T x) noexcept { // log_2(x) = ln(x) / ln(2) return return_t(log(x) / GCEM_LOG_2); } } /** * Compile-time binary logarithm function * * @param x a real-valued input. * @return \f$ \log_2(x) \f$ using \f[ \log_{2}(x) = \frac{\log_e(x)}{\log_e(2)} \f] */ template constexpr return_t log2(const T x) noexcept { return internal::log2_check( x ); } #endif gcem-1.18.0/include/gcem_incl/log_binomial_coef.hpp000066400000000000000000000034311507212366300222250ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #ifndef _gcem_log_binomial_coef_HPP #define _gcem_log_binomial_coef_HPP namespace internal { template constexpr T log_binomial_coef_compute(const T n, const T k) noexcept { return( lgamma(n+1) - (lgamma(k+1) + lgamma(n-k+1)) ); } template> constexpr TC log_binomial_coef_type_check(const T1 n, const T2 k) noexcept { return log_binomial_coef_compute(static_cast(n),static_cast(k)); } } /** * Compile-time log binomial coefficient * * @param n integral-valued input. * @param k integral-valued input. * @return computes the log Binomial coefficient * \f[ \ln \frac{n!}{k!(n-k)!} = \ln \Gamma(n+1) - [ \ln \Gamma(k+1) + \ln \Gamma(n-k+1) ] \f] */ template constexpr common_return_t log_binomial_coef(const T1 n, const T2 k) noexcept { return internal::log_binomial_coef_type_check(n,k); } #endifgcem-1.18.0/include/gcem_incl/mantissa.hpp000066400000000000000000000023371507212366300204210ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time mantissa function */ #ifndef _gcem_mantissa_HPP #define _gcem_mantissa_HPP namespace internal { template constexpr T mantissa(const T x) noexcept { return( x < T(1) ? \ mantissa(x * T(10)) : x > T(10) ? \ mantissa(x / T(10)) : // else x ); } } #endif gcem-1.18.0/include/gcem_incl/max.hpp000066400000000000000000000024401507212366300173620ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #ifndef _gcem_max_HPP #define _gcem_max_HPP /** * Compile-time pairwise maximum function * * @param x a real-valued input. * @param y a real-valued input. * @return Computes the maximum between \c x and \c y, where \c x and \c y have the same type (e.g., \c int, \c double, etc.) */ template constexpr common_t max(const T1 x, const T2 y) noexcept { return( y < x ? x : y ); } #endif gcem-1.18.0/include/gcem_incl/min.hpp000066400000000000000000000024401507212366300173600ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #ifndef _gcem_min_HPP #define _gcem_min_HPP /** * Compile-time pairwise minimum function * * @param x a real-valued input. * @param y a real-valued input. * @return Computes the minimum between \c x and \c y, where \c x and \c y have the same type (e.g., \c int, \c double, etc.) */ template constexpr common_t min(const T1 x, const T2 y) noexcept { return( y > x ? x : y ); } #endif gcem-1.18.0/include/gcem_incl/neg_zero.hpp000066400000000000000000000020771507212366300204130ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * extract signbit for signed zeros */ namespace internal { template constexpr bool neg_zero(const T x) noexcept { return( (x == T(0.0)) && (copysign(T(1.0), x) == T(-1.0)) ); } } gcem-1.18.0/include/gcem_incl/pow.hpp000066400000000000000000000043331507212366300174050ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time power function */ #ifndef _gcem_pow_HPP #define _gcem_pow_HPP namespace internal { template constexpr T pow_dbl(const T base, const T exp_term) noexcept { return exp(exp_term*log(base)); } template, typename std::enable_if::value>::type* = nullptr> constexpr TC pow_check(const T1 base, const T2 exp_term) noexcept { return( base < T1(0) ? \ GCLIM::quiet_NaN() : // pow_dbl(static_cast(base),static_cast(exp_term)) ); } template, typename std::enable_if::value>::type* = nullptr> constexpr TC pow_check(const T1 base, const T2 exp_term) noexcept { return pow_integral(base,exp_term); } } /** * Compile-time power function * * @param base a real-valued input. * @param exp_term a real-valued input. * @return Computes \c base raised to the power \c exp_term. In the case where \c exp_term is integral-valued, recursion by squaring is used, otherwise \f$ \text{base}^{\text{exp\_term}} = e^{\text{exp\_term} \log(\text{base})} \f$ */ template constexpr common_t pow(const T1 base, const T2 exp_term) noexcept { return internal::pow_check(base,exp_term); } #endif gcem-1.18.0/include/gcem_incl/pow_integral.hpp000066400000000000000000000071161507212366300212740ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time power function */ #ifndef _gcem_pow_integral_HPP #define _gcem_pow_integral_HPP namespace internal { template constexpr T1 pow_integral_compute(const T1 base, const T2 exp_term) noexcept; // integral-valued powers using method described in // https://en.wikipedia.org/wiki/Exponentiation_by_squaring template constexpr T1 pow_integral_compute_recur(const T1 base, const T1 val, const T2 exp_term) noexcept { return( exp_term > T2(1) ? \ (is_odd(exp_term) ? \ pow_integral_compute_recur(base*base,val*base,exp_term/2) : pow_integral_compute_recur(base*base,val,exp_term/2)) : (exp_term == T2(1) ? val*base : val) ); } template::value>::type* = nullptr> constexpr T1 pow_integral_sgn_check(const T1 base, const T2 exp_term) noexcept { return( exp_term < T2(0) ? \ // T1(1) / pow_integral_compute(base, - exp_term) : // pow_integral_compute_recur(base,T1(1),exp_term) ); } template::value>::type* = nullptr> constexpr T1 pow_integral_sgn_check(const T1 base, const T2 exp_term) noexcept { return( pow_integral_compute_recur(base,T1(1),exp_term) ); } template constexpr T1 pow_integral_compute(const T1 base, const T2 exp_term) noexcept { return( exp_term == T2(3) ? \ base*base*base : exp_term == T2(2) ? \ base*base : exp_term == T2(1) ? \ base : exp_term == T2(0) ? \ T1(1) : // check for overflow exp_term == GCLIM::min() ? \ T1(0) : exp_term == GCLIM::max() ? \ GCLIM::infinity() : // else pow_integral_sgn_check(base,exp_term) ); } template::value>::type* = nullptr> constexpr T1 pow_integral_type_check(const T1 base, const T2 exp_term) noexcept { return pow_integral_compute(base,exp_term); } template::value>::type* = nullptr> constexpr T1 pow_integral_type_check(const T1 base, const T2 exp_term) noexcept { // return GCLIM>::quiet_NaN(); return pow_integral_compute(base,static_cast(exp_term)); } // // main function template constexpr T1 pow_integral(const T1 base, const T2 exp_term) noexcept { return internal::pow_integral_type_check(base,exp_term); } } #endif gcem-1.18.0/include/gcem_incl/quadrature/000077500000000000000000000000001507212366300202415ustar00rootroot00000000000000gcem-1.18.0/include/gcem_incl/quadrature/gauss_legendre_30.hpp000066400000000000000000000067341507212366300242550ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * Gauss-Legendre quadrature: 30 points */ static const long double gauss_legendre_30_points[30] = \ { -0.05147184255531769583302521316672L, 0.05147184255531769583302521316672L, -0.15386991360858354696379467274326L, 0.15386991360858354696379467274326L, -0.25463692616788984643980512981781L, 0.25463692616788984643980512981781L, -0.35270472553087811347103720708937L, 0.35270472553087811347103720708937L, -0.44703376953808917678060990032285L, 0.44703376953808917678060990032285L, -0.53662414814201989926416979331107L, 0.53662414814201989926416979331107L, -0.62052618298924286114047755643119L, 0.62052618298924286114047755643119L, -0.69785049479331579693229238802664L, 0.69785049479331579693229238802664L, -0.76777743210482619491797734097450L, 0.76777743210482619491797734097450L, -0.82956576238276839744289811973250L, 0.82956576238276839744289811973250L, -0.88256053579205268154311646253023L, 0.88256053579205268154311646253023L, -0.92620004742927432587932427708047L, 0.92620004742927432587932427708047L, -0.96002186496830751221687102558180L, 0.96002186496830751221687102558180L, -0.98366812327974720997003258160566L, 0.98366812327974720997003258160566L, -0.99689348407464954027163005091870L, 0.99689348407464954027163005091870L\ }; static const long double gauss_legendre_30_weights[30] = \ { 0.10285265289355884034128563670542L, 0.10285265289355884034128563670542L, 0.10176238974840550459642895216855L, 0.10176238974840550459642895216855L, 0.09959342058679526706278028210357L, 0.09959342058679526706278028210357L, 0.09636873717464425963946862635181L, 0.09636873717464425963946862635181L, 0.09212252223778612871763270708762L, 0.09212252223778612871763270708762L, 0.08689978720108297980238753071513L, 0.08689978720108297980238753071513L, 0.08075589522942021535469493846053L, 0.08075589522942021535469493846053L, 0.07375597473770520626824385002219L, 0.07375597473770520626824385002219L, 0.06597422988218049512812851511596L, 0.06597422988218049512812851511596L, 0.05749315621761906648172168940206L, 0.05749315621761906648172168940206L, 0.04840267283059405290293814042281L, 0.04840267283059405290293814042281L, 0.03879919256962704959680193644635L, 0.03879919256962704959680193644635L, 0.02878470788332336934971917961129L, 0.02878470788332336934971917961129L, 0.01846646831109095914230213191205L, 0.01846646831109095914230213191205L, 0.00796819249616660561546588347467L, 0.00796819249616660561546588347467L\ }; gcem-1.18.0/include/gcem_incl/quadrature/gauss_legendre_50.hpp000066400000000000000000000121301507212366300242420ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * Gauss-Legendre quadrature: 50 points */ static const long double gauss_legendre_50_points[50] = \ { -0.03109833832718887611232898966595L, 0.03109833832718887611232898966595L, -0.09317470156008614085445037763960L, 0.09317470156008614085445037763960L, -0.15489058999814590207162862094111L, 0.15489058999814590207162862094111L, -0.21600723687604175684728453261710L, 0.21600723687604175684728453261710L, -0.27628819377953199032764527852113L, 0.27628819377953199032764527852113L, -0.33550024541943735683698825729107L, 0.33550024541943735683698825729107L, -0.39341431189756512739422925382382L, 0.39341431189756512739422925382382L, -0.44980633497403878914713146777838L, 0.44980633497403878914713146777838L, -0.50445814490746420165145913184914L, 0.50445814490746420165145913184914L, -0.55715830451465005431552290962580L, 0.55715830451465005431552290962580L, -0.60770292718495023918038179639183L, 0.60770292718495023918038179639183L, -0.65589646568543936078162486400368L, 0.65589646568543936078162486400368L, -0.70155246870682225108954625788366L, 0.70155246870682225108954625788366L, -0.74449430222606853826053625268219L, 0.74449430222606853826053625268219L, -0.78455583290039926390530519634099L, 0.78455583290039926390530519634099L, -0.82158207085933594835625411087394L, 0.82158207085933594835625411087394L, -0.85542976942994608461136264393476L, 0.85542976942994608461136264393476L, -0.88596797952361304863754098246675L, 0.88596797952361304863754098246675L, -0.91307855665579189308973564277166L, 0.91307855665579189308973564277166L, -0.93665661894487793378087494727250L, 0.93665661894487793378087494727250L, -0.95661095524280794299774564415662L, 0.95661095524280794299774564415662L, -0.97286438510669207371334410460625L, 0.97286438510669207371334410460625L, -0.98535408404800588230900962563249L, 0.98535408404800588230900962563249L, -0.99403196943209071258510820042069L, 0.99403196943209071258510820042069L, -0.99886640442007105018545944497422L, 0.99886640442007105018545944497422L\ }; static const long double gauss_legendre_50_weights[50] = \ { 0.06217661665534726232103310736061L, 0.06217661665534726232103310736061L, 0.06193606742068324338408750978083L, 0.06193606742068324338408750978083L, 0.06145589959031666375640678608392L, 0.06145589959031666375640678608392L, 0.06073797084177021603175001538481L, 0.06073797084177021603175001538481L, 0.05978505870426545750957640531259L, 0.05978505870426545750957640531259L, 0.05860084981322244583512243663085L, 0.05860084981322244583512243663085L, 0.05718992564772838372302931506599L, 0.05718992564772838372302931506599L, 0.05555774480621251762356742561227L, 0.05555774480621251762356742561227L, 0.05371062188899624652345879725566L, 0.05371062188899624652345879725566L, 0.05165570306958113848990529584010L, 0.05165570306958113848990529584010L, 0.04940093844946631492124358075143L, 0.04940093844946631492124358075143L, 0.04695505130394843296563301363499L, 0.04695505130394843296563301363499L, 0.04432750433880327549202228683039L, 0.04432750433880327549202228683039L, 0.04152846309014769742241197896407L, 0.04152846309014769742241197896407L, 0.03856875661258767524477015023639L, 0.03856875661258767524477015023639L, 0.03545983561514615416073461100098L, 0.03545983561514615416073461100098L, 0.03221372822357801664816582732300L, 0.03221372822357801664816582732300L, 0.02884299358053519802990637311323L, 0.02884299358053519802990637311323L, 0.02536067357001239044019487838544L, 0.02536067357001239044019487838544L, 0.02178024317012479298159206906269L, 0.02178024317012479298159206906269L, 0.01811556071348939035125994342235L, 0.01811556071348939035125994342235L, 0.01438082276148557441937890892732L, 0.01438082276148557441937890892732L, 0.01059054838365096926356968149924L, 0.01059054838365096926356968149924L, 0.00675979919574540150277887817799L, 0.00675979919574540150277887817799L, 0.00290862255315514095840072434286L, 0.00290862255315514095840072434286L\ }; gcem-1.18.0/include/gcem_incl/round.hpp000066400000000000000000000051641507212366300177320ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #ifndef _gcem_round_HPP #define _gcem_round_HPP namespace internal { template constexpr T round_int(const T x) noexcept { return( abs(x - internal::floor_check(x)) >= T(0.5) ? \ // if internal::floor_check(x) + sgn(x) : \ // else internal::floor_check(x) ); } template constexpr T round_check_internal(const T x) noexcept { return x; } template<> constexpr float round_check_internal(const float x) noexcept { return( abs(x) >= 8388608.f ? \ // if x : \ //else round_int(x) ); } template<> constexpr double round_check_internal(const double x) noexcept { return( abs(x) >= 4503599627370496. ? \ // if x : \ // else round_int(x) ); } template<> constexpr long double round_check_internal(const long double x) noexcept { return( abs(x) >= 9223372036854775808.l ? \ // if x : \ // else round_int(x) ); } template constexpr T round_check(const T x) noexcept { return( // NaN check is_nan(x) ? \ GCLIM::quiet_NaN() : // +/- infinite !is_finite(x) ? \ x : // signed-zero cases GCLIM::min() > abs(x) ? \ x : // else sgn(x) * round_check_internal(abs(x)) ); } } /** * Compile-time round function * * @param x a real-valued input. * @return computes the rounding value of the input. */ template constexpr return_t round(const T x) noexcept { return internal::round_check( static_cast>(x) ); } #endif gcem-1.18.0/include/gcem_incl/sgn.hpp000066400000000000000000000025321507212366300173660ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #ifndef _gcem_sgn_HPP #define _gcem_sgn_HPP /** * Compile-time sign function * * @param x a real-valued input * @return a value \f$ y \f$ such that \f[ y = \begin{cases} 1 \ &\text{ if } x > 0 \\ 0 \ &\text{ if } x = 0 \\ -1 \ &\text{ if } x < 0 \end{cases} \f] */ template constexpr int sgn(const T x) noexcept { return( // positive x > T(0) ? 1 : // negative x < T(0) ? -1 : // else 0 ); } #endif gcem-1.18.0/include/gcem_incl/signbit.hpp000066400000000000000000000024211507212366300202330ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #ifndef _gcem_signbit_HPP #define _gcem_signbit_HPP /** * Compile-time sign bit detection function * * @param x a real-valued input * @return return true if \c x is negative, otherwise return false. */ template constexpr bool signbit(const T x) noexcept { #ifdef _MSC_VER return( (x == T(0)) ? (_fpclass(x) == _FPCLASS_NZ) : (x < T(0)) ); #else return GCEM_SIGNBIT(x); #endif } #endif gcem-1.18.0/include/gcem_incl/sin.hpp000066400000000000000000000041441507212366300173710ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time sine function using tan(x/2) * * see eq. 5.4.8 in Numerical Recipes */ #ifndef _gcem_sin_HPP #define _gcem_sin_HPP namespace internal { template constexpr T sin_compute(const T x) noexcept { return T(2)*x/(T(1) + x*x); } template constexpr T sin_check(const T x) noexcept { return( // NaN check is_nan(x) ? \ GCLIM::quiet_NaN() : // indistinguishable from zero GCLIM::min() > abs(x) ? \ T(0) : // special cases: pi/2 and pi GCLIM::min() > abs(x - T(GCEM_HALF_PI)) ? \ T(1) : GCLIM::min() > abs(x + T(GCEM_HALF_PI)) ? \ - T(1) : GCLIM::min() > abs(x - T(GCEM_PI)) ? \ T(0) : GCLIM::min() > abs(x + T(GCEM_PI)) ? \ - T(0) : // else sin_compute( tan(x/T(2)) ) ); } } /** * Compile-time sine function * * @param x a real-valued input. * @return the sine function using \f[ \sin(x) = \frac{2\tan(x/2)}{1+\tan^2(x/2)} \f] */ template constexpr return_t sin(const T x) noexcept { return internal::sin_check( static_cast>(x) ); } #endif gcem-1.18.0/include/gcem_incl/sinh.hpp000066400000000000000000000031711507212366300175400ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time hyperbolic sine function */ #ifndef _gcem_sinh_HPP #define _gcem_sinh_HPP namespace internal { template constexpr T sinh_check(const T x) noexcept { return( // NaN check is_nan(x) ? \ GCLIM::quiet_NaN() : // indistinguishable from zero GCLIM::min() > abs(x) ? \ T(0) : // else (exp(x) - exp(-x))/T(2) ); } } /** * Compile-time hyperbolic sine function * * @param x a real-valued input. * @return the hyperbolic sine function using \f[ \sinh(x) = \frac{\exp(x) - \exp(-x)}{2} \f] */ template constexpr return_t sinh(const T x) noexcept { return internal::sinh_check( static_cast>(x) ); } #endif gcem-1.18.0/include/gcem_incl/sqrt.hpp000066400000000000000000000053661507212366300176000ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time square-root function */ #ifndef _gcem_sqrt_HPP #define _gcem_sqrt_HPP namespace internal { template constexpr T sqrt_recur(const T x, const T xn, const int count) noexcept { return( abs(xn - x/xn) / (T(1) + xn) < GCLIM::min() ? \ // if xn : // else count < GCEM_SQRT_MAX_ITER ? \ // if sqrt_recur(x, T(0.5)*(xn + x/xn), count+1) : // else xn ); } template constexpr T sqrt_simplify(const T x, const T m_val) noexcept { return( x > T(1e+08) ? \ sqrt_simplify(x / T(1e+08), T(1e+04) * m_val) : x > T(1e+06) ? \ sqrt_simplify(x / T(1e+06), T(1e+03) * m_val) : x > T(1e+04) ? \ sqrt_simplify(x / T(1e+04), T(1e+02) * m_val) : x > T(100) ? \ sqrt_simplify(x / T(100), T(10) * m_val) : x > T(4) ? \ sqrt_simplify(x / T(4), T(2) * m_val) : m_val * sqrt_recur(x, x / T(2), 0) ); } template constexpr T sqrt_check(const T x) noexcept { return( is_nan(x) ? \ GCLIM::quiet_NaN() : // x < T(0) ? \ GCLIM::quiet_NaN() : // is_posinf(x) ? \ x : // indistinguishable from zero or one GCLIM::min() > abs(x) ? \ T(0) : GCLIM::min() > abs(T(1) - x) ? \ x : // else sqrt_simplify(x, T(1)) ); } } /** * Compile-time square-root function * * @param x a real-valued input. * @return Computes \f$ \sqrt{x} \f$ using a Newton-Raphson approach. */ template constexpr return_t sqrt(const T x) noexcept { return internal::sqrt_check( static_cast>(x) ); } #endif gcem-1.18.0/include/gcem_incl/tan.hpp000066400000000000000000000073571507212366300173730ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time tangent function */ #ifndef _gcem_tan_HPP #define _gcem_tan_HPP namespace internal { template constexpr T tan_series_exp_long(const T z) noexcept { // this is based on a fourth-order expansion of tan(z) using Bernoulli numbers return( - 1/z + (z/3 + (pow_integral(z,3)/45 + (2*pow_integral(z,5)/945 + pow_integral(z,7)/4725))) ); } template constexpr T tan_series_exp(const T x) noexcept { return( GCLIM::min() > abs(x - T(GCEM_HALF_PI)) ? \ // the value tan(pi/2) is somewhat of a convention; // technically the function is not defined at EXACTLY pi/2, // but this is floating point pi/2 T(1.633124e+16) : // otherwise we use an expansion around pi/2 tan_series_exp_long(x - T(GCEM_HALF_PI)) ); } template constexpr T tan_cf_recur(const T xx, const int depth, const int max_depth) noexcept { return( depth < max_depth ? \ // if T(2*depth - 1) - xx/tan_cf_recur(xx,depth+1,max_depth) : // else T(2*depth - 1) ); } template constexpr T tan_cf_main(const T x) noexcept { return( (x > T(1.55) && x < T(1.60)) ? \ tan_series_exp(x) : // deals with a singularity at tan(pi/2) // x > T(1.4) ? \ x/tan_cf_recur(x*x,1,45) : x > T(1) ? \ x/tan_cf_recur(x*x,1,35) : // else x/tan_cf_recur(x*x,1,25) ); } template constexpr T tan_begin(const T x, const int count = 0) noexcept { // tan(x) = tan(x + pi) return( x > T(GCEM_PI) ? \ // if count > 1 ? GCLIM::quiet_NaN() : // protect against undefined behavior tan_begin( x - T(GCEM_PI) * internal::floor_check(x/T(GCEM_PI)), count+1 ) : // else tan_cf_main(x) ); } template constexpr T tan_check(const T x) noexcept { return( // NaN check is_nan(x) ? \ GCLIM::quiet_NaN() : // indistinguishable from zero GCLIM::min() > abs(x) ? \ T(0) : // else x < T(0) ? \ - tan_begin(-x) : tan_begin( x) ); } } /** * Compile-time tangent function * * @param x a real-valued input. * @return the tangent function using * \f[ \tan(x) = \dfrac{x}{1 - \dfrac{x^2}{3 - \dfrac{x^2}{5 - \ddots}}} \f] * To deal with a singularity at \f$ \pi / 2 \f$, the following expansion is employed: * \f[ \tan(x) = - \frac{1}{x-\pi/2} - \sum_{k=1}^\infty \frac{(-1)^k 2^{2k} B_{2k}}{(2k)!} (x - \pi/2)^{2k - 1} \f] * where \f$ B_n \f$ is the n-th Bernoulli number. */ template constexpr return_t tan(const T x) noexcept { return internal::tan_check( static_cast>(x) ); } #endif gcem-1.18.0/include/gcem_incl/tanh.hpp000066400000000000000000000046731507212366300175410ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * compile-time hyperbolic tangent function */ #ifndef _gcem_tanh_HPP #define _gcem_tanh_HPP namespace internal { #if __cplusplus >= 201402L // C++14 version template constexpr T tanh_cf(const T xx, const int depth_end) noexcept { int depth = GCEM_TANH_MAX_ITER - 1; T res = T(2*(depth+1) - 1); while (depth > depth_end - 1) { res = T(2*depth - 1) + xx / res; --depth; } return res; } #else // C++11 version template constexpr T tanh_cf(const T xx, const int depth) noexcept { return( depth < GCEM_TANH_MAX_ITER ? \ // if (2*depth - 1) + xx/tanh_cf(xx,depth+1) : // else T(2*depth - 1) ); } #endif template constexpr T tanh_begin(const T x) noexcept { return( x/tanh_cf(x*x,1) ); } template constexpr T tanh_check(const T x) noexcept { return( // NaN check is_nan(x) ? \ GCLIM::quiet_NaN() : // indistinguishable from zero GCLIM::min() > abs(x) ? \ T(0) : // else x < T(0) ? \ - tanh_begin(-x) : tanh_begin( x) ); } } /** * Compile-time hyperbolic tangent function * * @param x a real-valued input. * @return the hyperbolic tangent function using \f[ \tanh(x) = \dfrac{x}{1 + \dfrac{x^2}{3 + \dfrac{x^2}{5 + \dfrac{x^2}{7 + \ddots}}}} \f] */ template constexpr return_t tanh(const T x) noexcept { return internal::tanh_check( static_cast>(x) ); } #endif gcem-1.18.0/include/gcem_incl/tgamma.hpp000066400000000000000000000045061507212366300200500ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ /* * the ('true') gamma function */ #ifndef _gcem_tgamma_HPP #define _gcem_tgamma_HPP namespace internal { template constexpr T tgamma_check(const T x) noexcept { return( // NaN check is_nan(x) ? \ GCLIM::quiet_NaN() : // indistinguishable from one or zero GCLIM::min() > abs(x - T(1)) ? \ T(1) : GCLIM::min() > abs(x) ? \ GCLIM::infinity() : // negative numbers x < T(0) ? \ // check for integer GCLIM::min() > abs(x - find_whole(x)) ? \ GCLIM::quiet_NaN() : // else tgamma_check(x+T(1)) / x : // else exp(lgamma(x)) ); } } /** * Compile-time gamma function * * @param x a real-valued input. * @return computes the `true' gamma function * \f[ \Gamma(x) = \int_0^\infty y^{x-1} \exp(-y) dy \f] * using a polynomial form: * \f[ \Gamma(x+1) \approx (x+g+0.5)^{x+0.5} \exp(-x-g-0.5) \sqrt{2 \pi} \left[ c_0 + \frac{c_1}{x+1} + \frac{c_2}{x+2} + \cdots + \frac{c_n}{x+n} \right] \f] * where the value \f$ g \f$ and the coefficients \f$ (c_0, c_1, \ldots, c_n) \f$ * are taken from Paul Godfrey, whose note can be found here: http://my.fit.edu/~gabdo/gamma.txt */ template constexpr return_t tgamma(const T x) noexcept { return internal::tgamma_check( static_cast>(x) ); } #endif gcem-1.18.0/include/gcem_incl/trunc.hpp000066400000000000000000000050461507212366300177350ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #ifndef _gcem_trunc_HPP #define _gcem_trunc_HPP namespace internal { template constexpr T trunc_int(const T x) noexcept { return( T(static_cast(x)) ); } template constexpr T trunc_check_internal(const T x) noexcept { return x; } template<> constexpr float trunc_check_internal(const float x) noexcept { return( abs(x) >= 8388608.f ? \ // if x : \ // else trunc_int(x) ); } template<> constexpr double trunc_check_internal(const double x) noexcept { return( abs(x) >= 4503599627370496. ? \ // if x : \ // else trunc_int(x) ); } template<> constexpr long double trunc_check_internal(const long double x) noexcept { return( abs(x) >= 9223372036854775808.l ? \ // if x : \ // else ((long double)static_cast(abs(x))) * sgn(x) ); } template constexpr T trunc_check(const T x) noexcept { return( // NaN check is_nan(x) ? \ GCLIM::quiet_NaN() : // +/- infinite !is_finite(x) ? \ x : // signed-zero cases GCLIM::min() > abs(x) ? \ x : // else trunc_check_internal(x) ); } } /** * Compile-time trunc function * * @param x a real-valued input. * @return computes the trunc-value of the input, essentially returning the integer part of the input. */ template constexpr return_t trunc(const T x) noexcept { return internal::trunc_check( static_cast>(x) ); } #endif gcem-1.18.0/notebooks/000077500000000000000000000000001507212366300145245ustar00rootroot00000000000000gcem-1.18.0/notebooks/gcem.ipynb000066400000000000000000000206521507212366300165070ustar00rootroot00000000000000{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# [GCE-Math](https://github.com/kthohr/gcem)\n", "\n", "\n", "GCE-Math (Generalized Constant Expression Math) is a templated C++ library enabling compile-time computation of mathematical functions.\n", "\n", "* The library is written in C++11 `constexpr` format, and is C++11/14/17 compatible.\n", "* Continued fraction and series expansions are implemented using recursive templates.\n", "* The `gcem::` syntax is identical to the C++ standard library (`std::`).\n", "* Tested and accurate to floating-point precision against the C++ standard library.\n", "* Released under a permissive, non-GPL license.\n", "\n", "**Author**: Keith O'Hara\n", "\n", "\"License\"\n", "\n", " \n", "\n", "## Coverage and Documentation\n", "\n", "A list of features includes:\n", "\n", "* basic library functions:\n", " - ```abs```, ```exp```, ```log```, ```max```, ```min```, ```pow```, ```sqrt```, ```gcd```, ```lcm```, and more\n", "* trigonometric functions:\n", " - basic: ```cos```, ```sin```, ```tan```\n", " - inverse: ```acos```, ```asin```, ```atan```\n", " - hyperbolic (area) functions: ```cosh```, ```sinh```, ```tanh```, ```acosh```, ```asinh```, ```atanh```\n", "* special functions:\n", " - factorials and the binomial coefficient: ```factorial```, ```binomial_coef```\n", " - beta, gamma, and multivariate gamma functions: ```beta```, ```lbeta```, ```lgamma```, ```tgamma```, ```lmgamma```\n", " - the Gaussian error function and inverse error function: ```erf```, ```erf_inv```\n", " - (regularized) incomplete beta and incomplete gamma functions: ```incomplete_beta```, ```incomplete_gamma```\n", " - inverse incomplete beta and incomplete gamma functions: ```incomplete_beta_inv```, ```incomplete_gamma_inv```\n", "\n", "Full documentation is avaialble online:\n", "\n", "\"Documentation\" \n", "\n", " \n", "\n", "## This Notebook\n", "\n", "To run a code cell, use `shift + enter`.\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "// include libraries\n", "#include // for printing\n", "#include \"../include/gcem.hpp\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Syntax and Examples\n", "\n", "GCE-Math functions are written as C++ templates with `constexpr` specifiers. For example, the [Gaussian error function](https://en.wikipedia.org/wiki/Error_function) (```erf```) is defined as:\n", "```cpp\n", "template\n", "constexpr\n", "return_t\n", "erf(const T x);\n", "```\n", "where a set of internal templated ```constexpr``` functions will implement a continued fraction expansion to return a value of type ```return_t```. This output type ('```return_t```') is generally determined by the input type, e.g., ```int```, ```float```, ```double```, ```long double```, etc. When ```T``` is an intergral type, the output will be upgraded to ```return_t = double```, otherwise ```return_t = T```. For types not covered by ```std::is_integral```, recasts should be used." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "exp(3) = 20.0855\n", "error = 0\n" ] } ], "source": [ "// exponential and natural logarithm functions\n", "\n", "double exp_val_1 = gcem::exp(3);\n", "double log_val_1 = gcem::log(2);\n", "\n", "// compare with the standard library\n", "\n", "double exp_val_2 = std::exp(3);\n", "double log_val_2 = std::log(2);\n", "\n", "std::cout << \"exp(3) = \" << exp_val_1 << std::endl;\n", "std::cout << \"error = \" << gcem::abs(exp_val_1 - exp_val_2) << std::endl;" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "sin(pi) = 0\n", "sin(pi/2) = 1\n", "gcem::tan(pi/2) = 1.63312e+16\n", "std::tan(pi/2) = 1.63312e+16\n", "|gcem::tan(0.9) - std::tan(0.9)| = 1.77636e-15\n" ] } ], "source": [ "// trig functions\n", "\n", "double pi_dbl = double(GCEM_PI);\n", "double hpi_dbl = double(GCEM_HALF_PI);\n", "\n", "double sin_val_1 = gcem::sin(pi_dbl);\n", "double sin_val_2 = gcem::sin(hpi_dbl);\n", "\n", "std::cout << \"sin(pi) = \" << sin_val_1 << std::endl;\n", "std::cout << \"sin(pi/2) = \" << sin_val_2 << std::endl;\n", "\n", "std::cout << \"gcem::tan(pi/2) = \" << gcem::tan(hpi_dbl) << std::endl;\n", "std::cout << \"std::tan(pi/2) = \" << std::tan(hpi_dbl) << std::endl;\n", "\n", "std::cout << \"|gcem::tan(0.9) - std::tan(0.9)| = \" << gcem::abs(gcem::tan(1.5) - std::tan(1.5)) << std::endl;" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "gcem::cosh(0.3) = 1.04534\n", "gcem::acosh(gcem::cosh(0.3)) = 0.3\n" ] } ], "source": [ "// hyperbolic functions\n", "\n", "constexpr double cosh_val = gcem::cosh(0.3);\n", "constexpr double inp_val = gcem::acosh(cosh_val);\n", "\n", "std::cout << \"gcem::cosh(0.3) = \" << cosh_val << std::endl;\n", "std::cout << \"gcem::acosh(gcem::cosh(0.3)) = \" << inp_val << std::endl;" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Special Functions\n", "\n", "Special functions are so-called because of their extensive use in mathematics, physics, and statisitcs. Simple examples include the basic trigonometric functions (tan, sin, cos, etc.) and the natural logarithm.\n", "\n", "Of particular interest in statistics are integral equations, like the Gaussian error function and incomplete gamma and beta functions, necessary to calculate cumulative distribution functions." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "// define some storage\n", "double erf_inp_val, erf_val;\n", "double a_par, b_par;\n", "double ig_inp_val, bt_inp_val;\n", "double ig_val, bt_val;" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "gcem::erf(1.2) = 0.910314\n", "gcem::incomplete_gamma(3,4) = 0.761897\n", "gcem::incomplete_gamma(6,5,0.7) = 0.849732\n" ] } ], "source": [ "// Gaussian error function\n", "erf_inp_val = 1.2;\n", "erf_val = gcem::erf(erf_inp_val);\n", "\n", "std::cout << \"gcem::erf(\" << erf_inp_val << \") = \" << erf_val << std::endl;\n", "\n", "// regularied lower incomplete gamma function\n", "a_par = 3;\n", "ig_inp_val = 4;\n", "\n", "ig_val = gcem::incomplete_gamma(a_par,ig_inp_val);\n", "\n", "std::cout << \"gcem::incomplete_gamma(\" << a_par << \",\" << ig_inp_val << \") = \" << ig_val << std::endl;\n", "\n", "// regularied lower incomplete beta function\n", "a_par = 6;\n", "b_par = 5;\n", "bt_inp_val = 0.7;\n", "\n", "bt_val = gcem::incomplete_beta(a_par,b_par,bt_inp_val);\n", "\n", "std::cout << \"gcem::incomplete_gamma(\" << a_par << \",\" << b_par << \",\" << bt_inp_val << \") = \" << bt_val << std::endl;" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "C++11", "language": "C++11", "name": "xeus-cling-cpp11" }, "language_info": { "codemirror_mode": "text/x-c++src", "file_extension": ".cpp", "mimetype": "text/x-c++src", "name": "c++", "version": "-std=c++11" } }, "nbformat": 4, "nbformat_minor": 2 }gcem-1.18.0/tests/000077500000000000000000000000001507212366300136635ustar00rootroot00000000000000gcem-1.18.0/tests/CMakeLists.txt000066400000000000000000000046271507212366300164340ustar00rootroot00000000000000################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################ cmake_minimum_required(VERSION 3.1) if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) project(gcem-test) find_package(gcem REQUIRED CONFIG) set(GCEM_INCLUDE_DIR ${gcem_INCLUDE_DIRS}) endif () message(STATUS "Forcing tests build type to Release") set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) # if(NOT MSVC) include(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) if(COMPILER_SUPPORTS_CXX11) if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g -O0 -Wall -Wextra --coverage -fno-inline -fno-inline-small-functions -fno-default-inline") else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g -O0 -Wall -Wextra --coverage -fno-inline") endif() else() message(FATAL_ERROR "Unsupported compiler ${CMAKE_CXX_COMPILER} " "GCEM requires a C++11-compatible compiler.") endif() endif() if(MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP /bigobj") set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO) endif() # file(GLOB GCEM_TESTS_SOURCES **.cpp **.c) set( GCEM_TESTS ${GCEM_TESTS_SOURCES}) set(GCEM_TESTS_EX "") foreach( file_ ${GCEM_TESTS} ) get_filename_component(filename ${file_} NAME) string( REPLACE ".cpp" ".test" testname ${filename} ) add_executable( ${testname} EXCLUDE_FROM_ALL ${filename} ) target_link_libraries( ${testname} gcem ) list(APPEND GCEM_TESTS_EX ${testname}) endforeach() add_custom_target(gcem_tests DEPENDS ${GCEM_TESTS_EX}) # gcem-1.18.0/tests/Makefile000066400000000000000000000041771507212366300153340ustar00rootroot00000000000000# GCEM Test build ifeq ($(CXX),) CXX = g++ endif ifeq ($(GCEM_CXX_STD),) CXX_STD = -std=c++11 else CXX_STD=$(GCEM_CXX_STD) endif ifneq (,$(findstring clang,$(CXX))) OPT_FLAGS = -g -O0 -Wall -Wextra --coverage -fno-inline else OPT_FLAGS = -g -O0 -Wall -Wextra --coverage -fno-inline -fno-inline-small-functions -fno-default-inline endif ifneq ($(TRAVIS_CLANG_BUILD),) OPT_FLAGS += -DTRAVIS_CLANG_CXX endif # source directories SDIR = . HEADER_DIR = $(SDIR)/../include SOURCES_TESTS= $(wildcard $(SDIR)/*.cpp) OBJECTS_TESTS= $(SOURCES_TESTS:.cpp=.test) all: $(OBJECTS_TESTS) $(SDIR)/%.test: $(SDIR)/%.cpp $(CXX) $(CXX_STD) $(OPT_FLAGS) -I$(HEADER_DIR) $< -o $@ $(LIBS) # cleanup .PHONY: clean clean: @rm -rf *.test *.gcov *.gcno *.gcda *.dSYM # individual make calls GCEM_MAKE_CALL= $(CXX) $(CXX_STD) $(OPT_FLAGS) -I$(HEADER_DIR) $@.cpp -o $@.test $(LIBS) abs: $(GCEM_MAKE_CALL) acos: $(GCEM_MAKE_CALL) acosh: $(GCEM_MAKE_CALL) asin: $(GCEM_MAKE_CALL) asinh: $(GCEM_MAKE_CALL) atan: $(GCEM_MAKE_CALL) atan2: $(GCEM_MAKE_CALL) atanh: $(GCEM_MAKE_CALL) binomial_coef: $(GCEM_MAKE_CALL) copysign: $(GCEM_MAKE_CALL) cos: $(GCEM_MAKE_CALL) cosh: $(GCEM_MAKE_CALL) erf: $(GCEM_MAKE_CALL) erf_inv: $(GCEM_MAKE_CALL) exp: $(GCEM_MAKE_CALL) expm1: $(GCEM_MAKE_CALL) fabs: $(GCEM_MAKE_CALL) fabsf: $(GCEM_MAKE_CALL) fabsl: $(GCEM_MAKE_CALL) factorial: $(GCEM_MAKE_CALL) fmod: $(GCEM_MAKE_CALL) gcd: $(GCEM_MAKE_CALL) hypot: $(GCEM_MAKE_CALL) incomplete_beta: $(GCEM_MAKE_CALL) incomplete_beta_inv: $(GCEM_MAKE_CALL) incomplete_gamma: $(GCEM_MAKE_CALL) incomplete_gamma_inv: $(GCEM_MAKE_CALL) inv_sqrt: $(GCEM_MAKE_CALL) is_odd: $(GCEM_MAKE_CALL) lcm: $(GCEM_MAKE_CALL) lgamma: $(GCEM_MAKE_CALL) log_binomial_coef: $(GCEM_MAKE_CALL) log: $(GCEM_MAKE_CALL) log1p: $(GCEM_MAKE_CALL) log2: $(GCEM_MAKE_CALL) log10: $(GCEM_MAKE_CALL) other: $(GCEM_MAKE_CALL) pow: $(GCEM_MAKE_CALL) rounding: $(GCEM_MAKE_CALL) signbit: $(GCEM_MAKE_CALL) sin: $(GCEM_MAKE_CALL) sinh: $(GCEM_MAKE_CALL) sqrt: $(GCEM_MAKE_CALL) tan: $(GCEM_MAKE_CALL) tanh: $(GCEM_MAKE_CALL) tgamma: $(GCEM_MAKE_CALL) gcem-1.18.0/tests/abs.cpp000066400000000000000000000033121507212366300151330ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 6 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("abs"); // GCEM_TEST_COMPARE_VALS(gcem::abs,std::abs, 0.0); GCEM_TEST_COMPARE_VALS(gcem::abs,std::abs,-0.0); GCEM_TEST_COMPARE_VALS(gcem::abs,std::abs, 1.0); GCEM_TEST_COMPARE_VALS(gcem::abs,std::abs,-1.0); GCEM_TEST_COMPARE_VALS(gcem::abs,std::abs, 0); GCEM_TEST_COMPARE_VALS(gcem::abs,std::abs, 1); GCEM_TEST_COMPARE_VALS(gcem::abs,std::abs,-1); GCEM_TEST_COMPARE_VALS(gcem::abs,std::abs, INT64_MIN); GCEM_TEST_COMPARE_VALS(gcem::abs,std::abs, INT64_MAX); GCEM_TEST_COMPARE_VALS(gcem::abs,std::abs, TEST_NAN); GCEM_TEST_COMPARE_VALS(gcem::abs,std::abs, TEST_NEGINF); GCEM_TEST_COMPARE_VALS(gcem::abs,std::abs, TEST_POSINF); // print_final("abs"); return 0; } gcem-1.18.0/tests/acos.cpp000066400000000000000000000030001507212366300153050ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 6 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("acos"); // GCEM_TEST_COMPARE_VALS(gcem::acos,std::acos, 0.0L); GCEM_TEST_COMPARE_VALS(gcem::acos,std::acos, 0.001L); GCEM_TEST_COMPARE_VALS(gcem::acos,std::acos, 0.5L); GCEM_TEST_COMPARE_VALS(gcem::acos,std::acos,-0.5L); GCEM_TEST_COMPARE_VALS(gcem::acos,std::acos, 0.7568025L); GCEM_TEST_COMPARE_VALS(gcem::acos,std::acos, 1.0L); GCEM_TEST_COMPARE_VALS(gcem::acos,std::acos, 5.0L); GCEM_TEST_COMPARE_VALS(gcem::acos,std::acos, TEST_NAN); // print_final("acos"); return 0; } gcem-1.18.0/tests/acosh.cpp000066400000000000000000000026241507212366300154700ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 3 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("acosh"); // GCEM_TEST_COMPARE_VALS(gcem::acosh,std::acosh,1.001L); GCEM_TEST_COMPARE_VALS(gcem::acosh,std::acosh,1.5L); GCEM_TEST_COMPARE_VALS(gcem::acosh,std::acosh,11.1L); GCEM_TEST_COMPARE_VALS(gcem::acosh,std::acosh,50.0L); GCEM_TEST_COMPARE_VALS(gcem::acosh,std::acosh,0.5L); GCEM_TEST_COMPARE_VALS(gcem::acosh,std::acosh,TEST_NAN); // print_final("acosh"); return 0; } gcem-1.18.0/tests/asin.cpp000066400000000000000000000027711507212366300153300ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 6 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("asin"); // GCEM_TEST_COMPARE_VALS(gcem::asin,std::asin,0.0L); GCEM_TEST_COMPARE_VALS(gcem::asin,std::asin,0.001L); GCEM_TEST_COMPARE_VALS(gcem::asin,std::asin,0.5L); GCEM_TEST_COMPARE_VALS(gcem::asin,std::asin,-0.5L); GCEM_TEST_COMPARE_VALS(gcem::asin,std::asin,0.7568025L); GCEM_TEST_COMPARE_VALS(gcem::asin,std::asin,1.0L); GCEM_TEST_COMPARE_VALS(gcem::asin,std::asin,5.0L); GCEM_TEST_COMPARE_VALS(gcem::asin,std::asin,TEST_NAN); // print_final("asin"); return 0; } gcem-1.18.0/tests/asinh.cpp000066400000000000000000000030111507212366300154640ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 3 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("asinh"); // GCEM_TEST_COMPARE_VALS(gcem::asinh,std::asinh,0.0L); GCEM_TEST_COMPARE_VALS(gcem::asinh,std::asinh,0.001L); GCEM_TEST_COMPARE_VALS(gcem::asinh,std::asinh,1.001L); GCEM_TEST_COMPARE_VALS(gcem::asinh,std::asinh,1.5L); GCEM_TEST_COMPARE_VALS(gcem::asinh,std::asinh,11.1L); GCEM_TEST_COMPARE_VALS(gcem::asinh,std::asinh,50.0L); GCEM_TEST_COMPARE_VALS(gcem::asinh,std::asinh,-1.5L); GCEM_TEST_COMPARE_VALS(gcem::asinh,std::asinh,TEST_NAN); // print_final("asinh"); return 0; } gcem-1.18.0/tests/atan.cpp000066400000000000000000000045711507212366300153210ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 6 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("atan"); // GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,0.0L); GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,0.001L); GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,0.49L); GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,-0.5L); GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,-1.5L); GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,0.7568025L); GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,0.99L); GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,1.49L); GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,1.99L); GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,2.49L); GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,2.51L); GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,3.99L); GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,7.0L); GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,11.0L); GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,25.0L); GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,101.0L); GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,900.0L); GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,1001.0L); GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,1000000.0L); GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,TEST_NAN); // print_final("atan"); // constexpr long double ct1 = gcem::atan(0.99L); // std::cout << "ct1 = " << ct1 << std::endl; // constexpr long double ct2 = gcem::atan(4.99L); // std::cout << "ct2 = " << ct2 << std::endl; return 0; } gcem-1.18.0/tests/atan2.cpp000066400000000000000000000055121507212366300153770ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 6 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("atan2"); // GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 0.0L, 0.0L); GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, -0.0L, 0.0L); GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 0.0L, -0.0L); GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, -0.0L, -0.0L); GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 0.2L, 0.0L); GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, -0.2L, 0.0L); GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 0.001L, 0.001L); GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 0.49L, 0.49L); GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, -0.5L, -0.5L); GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 0.5L, -0.5L); GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, -0.5L, 0.5L); GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 9.6L, 8.4L); GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 1.0L, 0.0L); GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 0.0L, 1.0L); GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, -1.0L, 0.0L); GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 0.0L, -1.0L); GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 1.0L, 3.0L); GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, -5.0L, 2.5L); GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, -1000.0L, -0.001L); GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 0.1337L, -123456.0L); // GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, TEST_NAN, 1.0L); GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 1.0L, TEST_NAN); GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, TEST_NAN, TEST_NAN); // print_final("atan2"); return 0; } gcem-1.18.0/tests/atanh.cpp000066400000000000000000000027161507212366300154700ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 3 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("atanh"); // GCEM_TEST_COMPARE_VALS(gcem::atanh,std::atanh,-0.99L); GCEM_TEST_COMPARE_VALS(gcem::atanh,std::atanh,0.0L); GCEM_TEST_COMPARE_VALS(gcem::atanh,std::atanh,0.001L); GCEM_TEST_COMPARE_VALS(gcem::atanh,std::atanh,1.0L); GCEM_TEST_COMPARE_VALS(gcem::atanh,std::atanh,-1.0L); GCEM_TEST_COMPARE_VALS(gcem::atanh,std::atanh,1.1L); GCEM_TEST_COMPARE_VALS(gcem::atanh,std::atanh,TEST_NAN); // print_final("atanh"); return 0; } gcem-1.18.0/tests/binomial_coef.cpp000066400000000000000000000033501507212366300171560ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #include "gcem_tests.hpp" int main() { print_begin("binomial_coef"); // GCEM_TEST_EXPECTED_VAL(gcem::binomial_coef, 1, 0, 0); GCEM_TEST_EXPECTED_VAL(gcem::binomial_coef, 0, 0, 1); GCEM_TEST_EXPECTED_VAL(gcem::binomial_coef, 1, 1, 0); GCEM_TEST_EXPECTED_VAL(gcem::binomial_coef, 1, 1, 1); GCEM_TEST_EXPECTED_VAL(gcem::binomial_coef, 10, 5, 2); GCEM_TEST_EXPECTED_VAL(gcem::binomial_coef, 45, 10, 8); GCEM_TEST_EXPECTED_VAL(gcem::binomial_coef, 10, 10, 9); GCEM_TEST_EXPECTED_VAL(gcem::binomial_coef, 1, 10, 10); // // GCEM_TEST_EXPECTED_VAL(gcem::binomial_coef, TEST_NAN, TEST_NAN, 1.0L); // GCEM_TEST_EXPECTED_VAL(gcem::binomial_coef, TEST_NAN, 1.0L, TEST_NAN); // GCEM_TEST_EXPECTED_VAL(gcem::binomial_coef, TEST_NAN, TEST_NAN, TEST_NAN); // print_final("binomial_coef"); return 0; } gcem-1.18.0/tests/copysign.cpp000066400000000000000000000044501507212366300162250ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 2 #define TEST_PRINT_PRECISION_2 2 #include "gcem_tests.hpp" int main() { print_begin("copysign"); // GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, 1.0, 1.0); GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, -1.0, 1.0); GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, 1.0, -1.0); GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, -1.0, -1.0); GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, 1.0, 0.0); GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, -1.0, 0.0); GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, 1.0, -0.0); GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, -1.0, -0.0); GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, 0.0, 0.0); GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, -0.0, 0.0); GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, 0.0, -0.0); GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, -0.0, -0.0); GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, TEST_POSINF, TEST_POSINF); GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, TEST_NEGINF, TEST_POSINF); GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, TEST_POSINF, TEST_NEGINF); GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, TEST_NEGINF, TEST_NEGINF); GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, TEST_NAN, TEST_NAN); // print_final("copysign"); return 0; } gcem-1.18.0/tests/cos.cpp000066400000000000000000000030341507212366300151530ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 3 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("cos"); // GCEM_TEST_COMPARE_VALS(gcem::cos,std::cos,-1.5L); GCEM_TEST_COMPARE_VALS(gcem::cos,std::cos,0.0L); GCEM_TEST_COMPARE_VALS(gcem::cos,std::cos,0.001L); GCEM_TEST_COMPARE_VALS(gcem::cos,std::cos,1.001L); GCEM_TEST_COMPARE_VALS(gcem::cos,std::cos,1.5L); GCEM_TEST_COMPARE_VALS(gcem::cos,std::cos,11.1L); GCEM_TEST_COMPARE_VALS(gcem::cos,std::cos,50.0L); GCEM_TEST_COMPARE_VALS(gcem::cos,std::cos,150.0L); GCEM_TEST_COMPARE_VALS(gcem::cos,std::cos,TEST_NAN); // print_final("cos"); return 0; } gcem-1.18.0/tests/cosh.cpp000066400000000000000000000027711507212366300153320ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 6 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("cosh"); // GCEM_TEST_COMPARE_VALS(gcem::cosh,std::cosh,0.0L); GCEM_TEST_COMPARE_VALS(gcem::cosh,std::cosh,0.001L); GCEM_TEST_COMPARE_VALS(gcem::cosh,std::cosh,0.5L); GCEM_TEST_COMPARE_VALS(gcem::cosh,std::cosh,-0.5L); GCEM_TEST_COMPARE_VALS(gcem::cosh,std::cosh,0.7568025L); GCEM_TEST_COMPARE_VALS(gcem::cosh,std::cosh,1.0L); GCEM_TEST_COMPARE_VALS(gcem::cosh,std::cosh,5.0L); GCEM_TEST_COMPARE_VALS(gcem::cosh,std::cosh,TEST_NAN); // print_final("cosh"); return 0; } gcem-1.18.0/tests/cov_check000077500000000000000000000007221507212366300155360ustar00rootroot00000000000000 echo "SHOULD_RUN_COVERAGE: ${SHOULD_RUN_COVERAGE}" if [[ "${SHOULD_RUN_COVERAGE}" == "y" ]]; then if [ -z ${CCOV+x} ]; then CCOV=gcov fi echo "CCOV set to ${CCOV}" for t in ./*.cpp; do $CCOV "$t" > /dev/null 2>&1 done ./pow.test > /dev/null 2>&1 $CCOV pow.cpp > /dev/null 2>&1 ./exp.test > /dev/null 2>&1 $CCOV exp.cpp > /dev/null 2>&1 ./log.test > /dev/null 2>&1 $CCOV log.cpp > /dev/null 2>&1 fi gcem-1.18.0/tests/erf.cpp000066400000000000000000000044031507212366300151440ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_ERR_TOL 1e-12 #define TEST_PRINT_PRECISION_1 3 #define TEST_PRINT_PRECISION_2 10 #include "gcem_tests.hpp" int main() { print_begin("erf"); // GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, -3.0L); GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, -2.5L); GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, -2.11L); GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, -2.099L); GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, -2.0L); GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, -1.3L); GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, -0.7L); GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, -0.1L); GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, 0.0L); GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, 0.1L); GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, 0.7L); GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, 1.3L); GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, 1.3L); GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, 2.0L); GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, 2.099L); GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, 2.11L); GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, 2.5L); GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, 3.0L); // GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, TEST_NAN); GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, TEST_POSINF); GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, TEST_NEGINF); // print_final("erf"); return 0; } gcem-1.18.0/tests/erf_inv.cpp000066400000000000000000000042631507212366300160240ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_ERR_TOL 1e-12 #define TEST_PRINT_PRECISION_1 6 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("erf_inv"); // GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, -3.0L, -0.999977909503001415L); GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, -2.5L, -0.999593047982555041L); GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, -2.11L, -0.997154845031177802L); GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, -2.05L, -0.996258096044456873L); GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, -1.3L, -0.934007944940652437L); GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, 0.0L, 0.0L); GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, 1.3L, 0.934007944940652437L); GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, 2.05L, 0.996258096044456873L); GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, 2.11L, 0.997154845031177802L); GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, 2.5L, 0.999593047982555041L); GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, 3.0L, 0.999977909503001415L); // GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, TEST_NAN, TEST_NAN); GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, TEST_NAN, -1.1); GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, TEST_NAN, 1.1); GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, TEST_POSINF, 1); GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, TEST_NEGINF, -1); // print_final("erf_inv"); return 0; } gcem-1.18.0/tests/exp.cpp000066400000000000000000000034241507212366300151660ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 5 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("exp"); // GCEM_TEST_COMPARE_VALS(gcem::exp,std::exp, -40.0L); GCEM_TEST_COMPARE_VALS(gcem::exp,std::exp, -4.0L); GCEM_TEST_COMPARE_VALS(gcem::exp,std::exp, 0.0001L); GCEM_TEST_COMPARE_VALS(gcem::exp,std::exp, 1.0L); GCEM_TEST_COMPARE_VALS(gcem::exp,std::exp, 1.75L); GCEM_TEST_COMPARE_VALS(gcem::exp,std::exp, 1.9991L); GCEM_TEST_COMPARE_VALS(gcem::exp,std::exp, 2.1L); GCEM_TEST_COMPARE_VALS(gcem::exp,std::exp, 4.0L); GCEM_TEST_COMPARE_VALS(gcem::exp,std::exp, -std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::exp,std::exp, std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::exp,std::exp, std::numeric_limits::quiet_NaN()); // print_final("exp"); return 0; } gcem-1.18.0/tests/expm1.cpp000066400000000000000000000033761507212366300154320ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 5 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("expm1"); // GCEM_TEST_COMPARE_VALS(gcem::expm1,std::expm1,1.0L); GCEM_TEST_COMPARE_VALS(gcem::expm1,std::expm1,0.0L); GCEM_TEST_COMPARE_VALS(gcem::expm1,std::expm1,1e-04L); GCEM_TEST_COMPARE_VALS(gcem::expm1,std::expm1,-1e-04L); GCEM_TEST_COMPARE_VALS(gcem::expm1,std::expm1,1e-05L); GCEM_TEST_COMPARE_VALS(gcem::expm1,std::expm1,1e-06L); GCEM_TEST_COMPARE_VALS(gcem::expm1,std::expm1,1e-22L); GCEM_TEST_COMPARE_VALS(gcem::expm1,std::expm1, -std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::expm1,std::expm1, std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::expm1,std::expm1, std::numeric_limits::quiet_NaN()); // print_final("expm1"); return 0; } gcem-1.18.0/tests/fabs.cpp000066400000000000000000000055111507212366300153040ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 6 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("fabs"); // GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, 0.0f); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs,-0.0f); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, 1.0f); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs,-1.0f); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, 0.0); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs,-0.0); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, 1.0); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs,-1.0); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, 0); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, 1); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs,-1); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, 0.0L); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs,-0.0L); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, 1.0L); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs,-1.0L); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, std::numeric_limits::lowest()); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, std::numeric_limits::min()); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, std::numeric_limits::max()); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, std::numeric_limits::lowest()); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, std::numeric_limits::min()); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, std::numeric_limits::max()); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, std::numeric_limits::lowest()); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, std::numeric_limits::min()); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, std::numeric_limits::max()); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, TEST_NAN); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, TEST_NEGINF); GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, TEST_POSINF); // print_final("fabs"); return 0; } gcem-1.18.0/tests/fabsf.cpp000066400000000000000000000036411507212366300154540ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 6 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("fabsf"); // note: we use std::fabs instead of std::fabsf due to // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79700 GCEM_TEST_COMPARE_VALS(gcem::fabsf,std::fabs, 0.0f); GCEM_TEST_COMPARE_VALS(gcem::fabsf,std::fabs,-0.0f); GCEM_TEST_COMPARE_VALS(gcem::fabsf,std::fabs, 1.0f); GCEM_TEST_COMPARE_VALS(gcem::fabsf,std::fabs,-1.0f); GCEM_TEST_COMPARE_VALS(gcem::fabsf,std::fabs, std::numeric_limits::lowest()); GCEM_TEST_COMPARE_VALS(gcem::fabsf,std::fabs, std::numeric_limits::min()); GCEM_TEST_COMPARE_VALS(gcem::fabsf,std::fabs, std::numeric_limits::max()); GCEM_TEST_COMPARE_VALS(gcem::fabsf,std::fabs, std::numeric_limits::quiet_NaN()); GCEM_TEST_COMPARE_VALS(gcem::fabsf,std::fabs, std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::fabsf,std::fabs, -std::numeric_limits::infinity()); // print_final("fabsf"); return 0; } gcem-1.18.0/tests/fabsl.cpp000066400000000000000000000053061507212366300154620ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 6 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("fabsl"); // note: we use std::fabs instead of std::fabsl due to // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79700 GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, 0.0); GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs,-0.0); GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, 1.0); GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs,-1.0); GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, 0.0L); GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs,-0.0L); GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, 1.0L); GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs,-1.0L); GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, std::numeric_limits::lowest()); GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, std::numeric_limits::min()); GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, std::numeric_limits::max()); GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, std::numeric_limits::lowest()); GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, std::numeric_limits::min()); GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, std::numeric_limits::max()); GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, std::numeric_limits::quiet_NaN()); GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, -std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, std::numeric_limits::quiet_NaN()); GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, -std::numeric_limits::infinity()); // print_final("fabsl"); return 0; } gcem-1.18.0/tests/factorial.cpp000066400000000000000000000040171507212366300163350ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_ERR_TOL 1e-02 #define TEST_PRINT_PRECISION_1 6 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("factorial"); std::function std_fn = [] (long double x) -> long double { return std::tgamma(x+1); }; // // using long doubles -> tgamma GCEM_TEST_COMPARE_VALS(gcem::factorial,std_fn, 3.1L); GCEM_TEST_COMPARE_VALS(gcem::factorial,std_fn, 7.0L); GCEM_TEST_COMPARE_VALS(gcem::factorial,std_fn, 10.0L); GCEM_TEST_COMPARE_VALS(gcem::factorial,std_fn, 12.0L); GCEM_TEST_COMPARE_VALS(gcem::factorial,std_fn, 14.0L); GCEM_TEST_COMPARE_VALS(gcem::factorial,std_fn, 15.0L); // using long ints GCEM_TEST_COMPARE_VALS(gcem::factorial,std_fn, 5L); GCEM_TEST_COMPARE_VALS(gcem::factorial,std_fn, 9L); GCEM_TEST_COMPARE_VALS(gcem::factorial,std_fn, 11L); #ifndef _WIN32 GCEM_TEST_COMPARE_VALS(gcem::factorial,std_fn, 13L); GCEM_TEST_COMPARE_VALS(gcem::factorial,std_fn, 16L); GCEM_TEST_COMPARE_VALS(gcem::factorial,std_fn, 18L); GCEM_TEST_COMPARE_VALS(gcem::factorial,std_fn, 20L); #endif // print_final("factorial"); return 0; } gcem-1.18.0/tests/fmod.cpp000066400000000000000000000076411507212366300153240ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 2 #define TEST_PRINT_PRECISION_2 2 #include "gcem_tests.hpp" int main() { print_begin("fmod"); // GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, 0.0, 0.0); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, -0.0, 0.0); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, 0.0, -0.0); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, 5.3, 2.0); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, -5.3, 2.0); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, 5.3, -2.0); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, -5.3, -2.0); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, 18.5, 4.2); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, -18.5, 4.2); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, 18.5, -4.2); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, -18.5, -4.2); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, -std::numeric_limits::infinity(), 0.0); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, -std::numeric_limits::infinity(), -1.0); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, -std::numeric_limits::infinity(), 1.0); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, -std::numeric_limits::infinity(), std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, -std::numeric_limits::infinity(), -std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, -std::numeric_limits::infinity(), std::numeric_limits::quiet_NaN()); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, std::numeric_limits::infinity(), 0.0); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, std::numeric_limits::infinity(), -1.0); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, std::numeric_limits::infinity(), 1.0); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, std::numeric_limits::infinity(), std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, std::numeric_limits::infinity(), -std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, std::numeric_limits::infinity(), std::numeric_limits::quiet_NaN()); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, std::numeric_limits::quiet_NaN(), 0.0); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, std::numeric_limits::quiet_NaN(), -1.0); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, std::numeric_limits::quiet_NaN(), 1.0); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, std::numeric_limits::quiet_NaN(), -std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN()); // print_final("fmod"); return 0; } gcem-1.18.0/tests/gcd.cpp000066400000000000000000000022271507212366300151270ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_VAL_TYPES int #include "gcem_tests.hpp" int main() { print_begin("gcd"); // GCEM_TEST_EXPECTED_VAL(gcem::gcd,6,12,18); GCEM_TEST_EXPECTED_VAL(gcem::gcd,2,-4,14); GCEM_TEST_EXPECTED_VAL(gcem::gcd,14,42,56); // print_final("gcd"); return 0; } gcem-1.18.0/tests/gcem_tests.hpp000066400000000000000000000372351507212366300165430ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #include #include #include #include #include #include #include // INT64_MIN and INT64_MAX #include "gcem.hpp" // // tolerance int GCEM_TEST_NUMBER = 0; #ifndef TEST_VAL_TYPES #define TEST_VAL_TYPES long double #define TEST_VAL_TYPES_V 1 #endif #ifndef TEST_ERR_TOL #ifdef _WIN32 #define TEST_ERR_TOL 1e-10 #else #define TEST_ERR_TOL 1e-14 #endif #endif #ifdef TEST_VAL_TYPES_V #define PRINT_ERR(err_val) \ { \ printf(" error value = %LE.", err_val); \ } #else #define PRINT_ERR(err_val) \ { \ printf(" error value = %d.", err_val); \ } #endif #ifdef TEST_VAL_TYPES_V #define VAL_IS_INF(val) std::isinf(static_cast(val)) #define VAL_IS_NAN(val) std::isnan(static_cast(val)) #else #define VAL_IS_INF(val) false #define VAL_IS_NAN(val) false #endif #ifndef TEST_NAN #define TEST_NAN gcem::GCLIM::quiet_NaN() #endif #ifndef TEST_POSINF #define TEST_POSINF gcem::GCLIM::infinity() #endif #ifndef TEST_NEGINF #define TEST_NEGINF -gcem::GCLIM::infinity() #endif // #ifndef TEST_PRINT_LEVEL #define TEST_PRINT_LEVEL 3 #endif #ifndef TEST_PRINT_PRECISION_1 #define TEST_PRINT_PRECISION_1 2 #endif #ifndef TEST_PRINT_PRECISION_2 #define TEST_PRINT_PRECISION_2 5 #endif #ifndef GCEM_UNUSED_PAR #define GCEM_UNUSED_PAR(x) (void)(x) #endif // // printing pass #ifndef TRAVIS_CLANG_CXX #define TEST_PASS_PRINT_FINISH \ if (print_level > 1 && !VAL_IS_NAN(err_val)) { \ std::cout << std::setprecision(3) << std::scientific \ << " - error value = " << err_val << "\n"; \ } \ \ std::cout << std::defaultfloat; \ std::cout << std::endl; \ #else #define TEST_PASS_PRINT_FINISH \ if (print_level > 1 && !VAL_IS_NAN(err_val)) { \ std::cout << " - error value = " << err_val << "\n"; \ } \ \ std::cout << std::endl; \ #endif // template inline void print_test_pass(std::string fn_name, const int print_level, int print_precision_1, int print_precision_2, const T1 f_val, const T2 err_val, const T3 par_1) { std::cout << "[\033[32mOK\033[0m] "; std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(print_precision_1) << fn_name << "(" << par_1 << ") = " << std::setprecision(print_precision_2) << f_val << "\n"; TEST_PASS_PRINT_FINISH } template inline void print_test_pass(std::string fn_name, const int print_level, int print_precision_1, int print_precision_2, const T1 f_val, const T2 err_val, const T3 par_1, const T4 par_2) { std::cout << "[\033[32mOK\033[0m] "; std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(print_precision_1) << fn_name << "(" << par_1 << "," << par_2 << ") = " << std::setprecision(print_precision_2) << f_val << "\n"; TEST_PASS_PRINT_FINISH } template inline void print_test_pass(std::string fn_name, const int print_level, int print_precision_1, int print_precision_2, const T1 f_val, const T2 err_val, const T3 par_1, const T4 par_2, const T5 par_3) { std::cout << "[\033[32mOK\033[0m] "; std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(print_precision_1) << fn_name << "(" << par_1 << "," << par_2 << "," << par_3 << ") = " << std::setprecision(print_precision_2) << f_val << "\n"; TEST_PASS_PRINT_FINISH } // // printing fail template inline void print_test_fail(std::string fn_name, int test_number, const int print_level, int print_precision_1, int print_precision_2, const T1 f_val, const T2 expected_val, const T3 par_1) { GCEM_UNUSED_PAR(print_level); GCEM_UNUSED_PAR(print_precision_1); GCEM_UNUSED_PAR(print_precision_2); std::cerr << "\033[31m Test failed!\033[0m\n"; std::cerr << " - Test number: " << test_number << "\n"; std::cerr << " - Function Call: " << fn_name << "(" << par_1 << ");\n"; std::cerr << " - Expected value: " << expected_val << "\n"; std::cerr << " - Actual value: " << f_val << "\n"; std::cerr << std::endl; throw std::runtime_error("test fail"); } template inline void print_test_fail(std::string fn_name, int test_number, const int print_level, int print_precision_1, int print_precision_2, const T1 f_val, const T2 expected_val, const T3 par_1, const T4 par_2) { GCEM_UNUSED_PAR(print_level); GCEM_UNUSED_PAR(print_precision_1); GCEM_UNUSED_PAR(print_precision_2); std::cerr << "\033[31m Test failed!\033[0m\n"; std::cerr << " - Test number: " << test_number << "\n"; std::cerr << " - Function Call: " << fn_name << "(" << par_1 << "," << par_2 << ");\n"; std::cerr << " - Expected value: " << expected_val << "\n"; std::cerr << " - Actual value: " << f_val << "\n"; std::cerr << std::endl; throw std::runtime_error("test fail"); } template inline void print_test_fail(std::string fn_name, int test_number, const int print_level, int print_precision_1, int print_precision_2, const T1 f_val, const T2 expected_val, const T3 par_1, const T4 par_2, const T5 par_3) { GCEM_UNUSED_PAR(print_level); GCEM_UNUSED_PAR(print_precision_1); GCEM_UNUSED_PAR(print_precision_2); std::cerr << "\033[31m Test failed!\033[0m\n"; std::cerr << " - Test number: " << test_number << "\n"; std::cerr << " - Function Call: " << fn_name << "(" << par_1 << "," << par_2 << "," << par_3 << ");\n"; std::cerr << " - Expected value: " << expected_val << "\n"; std::cerr << " - Actual value: " << f_val << "\n"; std::cerr << std::endl; throw std::runtime_error("test fail"); } // // macros #define GCEM_TEST_EXPECTED_VAL(gcem_fn, expected_val, ...) \ { \ ++GCEM_TEST_NUMBER; \ std::string fn_name = #gcem_fn; \ \ auto f_val = gcem_fn(__VA_ARGS__); \ \ auto err_val = std::abs(f_val - expected_val) / (1 + std::abs(expected_val)); \ \ bool test_success = false; \ \ if (VAL_IS_NAN(expected_val) && VAL_IS_NAN(f_val)) { \ test_success = true; \ } else if(!VAL_IS_NAN(f_val) && VAL_IS_INF(f_val) && f_val == expected_val) { \ test_success = true; \ } else if(err_val < TEST_ERR_TOL) { \ test_success = true; \ } else { \ print_test_fail(fn_name,GCEM_TEST_NUMBER,TEST_PRINT_LEVEL, \ TEST_PRINT_PRECISION_1,TEST_PRINT_PRECISION_2, \ f_val,expected_val,__VA_ARGS__); \ } \ \ if (test_success && TEST_PRINT_LEVEL > 0) \ { \ print_test_pass(fn_name,TEST_PRINT_LEVEL, \ TEST_PRINT_PRECISION_1,TEST_PRINT_PRECISION_2, \ f_val,err_val,__VA_ARGS__); \ } \ } #define GCEM_TEST_COMPARE_VALS(gcem_fn, std_fn, ...) \ { \ ++GCEM_TEST_NUMBER; \ \ std::string fn_name = #gcem_fn; \ \ auto gcem_fn_val = gcem_fn(__VA_ARGS__); \ auto std_fn_val = std_fn(__VA_ARGS__); \ \ auto err_val = std::abs(gcem_fn_val - std_fn_val) / (1 + std::abs(std_fn_val)); \ \ bool test_success = false; \ \ if (VAL_IS_NAN(gcem_fn_val) && VAL_IS_NAN(std_fn_val)) { \ test_success = true; \ } else if(!VAL_IS_NAN(gcem_fn_val) && VAL_IS_INF(gcem_fn_val) && gcem_fn_val == std_fn_val) { \ test_success = true; \ } else if(err_val < TEST_ERR_TOL) { \ test_success = true; \ } else { \ print_test_fail(fn_name,GCEM_TEST_NUMBER,TEST_PRINT_LEVEL, \ TEST_PRINT_PRECISION_1,TEST_PRINT_PRECISION_2, \ gcem_fn_val,std_fn_val,__VA_ARGS__); \ } \ \ if (test_success && TEST_PRINT_LEVEL > 0) \ { \ print_test_pass(fn_name,TEST_PRINT_LEVEL, \ TEST_PRINT_PRECISION_1,TEST_PRINT_PRECISION_2, \ gcem_fn_val,err_val,__VA_ARGS__); \ } \ } // // begin and end print inline void finish_print_line(int k) { for (int i=0; i < 80 - k; ++i) { printf(" "); } printf("#"); } inline void print_begin(std::string fn_name) { // GCEM_UNUSED_PAR(fn_name); if (TEST_PRINT_LEVEL > 0) { std::cout << "\n################################################################################\n"; std::cout << "\n\033[36m~~~~ Begin tests for: " << fn_name << "\033[0m\n"; std::cout << std::endl; } } inline void print_final(std::string fn_name) { std::cout.precision(1); std::cout << "################################################################################\n" << "# TESTS SUMMARY #\n"; // std::cout << "# - Test suite: " << fn_name; finish_print_line(14 + int(fn_name.length()) + 4); std::cout << std::endl; // std::cout << "# - Number of tests: " << GCEM_TEST_NUMBER; finish_print_line(20 + (GCEM_TEST_NUMBER > 9 ? 1 : 0) + 4); std::cout << std::endl; // std::cout << "# - Error tolerance: " << std::scientific << TEST_ERR_TOL; finish_print_line(30); std::cout << std::endl; // std::cout << "# [\033[32mPASS\033[0m] #\n" << "################################################################################\n"; // std::cout << std::endl; } gcem-1.18.0/tests/hypot.cpp000066400000000000000000000064401507212366300155360ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 6 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("hypot"); // GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, 0.0L, 0.0L); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, -0.0L, 0.0L); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, 0.0L, -0.0L); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, -0.0L, -0.0L); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, 0.2L, 0.0L); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, -0.2L, 0.0L); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, 0.001L, 0.001L); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, 0.49L, 0.49L); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, -0.5L, -0.5L); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, 0.5L, -0.5L); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, -0.5L, 0.5L); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, 9.6L, 8.4L); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, 1.0L, 0.0L); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, 0.0L, 1.0L); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, -1.0L, 0.0L); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, 0.0L, -1.0L); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, 1.0L, 3.0L); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, -5.0L, 2.5L); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, -1000.0L, -0.001L); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, 0.1337L, -123456.0L); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, TEST_POSINF, 2.0L); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, 2.0L, TEST_POSINF); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, TEST_POSINF, TEST_POSINF); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, TEST_NEGINF, 2.0L); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, 2.0L, TEST_NEGINF); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, TEST_NEGINF, TEST_NEGINF); // GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, TEST_NAN, 1.0L); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, 1.0L, TEST_NAN); GCEM_TEST_COMPARE_VALS(gcem::hypot,std::hypot, TEST_NAN, TEST_NAN); // print_final("hypot"); return 0; } gcem-1.18.0/tests/incomplete_beta.cpp000066400000000000000000000043321507212366300175230ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 3 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("incomplete_beta"); // GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta, 0.11464699677582491921L, 0.9L, 0.9L, 0.1L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta, 0.78492840804657726395L, 0.9L, 0.9L, 0.8L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta, 0.80000000000000004441L, 1.0L, 1.0L, 0.8L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta, 0.89600000000000001865L, 2.0L, 2.0L, 0.8L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta, 0.81920000000000003926L, 3.0L, 2.0L, 0.8L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta, 0.97279999999999999805L, 2.0L, 3.0L, 0.8L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta, 3.9970000000000084279e-09L, 3.0L, 2.0L, 0.001L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta, 0.35200000000000003508L, 2.0L, 2.0L, 0.4L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta, TEST_NAN, TEST_NAN, TEST_NAN, TEST_NAN); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta, TEST_NAN, TEST_NAN, 2.0L, 0.8L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta, TEST_NAN, 2.0L, TEST_NAN, 0.8L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta, TEST_NAN, 2.0L, 2.0L, TEST_NAN); // print_final("incomplete_beta"); return 0; } gcem-1.18.0/tests/incomplete_beta_inv.cpp000066400000000000000000000042641507212366300204030ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 3 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("incomplete_beta_inv"); // GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta_inv, 0.085977260425697907276L, 0.9L, 0.9L, 0.1L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta_inv, 0.81533908558467627081L, 0.9L, 0.9L, 0.8L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta_inv, 0.80000000000000004441L, 1.0L, 1.0L, 0.8L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta_inv, 0.71285927458325959449L, 2.0L, 2.0L, 0.8L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta_inv, 0.78768287172204876079L, 3.0L, 2.0L, 0.8L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta_inv, 0.58245357452433332845L, 2.0L, 3.0L, 0.8L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta_inv, 0.064038139102833388505L, 3.0L, 2.0L, 0.001L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta_inv, 0.43293107714773171324L, 2.0L, 2.0L, 0.4L); // GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta_inv, TEST_NAN, TEST_NAN, 3.0L, 0.8L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta_inv, TEST_NAN, 3.0L, TEST_NAN, 0.8L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta_inv, TEST_NAN, 3.0L, 3.0L, TEST_NAN); // print_final("incomplete_beta_inv"); return 0; } gcem-1.18.0/tests/incomplete_gamma.cpp000066400000000000000000000120411507212366300176660ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_ERR_TOL 1e-12 #define TEST_PRINT_PRECISION_1 3 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("incomplete_gamma"); // GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.26424111765711527644L, 2.0L, 1.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.42759329552912134220L, 1.5L, 1.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.80085172652854419439L, 2.0L, 3.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.95957231800548714595L, 2.0L, 5.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.99876590195913317327L, 2.0L, 9.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 1.0L, 0.0L, 9.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.0L, 2.0L, 0.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.0L, 0.0L, 0.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.47974821959920432857L, 11.5L, 11.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.75410627202774938027L, 15.5L, 18.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.43775501395596266851L, 19.0L, 18.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.43939261060849132967L, 20.0L, 19.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.58504236243630125536L, 38.0L, 39.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.46422093592347296598L, 56.0L, 55.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.55342727426212001696L, 98.0L, 99.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.47356929040257916830L, 102.0L, 101.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.48457398488934400049L, 298.0L, 297.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.48467673854389853316L, 302.0L, 301.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.48807306199561317772L, 498.0L, 497.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.48812074555706047585L, 502.0L, 501.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.51881664512582725823L, 798.0L, 799.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.49059834200005758564L, 801.0L, 800.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.52943655952003709775L, 997.0L, 999.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.45389544705967349580L, 1005.0L, 1001.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.99947774194996708008L, 3.0L, 12.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.99914335878922466705L, 5.0L, 15.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.99998305525606989708L, 5.0L, 20.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.99999973309165746116L, 5.0L, 25.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.99999999995566213329L, 5.0L, 35.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 1.0L , 5.0L, 50.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 1.0L , 5.0L, 500.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.99791274095086501816L, 9.0L, 20.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.99999999914307291515L, 9.0L, 40.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.88153558847098478779L, 11.0L, 15.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.98918828117334733907L, 11.0L, 20.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.99941353837024693441L, 11.0L, 25.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.99999933855955824846L, 11.0L, 35.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.99999999999354982627L, 11.0L, 50.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 1.0L , 11.0L, 500.0L); // GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, TEST_NAN, -0.1, 0.0); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, TEST_NAN, TEST_NAN, TEST_NAN); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, TEST_NAN, TEST_NAN, 3.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, TEST_NAN, 2.0L, TEST_NAN); // print_final("incomplete_gamma"); return 0; } gcem-1.18.0/tests/incomplete_gamma_inv.cpp000066400000000000000000000075011507212366300205470ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #ifndef _WIN32 #define TEST_ERR_TOL 1e-12 #endif #define TEST_PRINT_PRECISION_1 3 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("incomplete_gamma_inv"); // GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 1.0L, 2.0L, 0.26424111765711527644L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 1.0L, 1.5L, 0.42759329552912134220L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 3.0L, 2.0L, 0.80085172652854419439L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 5.0L, 2.0L, 0.95957231800548714595L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 9.0L, 2.0L, 0.99876590195913317327L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, TEST_POSINF, 0.0L, 1.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 0.0L, 2.0L, 0.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 0.0L, 0.0L, 0.0L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 11.0L, 11.5L, 0.47974821959920432857L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 18.0L, 15.5L, 0.75410627202774938027L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 18.0L, 19.0L, 0.43775501395596266851L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 19.0L, 20.0L, 0.43939261060849132967L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 39.0L, 38.0L, 0.58504236243630125536L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 55.0L, 56.0L, 0.46422093592347296598L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 99.0L, 98.0L, 0.55342727426212001696L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 101.0L, 102.0L, 0.47356929040257916830L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 297.0L, 298.0L, 0.48457398488934400049L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 301.0L, 302.0L, 0.48467673854389853316L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 497.0L, 498.0L, 0.48807306199561317772L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 501.0L, 502.0L, 0.48812074555706047585L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 799.0L, 798.0L, 0.51881664512582725823L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 800.0L, 801.0L, 0.49059834200005758564L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 999.0L, 997.0L, 0.52943655952003709775L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 1001.0L, 1005.0L, 0.45389544705967349580L); // GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, TEST_NAN, TEST_NAN, TEST_NAN); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, TEST_NAN, TEST_NAN, 0.5L); GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, TEST_NAN, 2.0L, TEST_NAN); // print_final("incomplete_gamma_inv"); return 0; } gcem-1.18.0/tests/inv_sqrt.cpp000066400000000000000000000036421507212366300162410ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 6 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" template constexpr T std_test_fn(const T x) { return T(1) / std::sqrt(x); } int main() { print_begin("sqrt"); // GCEM_TEST_COMPARE_VALS(gcem::inv_sqrt, std_test_fn, 0.5L); GCEM_TEST_COMPARE_VALS(gcem::inv_sqrt, std_test_fn, 0.00199900000000000208L); GCEM_TEST_COMPARE_VALS(gcem::inv_sqrt, std_test_fn, 1.5L); GCEM_TEST_COMPARE_VALS(gcem::inv_sqrt, std_test_fn, 2.0L); GCEM_TEST_COMPARE_VALS(gcem::inv_sqrt, std_test_fn, 41.5L); GCEM_TEST_COMPARE_VALS(gcem::inv_sqrt, std_test_fn, 0.0L); GCEM_TEST_COMPARE_VALS(gcem::inv_sqrt, std_test_fn, -1.0L); GCEM_TEST_COMPARE_VALS(gcem::inv_sqrt, std_test_fn, -std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::inv_sqrt, std_test_fn, std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::inv_sqrt, std_test_fn, std::numeric_limits::quiet_NaN()); // print_final("sqrt"); return 0; } gcem-1.18.0/tests/is_odd.cpp000066400000000000000000000027551507212366300156410ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #include "gcem_tests.hpp" int main() { std::cout << "\n*** begin is_odd test ***\n" << std::endl; // int run_val = 0; run_val += gcem::internal::is_odd(1); run_val += gcem::internal::is_odd(3); run_val += gcem::internal::is_odd(-5); run_val += gcem::internal::is_even(10UL); run_val += gcem::internal::is_odd(-400009L); run_val += gcem::internal::is_even(100000000L); if (run_val == 6) std::cout << "\033[32m All OK.\033[0m" << std::endl; else throw std::runtime_error("test fail"); // std::cout << "\n*** end is_odd test ***\n" << std::endl; return 0; } gcem-1.18.0/tests/lcm.cpp000066400000000000000000000022311507212366300151400ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_VAL_TYPES int #include "gcem_tests.hpp" int main() { print_begin("lcm"); // GCEM_TEST_EXPECTED_VAL(gcem::lcm,12,3,4); GCEM_TEST_EXPECTED_VAL(gcem::lcm,60,12,15); GCEM_TEST_EXPECTED_VAL(gcem::lcm,1377,17,81); // print_final("lcm"); return 0; } gcem-1.18.0/tests/lgamma.cpp000066400000000000000000000026511507212366300156310ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 2 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("lgamma"); // GCEM_TEST_COMPARE_VALS(gcem::lgamma,std::lgamma, 1.5L); GCEM_TEST_COMPARE_VALS(gcem::lgamma,std::lgamma, 0.7L); GCEM_TEST_COMPARE_VALS(gcem::lgamma,std::lgamma, 1.0L); GCEM_TEST_COMPARE_VALS(gcem::lgamma,std::lgamma, 0.0L); GCEM_TEST_COMPARE_VALS(gcem::lgamma,std::lgamma, -1.0L); GCEM_TEST_COMPARE_VALS(gcem::lgamma,std::lgamma, TEST_NAN); // print_final("lgamma"); return 0; } gcem-1.18.0/tests/log.cpp000066400000000000000000000042351507212366300151540ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ // g++-mp-7 -O3 -Wall -std=c++11 -fconstexpr-depth=20 -fconstexpr-steps=1271242 -I./../include log.cpp -o log.test -framework Accelerate #define TEST_PRINT_PRECISION_1 6 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("log"); // GCEM_TEST_COMPARE_VALS(gcem::log,std::log, 0.5L); GCEM_TEST_COMPARE_VALS(gcem::log,std::log, 0.00199900000000000208L); GCEM_TEST_COMPARE_VALS(gcem::log,std::log, 1.0L); GCEM_TEST_COMPARE_VALS(gcem::log,std::log, 1.5L); GCEM_TEST_COMPARE_VALS(gcem::log,std::log, 41.5L); GCEM_TEST_COMPARE_VALS(gcem::log,std::log, 123456789.5L); GCEM_TEST_COMPARE_VALS(gcem::log,std::log, 0.0L); GCEM_TEST_COMPARE_VALS(gcem::log,std::log, -1.0L); GCEM_TEST_COMPARE_VALS(gcem::log,std::log, 1e-500L); GCEM_TEST_COMPARE_VALS(gcem::log,std::log, std::numeric_limits::min()); GCEM_TEST_COMPARE_VALS(gcem::log,std::log, std::numeric_limits::max()); GCEM_TEST_COMPARE_VALS(gcem::log,std::log, -std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::log,std::log, std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::log,std::log, std::numeric_limits::quiet_NaN()); // print_final("log"); return 0; } gcem-1.18.0/tests/log10.cpp000066400000000000000000000036011507212366300153110ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 6 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("log10"); // GCEM_TEST_COMPARE_VALS(gcem::log10, std::log10, 0.5L); GCEM_TEST_COMPARE_VALS(gcem::log10, std::log10, 0.00199900000000000208L); GCEM_TEST_COMPARE_VALS(gcem::log10, std::log10, 1.5L); GCEM_TEST_COMPARE_VALS(gcem::log10, std::log10, 41.5L); GCEM_TEST_COMPARE_VALS(gcem::log10, std::log10, 0.0L); GCEM_TEST_COMPARE_VALS(gcem::log10, std::log10, -1.0L); GCEM_TEST_COMPARE_VALS(gcem::log10, std::log10, 1e-500L); GCEM_TEST_COMPARE_VALS(gcem::log10, std::log10, std::numeric_limits::min()); GCEM_TEST_COMPARE_VALS(gcem::log10, std::log10, -std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::log10, std::log10, std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::log10, std::log10, std::numeric_limits::quiet_NaN()); // print_final("log10"); return 0; } gcem-1.18.0/tests/log1p.cpp000066400000000000000000000033761507212366300154220ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 5 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("log1p"); // GCEM_TEST_COMPARE_VALS(gcem::log1p,std::log1p,1.0L); GCEM_TEST_COMPARE_VALS(gcem::log1p,std::log1p,0.0L); GCEM_TEST_COMPARE_VALS(gcem::log1p,std::log1p,1e-04L); GCEM_TEST_COMPARE_VALS(gcem::log1p,std::log1p,-1e-04L); GCEM_TEST_COMPARE_VALS(gcem::log1p,std::log1p,1e-05L); GCEM_TEST_COMPARE_VALS(gcem::log1p,std::log1p,1e-06L); GCEM_TEST_COMPARE_VALS(gcem::log1p,std::log1p,1e-22L); GCEM_TEST_COMPARE_VALS(gcem::log1p,std::log1p, -std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::log1p,std::log1p, std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::log1p,std::log1p, std::numeric_limits::quiet_NaN()); // print_final("log1p"); return 0; } gcem-1.18.0/tests/log2.cpp000066400000000000000000000035471507212366300152430ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 6 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("log2"); // GCEM_TEST_COMPARE_VALS(gcem::log2, std::log2, 0.5L); GCEM_TEST_COMPARE_VALS(gcem::log2, std::log2, 0.00199900000000000208L); GCEM_TEST_COMPARE_VALS(gcem::log2, std::log2, 1.5L); GCEM_TEST_COMPARE_VALS(gcem::log2, std::log2, 41.5L); GCEM_TEST_COMPARE_VALS(gcem::log2, std::log2, 0.0L); GCEM_TEST_COMPARE_VALS(gcem::log2, std::log2, -1.0L); GCEM_TEST_COMPARE_VALS(gcem::log2,std::log2, 1e-500L); GCEM_TEST_COMPARE_VALS(gcem::log2,std::log2, std::numeric_limits::min()); GCEM_TEST_COMPARE_VALS(gcem::log2, std::log2, -std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::log2, std::log2, std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::log2, std::log2, std::numeric_limits::quiet_NaN()); // print_final("log2"); return 0; } gcem-1.18.0/tests/log_binomial_coef.cpp000066400000000000000000000031711507212366300200200ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #include "gcem_tests.hpp" int main() { print_begin("log_binomial_coef"); // GCEM_TEST_EXPECTED_VAL(gcem::log_binomial_coef, 0, 0, 0); GCEM_TEST_EXPECTED_VAL(gcem::log_binomial_coef, TEST_NEGINF, 0, 1); GCEM_TEST_EXPECTED_VAL(gcem::log_binomial_coef, 0, 1, 0); GCEM_TEST_EXPECTED_VAL(gcem::log_binomial_coef, 0, 1, 1); GCEM_TEST_EXPECTED_VAL(gcem::log_binomial_coef, std::log(10.0L), 5, 2); GCEM_TEST_EXPECTED_VAL(gcem::log_binomial_coef, std::log(45.0L), 10, 8); GCEM_TEST_EXPECTED_VAL(gcem::log_binomial_coef, std::log(10.0L), 10, 9); GCEM_TEST_EXPECTED_VAL(gcem::log_binomial_coef, 0, 10, 10); // print_final("log_binomial_coef"); return 0; } gcem-1.18.0/tests/other.cpp000066400000000000000000000026761507212366300155230ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #include "gcem_tests.hpp" // test misc functions int main() { GCEM_TEST_EXPECTED_VAL(gcem::sgn, 1, 1.5); GCEM_TEST_EXPECTED_VAL(gcem::sgn, -1, -1.5); GCEM_TEST_EXPECTED_VAL(gcem::internal::find_fraction, -0.5, 1.5); GCEM_TEST_EXPECTED_VAL(gcem::internal::find_fraction, 1.5, -1.5); GCEM_TEST_EXPECTED_VAL(gcem::internal::find_whole, 1, 1.5); GCEM_TEST_EXPECTED_VAL(gcem::internal::find_whole, -3, -1.5); GCEM_TEST_EXPECTED_VAL(gcem::internal::neg_zero, 0, 0.0); GCEM_TEST_EXPECTED_VAL(gcem::internal::neg_zero, 1, -0.0); return 0; } gcem-1.18.0/tests/pow.cpp000066400000000000000000000037571507212366300152100ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 5 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("pow"); // GCEM_TEST_COMPARE_VALS(gcem::pow,std::pow, 0.199900000000000208L, 3.5L); GCEM_TEST_COMPARE_VALS(gcem::pow,std::pow, 0.5L, 2.0L); GCEM_TEST_COMPARE_VALS(gcem::pow,std::pow, 1.5L, 0.99L); GCEM_TEST_COMPARE_VALS(gcem::pow,std::pow, 2.0L, 1.0L); GCEM_TEST_COMPARE_VALS(gcem::pow,std::pow, 41.5L, 7.0L); // int versions GCEM_TEST_COMPARE_VALS(gcem::pow,std::pow, 0.5L, 2L); GCEM_TEST_COMPARE_VALS(gcem::pow,std::pow, 41.5L, 7L); GCEM_TEST_COMPARE_VALS(gcem::pow,std::pow, std::numeric_limits::quiet_NaN(), 2); GCEM_TEST_COMPARE_VALS(gcem::pow,std::pow, 2, std::numeric_limits::quiet_NaN()); GCEM_TEST_COMPARE_VALS(gcem::pow,std::pow, std::numeric_limits::infinity(), 2); GCEM_TEST_COMPARE_VALS(gcem::pow,std::pow, std::numeric_limits::infinity(), - 2); GCEM_TEST_COMPARE_VALS(gcem::pow,std::pow, std::numeric_limits::infinity(), 0); // print_final("pow"); return 0; } gcem-1.18.0/tests/rounding.cpp000066400000000000000000000122011507212366300162100ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 2 #define TEST_PRINT_PRECISION_2 2 #include "gcem_tests.hpp" int main() { print_begin("rounding"); // GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, 0.0); GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, -0.0); GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, 4.2); GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, 4.5); GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, 4.7); GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, 5.0); GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, -4.2); GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, -4.7); GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, -5.0); GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, 42e32); GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, -42e32); GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, std::numeric_limits::max()); GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, -std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, std::numeric_limits::quiet_NaN()); // GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, 0.0); GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, -0.0); GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, 4.2); GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, 4.5); GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, 4.7); GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, 5.0); GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, -4.2); GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, -4.7); GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, -5.0); GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, 42e32); GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, -42e32); GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, std::numeric_limits::max()); GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, -std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, std::numeric_limits::quiet_NaN()); // GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, 0.0); GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, -0.0); GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, 4.2); GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, 4.5); GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, 4.7); GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, 5.0); GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, -4.2); GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, -4.7); GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, -5.0); GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, 42e32); GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, -42e32); GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, std::numeric_limits::max()); GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, -std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, std::numeric_limits::quiet_NaN()); // GCEM_TEST_COMPARE_VALS(gcem::round,std::round, 0.0); GCEM_TEST_COMPARE_VALS(gcem::round,std::round, -0.0); GCEM_TEST_COMPARE_VALS(gcem::round,std::round, 4.2); GCEM_TEST_COMPARE_VALS(gcem::round,std::round, 4.5); GCEM_TEST_COMPARE_VALS(gcem::round,std::round, 4.7); GCEM_TEST_COMPARE_VALS(gcem::round,std::round, 5.0); GCEM_TEST_COMPARE_VALS(gcem::round,std::round, -4.2); GCEM_TEST_COMPARE_VALS(gcem::round,std::round, -4.5); GCEM_TEST_COMPARE_VALS(gcem::round,std::round, -4.7); GCEM_TEST_COMPARE_VALS(gcem::round,std::round, -5.0); GCEM_TEST_COMPARE_VALS(gcem::round,std::round, 42e32); GCEM_TEST_COMPARE_VALS(gcem::round,std::round, -42e32); GCEM_TEST_COMPARE_VALS(gcem::round,std::round, std::numeric_limits::max()); GCEM_TEST_COMPARE_VALS(gcem::round,std::round, -std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::round,std::round, std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::round,std::round, std::numeric_limits::quiet_NaN()); // print_final("rounding"); return 0; } gcem-1.18.0/tests/run_tests000077500000000000000000000000441507212366300156350ustar00rootroot00000000000000 for t in ./*.test; do "$t" done gcem-1.18.0/tests/signbit.cpp000066400000000000000000000031501507212366300160250ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 2 #define TEST_PRINT_PRECISION_2 2 #include "gcem_tests.hpp" template constexpr int std_test_fn(const T x) { return static_cast(std::signbit(x)); } int main() { print_begin("signbit"); // GCEM_TEST_COMPARE_VALS(gcem::signbit,std_test_fn, 1.0); GCEM_TEST_COMPARE_VALS(gcem::signbit,std_test_fn, -1.0); GCEM_TEST_COMPARE_VALS(gcem::signbit,std_test_fn, 0.0); GCEM_TEST_COMPARE_VALS(gcem::signbit,std_test_fn, -0.0); GCEM_TEST_COMPARE_VALS(gcem::signbit,std_test_fn, TEST_POSINF); GCEM_TEST_COMPARE_VALS(gcem::signbit,std_test_fn, TEST_NEGINF); GCEM_TEST_COMPARE_VALS(gcem::signbit,std_test_fn, TEST_NAN); // print_final("signbit"); return 0; } gcem-1.18.0/tests/sin.cpp000066400000000000000000000030341507212366300151600ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 3 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("sin"); // GCEM_TEST_COMPARE_VALS(gcem::sin,std::sin,-1.5L); GCEM_TEST_COMPARE_VALS(gcem::sin,std::sin,0.0L); GCEM_TEST_COMPARE_VALS(gcem::sin,std::sin,0.001L); GCEM_TEST_COMPARE_VALS(gcem::sin,std::sin,1.001L); GCEM_TEST_COMPARE_VALS(gcem::sin,std::sin,1.5L); GCEM_TEST_COMPARE_VALS(gcem::sin,std::sin,11.1L); GCEM_TEST_COMPARE_VALS(gcem::sin,std::sin,50.0L); GCEM_TEST_COMPARE_VALS(gcem::sin,std::sin,150.0L); GCEM_TEST_COMPARE_VALS(gcem::sin,std::sin,TEST_NAN); // print_final("sin"); return 0; } gcem-1.18.0/tests/sinh.cpp000066400000000000000000000027711507212366300153370ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 6 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("sinh"); // GCEM_TEST_COMPARE_VALS(gcem::sinh,std::sinh,0.0L); GCEM_TEST_COMPARE_VALS(gcem::sinh,std::sinh,0.001L); GCEM_TEST_COMPARE_VALS(gcem::sinh,std::sinh,0.5L); GCEM_TEST_COMPARE_VALS(gcem::sinh,std::sinh,-0.5L); GCEM_TEST_COMPARE_VALS(gcem::sinh,std::sinh,0.7568025L); GCEM_TEST_COMPARE_VALS(gcem::sinh,std::sinh,1.0L); GCEM_TEST_COMPARE_VALS(gcem::sinh,std::sinh,5.0L); GCEM_TEST_COMPARE_VALS(gcem::sinh,std::sinh,TEST_NAN); // print_final("sinh"); return 0; } gcem-1.18.0/tests/sqrt.cpp000066400000000000000000000044051507212366300153630ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ // $CXX -O3 -Wall -std=c++11 -fconstexpr-depth=650 -fconstexpr-steps=1271242 -I./../include sqrt.cpp -o sqrt.test -framework Accelerate #define TEST_PRINT_PRECISION_1 6 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("sqrt"); // GCEM_TEST_COMPARE_VALS(gcem::sqrt,std::sqrt, 0.5L); GCEM_TEST_COMPARE_VALS(gcem::sqrt,std::sqrt, 0.00199900000000000208L); GCEM_TEST_COMPARE_VALS(gcem::sqrt,std::sqrt, 1.5L); GCEM_TEST_COMPARE_VALS(gcem::sqrt,std::sqrt, 2.0L); GCEM_TEST_COMPARE_VALS(gcem::sqrt,std::sqrt, 41.5L); GCEM_TEST_COMPARE_VALS(gcem::sqrt,std::sqrt, 123456789.5L); GCEM_TEST_COMPARE_VALS(gcem::sqrt,std::sqrt, 0.0L); GCEM_TEST_COMPARE_VALS(gcem::sqrt,std::sqrt, -1.0L); GCEM_TEST_COMPARE_VALS(gcem::sqrt,std::sqrt, 1e-500L); GCEM_TEST_COMPARE_VALS(gcem::sqrt,std::sqrt, std::numeric_limits::min()); GCEM_TEST_COMPARE_VALS(gcem::sqrt,std::sqrt, std::numeric_limits::max()); GCEM_TEST_COMPARE_VALS(gcem::sqrt,std::sqrt, -std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::sqrt,std::sqrt, std::numeric_limits::infinity()); GCEM_TEST_COMPARE_VALS(gcem::sqrt,std::sqrt, std::numeric_limits::quiet_NaN()); // constexpr auto v = gcem::sqrt(std::numeric_limits::max()); // print_final("sqrt"); return 0; } gcem-1.18.0/tests/tan.cpp000066400000000000000000000031761507212366300151600ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 3 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("tan"); // // static constexpr long double lrgval = std::numeric_limits::max()*100.0L; GCEM_TEST_COMPARE_VALS(gcem::tan,std::tan, 0.0L); GCEM_TEST_COMPARE_VALS(gcem::tan,std::tan, 0.001L); GCEM_TEST_COMPARE_VALS(gcem::tan,std::tan, 1.001L); GCEM_TEST_COMPARE_VALS(gcem::tan,std::tan, 1.5L); GCEM_TEST_COMPARE_VALS(gcem::tan,std::tan, 11.1L); GCEM_TEST_COMPARE_VALS(gcem::tan,std::tan, 50.0L); GCEM_TEST_COMPARE_VALS(gcem::tan,std::tan, -1.5L); // GCEM_TEST_COMPARE_VALS(gcem::tan,std::tan, lrgval); GCEM_TEST_COMPARE_VALS(gcem::tan,std::tan, TEST_NAN); // print_final("tan"); return 0; } gcem-1.18.0/tests/tanh.cpp000066400000000000000000000030071507212366300153210ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 6 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("tanh"); // GCEM_TEST_COMPARE_VALS(gcem::tanh,std::tanh, 0.0L); GCEM_TEST_COMPARE_VALS(gcem::tanh,std::tanh, 0.001L); GCEM_TEST_COMPARE_VALS(gcem::tanh,std::tanh, 0.5L); GCEM_TEST_COMPARE_VALS(gcem::tanh,std::tanh, -0.5L); GCEM_TEST_COMPARE_VALS(gcem::tanh,std::tanh, 0.7568025L); GCEM_TEST_COMPARE_VALS(gcem::tanh,std::tanh, 1.0L); GCEM_TEST_COMPARE_VALS(gcem::tanh,std::tanh, 5.0L); GCEM_TEST_COMPARE_VALS(gcem::tanh,std::tanh, TEST_NAN); // print_final("tanh"); return 0; } gcem-1.18.0/tests/tgamma.cpp000066400000000000000000000040641507212366300156410ustar00rootroot00000000000000/*################################################################################ ## ## Copyright (C) 2016-2024 Keith O'Hara ## ## This file is part of the GCE-Math C++ library. ## ## 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. ## ################################################################################*/ #define TEST_PRINT_PRECISION_1 3 #define TEST_PRINT_PRECISION_2 18 #include "gcem_tests.hpp" int main() { print_begin("tgamma"); // GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, 1.5L); GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, 2.7L); GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, 3.0L); GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, 4.0L); GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, 5.0L); GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, TEST_NAN); GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, 1.0); GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, 0.9); GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, 0.1); GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, 0.001); GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, 0.0); GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, -0.1); GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, -1); GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, -1.1); GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, -2); GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, -3); GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, -4); // print_final("tgamma"); return 0; }