Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: kthohr/gcem
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.13.1
Choose a base ref
...
head repository: kthohr/gcem
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Sep 20, 2020

  1. simplify cmake build files

    kthohr committed Sep 20, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    6137be1 View commit details
  2. update appveyor

    kthohr committed Sep 20, 2020
    Copy the full SHA
    894bd4d View commit details
  3. update appveyor

    kthohr committed Sep 20, 2020
    Copy the full SHA
    25d92da View commit details
  4. appveyor fix

    kthohr committed Sep 20, 2020
    Copy the full SHA
    307026a View commit details
  5. fix file extension

    kthohr committed Sep 20, 2020
    Copy the full SHA
    3ad1616 View commit details

Commits on May 26, 2021

  1. Fix #25.

    MarekKnapek committed May 26, 2021
    Copy the full SHA
    05dbcf0 View commit details

Commits on Jul 2, 2021

  1. update cmake test file

    kthohr committed Jul 2, 2021
    Copy the full SHA
    8d0e62d View commit details

Commits on Jan 1, 2022

  1. compatibility with math.h

    kthohr committed Jan 1, 2022
    Copy the full SHA
    16d5a95 View commit details
  2. copyright year bump

    kthohr committed Jan 1, 2022
    Copy the full SHA
    21b1123 View commit details
  3. add log10 function

    kthohr committed Jan 1, 2022
    Copy the full SHA
    b3893d9 View commit details
  4. version 0.14.0

    kthohr committed Jan 1, 2022
    Copy the full SHA
    e1443c5 View commit details
  5. fix docs typo

    kthohr committed Jan 1, 2022
    Copy the full SHA
    1f028f6 View commit details
  6. Create main.yml

    kthohr authored Jan 1, 2022
    Copy the full SHA
    f3fd390 View commit details
  7. modify workflow name

    kthohr committed Jan 1, 2022
    Copy the full SHA
    4f2195e View commit details
  8. add more build types

    kthohr committed Jan 1, 2022
    Copy the full SHA
    dc352d1 View commit details
  9. update README

    kthohr committed Jan 1, 2022
    Copy the full SHA
    9dd3a7d View commit details
  10. add ubuntu clang build

    kthohr committed Jan 1, 2022
    Copy the full SHA
    ed8cbb1 View commit details
  11. add coverage build

    kthohr committed Jan 1, 2022
    Copy the full SHA
    5fe7978 View commit details
  12. improve coverage stats

    kthohr committed Jan 1, 2022
    Copy the full SHA
    88a062a View commit details
  13. coverage build

    kthohr committed Jan 1, 2022
    Copy the full SHA
    e7210af View commit details
  14. coverage build

    kthohr committed Jan 1, 2022
    Copy the full SHA
    df99d21 View commit details
  15. update tests

    kthohr committed Jan 1, 2022
    Copy the full SHA
    61f77cb View commit details

Commits on Jan 9, 2022

  1. Copy the full SHA
    c6a4561 View commit details

Commits on Jan 21, 2022

  1. replace epsilon() with min()

    kthohr committed Jan 21, 2022
    Copy the full SHA
    1a5106f View commit details
  2. update tests

    kthohr committed Jan 21, 2022
    Copy the full SHA
    6251231 View commit details

Commits on Jan 22, 2022

  1. Copy the full SHA
    4fb808a View commit details

Commits on May 2, 2022

  1. Copy the full SHA
    215c927 View commit details

Commits on Jul 5, 2022

  1. Copy the full SHA
    89484ed View commit details
  2. Copy the full SHA
    2fe9ef8 View commit details
  3. Fixed problem on the long double overload of floor

    by using abs before doing the conversion to unsigned long long
    Unicode-Hater committed Jul 5, 2022
    Copy the full SHA
    761c986 View commit details

Commits on Jul 6, 2022

  1. Added tests for the double overload of

    trunc_check_internal in order to improve coverage
    Unicode-Hater committed Jul 6, 2022
    Copy the full SHA
    9c1bc2b View commit details

Commits on Jul 31, 2022

  1. v0.15.0

    kthohr committed Jul 31, 2022
    Copy the full SHA
    f509367 View commit details
  2. Merge pull request #32 from orionserup/master

    makes the library windows compatible as min and max are predefined by…
    kthohr authored Jul 31, 2022
    Copy the full SHA
    fa29df9 View commit details
  3. Merge pull request #34 from Hector-The-Coder/master

    Added rounding function handling for large numbers
    kthohr authored Jul 31, 2022
    Copy the full SHA
    8687926 View commit details
  4. add tests and minor reformat

    kthohr committed Jul 31, 2022
    Copy the full SHA
    4c47bc0 View commit details
  5. [ci skip] update docs

    kthohr committed Jul 31, 2022
    Copy the full SHA
    b5bbe9a View commit details

Commits on Aug 6, 2022

  1. add more builds to Actions

    kthohr committed Aug 6, 2022
    Copy the full SHA
    3b8aa60 View commit details
  2. update Actions

    kthohr committed Aug 6, 2022
    Copy the full SHA
    24165d8 View commit details
  3. [ci skip] update intro

    kthohr committed Aug 6, 2022
    Copy the full SHA
    b280a50 View commit details

Commits on Aug 7, 2022

  1. [ci skip] update Conda info

    kthohr committed Aug 7, 2022
    Copy the full SHA
    bc64444 View commit details

Commits on Aug 11, 2022

  1. [ci skip] update docs build

    kthohr committed Aug 11, 2022
    Copy the full SHA
    da63ed0 View commit details

Commits on Aug 27, 2022

  1. v1.16.0

    - add hypot function
    kthohr committed Aug 27, 2022
    Copy the full SHA
    68e01fa View commit details

Commits on Sep 18, 2022

  1. [ci skip] code readability

    kthohr committed Sep 18, 2022
    Copy the full SHA
    ece0770 View commit details
  2. Copy the full SHA
    70b1267 View commit details

Commits on Sep 24, 2022

  1. Copy the full SHA
    e50356a View commit details
  2. add test cases

    kthohr committed Sep 24, 2022
    Copy the full SHA
    59e6b2a View commit details

Commits on Mar 2, 2023

  1. code reformatting

    kthohr committed Mar 2, 2023
    Copy the full SHA
    289d970 View commit details
  2. update docs

    kthohr committed Mar 2, 2023
    Copy the full SHA
    3815c2b View commit details
  3. Copy the full SHA
    e34a11f View commit details
  4. copyright bump

    kthohr committed Mar 2, 2023
    Copy the full SHA
    5c1df05 View commit details
Showing with 1,778 additions and 455 deletions.
  1. +3 −39 .appveyor.yml
  2. +158 −0 .github/workflows/main.yml
  3. +6 −3 .readthedocs.requirements.txt
  4. +10 −5 .readthedocs.yml
  5. +23 −76 CMakeLists.txt
  6. +1 −1 NOTICE.txt
  7. +9 −11 README.md
  8. +1 −1 cmake_files/gcemConfig.cmake.in
  9. +9 −3 docs/environment.yml
  10. +1 −1 docs/source/api/algorithms.rst
  11. +25 −1 docs/source/api/basic_functions.rst
  12. +1 −1 docs/source/api/hyperbolic_functions.rst
  13. +13 −1 docs/source/api/math_index.rst
  14. +1 −1 docs/source/api/special_functions.rst
  15. +1 −1 docs/source/api/trigonometric_functions.rst
  16. +2 −2 docs/source/conf.py
  17. +1 −1 docs/source/examples.rst
  18. +6 −6 docs/source/index.rst
  19. +12 −6 include/gcem.hpp
  20. +2 −2 include/gcem_incl/abs.hpp
  21. +3 −3 include/gcem_incl/acos.hpp
  22. +2 −2 include/gcem_incl/acosh.hpp
  23. +3 −3 include/gcem_incl/asin.hpp
  24. +2 −2 include/gcem_incl/asinh.hpp
  25. +75 −13 include/gcem_incl/atan.hpp
  26. +3 −3 include/gcem_incl/atan2.hpp
  27. +3 −3 include/gcem_incl/atanh.hpp
  28. +1 −1 include/gcem_incl/beta.hpp
  29. +1 −1 include/gcem_incl/binomial_coef.hpp
  30. +51 −3 include/gcem_incl/ceil.hpp
  31. +1 −1 include/gcem_incl/copysign.hpp
  32. +6 −6 include/gcem_incl/cos.hpp
  33. +2 −2 include/gcem_incl/cosh.hpp
  34. +54 −6 include/gcem_incl/erf.hpp
  35. +3 −3 include/gcem_incl/erf_inv.hpp
  36. +32 −8 include/gcem_incl/exp.hpp
  37. +1 −1 include/gcem_incl/expm1.hpp
  38. +40 −0 include/gcem_incl/fabs.hpp
  39. +40 −0 include/gcem_incl/fabsf.hpp
  40. +40 −0 include/gcem_incl/fabsl.hpp
  41. +18 −16 include/gcem_incl/factorial.hpp
  42. +14 −4 include/gcem_incl/find_exponent.hpp
  43. +1 −1 include/gcem_incl/find_fraction.hpp
  44. +1 −1 include/gcem_incl/find_whole.hpp
  45. +51 −3 include/gcem_incl/floor.hpp
  46. +1 −1 include/gcem_incl/fmod.hpp
  47. +1 −1 include/gcem_incl/gcd.hpp
  48. +31 −4 include/gcem_incl/gcem_options.hpp
  49. +90 −0 include/gcem_incl/hypot.hpp
  50. +2 −2 include/gcem_incl/incomplete_beta.hpp
  51. +6 −6 include/gcem_incl/incomplete_beta_inv.hpp
  52. +3 −3 include/gcem_incl/incomplete_gamma.hpp
  53. +4 −4 include/gcem_incl/incomplete_gamma_inv.hpp
  54. +88 −0 include/gcem_incl/inv_sqrt.hpp
  55. +1 −1 include/gcem_incl/is_even.hpp
  56. +1 −1 include/gcem_incl/is_finite.hpp
  57. +1 −1 include/gcem_incl/is_inf.hpp
  58. +1 −1 include/gcem_incl/is_nan.hpp
  59. +1 −1 include/gcem_incl/is_odd.hpp
  60. +1 −1 include/gcem_incl/lbeta.hpp
  61. +1 −1 include/gcem_incl/lcm.hpp
  62. +3 −3 include/gcem_incl/lgamma.hpp
  63. +1 −1 include/gcem_incl/lmgamma.hpp
  64. +45 −6 include/gcem_incl/log.hpp
  65. +59 −0 include/gcem_incl/log10.hpp
  66. +1 −1 include/gcem_incl/log1p.hpp
  67. +5 −19 include/gcem_incl/log2.hpp
  68. +1 −1 include/gcem_incl/log_binomial_coef.hpp
  69. +3 −3 include/gcem_incl/mantissa.hpp
  70. +1 −1 include/gcem_incl/max.hpp
  71. +1 −1 include/gcem_incl/min.hpp
  72. +1 −1 include/gcem_incl/neg_zero.hpp
  73. +1 −1 include/gcem_incl/pow.hpp
  74. +1 −1 include/gcem_incl/pow_integral.hpp
  75. +1 −1 include/gcem_incl/quadrature/gauss_legendre_30.hpp
  76. +1 −1 include/gcem_incl/quadrature/gauss_legendre_50.hpp
  77. +56 −4 include/gcem_incl/round.hpp
  78. +1 −1 include/gcem_incl/sgn.hpp
  79. +1 −1 include/gcem_incl/signbit.hpp
  80. +6 −6 include/gcem_incl/sin.hpp
  81. +2 −2 include/gcem_incl/sinh.hpp
  82. +31 −12 include/gcem_incl/sqrt.hpp
  83. +3 −3 include/gcem_incl/tan.hpp
  84. +26 −2 include/gcem_incl/tanh.hpp
  85. +4 −4 include/gcem_incl/tgamma.hpp
  86. +51 −3 include/gcem_incl/trunc.hpp
  87. +13 −53 tests/CMakeLists.txt
  88. +18 −0 tests/Makefile
  89. +1 −1 tests/abs.cpp
  90. +1 −1 tests/acos.cpp
  91. +1 −1 tests/acosh.cpp
  92. +1 −1 tests/asin.cpp
  93. +1 −1 tests/asinh.cpp
  94. +9 −1 tests/atan.cpp
  95. +1 −1 tests/atan2.cpp
  96. +1 −1 tests/atanh.cpp
  97. +1 −1 tests/binomial_coef.cpp
  98. +1 −1 tests/copysign.cpp
  99. +1 −1 tests/cos.cpp
  100. +1 −1 tests/cosh.cpp
  101. +7 −0 tests/cov_check
  102. +13 −4 tests/erf.cpp
  103. +3 −1 tests/erf_inv.cpp
  104. +2 −1 tests/exp.cpp
  105. +1 −1 tests/expm1.cpp
  106. +71 −0 tests/fabs.cpp
  107. +51 −0 tests/fabsf.cpp
  108. +64 −0 tests/fabsl.cpp
  109. +3 −1 tests/factorial.cpp
  110. +1 −1 tests/fmod.cpp
  111. +1 −1 tests/gcd.cpp
  112. +2 −1 tests/gcem_tests.hpp
  113. +75 −0 tests/hypot.cpp
  114. +1 −1 tests/incomplete_beta.cpp
  115. +1 −1 tests/incomplete_beta_inv.cpp
  116. +3 −1 tests/incomplete_gamma.cpp
  117. +1 −1 tests/incomplete_gamma_inv.cpp
  118. +57 −0 tests/inv_sqrt.cpp
  119. +1 −1 tests/is_odd.cpp
  120. +1 −1 tests/lcm.cpp
  121. +1 −1 tests/lgamma.cpp
  122. +8 −1 tests/log.cpp
  123. +50 −0 tests/log10.cpp
  124. +1 −1 tests/log1p.cpp
  125. +3 −1 tests/log2.cpp
  126. +1 −1 tests/log_binomial_coef.cpp
  127. +1 −1 tests/other.cpp
  128. +2 −1 tests/pow.cpp
  129. +13 −1 tests/rounding.cpp
  130. +1 −3 tests/signbit.cpp
  131. +1 −1 tests/sin.cpp
  132. +1 −1 tests/sinh.cpp
  133. +10 −2 tests/sqrt.cpp
  134. +1 −1 tests/tan.cpp
  135. +1 −1 tests/tanh.cpp
  136. +1 −1 tests/tgamma.cpp
42 changes: 3 additions & 39 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -25,44 +25,8 @@ install:
- 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
- cd tests

build_script:
- .\abs.test
- .\acos.test
- .\acosh.test
- .\asin.test
- .\asinh.test
- .\atan.test
- .\atan2.test
- .\atanh.test
- .\binomial_coef.test
- .\copysign.test
- .\cos.test
- .\cosh.test
- .\erf.test
- .\erf_inv.test
- .\exp.test
- .\expm1.test
- .\factorial.test
- .\gcd.test
- .\incomplete_beta.test
- .\incomplete_beta_inv.test
- .\incomplete_gamma.test
- .\incomplete_gamma_inv.test
- .\is_odd.test
- .\lcm.test
- .\lgamma.test
- .\log.test
- .\log1p.test
- .\log_binomial_coef.test
- .\other.test
- .\pow.test
- .\rounding.test
- .\signbit.test
- .\sin.test
- .\sinh.test
- .\sqrt.test
- .\tan.test
- .\tanh.test
- .\tgamma.test
- cd tests
- cmd: dir
- cmd: for %%f in (*.test.exe) do ( echo %%~nf && .\%%~nf )
158 changes: 158 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@

# 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
9 changes: 6 additions & 3 deletions .readthedocs.requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
sphinx == 2.4.4
breathe == 4.11.0
sphinxcontrib-katex == 0.6.0
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.1
15 changes: 10 additions & 5 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
requirements_file: .readthedocs.requirements.txt
version: 2

# conda:
# file: docs/environment.yml
build:
os: "ubuntu-22.04"
tools:
python: "mambaforge-22.9"

python:
version: 3.6
formats:
- pdf

conda:
environment: docs/environment.yml
99 changes: 23 additions & 76 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -21,7 +21,7 @@
cmake_minimum_required(VERSION 3.1)
project(gcem)

set(GCEM_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
set(GCEM_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)

#

@@ -40,92 +40,41 @@ message(STATUS "GCE-Math version ${${PROJECT_NAME}_VERSION}")

#

set(GCEM_HEADERS
${GCEM_INCLUDE_DIR}/gcem.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/abs.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/acos.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/acosh.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/asin.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/asinh.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/atan.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/atan2.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/atanh.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/beta.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/binomial_coef.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/ceil.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/copysign.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/cos.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/cosh.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/erf_inv.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/erf.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/exp.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/expm1.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/factorial.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/find_exponent.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/find_fraction.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/find_whole.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/floor.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/fmod.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/gcd.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/gcem_options.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/incomplete_beta.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/incomplete_beta_inv.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/incomplete_gamma.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/incomplete_gamma_inv.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/is_even.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/is_odd.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/is_inf.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/is_nan.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/is_finite.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/lbeta.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/lcm.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/lgamma.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/lmgamma.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/log_binomial_coef.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/log.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/log1p.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/log2.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/mantissa.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/max.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/min.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/neg_zero.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/pow_integral.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/pow.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/quadrature/gauss_legendre_30.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/quadrature/gauss_legendre_50.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/round.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/signbit.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/sgn.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/sin.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/sinh.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/sqrt.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/tan.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/tanh.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/tgamma.hpp
${GCEM_INCLUDE_DIR}/gcem_incl/trunc.hpp
)
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 $<BUILD_INTERFACE:${GCEM_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>)

OPTION(GCEM_BUILD_TESTS "gcem test suite" OFF)

if(GCEM_BUILD_TESTS)
add_subdirectory(tests)
endif()

#

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

install(TARGETS gcem
EXPORT ${PROJECT_NAME}-targets)

#
install(
TARGETS gcem
EXPORT ${PROJECT_NAME}-targets
)

export(EXPORT ${PROJECT_NAME}-targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
@@ -141,8 +90,6 @@ 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)
2 changes: 1 addition & 1 deletion NOTICE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GCE-Math: A C++ generalized constant expression-based math library
Copyright 2016-2020 Keith O'Hara
Copyright 2016-2024 Keith O'Hara

This product includes software developed by Keith O'Hara (http://www.kthohr.com)
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# GCE-Math
[![Build Status](https://travis-ci.org/kthohr/gcem.svg?branch=master)](https://travis-ci.org/kthohr/gcem) [![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) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/19bf49e64ca04c848f6a0a8030d1f131)](https://www.codacy.com/app/kthohr/gcem?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=kthohr/gcem&amp;utm_campaign=Badge_Grade) [![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/kthohr/gcem.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/kthohr/gcem) [![Documentation Status](https://readthedocs.org/projects/gcem/badge/?version=latest)](https://gcem.readthedocs.io/en/latest/?badge=latest)
[![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 compatible.
* 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 the C++ standard library (`std::`).
* 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.

@@ -28,9 +28,9 @@ Features:
The library is actively maintained and is still being extended. A list of features includes:

* Basic library functions:
- `abs`, `max`, `min`, `pow`, `sqrt`,
- `abs`, `max`, `min`, `pow`, `sqrt`, `inv_sqrt`,
- `ceil`, `floor`, `round`, `trunc`, `fmod`,
- `exp`, `expm1`, `log`, `log1p`, `log2`, and more
- `exp`, `expm1`, `log`, `log1p`, `log2`, `log10`, and more
* Trigonometric functions:
- basic: `cos`, `sin`, `tan`
- inverse: `acos`, `asin`, `atan`, `atan2`
@@ -60,14 +60,12 @@ GCE-Math is a header-only library and does not require any additional libraries

### Conda

[![Anaconda-Server Badge](https://anaconda.org/kthohr/gcem/badges/version.svg)](https://anaconda.org/kthohr/gcem) [![Anaconda-Server Badge](https://anaconda.org/kthohr/gcem/badges/platforms.svg)](https://anaconda.org/kthohr/gcem)
[![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)

<!-- [![Anaconda-Server Badge](https://anaconda.org/kthohr/gcem/badges/platforms.svg)](https://anaconda.org/kthohr/gcem) -->

You can install GCE-Math using the conda package manager.
You can install GCE-Math using the Conda package manager.

```bash
conda install -c kthohr gcem
conda install -c conda-forge gcem
```

### CMake
@@ -129,7 +127,7 @@ constexpr
return_t<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<T>`. The output type ('`return_t<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<T> = double`, otherwise `return_t<T> = T`. For types not covered by `std::is_integral`, recasts should be used.
A set of internal templated `constexpr` functions will implement a continued fraction expansion and return a value of type `return_t<T>`. The output type ('`return_t<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<T> = double`, otherwise `return_t<T> = T`. For types not covered by `std::is_integral`, recasts should be used.
## Examples
2 changes: 1 addition & 1 deletion cmake_files/gcemConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
12 changes: 9 additions & 3 deletions docs/environment.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# problem: katex is not available on conda, yet

name: gcem-docs
name: optimlib-docs

channels:
- conda-forge

dependencies:
- breathe
- 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.1
2 changes: 1 addition & 1 deletion docs/source/api/algorithms.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. Copyright (c) 2016-2020 Keith O'Hara
.. Copyright (c) 2016-2024 Keith O'Hara
Distributed under the terms of the Apache License, Version 2.0.
26 changes: 25 additions & 1 deletion docs/source/api/basic_functions.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. Copyright (c) 2016-2020 Keith O'Hara
.. Copyright (c) 2016-2024 Keith O'Hara
Distributed under the terms of the Apache License, Version 2.0.
@@ -11,6 +11,18 @@ Basic functions
.. 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
@@ -39,6 +51,10 @@ Basic functions
.. 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
@@ -51,6 +67,10 @@ Basic functions
.. 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
@@ -79,6 +99,10 @@ Basic functions
.. 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
2 changes: 1 addition & 1 deletion docs/source/api/hyperbolic_functions.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. Copyright (c) 2016-2020 Keith O'Hara
.. Copyright (c) 2016-2024 Keith O'Hara
Distributed under the terms of the Apache License, Version 2.0.
14 changes: 13 additions & 1 deletion docs/source/api/math_index.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. Copyright (c) 2016-2020 Keith O'Hara
.. Copyright (c) 2016-2024 Keith O'Hara
Distributed under the terms of the Apache License, Version 2.0.
@@ -47,6 +47,12 @@ Mathematical functions
+---------------------------------------+----------------------------------------------------+
| :ref:`abs <abs-function-reference>` | absolute value |
+---------------------------------------+----------------------------------------------------+
| :ref:`fabs <fabs-function-reference>` | absolute value |
+---------------------------------------+----------------------------------------------------+
| :ref:`fabsf <fabsf-func-ref>` | absolute value |
+---------------------------------------+----------------------------------------------------+
| :ref:`fabsl <fabsl-func-ref>` | absolute value |
+---------------------------------------+----------------------------------------------------+
| :ref:`ceil <ceil-function-reference>` | ceiling function |
+---------------------------------------+----------------------------------------------------+
| :ref:`copysign <copysign-func-ref>` | copy sign function |
@@ -61,12 +67,16 @@ Mathematical functions
+---------------------------------------+----------------------------------------------------+
| :ref:`fmod <fmod-func-ref>` | remainder of division function |
+---------------------------------------+----------------------------------------------------+
| :ref:`hypot <hypot-func-ref>` | Pythagorean addition function |
+---------------------------------------+----------------------------------------------------+
| :ref:`log <log-function-reference>` | natural logarithm function |
+---------------------------------------+----------------------------------------------------+
| :ref:`log1p <log1p-func-ref>` | natural logarithm 1 plus argument function |
+---------------------------------------+----------------------------------------------------+
| :ref:`log2 <log2-func-ref>` | binary logarithm function |
+---------------------------------------+----------------------------------------------------+
| :ref:`log10 <log10-func-ref>` | common logarithm function |
+---------------------------------------+----------------------------------------------------+
| :ref:`max <max-function-reference>` | maximum between two numbers |
+---------------------------------------+----------------------------------------------------+
| :ref:`min <min-function-reference>` | minimum between two numbers |
@@ -81,6 +91,8 @@ Mathematical functions
+---------------------------------------+----------------------------------------------------+
| :ref:`sqrt <sqrt-function-reference>` | square root function |
+---------------------------------------+----------------------------------------------------+
| :ref:`inv_sqrt <inv_sqrt-func-ref>` | inverse square root function |
+---------------------------------------+----------------------------------------------------+
| :ref:`trunc <trunc-func-ref>` | truncate function |
+---------------------------------------+----------------------------------------------------+

2 changes: 1 addition & 1 deletion docs/source/api/special_functions.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. Copyright (c) 2016-2020 Keith O'Hara
.. Copyright (c) 2016-2024 Keith O'Hara
Distributed under the terms of the Apache License, Version 2.0.
2 changes: 1 addition & 1 deletion docs/source/api/trigonometric_functions.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. Copyright (c) 2016-2020 Keith O'Hara
.. Copyright (c) 2016-2024 Keith O'Hara
Distributed under the terms of the Apache License, Version 2.0.
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

def setup(app):
app.add_stylesheet("main_stylesheet.css")
app.add_css_file("main_stylesheet.css")

# extensions = ['breathe','sphinx.ext.mathjax']
extensions = ['breathe','sphinxcontrib.katex']
@@ -25,7 +25,7 @@ def setup(app):
source_suffix = '.rst'
master_doc = 'index'
project = 'gcem'
copyright = '2016-2020 Keith O\'Hara'
copyright = '2016-2024 Keith O\'Hara'
author = 'Keith O\'Hara'

exclude_patterns = []
2 changes: 1 addition & 1 deletion docs/source/examples.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. Copyright (c) 2016-2020 Keith O'Hara
.. Copyright (c) 2016-2024 Keith O'Hara
Distributed under the terms of the Apache License, Version 2.0.
12 changes: 6 additions & 6 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. Copyright (c) 2016-2020 Keith O'Hara
.. Copyright (c) 2016-2024 Keith O'Hara
Distributed under the terms of the Apache License, Version 2.0.
@@ -9,10 +9,10 @@ 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 compatible.
* 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 the C++ standard library (``std::``).
* Tested and accurate to machine precision against the C++ standard library.
* 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
@@ -25,9 +25,9 @@ Status
The library is actively maintained, and is still being extended. A list of features includes:

* basic library functions:
- ``abs``, ``max``, ``min``, ``pow``, ``sqrt``
- ``abs``, ``max``, ``min``, ``pow``, ``sqrt``, ``inv_sqrt``
- ``ceil``, ``floor``, ``round``, ``trunc``, ``fmod``,
- ``exp``, ``expm1``, ``log``, ``log1p``, and more
- ``exp``, ``expm1``, ``log``, ``log1p``, ``log2``, ``log10`` and more
* trigonometric functions:
- basic: ``cos``, ``sin``, ``tan``
- inverse: ``acos``, ``asin``, ``atan``, ``atan2``
18 changes: 12 additions & 6 deletions include/gcem.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -30,8 +30,16 @@ namespace gcem
#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"
@@ -40,11 +48,8 @@ namespace gcem
#include "gcem_incl/max.hpp"
#include "gcem_incl/min.hpp"
#include "gcem_incl/sqrt.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/inv_sqrt.hpp"
#include "gcem_incl/hypot.hpp"

#include "gcem_incl/find_exponent.hpp"
#include "gcem_incl/find_fraction.hpp"
@@ -59,6 +64,7 @@ namespace gcem
#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"
4 changes: 2 additions & 2 deletions include/gcem_incl/abs.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -25,7 +25,7 @@
* Compile-time absolute value function
*
* @param x a real-valued input.
* @return the absolute value of \c x, \f$ |x| \f$.
* @return the absolute value of \c x, \f$ |x| \f$, where the return type is the same as the input type.
*/

template<typename T>
6 changes: 3 additions & 3 deletions include/gcem_incl/acos.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -38,9 +38,9 @@ noexcept
abs(x) > T(1) ? \
GCLIM<T>::quiet_NaN() :
// indistinguishable from one or zero
GCLIM<T>::epsilon() > abs(x - T(1)) ? \
GCLIM<T>::min() > abs(x - T(1)) ? \
T(0) :
GCLIM<T>::epsilon() > abs(x) ? \
GCLIM<T>::min() > abs(x) ? \
T(GCEM_HALF_PI) :
// else
atan( sqrt(T(1) - x*x)/x ) );
4 changes: 2 additions & 2 deletions include/gcem_incl/acosh.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -41,7 +41,7 @@ noexcept
x < T(1) ? \
GCLIM<T>::quiet_NaN() :
// indistinguishable from 1
GCLIM<T>::epsilon() > abs(x - T(1)) ? \
GCLIM<T>::min() > abs(x - T(1)) ? \
T(0) :
// else
log( x + sqrt(x*x - T(1)) ) );
6 changes: 3 additions & 3 deletions include/gcem_incl/asin.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -38,9 +38,9 @@ noexcept
x > T(1) ? \
GCLIM<T>::quiet_NaN() :
// indistinguishable from one or zero
GCLIM<T>::epsilon() > abs(x - T(1)) ? \
GCLIM<T>::min() > abs(x - T(1)) ? \
T(GCEM_HALF_PI) :
GCLIM<T>::epsilon() > abs(x) ? \
GCLIM<T>::min() > abs(x) ? \
T(0) :
// else
atan( x/sqrt(T(1) - x*x) ) );
4 changes: 2 additions & 2 deletions include/gcem_incl/asinh.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -38,7 +38,7 @@ noexcept
is_nan(x) ? \
GCLIM<T>::quiet_NaN() :
// indistinguishable from zero
GCLIM<T>::epsilon() > abs(x) ? \
GCLIM<T>::min() > abs(x) ? \
T(0) :
// else
log( x + sqrt(x*x + T(1)) ) );
88 changes: 75 additions & 13 deletions include/gcem_incl/atan.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -37,21 +37,55 @@ namespace internal
template<typename T>
constexpr
T
atan_series_order_calc(const T x, const T x_pow, const uint_t order)
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*x) );
- T(1)/( T((order-1)*4 + 1) * x_pow * xx) );
}

#if __cplusplus >= 201402L // C++14 version

template<typename T>
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<typename T>
constexpr
T
atan_series_order(const T x, const T x_pow, const uint_t order, const uint_t max_order)
noexcept
{
return( order == 1 ? \
GCEM_HALF_PI - T(1)/x + atan_series_order(x*x,pow(x,3),order+1,max_order) :
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) \
@@ -60,6 +94,8 @@ noexcept
atan_series_order_calc(x,x_pow,order) );
}

#endif

template<typename T>
constexpr
T
@@ -79,6 +115,28 @@ noexcept

// CF

#if __cplusplus >= 201402L // C++14 version

template<typename T>
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<typename T>
constexpr
T
@@ -87,25 +145,27 @@ noexcept
{
return( depth < max_depth ? \
// if
T(2*depth - 1) + depth*depth*xx/atan_cf_recur(xx,depth+1,max_depth) :
T(2*depth - 1) + T(depth*depth) * xx / atan_cf_recur(xx,depth+1,max_depth) :
// else
T(2*depth - 1) );
}

#endif

template<typename T>
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 ) );
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<typename T>
constexpr
@@ -116,6 +176,8 @@ noexcept
return( x > T(2.5) ? atan_series_main(x) : atan_cf_main(x) );
}

// check input

template<typename T>
constexpr
T
@@ -126,7 +188,7 @@ noexcept
is_nan(x) ? \
GCLIM<T>::quiet_NaN() :
// indistinguishable from zero
GCLIM<T>::epsilon() > abs(x) ? \
GCLIM<T>::min() > abs(x) ? \
T(0) :
// negative or positive
x < T(0) ? \
6 changes: 3 additions & 3 deletions include/gcem_incl/atan2.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -38,9 +38,9 @@ noexcept
any_nan(y,x) ? \
GCLIM<T>::quiet_NaN() :
//
GCLIM<T>::epsilon() > abs(x) ? \
GCLIM<T>::min() > abs(x) ? \
//
GCLIM<T>::epsilon() > abs(y) ? \
GCLIM<T>::min() > abs(y) ? \
neg_zero(y) ? \
neg_zero(x) ? - T(GCEM_PI) : - T(0) :
neg_zero(x) ? T(GCEM_PI) : T(0) :
6 changes: 3 additions & 3 deletions include/gcem_incl/atanh.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -49,10 +49,10 @@ noexcept
// function is defined for |x| < 1
T(1) < abs(x) ? \
GCLIM<T>::quiet_NaN() :
GCLIM<T>::epsilon() > (T(1) - abs(x)) ? \
GCLIM<T>::min() > (T(1) - abs(x)) ? \
sgn(x)*GCLIM<T>::infinity() :
// indistinguishable from zero
GCLIM<T>::epsilon() > abs(x) ? \
GCLIM<T>::min() > abs(x) ? \
T(0) :
// else
atanh_compute(x) );
2 changes: 1 addition & 1 deletion include/gcem_incl/beta.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion include/gcem_incl/binomial_coef.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
54 changes: 51 additions & 3 deletions include/gcem_incl/ceil.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -42,6 +42,54 @@ noexcept
return( x_whole + static_cast<T>(ceil_resid(x,x_whole)) );
}

template<typename T>
constexpr
T
ceil_check_internal(const T x)
noexcept
{
return x;
}

template<>
constexpr
float
ceil_check_internal<float>(const float x)
noexcept
{
return( abs(x) >= 8388608.f ? \
// if
x : \
// else
ceil_int(x, float(static_cast<int>(x))) );
}

template<>
constexpr
double
ceil_check_internal<double>(const double x)
noexcept
{
return( abs(x) >= 4503599627370496. ? \
// if
x : \
// else
ceil_int(x, double(static_cast<llint_t>(x))) );
}

template<>
constexpr
long double
ceil_check_internal<long double>(const long double x)
noexcept
{
return( abs(x) >= 9223372036854775808.l ? \
// if
x : \
// else
ceil_int(x, ((long double)static_cast<ullint_t>(abs(x))) * sgn(x)) );
}

template<typename T>
constexpr
T
@@ -55,10 +103,10 @@ noexcept
!is_finite(x) ? \
x :
// signed-zero cases
GCLIM<T>::epsilon() > abs(x) ? \
GCLIM<T>::min() > abs(x) ? \
x :
// else
ceil_int(x, T(static_cast<llint_t>(x))) );
ceil_check_internal(x) );
}

}
2 changes: 1 addition & 1 deletion include/gcem_incl/copysign.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
12 changes: 6 additions & 6 deletions include/gcem_incl/cos.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -47,16 +47,16 @@ noexcept
is_nan(x) ? \
GCLIM<T>::quiet_NaN() :
// indistinguishable from 0
GCLIM<T>::epsilon() > abs(x) ?
GCLIM<T>::min() > abs(x) ?
T(1) :
// special cases: pi/2 and pi
GCLIM<T>::epsilon() > abs(x - T(GCEM_HALF_PI)) ? \
GCLIM<T>::min() > abs(x - T(GCEM_HALF_PI)) ? \
T(0) :
GCLIM<T>::epsilon() > abs(x + T(GCEM_HALF_PI)) ? \
GCLIM<T>::min() > abs(x + T(GCEM_HALF_PI)) ? \
T(0) :
GCLIM<T>::epsilon() > abs(x - T(GCEM_PI)) ? \
GCLIM<T>::min() > abs(x - T(GCEM_PI)) ? \
- T(1) :
GCLIM<T>::epsilon() > abs(x + T(GCEM_PI)) ? \
GCLIM<T>::min() > abs(x + T(GCEM_PI)) ? \
- T(1) :
// else
cos_compute( tan(x/T(2)) ) );
4 changes: 2 additions & 2 deletions include/gcem_incl/cosh.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -38,7 +38,7 @@ noexcept
is_nan(x) ? \
GCLIM<T>::quiet_NaN() :
// indistinguishable from zero
GCLIM<T>::epsilon() > abs(x) ? \
GCLIM<T>::min() > abs(x) ? \
T(1) :
// else
(exp(x) + exp(-x)) / T(2) );
60 changes: 54 additions & 6 deletions include/gcem_incl/erf.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -31,6 +31,28 @@ namespace internal
// see
// http://functions.wolfram.com/GammaBetaErf/Erf/10/01/0007/

#if __cplusplus >= 201402L // C++14 version

template<typename T>
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<typename T>
constexpr
T
@@ -39,11 +61,13 @@ noexcept
{
return( depth < GCEM_ERF_MAX_ITER ? \
// if
x + 2*depth/erf_cf_large_recur(x,depth+1) :
x + 2 * depth / erf_cf_large_recur(x,depth+1) :
// else
x );
}

#endif

template<typename T>
constexpr
T
@@ -57,6 +81,28 @@ noexcept
// see
// http://functions.wolfram.com/GammaBetaErf/Erf/10/01/0005/

#if __cplusplus >= 201402L // C++14 version

template<typename T>
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<typename T>
constexpr
T
@@ -65,12 +111,14 @@ noexcept
{
return( depth < GCEM_ERF_MAX_ITER ? \
// if
(2*depth - 1) - 2*xx \
+ 4*depth*xx / erf_cf_small_recur(xx,depth+1) :
(2*depth - T(1)) - 2 * xx \
+ 4 * depth * xx / erf_cf_small_recur(xx,depth+1) :
// else
(2*depth - 1) - 2*xx );
(2*depth - T(1)) - 2*xx );
}

#endif

template<typename T>
constexpr
T
@@ -111,7 +159,7 @@ noexcept
is_neginf(x) ? \
- T(1) :
// indistinguishable from zero
GCLIM<T>::epsilon() > abs(x) ? \
GCLIM<T>::min() > abs(x) ? \
T(0) :
// else
x < T(0) ? \
6 changes: 3 additions & 3 deletions include/gcem_incl/erf_inv.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -227,10 +227,10 @@ noexcept
abs(p) > T(1) ? \
GCLIM<T>::quiet_NaN() :
// indistinguishable from 1
GCLIM<T>::epsilon() > abs(T(1) - p) ? \
GCLIM<T>::min() > abs(T(1) - p) ? \
GCLIM<T>::infinity() :
// indistinguishable from - 1
GCLIM<T>::epsilon() > abs(T(1) + p) ? \
GCLIM<T>::min() > abs(T(1) + p) ? \
- GCLIM<T>::infinity() :
// else
erf_inv_recur_begin(erf_inv_initial_val(p),p) );
40 changes: 32 additions & 8 deletions include/gcem_incl/exp.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -28,6 +28,30 @@
namespace internal
{

// see https://en.wikipedia.org/wiki/Euler%27s_continued_fraction_formula

#if __cplusplus >= 201402L // C++14 version

template<typename T>
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<typename T>
constexpr
T
@@ -36,20 +60,20 @@ noexcept
{
return( depth < GCEM_EXP_MAX_ITER_SMALL ? \
// if
depth == 1 ? \
T(1) - x/exp_cf_recur(x,depth+1) :
T(1) + x/T(depth - 1) - x/depth/exp_cf_recur(x,depth+1) :
T(1) + x/T(depth - 1) - x/depth/exp_cf_recur(x,depth+1) :
// else
T(1) );
}

#endif

template<typename T>
constexpr
T
exp_cf(const T x)
noexcept
{
return( T(1)/exp_cf_recur(x,1) );
return( T(1) / (T(1) - x / exp_cf_recur(x,2)) );
}

template<typename T>
@@ -58,7 +82,7 @@ T
exp_split(const T x)
noexcept
{
return( pow_integral(GCEM_E,find_whole(x)) * exp_cf(find_fraction(x)) );
return( static_cast<T>(pow_integral(GCEM_E,find_whole(x))) * exp_cf(find_fraction(x)) );
}

template<typename T>
@@ -72,8 +96,8 @@ noexcept
//
is_neginf(x) ? \
T(0) :
//
GCLIM<T>::epsilon() > abs(x) ? \
// indistinguishable from zero
GCLIM<T>::min() > abs(x) ? \
T(1) :
//
is_posinf(x) ? \
2 changes: 1 addition & 1 deletion include/gcem_incl/expm1.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
40 changes: 40 additions & 0 deletions include/gcem_incl/fabs.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*################################################################################
##
## 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<typename T>
constexpr
return_t<T>
fabs(const T x)
noexcept
{
return gcem::abs( static_cast<return_t<T>>(x) );
}

#endif
40 changes: 40 additions & 0 deletions include/gcem_incl/fabsf.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*################################################################################
##
## 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<typename T>
constexpr
float
fabsf(const T x)
noexcept
{
return gcem::abs( static_cast<float>(x) );
}

#endif
40 changes: 40 additions & 0 deletions include/gcem_incl/fabsl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*################################################################################
##
## 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<typename T>
constexpr
long double
fabsl(const T x)
noexcept
{
return gcem::abs( static_cast<long double>(x) );
}

#endif
34 changes: 18 additions & 16 deletions include/gcem_incl/factorial.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -35,19 +35,24 @@ constexpr
T
factorial_table(const T x)
noexcept
{ // table for x! when x = {2,...,16}
return( x == T(2) ? T(2) : x == T(3) ? T(6) :
{ // 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) :
T(20922789888000) );
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<typename T, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr>
@@ -56,14 +61,11 @@ T
factorial_recur(const T x)
noexcept
{
return( x == T(0) ? T(1) :
x == T(1) ? x :
//
x < T(17) ? \
return( x < T(21) ? \
// if
factorial_table(x) :
// else
x*factorial_recur(x-1) );
// else (but overflow is almost guaranteed here)
x * factorial_recur(x - 1) );
}

template<typename T, typename std::enable_if<!std::is_integral<T>::value>::type* = nullptr>
18 changes: 14 additions & 4 deletions include/gcem_incl/find_exponent.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -34,10 +34,20 @@ llint_t
find_exponent(const T x, const llint_t exponent)
noexcept
{
return( x < T(1) ? \
find_exponent(x*T(10),exponent - llint_t(1)) :
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)) :
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 );
}
2 changes: 1 addition & 1 deletion include/gcem_incl/find_fraction.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion include/gcem_incl/find_whole.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
54 changes: 51 additions & 3 deletions include/gcem_incl/floor.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -42,6 +42,54 @@ noexcept
return( x_whole - static_cast<T>(floor_resid(x,x_whole)) );
}

template<typename T>
constexpr
T
floor_check_internal(const T x)
noexcept
{
return x;
}

template<>
constexpr
float
floor_check_internal<float>(const float x)
noexcept
{
return( abs(x) >= 8388608.f ? \
// if
x : \
// else
floor_int(x, float(static_cast<int>(x))) );
}

template<>
constexpr
double
floor_check_internal<double>(const double x)
noexcept
{
return( abs(x) >= 4503599627370496. ? \
// if
x : \
// else
floor_int(x, double(static_cast<llint_t>(x))) );
}

template<>
constexpr
long double
floor_check_internal<long double>(const long double x)
noexcept
{
return( abs(x) >= 9223372036854775808.l ? \
// if
x : \
// else
floor_int(x, ((long double)static_cast<ullint_t>(abs(x))) * sgn(x)) );
}

template<typename T>
constexpr
T
@@ -55,10 +103,10 @@ noexcept
!is_finite(x) ? \
x :
// signed-zero cases
GCLIM<T>::epsilon() > abs(x) ? \
GCLIM<T>::min() > abs(x) ? \
x :
// else
floor_int(x, T(static_cast<llint_t>(x))) );
floor_check_internal(x) );
}

}
2 changes: 1 addition & 1 deletion include/gcem_incl/fmod.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion include/gcem_incl/gcd.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
35 changes: 31 additions & 4 deletions include/gcem_incl/gcem_options.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -22,6 +22,29 @@
#include <limits>
#include <type_traits>

// 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

@@ -30,11 +53,11 @@
#endif

#ifndef GCEM_VERSION_MINOR
#define GCEM_VERSION_MINOR 13
#define GCEM_VERSION_MINOR 18
#endif

#ifndef GCEM_VERSION_PATCH
#define GCEM_VERSION_PATCH 1
#define GCEM_VERSION_PATCH 0
#endif

//
@@ -115,7 +138,7 @@ namespace gcem
#endif

#ifndef GCEM_ERF_INV_MAX_ITER
#define GCEM_ERF_INV_MAX_ITER 55
#define GCEM_ERF_INV_MAX_ITER 60
#endif

#ifndef GCEM_EXP_MAX_ITER_SMALL
@@ -158,6 +181,10 @@ namespace gcem
#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
90 changes: 90 additions & 0 deletions include/gcem_incl/hypot.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*################################################################################
##
## 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<typename T>
constexpr
T
hypot_compute(const T x, const T ydx)
noexcept
{
return abs(x) * sqrt( T(1) + (ydx * ydx) );
}

template<typename T>
constexpr
T
hypot_vals_check(const T x, const T y)
noexcept
{
return( any_nan(x, y) ? \
GCLIM<T>::quiet_NaN() :
//
any_inf(x,y) ? \
GCLIM<T>::infinity() :
// indistinguishable from zero or one
GCLIM<T>::min() > abs(x) ? \
abs(y) :
GCLIM<T>::min() > abs(y) ? \
abs(x) :
// else
hypot_compute(x, y/x) );
}

template<typename T1, typename T2, typename TC = common_return_t<T1,T2>>
constexpr
TC
hypot_type_check(const T1 x, const T2 y)
noexcept
{
return hypot_vals_check(static_cast<TC>(x),static_cast<TC>(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<typename T1, typename T2>
constexpr
common_return_t<T1,T2>
hypot(const T1 x, const T2 y)
noexcept
{
return internal::hypot_type_check(x,y);
}

#endif
4 changes: 2 additions & 2 deletions include/gcem_incl/incomplete_beta.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -142,7 +142,7 @@ noexcept
any_nan(a, b, z) ? \
GCLIM<T>::quiet_NaN() :
// indistinguishable from zero
GCLIM<T>::epsilon() > z ? \
GCLIM<T>::min() > z ? \
T(0) :
// parameter check for performance
(a + T(1))/(a + b + T(2)) > z ? \
12 changes: 6 additions & 6 deletions include/gcem_incl/incomplete_beta_inv.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -201,9 +201,9 @@ incomplete_beta_inv_deriv_1(const T value, const T alpha_par, const T beta_par,
noexcept
{ // derivative of the incomplete beta function w.r.t. x
return( // indistinguishable from zero or one
GCLIM<T>::epsilon() > abs(value) ? \
GCLIM<T>::min() > abs(value) ? \
T(0) :
GCLIM<T>::epsilon() > abs(T(1) - value) ? \
GCLIM<T>::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 ) );
@@ -253,7 +253,7 @@ incomplete_beta_inv_recur(const T value, const T alpha_par, const T beta_par, co
noexcept
{
return( // derivative = 0
GCLIM<T>::epsilon() > abs(deriv_1) ? \
GCLIM<T>::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
@@ -301,9 +301,9 @@ noexcept
any_nan(alpha_par, beta_par, p) ? \
GCLIM<T>::quiet_NaN() :
// indistinguishable from zero or one
GCLIM<T>::epsilon() > p ? \
GCLIM<T>::min() > p ? \
T(0) :
GCLIM<T>::epsilon() > abs(T(1) - p) ? \
GCLIM<T>::min() > abs(T(1) - p) ? \
T(1) :
// else
incomplete_beta_inv_begin(incomplete_beta_inv_initial_val(alpha_par,beta_par,p),
6 changes: 3 additions & 3 deletions include/gcem_incl/incomplete_gamma.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -194,10 +194,10 @@ noexcept
a < T(0) ? \
GCLIM<T>::quiet_NaN() :
//
GCLIM<T>::epsilon() > z ? \
GCLIM<T>::min() > z ? \
T(0) :
//
GCLIM<T>::epsilon() > a ? \
GCLIM<T>::min() > a ? \
T(1) :
// cf or quadrature
(a < T(10)) && (z - a < T(10)) ?
8 changes: 4 additions & 4 deletions include/gcem_incl/incomplete_gamma_inv.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -218,14 +218,14 @@ noexcept
any_nan(a, p) ? \
GCLIM<T>::quiet_NaN() :
//
GCLIM<T>::epsilon() > p ? \
GCLIM<T>::min() > p ? \
T(0) :
p > T(1) ? \
GCLIM<T>::quiet_NaN() :
GCLIM<T>::epsilon() > abs(T(1) - p) ? \
GCLIM<T>::min() > abs(T(1) - p) ? \
GCLIM<T>::infinity() :
//
GCLIM<T>::epsilon() > a ? \
GCLIM<T>::min() > a ? \
T(0) :
// else
incomplete_gamma_inv_begin(incomplete_gamma_inv_initial_val(a,p),a,p,lgamma(a)) );
88 changes: 88 additions & 0 deletions include/gcem_incl/inv_sqrt.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*################################################################################
##
## 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<typename T>
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<T>::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<typename T>
constexpr
T
inv_sqrt_check(const T x)
noexcept
{
return( is_nan(x) ? \
GCLIM<T>::quiet_NaN() :
//
x < T(0) ? \
GCLIM<T>::quiet_NaN() :
//
is_posinf(x) ? \
T(0) :
// indistinguishable from zero or one
GCLIM<T>::min() > abs(x) ? \
GCLIM<T>::infinity() :
GCLIM<T>::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<typename T>
constexpr
return_t<T>
inv_sqrt(const T x)
noexcept
{
return internal::inv_sqrt_check( static_cast<return_t<T>>(x) );
}

#endif
2 changes: 1 addition & 1 deletion include/gcem_incl/is_even.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion include/gcem_incl/is_finite.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion include/gcem_incl/is_inf.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion include/gcem_incl/is_nan.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion include/gcem_incl/is_odd.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion include/gcem_incl/lbeta.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion include/gcem_incl/lcm.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
6 changes: 3 additions & 3 deletions include/gcem_incl/lgamma.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -101,9 +101,9 @@ noexcept
is_nan(x) ? \
GCLIM<T>::quiet_NaN() :
// indistinguishable from one or <= zero
GCLIM<T>::epsilon() > abs(x - T(1)) ? \
GCLIM<T>::min() > abs(x - T(1)) ? \
T(0) :
GCLIM<T>::epsilon() > x ? \
GCLIM<T>::min() > x ? \
GCLIM<T>::infinity() :
// else
lgamma_begin(x - T(1)) );
2 changes: 1 addition & 1 deletion include/gcem_incl/lmgamma.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
51 changes: 45 additions & 6 deletions include/gcem_incl/log.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -31,6 +31,28 @@ 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<typename T>
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<typename T>
constexpr
T
@@ -39,11 +61,13 @@ noexcept
{
return( depth < GCEM_LOG_MAX_ITER_SMALL ? \
// if
T(2*depth - 1) - T(depth*depth)*xx/log_cf_main(xx,depth+1) :
T(2*depth - 1) - T(depth*depth) * xx / log_cf_main(xx,depth+1) :
// else
T(2*depth - 1) );
}

#endif

template<typename T>
constexpr
T
@@ -94,7 +118,7 @@ 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)) );
return( log_mantissa(mantissa(x)) + T(GCEM_LOG_10) * T(find_exponent(x,0)) );
}

template<typename T>
@@ -109,10 +133,10 @@ noexcept
x < T(0) ? \
GCLIM<T>::quiet_NaN() :
// x ~= 0
GCLIM<T>::epsilon() > x ? \
GCLIM<T>::min() > x ? \
- GCLIM<T>::infinity() :
// indistinguishable from 1
GCLIM<T>::epsilon() > abs(x - T(1)) ? \
GCLIM<T>::min() > abs(x - T(1)) ? \
T(0) :
//
x == GCLIM<T>::infinity() ? \
@@ -125,6 +149,21 @@ noexcept
log_main(x) );
}

template<typename T>
constexpr
return_t<T>
log_integral_check(const T x)
noexcept
{
return( std::is_integral<T>::value ? \
x == T(0) ? \
- GCLIM<return_t<T>>::infinity() :
x > T(1) ? \
log_check( static_cast<return_t<T>>(x) ) :
static_cast<return_t<T>>(0) :
log_check( static_cast<return_t<T>>(x) ) );
}

}

/**
@@ -141,7 +180,7 @@ return_t<T>
log(const T x)
noexcept
{
return internal::log_check( static_cast<return_t<T>>(x) );
return internal::log_integral_check( x );
}

#endif
59 changes: 59 additions & 0 deletions include/gcem_incl/log10.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*################################################################################
##
## 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<typename T>
constexpr
return_t<T>
log10_check(const T x)
noexcept
{
// log_10(x) = ln(x) / ln(10)
return return_t<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<typename T>
constexpr
return_t<T>
log10(const T x)
noexcept
{
return internal::log10_check( x );
}

#endif
2 changes: 1 addition & 1 deletion include/gcem_incl/log1p.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
24 changes: 5 additions & 19 deletions include/gcem_incl/log2.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -30,26 +30,12 @@ namespace internal

template<typename T>
constexpr
T
return_t<T>
log2_check(const T x)
noexcept
{
return( is_nan(x) ? \
GCLIM<T>::quiet_NaN() :
// x < 0
x < T(0) ? \
GCLIM<T>::quiet_NaN() :
// x ~= 0
GCLIM<T>::epsilon() > x ? \
- GCLIM<T>::infinity() :
// indistinguishable from 1
GCLIM<T>::epsilon() > abs(x - T(1)) ? \
T(0) :
//
x == GCLIM<T>::infinity() ? \
GCLIM<T>::infinity() :
// else: log_2(x) = ln(x) / ln(2)
T(log(x) / GCEM_LOG_2) );
// log_2(x) = ln(x) / ln(2)
return return_t<T>(log(x) / GCEM_LOG_2);
}

}
@@ -67,7 +53,7 @@ return_t<T>
log2(const T x)
noexcept
{
return internal::log2_check( static_cast<return_t<T>>(x) );
return internal::log2_check( x );
}

#endif
2 changes: 1 addition & 1 deletion include/gcem_incl/log_binomial_coef.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
6 changes: 3 additions & 3 deletions include/gcem_incl/mantissa.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -35,9 +35,9 @@ mantissa(const T x)
noexcept
{
return( x < T(1) ? \
mantissa(x*T(10)) :
mantissa(x * T(10)) :
x > T(10) ? \
mantissa(x/T(10)) :
mantissa(x / T(10)) :
// else
x );
}
2 changes: 1 addition & 1 deletion include/gcem_incl/max.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion include/gcem_incl/min.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion include/gcem_incl/neg_zero.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion include/gcem_incl/pow.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion include/gcem_incl/pow_integral.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion include/gcem_incl/quadrature/gauss_legendre_30.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion include/gcem_incl/quadrature/gauss_legendre_50.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
60 changes: 56 additions & 4 deletions include/gcem_incl/round.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -30,7 +30,59 @@ T
round_int(const T x)
noexcept
{
return static_cast<T>(find_whole(x));
return( abs(x - internal::floor_check(x)) >= T(0.5) ? \
// if
internal::floor_check(x) + sgn(x) : \
// else
internal::floor_check(x) );
}

template<typename T>
constexpr
T
round_check_internal(const T x)
noexcept
{
return x;
}

template<>
constexpr
float
round_check_internal<float>(const float x)
noexcept
{
return( abs(x) >= 8388608.f ? \
// if
x : \
//else
round_int(x) );
}

template<>
constexpr
double
round_check_internal<double>(const double x)
noexcept
{
return( abs(x) >= 4503599627370496. ? \
// if
x : \
// else
round_int(x) );
}

template<>
constexpr
long double
round_check_internal<long double>(const long double x)
noexcept
{
return( abs(x) >= 9223372036854775808.l ? \
// if
x : \
// else
round_int(x) );
}

template<typename T>
@@ -46,10 +98,10 @@ noexcept
!is_finite(x) ? \
x :
// signed-zero cases
GCLIM<T>::epsilon() > abs(x) ? \
GCLIM<T>::min() > abs(x) ? \
x :
// else
sgn(x) * round_int(abs(x)) );
sgn(x) * round_check_internal(abs(x)) );
}

}
2 changes: 1 addition & 1 deletion include/gcem_incl/sgn.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion include/gcem_incl/signbit.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
12 changes: 6 additions & 6 deletions include/gcem_incl/sin.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -49,16 +49,16 @@ noexcept
is_nan(x) ? \
GCLIM<T>::quiet_NaN() :
// indistinguishable from zero
GCLIM<T>::epsilon() > abs(x) ? \
GCLIM<T>::min() > abs(x) ? \
T(0) :
// special cases: pi/2 and pi
GCLIM<T>::epsilon() > abs(x - T(GCEM_HALF_PI)) ? \
GCLIM<T>::min() > abs(x - T(GCEM_HALF_PI)) ? \
T(1) :
GCLIM<T>::epsilon() > abs(x + T(GCEM_HALF_PI)) ? \
GCLIM<T>::min() > abs(x + T(GCEM_HALF_PI)) ? \
- T(1) :
GCLIM<T>::epsilon() > abs(x - T(GCEM_PI)) ? \
GCLIM<T>::min() > abs(x - T(GCEM_PI)) ? \
T(0) :
GCLIM<T>::epsilon() > abs(x + T(GCEM_PI)) ? \
GCLIM<T>::min() > abs(x + T(GCEM_PI)) ? \
- T(0) :
// else
sin_compute( tan(x/T(2)) ) );
4 changes: 2 additions & 2 deletions include/gcem_incl/sinh.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -38,7 +38,7 @@ noexcept
is_nan(x) ? \
GCLIM<T>::quiet_NaN() :
// indistinguishable from zero
GCLIM<T>::epsilon() > abs(x) ? \
GCLIM<T>::min() > abs(x) ? \
T(0) :
// else
(exp(x) - exp(-x))/T(2) );
43 changes: 31 additions & 12 deletions include/gcem_incl/sqrt.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -34,19 +34,40 @@ T
sqrt_recur(const T x, const T xn, const int count)
noexcept
{
return( abs(xn - x/xn) / (T(1) + xn) < GCLIM<T>::epsilon() ? \
return( abs(xn - x/xn) / (T(1) + xn) < GCLIM<T>::min() ? \
// if
xn :
count < GCEM_SQRT_MAX_ITER ? \
// else
sqrt_recur(x,T(0.5)*(xn + x/xn), count+1) :
xn );
count < GCEM_SQRT_MAX_ITER ? \
// if
sqrt_recur(x, T(0.5)*(xn + x/xn), count+1) :
// else
xn );
}

template<typename T>
constexpr
T
sqrt_check(const T x, const T m_val)
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<typename T>
constexpr
T
sqrt_check(const T x)
noexcept
{
return( is_nan(x) ? \
@@ -58,14 +79,12 @@ noexcept
is_posinf(x) ? \
x :
// indistinguishable from zero or one
GCLIM<T>::epsilon() > abs(x) ? \
GCLIM<T>::min() > abs(x) ? \
T(0) :
GCLIM<T>::epsilon() > abs(T(1)-x) ? \
GCLIM<T>::min() > abs(T(1) - x) ? \
x :
// else
x > T(4) ? \
sqrt_check(x/T(4),T(2)*m_val) :
m_val*sqrt_recur(x,x/T(2),0) );
sqrt_simplify(x, T(1)) );
}

}
@@ -84,7 +103,7 @@ return_t<T>
sqrt(const T x)
noexcept
{
return internal::sqrt_check( static_cast<return_t<T>>(x), return_t<T>(1) );
return internal::sqrt_check( static_cast<return_t<T>>(x) );
}

#endif
6 changes: 3 additions & 3 deletions include/gcem_incl/tan.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -43,7 +43,7 @@ T
tan_series_exp(const T x)
noexcept
{
return( GCLIM<T>::epsilon() > abs(x - T(GCEM_HALF_PI)) ? \
return( GCLIM<T>::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
@@ -107,7 +107,7 @@ noexcept
is_nan(x) ? \
GCLIM<T>::quiet_NaN() :
// indistinguishable from zero
GCLIM<T>::epsilon() > abs(x) ? \
GCLIM<T>::min() > abs(x) ? \
T(0) :
// else
x < T(0) ? \
28 changes: 26 additions & 2 deletions include/gcem_incl/tanh.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -28,6 +28,28 @@
namespace internal
{

#if __cplusplus >= 201402L // C++14 version

template<typename T>
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<typename T>
constexpr
T
@@ -41,6 +63,8 @@ noexcept
T(2*depth - 1) );
}

#endif

template<typename T>
constexpr
T
@@ -60,7 +84,7 @@ noexcept
is_nan(x) ? \
GCLIM<T>::quiet_NaN() :
// indistinguishable from zero
GCLIM<T>::epsilon() > abs(x) ? \
GCLIM<T>::min() > abs(x) ? \
T(0) :
// else
x < T(0) ? \
8 changes: 4 additions & 4 deletions include/gcem_incl/tgamma.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -38,14 +38,14 @@ noexcept
is_nan(x) ? \
GCLIM<T>::quiet_NaN() :
// indistinguishable from one or zero
GCLIM<T>::epsilon() > abs(x - T(1)) ? \
GCLIM<T>::min() > abs(x - T(1)) ? \
T(1) :
GCLIM<T>::epsilon() > abs(x) ? \
GCLIM<T>::min() > abs(x) ? \
GCLIM<T>::infinity() :
// negative numbers
x < T(0) ? \
// check for integer
GCLIM<T>::epsilon() > abs(x - find_whole(x)) ? \
GCLIM<T>::min() > abs(x - find_whole(x)) ? \
GCLIM<T>::quiet_NaN() :
// else
tgamma_check(x+T(1)) / x :
54 changes: 51 additions & 3 deletions include/gcem_incl/trunc.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -33,6 +33,54 @@ noexcept
return( T(static_cast<llint_t>(x)) );
}

template<typename T>
constexpr
T
trunc_check_internal(const T x)
noexcept
{
return x;
}

template<>
constexpr
float
trunc_check_internal<float>(const float x)
noexcept
{
return( abs(x) >= 8388608.f ? \
// if
x : \
// else
trunc_int(x) );
}

template<>
constexpr
double
trunc_check_internal<double>(const double x)
noexcept
{
return( abs(x) >= 4503599627370496. ? \
// if
x : \
// else
trunc_int(x) );
}

template<>
constexpr
long double
trunc_check_internal<long double>(const long double x)
noexcept
{
return( abs(x) >= 9223372036854775808.l ? \
// if
x : \
// else
((long double)static_cast<ullint_t>(abs(x))) * sgn(x) );
}

template<typename T>
constexpr
T
@@ -46,10 +94,10 @@ noexcept
!is_finite(x) ? \
x :
// signed-zero cases
GCLIM<T>::epsilon() > abs(x) ? \
GCLIM<T>::min() > abs(x) ? \
x :
// else
trunc_int(x) );
trunc_check_internal(x) );
}

}
66 changes: 13 additions & 53 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -30,20 +30,21 @@ endif ()
message(STATUS "Forcing tests build type to Release")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)

include(CheckCXXCompilerFlag)

#

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
CHECK_CXX_COMPILER_FLAG("-std=c++11" HAS_CPP11_FLAG)
if (HAS_CPP11_FLAG)
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 -- gcem requires C++11 support!")
message(FATAL_ERROR "Unsupported compiler ${CMAKE_CXX_COMPILER} "
"GCEM requires a C++11-compatible compiler.")
endif()
endif()

@@ -54,57 +55,16 @@ endif()

#

set(GCEM_TESTS
abs.cpp
acos.cpp
acosh.cpp
asin.cpp
asinh.cpp
atan.cpp
atan2.cpp
atanh.cpp
binomial_coef.cpp
copysign.cpp
cos.cpp
cosh.cpp
erf.cpp
erf_inv.cpp
exp.cpp
expm1.cpp
factorial.cpp
fmod.cpp
gcd.cpp
incomplete_beta.cpp
incomplete_beta_inv.cpp
incomplete_gamma.cpp
incomplete_gamma_inv.cpp
is_odd.cpp
lcm.cpp
lgamma.cpp
log.cpp
log1p.cpp
log2.cpp
log_binomial_coef.cpp
other.cpp
pow.cpp
rounding.cpp
signbit.cpp
sin.cpp
sinh.cpp
sqrt.cpp
tan.cpp
tanh.cpp
tgamma.cpp
)

#
file(GLOB GCEM_TESTS_SOURCES **.cpp **.c)
set( GCEM_TESTS ${GCEM_TESTS_SOURCES})

set(GCEM_TESTS_EX "")

foreach( file_ ${GCEM_TESTS} )
string( REPLACE ".cpp" ".test" testname ${file_} )
get_filename_component(filename ${file_} NAME)
string( REPLACE ".cpp" ".test" testname ${filename} )

add_executable( ${testname} EXCLUDE_FROM_ALL ${file_} ${GCEM_HEADERS})
add_executable( ${testname} EXCLUDE_FROM_ALL ${filename} )
target_link_libraries( ${testname} gcem )

list(APPEND GCEM_TESTS_EX ${testname})
18 changes: 18 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -89,6 +89,15 @@ exp:
expm1:
$(GCEM_MAKE_CALL)

fabs:
$(GCEM_MAKE_CALL)

fabsf:
$(GCEM_MAKE_CALL)

fabsl:
$(GCEM_MAKE_CALL)

factorial:
$(GCEM_MAKE_CALL)

@@ -98,6 +107,9 @@ fmod:
gcd:
$(GCEM_MAKE_CALL)

hypot:
$(GCEM_MAKE_CALL)

incomplete_beta:
$(GCEM_MAKE_CALL)

@@ -110,6 +122,9 @@ incomplete_gamma:
incomplete_gamma_inv:
$(GCEM_MAKE_CALL)

inv_sqrt:
$(GCEM_MAKE_CALL)

is_odd:
$(GCEM_MAKE_CALL)

@@ -131,6 +146,9 @@ log1p:
log2:
$(GCEM_MAKE_CALL)

log10:
$(GCEM_MAKE_CALL)

other:
$(GCEM_MAKE_CALL)

2 changes: 1 addition & 1 deletion tests/abs.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion tests/acos.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion tests/acosh.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion tests/asin.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion tests/asinh.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
10 changes: 9 additions & 1 deletion tests/atan.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -50,11 +50,19 @@ int main()
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;
}
2 changes: 1 addition & 1 deletion tests/atan2.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion tests/atanh.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion tests/binomial_coef.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion tests/copysign.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion tests/cos.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
2 changes: 1 addition & 1 deletion tests/cosh.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
7 changes: 7 additions & 0 deletions tests/cov_check
Original file line number Diff line number Diff line change
@@ -12,4 +12,11 @@ if [[ "${SHOULD_RUN_COVERAGE}" == "y" ]]; then
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
17 changes: 13 additions & 4 deletions tests/erf.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -18,8 +18,10 @@
##
################################################################################*/

#define TEST_ERR_TOL 1e-12

#define TEST_PRINT_PRECISION_1 3
#define TEST_PRINT_PRECISION_2 18
#define TEST_PRINT_PRECISION_2 10

#include "gcem_tests.hpp"

@@ -32,11 +34,18 @@ int main()
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.05L);
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.05L);
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);
4 changes: 3 additions & 1 deletion tests/erf_inv.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -18,6 +18,8 @@
##
################################################################################*/

#define TEST_ERR_TOL 1e-12

#define TEST_PRINT_PRECISION_1 6
#define TEST_PRINT_PRECISION_2 18

3 changes: 2 additions & 1 deletion tests/exp.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
@@ -32,6 +32,7 @@ int main()
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);
2 changes: 1 addition & 1 deletion tests/expm1.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*################################################################################
##
## Copyright (C) 2016-2020 Keith O'Hara
## Copyright (C) 2016-2024 Keith O'Hara
##
## This file is part of the GCE-Math C++ library.
##
71 changes: 71 additions & 0 deletions tests/fabs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*################################################################################
##
## 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<float>::lowest());
GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, std::numeric_limits<float>::min());
GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, std::numeric_limits<float>::max());

GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, std::numeric_limits<double>::lowest());
GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, std::numeric_limits<double>::min());
GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, std::numeric_limits<double>::max());

GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, std::numeric_limits<long double>::lowest());
GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, std::numeric_limits<long double>::min());
GCEM_TEST_COMPARE_VALS(gcem::fabs,std::fabs, std::numeric_limits<long double>::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;
}
51 changes: 51 additions & 0 deletions tests/fabsf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*################################################################################
##
## 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<float>::lowest());
GCEM_TEST_COMPARE_VALS(gcem::fabsf,std::fabs, std::numeric_limits<float>::min());
GCEM_TEST_COMPARE_VALS(gcem::fabsf,std::fabs, std::numeric_limits<float>::max());

GCEM_TEST_COMPARE_VALS(gcem::fabsf,std::fabs, std::numeric_limits<float>::quiet_NaN());
GCEM_TEST_COMPARE_VALS(gcem::fabsf,std::fabs, std::numeric_limits<float>::infinity());
GCEM_TEST_COMPARE_VALS(gcem::fabsf,std::fabs, -std::numeric_limits<float>::infinity());

//

print_final("fabsf");

return 0;
}
64 changes: 64 additions & 0 deletions tests/fabsl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*################################################################################
##
## 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<double>::lowest());
GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, std::numeric_limits<double>::min());
GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, std::numeric_limits<double>::max());

GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, std::numeric_limits<long double>::lowest());
GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, std::numeric_limits<long double>::min());
GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, std::numeric_limits<long double>::max());

GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, std::numeric_limits<double>::quiet_NaN());
GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, std::numeric_limits<double>::infinity());
GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, -std::numeric_limits<double>::infinity());

GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, std::numeric_limits<long double>::quiet_NaN());
GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, std::numeric_limits<long double>::infinity());
GCEM_TEST_COMPARE_VALS(gcem::fabsl,std::fabs, -std::numeric_limits<long double>::infinity());

//

print_final("fabsl");

return 0;
}
Loading