Jackalope / jmath (public) (License: GPLv3 or later) (since 2018-10-11) (hash sha1)
C++ conxstexpr template Math library with:
- multidimensional vectors and matrices
- geometry primitives with projection, distance and intersection functions
- coordinate systems conversions
- some routines

Depends on GCE-math C++ library as git submodule.

Used with clang (version 9 or 10) and gcc (version 9).
Written with C++17.
List of commits:
Subject Hash Author Date (UTC)
gcem updated ff3d073843c2f3a153de930a3651ad8e02c1b7d1 jp.larry 2019-06-19 10:59:53
new functions 46561c6e97aa1ba2d0c41a19ba1977b0427b5f4b Your Name 2019-05-07 05:42:45
new functions 61e3c490daf394f07a4b9de2640d9e1b42fc2dd1 Your Name 2019-05-05 11:28:57
pragma removed 5843f3d68f0d3c08d5be7d16ef8c05db5bceda89 jp.larry 2019-05-01 12:31:57
uint replaced with unsigned int bbde30ca5f66601143ed8862aded9da0cd3aadf8 Your Name 2019-04-30 23:30:19
New enums for vector subscription (X, Y, Z, W, U, V indices) 760dc000f5349f72f8c73330801d1986c46dbb49 jp.larry 2019-04-29 10:43:53
new vector function 570b1dab1163d43426d70048a7ed51162127774e jp.larry 2019-04-26 04:45:13
new functions all vector summ, all vector equal to value ... a47df1be3233abb5e6e2f479b24725bb474cc483 jp.larry 2019-04-25 04:04:26
vector abs 85a414da1c952aa9ec9e2c9e4c8a938becb7a24d jp.larry 2019-04-20 14:11:03
gcem added as module 8a7946d3c3de780c6cee1bba325bb9e4b9490e42 Your Name 2019-03-18 22:05:51
new vector types b338913aa1d93eeda0b771e27dd0572353d17139 jp.larry 2019-02-26 03:33:58
inlines and new functions 1a2b86f33d8a0b1ec7db4edc138b8058fd6935b3 jp.larry 2019-02-23 18:24:38
type cast for warning remove a401d65e4ba7f4edbb9f193397017a0ddabd55cd jp.larry 2019-01-18 23:09:44
comparison operator issue solved, added begin & end functions for vector 56bc2502562e613fee6be95a889ee98197f253a2 jp.larry 2019-01-06 08:58:32
reduced pi number precision from 100500 numbers after dots to 100498 278d8e24bcabb0d55f3414915b348db601c30092 jp.larry 2019-01-06 02:34:07
nothing ba652a4c8dfd731fcc7bad57bba65ec3cb77716b jp.larry 2018-11-01 03:54:11
added is_power_of_2 for integers adf0dcb3a3ed02c441e6712f1a031ab05788045b jp.larry 2018-10-29 00:47:48
Initial commit f36f18cb8677587102be1f4f04027a04a94624b3 jp.larry 2018-10-11 19:06:27
Commit ff3d073843c2f3a153de930a3651ad8e02c1b7d1 - gcem updated
Author: jp.larry
Author date (UTC): 2019-06-19 10:59
Committer name: jp.larry
Committer date (UTC): 2019-06-19 11:00
Parent(s): 46561c6e97aa1ba2d0c41a19ba1977b0427b5f4b
Signer:
Signing key:
Signing status: N
Tree: b23771453f500dffaa3a8d27c4d01ef9d07b906d
File Lines added Lines deleted
constants.h 0 0
coordinates/coordinates.h 0 0
coordinates/spherical.h 0 0
coordinates/spherical.hpp 0 0
gcem 1 1
math.h 0 0
matrix/base.h 0 0
matrix/base.hpp 0 0
matrix/matrix.h 0 0
matrix/matrix_functions.h 0 0
matrix/matrix_functions.hpp 0 0
matrix/type_defs.h 0 0
misc.h 0 0
vector/base.h 0 0
vector/base.hpp 0 0
vector/constants.h 0 0
vector/coordinates/coordinates.h 0 0
vector/coordinates/spherical.h 0 0
vector/coordinates/spherical.hpp 0 0
vector/gcem/.appveyor.yml 63 0
vector/gcem/.gitignore 18 0
vector/gcem/.lgtm.yml 10 0
vector/gcem/.readthedocs.requirements.txt 2 0
vector/gcem/.readthedocs.yml 4 0
vector/gcem/.travis.yml 119 0
vector/gcem/CMakeLists.txt 149 0
vector/gcem/LICENSE 202 0
vector/gcem/NOTICE.txt 4 0
vector/gcem/README.md 191 0
vector/gcem/binder/environment.yml 8 0
vector/gcem/cmake_files/gcemConfig.cmake.in 26 0
vector/gcem/contributors.txt 8 0
vector/gcem/docs/Doxyfile 13 0
vector/gcem/docs/Makefile 186 0
vector/gcem/docs/environment.yml 9 0
vector/gcem/docs/make.bat 264 0
vector/gcem/docs/source/_static/main_stylesheet.css 4 0
vector/gcem/docs/source/api/algorithms.rst 16 0
vector/gcem/docs/source/api/basic_functions.rst 52 0
vector/gcem/docs/source/api/hyperbolic_functions.rst 35 0
vector/gcem/docs/source/api/math_index.rst 139 0
vector/gcem/docs/source/api/special_functions.rst 66 0
vector/gcem/docs/source/api/trigonometric_functions.rst 39 0
vector/gcem/docs/source/conf.py 36 0
vector/gcem/docs/source/examples.rst 87 0
vector/gcem/docs/source/index.rst 73 0
vector/gcem/include/gcem.hpp 93 0
vector/gcem/include/gcem_incl/abs.hpp 42 0
vector/gcem/include/gcem_incl/acos.hpp 80 0
vector/gcem/include/gcem_incl/acosh.hpp 65 0
vector/gcem/include/gcem_incl/asin.hpp 76 0
vector/gcem/include/gcem_incl/asinh.hpp 63 0
vector/gcem/include/gcem_incl/atan.hpp 152 0
vector/gcem/include/gcem_incl/atan2.hpp 84 0
vector/gcem/include/gcem_incl/atanh.hpp 76 0
vector/gcem/include/gcem_incl/beta.hpp 42 0
vector/gcem/include/gcem_incl/binomial_coef.hpp 88 0
vector/gcem/include/gcem_incl/cos.hpp 80 0
vector/gcem/include/gcem_incl/cosh.hpp 62 0
vector/gcem/include/gcem_incl/erf.hpp 135 0
vector/gcem/include/gcem_incl/erf_inv.hpp 251 0
vector/gcem/include/gcem_incl/exp.hpp 106 0
vector/gcem/include/gcem_incl/expm1.hpp 72 0
vector/gcem/include/gcem_incl/factorial.hpp 98 0
vector/gcem/include/gcem_incl/find_exponent.hpp 47 0
vector/gcem/include/gcem_incl/find_fraction.hpp 46 0
vector/gcem/include/gcem_incl/find_whole.hpp 46 0
vector/gcem/include/gcem_incl/floor.hpp 38 0
vector/gcem/include/gcem_incl/gcd.hpp 82 0
vector/gcem/include/gcem_incl/gcem_options.hpp 186 0
vector/gcem/include/gcem_incl/incomplete_beta.hpp 191 0
vector/gcem/include/gcem_incl/incomplete_beta_inv.hpp 349 0
vector/gcem/include/gcem_incl/incomplete_gamma.hpp 217 0
vector/gcem/include/gcem_incl/incomplete_gamma_inv.hpp 267 0
vector/gcem/include/gcem_incl/is_even.hpp 41 0
vector/gcem/include/gcem_incl/is_finite.hpp 78 0
vector/gcem/include/gcem_incl/is_inf.hpp 172 0
vector/gcem/include/gcem_incl/is_nan.hpp 80 0
vector/gcem/include/gcem_incl/is_odd.hpp 42 0
vector/gcem/include/gcem_incl/lbeta.hpp 42 0
vector/gcem/include/gcem_incl/lcm.hpp 65 0
vector/gcem/include/gcem_incl/lgamma.hpp 132 0
vector/gcem/include/gcem_incl/lmgamma.hpp 69 0
vector/gcem/include/gcem_incl/log.hpp 147 0
vector/gcem/include/gcem_incl/log1p.hpp 76 0
vector/gcem/include/gcem_incl/log_binomial_coef.hpp 65 0
vector/gcem/include/gcem_incl/mantissa.hpp 47 0
vector/gcem/include/gcem_incl/max.hpp 41 0
vector/gcem/include/gcem_incl/min.hpp 41 0
vector/gcem/include/gcem_incl/neg_zero.hpp 37 0
vector/gcem/include/gcem_incl/pow.hpp 82 0
vector/gcem/include/gcem_incl/pow_integral.hpp 128 0
vector/gcem/include/gcem_incl/quadrature/gauss_legendre_30.hpp 91 0
vector/gcem/include/gcem_incl/quadrature/gauss_legendre_50.hpp 131 0
vector/gcem/include/gcem_incl/sgn.hpp 45 0
vector/gcem/include/gcem_incl/sin.hpp 82 0
vector/gcem/include/gcem_incl/sinh.hpp 62 0
vector/gcem/include/gcem_incl/sqrt.hpp 85 0
vector/gcem/include/gcem_incl/tan.hpp 137 0
vector/gcem/include/gcem_incl/tanh.hpp 86 0
vector/gcem/include/gcem_incl/tgamma.hpp 69 0
vector/gcem/notebooks/gcem.ipynb 255 0
vector/gcem/tests/CMakeLists.txt 108 0
vector/gcem/tests/Makefile 30 0
vector/gcem/tests/acos.cpp 52 0
vector/gcem/tests/acosh.cpp 50 0
vector/gcem/tests/asin.cpp 52 0
vector/gcem/tests/asinh.cpp 52 0
vector/gcem/tests/atan.cpp 62 0
vector/gcem/tests/atan2.cpp 67 0
vector/gcem/tests/atanh.cpp 51 0
vector/gcem/tests/binomial_coef.cpp 51 0
vector/gcem/tests/cos.cpp 53 0
vector/gcem/tests/cosh.cpp 52 0
vector/gcem/tests/cov_check 15 0
vector/gcem/tests/erf.cpp 56 0
vector/gcem/tests/erf_inv.cpp 65 0
vector/gcem/tests/exp.cpp 58 0
vector/gcem/tests/expm1.cpp 52 0
vector/gcem/tests/factorial.cpp 59 0
vector/gcem/tests/gcd.cpp 52 0
vector/gcem/tests/gcem_tests.hpp 310 0
vector/gcem/tests/incomplete_beta.cpp 62 0
vector/gcem/tests/incomplete_beta_inv.cpp 62 0
vector/gcem/tests/incomplete_gamma.cpp 99 0
vector/gcem/tests/incomplete_gamma_inv.cpp 103 0
vector/gcem/tests/is_odd.cpp 48 0
vector/gcem/tests/lcm.cpp 52 0
vector/gcem/tests/lgamma.cpp 50 0
vector/gcem/tests/log.cpp 59 0
vector/gcem/tests/log1p.cpp 52 0
vector/gcem/tests/log_binomial_coef.cpp 51 0
vector/gcem/tests/other.cpp 34 0
vector/gcem/tests/pow.cpp 53 0
vector/gcem/tests/run_tests 4 0
vector/gcem/tests/sin.cpp 52 0
vector/gcem/tests/sinh.cpp 52 0
vector/gcem/tests/sqrt.cpp 54 0
vector/gcem/tests/tan.cpp 55 0
vector/gcem/tests/tanh.cpp 52 0
vector/math.h 0 0
vector/matrix/base.h 0 0
vector/matrix/base.hpp 0 0
vector/matrix/matrix.h 0 0
vector/matrix/matrix_functions.h 0 0
vector/matrix/matrix_functions.hpp 0 0
vector/matrix/type_defs.h 0 0
vector/misc.h 0 0
vector/type_defs.h 0 0
vector/vector.h 0 0
vector/vector/base.h 0 0
vector/vector/base.hpp 0 0
vector/vector/type_defs.h 0 0
vector/vector/vector.h 0 0
vector/vector/vector_functions.h 0 0
vector/vector/vector_functions.hpp 0 0
vector/vector_functions.h 0 0
vector/vector_functions.hpp 0 0
File constants.h changed (mode: 100644 -> 100755)
File coordinates/coordinates.h changed (mode: 100644 -> 100755)
File coordinates/spherical.h changed (mode: 100644 -> 100755)
File coordinates/spherical.hpp changed (mode: 100644 -> 100755)
File gcem changed (mode: 160000) (index ff74f5b..94443c9)
1 Subproject commit ff74f5bc3a2be949b083dcf5c1090c22ea509de9
1 Subproject commit 94443c99a7db939ac2edbba2674fdc54a8ec70c5
File math.h changed (mode: 100644 -> 100755)
File matrix/base.h changed (mode: 100644 -> 100755)
File matrix/base.hpp changed (mode: 100644 -> 100755)
File matrix/matrix.h changed (mode: 100644 -> 100755)
File matrix/matrix_functions.h changed (mode: 100644 -> 100755)
File matrix/matrix_functions.hpp changed (mode: 100644 -> 100755)
File matrix/type_defs.h changed (mode: 100644 -> 100755)
File misc.h changed (mode: 100644 -> 100755)
File vector/base.h changed (mode: 100644 -> 100755)
File vector/base.hpp changed (mode: 100644 -> 100755)
File vector/constants.h copied from file constants.h (similarity 100%)
File vector/coordinates/coordinates.h copied from file coordinates/coordinates.h (similarity 100%)
File vector/coordinates/spherical.h copied from file coordinates/spherical.h (similarity 100%)
File vector/coordinates/spherical.hpp copied from file coordinates/spherical.hpp (similarity 100%)
File vector/gcem/.appveyor.yml added (mode: 100644) (index 0000000..9fd6ddc)
1 build: false
2
3 os: Visual Studio 2015
4
5 platform:
6 - x64
7 - x86
8
9 environment:
10 matrix:
11 - MINICONDA: C:\gcem-conda
12
13 init:
14 - "ECHO %MINICONDA%"
15 - C:\"Program Files (x86)"\"Microsoft Visual Studio 14.0"\VC\vcvarsall.bat %PLATFORM%
16 - ps: if($env:Platform -eq "x64"){Start-FileDownload 'http://repo.continuum.io/miniconda/Miniconda3-latest-Windows-x86_64.exe' C:\Miniconda.exe; echo "Done"}
17 - ps: if($env:Platform -eq "x86"){Start-FileDownload 'http://repo.continuum.io/miniconda/Miniconda3-latest-Windows-x86.exe' C:\Miniconda.exe; echo "Done"}
18 - cmd: C:\Miniconda.exe /S /D=C:\gcem-conda
19 - "set PATH=%MINICONDA%;%MINICONDA%\\Scripts;%MINICONDA%\\Library\\bin;%PATH%"
20
21 install:
22 - conda config --set always_yes yes --set changeps1 no
23 - conda update -q conda
24 - conda info -a
25 - conda install cmake -c conda-forge
26 - cmake -G "NMake Makefiles" -D BUILD_TESTS=1 -D CMAKE_INSTALL_PREFIX=%MINICONDA%\\LIBRARY -D CMAKE_BUILD_TYPE=Release .
27 - nmake gcem_tests
28 - cd tests
29
30 build_script:
31 - .\acos.test
32 - .\acosh.test
33 - .\asin.test
34 - .\asinh.test
35 - .\atan.test
36 - .\atan2.test
37 - .\atanh.test
38 - .\binomial_coef.test
39 - .\cos.test
40 - .\cosh.test
41 - .\erf.test
42 - .\erf_inv.test
43 - .\exp.test
44 - .\expm1.test
45 - .\factorial.test
46 - .\gcd.test
47 - .\incomplete_beta.test
48 - .\incomplete_beta_inv.test
49 - .\incomplete_gamma.test
50 - .\incomplete_gamma_inv.test
51 - .\is_odd.test
52 - .\lcm.test
53 - .\lgamma.test
54 - .\log.test
55 - .\log1p.test
56 - .\log_binomial_coef.test
57 - .\other.test
58 - .\pow.test
59 - .\sin.test
60 - .\sinh.test
61 - .\sqrt.test
62 - .\tan.test
63 - .\tanh.test
File vector/gcem/.gitignore added (mode: 100644) (index 0000000..58d3517)
1 .DS_Store
2 .ipynb_checkpoints
3 .Rproj.user
4 .Rhistory
5 build
6 docs/xml
7 *.dll
8 *.exe
9 *.log
10 *.lp
11 *.o
12 *.so
13 *.test
14 *.vscode
15 *.gcda
16 *.gcno
17 *.gcov
18 *.dSYM
File vector/gcem/.lgtm.yml added (mode: 100644) (index 0000000..698655d)
1
2 path_classifiers:
3 test:
4 - tests
5 extraction:
6 cpp:
7 index:
8 build_command:
9 - cd ./tests
10 - make
File vector/gcem/.readthedocs.requirements.txt added (mode: 100644) (index 0000000..78ea10a)
1 breathe
2 sphinxcontrib-katex
File vector/gcem/.readthedocs.yml added (mode: 100644) (index 0000000..77c2388)
1 requirements_file: .readthedocs.requirements.txt
2
3 # conda:
4 # file: docs/environment.yml
File vector/gcem/.travis.yml added (mode: 100644) (index 0000000..83d79a3)
1
2 language: c++
3 sudo: required
4
5 matrix:
6 include:
7 - os: linux
8 dist: trusty
9 addons:
10 apt:
11 packages:
12 - g++-5
13 sources: &sources
14 - ubuntu-toolchain-r-test
15 env:
16 - MATRIX_EVAL="CC=gcc-5 && CXX=g++-5"
17 compiler: gcc
18
19 - os: linux
20 dist: trusty
21 addons:
22 apt:
23 packages:
24 - g++-6
25 sources: &sources
26 - ubuntu-toolchain-r-test
27 env:
28 - MATRIX_EVAL="CC=gcc-6 && CXX=g++-6"
29 compiler: gcc
30
31 - os: linux
32 dist: trusty
33 addons:
34 apt:
35 packages:
36 - g++-7
37 sources: &sources
38 - ubuntu-toolchain-r-test
39 env:
40 - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7"
41 - CCOV=gcov-7
42 - SHOULD_RUN_COVERAGE="y"
43 compiler: gcc
44
45 - os: linux
46 dist: trusty
47 addons:
48 apt:
49 packages:
50 - g++-8
51 sources: &sources
52 - ubuntu-toolchain-r-test
53 env:
54 - MATRIX_EVAL="CC=gcc-8 && CXX=g++-8"
55 compiler: gcc
56
57 - os: linux
58 dist: trusty
59 addons:
60 apt:
61 packages:
62 - clang-5.0
63 sources: &sources
64 - llvm-toolchain-trusty-5.0
65 env:
66 - MATRIX_EVAL="CC=clang-5.0 && CXX=clang++-5.0"
67 compiler: clang
68
69 - os: linux
70 dist: trusty
71 addons:
72 apt:
73 packages:
74 - clang-6.0
75 sources: &sources
76 - llvm-toolchain-trusty-6.0
77 - sourceline: 'ppa:ubuntu-toolchain-r/test'
78 env:
79 - MATRIX_EVAL="CC=clang-6.0 && CXX=clang++-6.0"
80 compiler: clang
81
82 - os: osx
83 osx_image: xcode9
84 env:
85 - MATRIX_EVAL="CC=clang && CXX=clang++"
86 compiler: clang
87
88 before_install:
89 - eval "${MATRIX_EVAL}"
90
91 install:
92 - |
93 if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then
94 sudo apt-get update
95 # else
96 # OSX
97 # brew upgrade gcc || brew install gcc
98 fi
99
100 script:
101 - cd ./tests && make
102 - ./run_tests
103 - ./cov_check
104 - cd ..
105
106 after_success:
107 - |
108 if [[ "${SHOULD_RUN_COVERAGE}" == "y" ]]; then
109 alias gcov=$CCOV
110 bash <(curl -s https://codecov.io/bash) -x $CCOV
111 fi
112
113 after_failure:
114 - ./travis-tool.sh dump_logs
115
116 notifications:
117 email:
118 on_success: change
119 on_failure: change
File vector/gcem/CMakeLists.txt added (mode: 100644) (index 0000000..09d7ef7)
1 ################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################
20
21 cmake_minimum_required(VERSION 3.1)
22 project(gcem)
23
24 set(GCEM_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
25
26 #
27
28 file(STRINGS "${GCEM_INCLUDE_DIR}/gcem_incl/gcem_options.hpp" gcem_version_defines
29 REGEX "#define GCEM_VERSION_(MAJOR|MINOR|PATCH)")
30
31 foreach(ver ${gcem_version_defines})
32 if(ver MATCHES "#define GCEM_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")
33 set(GCEM_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
34 endif()
35 endforeach()
36
37 set(${PROJECT_NAME}_VERSION
38 ${GCEM_VERSION_MAJOR}.${GCEM_VERSION_MINOR}.${GCEM_VERSION_PATCH})
39 message(STATUS "GCE-Math version ${${PROJECT_NAME}_VERSION}")
40
41 #
42
43 set(GCEM_HEADERS
44 ${GCEM_INCLUDE_DIR}/gcem.hpp
45 ${GCEM_INCLUDE_DIR}/gcem_incl/abs.hpp
46 ${GCEM_INCLUDE_DIR}/gcem_incl/acos.hpp
47 ${GCEM_INCLUDE_DIR}/gcem_incl/acosh.hpp
48 ${GCEM_INCLUDE_DIR}/gcem_incl/asin.hpp
49 ${GCEM_INCLUDE_DIR}/gcem_incl/asinh.hpp
50 ${GCEM_INCLUDE_DIR}/gcem_incl/atan.hpp
51 ${GCEM_INCLUDE_DIR}/gcem_incl/atan2.hpp
52 ${GCEM_INCLUDE_DIR}/gcem_incl/atanh.hpp
53 ${GCEM_INCLUDE_DIR}/gcem_incl/beta.hpp
54 ${GCEM_INCLUDE_DIR}/gcem_incl/binomial_coef.hpp
55 ${GCEM_INCLUDE_DIR}/gcem_incl/cos.hpp
56 ${GCEM_INCLUDE_DIR}/gcem_incl/cosh.hpp
57 ${GCEM_INCLUDE_DIR}/gcem_incl/erf_inv.hpp
58 ${GCEM_INCLUDE_DIR}/gcem_incl/erf.hpp
59 ${GCEM_INCLUDE_DIR}/gcem_incl/exp.hpp
60 ${GCEM_INCLUDE_DIR}/gcem_incl/expm1.hpp
61 ${GCEM_INCLUDE_DIR}/gcem_incl/factorial.hpp
62 ${GCEM_INCLUDE_DIR}/gcem_incl/find_exponent.hpp
63 ${GCEM_INCLUDE_DIR}/gcem_incl/find_fraction.hpp
64 ${GCEM_INCLUDE_DIR}/gcem_incl/find_whole.hpp
65 ${GCEM_INCLUDE_DIR}/gcem_incl/floor.hpp
66 ${GCEM_INCLUDE_DIR}/gcem_incl/gcd.hpp
67 ${GCEM_INCLUDE_DIR}/gcem_incl/gcem_options.hpp
68 ${GCEM_INCLUDE_DIR}/gcem_incl/incomplete_beta.hpp
69 ${GCEM_INCLUDE_DIR}/gcem_incl/incomplete_beta_inv.hpp
70 ${GCEM_INCLUDE_DIR}/gcem_incl/incomplete_gamma.hpp
71 ${GCEM_INCLUDE_DIR}/gcem_incl/incomplete_gamma_inv.hpp
72 ${GCEM_INCLUDE_DIR}/gcem_incl/is_even.hpp
73 ${GCEM_INCLUDE_DIR}/gcem_incl/is_odd.hpp
74 ${GCEM_INCLUDE_DIR}/gcem_incl/is_inf.hpp
75 ${GCEM_INCLUDE_DIR}/gcem_incl/is_nan.hpp
76 ${GCEM_INCLUDE_DIR}/gcem_incl/is_finite.hpp
77 ${GCEM_INCLUDE_DIR}/gcem_incl/lbeta.hpp
78 ${GCEM_INCLUDE_DIR}/gcem_incl/lcm.hpp
79 ${GCEM_INCLUDE_DIR}/gcem_incl/lgamma.hpp
80 ${GCEM_INCLUDE_DIR}/gcem_incl/lmgamma.hpp
81 ${GCEM_INCLUDE_DIR}/gcem_incl/log_binomial_coef.hpp
82 ${GCEM_INCLUDE_DIR}/gcem_incl/log.hpp
83 ${GCEM_INCLUDE_DIR}/gcem_incl/log1p.hpp
84 ${GCEM_INCLUDE_DIR}/gcem_incl/mantissa.hpp
85 ${GCEM_INCLUDE_DIR}/gcem_incl/max.hpp
86 ${GCEM_INCLUDE_DIR}/gcem_incl/min.hpp
87 ${GCEM_INCLUDE_DIR}/gcem_incl/neg_zero.hpp
88 ${GCEM_INCLUDE_DIR}/gcem_incl/pow_integral.hpp
89 ${GCEM_INCLUDE_DIR}/gcem_incl/pow.hpp
90 ${GCEM_INCLUDE_DIR}/gcem_incl/quadrature/gauss_legendre_30.hpp
91 ${GCEM_INCLUDE_DIR}/gcem_incl/quadrature/gauss_legendre_50.hpp
92 ${GCEM_INCLUDE_DIR}/gcem_incl/sgn.hpp
93 ${GCEM_INCLUDE_DIR}/gcem_incl/sin.hpp
94 ${GCEM_INCLUDE_DIR}/gcem_incl/sinh.hpp
95 ${GCEM_INCLUDE_DIR}/gcem_incl/sqrt.hpp
96 ${GCEM_INCLUDE_DIR}/gcem_incl/tan.hpp
97 ${GCEM_INCLUDE_DIR}/gcem_incl/tanh.hpp
98 ${GCEM_INCLUDE_DIR}/gcem_incl/tgamma.hpp
99 )
100
101 #
102
103 add_library(gcem INTERFACE)
104 target_include_directories(gcem INTERFACE $<BUILD_INTERFACE:${GCEM_INCLUDE_DIR}>
105 $<INSTALL_INTERFACE:include>)
106
107 OPTION(BUILD_TESTS "gcem test suite" OFF)
108
109 if(BUILD_TESTS)
110 add_subdirectory(tests)
111 endif()
112
113 #
114
115 include(GNUInstallDirs)
116 include(CMakePackageConfigHelpers)
117
118 install(TARGETS gcem
119 EXPORT ${PROJECT_NAME}-targets)
120
121 #
122
123 export(EXPORT ${PROJECT_NAME}-targets
124 FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
125
126 install(DIRECTORY ${GCEM_INCLUDE_DIR}/
127 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
128
129 #
130
131 set(GCEM_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE STRING "install path for gcemConfig.cmake")
132
133 configure_package_config_file(cmake_files/${PROJECT_NAME}Config.cmake.in
134 "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
135 INSTALL_DESTINATION ${GCEM_CMAKECONFIG_INSTALL_DIR})
136
137 #
138
139 write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
140 VERSION ${${PROJECT_NAME}_VERSION}
141 COMPATIBILITY SameMajorVersion)
142
143 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
144 ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
145 DESTINATION ${GCEM_CMAKECONFIG_INSTALL_DIR})
146
147 install(EXPORT ${PROJECT_NAME}-targets
148 FILE ${PROJECT_NAME}Targets.cmake
149 DESTINATION ${GCEM_CMAKECONFIG_INSTALL_DIR})
File vector/gcem/LICENSE added (mode: 100644) (index 0000000..7a4a3ea)
1
2 Apache License
3 Version 2.0, January 2004
4 http://www.apache.org/licenses/
5
6 TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
8 1. Definitions.
9
10 "License" shall mean the terms and conditions for use, reproduction,
11 and distribution as defined by Sections 1 through 9 of this document.
12
13 "Licensor" shall mean the copyright owner or entity authorized by
14 the copyright owner that is granting the License.
15
16 "Legal Entity" shall mean the union of the acting entity and all
17 other entities that control, are controlled by, or are under common
18 control with that entity. For the purposes of this definition,
19 "control" means (i) the power, direct or indirect, to cause the
20 direction or management of such entity, whether by contract or
21 otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 outstanding shares, or (iii) beneficial ownership of such entity.
23
24 "You" (or "Your") shall mean an individual or Legal Entity
25 exercising permissions granted by this License.
26
27 "Source" form shall mean the preferred form for making modifications,
28 including but not limited to software source code, documentation
29 source, and configuration files.
30
31 "Object" form shall mean any form resulting from mechanical
32 transformation or translation of a Source form, including but
33 not limited to compiled object code, generated documentation,
34 and conversions to other media types.
35
36 "Work" shall mean the work of authorship, whether in Source or
37 Object form, made available under the License, as indicated by a
38 copyright notice that is included in or attached to the work
39 (an example is provided in the Appendix below).
40
41 "Derivative Works" shall mean any work, whether in Source or Object
42 form, that is based on (or derived from) the Work and for which the
43 editorial revisions, annotations, elaborations, or other modifications
44 represent, as a whole, an original work of authorship. For the purposes
45 of this License, Derivative Works shall not include works that remain
46 separable from, or merely link (or bind by name) to the interfaces of,
47 the Work and Derivative Works thereof.
48
49 "Contribution" shall mean any work of authorship, including
50 the original version of the Work and any modifications or additions
51 to that Work or Derivative Works thereof, that is intentionally
52 submitted to Licensor for inclusion in the Work by the copyright owner
53 or by an individual or Legal Entity authorized to submit on behalf of
54 the copyright owner. For the purposes of this definition, "submitted"
55 means any form of electronic, verbal, or written communication sent
56 to the Licensor or its representatives, including but not limited to
57 communication on electronic mailing lists, source code control systems,
58 and issue tracking systems that are managed by, or on behalf of, the
59 Licensor for the purpose of discussing and improving the Work, but
60 excluding communication that is conspicuously marked or otherwise
61 designated in writing by the copyright owner as "Not a Contribution."
62
63 "Contributor" shall mean Licensor and any individual or Legal Entity
64 on behalf of whom a Contribution has been received by Licensor and
65 subsequently incorporated within the Work.
66
67 2. Grant of Copyright License. Subject to the terms and conditions of
68 this License, each Contributor hereby grants to You a perpetual,
69 worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 copyright license to reproduce, prepare Derivative Works of,
71 publicly display, publicly perform, sublicense, and distribute the
72 Work and such Derivative Works in Source or Object form.
73
74 3. Grant of Patent License. Subject to the terms and conditions of
75 this License, each Contributor hereby grants to You a perpetual,
76 worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 (except as stated in this section) patent license to make, have made,
78 use, offer to sell, sell, import, and otherwise transfer the Work,
79 where such license applies only to those patent claims licensable
80 by such Contributor that are necessarily infringed by their
81 Contribution(s) alone or by combination of their Contribution(s)
82 with the Work to which such Contribution(s) was submitted. If You
83 institute patent litigation against any entity (including a
84 cross-claim or counterclaim in a lawsuit) alleging that the Work
85 or a Contribution incorporated within the Work constitutes direct
86 or contributory patent infringement, then any patent licenses
87 granted to You under this License for that Work shall terminate
88 as of the date such litigation is filed.
89
90 4. Redistribution. You may reproduce and distribute copies of the
91 Work or Derivative Works thereof in any medium, with or without
92 modifications, and in Source or Object form, provided that You
93 meet the following conditions:
94
95 (a) You must give any other recipients of the Work or
96 Derivative Works a copy of this License; and
97
98 (b) You must cause any modified files to carry prominent notices
99 stating that You changed the files; and
100
101 (c) You must retain, in the Source form of any Derivative Works
102 that You distribute, all copyright, patent, trademark, and
103 attribution notices from the Source form of the Work,
104 excluding those notices that do not pertain to any part of
105 the Derivative Works; and
106
107 (d) If the Work includes a "NOTICE" text file as part of its
108 distribution, then any Derivative Works that You distribute must
109 include a readable copy of the attribution notices contained
110 within such NOTICE file, excluding those notices that do not
111 pertain to any part of the Derivative Works, in at least one
112 of the following places: within a NOTICE text file distributed
113 as part of the Derivative Works; within the Source form or
114 documentation, if provided along with the Derivative Works; or,
115 within a display generated by the Derivative Works, if and
116 wherever such third-party notices normally appear. The contents
117 of the NOTICE file are for informational purposes only and
118 do not modify the License. You may add Your own attribution
119 notices within Derivative Works that You distribute, alongside
120 or as an addendum to the NOTICE text from the Work, provided
121 that such additional attribution notices cannot be construed
122 as modifying the License.
123
124 You may add Your own copyright statement to Your modifications and
125 may provide additional or different license terms and conditions
126 for use, reproduction, or distribution of Your modifications, or
127 for any such Derivative Works as a whole, provided Your use,
128 reproduction, and distribution of the Work otherwise complies with
129 the conditions stated in this License.
130
131 5. Submission of Contributions. Unless You explicitly state otherwise,
132 any Contribution intentionally submitted for inclusion in the Work
133 by You to the Licensor shall be under the terms and conditions of
134 this License, without any additional terms or conditions.
135 Notwithstanding the above, nothing herein shall supersede or modify
136 the terms of any separate license agreement you may have executed
137 with Licensor regarding such Contributions.
138
139 6. Trademarks. This License does not grant permission to use the trade
140 names, trademarks, service marks, or product names of the Licensor,
141 except as required for reasonable and customary use in describing the
142 origin of the Work and reproducing the content of the NOTICE file.
143
144 7. Disclaimer of Warranty. Unless required by applicable law or
145 agreed to in writing, Licensor provides the Work (and each
146 Contributor provides its Contributions) on an "AS IS" BASIS,
147 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 implied, including, without limitation, any warranties or conditions
149 of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 PARTICULAR PURPOSE. You are solely responsible for determining the
151 appropriateness of using or redistributing the Work and assume any
152 risks associated with Your exercise of permissions under this License.
153
154 8. Limitation of Liability. In no event and under no legal theory,
155 whether in tort (including negligence), contract, or otherwise,
156 unless required by applicable law (such as deliberate and grossly
157 negligent acts) or agreed to in writing, shall any Contributor be
158 liable to You for damages, including any direct, indirect, special,
159 incidental, or consequential damages of any character arising as a
160 result of this License or out of the use or inability to use the
161 Work (including but not limited to damages for loss of goodwill,
162 work stoppage, computer failure or malfunction, or any and all
163 other commercial damages or losses), even if such Contributor
164 has been advised of the possibility of such damages.
165
166 9. Accepting Warranty or Additional Liability. While redistributing
167 the Work or Derivative Works thereof, You may choose to offer,
168 and charge a fee for, acceptance of support, warranty, indemnity,
169 or other liability obligations and/or rights consistent with this
170 License. However, in accepting such obligations, You may act only
171 on Your own behalf and on Your sole responsibility, not on behalf
172 of any other Contributor, and only if You agree to indemnify,
173 defend, and hold each Contributor harmless for any liability
174 incurred by, or claims asserted against, such Contributor by reason
175 of your accepting any such warranty or additional liability.
176
177 END OF TERMS AND CONDITIONS
178
179 APPENDIX: How to apply the Apache License to your work.
180
181 To apply the Apache License to your work, attach the following
182 boilerplate notice, with the fields enclosed by brackets "[]"
183 replaced with your own identifying information. (Don't include
184 the brackets!) The text should be enclosed in the appropriate
185 comment syntax for the file format. We also recommend that a
186 file or class name and description of purpose be included on the
187 same "printed page" as the copyright notice for easier
188 identification within third-party archives.
189
190 Copyright [yyyy] [name of copyright owner]
191
192 Licensed under the Apache License, Version 2.0 (the "License");
193 you may not use this file except in compliance with the License.
194 You may obtain a copy of the License at
195
196 http://www.apache.org/licenses/LICENSE-2.0
197
198 Unless required by applicable law or agreed to in writing, software
199 distributed under the License is distributed on an "AS IS" BASIS,
200 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 See the License for the specific language governing permissions and
202 limitations under the License.
File vector/gcem/NOTICE.txt added (mode: 100644) (index 0000000..dd017b9)
1 GCE-Math: A C++ generalized constant expression-based math library
2 Copyright 2016-2019 Keith O'Hara
3
4 This product includes software developed by Keith O'Hara (http://www.kthohr.com)
File vector/gcem/README.md added (mode: 100644) (index 0000000..f229e1b)
1 # GCE-Math
2 [![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)
3
4 GCE-Math (**G**eneralized **C**onstant **E**xpression Math) is a templated C++ library enabling compile-time computation of mathematical functions.
5
6 Features:
7
8 * The library is written in C++11 ```constexpr``` format, and is C++11/14/17 compatible.
9 * Continued fraction and series expansions are implemented using recursive templates.
10 * The ```gcem::``` syntax is identical to the C++ standard library (`std::`).
11 * Tested and accurate to floating-point precision against the C++ standard library.
12 * Released under a permissive, non-GPL license.
13
14 **Author**: Keith O'Hara
15
16 [![License](https://img.shields.io/badge/Licence-Apache%202.0-blue.svg)](./LICENSE)
17
18 ### Contents:
19 * [Status and Documentation](#status-and-documentation)
20 * [Installation and Tests](#installation-and-tests)
21 * [Jupyter Notebook](#jupyter-notebook)
22 * [General Syntax](#general-syntax)
23 * [Examples](#examples)
24
25 ## Status and Documentation
26
27 The library is actively maintained, and is still being extended. A list of features includes:
28
29 * basic library functions:
30 - ```abs```, ```max```, ```min```, ```pow```, ```sqrt```,
31 - ```exp```, ```expm1```, ```log```, ```log1p```, and more
32 * trigonometric functions:
33 - basic: ```cos```, ```sin```, ```tan```
34 - inverse: ```acos```, ```asin```, ```atan```, ```atan2```
35 * hyperbolic (area) functions:
36 - ```cosh```, ```sinh```, ```tanh```, ```acosh```, ```asinh```, ```atanh```
37 * algorithms:
38 - ```gcd```, ```lcm```
39 * special functions:
40 - factorials and the binomial coefficient: ```factorial```, ```binomial_coef```
41 - beta, gamma, and multivariate gamma functions: ```beta```, ```lbeta```, ```lgamma```, ```tgamma```, ```lmgamma```
42 - the Gaussian error function and inverse error function: ```erf```, ```erf_inv```
43 - (regularized) incomplete beta and incomplete gamma functions: ```incomplete_beta```, ```incomplete_gamma```
44 - inverse incomplete beta and incomplete gamma functions: ```incomplete_beta_inv```, ```incomplete_gamma_inv```
45
46 Full documentation is available online:
47
48 [![Documentation Status](https://readthedocs.org/projects/gcem/badge/?version=latest)](https://gcem.readthedocs.io/en/latest/?badge=latest)
49
50 ## Installation and Tests
51
52 GCE-Math is a header-only library and does not require any additional libraries (beyond a C++11 compatible compiler). Simply add the header files to your project using:
53 ```cpp
54 #include "gcem.hpp"
55 ```
56
57 ### Conda
58
59 <!-- [![Anaconda-Server Badge](https://anaconda.org/kthohr/gcem/badges/platforms.svg)](https://anaconda.org/kthohr/gcem) -->
60
61 You can install GCE-Math using the conda package manager.
62
63 ```bash
64 conda install gcem -c kthohr
65 ```
66
67 ### CMake
68
69 You can also install the library from source using CMake.
70
71 ```bash
72 # clone gcem from GitHub
73 git clone https://github.com/kthohr/gcem ./gcem
74
75 # make a build directory
76 cd ./gcem
77 mkdir build
78 cd build
79
80 # generate Makefiles and install
81 cmake .. -DCMAKE_INSTALL_PREFIX=/gcem/install/location
82 make install
83 ```
84 For example, `/gcem/install/location` could be `/usr/local/`.
85
86 ### Test Suite
87
88 There are two ways to build the test suite. On Unix-alike systems, a Makefile is available under `tests/`.
89
90 ```bash
91 cd ./gcem/tests
92 make
93 ./run_tests
94 ```
95
96 With CMake, the option `BUILD_TESTS=1` generates the necessary Makefiles to build the test suite.
97 ```bash
98 cd ./gcem
99 mkdir build
100
101 cd build
102 cmake ../ -DBUILD_TESTS=1 -DCMAKE_INSTALL_PREFIX=/gcem/install/location
103 make gcem_tests
104
105 cd tests
106 ./exp.test
107 ```
108
109 ## Jupyter Notebook
110
111 You can test the library online using an interactive Jupyter notebook:
112
113 [![Binder](https://mybinder.org/badge.svg)](https://mybinder.org/v2/gh/kthohr/gcem/master?filepath=notebooks%2Fgcem.ipynb)
114
115 ## General Syntax
116
117 GCE-Math functions are written as C++ templates with `constexpr` specifiers, the format of which might be confusing to users unfamiliar with template-based programming. As an example, the [Gaussian error function](https://en.wikipedia.org/wiki/Error_function) (```erf```) is defined as:
118 ```cpp
119 template<typename T>
120 constexpr
121 return_t<T>
122 erf(const T x) noexcept;
123 ```
124 where a set of internal templated ```constexpr``` functions will implement a continued fraction expansion to return a value of type ```return_t<T>```. This 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.
125
126 ## Examples
127
128 To calculate 10!:
129
130 ```cpp
131 #include "gcem.hpp"
132
133 int main()
134 {
135 constexpr int x = 10;
136 constexpr int res = gcem::factorial(x);
137
138 return 0;
139 }
140 ```
141 Inspecting the assembly code generated by Clang 7.0.0:
142 ```assembly
143 push rbp
144 mov rbp, rsp
145 xor eax, eax
146 mov dword ptr [rbp - 4], 0
147 mov dword ptr [rbp - 8], 10
148 mov dword ptr [rbp - 12], 3628800
149 pop rbp
150 ret
151 ```
152 We see that a function call has been replaced by a numeric value (10! = 3628800).
153
154 Similarly, to compute the log Gamma function at a point:
155
156 ```cpp
157 #include "gcem.hpp"
158
159 int main()
160 {
161 constexpr long double x = 1.5;
162 constexpr long double res = gcem::lgamma(x);
163
164 return 0;
165 }
166 ```
167 Assembly code:
168 ```assembly
169 .LCPI0_0:
170 .long 1069547520 # float 1.5
171 .LCPI0_1:
172 .quad -622431863250842976 # x86_fp80 -0.120782237635245222719
173 .short 49147
174 .zero 6
175 main: # @main
176 push rbp
177 mov rbp, rsp
178 xor eax, eax
179 mov dword ptr [rbp - 4], 0
180 fld dword ptr [rip + .LCPI0_0]
181 fstp tbyte ptr [rbp - 32]
182 fld tbyte ptr [rip + .LCPI0_1]
183 fstp tbyte ptr [rbp - 48]
184 pop rbp
185 ret
186 ```
187
188 ## Related libraries
189
190 For a library built on the GCEM compile-time functionality, see [StatsLib](https://github.com/kthohr/stats).
191
File vector/gcem/binder/environment.yml added (mode: 100644) (index 0000000..58f327a)
1 # For use with Binder
2 name: statslib
3 channels:
4 - QuantStack
5 - conda-forge
6 dependencies:
7 - xeus-cling=0.4.7
8 - notebook
File vector/gcem/cmake_files/gcemConfig.cmake.in added (mode: 100644) (index 0000000..de98d38)
1 ################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################
20
21 @PACKAGE_INIT@
22
23 if(NOT TARGET @PROJECT_NAME@)
24 include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
25 get_target_property(@PROJECT_NAME@_INCLUDE_DIRS gcem INTERFACE_INCLUDE_DIRECTORIES)
26 endif()
File vector/gcem/contributors.txt added (mode: 100644) (index 0000000..5d3383c)
1 External contributions to GCEM
2 ----
3
4 2018-08-02 @jonathansharman
5 - atan2 implementation
6
7 2018-07-13 @cpsauer
8 - fix bug in binomial_coef
File vector/gcem/docs/Doxyfile added (mode: 100644) (index 0000000..9b0ff67)
1 PROJECT_NAME = "gcem"
2 XML_OUTPUT = xml
3 INPUT = ../include
4 GENERATE_LATEX = NO
5 GENERATE_MAN = NO
6 GENERATE_RTF = NO
7 CASE_SENSE_NAMES = NO
8 GENERATE_HTML = NO
9 GENERATE_XML = YES
10 RECURSIVE = YES
11 QUIET = YES
12 JAVADOC_AUTOBRIEF = YES
13 WARN_IF_UNDOCUMENTED = NO
File vector/gcem/docs/Makefile added (mode: 100644) (index 0000000..a198dfc)
1 # You can set these variables from the command line.
2 SPHINXOPTS =
3 SPHINXBUILD = sphinx-build
4 PAPER =
5 BUILDDIR = build
6
7 # User-friendly check for sphinx-build
8 ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
9 $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
10 endif
11
12 # Internal variables.
13 PAPEROPT_a4 = -D latex_paper_size=a4
14 PAPEROPT_letter = -D latex_paper_size=letter
15 ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
16 # the i18n builder cannot share the environment and doctrees with the others
17 I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
18
19 .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest coverage gettext api
20
21 default: html
22
23 help:
24 @echo "Please use \`make <target>' where <target> is one of"
25 @echo " html to make standalone HTML files"
26 @echo " dirhtml to make HTML files named index.html in directories"
27 @echo " singlehtml to make a single large HTML file"
28 @echo " pickle to make pickle files"
29 @echo " json to make JSON files"
30 @echo " htmlhelp to make HTML files and a HTML help project"
31 @echo " qthelp to make HTML files and a qthelp project"
32 @echo " applehelp to make an Apple Help Book"
33 @echo " devhelp to make HTML files and a Devhelp project"
34 @echo " epub to make an epub"
35 @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
36 @echo " latexpdf to make LaTeX files and run them through pdflatex"
37 @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
38 @echo " text to make text files"
39 @echo " man to make manual pages"
40 @echo " texinfo to make Texinfo files"
41 @echo " info to make Texinfo files and run them through makeinfo"
42 @echo " gettext to make PO message catalogs"
43 @echo " changes to make an overview of all changed/added/deprecated items"
44 @echo " xml to make Docutils-native XML files"
45 @echo " pseudoxml to make pseudoxml-XML files for display purposes"
46 @echo " linkcheck to check all external links for integrity"
47 @echo " doctest to run all doctests embedded in the documentation (if enabled)"
48 @echo " coverage to run coverage check of the documentation (if enabled)"
49
50 clean:
51 rm -rf $(BUILDDIR)/*
52
53 html:
54 doxygen
55 $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
56 @echo
57 @echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
58
59 dirhtml:
60 doxygen
61 $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
62 @echo
63 @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
64
65 singlehtml:
66 doxygen
67 $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
68 @echo
69 @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
70
71 pickle:
72 doxygen
73 $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
74 @echo
75 @echo "Build finished; now you can process the pickle files."
76
77 json:
78 doxygen
79 $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
80 @echo
81 @echo "Build finished; now you can process the JSON files."
82
83 htmlhelp:
84 doxygen
85 $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
86 @echo
87 @echo "Build finished; now you can run HTML Help Workshop with the" \
88 ".hhp project file in $(BUILDDIR)/htmlhelp."
89
90 epub:
91 doxygen
92 $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
93 @echo
94 @echo "Build finished. The epub file is in $(BUILDDIR)/epub."
95
96 latex:
97 doxygen
98 $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
99 @echo
100 @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
101 @echo "Run \`make' in that directory to run these through (pdf)latex" \
102 "(use \`make latexpdf' here to do that automatically)."
103
104 latexpdf:
105 doxygen
106 $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
107 @echo "Running LaTeX files through pdflatex..."
108 $(MAKE) -C $(BUILDDIR)/latex all-pdf
109 @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
110
111 latexpdfja:
112 doxygen
113 $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
114 @echo "Running LaTeX files through platex and dvipdfmx..."
115 $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
116 @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
117
118 text:
119 doxygen
120 $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
121 @echo
122 @echo "Build finished. The text files are in $(BUILDDIR)/text."
123
124 man:
125 doxygen
126 $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
127 @echo
128 @echo "Build finished. The manual pages are in $(BUILDDIR)/man."
129
130 texinfo:
131 doxygen
132 $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
133 @echo
134 @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
135 @echo "Run \`make' in that directory to run these through makeinfo" \
136 "(use \`make info' here to do that automatically)."
137
138 info:
139 doxygen
140 $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
141 @echo "Running Texinfo files through makeinfo..."
142 make -C $(BUILDDIR)/texinfo info
143 @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
144
145 gettext:
146 doxygen
147 $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
148 @echo
149 @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
150
151 changes:
152 doxygen
153 $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
154 @echo
155 @echo "The overview file is in $(BUILDDIR)/changes."
156
157 linkcheck:
158 doxygen
159 $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
160 @echo
161 @echo "Link check complete; look for any errors in the above output " \
162 "or in $(BUILDDIR)/linkcheck/output.txt."
163
164 doctest:
165 doxygen
166 $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
167 @echo "Testing of doctests in the sources finished, look at the " \
168 "results in $(BUILDDIR)/doctest/output.txt."
169
170 coverage:
171 doxygen
172 $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage
173 @echo "Testing of coverage in the sources finished, look at the " \
174 "results in $(BUILDDIR)/coverage/python.txt."
175
176 xml:
177 doxygen
178 $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
179 @echo
180 @echo "Build finished. The XML files are in $(BUILDDIR)/xml."
181
182 pseudoxml:
183 doxygen
184 $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
185 @echo
186 @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
File vector/gcem/docs/environment.yml added (mode: 100644) (index 0000000..e43e3ba)
1 # problem: katex is not available on conda, yet
2
3 name: gcem-docs
4
5 channels:
6 - conda-forge
7
8 dependencies:
9 - breathe
File vector/gcem/docs/make.bat added (mode: 100644) (index 0000000..0df92b4)
1 @ECHO OFF
2
3 REM Command file for Sphinx documentation
4
5 if "%SPHINXBUILD%" == "" (
6 set SPHINXBUILD=sphinx-build
7 )
8 set BUILDDIR=build
9 set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% source
10 set I18NSPHINXOPTS=%SPHINXOPTS% source
11 if NOT "%PAPER%" == "" (
12 set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
13 set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
14 )
15
16 if "%1" == "" goto help
17
18 if "%1" == "help" (
19 :help
20 echo.Please use `make ^<target^>` where ^<target^> is one of
21 echo. html to make standalone HTML files
22 echo. dirhtml to make HTML files named index.html in directories
23 echo. singlehtml to make a single large HTML file
24 echo. pickle to make pickle files
25 echo. json to make JSON files
26 echo. htmlhelp to make HTML files and a HTML help project
27 echo. qthelp to make HTML files and a qthelp project
28 echo. devhelp to make HTML files and a Devhelp project
29 echo. epub to make an epub
30 echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
31 echo. text to make text files
32 echo. man to make manual pages
33 echo. texinfo to make Texinfo files
34 echo. gettext to make PO message catalogs
35 echo. changes to make an overview over all changed/added/deprecated items
36 echo. xml to make Docutils-native XML files
37 echo. pseudoxml to make pseudoxml-XML files for display purposes
38 echo. linkcheck to check all external links for integrity
39 echo. doctest to run all doctests embedded in the documentation if enabled
40 echo. coverage to run coverage check of the documentation if enabled
41 goto end
42 )
43
44 if "%1" == "clean" (
45 for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
46 del /q /s %BUILDDIR%\*
47 goto end
48 )
49
50
51 REM Check if sphinx-build is available and fallback to Python version if any
52 %SPHINXBUILD% 1>NUL 2>NUL
53 if errorlevel 9009 goto sphinx_python
54 goto sphinx_ok
55
56 :sphinx_python
57
58 set SPHINXBUILD=python -m sphinx.__init__
59 %SPHINXBUILD% 2> nul
60 if errorlevel 9009 (
61 echo.
62 echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
63 echo.installed, then set the SPHINXBUILD environment variable to point
64 echo.to the full path of the 'sphinx-build' executable. Alternatively you
65 echo.may add the Sphinx directory to PATH.
66 echo.
67 echo.If you don't have Sphinx installed, grab it from
68 echo.http://sphinx-doc.org/
69 exit /b 1
70 )
71
72 :sphinx_ok
73
74
75 if "%1" == "html" (
76 doxygen
77 %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
78 if errorlevel 1 exit /b 1
79 echo.
80 echo.Build finished. The HTML pages are in %BUILDDIR%/html.
81 goto end
82 )
83
84 if "%1" == "dirhtml" (
85 %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
86 if errorlevel 1 exit /b 1
87 echo.
88 echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
89 goto end
90 )
91
92 if "%1" == "singlehtml" (
93 %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
94 if errorlevel 1 exit /b 1
95 echo.
96 echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
97 goto end
98 )
99
100 if "%1" == "pickle" (
101 %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
102 if errorlevel 1 exit /b 1
103 echo.
104 echo.Build finished; now you can process the pickle files.
105 goto end
106 )
107
108 if "%1" == "json" (
109 %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
110 if errorlevel 1 exit /b 1
111 echo.
112 echo.Build finished; now you can process the JSON files.
113 goto end
114 )
115
116 if "%1" == "htmlhelp" (
117 %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
118 if errorlevel 1 exit /b 1
119 echo.
120 echo.Build finished; now you can run HTML Help Workshop with the ^
121 .hhp project file in %BUILDDIR%/htmlhelp.
122 goto end
123 )
124
125 if "%1" == "qthelp" (
126 %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
127 if errorlevel 1 exit /b 1
128 echo.
129 echo.Build finished; now you can run "qcollectiongenerator" with the ^
130 .qhcp project file in %BUILDDIR%/qthelp, like this:
131 echo.^> qcollectiongenerator %BUILDDIR%\qthelp\packagename.qhcp
132 echo.To view the help file:
133 echo.^> assistant -collectionFile %BUILDDIR%\qthelp\packagename.ghc
134 goto end
135 )
136
137 if "%1" == "devhelp" (
138 %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
139 if errorlevel 1 exit /b 1
140 echo.
141 echo.Build finished.
142 goto end
143 )
144
145 if "%1" == "epub" (
146 %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
147 if errorlevel 1 exit /b 1
148 echo.
149 echo.Build finished. The epub file is in %BUILDDIR%/epub.
150 goto end
151 )
152
153 if "%1" == "latex" (
154 %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
155 if errorlevel 1 exit /b 1
156 echo.
157 echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
158 goto end
159 )
160
161 if "%1" == "latexpdf" (
162 %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
163 cd %BUILDDIR%/latex
164 make all-pdf
165 cd %~dp0
166 echo.
167 echo.Build finished; the PDF files are in %BUILDDIR%/latex.
168 goto end
169 )
170
171 if "%1" == "latexpdfja" (
172 %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
173 cd %BUILDDIR%/latex
174 make all-pdf-ja
175 cd %~dp0
176 echo.
177 echo.Build finished; the PDF files are in %BUILDDIR%/latex.
178 goto end
179 )
180
181 if "%1" == "text" (
182 %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
183 if errorlevel 1 exit /b 1
184 echo.
185 echo.Build finished. The text files are in %BUILDDIR%/text.
186 goto end
187 )
188
189 if "%1" == "man" (
190 %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
191 if errorlevel 1 exit /b 1
192 echo.
193 echo.Build finished. The manual pages are in %BUILDDIR%/man.
194 goto end
195 )
196
197 if "%1" == "texinfo" (
198 %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
199 if errorlevel 1 exit /b 1
200 echo.
201 echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
202 goto end
203 )
204
205 if "%1" == "gettext" (
206 %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
207 if errorlevel 1 exit /b 1
208 echo.
209 echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
210 goto end
211 )
212
213 if "%1" == "changes" (
214 %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
215 if errorlevel 1 exit /b 1
216 echo.
217 echo.The overview file is in %BUILDDIR%/changes.
218 goto end
219 )
220
221 if "%1" == "linkcheck" (
222 %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
223 if errorlevel 1 exit /b 1
224 echo.
225 echo.Link check complete; look for any errors in the above output ^
226 or in %BUILDDIR%/linkcheck/output.txt.
227 goto end
228 )
229
230 if "%1" == "doctest" (
231 %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
232 if errorlevel 1 exit /b 1
233 echo.
234 echo.Testing of doctests in the sources finished, look at the ^
235 results in %BUILDDIR%/doctest/output.txt.
236 goto end
237 )
238
239 if "%1" == "coverage" (
240 %SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage
241 if errorlevel 1 exit /b 1
242 echo.
243 echo.Testing of coverage in the sources finished, look at the ^
244 results in %BUILDDIR%/coverage/python.txt.
245 goto end
246 )
247
248 if "%1" == "xml" (
249 %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml
250 if errorlevel 1 exit /b 1
251 echo.
252 echo.Build finished. The XML files are in %BUILDDIR%/xml.
253 goto end
254 )
255
256 if "%1" == "pseudoxml" (
257 %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml
258 if errorlevel 1 exit /b 1
259 echo.
260 echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml.
261 goto end
262 )
263
264 :end
File vector/gcem/docs/source/_static/main_stylesheet.css added (mode: 100644) (index 0000000..dc4199e)
1 .wy-nav-content{
2 max-width: 1000px;
3 margin: auto;
4 }
File vector/gcem/docs/source/api/algorithms.rst added (mode: 100644) (index 0000000..d2308db)
1 .. Copyright (c) 2016--2018 Keith O'Hara
2
3 Distributed under the terms of the Apache License, Version 2.0.
4
5 The full license is in the file LICENSE, distributed with this software.
6
7 Algorithms
8 ===============
9
10 .. _gcd-function-reference:
11 .. doxygenfunction:: gcd(const T1, const T2)
12 :project: gcem
13
14 .. _lcm-function-reference:
15 .. doxygenfunction:: lcm(const T1, const T2)
16 :project: gcem
File vector/gcem/docs/source/api/basic_functions.rst added (mode: 100644) (index 0000000..73e6056)
1 .. Copyright (c) 2016--2018 Keith O'Hara
2
3 Distributed under the terms of the Apache License, Version 2.0.
4
5 The full license is in the file LICENSE, distributed with this software.
6
7 Basic functions
8 ===============
9
10 .. _abs-function-reference:
11 .. doxygenfunction:: abs(const T)
12 :project: gcem
13
14 .. _exp-function-reference:
15 .. doxygenfunction:: exp(const T)
16 :project: gcem
17
18 .. _expm1-func-ref:
19 .. doxygenfunction:: expm1(const T)
20 :project: gcem
21
22 .. _factorial-func-ref:
23 .. doxygenfunction:: factorial(const T)
24 :project: gcem
25
26 .. _log-function-reference:
27 .. doxygenfunction:: log(const T)
28 :project: gcem
29
30 .. _log1p-func-ref:
31 .. doxygenfunction:: log1p(const T)
32 :project: gcem
33
34 .. _max-function-reference:
35 .. doxygenfunction:: max(const T1, const T2)
36 :project: gcem
37
38 .. _min-function-reference:
39 .. doxygenfunction:: min(const T1, const T2)
40 :project: gcem
41
42 .. _pow-function-reference:
43 .. doxygenfunction:: pow(const T1, const T2)
44 :project: gcem
45
46 .. _sgn-function-reference:
47 .. doxygenfunction:: sgn(const T)
48 :project: gcem
49
50 .. _sqrt-function-reference:
51 .. doxygenfunction:: sqrt(const T)
52 :project: gcem
File vector/gcem/docs/source/api/hyperbolic_functions.rst added (mode: 100644) (index 0000000..fddbdf0)
1 .. Copyright (c) 2016--2018 Keith O'Hara
2
3 Distributed under the terms of the Apache License, Version 2.0.
4
5 The full license is in the file LICENSE, distributed with this software.
6
7 Hyperbolic functions
8 ===============
9
10 .. _cosh-function-reference:
11 .. doxygenfunction:: cosh(const T)
12 :project: gcem
13
14 .. _sinh-function-reference:
15 .. doxygenfunction:: sinh(const T)
16 :project: gcem
17
18 .. _tanh-function-reference:
19 .. doxygenfunction:: tanh(const T)
20 :project: gcem
21
22 Inverse hyperbolic functions
23 -----------------
24
25 .. _acosh-func-ref:
26 .. doxygenfunction:: acosh(const T)
27 :project: gcem
28
29 .. _asinh-func-ref:
30 .. doxygenfunction:: asinh(const T)
31 :project: gcem
32
33 .. _atanh-func-ref:
34 .. doxygenfunction:: atanh(const T)
35 :project: gcem
File vector/gcem/docs/source/api/math_index.rst added (mode: 100644) (index 0000000..072947b)
1 .. Copyright (c) 2016--2018 Keith O'Hara
2
3 Distributed under the terms of the Apache License, Version 2.0.
4
5 The full license is in the file LICENSE, distributed with this software.
6
7 .. raw:: html
8
9 <style>
10 .rst-content table.docutils {
11 width: 100%;
12 table-layout: fixed;
13 }
14
15 table.docutils .line-block {
16 margin-left: 0;
17 margin-bottom: 0;
18 }
19
20 table.docutils code.literal {
21 color: initial;
22 }
23
24 code.docutils {
25 background: initial;
26 }
27 </style>
28
29 Mathematical functions
30 ======================
31
32 .. toctree::
33
34 algorithms
35
36 +---------------------------------------+----------------------------------------------------+
37 | :ref:`gcd <gcd-function-reference>` | greatest common divisor |
38 +---------------------------------------+----------------------------------------------------+
39 | :ref:`lcm <lcm-function-reference>` | least common multiple |
40 +---------------------------------------+----------------------------------------------------+
41
42
43 .. toctree::
44
45 basic_functions
46
47 +---------------------------------------+----------------------------------------------------+
48 | :ref:`abs <abs-function-reference>` | absolute value |
49 +---------------------------------------+----------------------------------------------------+
50 | :ref:`exp <exp-function-reference>` | exponential function |
51 +---------------------------------------+----------------------------------------------------+
52 | :ref:`expm1 <expm1-func-ref>` | exponential minus 1 function |
53 +---------------------------------------+----------------------------------------------------+
54 | :ref:`factorial <factorial-func-ref>` | factorial function |
55 +---------------------------------------+----------------------------------------------------+
56 | :ref:`log <log-function-reference>` | natural logarithm function |
57 +---------------------------------------+----------------------------------------------------+
58 | :ref:`log1p <log1p-func-ref>` | natural logarithm 1 plus argument function |
59 +---------------------------------------+----------------------------------------------------+
60 | :ref:`max <max-function-reference>` | maximum between two numbers |
61 +---------------------------------------+----------------------------------------------------+
62 | :ref:`min <min-function-reference>` | minimum between two numbers |
63 +---------------------------------------+----------------------------------------------------+
64 | :ref:`pow <pow-function-reference>` | power function |
65 +---------------------------------------+----------------------------------------------------+
66 | :ref:`sgn <sgn-function-reference>` | sign function |
67 +---------------------------------------+----------------------------------------------------+
68 | :ref:`sqrt <sqrt-function-reference>` | square root function |
69 +---------------------------------------+----------------------------------------------------+
70
71 .. toctree::
72
73 hyperbolic_functions
74
75 +---------------------------------------+----------------------------------------------------+
76 | :ref:`cosh <cosh-function-reference>` | hyperbolic cosine function |
77 +---------------------------------------+----------------------------------------------------+
78 | :ref:`sinh <sinh-function-reference>` | hyperbolic sine function |
79 +---------------------------------------+----------------------------------------------------+
80 | :ref:`tanh <tanh-function-reference>` | hyperbolic tangent function |
81 +---------------------------------------+----------------------------------------------------+
82 | :ref:`acosh <acosh-func-ref>` | inverse hyperbolic cosine function |
83 +---------------------------------------+----------------------------------------------------+
84 | :ref:`asinh <asinh-func-ref>` | inverse hyperbolic sine function |
85 +---------------------------------------+----------------------------------------------------+
86 | :ref:`atanh <atanh-func-ref>` | inverse hyperbolic tangent function |
87 +---------------------------------------+----------------------------------------------------+
88
89 .. toctree::
90
91 special_functions
92
93 +---------------------------------------+----------------------------------------------------+
94 | :ref:`binomial_coef <binom-func-ref>` | binomial coefficient |
95 +---------------------------------------+----------------------------------------------------+
96 | :ref:`log_binomial_coef <lbinom-ref>` | log binomial coefficient |
97 +---------------------------------------+----------------------------------------------------+
98 | :ref:`beta <beta-function-reference>` | beta function |
99 +---------------------------------------+----------------------------------------------------+
100 | :ref:`lbeta <lbeta-func-ref>` | log-beta function |
101 +---------------------------------------+----------------------------------------------------+
102 | :ref:`tgamma <tgamma-func-ref>` | gamma function |
103 +---------------------------------------+----------------------------------------------------+
104 | :ref:`lgamma <lgamma-func-ref>` | log-gamma function |
105 +---------------------------------------+----------------------------------------------------+
106 | :ref:`lmgamma <lmgamma-func-ref>` | log-multivariate gamma function |
107 +---------------------------------------+----------------------------------------------------+
108 | :ref:`erf <erf-function-reference>` | error function |
109 +---------------------------------------+----------------------------------------------------+
110 | :ref:`incomplete_beta <ib-func-ref>` | incomplete beta function |
111 +---------------------------------------+----------------------------------------------------+
112 | :ref:`incomplete_gamma <ig-func-ref>` | incomplete gamma function |
113 +---------------------------------------+----------------------------------------------------+
114 | :ref:`erf_inv <erf_inv-func-ref>` | inverse error function |
115 +---------------------------------------+----------------------------------------------------+
116 | :ref:`incomplete_beta_inv <iib-ref>` | inverse incomplete beta function |
117 +---------------------------------------+----------------------------------------------------+
118 | :ref:`incomplete_gamma_inv <iig-ref>` | inverse incomplete gamma function |
119 +---------------------------------------+----------------------------------------------------+
120
121 .. toctree::
122
123 trigonometric_functions
124
125 +---------------------------------------+----------------------------------------------------+
126 | :ref:`cos <cos-function-reference>` | cosine function |
127 +---------------------------------------+----------------------------------------------------+
128 | :ref:`sin <sin-function-reference>` | sine function |
129 +---------------------------------------+----------------------------------------------------+
130 | :ref:`tan <tan-function-reference>` | tangent function |
131 +---------------------------------------+----------------------------------------------------+
132 | :ref:`acos <acos-function-reference>` | arccosine function |
133 +---------------------------------------+----------------------------------------------------+
134 | :ref:`asin <asin-function-reference>` | arcsine function |
135 +---------------------------------------+----------------------------------------------------+
136 | :ref:`atan <atan-function-reference>` | arctangent function |
137 +---------------------------------------+----------------------------------------------------+
138 | :ref:`atan2 <atan2-func-ref>` | two-argument arctangent function |
139 +---------------------------------------+----------------------------------------------------+
File vector/gcem/docs/source/api/special_functions.rst added (mode: 100644) (index 0000000..6bd21b9)
1 .. Copyright (c) 2016--2018 Keith O'Hara
2
3 Distributed under the terms of the Apache License, Version 2.0.
4
5 The full license is in the file LICENSE, distributed with this software.
6
7 Special functions
8 ===============
9
10 .. _binom-func-ref:
11 .. doxygenfunction:: binomial_coef(const T1, const T2)
12 :project: gcem
13
14 .. _lbinom-ref:
15 .. doxygenfunction:: log_binomial_coef(const T1, const T2)
16 :project: gcem
17
18 .. _beta-function-reference:
19 .. doxygenfunction:: beta(const T1, const T2)
20 :project: gcem
21
22 .. _lbeta-func-ref:
23 .. doxygenfunction:: lbeta(const T1, const T2)
24 :project: gcem
25
26 .. _tgamma-func-ref:
27 .. doxygenfunction:: tgamma(const T)
28 :project: gcem
29
30 .. _lgamma-func-ref:
31 .. doxygenfunction:: lgamma(const T)
32 :project: gcem
33
34 .. _lmgamma-func-ref:
35 .. doxygenfunction:: lmgamma(const T1, const T2)
36 :project: gcem
37
38 Incomplete integral functions
39 -----------------
40
41 .. _erf-function-reference:
42 .. doxygenfunction:: erf(const T)
43 :project: gcem
44
45 .. _ib-func-ref:
46 .. doxygenfunction:: incomplete_beta(const T1, const T2, const T3)
47 :project: gcem
48
49 .. _ig-func-ref:
50 .. doxygenfunction:: incomplete_gamma(const T1, const T2)
51 :project: gcem
52
53 Inverse incomplete integral functions
54 -----------------
55
56 .. _erf_inv-func-ref:
57 .. doxygenfunction:: erf_inv(const T)
58 :project: gcem
59
60 .. _iib-ref:
61 .. doxygenfunction:: incomplete_beta_inv(const T1, const T2, const T3)
62 :project: gcem
63
64 .. _iig-ref:
65 .. doxygenfunction:: incomplete_gamma_inv(const T1, const T2)
66 :project: gcem
File vector/gcem/docs/source/api/trigonometric_functions.rst added (mode: 100644) (index 0000000..c3d561e)
1 .. Copyright (c) 2016--2018 Keith O'Hara
2
3 Distributed under the terms of the Apache License, Version 2.0.
4
5 The full license is in the file LICENSE, distributed with this software.
6
7 Trigonometric functions
8 ===============
9
10 .. _cos-function-reference:
11 .. doxygenfunction:: cos(const T)
12 :project: gcem
13
14 .. _sin-function-reference:
15 .. doxygenfunction:: sin(const T)
16 :project: gcem
17
18 .. _tan-function-reference:
19 .. doxygenfunction:: tan(const T)
20 :project: gcem
21
22 Inverse trigonometric functions
23 -----------------
24
25 .. _acos-function-reference:
26 .. doxygenfunction:: acos(const T)
27 :project: gcem
28
29 .. _asin-function-reference:
30 .. doxygenfunction:: asin(const T)
31 :project: gcem
32
33 .. _atan-function-reference:
34 .. doxygenfunction:: atan(const T)
35 :project: gcem
36
37 .. _atan2-func-ref:
38 .. doxygenfunction:: atan2(const T1, const T2)
39 :project: gcem
File vector/gcem/docs/source/conf.py added (mode: 100644) (index 0000000..4801437)
1 #!/usr/bin/env python3
2
3 import os
4 import subprocess
5
6 on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
7
8 if on_rtd:
9 subprocess.call('cd ..; doxygen', shell=True)
10
11 import sphinx_rtd_theme
12
13 html_theme = "sphinx_rtd_theme"
14
15 html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
16
17 def setup(app):
18 app.add_stylesheet("main_stylesheet.css")
19
20 # extensions = ['breathe','sphinx.ext.mathjax']
21 extensions = ['breathe','sphinxcontrib.katex']
22 breathe_projects = { 'gcem': '../xml' }
23 templates_path = ['_templates']
24 html_static_path = ['_static']
25 source_suffix = '.rst'
26 master_doc = 'index'
27 project = 'gcem'
28 copyright = '2016-2019 Keith O\'Hara'
29 author = 'Keith O\'Hara'
30
31 exclude_patterns = []
32 highlight_language = 'c++'
33 pygments_style = 'sphinx'
34 todo_include_todos = False
35 htmlhelp_basename = 'gcemdoc'
36
File vector/gcem/docs/source/examples.rst added (mode: 100644) (index 0000000..8005c88)
1 .. Copyright (c) 2016--2018 Keith O'Hara
2
3 Distributed under the terms of the Apache License, Version 2.0.
4
5 The full license is in the file LICENSE, distributed with this software.
6
7 Examples
8 ===========
9
10 To calculate 10!:
11
12 .. code:: cpp
13
14 #include "gcem.hpp"
15
16 int main()
17 {
18 constexpr int x = 10;
19 constexpr int res = gcem::factorial(x);
20
21 return 0;
22 }
23
24 Inspecting the assembly code generated by Clang:
25
26 .. code:: asm
27
28 push rbp
29 mov rbp, rsp
30 xor eax, eax
31 mov dword ptr [rbp - 4], 0
32 mov dword ptr [rbp - 8], 10
33 mov dword ptr [rbp - 12], 3628800
34 pop rbp
35 ret
36
37 We see that a function call has been replaced by a numeric value (10! = 3628800).
38
39 Similarly, to compute the log-Gamma function at a point:
40
41 .. code:: cpp
42
43 #include "gcem.hpp"
44
45 int main()
46 {
47 constexpr long double x = 1.5;
48 constexpr long double res = gcem::lgamma(x);
49
50 return 0;
51 }
52
53 Assembly code:
54
55 .. code:: asm
56
57 .LCPI0_0:
58 .long 1069547520 # float 1.5
59 .LCPI0_1:
60 .quad -622431863250842976 # x86_fp80 -0.120782237635245222719
61 .short 49147
62 .zero 6
63 main: # @main
64 push rbp
65 mov rbp, rsp
66 xor eax, eax
67 mov dword ptr [rbp - 4], 0
68 fld dword ptr [rip + .LCPI0_0]
69 fstp tbyte ptr [rbp - 32]
70 fld tbyte ptr [rip + .LCPI0_1]
71 fstp tbyte ptr [rbp - 48]
72 pop rbp
73 ret
74
75 Test suite
76 ----------
77
78 To build the full test suite:
79
80 .. code:: bash
81
82 # clone gcem from GitHub
83 git clone -b master --single-branch https://github.com/kthohr/gcem ./gcem
84 # compile tests
85 cd ./gcem/tests
86 make
87 ./run_tests
File vector/gcem/docs/source/index.rst added (mode: 100644) (index 0000000..8c4b1d7)
1 .. Copyright (c) 2016--2018 Keith O'Hara
2
3 Distributed under the terms of the Apache License, Version 2.0.
4
5 The full license is in the file LICENSE, distributed with this software.
6
7 Introduction
8 ============
9
10 GCE-Math (\ **G**\ eneralized **C**\ onstant **E**\ xpression Math) is a templated C++ library enabling compile-time computation of mathematical functions.
11
12 * The library is written in C++11 ``constexpr`` format, and is C++11/14/17 compatible.
13 * Continued fraction and series expansions are implemented using recursive templates.
14 * The ``gcem::`` syntax is identical to the C++ standard library (``std::``).
15 * Tested and accurate to machine precision against the C++ standard library.
16 * Released under a permissive, non-GPL license.
17
18 Author: Keith O'Hara
19
20 License: Apache 2.0
21
22 Status
23 ------
24
25 The library is actively maintained, and is still being extended. A list of features includes:
26
27 * basic library functions:
28 - ``abs``, ``max``, ``min``, ``pow``, ``sqrt``
29 - ``exp``, ``expm1``, ``log``, ``log1p``, and more
30 * trigonometric functions:
31 - basic: ``cos``, ``sin``, ``tan``
32 - inverse: ``acos``, ``asin``, ``atan``, ``atan2``
33 * hyperbolic (area) functions:
34 - ``cosh``, ``sinh``, ``tanh``, ``acosh``, ``asinh``, ``atanh``
35 * algorithms:
36 - ``gcd``, ``lcm``
37 * special functions:
38 - factorials and the binomial coefficient: ``factorial``, ``binomial_coef``
39 - beta, gamma, and multivariate gamma functions: ``beta``, ``lbeta``, ``lgamma``, ``tgamma``, ``lmgamma``
40 - the Gaussian error function and inverse error function: ``erf``, ``erf_inv``
41 - (regularized) incomplete beta and incomplete gamma functions: ``incomplete_beta``, ``incomplete_gamma``
42 - inverse incomplete beta and incomplete gamma functions: ``incomplete_beta_inv``, ``incomplete_gamma_inv``
43
44 General Syntax
45 --------------
46
47 GCE-Math functions are written as C++ templates with ``constexpr`` specifiers, the format of which might be confusing to users unfamiliar with template-based programming. As an example, the `Gaussian error function <https://en.wikipedia.org/wiki/Error_function>`_ (``erf``) is defined as:
48
49 .. code:: cpp
50
51 template<typename T>
52 constexpr
53 return_t<T>
54 erf(const T x) noexcept;
55
56 where a set of internal templated ``constexpr`` functions will implement a continued fraction expansion to return a value of type ``return_t<T>``. This 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.
57
58
59 Contents
60 --------
61
62 .. toctree::
63 :caption: EXAMPLES
64 :maxdepth: 2
65
66 examples
67
68 .. toctree::
69 :titlesonly:
70 :caption: API REFERENCE
71 :maxdepth: 2
72
73 api/math_index
File vector/gcem/include/gcem.hpp added (mode: 100644) (index 0000000..27f83d0)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #ifndef _gcem_misc_HPP
22 #define _gcem_misc_HPP
23
24 #include "gcem_incl/gcem_options.hpp"
25
26 namespace gcem
27 {
28 #include "gcem_incl/quadrature/gauss_legendre_50.hpp"
29
30 #include "gcem_incl/abs.hpp"
31 #include "gcem_incl/floor.hpp"
32 #include "gcem_incl/is_odd.hpp"
33 #include "gcem_incl/is_even.hpp"
34 #include "gcem_incl/is_inf.hpp"
35 #include "gcem_incl/is_nan.hpp"
36 #include "gcem_incl/is_finite.hpp"
37 #include "gcem_incl/max.hpp"
38 #include "gcem_incl/min.hpp"
39 #include "gcem_incl/sqrt.hpp"
40
41 #include "gcem_incl/neg_zero.hpp"
42 #include "gcem_incl/sgn.hpp"
43
44 #include "gcem_incl/find_exponent.hpp"
45 #include "gcem_incl/find_fraction.hpp"
46 #include "gcem_incl/find_whole.hpp"
47 #include "gcem_incl/mantissa.hpp"
48
49 #include "gcem_incl/pow_integral.hpp"
50 #include "gcem_incl/exp.hpp"
51 #include "gcem_incl/expm1.hpp"
52 #include "gcem_incl/log.hpp"
53 #include "gcem_incl/log1p.hpp"
54 #include "gcem_incl/pow.hpp"
55
56 #include "gcem_incl/gcd.hpp"
57 #include "gcem_incl/lcm.hpp"
58
59 #include "gcem_incl/tan.hpp"
60 #include "gcem_incl/cos.hpp"
61 #include "gcem_incl/sin.hpp"
62
63 #include "gcem_incl/atan.hpp"
64 #include "gcem_incl/atan2.hpp"
65 #include "gcem_incl/acos.hpp"
66 #include "gcem_incl/asin.hpp"
67
68 #include "gcem_incl/tanh.hpp"
69 #include "gcem_incl/cosh.hpp"
70 #include "gcem_incl/sinh.hpp"
71
72 #include "gcem_incl/atanh.hpp"
73 #include "gcem_incl/acosh.hpp"
74 #include "gcem_incl/asinh.hpp"
75
76 #include "gcem_incl/binomial_coef.hpp"
77 #include "gcem_incl/lgamma.hpp"
78 #include "gcem_incl/tgamma.hpp"
79 #include "gcem_incl/factorial.hpp"
80 #include "gcem_incl/lbeta.hpp"
81 #include "gcem_incl/beta.hpp"
82 #include "gcem_incl/lmgamma.hpp"
83 #include "gcem_incl/log_binomial_coef.hpp"
84
85 #include "gcem_incl/erf.hpp"
86 #include "gcem_incl/erf_inv.hpp"
87 #include "gcem_incl/incomplete_beta.hpp"
88 #include "gcem_incl/incomplete_beta_inv.hpp"
89 #include "gcem_incl/incomplete_gamma.hpp"
90 #include "gcem_incl/incomplete_gamma_inv.hpp"
91 }
92
93 #endif
File vector/gcem/include/gcem_incl/abs.hpp added (mode: 100644) (index 0000000..78d8946)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #ifndef _gcem_abs_HPP
22 #define _gcem_abs_HPP
23
24 /**
25 * Compile-time absolute value function
26 *
27 * @param x a real-valued input.
28 * @return the absolute value of \c x, \f$ |x| \f$.
29 */
30
31 template<typename T>
32 constexpr
33 T
34 abs(const T x)
35 noexcept
36 {
37 return( x == T(0) ? T(0) : // deal with signed-zeros
38 //
39 x < T(0) ? - x : x );
40 }
41
42 #endif
File vector/gcem/include/gcem_incl/acos.hpp added (mode: 100644) (index 0000000..f587250)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time arccosine function
23 */
24
25 #ifndef _gcem_acos_HPP
26 #define _gcem_acos_HPP
27
28 namespace internal
29 {
30
31 template<typename T>
32 constexpr
33 T
34 acos_compute(const T x)
35 noexcept
36 {
37 return( // only defined on [-1,1]
38 abs(x) > T(1) ? \
39 GCLIM<T>::quiet_NaN() :
40 // indistinguishable from one or zero
41 GCLIM<T>::epsilon() > abs(x - T(1)) ? \
42 T(0) :
43 GCLIM<T>::epsilon() > abs(x) ? \
44 T(GCEM_HALF_PI) :
45 // else
46 atan( sqrt(T(1) - x*x)/x ) );
47 }
48
49 template<typename T>
50 constexpr
51 T
52 acos_check(const T x)
53 noexcept
54 {
55 return( x > T(0) ? \
56 // if
57 acos_compute(x) :
58 // else
59 T(GCEM_PI) - acos_compute(-x) );
60 }
61
62 }
63
64 /**
65 * Compile-time arccosine function
66 *
67 * @param x a real-valued input, where \f$ x \in [-1,1] \f$.
68 * @return the inverse cosine function using \f[ \text{acos}(x) = \text{atan} \left( \frac{\sqrt{1-x^2}}{x} \right) \f]
69 */
70
71 template<typename T>
72 constexpr
73 return_t<T>
74 acos(const T x)
75 noexcept
76 {
77 return internal::acos_check( static_cast<return_t<T>>(x) );
78 }
79
80 #endif
File vector/gcem/include/gcem_incl/acosh.hpp added (mode: 100644) (index 0000000..275738a)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time inverse hyperbolic cosine function
23 */
24
25 #ifndef _gcem_acosh_HPP
26 #define _gcem_acosh_HPP
27
28 namespace internal
29 {
30
31 template<typename T>
32 constexpr
33 T
34 acosh_compute(const T x)
35 noexcept
36 {
37 return( // function defined for x >= 1
38 x < T(1) ? \
39 GCLIM<T>::quiet_NaN() :
40 // indistinguishable from 1
41 GCLIM<T>::epsilon() > abs(x - T(1)) ? \
42 T(0) :
43 // else
44 log( x + sqrt(x*x - T(1)) ) );
45 }
46
47 }
48
49 /**
50 * Compile-time inverse hyperbolic cosine function
51 *
52 * @param x a real-valued input.
53 * @return the inverse hyperbolic cosine function using \f[ \text{acosh}(x) = \ln \left( x + \sqrt{x^2 - 1} \right) \f]
54 */
55
56 template<typename T>
57 constexpr
58 return_t<T>
59 acosh(const T x)
60 noexcept
61 {
62 return internal::acosh_compute( static_cast<return_t<T>>(x) );
63 }
64
65 #endif
File vector/gcem/include/gcem_incl/asin.hpp added (mode: 100644) (index 0000000..ef18173)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time arcsine function
23 */
24
25 #ifndef _gcem_asin_HPP
26 #define _gcem_asin_HPP
27
28 namespace internal
29 {
30
31 template<typename T>
32 constexpr
33 T
34 asin_compute(const T x)
35 noexcept
36 {
37 return( // only defined on [-1,1]
38 x > T(1) ? \
39 GCLIM<T>::quiet_NaN() :
40 // indistinguishable from one or zero
41 GCLIM<T>::epsilon() > abs(x - T(1)) ? \
42 T(GCEM_HALF_PI) :
43 GCLIM<T>::epsilon() > abs(x) ? \
44 T(0) :
45 // else
46 atan( x/sqrt(T(1) - x*x) ) );
47 }
48
49 template<typename T>
50 constexpr
51 T
52 asin_check(const T x)
53 noexcept
54 {
55 return( x < T(0) ? - asin_compute(-x) : asin_compute(x) );
56 }
57
58 }
59
60 /**
61 * Compile-time arcsine function
62 *
63 * @param x a real-valued input, where \f$ x \in [-1,1] \f$.
64 * @return the inverse sine function using \f[ \text{asin}(x) = \text{atan} \left( \frac{x}{\sqrt{1-x^2}} \right) \f]
65 */
66
67 template<typename T>
68 constexpr
69 return_t<T>
70 asin(const T x)
71 noexcept
72 {
73 return internal::asin_check( static_cast<return_t<T>>(x) );
74 }
75
76 #endif
File vector/gcem/include/gcem_incl/asinh.hpp added (mode: 100644) (index 0000000..5344e61)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time inverse hyperbolic sine function
23 */
24
25 #ifndef _gcem_asinh_HPP
26 #define _gcem_asinh_HPP
27
28 namespace internal
29 {
30
31 template<typename T>
32 constexpr
33 T
34 asinh_compute(const T x)
35 noexcept
36 {
37 return( // indistinguishable from zero
38 GCLIM<T>::epsilon() > abs(x) ? \
39 T(0) :
40 // else
41 log( x + sqrt(x*x + T(1)) ) );
42 }
43
44 }
45
46 /**
47 * Compile-time inverse hyperbolic sine function
48 *
49 * @param x a real-valued input.
50 * @return the inverse hyperbolic sine function using \f[ \text{asinh}(x) = \ln \left( x + \sqrt{x^2 + 1} \right) \f]
51 */
52
53 template<typename T>
54 constexpr
55 return_t<T>
56 asinh(const T x)
57 noexcept
58 {
59 return internal::asinh_compute( static_cast<return_t<T>>(x) );
60 }
61
62
63 #endif
File vector/gcem/include/gcem_incl/atan.hpp added (mode: 100644) (index 0000000..5e59a43)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time arctangent function
23 */
24
25 // see
26 // http://functions.wolfram.com/ElementaryFunctions/ArcTan/10/0001/
27 // http://functions.wolfram.com/ElementaryFunctions/ArcTan/06/01/06/01/0002/
28
29 #ifndef _gcem_atan_HPP
30 #define _gcem_atan_HPP
31
32 namespace internal
33 {
34
35 // Series
36
37 template<typename T>
38 constexpr
39 T
40 atan_series_order_calc(const T x, const T x_pow, const uint_t order)
41 noexcept
42 {
43 return( T(1)/( T((order-1)*4 - 1) * x_pow ) \
44 - T(1)/( T((order-1)*4 + 1) * x_pow*x) );
45 }
46
47 template<typename T>
48 constexpr
49 T
50 atan_series_order(const T x, const T x_pow, const uint_t order, const uint_t max_order)
51 noexcept
52 {
53 return( order == 1 ? \
54 GCEM_HALF_PI - T(1)/x + atan_series_order(x*x,pow(x,3),order+1,max_order) :
55 // NOTE: x changes to x*x for order > 1
56 order < max_order ? \
57 atan_series_order_calc(x,x_pow,order) \
58 + atan_series_order(x,x_pow*x*x,order+1,max_order) :
59 // order == max_order
60 atan_series_order_calc(x,x_pow,order) );
61 }
62
63 template<typename T>
64 constexpr
65 T
66 atan_series_main(const T x)
67 noexcept
68 {
69 return( x < T(3) ? atan_series_order(x,x,1U,10U) : // O(1/x^39)
70 x < T(4) ? atan_series_order(x,x,1U,9U) : // O(1/x^35)
71 x < T(5) ? atan_series_order(x,x,1U,8U) : // O(1/x^31)
72 x < T(7) ? atan_series_order(x,x,1U,7U) : // O(1/x^27)
73 x < T(11) ? atan_series_order(x,x,1U,6U) : // O(1/x^23)
74 x < T(25) ? atan_series_order(x,x,1U,5U) : // O(1/x^19)
75 x < T(100) ? atan_series_order(x,x,1U,4U) : // O(1/x^15)
76 x < T(1000) ? atan_series_order(x,x,1U,3U) : // O(1/x^11)
77 atan_series_order(x,x,1U,2U) ); // O(1/x^7)
78 }
79
80 // CF
81
82 template<typename T>
83 constexpr
84 T
85 atan_cf_recur(const T xx, const uint_t depth, const uint_t max_depth)
86 noexcept
87 {
88 return( depth < max_depth ? \
89 // if
90 T(2*depth - 1) + depth*depth*xx/atan_cf_recur(xx,depth+1,max_depth) :
91 // else
92 T(2*depth - 1) );
93 }
94
95 template<typename T>
96 constexpr
97 T
98 atan_cf_main(const T x)
99 noexcept
100 {
101 return( x < T(0.5) ? x/atan_cf_recur(x*x,1U, 15U ) :
102 x < T(1) ? x/atan_cf_recur(x*x,1U, 25U ) :
103 x < T(1.5) ? x/atan_cf_recur(x*x,1U, 35U ) :
104 x < T(2) ? x/atan_cf_recur(x*x,1U, 45U ) :
105 x/atan_cf_recur(x*x,1U, 52U ) );
106 }
107
108 //
109
110 template<typename T>
111 constexpr
112 T
113 atan_begin(const T x)
114 noexcept
115 {
116 return( x > T(2.5) ? atan_series_main(x) : atan_cf_main(x) );
117 }
118
119 template<typename T>
120 constexpr
121 T
122 atan_check(const T x)
123 noexcept
124 {
125 return( // indistinguishable from zero
126 GCLIM<T>::epsilon() > abs(x) ? \
127 T(0) :
128 // negative or positive
129 x < T(0) ? \
130 - atan_begin(-x) :
131 atan_begin( x) );
132 }
133
134 }
135
136 /**
137 * Compile-time arctangent function
138 *
139 * @param x a real-valued input.
140 * @return the inverse tangent function using \f[ \text{atan}(x) = \dfrac{x}{1 + \dfrac{x^2}{3 + \dfrac{4x^2}{5 + \dfrac{9x^2}{7 + \ddots}}}} \f]
141 */
142
143 template<typename T>
144 constexpr
145 return_t<T>
146 atan(const T x)
147 noexcept
148 {
149 return internal::atan_check( static_cast<return_t<T>>(x) );
150 }
151
152 #endif
File vector/gcem/include/gcem_incl/atan2.hpp added (mode: 100644) (index 0000000..30ef05d)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time two-argument arctangent function
23 */
24
25 #ifndef _gcem_atan2_HPP
26 #define _gcem_atan2_HPP
27
28 namespace internal
29 {
30
31 template<typename T>
32 constexpr
33 T
34 atan2_compute(const T y, const T x)
35 noexcept
36 {
37 return( GCLIM<T>::epsilon() > abs(x) ? \
38 //
39 GCLIM<T>::epsilon() > abs(y) ? \
40 neg_zero(y) ? \
41 neg_zero(x) ? - T(GCEM_PI) : - T(0) :
42 neg_zero(x) ? T(GCEM_PI) : T(0) :
43 y > T(0) ? \
44 T(GCEM_HALF_PI) : - T(GCEM_HALF_PI) :
45 //
46 x < T(0) ? \
47 y < T(0) ? \
48 atan(y/x) - T(GCEM_PI) :
49 atan(y/x) + T(GCEM_PI) :
50 //
51 atan(y/x) );
52 }
53
54 template<typename T1, typename T2, typename TC = common_return_t<T1,T2>>
55 constexpr
56 TC
57 atan2_type_check(const T1 y, const T2 x)
58 noexcept
59 {
60 return atan2_compute(static_cast<TC>(x),static_cast<TC>(y));
61 }
62
63 }
64
65 /**
66 * Compile-time two-argument arctangent function
67 *
68 * @param y a real-valued input.
69 * @param x a real-valued input.
70 * @return \f[ \text{atan2}(y,x) = \begin{cases} \text{atan}(y/x) & \text{ if } x > 0 \\ \text{atan}(y/x) + \pi & \text{ if } x < 0 \text{ and } y \geq 0 \\ \text{atan}(y/x) - \pi & \text{ if } x < 0 \text{ and } y < 0 \\ + \pi/2 & \text{ if } x = 0 \text{ and } y > 0 \\ - \pi/2 & \text{ if } x = 0 \text{ and } y < 0 \end{cases} \f]
71 * The function is undefined at the origin, however the following conventions are used.
72 * \f[ \text{atan2}(y,x) = \begin{cases} +0 & \text{ if } x = +0 \text{ and } y = +0 \\ -0 & \text{ if } x = +0 \text{ and } y = -0 \\ +\pi & \text{ if } x = -0 \text{ and } y = +0 \\ - \pi & \text{ if } x = -0 \text{ and } y = -0 \end{cases} \f]
73 */
74
75 template<typename T1, typename T2>
76 constexpr
77 common_return_t<T1,T2>
78 atan2(const T1 y, const T2 x)
79 noexcept
80 {
81 return internal::atan2_type_check(x,y);
82 }
83
84 #endif
File vector/gcem/include/gcem_incl/atanh.hpp added (mode: 100644) (index 0000000..57fcee2)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time inverse hyperbolic tangent function
23 */
24
25 #ifndef _gcem_atanh_HPP
26 #define _gcem_atanh_HPP
27
28 namespace internal
29 {
30
31 template<typename T>
32 constexpr
33 T
34 atanh_compute(const T x)
35 noexcept
36 {
37 return( log( (T(1) + x)/(T(1) - x) ) / T(2) );
38 }
39
40 template<typename T>
41 constexpr
42 T
43 atanh_check(const T x)
44 noexcept
45 {
46 return( // function is defined for |x| < 1
47 T(1) < abs(x) ? \
48 GCLIM<T>::quiet_NaN() :
49 GCLIM<T>::epsilon() > (T(1) - abs(x)) ? \
50 sgn(x)*GCLIM<T>::infinity() :
51 // indistinguishable from zero
52 GCLIM<T>::epsilon() > abs(x) ? \
53 T(0) :
54 // else
55 atanh_compute(x) );
56 }
57
58 }
59
60 /**
61 * Compile-time inverse hyperbolic tangent function
62 *
63 * @param x a real-valued input.
64 * @return the inverse hyperbolic tangent function using \f[ \text{atanh}(x) = \frac{1}{2} \ln \left( \frac{1+x}{1-x} \right) \f]
65 */
66
67 template<typename T>
68 constexpr
69 return_t<T>
70 atanh(const T x)
71 noexcept
72 {
73 return internal::atanh_check( static_cast<return_t<T>>(x) );
74 }
75
76 #endif
File vector/gcem/include/gcem_incl/beta.hpp added (mode: 100644) (index 0000000..53e4e2b)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #ifndef _gcem_beta_HPP
22 #define _gcem_beta_HPP
23
24 /**
25 * Compile-time beta function
26 *
27 * @param a a real-valued input.
28 * @param b a real-valued input.
29 * @return the beta function using \f[ \text{B}(\alpha,\beta) := \int_0^1 t^{\alpha - 1} (1-t)^{\beta - 1} dt = \frac{\Gamma(\alpha)\Gamma(\beta)}{\Gamma(\alpha + \beta)} \f]
30 * where \f$ \Gamma \f$ denotes the gamma function.
31 */
32
33 template<typename T1, typename T2>
34 constexpr
35 common_return_t<T1,T2>
36 beta(const T1 a, const T2 b)
37 noexcept
38 {
39 return exp( lbeta(a,b) );
40 }
41
42 #endif
File vector/gcem/include/gcem_incl/binomial_coef.hpp added (mode: 100644) (index 0000000..4f1b854)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #ifndef _gcem_binomial_coef_HPP
22 #define _gcem_binomial_coef_HPP
23
24 namespace internal
25 {
26
27 template<typename T>
28 constexpr
29 T
30 binomial_coef_recur(const T n, const T k)
31 noexcept
32 {
33 return( // edge cases
34 (k == T(0) || n == k) ? T(1) : // deals with 0 choose 0 case
35 n == T(0) ? T(0) :
36 // else
37 binomial_coef_recur(n-1,k-1) + binomial_coef_recur(n-1,k) );
38 }
39
40 template<typename T, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr>
41 constexpr
42 T
43 binomial_coef_check(const T n, const T k)
44 noexcept
45 {
46 return binomial_coef_recur(n,k);
47 }
48
49 template<typename T, typename std::enable_if<!std::is_integral<T>::value>::type* = nullptr>
50 constexpr
51 T
52 binomial_coef_check(const T n, const T k)
53 noexcept
54 {
55 return static_cast<T>(binomial_coef_recur(static_cast<ullint_t>(n),static_cast<ullint_t>(k)));
56 }
57
58 template<typename T1, typename T2, typename TC = common_t<T1,T2>>
59 constexpr
60 TC
61 binomial_coef_type_check(const T1 n, const T2 k)
62 noexcept
63 {
64 return binomial_coef_check(static_cast<TC>(n),static_cast<TC>(k));
65 }
66
67 }
68
69 /**
70 * Compile-time binomial coefficient
71 *
72 * @param n integral-valued input.
73 * @param k integral-valued input.
74 * @return computes the Binomial coefficient
75 * \f[ \binom{n}{k} = \frac{n!}{k!(n-k)!} \f]
76 * also known as '\c n choose \c k '.
77 */
78
79 template<typename T1, typename T2>
80 constexpr
81 common_t<T1,T2>
82 binomial_coef(const T1 n, const T2 k)
83 noexcept
84 {
85 return internal::binomial_coef_type_check(n,k);
86 }
87
88 #endif
File vector/gcem/include/gcem_incl/cos.hpp added (mode: 100644) (index 0000000..e69770a)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time cosine function using tan(x/2)
23 */
24
25 #ifndef _gcem_cos_HPP
26 #define _gcem_cos_HPP
27
28 namespace internal
29 {
30
31 template<typename T>
32 constexpr
33 T
34 cos_compute(const T x)
35 noexcept
36 {
37 return( T(1) - x*x)/(T(1) + x*x );
38 }
39
40 template<typename T>
41 constexpr
42 T
43 cos_check(const T x)
44 noexcept
45 {
46 return( // indistinguishable from 0
47 GCLIM<T>::epsilon() > abs(x) ?
48 T(1) :
49 // special cases: pi/2 and pi
50 GCLIM<T>::epsilon() > abs(x - T(GCEM_HALF_PI)) ? \
51 T(0) :
52 GCLIM<T>::epsilon() > abs(x + T(GCEM_HALF_PI)) ? \
53 T(0) :
54 GCLIM<T>::epsilon() > abs(x - T(GCEM_PI)) ? \
55 - T(1) :
56 GCLIM<T>::epsilon() > abs(x + T(GCEM_PI)) ? \
57 - T(1) :
58 // else
59 cos_compute( tan(x/T(2)) ) );
60 }
61
62 }
63
64 /**
65 * Compile-time cosine function
66 *
67 * @param x a real-valued input.
68 * @return the cosine function using \f[ \cos(x) = \frac{1-\tan^2(x/2)}{1+\tan^2(x/2)} \f]
69 */
70
71 template<typename T>
72 constexpr
73 return_t<T>
74 cos(const T x)
75 noexcept
76 {
77 return internal::cos_check( static_cast<return_t<T>>(x) );
78 }
79
80 #endif
File vector/gcem/include/gcem_incl/cosh.hpp added (mode: 100644) (index 0000000..aae4a91)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time hyperbolic cosine function
23 */
24
25 #ifndef _gcem_cosh_HPP
26 #define _gcem_cosh_HPP
27
28 namespace internal
29 {
30
31 template<typename T>
32 constexpr
33 T
34 cosh_compute(const T x)
35 noexcept
36 {
37 return( // indistinguishable from zero
38 GCLIM<T>::epsilon() > abs(x) ? \
39 T(1) :
40 // else
41 (exp(x) + exp(-x)) / T(2) );
42 }
43
44 }
45
46 /**
47 * Compile-time hyperbolic cosine function
48 *
49 * @param x a real-valued input.
50 * @return the hyperbolic cosine function using \f[ \cosh(x) = \frac{\exp(x) + \exp(-x)}{2} \f]
51 */
52
53 template<typename T>
54 constexpr
55 return_t<T>
56 cosh(const T x)
57 noexcept
58 {
59 return internal::cosh_compute( static_cast<return_t<T>>(x) );
60 }
61
62 #endif
File vector/gcem/include/gcem_incl/erf.hpp added (mode: 100644) (index 0000000..ccf985b)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time error function
23 */
24
25 #ifndef _gcem_erf_HPP
26 #define _gcem_erf_HPP
27
28 namespace internal
29 {
30
31 // see
32 // http://functions.wolfram.com/GammaBetaErf/Erf/10/01/0007/
33
34 template<typename T>
35 constexpr
36 T
37 erf_cf_large_recur(const T x, const int depth)
38 noexcept
39 {
40 return( depth < GCEM_ERF_MAX_ITER ? \
41 // if
42 x + 2*depth/erf_cf_large_recur(x,depth+1) :
43 // else
44 x );
45 }
46
47 template<typename T>
48 constexpr
49 T
50 erf_cf_large_main(const T x)
51 noexcept
52 {
53 return( T(1) - T(2) * ( exp(-x*x) / T(GCEM_SQRT_PI) ) \
54 / erf_cf_large_recur(T(2)*x,1) );
55 }
56
57 // see
58 // http://functions.wolfram.com/GammaBetaErf/Erf/10/01/0005/
59
60 template<typename T>
61 constexpr
62 T
63 erf_cf_small_recur(const T xx, const int depth)
64 noexcept
65 {
66 return( depth < GCEM_ERF_MAX_ITER ? \
67 // if
68 (2*depth - 1) - 2*xx \
69 + 4*depth*xx / erf_cf_small_recur(xx,depth+1) :
70 // else
71 (2*depth - 1) - 2*xx );
72 }
73
74 template<typename T>
75 constexpr
76 T
77 erf_cf_small_main(const T x)
78 noexcept
79 {
80 return( T(2) * x * ( exp(-x*x) / T(GCEM_SQRT_PI) ) \
81 / erf_cf_small_recur(x*x,1) );
82 }
83
84 //
85
86 template<typename T>
87 constexpr
88 T
89 erf_begin(const T x)
90 noexcept
91 {
92 return( x > T(2.1) ? \
93 // if
94 erf_cf_large_main(x) :
95 // else
96 erf_cf_small_main(x) );
97 }
98
99 template<typename T>
100 constexpr
101 T
102 erf_check(const T x)
103 noexcept
104 {
105 return( // indistinguishable from zero
106 GCLIM<T>::epsilon() > abs(x) ? \
107 T(0) :
108 // else
109 x < T(0) ? \
110 - erf_begin(-x) :
111 erf_begin( x) );
112 }
113
114 }
115
116 /**
117 * Compile-time Gaussian error function
118 *
119 * @param x a real-valued input.
120 * @return computes the Gaussian error function
121 * \f[ \text{erf}(x) = \frac{2}{\sqrt{\pi}} \int_0^x \exp( - t^2) dt \f]
122 * using a continued fraction representation:
123 * \f[ \text{erf}(x) = \frac{2x}{\sqrt{\pi}} \exp(-x^2) \dfrac{1}{1 - 2x^2 + \dfrac{4x^2}{3 - 2x^2 + \dfrac{8x^2}{5 - 2x^2 + \dfrac{12x^2}{7 - 2x^2 + \ddots}}}} \f]
124 */
125
126 template<typename T>
127 constexpr
128 return_t<T>
129 erf(const T x)
130 noexcept
131 {
132 return internal::erf_check( static_cast<return_t<T>>(x) );
133 }
134
135 #endif
File vector/gcem/include/gcem_incl/erf_inv.hpp added (mode: 100644) (index 0000000..dc795c1)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time inverse error function
23 *
24 * Initial approximation based on:
25 * 'Approximating the erfinv function' by Mike Giles
26 */
27
28 #ifndef _gcem_erf_inv_HPP
29 #define _gcem_erf_inv_HPP
30
31 namespace internal
32 {
33
34 template<typename T>
35 constexpr T erf_inv_decision(const T value, const T p, const T direc, const int iter_count) noexcept;
36
37 //
38 // initial value
39
40 // two cases: (1) a < 5; and (2) otherwise
41
42 template<typename T>
43 constexpr
44 T
45 erf_inv_initial_val_coef_2(const T a, const T p_term, const int order)
46 noexcept
47 {
48 return( order == 1 ? T(-0.000200214257L) :
49 order == 2 ? T( 0.000100950558L) + a*p_term :
50 order == 3 ? T( 0.00134934322L) + a*p_term :
51 order == 4 ? T(-0.003673428440L) + a*p_term :
52 order == 5 ? T( 0.005739507730L) + a*p_term :
53 order == 6 ? T(-0.00762246130L) + a*p_term :
54 order == 7 ? T( 0.009438870470L) + a*p_term :
55 order == 8 ? T( 1.001674060000L) + a*p_term :
56 order == 9 ? T( 2.83297682000L) + a*p_term :
57 p_term );
58 }
59
60 template<typename T>
61 constexpr
62 T
63 erf_inv_initial_val_case_2(const T a, const T p_term, const int order)
64 noexcept
65 {
66 return( order == 9 ? \
67 // if
68 erf_inv_initial_val_coef_2(a,p_term,order) :
69 // else
70 erf_inv_initial_val_case_2(a,erf_inv_initial_val_coef_2(a,p_term,order),order+1) );
71 }
72
73 template<typename T>
74 constexpr
75 T
76 erf_inv_initial_val_coef_1(const T a, const T p_term, const int order)
77 noexcept
78 {
79 return( order == 1 ? T( 2.81022636e-08L) :
80 order == 2 ? T( 3.43273939e-07L) + a*p_term :
81 order == 3 ? T(-3.5233877e-06L) + a*p_term :
82 order == 4 ? T(-4.39150654e-06L) + a*p_term :
83 order == 5 ? T( 0.00021858087L) + a*p_term :
84 order == 6 ? T(-0.00125372503L) + a*p_term :
85 order == 7 ? T(-0.004177681640L) + a*p_term :
86 order == 8 ? T( 0.24664072700L) + a*p_term :
87 order == 9 ? T( 1.50140941000L) + a*p_term :
88 p_term );
89 }
90
91 template<typename T>
92 constexpr
93 T
94 erf_inv_initial_val_case_1(const T a, const T p_term, const int order)
95 noexcept
96 {
97 return( order == 9 ? \
98 // if
99 erf_inv_initial_val_coef_1(a,p_term,order) :
100 // else
101 erf_inv_initial_val_case_1(a,erf_inv_initial_val_coef_1(a,p_term,order),order+1) );
102 }
103
104 template<typename T>
105 constexpr
106 T
107 erf_inv_initial_val_int(const T a)
108 noexcept
109 {
110 return( a < T(5) ? \
111 // if
112 erf_inv_initial_val_case_1(a-T(2.5),T(0),1) :
113 // else
114 erf_inv_initial_val_case_2(sqrt(a)-T(3),T(0),1) );
115 }
116
117 template<typename T>
118 constexpr
119 T
120 erf_inv_initial_val(const T x)
121 noexcept
122 {
123 return x*erf_inv_initial_val_int( -log( (T(1) - x)*(T(1) + x) ) );
124 }
125
126 //
127 // Halley recursion
128
129 template<typename T>
130 constexpr
131 T
132 erf_inv_err_val(const T value, const T p)
133 noexcept
134 { // err_val = f(x)
135 return( erf(value) - p );
136 }
137
138 template<typename T>
139 constexpr
140 T
141 erf_inv_deriv_1(const T value)
142 noexcept
143 { // derivative of the error function w.r.t. x
144 return( exp( -value*value ) );
145 }
146
147 template<typename T>
148 constexpr
149 T
150 erf_inv_deriv_2(const T value, const T deriv_1)
151 noexcept
152 { // second derivative of the error function w.r.t. x
153 return( deriv_1*( -T(2)*value ) );
154 }
155
156 template<typename T>
157 constexpr
158 T
159 erf_inv_ratio_val_1(const T value, const T p, const T deriv_1)
160 noexcept
161 {
162 return( erf_inv_err_val(value,p) / deriv_1 );
163 }
164
165 template<typename T>
166 constexpr
167 T
168 erf_inv_ratio_val_2(const T value, const T deriv_1)
169 noexcept
170 {
171 return( erf_inv_deriv_2(value,deriv_1) / deriv_1 );
172 }
173
174 template<typename T>
175 constexpr
176 T
177 erf_inv_halley(const T ratio_val_1, const T ratio_val_2)
178 noexcept
179 {
180 return( ratio_val_1 / max( T(0.8), min( T(1.2), T(1) - T(0.5)*ratio_val_1*ratio_val_2 ) ) );
181 }
182
183 template<typename T>
184 constexpr
185 T
186 erf_inv_recur(const T value, const T p, const T deriv_1, const int iter_count)
187 noexcept
188 {
189 return erf_inv_decision( value, p,
190 erf_inv_halley(erf_inv_ratio_val_1(value,p,deriv_1),
191 erf_inv_ratio_val_2(value,deriv_1)),
192 iter_count );
193 }
194
195 template<typename T>
196 constexpr
197 T
198 erf_inv_decision(const T value, const T p, const T direc, const int iter_count)
199 noexcept
200 {
201 return( iter_count < GCEM_ERF_INV_MAX_ITER ? \
202 // if
203 erf_inv_recur(value-direc,p, erf_inv_deriv_1(value), iter_count+1) :
204 // else
205 value - direc );
206 }
207
208 template<typename T>
209 constexpr
210 T
211 erf_inv_recur_begin(const T initial_val, const T p)
212 noexcept
213 {
214 return erf_inv_recur(initial_val,p,erf_inv_deriv_1(initial_val),1);
215 }
216
217 template<typename T>
218 constexpr
219 T
220 erf_inv_begin(const T p)
221 noexcept
222 {
223 return erf_inv_recur_begin(erf_inv_initial_val(p),p);
224 }
225
226 }
227
228 /**
229 * Compile-time inverse Gaussian error function
230 *
231 * @param p a real-valued input with values in the unit-interval.
232 * @return Computes the inverse Gaussian error function, a value \f$ x \f$ such that
233 * \f[ f(x) := \text{erf}(x) - p \f]
234 * is equal to zero, for a given \c p.
235 * GCE-Math finds this root using Halley's method:
236 * \f[ x_{n+1} = x_n - \frac{f(x_n)/f'(x_n)}{1 - 0.5 \frac{f(x_n)}{f'(x_n)} \frac{f''(x_n)}{f'(x_n)} } \f]
237 * where
238 * \f[ \frac{\partial}{\partial x} \text{erf}(x) = \exp(-x^2), \ \ \frac{\partial^2}{\partial x^2} \text{erf}(x) = -2x\exp(-x^2) \f]
239 */
240
241 template<typename T>
242 constexpr
243 return_t<T>
244 erf_inv(const T p)
245 noexcept
246 {
247 return internal::erf_inv_begin( static_cast<return_t<T>>(p) );
248 }
249
250
251 #endif
File vector/gcem/include/gcem_incl/exp.hpp added (mode: 100644) (index 0000000..e0adcb9)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time exponential function
23 */
24
25 #ifndef _gcem_exp_HPP
26 #define _gcem_exp_HPP
27
28 namespace internal
29 {
30
31 template<typename T>
32 constexpr
33 T
34 exp_cf_recur(const T x, const int depth)
35 noexcept
36 {
37 return( depth < GCEM_EXP_MAX_ITER_SMALL ? \
38 // if
39 depth == 1 ? \
40 T(1) - x/exp_cf_recur(x,depth+1) :
41 T(1) + x/T(depth - 1) - x/depth/exp_cf_recur(x,depth+1) :
42 // else
43 T(1) );
44 }
45
46 template<typename T>
47 constexpr
48 T
49 exp_cf(const T x)
50 noexcept
51 {
52 return( T(1)/exp_cf_recur(x,1) );
53 }
54
55 template<typename T>
56 constexpr
57 T
58 exp_split(const T x)
59 noexcept
60 {
61 return( pow_integral(GCEM_E,find_whole(x)) * exp_cf(find_fraction(x)) );
62 }
63
64 template<typename T>
65 constexpr
66 T
67 exp_check(const T x)
68 noexcept
69 {
70 return( x == GCLIM<T>::quiet_NaN() ? \
71 GCLIM<T>::quiet_NaN() :
72 //
73 x == - GCLIM<T>::infinity() ? \
74 T(0) :
75 //
76 GCLIM<T>::epsilon() > abs(x) ? \
77 T(1) :
78 //
79 x == GCLIM<T>::infinity() ? \
80 GCLIM<T>::infinity() :
81 //
82 abs(x) < T(2) ? \
83 exp_cf(x) : \
84 exp_split(x) );
85 }
86
87 }
88
89 /**
90 * Compile-time exponential function
91 *
92 * @param x a real-valued input.
93 * @return \f$ \exp(x) \f$ using \f[ \exp(x) = \dfrac{1}{1-\dfrac{x}{1+x-\dfrac{\frac{1}{2}x}{1 + \frac{1}{2}x - \dfrac{\frac{1}{3}x}{1 + \frac{1}{3}x - \ddots}}}} \f]
94 * The continued fraction argument is split into two parts: \f$ x = n + r \f$, where \f$ n \f$ is an integer and \f$ r \in [-0.5,0.5] \f$.
95 */
96
97 template<typename T>
98 constexpr
99 return_t<T>
100 exp(const T x)
101 noexcept
102 {
103 return internal::exp_check( static_cast<return_t<T>>(x) );
104 }
105
106 #endif
File vector/gcem/include/gcem_incl/expm1.hpp added (mode: 100644) (index 0000000..d780ee4)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time exponential function
23 */
24
25 #ifndef _gcem_expm1_HPP
26 #define _gcem_expm1_HPP
27
28 namespace internal
29 {
30
31 template<typename T>
32 constexpr
33 T
34 expm1_compute(const T x)
35 noexcept
36 {
37 // return x * ( T(1) + x * ( T(1)/T(2) + x * ( T(1)/T(6) + x * ( T(1)/T(24) + x/T(120) ) ) ) ); // O(x^6)
38 return x + x * ( x/T(2) + x * ( x/T(6) + x * ( x/T(24) + x*x/T(120) ) ) ); // O(x^6)
39 }
40
41 template<typename T>
42 constexpr
43 T
44 expm1_check(const T x)
45 noexcept
46 {
47 return( abs(x) > T(1e-04) ? \
48 // if
49 exp(x) - T(1) :
50 // else
51 expm1_compute(x) );
52 }
53
54 }
55
56 /**
57 * Compile-time exponential-minus-1 function
58 *
59 * @param x a real-valued input.
60 * @return \f$ \exp(x) - 1 \f$ using \f[ \exp(x) = \sum_{k=0}^\infty \dfrac{x^k}{k!} \f]
61 */
62
63 template<typename T>
64 constexpr
65 return_t<T>
66 expm1(const T x)
67 noexcept
68 {
69 return internal::expm1_check( static_cast<return_t<T>>(x) );
70 }
71
72 #endif
File vector/gcem/include/gcem_incl/factorial.hpp added (mode: 100644) (index 0000000..dd86549)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time factorial function
23 */
24
25 #ifndef _gcem_factorial_HPP
26 #define _gcem_factorial_HPP
27
28 namespace internal
29 {
30
31 // T should be int, long int, unsigned int, etc.
32
33 template<typename T>
34 constexpr
35 T
36 factorial_table(const T x)
37 noexcept
38 { // table for x! when x = {2,...,16}
39 return( x == T(2) ? T(2) : x == T(3) ? T(6) :
40 x == T(4) ? T(24) : x == T(5) ? T(120) :
41 x == T(6) ? T(720) : x == T(7) ? T(5040) :
42 x == T(8) ? T(40320) : x == T(9) ? T(362880) :
43 //
44 x == T(10) ? T(3628800) :
45 x == T(11) ? T(39916800) :
46 x == T(12) ? T(479001600) :
47 x == T(13) ? T(6227020800) :
48 x == T(14) ? T(87178291200) :
49 x == T(15) ? T(1307674368000) :
50 T(20922789888000) );
51 }
52
53 template<typename T, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr>
54 constexpr
55 T
56 factorial_recur(const T x)
57 noexcept
58 {
59 return( x == T(0) ? T(1) :
60 x == T(1) ? x :
61 //
62 x < T(17) ? \
63 // if
64 factorial_table(x) :
65 // else
66 x*factorial_recur(x-1) );
67 }
68
69 template<typename T, typename std::enable_if<!std::is_integral<T>::value>::type* = nullptr>
70 constexpr
71 T
72 factorial_recur(const T x)
73 noexcept
74 {
75 return tgamma(x + 1);
76 }
77
78 }
79
80 /**
81 * Compile-time factorial function
82 *
83 * @param x a real-valued input.
84 * @return Computes the factorial value \f$ x! \f$.
85 * When \c x is an integral type (\c int, <tt>long int</tt>, etc.), a simple recursion method is used, along with table values.
86 * When \c x is real-valued, <tt>factorial(x) = tgamma(x+1)</tt>.
87 */
88
89 template<typename T>
90 constexpr
91 T
92 factorial(const T x)
93 noexcept
94 {
95 return internal::factorial_recur(x);
96 }
97
98 #endif
File vector/gcem/include/gcem_incl/find_exponent.hpp added (mode: 100644) (index 0000000..293cc8d)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time find_exponent function
23 */
24
25 #ifndef _gcem_find_exponent_HPP
26 #define _gcem_find_exponent_HPP
27
28 namespace internal
29 {
30
31 template<typename T>
32 constexpr
33 llint_t
34 find_exponent(const T x, const llint_t exponent)
35 noexcept
36 {
37 return( x < T(1) ? \
38 find_exponent(x*T(10),exponent - llint_t(1)) :
39 x > T(10) ? \
40 find_exponent(x/T(10),exponent + llint_t(1)) :
41 // else
42 exponent );
43 }
44
45 }
46
47 #endif
File vector/gcem/include/gcem_incl/find_fraction.hpp added (mode: 100644) (index 0000000..149d659)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * find the fraction part of x = n + r, where -0.5 < r < 0.5
23 */
24
25 #ifndef _gcem_find_fraction_HPP
26 #define _gcem_find_fraction_HPP
27
28 namespace internal
29 {
30
31 template<typename T>
32 constexpr
33 T
34 find_fraction(const T x)
35 noexcept
36 {
37 return( abs(x - internal::floor(x)) > T(0.5) ? \
38 // if
39 x - internal::floor(x) - sgn(x) :
40 //else
41 x - internal::floor(x) );
42 }
43
44 }
45
46 #endif
File vector/gcem/include/gcem_incl/find_whole.hpp added (mode: 100644) (index 0000000..90e3c4f)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * find the whole number part of x = n + r, where -0.5 < r < 0.5
23 */
24
25 #ifndef _gcem_find_whole_HPP
26 #define _gcem_find_whole_HPP
27
28 namespace internal
29 {
30
31 template<typename T>
32 constexpr
33 llint_t
34 find_whole(const T x)
35 noexcept
36 {
37 return( abs(x - internal::floor(x)) > T(0.5) ? \
38 // if
39 static_cast<llint_t>(internal::floor(x) + sgn(x)) :
40 // else
41 static_cast<llint_t>(internal::floor(x)) );
42 }
43
44 }
45
46 #endif
File vector/gcem/include/gcem_incl/floor.hpp added (mode: 100644) (index 0000000..a675488)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #ifndef _gcem_floor_HPP
22 #define _gcem_floor_HPP
23
24 namespace internal
25 {
26
27 template<typename T>
28 constexpr
29 T
30 floor(const T x)
31 noexcept
32 {
33 return T(static_cast<llint_t>(x));
34 }
35
36 }
37
38 #endif
File vector/gcem/include/gcem_incl/gcd.hpp added (mode: 100644) (index 0000000..4961078)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #ifndef _gcem_gcd_HPP
22 #define _gcem_gcd_HPP
23
24 namespace internal
25 {
26
27 template<typename T>
28 constexpr
29 T
30 gcd_recur(const T a, const T b)
31 noexcept
32 {
33 return( b == T(0) ? a : gcd_recur(b, a % b) );
34 }
35
36 template<typename T, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr>
37 constexpr
38 T
39 gcd_int_check(const T a, const T b)
40 noexcept
41 {
42 return gcd_recur(a,b);
43 }
44
45 template<typename T, typename std::enable_if<!std::is_integral<T>::value>::type* = nullptr>
46 constexpr
47 T
48 gcd_int_check(const T a, const T b)
49 noexcept
50 {
51 return gcd_recur( static_cast<ullint_t>(a), static_cast<ullint_t>(b) );
52 }
53
54 template<typename T1, typename T2, typename TC = common_t<T1,T2>>
55 constexpr
56 TC
57 gcd_type_check(const T1 a, const T2 b)
58 noexcept
59 {
60 return gcd_int_check( static_cast<TC>(abs(a)), static_cast<TC>(abs(b)) );
61 }
62
63 }
64
65 /**
66 * Compile-time greatest common divisor (GCD) function
67 *
68 * @param a integral-valued input.
69 * @param b integral-valued input.
70 * @return the greatest common divisor between integers \c a and \c b using a Euclidean algorithm.
71 */
72
73 template<typename T1, typename T2>
74 constexpr
75 common_t<T1,T2>
76 gcd(const T1 a, const T2 b)
77 noexcept
78 {
79 return internal::gcd_type_check(a,b);
80 }
81
82 #endif
File vector/gcem/include/gcem_incl/gcem_options.hpp added (mode: 100644) (index 0000000..17d0941)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include <cstddef> // size_t
22 #include <limits>
23 #include <type_traits>
24
25 //
26 // version
27
28 #ifndef GCEM_VERSION_MAJOR
29 #define GCEM_VERSION_MAJOR 1
30 #endif
31
32 #ifndef GCEM_VERSION_MINOR
33 #define GCEM_VERSION_MINOR 10
34 #endif
35
36 #ifndef GCEM_VERSION_PATCH
37 #define GCEM_VERSION_PATCH 0
38 #endif
39
40 //
41 // types
42
43 namespace gcem
44 {
45 using uint_t = unsigned int;
46 using ullint_t = unsigned long long int;
47
48 using llint_t = long long int;
49
50 template<class T>
51 using GCLIM = std::numeric_limits<T>;
52
53 template<typename T>
54 using return_t = typename std::conditional<std::is_integral<T>::value,double,T>::type;
55
56 template<typename ...T>
57 using common_t = typename std::common_type<T...>::type;
58
59 template<typename ...T>
60 using common_return_t = return_t<common_t<T...>>;
61 }
62
63 //
64 // constants
65
66 #ifndef GCEM_LOG_2
67 #define GCEM_LOG_2 0.6931471805599453094172321214581765680755L
68 #endif
69
70 #ifndef GCEM_LOG_10
71 #define GCEM_LOG_10 2.3025850929940456840179914546843642076011L
72 #endif
73
74 #ifndef GCEM_PI
75 #define GCEM_PI 3.1415926535897932384626433832795028841972L
76 #endif
77
78 #ifndef GCEM_LOG_PI
79 #define GCEM_LOG_PI 1.1447298858494001741434273513530587116473L
80 #endif
81
82 #ifndef GCEM_LOG_2PI
83 #define GCEM_LOG_2PI 1.8378770664093454835606594728112352797228L
84 #endif
85
86 #ifndef GCEM_LOG_SQRT_2PI
87 #define GCEM_LOG_SQRT_2PI 0.9189385332046727417803297364056176398614L
88 #endif
89
90 #ifndef GCEM_SQRT_2
91 #define GCEM_SQRT_2 1.4142135623730950488016887242096980785697L
92 #endif
93
94 #ifndef GCEM_HALF_PI
95 #define GCEM_HALF_PI 1.5707963267948966192313216916397514420986L
96 #endif
97
98 #ifndef GCEM_SQRT_PI
99 #define GCEM_SQRT_PI 1.7724538509055160272981674833411451827975L
100 #endif
101
102 #ifndef GCEM_SQRT_HALF_PI
103 #define GCEM_SQRT_HALF_PI 1.2533141373155002512078826424055226265035L
104 #endif
105
106 #ifndef GCEM_E
107 #define GCEM_E 2.7182818284590452353602874713526624977572L
108 #endif
109
110 //
111 // convergence settings
112
113 #ifndef GCEM_ERF_MAX_ITER
114 #define GCEM_ERF_MAX_ITER 60
115 #endif
116
117 #ifndef GCEM_ERF_INV_MAX_ITER
118 #define GCEM_ERF_INV_MAX_ITER 55
119 #endif
120
121 #ifndef GCEM_EXP_MAX_ITER_SMALL
122 #define GCEM_EXP_MAX_ITER_SMALL 25
123 #endif
124
125 // #ifndef GCEM_LOG_TOL
126 // #define GCEM_LOG_TOL 1E-14
127 // #endif
128
129 #ifndef GCEM_LOG_MAX_ITER_SMALL
130 #define GCEM_LOG_MAX_ITER_SMALL 25
131 #endif
132
133 #ifndef GCEM_LOG_MAX_ITER_BIG
134 #define GCEM_LOG_MAX_ITER_BIG 255
135 #endif
136
137 #ifndef GCEM_INCML_BETA_TOL
138 #define GCEM_INCML_BETA_TOL 1E-15
139 #endif
140
141 #ifndef GCEM_INCML_BETA_MAX_ITER
142 #define GCEM_INCML_BETA_MAX_ITER 205
143 #endif
144
145 #ifndef GCEM_INCML_BETA_INV_MAX_ITER
146 #define GCEM_INCML_BETA_INV_MAX_ITER 35
147 #endif
148
149 #ifndef GCEM_INCML_GAMMA_MAX_ITER
150 #define GCEM_INCML_GAMMA_MAX_ITER 55
151 #endif
152
153 #ifndef GCEM_INCML_GAMMA_INV_MAX_ITER
154 #define GCEM_INCML_GAMMA_INV_MAX_ITER 35
155 #endif
156
157 #ifndef GCEM_SQRT_MAX_ITER
158 #define GCEM_SQRT_MAX_ITER 100
159 #endif
160
161 #ifndef GCEM_TAN_MAX_ITER
162 #define GCEM_TAN_MAX_ITER 35
163 #endif
164
165 #ifndef GCEM_TANH_MAX_ITER
166 #define GCEM_TANH_MAX_ITER 35
167 #endif
168
169 //
170 // Macros
171
172 #ifdef _MSC_VER
173 #ifndef GCEM_SIGNBIT
174 #define GCEM_SIGNBIT(x) _signbit(x)
175 #endif
176 #ifndef GCEM_COPYSIGN
177 #define GCEM_COPYSIGN(x,y) _copysign(x,y)
178 #endif
179 #else
180 #ifndef GCEM_SIGNBIT
181 #define GCEM_SIGNBIT(x) __builtin_signbit(x)
182 #endif
183 #ifndef GCEM_COPYSIGN
184 #define GCEM_COPYSIGN(x,y) __builtin_copysign(x,y)
185 #endif
186 #endif
File vector/gcem/include/gcem_incl/incomplete_beta.hpp added (mode: 100644) (index 0000000..802a85b)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time incomplete beta function
23 *
24 * see eq. 18.5.17a in the Handbook of Continued Fractions for Special Functions
25 */
26
27 #ifndef _gcem_incomplete_beta_HPP
28 #define _gcem_incomplete_beta_HPP
29
30 namespace internal
31 {
32
33 template<typename T>
34 constexpr T incomplete_beta_cf(const T a, const T b, const T z, const T c_j, const T d_j, const T f_j, const int depth) noexcept;
35
36 //
37 // coefficients; see eq. 18.5.17b
38
39 template<typename T>
40 constexpr
41 T
42 incomplete_beta_coef_even(const T a, const T b, const T z, const int k)
43 noexcept
44 {
45 return( -z*(a + k)*(a + b + k)/( (a + 2*k)*(a + 2*k + T(1)) ) );
46 }
47
48 template<typename T>
49 constexpr
50 T
51 incomplete_beta_coef_odd(const T a, const T b, const T z, const int k)
52 noexcept
53 {
54 return( z*k*(b - k)/((a + 2*k - T(1))*(a + 2*k)) );
55 }
56
57 template<typename T>
58 constexpr
59 T
60 incomplete_beta_coef(const T a, const T b, const T z, const int depth)
61 noexcept
62 {
63 return( !is_odd(depth) ? incomplete_beta_coef_even(a,b,z,depth/2) :
64 incomplete_beta_coef_odd(a,b,z,(depth+1)/2) );
65 }
66
67 //
68 // update formulae for the modified Lentz method
69
70 template<typename T>
71 constexpr
72 T
73 incomplete_beta_c_update(const T a, const T b, const T z, const T c_j, const int depth)
74 noexcept
75 {
76 return( T(1) + incomplete_beta_coef(a,b,z,depth)/c_j );
77 }
78
79 template<typename T>
80 constexpr
81 T
82 incomplete_beta_d_update(const T a, const T b, const T z, const T d_j, const int depth)
83 noexcept
84 {
85 return( T(1) / (T(1) + incomplete_beta_coef(a,b,z,depth)*d_j) );
86 }
87
88 //
89 // convergence-type condition
90
91 template<typename T>
92 constexpr
93 T
94 incomplete_beta_decision(const T a, const T b, const T z, const T c_j, const T d_j, const T f_j, const int depth)
95 noexcept
96 {
97 return( // tolerance check
98 abs(c_j*d_j - T(1)) < GCEM_INCML_BETA_TOL ? f_j*c_j*d_j :
99 // max_iter check
100 depth < GCEM_INCML_BETA_MAX_ITER ? \
101 // if
102 incomplete_beta_cf(a,b,z,c_j,d_j,f_j*c_j*d_j,depth+1) :
103 // else
104 f_j*c_j*d_j );
105 }
106
107 template<typename T>
108 constexpr
109 T
110 incomplete_beta_cf(const T a, const T b, const T z, const T c_j, const T d_j, const T f_j, const int depth)
111 noexcept
112 {
113 return incomplete_beta_decision(a,b,z,
114 incomplete_beta_c_update(a,b,z,c_j,depth),
115 incomplete_beta_d_update(a,b,z,d_j,depth),
116 f_j,depth);
117 }
118
119 //
120 // x^a (1-x)^{b} / (a beta(a,b)) * cf
121
122 template<typename T>
123 constexpr
124 T
125 incomplete_beta_begin(const T a, const T b, const T z)
126 noexcept
127 {
128 return ( (exp(a*log(z) + b*log(T(1)-z) - lbeta(a,b)) / a) * \
129 incomplete_beta_cf(a,b,z,T(1),
130 incomplete_beta_d_update(a,b,z,T(1),0),
131 incomplete_beta_d_update(a,b,z,T(1),0),1)
132 );
133 }
134
135 template<typename T>
136 constexpr
137 T
138 incomplete_beta_check(const T a, const T b, const T z)
139 noexcept
140 {
141 return( // indistinguishable from zero
142 GCLIM<T>::epsilon() > z ? \
143 T(0) :
144 // parameter check for performance
145 (a + T(1))/(a + b + T(2)) > z ? \
146 incomplete_beta_begin(a,b,z) :
147 T(1) - incomplete_beta_begin(b,a,T(1) - z) );
148 }
149
150 template<typename T1, typename T2, typename T3, typename TC = common_return_t<T1,T2,T3>>
151 constexpr
152 TC
153 incomplete_beta_type_check(const T1 a, const T2 b, const T3 p)
154 noexcept
155 {
156 return incomplete_beta_check(static_cast<TC>(a),
157 static_cast<TC>(b),
158 static_cast<TC>(p));
159 }
160
161 }
162
163 /**
164 * Compile-time regularized incomplete beta function
165 *
166 * @param a a real-valued, non-negative input.
167 * @param b a real-valued, non-negative input.
168 * @param z a real-valued, non-negative input.
169 *
170 * @return computes the regularized incomplete beta function,
171 * \f[ \frac{\text{B}(z;\alpha,\beta)}{\text{B}(\alpha,\beta)} = \frac{1}{\text{B}(\alpha,\beta)}\int_0^z t^{a-1} (1-t)^{\beta-1} dt \f]
172 * using a continued fraction representation, found in the Handbook of Continued Fractions for Special Functions, and a modified Lentz method.
173 * \f[ \frac{\text{B}(z;\alpha,\beta)}{\text{B}(\alpha,\beta)} = \frac{z^{\alpha} (1-t)^{\beta}}{\alpha \text{B}(\alpha,\beta)} \dfrac{a_1}{1 + \dfrac{a_2}{1 + \dfrac{a_3}{1 + \dfrac{a_4}{1 + \ddots}}}} \f]
174 * where \f$ a_1 = 1 \f$ and
175 * \f[ a_{2m+2} = - \frac{(\alpha + m)(\alpha + \beta + m)}{(\alpha + 2m)(\alpha + 2m + 1)}, \ m \geq 0 \f]
176 * \f[ a_{2m+1} = \frac{m(\beta - m)}{(\alpha + 2m - 1)(\alpha + 2m)}, \ m \geq 1 \f]
177 * The Lentz method works as follows: let \f$ f_j \f$ denote the value of the continued fraction up to the first \f$ j \f$ terms; \f$ f_j \f$ is updated as follows:
178 * \f[ c_j = 1 + a_j / c_{j-1}, \ \ d_j = 1 / (1 + a_j d_{j-1}) \f]
179 * \f[ f_j = c_j d_j f_{j-1} \f]
180 */
181
182 template<typename T1, typename T2, typename T3>
183 constexpr
184 common_return_t<T1,T2,T3>
185 incomplete_beta(const T1 a, const T2 b, const T3 z)
186 noexcept
187 {
188 return internal::incomplete_beta_type_check(a,b,z);
189 }
190
191 #endif
File vector/gcem/include/gcem_incl/incomplete_beta_inv.hpp added (mode: 100644) (index 0000000..b1ad0fb)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * inverse of the incomplete beta function
23 */
24
25 #ifndef _gcem_incomplete_beta_inv_HPP
26 #define _gcem_incomplete_beta_inv_HPP
27
28 namespace internal
29 {
30
31 template<typename T>
32 constexpr T incomplete_beta_inv_decision(const T value, const T alpha_par, const T beta_par, const T p,
33 const T direc, const T lb_val, const int iter_count) noexcept;
34
35 //
36 // initial value for Halley
37
38 //
39 // a,b > 1 case
40
41 template<typename T>
42 constexpr
43 T
44 incomplete_beta_inv_initial_val_1_tval(const T p)
45 noexcept
46 { // a > 1.0
47 return( p > T(0.5) ? \
48 // if
49 sqrt(-T(2)*log(T(1) - p)) :
50 // else
51 sqrt(-T(2)*log(p)) );
52 }
53
54 template<typename T>
55 constexpr
56 T
57 incomplete_beta_inv_initial_val_1_int_begin(const T t_val)
58 noexcept
59 { // internal for a > 1.0
60 return( t_val - ( T(2.515517) + T(0.802853)*t_val + T(0.010328)*t_val*t_val ) \
61 / ( T(1) + T(1.432788)*t_val + T(0.189269)*t_val*t_val + T(0.001308)*t_val*t_val*t_val ) );
62 }
63
64 template<typename T>
65 constexpr
66 T
67 incomplete_beta_inv_initial_val_1_int_ab1(const T alpha_par, const T beta_par)
68 noexcept
69 {
70 return( T(1)/(2*alpha_par - T(1)) + T(1)/(2*beta_par - T(1)) );
71 }
72
73 template<typename T>
74 constexpr
75 T
76 incomplete_beta_inv_initial_val_1_int_ab2(const T alpha_par, const T beta_par)
77 noexcept
78 {
79 return( T(1)/(2*beta_par - T(1)) - T(1)/(2*alpha_par - T(1)) );
80 }
81
82 template<typename T>
83 constexpr
84 T
85 incomplete_beta_inv_initial_val_1_int_h(const T ab_term_1)
86 noexcept
87 {
88 return( T(2) / ab_term_1 );
89 }
90
91 template<typename T>
92 constexpr
93 T
94 incomplete_beta_inv_initial_val_1_int_w(const T value, const T ab_term_2, const T h_term)
95 noexcept
96 {
97 // return( value * sqrt(h_term + lambda)/h_term - ab_term_2*(lambda + 5.0/6.0 -2.0/(3.0*h_term)) );
98 return( value * sqrt(h_term + (value*value - T(3))/T(6))/h_term \
99 - ab_term_2*((value*value - T(3))/T(6) + T(5)/T(6) - T(2)/(T(3)*h_term)) );
100 }
101
102 template<typename T>
103 constexpr
104 T
105 incomplete_beta_inv_initial_val_1_int_end(const T alpha_par, const T beta_par, const T w_term)
106 noexcept
107 {
108 return( alpha_par / (alpha_par + beta_par*exp(2*w_term)) );
109 }
110
111 template<typename T>
112 constexpr
113 T
114 incomplete_beta_inv_initial_val_1(const T alpha_par, const T beta_par, const T t_val, const T sgn_term)
115 noexcept
116 { // a > 1.0
117 return incomplete_beta_inv_initial_val_1_int_end( alpha_par, beta_par,
118 incomplete_beta_inv_initial_val_1_int_w(
119 sgn_term*incomplete_beta_inv_initial_val_1_int_begin(t_val),
120 incomplete_beta_inv_initial_val_1_int_ab2(alpha_par,beta_par),
121 incomplete_beta_inv_initial_val_1_int_h(
122 incomplete_beta_inv_initial_val_1_int_ab1(alpha_par,beta_par)
123 )
124 )
125 );
126 }
127
128 //
129 // a,b else
130
131 template<typename T>
132 constexpr
133 T
134 incomplete_beta_inv_initial_val_2_s1(const T alpha_par, const T beta_par)
135 noexcept
136 {
137 return( pow(alpha_par/(alpha_par+beta_par),alpha_par) / alpha_par );
138 }
139
140 template<typename T>
141 constexpr
142 T
143 incomplete_beta_inv_initial_val_2_s2(const T alpha_par, const T beta_par)
144 noexcept
145 {
146 return( pow(beta_par/(alpha_par+beta_par),beta_par) / beta_par );
147 }
148
149 template<typename T>
150 constexpr
151 T
152 incomplete_beta_inv_initial_val_2(const T alpha_par, const T beta_par, const T p, const T s_1, const T s_2)
153 noexcept
154 {
155 return( p <= s_1/(s_1 + s_2) ? pow(p*(s_1+s_2)*alpha_par,T(1)/alpha_par) :
156 T(1) - pow(p*(s_1+s_2)*beta_par,T(1)/beta_par) );
157 }
158
159 // initial value
160
161 template<typename T>
162 constexpr
163 T
164 incomplete_beta_inv_initial_val(const T alpha_par, const T beta_par, const T p)
165 noexcept
166 {
167 return( (alpha_par > T(1) && beta_par > T(1)) ?
168 // if
169 incomplete_beta_inv_initial_val_1(alpha_par,beta_par,
170 incomplete_beta_inv_initial_val_1_tval(p),
171 p < T(0.5) ? T(1) : T(-1) ) :
172 // else
173 p > T(0.5) ?
174 // if
175 T(1) - incomplete_beta_inv_initial_val_2(beta_par,alpha_par,T(1) - p,
176 incomplete_beta_inv_initial_val_2_s1(beta_par,alpha_par),
177 incomplete_beta_inv_initial_val_2_s2(beta_par,alpha_par)) :
178 // else
179 incomplete_beta_inv_initial_val_2(alpha_par,beta_par,p,
180 incomplete_beta_inv_initial_val_2_s1(alpha_par,beta_par),
181 incomplete_beta_inv_initial_val_2_s2(alpha_par,beta_par))
182 );
183 }
184
185 //
186 // Halley recursion
187
188 template<typename T>
189 constexpr
190 T
191 incomplete_beta_inv_err_val(const T value, const T alpha_par, const T beta_par, const T p)
192 noexcept
193 { // err_val = f(x)
194 return( incomplete_beta(alpha_par,beta_par,value) - p );
195 }
196
197 template<typename T>
198 constexpr
199 T
200 incomplete_beta_inv_deriv_1(const T value, const T alpha_par, const T beta_par, const T lb_val)
201 noexcept
202 { // derivative of the incomplete beta function w.r.t. x
203 return( // indistinguishable from zero or one
204 GCLIM<T>::epsilon() > abs(value) ? \
205 T(0) :
206 GCLIM<T>::epsilon() > abs(T(1) - value) ? \
207 T(0) :
208 // else
209 exp( (alpha_par - T(1))*log(value) + (beta_par - T(1))*log(T(1) - value) - lb_val ) );
210 }
211
212 template<typename T>
213 constexpr
214 T
215 incomplete_beta_inv_deriv_2(const T value, const T alpha_par, const T beta_par, const T deriv_1)
216 noexcept
217 { // second derivative of the incomplete beta function w.r.t. x
218 return( deriv_1*((alpha_par - T(1))/value - (beta_par - T(1))/(T(1) - value)) );
219 }
220
221 template<typename T>
222 constexpr
223 T
224 incomplete_beta_inv_ratio_val_1(const T value, const T alpha_par, const T beta_par, const T p, const T deriv_1)
225 noexcept
226 {
227 return( incomplete_beta_inv_err_val(value,alpha_par,beta_par,p) / deriv_1 );
228 }
229
230 template<typename T>
231 constexpr
232 T
233 incomplete_beta_inv_ratio_val_2(const T value, const T alpha_par, const T beta_par, const T deriv_1)
234 noexcept
235 {
236 return( incomplete_beta_inv_deriv_2(value,alpha_par,beta_par,deriv_1) / deriv_1 );
237 }
238
239 template<typename T>
240 constexpr
241 T
242 incomplete_beta_inv_halley(const T ratio_val_1, const T ratio_val_2)
243 noexcept
244 {
245 return( ratio_val_1 / max( T(0.8), min( T(1.2), T(1) - T(0.5)*ratio_val_1*ratio_val_2 ) ) );
246 }
247
248 template<typename T>
249 constexpr
250 T
251 incomplete_beta_inv_recur(const T value, const T alpha_par, const T beta_par, const T p, const T deriv_1,
252 const T lb_val, const int iter_count)
253 noexcept
254 {
255 return( // derivative = 0
256 GCLIM<T>::epsilon() > abs(deriv_1) ? \
257 incomplete_beta_inv_decision( value, alpha_par, beta_par, p, T(0), lb_val,
258 GCEM_INCML_BETA_INV_MAX_ITER+1) :
259 // else
260 incomplete_beta_inv_decision( value, alpha_par, beta_par, p,
261 incomplete_beta_inv_halley(
262 incomplete_beta_inv_ratio_val_1(value,alpha_par,beta_par,p,deriv_1),
263 incomplete_beta_inv_ratio_val_2(value,alpha_par,beta_par,deriv_1)
264 ), lb_val, iter_count) );
265 }
266
267 template<typename T>
268 constexpr
269 T
270 incomplete_beta_inv_decision(const T value, const T alpha_par, const T beta_par, const T p, const T direc,
271 const T lb_val, const int iter_count)
272 noexcept
273 {
274 return( iter_count <= GCEM_INCML_BETA_INV_MAX_ITER ?
275 // if
276 incomplete_beta_inv_recur(value-direc,alpha_par,beta_par,p,
277 incomplete_beta_inv_deriv_1(value,alpha_par,beta_par,lb_val),
278 lb_val, iter_count+1) :
279 // else
280 value - direc );
281 }
282
283 template<typename T>
284 constexpr
285 T
286 incomplete_beta_inv_begin(const T initial_val, const T alpha_par, const T beta_par, const T p, const T lb_val)
287 noexcept
288 {
289 return incomplete_beta_inv_recur(initial_val,alpha_par,beta_par,p,
290 incomplete_beta_inv_deriv_1(initial_val,alpha_par,beta_par,lb_val),
291 lb_val,1);
292 }
293
294 template<typename T>
295 constexpr
296 T
297 incomplete_beta_inv_check(const T alpha_par, const T beta_par, const T p)
298 noexcept
299 {
300 return( // indistinguishable from zero or one
301 GCLIM<T>::epsilon() > p ? \
302 T(0) :
303 GCLIM<T>::epsilon() > abs(T(1) - p) ? \
304 T(1) :
305 // else
306 incomplete_beta_inv_begin(incomplete_beta_inv_initial_val(alpha_par,beta_par,p),
307 alpha_par,beta_par,p,lbeta(alpha_par,beta_par)) );
308 }
309
310 template<typename T1, typename T2, typename T3, typename TC = common_t<T1,T2,T3>>
311 constexpr
312 TC
313 incomplete_beta_inv_type_check(const T1 a, const T2 b, const T3 p)
314 noexcept
315 {
316 return incomplete_beta_inv_check(static_cast<TC>(a),
317 static_cast<TC>(b),
318 static_cast<TC>(p));
319 }
320
321 }
322
323 /**
324 * Compile-time inverse incomplete beta function
325 *
326 * @param a a real-valued, non-negative input.
327 * @param b a real-valued, non-negative input.
328 * @param p a real-valued input with values in the unit-interval.
329 *
330 * @return Computes the inverse incomplete beta function, a value \f$ x \f$ such that
331 * \f[ f(x) := \frac{\text{B}(x;\alpha,\beta)}{\text{B}(\alpha,\beta)} - p \f]
332 * equal to zero, for a given \c p.
333 * GCE-Math finds this root using Halley's method:
334 * \f[ x_{n+1} = x_n - \frac{f(x_n)/f'(x_n)}{1 - 0.5 \frac{f(x_n)}{f'(x_n)} \frac{f''(x_n)}{f'(x_n)} } \f]
335 * where
336 * \f[ \frac{\partial}{\partial x} \left(\frac{\text{B}(x;\alpha,\beta)}{\text{B}(\alpha,\beta)}\right) = \frac{1}{\text{B}(\alpha,\beta)} x^{\alpha-1} (1-x)^{\beta-1} \f]
337 * \f[ \frac{\partial^2}{\partial x^2} \left(\frac{\text{B}(x;\alpha,\beta)}{\text{B}(\alpha,\beta)}\right) = \frac{1}{\text{B}(\alpha,\beta)} x^{\alpha-1} (1-x)^{\beta-1} \left( \frac{\alpha-1}{x} - \frac{\beta-1}{1 - x} \right) \f]
338 */
339
340 template<typename T1, typename T2, typename T3>
341 constexpr
342 common_t<T1,T2,T3>
343 incomplete_beta_inv(const T1 a, const T2 b, const T3 p)
344 noexcept
345 {
346 return internal::incomplete_beta_inv_type_check(a,b,p);
347 }
348
349 #endif
File vector/gcem/include/gcem_incl/incomplete_gamma.hpp added (mode: 100644) (index 0000000..94aa3d8)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time (regularized) incomplete gamma function
23 */
24
25 #ifndef _gcem_incomplete_gamma_HPP
26 #define _gcem_incomplete_gamma_HPP
27
28 namespace internal
29 {
30
31 // 50 point Gauss-Legendre quadrature
32
33 template<typename T>
34 constexpr
35 T
36 incomplete_gamma_quad_inp_vals(const T lb, const T ub, const int counter)
37 noexcept
38 {
39 return (ub-lb) * gauss_legendre_50_points[counter] / T(2) + (ub + lb) / T(2);
40 }
41
42 template<typename T>
43 constexpr
44 T
45 incomplete_gamma_quad_weight_vals(const T lb, const T ub, const int counter)
46 noexcept
47 {
48 return (ub-lb) * gauss_legendre_50_weights[counter] / T(2);
49 }
50
51 template<typename T>
52 constexpr
53 T
54 incomplete_gamma_quad_fn(const T x, const T a, const T lg_term)
55 noexcept
56 {
57 return exp( -x + (a-T(1))*log(x) - lg_term );
58 }
59
60 template<typename T>
61 constexpr
62 T
63 incomplete_gamma_quad_recur(const T lb, const T ub, const T a, const T lg_term, const int counter)
64 noexcept
65 {
66 return( counter < 49 ? \
67 // if
68 incomplete_gamma_quad_fn(incomplete_gamma_quad_inp_vals(lb,ub,counter),a,lg_term) \
69 * incomplete_gamma_quad_weight_vals(lb,ub,counter) \
70 + incomplete_gamma_quad_recur(lb,ub,a,lg_term,counter+1) :
71 // else
72 incomplete_gamma_quad_fn(incomplete_gamma_quad_inp_vals(lb,ub,counter),a,lg_term) \
73 * incomplete_gamma_quad_weight_vals(lb,ub,counter) );
74 }
75
76 template<typename T>
77 constexpr
78 T
79 incomplete_gamma_quad_lb(const T a, const T z)
80 noexcept
81 {
82 return( a > T(1000) ? max(T(0),min(z,a) - 11*sqrt(a)) : // break integration into ranges
83 a > T(800) ? max(T(0),min(z,a) - 11*sqrt(a)) :
84 a > T(500) ? max(T(0),min(z,a) - 10*sqrt(a)) :
85 a > T(300) ? max(T(0),min(z,a) - 10*sqrt(a)) :
86 a > T(100) ? max(T(0),min(z,a) - 9*sqrt(a)) :
87 a > T(90) ? max(T(0),min(z,a) - 9*sqrt(a)) :
88 a > T(70) ? max(T(0),min(z,a) - 8*sqrt(a)) :
89 a > T(50) ? max(T(0),min(z,a) - 7*sqrt(a)) :
90 a > T(40) ? max(T(0),min(z,a) - 6*sqrt(a)) :
91 a > T(30) ? max(T(0),min(z,a) - 5*sqrt(a)) :
92 // else
93 max(T(0),min(z,a)-4*sqrt(a)) );
94 }
95
96 template<typename T>
97 constexpr
98 T
99 incomplete_gamma_quad_ub(const T a, const T z)
100 noexcept
101 {
102 return( a > T(1000) ? min(z, a + 10*sqrt(a)) :
103 a > T(800) ? min(z, a + 10*sqrt(a)) :
104 a > T(500) ? min(z, a + 9*sqrt(a)) :
105 a > T(300) ? min(z, a + 9*sqrt(a)) :
106 a > T(100) ? min(z, a + 8*sqrt(a)) :
107 a > T(90) ? min(z, a + 8*sqrt(a)) :
108 a > T(70) ? min(z, a + 7*sqrt(a)) :
109 a > T(50) ? min(z, a + 6*sqrt(a)) :
110 a > T(40) ? min(z, a + 5*sqrt(a)) :
111 // else
112 min(z, a + 4*sqrt(a)) );
113 }
114
115 template<typename T>
116 constexpr
117 T
118 incomplete_gamma_quad(const T a, const T z)
119 noexcept
120 {
121 return incomplete_gamma_quad_recur(incomplete_gamma_quad_lb(a,z), incomplete_gamma_quad_ub(a,z), a,lgamma(a),0);
122 }
123
124 // cf expansion
125 // see: http://functions.wolfram.com/GammaBetaErf/Gamma2/10/0009/
126
127 template<typename T>
128 constexpr
129 T
130 incomplete_gamma_cf_coef(const T a, const T z, const int depth)
131 noexcept
132 {
133 return( is_odd(depth) ? - (a - 1 + T(depth+1)/T(2)) * z : T(depth)/T(2) * z );
134 }
135
136 template<typename T>
137 constexpr
138 T
139 incomplete_gamma_cf_recur(const T a, const T z, const int depth)
140 noexcept
141 {
142 return( depth < GCEM_INCML_GAMMA_MAX_ITER ? \
143 // if
144 (a + depth - 1) + incomplete_gamma_cf_coef(a,z,depth)/incomplete_gamma_cf_recur(a,z,depth+1) :
145 // else
146 (a + depth - 1) );
147 }
148
149 template<typename T>
150 constexpr
151 T
152 incomplete_gamma_cf(const T a, const T z)
153 noexcept
154 { // lower (regularized) incomplete gamma function
155 return( exp(a*log(z) - z) / tgamma(a) / incomplete_gamma_cf_recur(a,z,1) );
156 }
157
158 //
159
160 template<typename T>
161 constexpr
162 T
163 incomplete_gamma_check(const T a, const T z)
164 noexcept
165 {
166 return( a < T(0) ? \
167 GCLIM<T>::quiet_NaN() :
168 //
169 GCLIM<T>::epsilon() > z ? \
170 T(0) :
171 //
172 GCLIM<T>::epsilon() > a ? \
173 T(1) :
174 // cf or quadrature
175 a < T(10) ?
176 incomplete_gamma_cf(a,z) :
177 // else
178 incomplete_gamma_quad(a,z) );
179 }
180
181 template<typename T1, typename T2, typename TC = common_return_t<T1,T2>>
182 constexpr
183 TC
184 incomplete_gamma_type_check(const T1 a, const T2 p)
185 noexcept
186 {
187 return incomplete_gamma_check(static_cast<TC>(a),
188 static_cast<TC>(p));
189 }
190
191 }
192
193 /**
194 * Compile-time regularized lower incomplete gamma function
195 *
196 * @param a a real-valued, non-negative input.
197 * @param x a real-valued, non-negative input.
198 *
199 * @return the regularized lower incomplete gamma function evaluated at (\c a, \c x),
200 * \f[ \frac{\gamma(a,x)}{\Gamma(a)} = \frac{1}{\Gamma(a)} \int_0^x t^{a-1} \exp(-t) dt \f]
201 * When \c a is not too large, the value is computed using the continued fraction representation of the upper incomplete gamma function, \f$ \Gamma(a,x) \f$, using
202 * \f[ \Gamma(a,x) = \Gamma(a) - \dfrac{x^a\exp(-x)}{a - \dfrac{ax}{a + 1 + \dfrac{x}{a + 2 - \dfrac{(a+1)x}{a + 3 + \dfrac{2x}{a + 4 - \ddots}}}}} \f]
203 * where \f$ \gamma(a,x) \f$ and \f$ \Gamma(a,x) \f$ are connected via
204 * \f[ \frac{\gamma(a,x)}{\Gamma(a)} + \frac{\Gamma(a,x)}{\Gamma(a)} = 1 \f]
205 * When \f$ a > 10 \f$, a 50-point Gauss-Legendre quadrature scheme is employed.
206 */
207
208 template<typename T1, typename T2>
209 constexpr
210 common_return_t<T1,T2>
211 incomplete_gamma(const T1 a, const T2 x)
212 noexcept
213 {
214 return internal::incomplete_gamma_type_check(a,x);
215 }
216
217 #endif
File vector/gcem/include/gcem_incl/incomplete_gamma_inv.hpp added (mode: 100644) (index 0000000..de2e1a1)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * inverse of the incomplete gamma function
23 */
24
25 #ifndef _gcem_incomplete_gamma_inv_HPP
26 #define _gcem_incomplete_gamma_inv_HPP
27
28 namespace internal
29 {
30
31 template<typename T>
32 constexpr T incomplete_gamma_inv_decision(const T value, const T a, const T p, const T direc, const T lg_val, const int iter_count) noexcept;
33
34 //
35 // initial value for Halley
36
37 template<typename T>
38 constexpr
39 T
40 incomplete_gamma_inv_t_val_1(const T p)
41 noexcept
42 { // a > 1.0
43 return( p > T(0.5) ? sqrt(-2*log(T(1) - p)) : sqrt(-2*log(p)) );
44 }
45
46 template<typename T>
47 constexpr
48 T
49 incomplete_gamma_inv_t_val_2(const T a)
50 noexcept
51 { // a <= 1.0
52 return( T(1) - T(0.253) * a - T(0.12) * a*a );
53 }
54
55 //
56
57 template<typename T>
58 constexpr
59 T
60 incomplete_gamma_inv_initial_val_1_int_begin(const T t_val)
61 noexcept
62 { // internal for a > 1.0
63 return( t_val - (T(2.515517L) + T(0.802853L)*t_val + T(0.010328L)*t_val*t_val) \
64 / (T(1) + T(1.432788L)*t_val + T(0.189269L)*t_val*t_val + T(0.001308L)*t_val*t_val*t_val) );
65 }
66
67 template<typename T>
68 constexpr
69 T
70 incomplete_gamma_inv_initial_val_1_int_end(const T value_inp, const T a)
71 noexcept
72 { // internal for a > 1.0
73 return max( T(1E-04), a*pow(T(1) - T(1)/(9*a) - value_inp/(3*sqrt(a)), 3) );
74 }
75
76 template<typename T>
77 constexpr
78 T
79 incomplete_gamma_inv_initial_val_1(const T a, const T t_val, const T sgn_term)
80 noexcept
81 { // a > 1.0
82 return incomplete_gamma_inv_initial_val_1_int_end(sgn_term*incomplete_gamma_inv_initial_val_1_int_begin(t_val), a);
83 }
84
85 template<typename T>
86 constexpr
87 T
88 incomplete_gamma_inv_initial_val_2(const T a, const T p, const T t_val)
89 noexcept
90 { // a <= 1.0
91 return( p < t_val ? \
92 // if
93 pow(p/t_val,T(1)/a) :
94 // else
95 T(1) - log(T(1) - (p - t_val)/(T(1) - t_val)) );
96 }
97
98 // initial value
99
100 template<typename T>
101 constexpr
102 T
103 incomplete_gamma_inv_initial_val(const T a, const T p)
104 noexcept
105 {
106 return( a > T(1) ? \
107 // if
108 incomplete_gamma_inv_initial_val_1(a,
109 incomplete_gamma_inv_t_val_1(p),
110 p > T(0.5) ? T(-1) : T(1)) :
111 // else
112 incomplete_gamma_inv_initial_val_2(a,p,
113 incomplete_gamma_inv_t_val_2(a)));
114 }
115
116 //
117 // Halley recursion
118
119 template<typename T>
120 constexpr
121 T
122 incomplete_gamma_inv_err_val(const T value, const T a, const T p)
123 noexcept
124 { // err_val = f(x)
125 return( incomplete_gamma(a,value) - p );
126 }
127
128 template<typename T>
129 constexpr
130 T
131 incomplete_gamma_inv_deriv_1(const T value, const T a, const T lg_val)
132 noexcept
133 { // derivative of the incomplete gamma function w.r.t. x
134 return( exp( - value + (a - T(1))*log(value) - lg_val ) );
135 }
136
137 template<typename T>
138 constexpr
139 T
140 incomplete_gamma_inv_deriv_2(const T value, const T a, const T deriv_1)
141 noexcept
142 { // second derivative of the incomplete gamma function w.r.t. x
143 return( deriv_1*((a - T(1))/value - T(1)) );
144 }
145
146 template<typename T>
147 constexpr
148 T
149 incomplete_gamma_inv_ratio_val_1(const T value, const T a, const T p, const T deriv_1)
150 noexcept
151 {
152 return( incomplete_gamma_inv_err_val(value,a,p) / deriv_1 );
153 }
154
155 template<typename T>
156 constexpr
157 T
158 incomplete_gamma_inv_ratio_val_2(const T value, const T a, const T deriv_1)
159 noexcept
160 {
161 return( incomplete_gamma_inv_deriv_2(value,a,deriv_1) / deriv_1 );
162 }
163
164 template<typename T>
165 constexpr
166 T
167 incomplete_gamma_inv_halley(const T ratio_val_1, const T ratio_val_2)
168 noexcept
169 {
170 return( ratio_val_1 / max( T(0.8), min( T(1.2), T(1) - T(0.5)*ratio_val_1*ratio_val_2 ) ) );
171 }
172
173 template<typename T>
174 constexpr
175 T
176 incomplete_gamma_inv_recur(const T value, const T a, const T p, const T deriv_1, const T lg_val, const int iter_count)
177 noexcept
178 {
179 return incomplete_gamma_inv_decision(value, a, p,
180 incomplete_gamma_inv_halley(incomplete_gamma_inv_ratio_val_1(value,a,p,deriv_1),
181 incomplete_gamma_inv_ratio_val_2(value,a,deriv_1)),
182 lg_val, iter_count);
183 }
184
185 template<typename T>
186 constexpr
187 T
188 incomplete_gamma_inv_decision(const T value, const T a, const T p, const T direc, const T lg_val, const int iter_count)
189 noexcept
190 {
191 // return( abs(direc) > GCEM_INCML_GAMMA_INV_TOL ? incomplete_gamma_inv_recur(value - direc, a, p, incomplete_gamma_inv_deriv_1(value,a,lg_val), lg_val) : value - direc );
192 return( iter_count <= GCEM_INCML_GAMMA_INV_MAX_ITER ? \
193 // if
194 incomplete_gamma_inv_recur(value-direc,a,p,
195 incomplete_gamma_inv_deriv_1(value,a,lg_val),
196 lg_val,iter_count+1) :
197 // else
198 value - direc );
199 }
200
201 template<typename T>
202 constexpr
203 T
204 incomplete_gamma_inv_begin(const T initial_val, const T a, const T p, const T lg_val)
205 noexcept
206 {
207 return incomplete_gamma_inv_recur(initial_val,a,p,
208 incomplete_gamma_inv_deriv_1(initial_val,a,lg_val), lg_val,1);
209 }
210
211 template<typename T>
212 constexpr
213 T
214 incomplete_gamma_inv_check(const T a, const T p)
215 noexcept
216 {
217 return( GCLIM<T>::epsilon() > p ? \
218 T(0) :
219 p > T(1) ? \
220 GCLIM<T>::quiet_NaN() :
221 GCLIM<T>::epsilon() > abs(T(1) - p) ? \
222 GCLIM<T>::infinity() :
223 //
224 GCLIM<T>::epsilon() > a ? \
225 T(0) :
226 // else
227 incomplete_gamma_inv_begin(incomplete_gamma_inv_initial_val(a,p),a,p,lgamma(a)) );
228 }
229
230 template<typename T1, typename T2, typename TC = common_return_t<T1,T2>>
231 constexpr
232 TC
233 incomplete_gamma_inv_type_check(const T1 a, const T2 p)
234 noexcept
235 {
236 return incomplete_gamma_inv_check(static_cast<TC>(a),
237 static_cast<TC>(p));
238 }
239
240 }
241
242 /**
243 * Compile-time inverse incomplete gamma function
244 *
245 * @param a a real-valued, non-negative input.
246 * @param p a real-valued input with values in the unit-interval.
247 *
248 * @return Computes the inverse incomplete gamma function, a value \f$ x \f$ such that
249 * \f[ f(x) := \frac{\gamma(a,x)}{\Gamma(a)} - p \f]
250 * equal to zero, for a given \c p.
251 * GCE-Math finds this root using Halley's method:
252 * \f[ x_{n+1} = x_n - \frac{f(x_n)/f'(x_n)}{1 - 0.5 \frac{f(x_n)}{f'(x_n)} \frac{f''(x_n)}{f'(x_n)} } \f]
253 * where
254 * \f[ \frac{\partial}{\partial x} \left(\frac{\gamma(a,x)}{\Gamma(a)}\right) = \frac{1}{\Gamma(a)} x^{a-1} \exp(-x) \f]
255 * \f[ \frac{\partial^2}{\partial x^2} \left(\frac{\gamma(a,x)}{\Gamma(a)}\right) = \frac{1}{\Gamma(a)} x^{a-1} \exp(-x) \left( \frac{a-1}{x} - 1 \right) \f]
256 */
257
258 template<typename T1, typename T2>
259 constexpr
260 common_return_t<T1,T2>
261 incomplete_gamma_inv(const T1 a, const T2 p)
262 noexcept
263 {
264 return internal::incomplete_gamma_inv_type_check(a,p);
265 }
266
267 #endif
File vector/gcem/include/gcem_incl/is_even.hpp added (mode: 100644) (index 0000000..60e9f19)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time check if integer is even
23 */
24
25 #ifndef _gcem_is_even_HPP
26 #define _gcem_is_even_HPP
27
28 namespace internal
29 {
30
31 constexpr
32 bool
33 is_even(const llint_t x)
34 noexcept
35 {
36 return !is_odd(x);
37 }
38
39 }
40
41 #endif
File vector/gcem/include/gcem_incl/is_finite.hpp added (mode: 100644) (index 0000000..e85f71a)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time check if a float is not NaN-valued or +/-Inf
23 */
24
25 #ifndef _gcem_is_finite_HPP
26 #define _gcem_is_finite_HPP
27
28 namespace internal
29 {
30
31 template<typename T>
32 constexpr
33 bool
34 is_finite(const T x)
35 noexcept
36 {
37 return (!is_nan(x)) && (!is_inf(x));
38 }
39
40 template<typename T1, typename T2>
41 constexpr
42 bool
43 any_finite(const T1 x, const T2 y)
44 noexcept
45 {
46 return( is_finite(x) || is_finite(y) );
47 }
48
49 template<typename T1, typename T2>
50 constexpr
51 bool
52 all_finite(const T1 x, const T2 y)
53 noexcept
54 {
55 return( is_finite(x) && is_finite(y) );
56 }
57
58 template<typename T1, typename T2, typename T3>
59 constexpr
60 bool
61 any_finite(const T1 x, const T2 y, const T3 z)
62 noexcept
63 {
64 return( is_finite(x) || is_finite(y) || is_finite(z) );
65 }
66
67 template<typename T1, typename T2, typename T3>
68 constexpr
69 bool
70 all_finite(const T1 x, const T2 y, const T3 z)
71 noexcept
72 {
73 return( is_finite(x) && is_finite(y) && is_finite(z) );
74 }
75
76 }
77
78 #endif
File vector/gcem/include/gcem_incl/is_inf.hpp added (mode: 100644) (index 0000000..29ee3a3)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time check if a float is +/-Inf
23 */
24
25 #ifndef _gcem_is_inf_HPP
26 #define _gcem_is_inf_HPP
27
28 namespace internal
29 {
30
31 template<typename T>
32 constexpr
33 bool
34 is_neginf(const T x)
35 noexcept
36 {
37 return x == - GCLIM<T>::infinity();
38 }
39
40 template<typename T1, typename T2>
41 constexpr
42 bool
43 any_neginf(const T1 x, const T2 y)
44 noexcept
45 {
46 return( is_neginf(x) || is_neginf(y) );
47 }
48
49 template<typename T1, typename T2>
50 constexpr
51 bool
52 all_neginf(const T1 x, const T2 y)
53 noexcept
54 {
55 return( is_neginf(x) && is_neginf(y) );
56 }
57
58 template<typename T1, typename T2, typename T3>
59 constexpr
60 bool
61 any_neginf(const T1 x, const T2 y, const T3 z)
62 noexcept
63 {
64 return( is_neginf(x) || is_neginf(y) || is_neginf(z) );
65 }
66
67 template<typename T1, typename T2, typename T3>
68 constexpr
69 bool
70 all_neginf(const T1 x, const T2 y, const T3 z)
71 noexcept
72 {
73 return( is_neginf(x) && is_neginf(y) && is_neginf(z) );
74 }
75
76 //
77
78 template<typename T>
79 constexpr
80 bool
81 is_posinf(const T x)
82 noexcept
83 {
84 return x == GCLIM<T>::infinity();
85 }
86
87 template<typename T1, typename T2>
88 constexpr
89 bool
90 any_posinf(const T1 x, const T2 y)
91 noexcept
92 {
93 return( is_posinf(x) || is_posinf(y) );
94 }
95
96 template<typename T1, typename T2>
97 constexpr
98 bool
99 all_posinf(const T1 x, const T2 y)
100 noexcept
101 {
102 return( is_posinf(x) && is_posinf(y) );
103 }
104
105 template<typename T1, typename T2, typename T3>
106 constexpr
107 bool
108 any_posinf(const T1 x, const T2 y, const T3 z)
109 noexcept
110 {
111 return( is_posinf(x) || is_posinf(y) || is_posinf(z) );
112 }
113
114 template<typename T1, typename T2, typename T3>
115 constexpr
116 bool
117 all_posinf(const T1 x, const T2 y, const T3 z)
118 noexcept
119 {
120 return( is_posinf(x) && is_posinf(y) && is_posinf(z) );
121 }
122
123 //
124
125 template<typename T>
126 constexpr
127 bool
128 is_inf(const T x)
129 noexcept
130 {
131 return( is_neginf(x) || is_posinf(x) );
132 }
133
134 template<typename T1, typename T2>
135 constexpr
136 bool
137 any_inf(const T1 x, const T2 y)
138 noexcept
139 {
140 return( is_inf(x) || is_inf(y) );
141 }
142
143 template<typename T1, typename T2>
144 constexpr
145 bool
146 all_inf(const T1 x, const T2 y)
147 noexcept
148 {
149 return( is_inf(x) && is_inf(y) );
150 }
151
152 template<typename T1, typename T2, typename T3>
153 constexpr
154 bool
155 any_inf(const T1 x, const T2 y, const T3 z)
156 noexcept
157 {
158 return( is_inf(x) || is_inf(y) || is_inf(z) );
159 }
160
161 template<typename T1, typename T2, typename T3>
162 constexpr
163 bool
164 all_inf(const T1 x, const T2 y, const T3 z)
165 noexcept
166 {
167 return( is_inf(x) && is_inf(y) && is_inf(z) );
168 }
169
170 }
171
172 #endif
File vector/gcem/include/gcem_incl/is_nan.hpp added (mode: 100644) (index 0000000..8f31f9a)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time check if a float is NaN-valued
23 */
24
25 #ifndef _gcem_is_nan_HPP
26 #define _gcem_is_nan_HPP
27
28 namespace internal
29 {
30
31 // future: consider using __builtin_isnan(__x)
32
33 template<typename T>
34 constexpr
35 bool
36 is_nan(const T x)
37 noexcept
38 {
39 return x != x;
40 }
41
42 template<typename T1, typename T2>
43 constexpr
44 bool
45 any_nan(const T1 x, const T2 y)
46 noexcept
47 {
48 return( is_nan(x) || is_nan(y) );
49 }
50
51 template<typename T1, typename T2>
52 constexpr
53 bool
54 all_nan(const T1 x, const T2 y)
55 noexcept
56 {
57 return( is_nan(x) && is_nan(y) );
58 }
59
60 template<typename T1, typename T2, typename T3>
61 constexpr
62 bool
63 any_nan(const T1 x, const T2 y, const T3 z)
64 noexcept
65 {
66 return( is_nan(x) || is_nan(y) || is_nan(z) );
67 }
68
69 template<typename T1, typename T2, typename T3>
70 constexpr
71 bool
72 all_nan(const T1 x, const T2 y, const T3 z)
73 noexcept
74 {
75 return( is_nan(x) && is_nan(y) && is_nan(z) );
76 }
77
78 }
79
80 #endif
File vector/gcem/include/gcem_incl/is_odd.hpp added (mode: 100644) (index 0000000..a6c6af3)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time check if integer is odd
23 */
24
25 #ifndef _gcem_is_odd_HPP
26 #define _gcem_is_odd_HPP
27
28 namespace internal
29 {
30
31 constexpr
32 bool
33 is_odd(const llint_t x)
34 noexcept
35 {
36 // return( x % llint_t(2) == llint_t(0) ? false : true );
37 return (x & 1U) != 0;
38 }
39
40 }
41
42 #endif
File vector/gcem/include/gcem_incl/lbeta.hpp added (mode: 100644) (index 0000000..8fb1364)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #ifndef _gcem_lbeta_HPP
22 #define _gcem_lbeta_HPP
23
24 /**
25 * Compile-time log-beta function
26 *
27 * @param a a real-valued input.
28 * @param b a real-valued input.
29 * @return the log-beta function using \f[ \ln \text{B}(\alpha,\beta) := \ln \int_0^1 t^{\alpha - 1} (1-t)^{\beta - 1} dt = \ln \Gamma(\alpha) + \ln \Gamma(\beta) - \ln \Gamma(\alpha + \beta) \f]
30 * where \f$ \Gamma \f$ denotes the gamma function.
31 */
32
33 template<typename T1, typename T2>
34 constexpr
35 common_return_t<T1,T2>
36 lbeta(const T1 a, const T2 b)
37 noexcept
38 {
39 return( (lgamma(a) + lgamma(b)) - lgamma(a+b) );
40 }
41
42 #endif
File vector/gcem/include/gcem_incl/lcm.hpp added (mode: 100644) (index 0000000..bf057eb)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #ifndef _gcem_lcm_HPP
22 #define _gcem_lcm_HPP
23
24 namespace internal
25 {
26
27 template<typename T>
28 constexpr
29 T
30 lcm_compute(const T a, const T b)
31 noexcept
32 {
33 return abs(a * (b / gcd(a,b)));
34 }
35
36 template<typename T1, typename T2, typename TC = common_t<T1,T2>>
37 constexpr
38 TC
39 lcm_type_check(const T1 a, const T2 b)
40 noexcept
41 {
42 return lcm_compute(static_cast<TC>(a),static_cast<TC>(b));
43 }
44
45 }
46
47 /**
48 * Compile-time least common multiple (LCM) function
49 *
50 * @param a integral-valued input.
51 * @param b integral-valued input.
52 * @return the least common multiple between integers \c a and \c b using the representation \f[ \text{lcm}(a,b) = \dfrac{| a b |}{\text{gcd}(a,b)} \f]
53 * where \f$ \text{gcd}(a,b) \f$ denotes the greatest common divisor between \f$ a \f$ and \f$ b \f$.
54 */
55
56 template<typename T1, typename T2>
57 constexpr
58 common_t<T1,T2>
59 lcm(const T1 a, const T2 b)
60 noexcept
61 {
62 return internal::lcm_type_check(a,b);
63 }
64
65 #endif
File vector/gcem/include/gcem_incl/lgamma.hpp added (mode: 100644) (index 0000000..bc6b5ba)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time log-gamma function
23 *
24 * for coefficient values, see:
25 * http://my.fit.edu/~gabdo/gamma.txt
26 */
27
28 #ifndef _gcem_lgamma_HPP
29 #define _gcem_lgamma_HPP
30
31 namespace internal
32 {
33
34 // P. Godfrey's coefficients:
35 //
36 // 0.99999999999999709182
37 // 57.156235665862923517
38 // -59.597960355475491248
39 // 14.136097974741747174
40 // -0.49191381609762019978
41 // .33994649984811888699e-4
42 // .46523628927048575665e-4
43 // -.98374475304879564677e-4
44 // .15808870322491248884e-3
45 // -.21026444172410488319e-3
46 // .21743961811521264320e-3
47 // -.16431810653676389022e-3
48 // .84418223983852743293e-4
49 // -.26190838401581408670e-4
50 // .36899182659531622704e-5
51
52 constexpr
53 long double
54 lgamma_coef_term(const long double x)
55 noexcept
56 {
57 return( 0.99999999999999709182L + 57.156235665862923517L / (x+1) \
58 - 59.597960355475491248L / (x+2) + 14.136097974741747174L / (x+3) \
59 - 0.49191381609762019978L / (x+4) + .33994649984811888699e-4L / (x+5) \
60 + .46523628927048575665e-4L / (x+6) - .98374475304879564677e-4L / (x+7) \
61 + .15808870322491248884e-3L / (x+8) - .21026444172410488319e-3L / (x+9) \
62 + .21743961811521264320e-3L / (x+10) - .16431810653676389022e-3L / (x+11) \
63 + .84418223983852743293e-4L / (x+12) - .26190838401581408670e-4L / (x+13) \
64 + .36899182659531622704e-5L / (x+14) );
65 }
66
67 template<typename T>
68 constexpr
69 T
70 lgamma_term_2(const T x)
71 noexcept
72 { //
73 return( T(GCEM_LOG_SQRT_2PI) + log(T(lgamma_coef_term(x))) );
74 }
75
76 template<typename T>
77 constexpr
78 T
79 lgamma_term_1(const T x)
80 noexcept
81 { // note: 607/128 + 0.5 = 5.2421875
82 return( (x + T(0.5))*log(x + T(5.2421875L)) - (x + T(5.2421875L)) );
83 }
84
85 template<typename T>
86 constexpr
87 T
88 lgamma_begin(const T x)
89 noexcept
90 { // returns lngamma(x+1)
91 return( lgamma_term_1(x) + lgamma_term_2(x) );
92 }
93
94 template<typename T>
95 constexpr
96 T
97 lgamma_check(const T x)
98 noexcept
99 {
100 return( // indistinguishable from one or <= zero
101 GCLIM<T>::epsilon() > abs(x - T(1)) ? \
102 T(0) :
103 GCLIM<T>::epsilon() > x ? \
104 GCLIM<T>::infinity() :
105 // else
106 lgamma_begin(x - T(1)) );
107 }
108
109 }
110
111 /**
112 * Compile-time log-gamma function
113 *
114 * @param x a real-valued input.
115 * @return computes the log-gamma function
116 * \f[ \ln \Gamma(x) = \ln \int_0^\infty y^{x-1} \exp(-y) dy \f]
117 * using a polynomial form:
118 * \f[ \Gamma(x+1) \approx (x+g+0.5)^{x+0.5} \exp(-x-g-0.5) \sqrt{2 \pi} \left[ c_0 + \frac{c_1}{x+1} + \frac{c_2}{x+2} + \cdots + \frac{c_n}{x+n} \right] \f]
119 * where the value \f$ g \f$ and the coefficients \f$ (c_0, c_1, \ldots, c_n) \f$
120 * are taken from Paul Godfrey, whose note can be found here: http://my.fit.edu/~gabdo/gamma.txt
121 */
122
123 template<typename T>
124 constexpr
125 return_t<T>
126 lgamma(const T x)
127 noexcept
128 {
129 return internal::lgamma_check( static_cast<return_t<T>>(x) );
130 }
131
132 #endif
File vector/gcem/include/gcem_incl/lmgamma.hpp added (mode: 100644) (index 0000000..4772200)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * log multivariate gamma function
23 */
24
25 #ifndef _gcem_lmgamma_HPP
26 #define _gcem_lmgamma_HPP
27
28 namespace internal
29 {
30
31 // see https://en.wikipedia.org/wiki/Multivariate_gamma_function
32
33 template<typename T1, typename T2>
34 constexpr
35 T1
36 lmgamma_recur(const T1 a, const T2 p)
37 noexcept
38 {
39 return( p == T2(1) ? \
40 lgamma(a) :
41 p < T2(1) ? \
42 GCLIM<T1>::quiet_NaN() :
43 // else
44 T1(GCEM_LOG_PI) * (p - T1(1))/T1(2) \
45 + lgamma(a) + lmgamma_recur(a - T1(0.5),p-T2(1)) );
46 }
47
48 }
49
50 /**
51 * Compile-time log multivariate gamma function
52 *
53 * @param a a real-valued input.
54 * @param p integral-valued input.
55 * @return computes log-multivariate gamma function via recursion
56 * \f[ \Gamma_p(a) = \pi^{(p-1)/2} \Gamma(a) \Gamma_{p-1}(a-0.5) \f]
57 * where \f$ \Gamma_1(a) = \Gamma(a) \f$.
58 */
59
60 template<typename T1, typename T2>
61 constexpr
62 return_t<T1>
63 lmgamma(const T1 a, const T2 p)
64 noexcept
65 {
66 return internal::lmgamma_recur(static_cast<return_t<T1>>(a),p);
67 }
68
69 #endif
File vector/gcem/include/gcem_incl/log.hpp added (mode: 100644) (index 0000000..4745cb5)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time natural logarithm function
23 */
24
25 #ifndef _gcem_log_HPP
26 #define _gcem_log_HPP
27
28 namespace internal
29 {
30
31 // continued fraction seems to be a better approximation for small x
32 // see http://functions.wolfram.com/ElementaryFunctions/Log/10/0005/
33
34 template<typename T>
35 constexpr
36 T
37 log_cf_main(const T xx, const int depth)
38 noexcept
39 {
40 return( depth < GCEM_LOG_MAX_ITER_SMALL ? \
41 // if
42 T(2*depth - 1) - T(depth*depth)*xx/log_cf_main(xx,depth+1) :
43 // else
44 T(2*depth - 1) );
45 }
46
47 template<typename T>
48 constexpr
49 T
50 log_cf_begin(const T x)
51 noexcept
52 {
53 return( T(2)*x/log_cf_main(x*x,1) );
54 }
55
56 template<typename T>
57 constexpr
58 T
59 log_main(const T x)
60 noexcept
61 {
62 return( log_cf_begin((x - T(1))/(x + T(1))) );
63 }
64
65 constexpr
66 long double
67 log_mantissa_integer(const int x)
68 noexcept
69 {
70 return( x == 2 ? 0.6931471805599453094172321214581765680755L :
71 x == 3 ? 1.0986122886681096913952452369225257046475L :
72 x == 4 ? 1.3862943611198906188344642429163531361510L :
73 x == 5 ? 1.6094379124341003746007593332261876395256L :
74 x == 6 ? 1.7917594692280550008124773583807022727230L :
75 x == 7 ? 1.9459101490553133051053527434431797296371L :
76 x == 8 ? 2.0794415416798359282516963643745297042265L :
77 x == 9 ? 2.1972245773362193827904904738450514092950L :
78 x == 10 ? 2.3025850929940456840179914546843642076011L :
79 0.0L );
80 }
81
82 template<typename T>
83 constexpr
84 T
85 log_mantissa(const T x)
86 noexcept
87 { // divide by the integer part of x, which will be in [1,10], then adjust using tables
88 return( log_main(x/T(static_cast<int>(x))) + T(log_mantissa_integer(static_cast<int>(x))) );
89 }
90
91 template<typename T>
92 constexpr
93 T
94 log_breakup(const T x)
95 noexcept
96 { // x = a*b, where b = 10^c
97 return( log_mantissa(mantissa(x)) + T(GCEM_LOG_10)*T(find_exponent(x,0)) );
98 }
99
100 template<typename T>
101 constexpr
102 T
103 log_check(const T x)
104 noexcept
105 {
106 return( x == GCLIM<T>::quiet_NaN() ? \
107 GCLIM<T>::quiet_NaN() :
108 // x < 0
109 x < T(0) ? \
110 GCLIM<T>::quiet_NaN() :
111 // x ~= 0
112 GCLIM<T>::epsilon() > x ? \
113 - GCLIM<T>::infinity() :
114 // indistinguishable from 1
115 GCLIM<T>::epsilon() > abs(x - T(1)) ? \
116 T(0) :
117 //
118 x == GCLIM<T>::infinity() ? \
119 GCLIM<T>::infinity() :
120 // else
121 (x < T(0.5) || x > T(1.5)) ?
122 // if
123 log_breakup(x) :
124 // else
125 log_main(x) );
126 }
127
128 }
129
130 /**
131 * Compile-time natural logarithm function
132 *
133 * @param x a real-valued input.
134 * @return \f$ \log_e(x) \f$ using \f[ \log\left(\frac{1+x}{1-x}\right) = \dfrac{2x}{1-\dfrac{x^2}{3-\dfrac{4x^2}{5 - \dfrac{9x^3}{7 - \ddots}}}}, \ \ x \in [-1,1] \f]
135 * The continued fraction argument is split into two parts: \f$ x = a \times 10^c \f$, where \f$ c \f$ is an integer.
136 */
137
138 template<typename T>
139 constexpr
140 return_t<T>
141 log(const T x)
142 noexcept
143 {
144 return internal::log_check( static_cast<return_t<T>>(x) );
145 }
146
147 #endif
File vector/gcem/include/gcem_incl/log1p.hpp added (mode: 100644) (index 0000000..719ba5f)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time natural logarithm(x+1) function
23 */
24
25 #ifndef _gcem_log1p_HPP
26 #define _gcem_log1p_HPP
27
28 namespace internal
29 {
30
31 // see:
32 // http://functions.wolfram.com/ElementaryFunctions/Log/06/01/04/01/0003/
33
34
35 template<typename T>
36 constexpr
37 T
38 log1p_compute(const T x)
39 noexcept
40 {
41 // return x * ( T(1) + x * ( -T(1)/T(2) + x * ( T(1)/T(3) + x * ( -T(1)/T(4) + x/T(5) ) ) ) ); // O(x^6)
42 return x + x * ( - x/T(2) + x * ( x/T(3) + x * ( -x/T(4) + x*x/T(5) ) ) ); // O(x^6)
43 }
44
45 template<typename T>
46 constexpr
47 T
48 log1p_check(const T x)
49 noexcept
50 {
51 return( abs(x) > T(1e-04) ? \
52 // if
53 log(T(1) + x) :
54 // else
55 log1p_compute(x) );
56 }
57
58 }
59
60 /**
61 * Compile-time natural-logarithm-plus-1 function
62 *
63 * @param x a real-valued input.
64 * @return \f$ \log_e(x+1) \f$ using \f[ \log(x+1) = \sum_{k=1}^\infty \dfrac{(-1)^{k-1}x^k}{k}, \ \ |x| < 1 \f]
65 */
66
67 template<typename T>
68 constexpr
69 return_t<T>
70 log1p(const T x)
71 noexcept
72 {
73 return internal::log1p_check( static_cast<return_t<T>>(x) );
74 }
75
76 #endif
File vector/gcem/include/gcem_incl/log_binomial_coef.hpp added (mode: 100644) (index 0000000..338365d)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #ifndef _gcem_log_binomial_coef_HPP
22 #define _gcem_log_binomial_coef_HPP
23
24 namespace internal
25 {
26
27 template<typename T>
28 constexpr
29 T
30 log_binomial_coef_compute(const T n, const T k)
31 noexcept
32 {
33 return( lgamma(n+1) - (lgamma(k+1) + lgamma(n-k+1)) );
34 }
35
36 template<typename T1, typename T2, typename TC = common_return_t<T1,T2>>
37 constexpr
38 TC
39 log_binomial_coef_type_check(const T1 n, const T2 k)
40 noexcept
41 {
42 return log_binomial_coef_compute(static_cast<TC>(n),static_cast<TC>(k));
43 }
44
45 }
46
47 /**
48 * Compile-time log binomial coefficient
49 *
50 * @param n integral-valued input.
51 * @param k integral-valued input.
52 * @return computes the log Binomial coefficient
53 * \f[ \ln \frac{n!}{k!(n-k)!} = \ln \Gamma(n+1) - [ \ln \Gamma(k+1) + \ln \Gamma(n-k+1) ] \f]
54 */
55
56 template<typename T1, typename T2>
57 constexpr
58 common_return_t<T1,T2>
59 log_binomial_coef(const T1 n, const T2 k)
60 noexcept
61 {
62 return internal::log_binomial_coef_type_check(n,k);
63 }
64
65 #endif
File vector/gcem/include/gcem_incl/mantissa.hpp added (mode: 100644) (index 0000000..478f99c)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time mantissa function
23 */
24
25 #ifndef _gcem_mantissa_HPP
26 #define _gcem_mantissa_HPP
27
28 namespace internal
29 {
30
31 template<typename T>
32 constexpr
33 T
34 mantissa(const T x)
35 noexcept
36 {
37 return( x < T(1) ? \
38 mantissa(x*T(10)) :
39 x > T(10) ? \
40 mantissa(x/T(10)) :
41 // else
42 x );
43 }
44
45 }
46
47 #endif
File vector/gcem/include/gcem_incl/max.hpp added (mode: 100644) (index 0000000..2f224bb)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #ifndef _gcem_max_HPP
22 #define _gcem_max_HPP
23
24 /**
25 * Compile-time pairwise maximum function
26 *
27 * @param x a real-valued input.
28 * @param y a real-valued input.
29 * @return Computes the maximum between \c x and \c y, where \c x and \c y have the same type (e.g., \c int, \c double, etc.)
30 */
31
32 template<typename T1, typename T2>
33 constexpr
34 common_t<T1,T2>
35 max(const T1 x, const T2 y)
36 noexcept
37 {
38 return( y < x ? x : y );
39 }
40
41 #endif
File vector/gcem/include/gcem_incl/min.hpp added (mode: 100644) (index 0000000..e055caf)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #ifndef _gcem_min_HPP
22 #define _gcem_min_HPP
23
24 /**
25 * Compile-time pairwise minimum function
26 *
27 * @param x a real-valued input.
28 * @param y a real-valued input.
29 * @return Computes the minimum between \c x and \c y, where \c x and \c y have the same type (e.g., \c int, \c double, etc.)
30 */
31
32 template<typename T1, typename T2>
33 constexpr
34 common_t<T1,T2>
35 min(const T1 x, const T2 y)
36 noexcept
37 {
38 return( y > x ? x : y );
39 }
40
41 #endif
File vector/gcem/include/gcem_incl/neg_zero.hpp added (mode: 100644) (index 0000000..68075d5)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * extract signbit for signed zeros
23 */
24
25 namespace internal
26 {
27
28 template<typename T>
29 constexpr
30 bool
31 neg_zero(const T x)
32 noexcept
33 {
34 return( (x == T(0.0)) && (GCEM_COPYSIGN(T(1.0), x) == T(-1.0)) );
35 }
36
37 }
File vector/gcem/include/gcem_incl/pow.hpp added (mode: 100644) (index 0000000..00bdc28)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time power function
23 */
24
25 #ifndef _gcem_pow_HPP
26 #define _gcem_pow_HPP
27
28 namespace internal
29 {
30
31 template<typename T>
32 constexpr
33 T
34 pow_dbl(const T base, const T exp_term)
35 noexcept
36 {
37 return exp(exp_term*log(base));
38 }
39
40 template<typename T1, typename T2, typename TC = common_t<T1,T2>,
41 typename std::enable_if<!std::is_integral<T2>::value>::type* = nullptr>
42 constexpr
43 TC
44 pow_check(const T1 base, const T2 exp_term)
45 noexcept
46 {
47 return( base < T1(0) ? \
48 GCLIM<TC>::quiet_NaN() :
49 //
50 pow_dbl(static_cast<TC>(base),static_cast<TC>(exp_term)) );
51 }
52
53 template<typename T1, typename T2, typename TC = common_t<T1,T2>,
54 typename std::enable_if<std::is_integral<T2>::value>::type* = nullptr>
55 constexpr
56 TC
57 pow_check(const T1 base, const T2 exp_term)
58 noexcept
59 {
60 return pow_integral(base,exp_term);
61 }
62
63 }
64
65 /**
66 * Compile-time power function
67 *
68 * @param base a real-valued input.
69 * @param exp_term a real-valued input.
70 * @return Computes \c base raised to the power \c exp_term. In the case where \c exp_term is integral-valued, recursion by squaring is used, otherwise \f$ \text{base}^{\text{exp\_term}} = e^{\text{exp\_term} \log(\text{base})} \f$
71 */
72
73 template<typename T1, typename T2>
74 constexpr
75 common_t<T1,T2>
76 pow(const T1 base, const T2 exp_term)
77 noexcept
78 {
79 return internal::pow_check(base,exp_term);
80 }
81
82 #endif
File vector/gcem/include/gcem_incl/pow_integral.hpp added (mode: 100644) (index 0000000..2d30971)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time power function
23 */
24
25 #ifndef _gcem_pow_integral_HPP
26 #define _gcem_pow_integral_HPP
27
28 namespace internal
29 {
30
31 template<typename T1, typename T2>
32 constexpr T1 pow_integral_compute(const T1 base, const T2 exp_term) noexcept;
33
34 // integral-valued powers using method described in
35 // https://en.wikipedia.org/wiki/Exponentiation_by_squaring
36
37 template<typename T1, typename T2>
38 constexpr
39 T1
40 pow_integral_compute_recur(const T1 base, const T1 val, const T2 exp_term)
41 noexcept
42 {
43 return( exp_term > T2(1) ? \
44 (is_odd(exp_term) ? \
45 pow_integral_compute_recur(base*base,val*base,exp_term/2) :
46 pow_integral_compute_recur(base*base,val,exp_term/2)) :
47 (exp_term == T2(1) ? val*base : val) );
48 }
49
50 template<typename T1, typename T2, typename std::enable_if<std::is_signed<T2>::value>::type* = nullptr>
51 constexpr
52 T1
53 pow_integral_sgn_check(const T1 base, const T2 exp_term)
54 noexcept
55 {
56 return( exp_term < T2(0) ? \
57 //
58 T1(1) / pow_integral_compute(base, - exp_term) :
59 //
60 pow_integral_compute_recur(base,T1(1),exp_term) );
61 }
62
63 template<typename T1, typename T2, typename std::enable_if<!std::is_signed<T2>::value>::type* = nullptr>
64 constexpr
65 T1
66 pow_integral_sgn_check(const T1 base, const T2 exp_term)
67 noexcept
68 {
69 return( pow_integral_compute_recur(base,T1(1),exp_term) );
70 }
71
72 template<typename T1, typename T2>
73 constexpr
74 T1
75 pow_integral_compute(const T1 base, const T2 exp_term)
76 noexcept
77 {
78 return( exp_term == T2(3) ? \
79 base*base*base :
80 exp_term == T2(2) ? \
81 base*base :
82 exp_term == T2(1) ? \
83 base :
84 exp_term == T2(0) ? \
85 T1(1) :
86 // check for overflow
87 exp_term == GCLIM<T2>::min() ? \
88 T1(0) :
89 exp_term == GCLIM<T2>::max() ? \
90 GCLIM<T1>::infinity() :
91 // else
92 pow_integral_sgn_check(base,exp_term) );
93 }
94
95 template<typename T1, typename T2, typename std::enable_if<std::is_integral<T2>::value>::type* = nullptr>
96 constexpr
97 T1
98 pow_integral_type_check(const T1 base, const T2 exp_term)
99 noexcept
100 {
101 return pow_integral_compute(base,exp_term);
102 }
103
104 template<typename T1, typename T2, typename std::enable_if<!std::is_integral<T2>::value>::type* = nullptr>
105 constexpr
106 T1
107 pow_integral_type_check(const T1 base, const T2 exp_term)
108 noexcept
109 {
110 // return GCLIM<return_t<T1>>::quiet_NaN();
111 return pow_integral_compute(base,static_cast<llint_t>(exp_term));
112 }
113
114 //
115 // main function
116
117 template<typename T1, typename T2>
118 constexpr
119 T1
120 pow_integral(const T1 base, const T2 exp_term)
121 noexcept
122 {
123 return internal::pow_integral_type_check(base,exp_term);
124 }
125
126 }
127
128 #endif
File vector/gcem/include/gcem_incl/quadrature/gauss_legendre_30.hpp added (mode: 100644) (index 0000000..677cc67)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * Gauss-Legendre quadrature: 30 points
23 */
24
25 static const long double gauss_legendre_30_points[30] = \
26 {
27 -0.05147184255531769583302521316672L,
28 0.05147184255531769583302521316672L,
29 -0.15386991360858354696379467274326L,
30 0.15386991360858354696379467274326L,
31 -0.25463692616788984643980512981781L,
32 0.25463692616788984643980512981781L,
33 -0.35270472553087811347103720708937L,
34 0.35270472553087811347103720708937L,
35 -0.44703376953808917678060990032285L,
36 0.44703376953808917678060990032285L,
37 -0.53662414814201989926416979331107L,
38 0.53662414814201989926416979331107L,
39 -0.62052618298924286114047755643119L,
40 0.62052618298924286114047755643119L,
41 -0.69785049479331579693229238802664L,
42 0.69785049479331579693229238802664L,
43 -0.76777743210482619491797734097450L,
44 0.76777743210482619491797734097450L,
45 -0.82956576238276839744289811973250L,
46 0.82956576238276839744289811973250L,
47 -0.88256053579205268154311646253023L,
48 0.88256053579205268154311646253023L,
49 -0.92620004742927432587932427708047L,
50 0.92620004742927432587932427708047L,
51 -0.96002186496830751221687102558180L,
52 0.96002186496830751221687102558180L,
53 -0.98366812327974720997003258160566L,
54 0.98366812327974720997003258160566L,
55 -0.99689348407464954027163005091870L,
56 0.99689348407464954027163005091870L\
57 };
58
59 static const long double gauss_legendre_30_weights[30] = \
60 {
61 0.10285265289355884034128563670542L,
62 0.10285265289355884034128563670542L,
63 0.10176238974840550459642895216855L,
64 0.10176238974840550459642895216855L,
65 0.09959342058679526706278028210357L,
66 0.09959342058679526706278028210357L,
67 0.09636873717464425963946862635181L,
68 0.09636873717464425963946862635181L,
69 0.09212252223778612871763270708762L,
70 0.09212252223778612871763270708762L,
71 0.08689978720108297980238753071513L,
72 0.08689978720108297980238753071513L,
73 0.08075589522942021535469493846053L,
74 0.08075589522942021535469493846053L,
75 0.07375597473770520626824385002219L,
76 0.07375597473770520626824385002219L,
77 0.06597422988218049512812851511596L,
78 0.06597422988218049512812851511596L,
79 0.05749315621761906648172168940206L,
80 0.05749315621761906648172168940206L,
81 0.04840267283059405290293814042281L,
82 0.04840267283059405290293814042281L,
83 0.03879919256962704959680193644635L,
84 0.03879919256962704959680193644635L,
85 0.02878470788332336934971917961129L,
86 0.02878470788332336934971917961129L,
87 0.01846646831109095914230213191205L,
88 0.01846646831109095914230213191205L,
89 0.00796819249616660561546588347467L,
90 0.00796819249616660561546588347467L\
91 };
File vector/gcem/include/gcem_incl/quadrature/gauss_legendre_50.hpp added (mode: 100644) (index 0000000..7853dc5)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * Gauss-Legendre quadrature: 50 points
23 */
24
25 static const long double gauss_legendre_50_points[50] = \
26 {
27 -0.03109833832718887611232898966595L,
28 0.03109833832718887611232898966595L,
29 -0.09317470156008614085445037763960L,
30 0.09317470156008614085445037763960L,
31 -0.15489058999814590207162862094111L,
32 0.15489058999814590207162862094111L,
33 -0.21600723687604175684728453261710L,
34 0.21600723687604175684728453261710L,
35 -0.27628819377953199032764527852113L,
36 0.27628819377953199032764527852113L,
37 -0.33550024541943735683698825729107L,
38 0.33550024541943735683698825729107L,
39 -0.39341431189756512739422925382382L,
40 0.39341431189756512739422925382382L,
41 -0.44980633497403878914713146777838L,
42 0.44980633497403878914713146777838L,
43 -0.50445814490746420165145913184914L,
44 0.50445814490746420165145913184914L,
45 -0.55715830451465005431552290962580L,
46 0.55715830451465005431552290962580L,
47 -0.60770292718495023918038179639183L,
48 0.60770292718495023918038179639183L,
49 -0.65589646568543936078162486400368L,
50 0.65589646568543936078162486400368L,
51 -0.70155246870682225108954625788366L,
52 0.70155246870682225108954625788366L,
53 -0.74449430222606853826053625268219L,
54 0.74449430222606853826053625268219L,
55 -0.78455583290039926390530519634099L,
56 0.78455583290039926390530519634099L,
57 -0.82158207085933594835625411087394L,
58 0.82158207085933594835625411087394L,
59 -0.85542976942994608461136264393476L,
60 0.85542976942994608461136264393476L,
61 -0.88596797952361304863754098246675L,
62 0.88596797952361304863754098246675L,
63 -0.91307855665579189308973564277166L,
64 0.91307855665579189308973564277166L,
65 -0.93665661894487793378087494727250L,
66 0.93665661894487793378087494727250L,
67 -0.95661095524280794299774564415662L,
68 0.95661095524280794299774564415662L,
69 -0.97286438510669207371334410460625L,
70 0.97286438510669207371334410460625L,
71 -0.98535408404800588230900962563249L,
72 0.98535408404800588230900962563249L,
73 -0.99403196943209071258510820042069L,
74 0.99403196943209071258510820042069L,
75 -0.99886640442007105018545944497422L,
76 0.99886640442007105018545944497422L\
77 };
78
79 static const long double gauss_legendre_50_weights[50] = \
80 {
81 0.06217661665534726232103310736061L,
82 0.06217661665534726232103310736061L,
83 0.06193606742068324338408750978083L,
84 0.06193606742068324338408750978083L,
85 0.06145589959031666375640678608392L,
86 0.06145589959031666375640678608392L,
87 0.06073797084177021603175001538481L,
88 0.06073797084177021603175001538481L,
89 0.05978505870426545750957640531259L,
90 0.05978505870426545750957640531259L,
91 0.05860084981322244583512243663085L,
92 0.05860084981322244583512243663085L,
93 0.05718992564772838372302931506599L,
94 0.05718992564772838372302931506599L,
95 0.05555774480621251762356742561227L,
96 0.05555774480621251762356742561227L,
97 0.05371062188899624652345879725566L,
98 0.05371062188899624652345879725566L,
99 0.05165570306958113848990529584010L,
100 0.05165570306958113848990529584010L,
101 0.04940093844946631492124358075143L,
102 0.04940093844946631492124358075143L,
103 0.04695505130394843296563301363499L,
104 0.04695505130394843296563301363499L,
105 0.04432750433880327549202228683039L,
106 0.04432750433880327549202228683039L,
107 0.04152846309014769742241197896407L,
108 0.04152846309014769742241197896407L,
109 0.03856875661258767524477015023639L,
110 0.03856875661258767524477015023639L,
111 0.03545983561514615416073461100098L,
112 0.03545983561514615416073461100098L,
113 0.03221372822357801664816582732300L,
114 0.03221372822357801664816582732300L,
115 0.02884299358053519802990637311323L,
116 0.02884299358053519802990637311323L,
117 0.02536067357001239044019487838544L,
118 0.02536067357001239044019487838544L,
119 0.02178024317012479298159206906269L,
120 0.02178024317012479298159206906269L,
121 0.01811556071348939035125994342235L,
122 0.01811556071348939035125994342235L,
123 0.01438082276148557441937890892732L,
124 0.01438082276148557441937890892732L,
125 0.01059054838365096926356968149924L,
126 0.01059054838365096926356968149924L,
127 0.00675979919574540150277887817799L,
128 0.00675979919574540150277887817799L,
129 0.00290862255315514095840072434286L,
130 0.00290862255315514095840072434286L\
131 };
File vector/gcem/include/gcem_incl/sgn.hpp added (mode: 100644) (index 0000000..2192d5e)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #ifndef _gcem_sgn_HPP
22 #define _gcem_sgn_HPP
23
24 /**
25 * Compile-time sign function
26 *
27 * @param x a real-valued input
28 * @return a value \f$ y \f$ such that \f[ y = \begin{cases} 1 \ &\text{ if } x > 0 \\ 0 \ &\text{ if } x = 0 \\ -1 \ &\text{ if } x < 0 \end{cases} \f]
29 */
30
31 template<typename T>
32 constexpr
33 int
34 sgn(const T x)
35 noexcept
36 {
37 return( // positive
38 x > T(0) ? 1 :
39 // negative
40 x < T(0) ? -1 :
41 // else
42 0 );
43 }
44
45 #endif
File vector/gcem/include/gcem_incl/sin.hpp added (mode: 100644) (index 0000000..6978bbc)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time sine function using tan(x/2)
23 *
24 * see eq. 5.4.8 in Numerical Recipes
25 */
26
27 #ifndef _gcem_sin_HPP
28 #define _gcem_sin_HPP
29
30 namespace internal
31 {
32
33 template<typename T>
34 constexpr
35 T
36 sin_compute(const T x)
37 noexcept
38 {
39 return T(2)*x/(T(1) + x*x);
40 }
41
42 template<typename T>
43 constexpr
44 T
45 sin_check(const T x)
46 noexcept
47 {
48 return( // indistinguishable from zero
49 GCLIM<T>::epsilon() > abs(x) ? \
50 T(0) :
51 // special cases: pi/2 and pi
52 GCLIM<T>::epsilon() > abs(x - T(GCEM_HALF_PI)) ? \
53 T(1) :
54 GCLIM<T>::epsilon() > abs(x + T(GCEM_HALF_PI)) ? \
55 - T(1) :
56 GCLIM<T>::epsilon() > abs(x - T(GCEM_PI)) ? \
57 T(0) :
58 GCLIM<T>::epsilon() > abs(x + T(GCEM_PI)) ? \
59 - T(0) :
60 // else
61 sin_compute( tan(x/T(2)) ) );
62 }
63
64 }
65
66 /**
67 * Compile-time sine function
68 *
69 * @param x a real-valued input.
70 * @return the sine function using \f[ \sin(x) = \frac{2\tan(x/2)}{1+\tan^2(x/2)} \f]
71 */
72
73 template<typename T>
74 constexpr
75 return_t<T>
76 sin(const T x)
77 noexcept
78 {
79 return internal::sin_check( static_cast<return_t<T>>(x) );
80 }
81
82 #endif
File vector/gcem/include/gcem_incl/sinh.hpp added (mode: 100644) (index 0000000..964f52f)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time hyperbolic sine function
23 */
24
25 #ifndef _gcem_sinh_HPP
26 #define _gcem_sinh_HPP
27
28 namespace internal
29 {
30
31 template<typename T>
32 constexpr
33 T
34 sinh_check(const T x)
35 noexcept
36 {
37 return( // indistinguishable from zero
38 GCLIM<T>::epsilon() > abs(x) ? \
39 T(0) :
40 // else
41 (exp(x) - exp(-x))/T(2) );
42 }
43
44 }
45
46 /**
47 * Compile-time hyperbolic sine function
48 *
49 * @param x a real-valued input.
50 * @return the hyperbolic sine function using \f[ \sinh(x) = \frac{\exp(x) - \exp(-x)}{2} \f]
51 */
52
53 template<typename T>
54 constexpr
55 return_t<T>
56 sinh(const T x)
57 noexcept
58 {
59 return internal::sinh_check( static_cast<return_t<T>>(x) );
60 }
61
62 #endif
File vector/gcem/include/gcem_incl/sqrt.hpp added (mode: 100644) (index 0000000..a6ee3db)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time square-root function
23 */
24
25 #ifndef _gcem_sqrt_HPP
26 #define _gcem_sqrt_HPP
27
28 namespace internal
29 {
30
31 template<typename T>
32 constexpr
33 T
34 sqrt_recur(const T x, const T xn, const int count)
35 noexcept
36 {
37 return( abs(xn - x/xn) / (T(1) + xn) < GCLIM<T>::epsilon() ? \
38 // if
39 xn :
40 count < GCEM_SQRT_MAX_ITER ? \
41 // else
42 sqrt_recur(x,T(0.5)*(xn + x/xn), count+1) :
43 xn );
44 }
45
46 template<typename T>
47 constexpr
48 T
49 sqrt_check(const T x, const T m_val)
50 noexcept
51 {
52 return( // negative values
53 x < T(0) ? \
54 GCLIM<T>::quiet_NaN() :
55 // indistinguishable from zero or one
56 GCLIM<T>::epsilon() > abs(x) ? \
57 T(0) :
58 GCLIM<T>::epsilon() > abs(T(1)-x) ? \
59 x :
60 // else
61 x > T(4) ? \
62 sqrt_check(x/T(4),T(2)*m_val) :
63 m_val*sqrt_recur(x,x/T(2),0) );
64 }
65
66 }
67
68
69 /**
70 * Compile-time square-root function
71 *
72 * @param x a real-valued input.
73 * @return Computes \f$ \sqrt{x} \f$ using a Newton-Raphson approach.
74 */
75
76 template<typename T>
77 constexpr
78 return_t<T>
79 sqrt(const T x)
80 noexcept
81 {
82 return internal::sqrt_check( static_cast<return_t<T>>(x), return_t<T>(1) );
83 }
84
85 #endif
File vector/gcem/include/gcem_incl/tan.hpp added (mode: 100644) (index 0000000..97e3f98)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time tangent function
23 */
24
25 #ifndef _gcem_tan_HPP
26 #define _gcem_tan_HPP
27
28 namespace internal
29 {
30
31 template<typename T>
32 constexpr
33 T
34 tan_series_exp_long(const T z)
35 noexcept
36 { // this is based on a fourth-order expansion of tan(z) using Bernoulli numbers
37 return( - 1/z + (z/3 + (pow_integral(z,3)/45 + (2*pow_integral(z,5)/945 + pow_integral(z,7)/4725))) );
38 }
39
40 template<typename T>
41 constexpr
42 T
43 tan_series_exp(const T x)
44 noexcept
45 {
46 return( GCLIM<T>::epsilon() > abs(x - T(GCEM_HALF_PI)) ? \
47 // the value tan(pi/2) is somewhat of a convention;
48 // technically the function is not defined at EXACTLY pi/2,
49 // but this is floating point pi/2
50 T(1.633124e+16) :
51 // otherwise we use an expansion around pi/2
52 tan_series_exp_long(x - T(GCEM_HALF_PI))
53 );
54 }
55
56 template<typename T>
57 constexpr
58 T
59 tan_cf_recur(const T xx, const int depth, const int max_depth)
60 noexcept
61 {
62 return( depth < max_depth ? \
63 // if
64 T(2*depth - 1) - xx/tan_cf_recur(xx,depth+1,max_depth) :
65 // else
66 T(2*depth - 1) );
67 }
68
69 template<typename T>
70 constexpr
71 T
72 tan_cf_main(const T x)
73 noexcept
74 {
75 return( (x > T(1.55) && x < T(1.60)) ? \
76 tan_series_exp(x) : // deals with a singularity at tan(pi/2)
77 //
78 x > T(1.4) ? \
79 x/tan_cf_recur(x*x,1,45) :
80 x > T(1) ? \
81 x/tan_cf_recur(x*x,1,35) :
82 // else
83 x/tan_cf_recur(x*x,1,25) );
84 }
85
86 template<typename T>
87 constexpr
88 T
89 tan_begin(const T x, const int count = 0)
90 noexcept
91 { // tan(x) = tan(x + pi)
92 return( x > T(GCEM_PI) ? \
93 // if
94 count > 1 ? GCLIM<T>::quiet_NaN() : // protect against undefined behavior
95 tan_begin( x - T(GCEM_PI) * internal::floor(x/T(GCEM_PI)), count+1 ) :
96 // else
97 tan_cf_main(x) );
98 }
99
100 template<typename T>
101 constexpr
102 T
103 tan_check(const T x)
104 noexcept
105 {
106 return( // indistinguishable from zero
107 GCLIM<T>::epsilon() > abs(x) ? \
108 T(0) :
109 // else
110 x < T(0) ? \
111 - tan_begin(-x) :
112 tan_begin( x) );
113 }
114
115 }
116
117 /**
118 * Compile-time tangent function
119 *
120 * @param x a real-valued input.
121 * @return the tangent function using
122 * \f[ \tan(x) = \dfrac{x}{1 - \dfrac{x^2}{3 - \dfrac{x^2}{5 - \ddots}}} \f]
123 * To deal with a singularity at \f$ \pi / 2 \f$, the following expansion is employed:
124 * \f[ \tan(x) = - \frac{1}{x-\pi/2} - \sum_{k=1}^\infty \frac{(-1)^k 2^{2k} B_{2k}}{(2k)!} (x - \pi/2)^{2k - 1} \f]
125 * where \f$ B_n \f$ is the n-th Bernoulli number.
126 */
127
128 template<typename T>
129 constexpr
130 return_t<T>
131 tan(const T x)
132 noexcept
133 {
134 return internal::tan_check( static_cast<return_t<T>>(x) );
135 }
136
137 #endif
File vector/gcem/include/gcem_incl/tanh.hpp added (mode: 100644) (index 0000000..5666cdb)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * compile-time hyperbolic tangent function
23 */
24
25 #ifndef _gcem_tanh_HPP
26 #define _gcem_tanh_HPP
27
28 namespace internal
29 {
30
31 template<typename T>
32 constexpr
33 T
34 tanh_cf(const T xx, const int depth)
35 noexcept
36 {
37 return( depth < GCEM_TANH_MAX_ITER ? \
38 // if
39 (2*depth - 1) + xx/tanh_cf(xx,depth+1) :
40 // else
41 T(2*depth - 1) );
42 }
43
44 template<typename T>
45 constexpr
46 T
47 tanh_begin(const T x)
48 noexcept
49 {
50 return( x/tanh_cf(x*x,1) );
51 }
52
53 template<typename T>
54 constexpr
55 T
56 tanh_check(const T x)
57 noexcept
58 {
59 return( // indistinguishable from zero
60 GCLIM<T>::epsilon() > abs(x) ? \
61 T(0) :
62 // else
63 x < T(0) ? \
64 - tanh_begin(-x) :
65 tanh_begin( x) );
66 }
67
68 }
69
70 /**
71 * Compile-time hyperbolic tangent function
72 *
73 * @param x a real-valued input.
74 * @return the hyperbolic tangent function using \f[ \tanh(x) = \dfrac{x}{1 + \dfrac{x^2}{3 + \dfrac{x^2}{5 + \dfrac{x^2}{7 + \ddots}}}} \f]
75 */
76
77 template<typename T>
78 constexpr
79 return_t<T>
80 tanh(const T x)
81 noexcept
82 {
83 return internal::tanh_check( static_cast<return_t<T>>(x) );
84 }
85
86 #endif
File vector/gcem/include/gcem_incl/tgamma.hpp added (mode: 100644) (index 0000000..b98111f)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 /*
22 * the ('true') gamma function
23 */
24
25 #ifndef _gcem_tgamma_HPP
26 #define _gcem_tgamma_HPP
27
28 namespace internal
29 {
30
31 template<typename T>
32 constexpr
33 T
34 tgamma_check(const T x)
35 noexcept
36 {
37 return( // indistinguishable from one or zero
38 GCLIM<T>::epsilon() > abs(x - T(1)) ? \
39 T(1) :
40 GCLIM<T>::epsilon() > abs(x) ? \
41 GCLIM<T>::quiet_NaN() :
42 // else
43 exp(lgamma(x)));
44 }
45
46 }
47
48 /**
49 * Compile-time gamma function
50 *
51 * @param x a real-valued input.
52 * @return computes the `true' gamma function
53 * \f[ \Gamma(x) = \int_0^\infty y^{x-1} \exp(-y) dy \f]
54 * using a polynomial form:
55 * \f[ \Gamma(x+1) \approx (x+g+0.5)^{x+0.5} \exp(-x-g-0.5) \sqrt{2 \pi} \left[ c_0 + \frac{c_1}{x+1} + \frac{c_2}{x+2} + \cdots + \frac{c_n}{x+n} \right] \f]
56 * where the value \f$ g \f$ and the coefficients \f$ (c_0, c_1, \ldots, c_n) \f$
57 * are taken from Paul Godfrey, whose note can be found here: http://my.fit.edu/~gabdo/gamma.txt
58 */
59
60 template<typename T>
61 constexpr
62 return_t<T>
63 tgamma(const T x)
64 noexcept
65 {
66 return internal::tgamma_check( static_cast<return_t<T>>(x) );
67 }
68
69 #endif
File vector/gcem/notebooks/gcem.ipynb added (mode: 100644) (index 0000000..342bf73)
1 {
2 "cells": [
3 {
4 "cell_type": "markdown",
5 "metadata": {},
6 "source": [
7 "# [GCE-Math](https://github.com/kthohr/gcem)\n",
8 "\n",
9 "\n",
10 "GCE-Math (Generalized Constant Expression Math) is a templated C++ library enabling compile-time computation of mathematical functions.\n",
11 "\n",
12 "* The library is written in C++11 `constexpr` format, and is C++11/14/17 compatible.\n",
13 "* Continued fraction and series expansions are implemented using recursive templates.\n",
14 "* The `gcem::` syntax is identical to the C++ standard library (`std::`).\n",
15 "* Tested and accurate to floating-point precision against the C++ standard library.\n",
16 "* Released under a permissive, non-GPL license.\n",
17 "\n",
18 "**Author**: Keith O'Hara\n",
19 "\n",
20 "<a href=\"https://travis-ci.org/kthohr/gcem/LICENSE\" target=\"_blank\"><img style=\"float: left;\" src=\"https://img.shields.io/badge/Licence-Apache%202.0-blue.svg\" alt=\"License\"></a>\n",
21 "\n",
22 "&nbsp;\n",
23 "\n",
24 "## Coverage and Documentation\n",
25 "\n",
26 "A list of features includes:\n",
27 "\n",
28 "* basic library functions:\n",
29 " - ```abs```, ```exp```, ```log```, ```max```, ```min```, ```pow```, ```sqrt```, ```gcd```, ```lcm```, and more\n",
30 "* trigonometric functions:\n",
31 " - basic: ```cos```, ```sin```, ```tan```\n",
32 " - inverse: ```acos```, ```asin```, ```atan```\n",
33 " - hyperbolic (area) functions: ```cosh```, ```sinh```, ```tanh```, ```acosh```, ```asinh```, ```atanh```\n",
34 "* special functions:\n",
35 " - factorials and the binomial coefficient: ```factorial```, ```binomial_coef```\n",
36 " - beta, gamma, and multivariate gamma functions: ```beta```, ```lbeta```, ```lgamma```, ```tgamma```, ```lmgamma```\n",
37 " - the Gaussian error function and inverse error function: ```erf```, ```erf_inv```\n",
38 " - (regularized) incomplete beta and incomplete gamma functions: ```incomplete_beta```, ```incomplete_gamma```\n",
39 " - inverse incomplete beta and incomplete gamma functions: ```incomplete_beta_inv```, ```incomplete_gamma_inv```\n",
40 "\n",
41 "Full documentation is avaialble online:\n",
42 "\n",
43 "<a href=\"https://gcem.readthedocs.io/en/latest/?badge=latest\" target=\"_blank\"><img style=\"float: left;\" src=\"https://readthedocs.org/projects/gcem/badge/?version=latest\" alt=\"Documentation\"></a> \n",
44 "\n",
45 "&nbsp;\n",
46 "\n",
47 "## This Notebook\n",
48 "\n",
49 "To run a code cell, use `shift + enter`.\n"
50 ]
51 },
52 {
53 "cell_type": "code",
54 "execution_count": 1,
55 "metadata": {},
56 "outputs": [],
57 "source": [
58 "// include libraries\n",
59 "#include <iostream> // for printing\n",
60 "#include \"../include/gcem.hpp\""
61 ]
62 },
63 {
64 "cell_type": "markdown",
65 "metadata": {},
66 "source": [
67 "## Syntax and Examples\n",
68 "\n",
69 "GCE-Math functions are written as C++ templates with `constexpr` specifiers, the format of which might be confusing to users unfamiliar with template-based programming. As an example, the [Gaussian error function](https://en.wikipedia.org/wiki/Error_function) (```erf```) is defined as:\n",
70 "```cpp\n",
71 "template<typename T>\n",
72 "constexpr\n",
73 "return_t<T>\n",
74 "erf(const T x);\n",
75 "```\n",
76 "where a set of internal templated ```constexpr``` functions will implement a continued fraction expansion to return a value of type ```return_t<T>```. This 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."
77 ]
78 },
79 {
80 "cell_type": "code",
81 "execution_count": 2,
82 "metadata": {},
83 "outputs": [
84 {
85 "name": "stdout",
86 "output_type": "stream",
87 "text": [
88 "exp(3) = 20.0855\n",
89 "error = 0\n"
90 ]
91 }
92 ],
93 "source": [
94 "// exponential and natural logarithm functions\n",
95 "\n",
96 "double exp_val_1 = gcem::exp(3);\n",
97 "double log_val_1 = gcem::log(2);\n",
98 "\n",
99 "// compare with the standard library\n",
100 "\n",
101 "double exp_val_2 = std::exp(3);\n",
102 "double log_val_2 = std::log(2);\n",
103 "\n",
104 "std::cout << \"exp(3) = \" << exp_val_1 << std::endl;\n",
105 "std::cout << \"error = \" << gcem::abs(exp_val_1 - exp_val_2) << std::endl;"
106 ]
107 },
108 {
109 "cell_type": "code",
110 "execution_count": 3,
111 "metadata": {},
112 "outputs": [
113 {
114 "name": "stdout",
115 "output_type": "stream",
116 "text": [
117 "sin(pi) = 0\n",
118 "sin(pi/2) = 1\n",
119 "gcem::tan(pi/2) = 1.63312e+16\n",
120 "std::tan(pi/2) = 1.63312e+16\n",
121 "|gcem::tan(0.9) - std::tan(0.9)| = 1.77636e-15\n"
122 ]
123 }
124 ],
125 "source": [
126 "// trig functions\n",
127 "\n",
128 "double pi_dbl = double(GCEM_PI);\n",
129 "double hpi_dbl = double(GCEM_HALF_PI);\n",
130 "\n",
131 "double sin_val_1 = gcem::sin(pi_dbl);\n",
132 "double sin_val_2 = gcem::sin(hpi_dbl);\n",
133 "\n",
134 "std::cout << \"sin(pi) = \" << sin_val_1 << std::endl;\n",
135 "std::cout << \"sin(pi/2) = \" << sin_val_2 << std::endl;\n",
136 "\n",
137 "std::cout << \"gcem::tan(pi/2) = \" << gcem::tan(hpi_dbl) << std::endl;\n",
138 "std::cout << \"std::tan(pi/2) = \" << std::tan(hpi_dbl) << std::endl;\n",
139 "\n",
140 "std::cout << \"|gcem::tan(0.9) - std::tan(0.9)| = \" << gcem::abs(gcem::tan(1.5) - std::tan(1.5)) << std::endl;"
141 ]
142 },
143 {
144 "cell_type": "code",
145 "execution_count": 4,
146 "metadata": {},
147 "outputs": [
148 {
149 "name": "stdout",
150 "output_type": "stream",
151 "text": [
152 "gcem::cosh(0.3) = 1.04534\n",
153 "gcem::acosh(gcem::cosh(0.3)) = 0.3\n"
154 ]
155 }
156 ],
157 "source": [
158 "// hyperbolic functions\n",
159 "\n",
160 "constexpr double cosh_val = gcem::cosh(0.3);\n",
161 "constexpr double inp_val = gcem::acosh(cosh_val);\n",
162 "\n",
163 "std::cout << \"gcem::cosh(0.3) = \" << cosh_val << std::endl;\n",
164 "std::cout << \"gcem::acosh(gcem::cosh(0.3)) = \" << inp_val << std::endl;"
165 ]
166 },
167 {
168 "cell_type": "markdown",
169 "metadata": {},
170 "source": [
171 "### Special Functions\n",
172 "\n",
173 "Special functions are so-called because of their extensive use in mathematics, physics, and statisitcs. Simple examples include the basic trigonometric functions (tan, sin, cos, etc.) and the natural logarithm.\n",
174 "\n",
175 "Of particular interest in statistics are integral equations, like the Gaussian error function and incomplete gamma and beta functions, necessary to calculate cumulative distribution functions."
176 ]
177 },
178 {
179 "cell_type": "code",
180 "execution_count": 5,
181 "metadata": {},
182 "outputs": [],
183 "source": [
184 "// define some storage\n",
185 "double erf_inp_val, erf_val;\n",
186 "double a_par, b_par;\n",
187 "double ig_inp_val, bt_inp_val;\n",
188 "double ig_val, bt_val;"
189 ]
190 },
191 {
192 "cell_type": "code",
193 "execution_count": 6,
194 "metadata": {},
195 "outputs": [
196 {
197 "name": "stdout",
198 "output_type": "stream",
199 "text": [
200 "gcem::erf(1.2) = 0.910314\n",
201 "gcem::incomplete_gamma(3,4) = 0.761897\n",
202 "gcem::incomplete_gamma(6,5,0.7) = 0.849732\n"
203 ]
204 }
205 ],
206 "source": [
207 "// Gaussian error function\n",
208 "erf_inp_val = 1.2;\n",
209 "erf_val = gcem::erf(erf_inp_val);\n",
210 "\n",
211 "std::cout << \"gcem::erf(\" << erf_inp_val << \") = \" << erf_val << std::endl;\n",
212 "\n",
213 "// regularied lower incomplete gamma function\n",
214 "a_par = 3;\n",
215 "ig_inp_val = 4;\n",
216 "\n",
217 "ig_val = gcem::incomplete_gamma(a_par,ig_inp_val);\n",
218 "\n",
219 "std::cout << \"gcem::incomplete_gamma(\" << a_par << \",\" << ig_inp_val << \") = \" << ig_val << std::endl;\n",
220 "\n",
221 "// regularied lower incomplete beta function\n",
222 "a_par = 6;\n",
223 "b_par = 5;\n",
224 "bt_inp_val = 0.7;\n",
225 "\n",
226 "bt_val = gcem::incomplete_beta(a_par,b_par,bt_inp_val);\n",
227 "\n",
228 "std::cout << \"gcem::incomplete_gamma(\" << a_par << \",\" << b_par << \",\" << bt_inp_val << \") = \" << bt_val << std::endl;"
229 ]
230 },
231 {
232 "cell_type": "code",
233 "execution_count": null,
234 "metadata": {},
235 "outputs": [],
236 "source": []
237 }
238 ],
239 "metadata": {
240 "kernelspec": {
241 "display_name": "C++11",
242 "language": "C++11",
243 "name": "xeus-cling-cpp11"
244 },
245 "language_info": {
246 "codemirror_mode": "text/x-c++src",
247 "file_extension": ".cpp",
248 "mimetype": "text/x-c++src",
249 "name": "c++",
250 "version": "-std=c++11"
251 }
252 },
253 "nbformat": 4,
254 "nbformat_minor": 2
255 }
File vector/gcem/tests/CMakeLists.txt added (mode: 100644) (index 0000000..dbe3496)
1 ################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################
20
21 cmake_minimum_required(VERSION 3.1)
22
23 if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
24 project(gcem-test)
25
26 find_package(gcem REQUIRED CONFIG)
27 set(GCEM_INCLUDE_DIR ${gcem_INCLUDE_DIRS})
28 endif ()
29
30 message(STATUS "Forcing tests build type to Release")
31 set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
32
33 include(CheckCXXCompilerFlag)
34
35 #
36
37 if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
38 CHECK_CXX_COMPILER_FLAG("-std=c++11" HAS_CPP11_FLAG)
39 if (HAS_CPP11_FLAG)
40 if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
41 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g -O0 -Wall -Wextra --coverage -fno-inline -fno-inline-small-functions -fno-default-inline")
42 else()
43 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g -O0 -Wall -Wextra --coverage -fno-inline")
44 endif()
45 else()
46 message(FATAL_ERROR "Unsupported compiler -- gcem requires C++11 support!")
47 endif()
48 endif()
49
50 if(MSVC)
51 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP /bigobj")
52 set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO)
53 endif()
54
55 #
56
57 set(GCEM_TESTS
58 acos.cpp
59 acosh.cpp
60 asin.cpp
61 asinh.cpp
62 atan.cpp
63 atan2.cpp
64 atanh.cpp
65 binomial_coef.cpp
66 cos.cpp
67 cosh.cpp
68 erf.cpp
69 erf_inv.cpp
70 exp.cpp
71 expm1.cpp
72 factorial.cpp
73 gcd.cpp
74 incomplete_beta.cpp
75 incomplete_beta_inv.cpp
76 incomplete_gamma.cpp
77 incomplete_gamma_inv.cpp
78 is_odd.cpp
79 lcm.cpp
80 lgamma.cpp
81 log.cpp
82 log1p.cpp
83 log_binomial_coef.cpp
84 other.cpp
85 pow.cpp
86 sin.cpp
87 sinh.cpp
88 sqrt.cpp
89 tan.cpp
90 tanh.cpp
91 )
92
93 #
94
95 set(GCEM_TESTS_EX "")
96
97 foreach( file_ ${GCEM_TESTS} )
98 string( REPLACE ".cpp" ".test" testname ${file_} )
99
100 add_executable( ${testname} EXCLUDE_FROM_ALL ${file_} ${GCEM_HEADERS})
101 target_link_libraries( ${testname} gcem )
102
103 list(APPEND GCEM_TESTS_EX ${testname})
104 endforeach()
105
106 add_custom_target(gcem_tests DEPENDS ${GCEM_TESTS_EX})
107
108 #
File vector/gcem/tests/Makefile added (mode: 100644) (index 0000000..f7a9ffb)
1 # GCEM Test build
2
3 ifeq ($(CXX),)
4 CXX = g++
5 endif
6
7 CXX_STD = -std=c++11
8
9 ifneq (,$(findstring clang,$(CXX)))
10 OPT_FLAGS = -g -O0 -Wall -Wextra --coverage -fno-inline
11 else
12 OPT_FLAGS = -g -O0 -Wall -Wextra --coverage -fno-inline -fno-inline-small-functions -fno-default-inline
13 endif
14
15 # source directories
16 SDIR = .
17 HEADER_DIR = $(SDIR)/../include
18
19 SOURCES_TESTS= $(wildcard $(SDIR)/*.cpp)
20 OBJECTS_TESTS= $(SOURCES_TESTS:.cpp=.test)
21
22 all: $(OBJECTS_TESTS)
23
24 $(SDIR)/%.test: $(SDIR)/%.cpp
25 $(CXX) $(CXX_STD) $(OPT_FLAGS) -I$(HEADER_DIR) $< -o $@ $(LIBS)
26
27 # cleanup and install
28 .PHONY: clean
29 clean:
30 @rm -rf *.test *.gcov *.gcno *.gcda *.dSYM
File vector/gcem/tests/acos.cpp added (mode: 100644) (index 0000000..34b722e)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin acos test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double)> test_fn = gcem::acos<long double>;
30 std::string test_fn_name = "gcem::acos";
31
32 std::function<long double (long double)> std_fn = [] (long double x) -> long double { return std::acos(x); };
33 std::string std_fn_name = "std::acos";
34
35 //
36
37 static constexpr long double test_vals[] = { 0.0L, 0.001L, 0.5L, -0.5L, 0.7568025L, 1.0L, 5.0L };
38
39 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,0,test_fn,std_fn,true," ",6,18,false,false);
40 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,1,test_fn,std_fn,true," ",6,18,false,false);
41 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,2,test_fn,std_fn,true," ",6,18,false,false);
42 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,3,test_fn,std_fn,true," ",6,18,false,false);
43 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,4,test_fn,std_fn,true," ",6,18,false,false);
44 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,5,test_fn,std_fn,true," ",6,18,false,false);
45 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,6,test_fn,std_fn,false," ",6,18,false,true);
46
47 //
48
49 std::cout << "\n*** end acos test ***\n" << std::endl;
50
51 return 0;
52 }
File vector/gcem/tests/acosh.cpp added (mode: 100644) (index 0000000..dd13d2a)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin acosh test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double)> test_fn = gcem::acosh<long double>;
30 std::string test_fn_name = "gcem::acosh";
31
32 std::function<long double (long double)> std_fn = [] (long double x) -> long double { return std::acosh(x); };
33 std::string std_fn_name = "std::acosh";
34
35 //
36
37 static constexpr long double test_vals[] = { 1.001L, 1.5L, 11.1L, 50.0L, 0.5L };
38
39 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,0,test_fn,std_fn,true," ",6,18,false,false);
40 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,1,test_fn,std_fn,true," ",6,18,false,false);
41 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,2,test_fn,std_fn,true," ",6,18,false,false);
42 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,3,test_fn,std_fn,true," ",6,18,false,false);
43 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,4,test_fn,std_fn,false," ",6,18,false,true);
44
45 //
46
47 std::cout << "\n*** end acosh test ***\n" << std::endl;
48
49 return 0;
50 }
File vector/gcem/tests/asin.cpp added (mode: 100644) (index 0000000..01e00cf)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin asin test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double)> test_fn = gcem::asin<long double>;
30 std::string test_fn_name = "gcem::asin";
31
32 std::function<long double (long double)> std_fn = [] (long double x) -> long double { return std::asin(x); };
33 std::string std_fn_name = "std::asin";
34
35 //
36
37 static constexpr long double test_vals[] = { 0.0L, 0.001L, 0.5L, -0.5L, 0.7568025L, 1.0L, 5.0L };
38
39 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,0,test_fn,std_fn,true," ",6,18,false,false);
40 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,1,test_fn,std_fn,true," ",6,18,false,false);
41 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,2,test_fn,std_fn,true," ",6,18,false,false);
42 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,3,test_fn,std_fn,true," ",6,18,false,false);
43 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,4,test_fn,std_fn,true," ",6,18,false,false);
44 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,5,test_fn,std_fn,true," ",6,18,false,false);
45 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,6,test_fn,std_fn,false," ",6,18,false,true);
46
47 //
48
49 std::cout << "\n*** end asin test ***\n" << std::endl;
50
51 return 0;
52 }
File vector/gcem/tests/asinh.cpp added (mode: 100644) (index 0000000..3a1bbe8)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin asinh test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double)> test_fn = gcem::asinh<long double>;
30 std::string test_fn_name = "gcem::asinh";
31
32 std::function<long double (long double)> std_fn = [] (long double x) -> long double { return std::asinh(x); };
33 std::string std_fn_name = "std::asinh";
34
35 //
36
37 static constexpr long double test_vals[] = { 0.0L, 0.001L, 1.001L, 1.5L, 11.1L, 50.0L, -1.5L };
38
39 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,0,test_fn,std_fn,true," ",6,18,false,false);
40 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,1,test_fn,std_fn,true," ",6,18,false,false);
41 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,2,test_fn,std_fn,true," ",6,18,false,false);
42 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,3,test_fn,std_fn,true," ",6,18,false,false);
43 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,4,test_fn,std_fn,true," ",6,18,false,false);
44 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,5,test_fn,std_fn,true," ",6,18,false,false);
45 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,6,test_fn,std_fn,false," ",6,18,false,false);
46
47 //
48
49 std::cout << "\n*** end asinh test ***\n" << std::endl;
50
51 return 0;
52 }
File vector/gcem/tests/atan.cpp added (mode: 100644) (index 0000000..ed1a1c4)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin atan test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double)> test_fn = gcem::atan<long double>;
30 std::string test_fn_name = "gcem::atan";
31
32 std::function<long double (long double)> std_fn = [] (long double x) -> long double { return std::atan(x); };
33 std::string std_fn_name = "std::atan";
34
35 //
36
37 static constexpr long double test_vals[] = { 0.0L, 0.001L, 0.49L, -0.5L, -1.5L, 0.7568025L, 0.99L, 1.49L, 1.99L, \
38 2.49L, 2.51L, 3.99L, 7.0L, 11.0L, 25.0L, 101.0L, 900.0L, 1001.0L };
39
40 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,0,test_fn,std_fn,true," ",6,18,false,false);
41 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,1,test_fn,std_fn,true," ",6,18,false,false);
42 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,2,test_fn,std_fn,true," ",6,18,false,false);
43 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,3,test_fn,std_fn,true," ",6,18,false,false);
44 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,4,test_fn,std_fn,true," ",6,18,false,false);
45 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,5,test_fn,std_fn,true," ",6,18,false,false);
46 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,6,test_fn,std_fn,true," ",6,18,false,false);
47 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,7,test_fn,std_fn,true," ",6,18,false,false);
48 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,8,test_fn,std_fn,true," ",6,18,false,false);
49 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,9,test_fn,std_fn,true," ",6,18,false,false);
50 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,10,test_fn,std_fn,true," ",6,18,false,false);
51 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,11,test_fn,std_fn,true," ",6,18,false,false);
52 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,12,test_fn,std_fn,true," ",6,18,false,false);
53 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,13,test_fn,std_fn,true," ",6,18,false,false);
54 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,14,test_fn,std_fn,true," ",6,18,false,false);
55 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,15,test_fn,std_fn,true," ",6,18,false,false);
56 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,16,test_fn,std_fn,true," ",6,18,false,false);
57 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,17,test_fn,std_fn,false," ",6,18,false,false);
58
59 std::cout << "\n*** end atan test ***\n" << std::endl;
60
61 return 0;
62 }
File vector/gcem/tests/atan2.cpp added (mode: 100644) (index 0000000..5a4a4f2)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin atan2 test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double,long double)> test_fn = gcem::atan2<long double,long double>;
30 std::string test_fn_name = "gcem::atan2";
31
32 std::function<long double (long double, long double)> std_fn = [] (long double x, long double y) -> long double { return std::atan2(x,y); };
33 std::string std_fn_name = "std::atan2";
34
35 //
36
37 static constexpr long double test_vals_1[] = { 0.0L, -0.0L, 0.0L, -0.0L, 0.2L, -0.2L, 0.001L, 0.49L, -0.5L, 0.5L, -0.5L, \
38 9.6L, 1.0L, 0.0L, -1.0L, 0.0L, 1.0L, -5.0L, -1000.0L, 0.1337L };
39
40 static constexpr long double test_vals_2[] = { 0.0L, 0.0L, -0.0L, -0.0L, 0.0L, 0.0L, 0.001L, 0.49L, -0.5L, -0.5L, 0.5L, \
41 8.4L, 0.0L, 1.0L, 0.0L, -1.0L, 3.0L, 2.5L, -0.001L, -123456.0L };
42
43 PRINT_TEST_2_COMPARE(test_fn_name,std_fn_name,test_vals_1,test_vals_2,0,test_fn,std_fn,true," ",6,18,false,false);
44 PRINT_TEST_2_COMPARE(test_fn_name,std_fn_name,test_vals_1,test_vals_2,1,test_fn,std_fn,true," ",6,18,false,false);
45 PRINT_TEST_2_COMPARE(test_fn_name,std_fn_name,test_vals_1,test_vals_2,2,test_fn,std_fn,true," ",6,18,false,false);
46 PRINT_TEST_2_COMPARE(test_fn_name,std_fn_name,test_vals_1,test_vals_2,3,test_fn,std_fn,true," ",6,18,false,false);
47 PRINT_TEST_2_COMPARE(test_fn_name,std_fn_name,test_vals_1,test_vals_2,4,test_fn,std_fn,true," ",6,18,false,false);
48 PRINT_TEST_2_COMPARE(test_fn_name,std_fn_name,test_vals_1,test_vals_2,5,test_fn,std_fn,true," ",6,18,false,false);
49 PRINT_TEST_2_COMPARE(test_fn_name,std_fn_name,test_vals_1,test_vals_2,6,test_fn,std_fn,true," ",6,18,false,false);
50 PRINT_TEST_2_COMPARE(test_fn_name,std_fn_name,test_vals_1,test_vals_2,7,test_fn,std_fn,true," ",6,18,false,false);
51 PRINT_TEST_2_COMPARE(test_fn_name,std_fn_name,test_vals_1,test_vals_2,8,test_fn,std_fn,true," ",6,18,false,false);
52 PRINT_TEST_2_COMPARE(test_fn_name,std_fn_name,test_vals_1,test_vals_2,9,test_fn,std_fn,true," ",6,18,false,false);
53 PRINT_TEST_2_COMPARE(test_fn_name,std_fn_name,test_vals_1,test_vals_2,10,test_fn,std_fn,true," ",6,18,false,false);
54 PRINT_TEST_2_COMPARE(test_fn_name,std_fn_name,test_vals_1,test_vals_2,11,test_fn,std_fn,true," ",6,18,false,false);
55 PRINT_TEST_2_COMPARE(test_fn_name,std_fn_name,test_vals_1,test_vals_2,12,test_fn,std_fn,true," ",6,18,false,false);
56 PRINT_TEST_2_COMPARE(test_fn_name,std_fn_name,test_vals_1,test_vals_2,13,test_fn,std_fn,true," ",6,18,false,false);
57 PRINT_TEST_2_COMPARE(test_fn_name,std_fn_name,test_vals_1,test_vals_2,14,test_fn,std_fn,true," ",6,18,false,false);
58 PRINT_TEST_2_COMPARE(test_fn_name,std_fn_name,test_vals_1,test_vals_2,15,test_fn,std_fn,true," ",6,18,false,false);
59 PRINT_TEST_2_COMPARE(test_fn_name,std_fn_name,test_vals_1,test_vals_2,16,test_fn,std_fn,true," ",6,18,false,false);
60 PRINT_TEST_2_COMPARE(test_fn_name,std_fn_name,test_vals_1,test_vals_2,17,test_fn,std_fn,true," ",6,18,false,false);
61 PRINT_TEST_2_COMPARE(test_fn_name,std_fn_name,test_vals_1,test_vals_2,18,test_fn,std_fn,true," ",6,18,false,false);
62 PRINT_TEST_2_COMPARE(test_fn_name,std_fn_name,test_vals_1,test_vals_2,19,test_fn,std_fn,false," ",6,18,false,false);
63
64 std::cout << "\n*** end atan2 test ***\n" << std::endl;
65
66 return 0;
67 }
File vector/gcem/tests/atanh.cpp added (mode: 100644) (index 0000000..d50a866)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin atanh test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double)> test_fn = gcem::atanh<long double>;
30 std::string test_fn_name = "gcem::atanh";
31
32 std::function<long double (long double)> std_fn = [] (long double x) -> long double { return std::atanh(x); };
33 std::string std_fn_name = "std::atanh";
34
35 //
36
37 static constexpr long double test_vals[] = { -0.99L, 0.0L, 0.001L, 1.0L, -1.0L, 1.1L };
38
39 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,0,test_fn,std_fn,true," ",3,18,false,false);
40 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,1,test_fn,std_fn,true," ",3,18,false,false);
41 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,2,test_fn,std_fn,true," ",3,18,false,false);
42 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,3,test_fn,std_fn,true," ",3,18,true,false);
43 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,4,test_fn,std_fn,true," ",3,18,true,false);
44 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,5,test_fn,std_fn,false," ",3,18,false,true);
45
46 //
47
48 std::cout << "\n*** end atanh test ***\n" << std::endl;
49
50 return 0;
51 }
File vector/gcem/tests/binomial_coef.cpp added (mode: 100644) (index 0000000..1e16a3b)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin binomial_coef test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double, long double)> test_fn = gcem::binomial_coef<long double, long double>;
30 std::string test_fn_name = "gcem::binomial_coef";
31
32 //
33
34 static constexpr long double test_vals_1[] = { 0.0L, 0.0L, 1.0L, 1.0L, 5.0L, 10.0L, 10.0L, 10.0L };
35 static constexpr long double test_vals_2[] = { 0.0L, 1.0L, 0.0L, 1.0L, 2.0L, 8.0L, 9.0L, 10.0L };
36
37 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,0,test_fn,1.0L,true,"",2,2,false,false);
38 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,1,test_fn,0.0L,true,"",2,2,false,false);
39 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,2,test_fn,1.0L,true,"",2,2,false,false);
40 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,3,test_fn,1.0L,true,"",2,2,false,false);
41 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,4,test_fn,10.0L,true,"",2,2,false,false);
42 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,5,test_fn,45.0L,true,"",2,2,false,false);
43 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,6,test_fn,10.0L,true,"",2,2,false,false);
44 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,7,test_fn,1.0L,false,"",2,2,false,false);
45
46 //
47
48 std::cout << "\n*** end binomial_coef test ***\n" << std::endl;
49
50 return 0;
51 }
File vector/gcem/tests/cos.cpp added (mode: 100644) (index 0000000..d48da52)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin cos test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double)> test_fn = gcem::cos<long double>;
30 std::string test_fn_name = "gcem::cos";
31
32 std::function<long double (long double)> std_fn = [] (long double x) -> long double { return std::cos(x); };
33 std::string std_fn_name = "std::cos";
34
35 //
36
37 static constexpr long double test_vals[] = { -1.5L, 0.0L, 0.001L, 1.001L, 1.5L, 11.1L, 50.0L, 150.0L };
38
39 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,0,test_fn,std_fn,true," ",3,18,false,false);
40 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,1,test_fn,std_fn,true," ",3,18,false,false);
41 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,2,test_fn,std_fn,true," ",3,18,false,false);
42 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,3,test_fn,std_fn,true," ",3,18,false,false);
43 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,4,test_fn,std_fn,true," ",3,18,false,false);
44 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,5,test_fn,std_fn,true," ",3,18,false,false);
45 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,6,test_fn,std_fn,true," ",3,18,false,false);
46 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,7,test_fn,std_fn,false," ",3,18,false,false);
47
48 //
49
50 std::cout << "\n*** end cos test ***\n" << std::endl;
51
52 return 0;
53 }
File vector/gcem/tests/cosh.cpp added (mode: 100644) (index 0000000..b5b7369)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin cosh test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double)> test_fn = gcem::cosh<long double>;
30 std::string test_fn_name = "gcem::cosh";
31
32 std::function<long double (long double)> std_fn = [] (long double x) -> long double { return std::cosh(x); };
33 std::string std_fn_name = "std::cosh";
34
35 //
36
37 static constexpr long double test_vals[] = { 0.0L, 0.001L, 0.5L, -0.5L, 0.7568025L, 1.0L, 5.0L };
38
39 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,0,test_fn,std_fn,true," ",6,18,false,false);
40 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,1,test_fn,std_fn,true," ",6,18,false,false);
41 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,2,test_fn,std_fn,true," ",6,18,false,false);
42 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,3,test_fn,std_fn,true," ",6,18,false,false);
43 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,4,test_fn,std_fn,true," ",6,18,false,false);
44 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,5,test_fn,std_fn,true," ",6,18,false,false);
45 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,6,test_fn,std_fn,false," ",6,18,false,false);
46
47 //
48
49 std::cout << "\n*** end cosh test ***\n" << std::endl;
50
51 return 0;
52 }
File vector/gcem/tests/cov_check added (mode: 100755) (index 0000000..6590fda)
1
2 echo "SHOULD_RUN_COVERAGE: ${SHOULD_RUN_COVERAGE}"
3
4 if [[ "${SHOULD_RUN_COVERAGE}" == "y" ]]; then
5
6 if [ -z ${CCOV+x} ]; then
7 CCOV=gcov
8 fi
9
10 echo "CCOV set to ${CCOV}"
11
12 for t in ./*.cpp; do
13 $CCOV "$t" > /dev/null 2>&1
14 done
15 fi
File vector/gcem/tests/erf.cpp added (mode: 100644) (index 0000000..3902bf3)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin erf test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double)> test_fn = gcem::erf<long double>;
30 std::string test_fn_name = "gcem::erf";
31
32 std::function<long double (long double)> std_fn = [] (long double x) -> long double { return std::erf(x); };
33 std::string std_fn_name = "std::erf";
34
35 //
36
37 static constexpr long double test_vals[] = { -3.0L, -2.5L, -2.11L, -2.05L, -1.3L, 0.0L, 1.3L, 2.05L, 2.11L, 2.5L, 3.1L };
38
39 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,0,test_fn,std_fn,true," ",3,18,false,false);
40 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,1,test_fn,std_fn,true," ",3,18,false,false);
41 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,2,test_fn,std_fn,true," ",3,18,false,false);
42 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,3,test_fn,std_fn,true," ",3,18,false,false);
43 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,4,test_fn,std_fn,true," ",3,18,false,false);
44 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,5,test_fn,std_fn,true," ",3,18,false,false);
45 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,6,test_fn,std_fn,true," ",3,18,false,false);
46 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,7,test_fn,std_fn,true," ",3,18,false,false);
47 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,8,test_fn,std_fn,true," ",3,18,false,false);
48 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,9,test_fn,std_fn,true," ",3,18,false,false);
49 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,10,test_fn,std_fn,false," ",3,18,false,false);
50
51 //
52
53 std::cout << "\n*** end erf test ***\n" << std::endl;
54
55 return 0;
56 }
File vector/gcem/tests/erf_inv.cpp added (mode: 100644) (index 0000000..3303292)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin erf_inv test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double)> test_fn = gcem::erf_inv<long double>;
30 std::string test_fn_name = "gcem::erf_inv";
31
32 //
33
34 static constexpr long double test_vals[] = { -0.999977909503001415L, \
35 -0.999593047982555041L, \
36 -0.997154845031177802L, \
37 -0.996258096044456873L, \
38 -0.934007944940652437L, \
39 0.0L, \
40 0.934007944940652437L, \
41 0.996258096044456873L, \
42 0.997154845031177802L, \
43 0.999593047982555041L, \
44 0.999988351342632800L};
45
46 static constexpr long double results[] = { -3.0L, -2.5L, -2.11L, -2.05L, -1.3L, 0.0L, 1.3L, 2.05L, 2.11L, 2.5L, 3.1L };
47
48 PRINT_TEST_1_EXPECT(test_fn_name,test_vals,0,test_fn,results[0],true," ",6,18,false,false);
49 PRINT_TEST_1_EXPECT(test_fn_name,test_vals,1,test_fn,results[1],true," ",6,18,false,false);
50 PRINT_TEST_1_EXPECT(test_fn_name,test_vals,2,test_fn,results[2],true," ",6,18,false,false);
51 PRINT_TEST_1_EXPECT(test_fn_name,test_vals,3,test_fn,results[3],true," ",6,18,false,false);
52 PRINT_TEST_1_EXPECT(test_fn_name,test_vals,4,test_fn,results[4],true," ",6,18,false,false);
53 PRINT_TEST_1_EXPECT(test_fn_name,test_vals,5,test_fn,results[5],true," ",6,18,false,false);
54 PRINT_TEST_1_EXPECT(test_fn_name,test_vals,6,test_fn,results[6],true," ",6,18,false,false);
55 PRINT_TEST_1_EXPECT(test_fn_name,test_vals,7,test_fn,results[7],true," ",6,18,false,false);
56 PRINT_TEST_1_EXPECT(test_fn_name,test_vals,8,test_fn,results[8],true," ",6,18,false,false);
57 PRINT_TEST_1_EXPECT(test_fn_name,test_vals,9,test_fn,results[9],true," ",6,18,false,false);
58 PRINT_TEST_1_EXPECT(test_fn_name,test_vals,10,test_fn,results[10],false," ",6,18,false,false);
59
60 //
61
62 std::cout << "\n*** end inv_erf test ***\n" << std::endl;
63
64 return 0;
65 }
File vector/gcem/tests/exp.cpp added (mode: 100644) (index 0000000..b3ddd44)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin exp test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double)> test_fn = gcem::exp<long double>;
30 std::string test_fn_name = "gcem::exp";
31
32 std::function<long double (long double)> std_fn = [] (long double x) -> long double { return std::exp(x); };
33 std::string std_fn_name = "std::exp";
34
35 //
36
37 static constexpr long double test_vals[] = { -40.0L, -4.0L, 0.0001L, 1.75L, 1.9991L, 2.10L, 4.0L,
38 - std::numeric_limits<long double>::infinity(),
39 std::numeric_limits<long double>::infinity(),
40 std::numeric_limits<long double>::quiet_NaN() };
41
42 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,0,test_fn,std_fn,true," ",5,18,false,false);
43 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,1,test_fn,std_fn,true," ",5,18,false,false);
44 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,2,test_fn,std_fn,true," ",5,18,false,false);
45 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,3,test_fn,std_fn,true," ",5,18,false,false);
46 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,4,test_fn,std_fn,true," ",5,18,false,false);
47 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,5,test_fn,std_fn,true," ",5,18,false,false);
48 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,6,test_fn,std_fn,true," ",5,18,false,false);
49 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,7,test_fn,std_fn,true," ",5,18,false,false);
50 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,8,test_fn,std_fn,true," ",5,18,true,false);
51 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,9,test_fn,std_fn,false," ",5,18,false,true);
52
53 //
54
55 std::cout << "\n*** end exp test ***\n" << std::endl;
56
57 return 0;
58 }
File vector/gcem/tests/expm1.cpp added (mode: 100644) (index 0000000..90d5656)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin expm1 test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double)> test_fn = gcem::expm1<long double>;
30 std::string test_fn_name = "gcem::expm1";
31
32 std::function<long double (long double)> std_fn = [] (long double x) -> long double { return std::expm1(x); };
33 std::string std_fn_name = "std::expm1";
34
35 //
36
37 static constexpr long double test_vals[] = { 1.0L, 0.0L, 1e-04L, -1e-04L, 1e-05L, 1e-06L, 1e-22L };
38
39 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,0,test_fn,std_fn,true," ",5,18,false,false);
40 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,1,test_fn,std_fn,true," ",5,18,false,false);
41 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,2,test_fn,std_fn,true," ",5,18,false,false);
42 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,3,test_fn,std_fn,true," ",5,18,false,false);
43 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,4,test_fn,std_fn,true," ",5,18,false,false);
44 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,5,test_fn,std_fn,true," ",5,18,false,false);
45 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,6,test_fn,std_fn,false," ",5,18,false,false);
46
47 //
48
49 std::cout << "\n*** end expm1 test ***\n" << std::endl;
50
51 return 0;
52 }
File vector/gcem/tests/factorial.cpp added (mode: 100644) (index 0000000..4d279f7)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #define TEST_ERR_TOL 1e-02
22 #include "gcem_tests.hpp"
23
24 int main()
25 {
26 std::cout << "\n*** begin factorial test ***\n" << std::endl;
27
28 //
29
30 std::function<long double (long double)> test_fn_int = [] (long double x) -> long double \
31 { return static_cast<long double>(gcem::factorial<size_t>(size_t(x))); };
32 std::function<long double (long double)> test_fn_dbl = gcem::factorial<long double>;
33 std::string test_fn_name = "gcem::factorial";
34
35 std::function<long double (long double)> std_fn = [] (long double x) -> long double { return std::tgamma(x+1); };
36 std::string std_fn_name = "std::tgamma";
37
38 //
39
40 static constexpr long double test_vals[] = { 3.1L, 5.0L, 7.0L, 9.0L, 10.0L, 11.0L, 12.0L, 13.0L, 14.0L, 15.0L, 16.0L };
41
42 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,0,test_fn_dbl,std_fn,true," ",2,18,false,false);
43 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,1,test_fn_int,std_fn,true," ",2,2,false,false);
44 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,2,test_fn_dbl,std_fn,true," ",2,2,false,false);
45 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,3,test_fn_int,std_fn,true," ",2,2,false,false);
46 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,4,test_fn_dbl,std_fn,true," ",2,2,false,false);
47 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,5,test_fn_int,std_fn,true," ",2,2,false,false);
48 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,6,test_fn_dbl,std_fn,true," ",2,2,false,false);
49 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,7,test_fn_int,std_fn,true," ",2,2,false,false);
50 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,8,test_fn_dbl,std_fn,true," ",2,2,false,false);
51 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,9,test_fn_dbl,std_fn,true," ",2,2,false,false);
52 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,10,test_fn_int,std_fn,false," ",2,2,false,false);
53
54 //
55
56 std::cout << "\n*** end factorial test ***\n" << std::endl;
57
58 return 0;
59 }
File vector/gcem/tests/gcd.cpp added (mode: 100644) (index 0000000..88eca61)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #define TEST_VAL_TYPES int
22
23 #include "gcem_tests.hpp"
24
25 int main()
26 {
27 std::cout << "\n*** begin gcd test ***\n" << std::endl;
28
29 //
30
31 std::function<int (int, int)> test_fn = gcem::gcd<int,int>;
32 std::string test_fn_name = "gcem::gcd";
33
34 //
35
36 static constexpr int test_vals_1[] = { 12, -4, 42 }; // shape
37 static constexpr int test_vals_2[] = { 18, 14, 56 }; // x
38
39 static constexpr int expected_vals[] = { 6, 2, 14 };
40
41 //
42
43 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,0,test_fn,expected_vals[0],true,"",3,18,false,false);
44 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,1,test_fn,expected_vals[1],true,"",3,18,false,false);
45 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,2,test_fn,expected_vals[2],false,"",3,18,false,false);
46
47 //
48
49 std::cout << "\n*** end gcd test ***\n" << std::endl;
50
51 return 0;
52 }
File vector/gcem/tests/gcem_tests.hpp added (mode: 100644) (index 0000000..f063713)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include <cmath>
22 #include <iostream>
23 #include <iomanip>
24 #include <string>
25 #include <functional>
26
27 #include "gcem.hpp"
28
29 //
30 // tolerance
31
32 #ifndef TEST_VAL_TYPES
33 #define TEST_VAL_TYPES long double
34 #define TEST_VAL_TYPES_V 1
35 #endif
36
37 #ifndef TEST_ERR_TOL
38 #ifdef _WIN32
39 #define TEST_ERR_TOL 1e-10
40 #else
41 #define TEST_ERR_TOL 1e-14
42 #endif
43 #endif
44
45 #ifdef TEST_VAL_TYPES_V
46 #define PRINT_ERR(err_val) \
47 { \
48 printf(" error value = %LE.", err_val); \
49 }
50 #else
51 #define PRINT_ERR(err_val) \
52 { \
53 printf(" error value = %d.", err_val); \
54 }
55 #endif
56
57 #ifdef TEST_VAL_TYPES_V
58 #define TEST_IS_INF(val) std::isinf(val)
59 #define TEST_IS_NAN(val) std::isnan(val)
60 #else
61 #define TEST_IS_INF(val) false
62 #define TEST_IS_NAN(val) false
63 #endif
64
65 //
66 // one input
67
68 template<typename T>
69 inline
70 T
71 print_test_1(const std::string fn_name, const T val_inp_1, std::function<T (const T val_inp)> fn_eval,
72 const bool new_line=false, const std::string extra_space="",
73 const int precision_1=2, const int precision_2=18)
74 {
75 T f_val = fn_eval(val_inp_1);
76 std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(precision_1) << fn_name \
77 << "(" << val_inp_1 << ")" << extra_space << " = " \
78 << std::setprecision(precision_2) << f_val << std::endl;
79 if (new_line) std::cout << std::endl;
80 return f_val;
81 }
82
83 #define PRINT_TEST_1_EXPECT(fn_name, vals_inp, j, fn_eval, expected_val, \
84 new_line, extra_space, \
85 precision_1, precision_2, is_inf, is_nan) \
86 { \
87 constexpr TEST_VAL_TYPES val_1 = vals_inp[j]; \
88 \
89 TEST_VAL_TYPES f_val = print_test_1(fn_name,val_1,fn_eval,false,extra_space,precision_1,precision_2); \
90 \
91 bool test_pass = false; \
92 \
93 printf(" -"); \
94 if (!is_nan && !is_inf) { \
95 TEST_VAL_TYPES err_val = std::abs(f_val - expected_val); \
96 PRINT_ERR(err_val); \
97 test_pass = (err_val < TEST_ERR_TOL) ? true : false; \
98 } else if (is_nan) { \
99 if (TEST_IS_NAN(f_val)) { \
100 test_pass = true; \
101 } \
102 } else if (is_inf) { \
103 if (TEST_IS_INF(f_val)) { \
104 test_pass = true; \
105 } \
106 } else { \
107 printf("unknown error!"); \
108 } \
109 \
110 if (test_pass) { \
111 std::cout << "\033[32m OK.\033[0m" << std::endl; \
112 } else { \
113 std::cout << "\033[31m FAIL.\033[0m" << std::endl; \
114 } \
115 \
116 if (new_line) std::cout << std::endl; \
117 } \
118 \
119
120 #define PRINT_TEST_1_COMPARE(fn_name_1, fn_name_2, vals_inp, j, \
121 fn_eval_1, fn_eval_2, new_line, extra_space, \
122 precision_1, precision_2, is_inf, is_nan) \
123 { \
124 constexpr TEST_VAL_TYPES c_val = vals_inp[j]; \
125 TEST_VAL_TYPES x_val = vals_inp[j]; \
126 \
127 TEST_VAL_TYPES f_val_1 = print_test_1(fn_name_1,c_val,fn_eval_1,false,"",precision_1,precision_2); \
128 TEST_VAL_TYPES f_val_2 = print_test_1(fn_name_2,x_val,fn_eval_2,false,extra_space,precision_1,precision_2); \
129 \
130 bool test_pass = false; \
131 \
132 printf(" -"); \
133 if (!is_nan && !is_inf) { \
134 TEST_VAL_TYPES err_val = std::abs(f_val_1 - f_val_2); \
135 PRINT_ERR(err_val); \
136 test_pass = (err_val < TEST_ERR_TOL) ? true : false; \
137 } else if (is_nan) { \
138 if (std::isnan(f_val_1) && std::isnan(f_val_2)) { \
139 test_pass = true; \
140 } \
141 } else if (is_inf) { \
142 if (std::isinf(f_val_1) && std::isinf(f_val_2)) { \
143 test_pass = true; \
144 } \
145 } else { \
146 printf("unknown error!"); \
147 } \
148 \
149 if (test_pass) { \
150 std::cout << "\033[32m OK.\033[0m" << std::endl; \
151 } else { \
152 std::cout << "\033[31m FAIL.\033[0m" << std::endl; \
153 } \
154 \
155 if (new_line) std::cout << std::endl; \
156 } \
157
158 //
159 // two inputs
160
161 template<typename T>
162 inline
163 T
164 print_test_2(const std::string fn_name, const T val_inp_1, const T val_inp_2, std::function<T (const T val_inp, const T par_inp)> fn_eval,
165 const bool new_line=false, const std::string extra_space="",
166 const int precision_1=2, const int precision_2=18)
167 {
168 T f_val = fn_eval(val_inp_1,val_inp_2);
169 std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(precision_1) << fn_name \
170 << "(" << val_inp_1 << "," << val_inp_2 << ")" << extra_space << " = " \
171 << std::setprecision(precision_2) << f_val << std::endl;
172 if (new_line) std::cout << std::endl;
173 return f_val;
174 }
175
176 #define PRINT_TEST_2_EXPECT(fn_name, vals_inp_1, vals_inp_2, j, fn_eval, expected_val, \
177 new_line, extra_space, \
178 precision_1, precision_2, is_inf, is_nan) \
179 { \
180 constexpr TEST_VAL_TYPES val_1 = vals_inp_1[j]; \
181 constexpr TEST_VAL_TYPES val_2 = vals_inp_2[j]; \
182 \
183 TEST_VAL_TYPES f_val = print_test_2(fn_name,val_1,val_2,fn_eval,false,extra_space,precision_1,precision_2); \
184 \
185 bool test_pass = false; \
186 \
187 printf(" -"); \
188 if (!is_nan && !is_inf) { \
189 TEST_VAL_TYPES err_val = std::abs(f_val - expected_val); \
190 PRINT_ERR(err_val); \
191 test_pass = (err_val < TEST_ERR_TOL) ? true : false; \
192 } else if (is_nan) { \
193 if (TEST_IS_NAN(f_val)) { \
194 test_pass = true; \
195 } \
196 } else if (is_inf) { \
197 if (TEST_IS_INF(f_val)) { \
198 test_pass = true; \
199 } \
200 } else { \
201 printf("unknown error!"); \
202 } \
203 \
204 if (test_pass) { \
205 std::cout << "\033[32m OK.\033[0m" << std::endl; \
206 } else { \
207 std::cout << "\033[31m FAIL.\033[0m" << std::endl; \
208 } \
209 \
210 if (new_line) std::cout << std::endl; \
211 } \
212
213 #define PRINT_TEST_2_COMPARE(fn_name_1, fn_name_2, vals_inp_1, vals_inp_2, j, \
214 fn_eval_1, fn_eval_2, new_line, extra_space, \
215 precision_1, precision_2, is_inf, is_nan) \
216 { \
217 constexpr TEST_VAL_TYPES c_val_1 = vals_inp_1[j]; \
218 constexpr TEST_VAL_TYPES c_val_2 = vals_inp_2[j]; \
219 TEST_VAL_TYPES x_val_1 = vals_inp_1[j]; \
220 TEST_VAL_TYPES x_val_2 = vals_inp_2[j]; \
221 \
222 TEST_VAL_TYPES f_val_1 = print_test_2(fn_name_1,c_val_1,c_val_2,fn_eval_1,false,"",precision_1,precision_2); \
223 TEST_VAL_TYPES f_val_2 = print_test_2(fn_name_2,x_val_1,x_val_2,fn_eval_2,false,extra_space,precision_1,precision_2); \
224 \
225 bool test_pass = false; \
226 \
227 printf(" -"); \
228 if (!is_nan && !is_inf) { \
229 TEST_VAL_TYPES err_val = std::abs(f_val_1 - f_val_2); \
230 PRINT_ERR(err_val); \
231 test_pass = (err_val < TEST_ERR_TOL) ? true : false; \
232 } else if (is_nan) { \
233 if (std::isnan(f_val_1) && std::isnan(f_val_2)) { \
234 test_pass = true; \
235 } \
236 } else if (is_inf) { \
237 if (std::isinf(f_val_1) && std::isinf(f_val_2)) { \
238 test_pass = true; \
239 } \
240 } else { \
241 printf("unknown error!"); \
242 } \
243 \
244 if (test_pass) { \
245 std::cout << "\033[32m OK.\033[0m" << std::endl; \
246 } else { \
247 std::cout << "\033[31m FAIL.\033[0m" << std::endl; \
248 } \
249 \
250 if (new_line) std::cout << std::endl; \
251 } \
252
253 //
254 // three inputs
255
256 template<typename T>
257 inline
258 T
259 print_test_3(const std::string fn_name, const T val_inp_1, const T val_inp_2, const T val_inp_3,
260 std::function<T (const T val_inp, const T par_inp_1, const T par_inp_2)> fn_eval,
261 const bool new_line=false, const std::string extra_space="",
262 const int precision_1=2, const int precision_2=18)
263 {
264 T f_val = fn_eval(val_inp_1,val_inp_2,val_inp_3);
265 std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(precision_1) << fn_name \
266 << "(" << val_inp_1 << "," << val_inp_2 << "," << val_inp_3 << ")" << extra_space << " = " \
267 << std::setprecision(precision_2) << f_val << std::endl;
268 if (new_line) std::cout << std::endl;
269 return f_val;
270 }
271
272 #define PRINT_TEST_3_EXPECT(fn_name, vals_inp_1, vals_inp_2, vals_inp_3, \
273 j, fn_eval, expected_val, \
274 new_line, extra_space, \
275 precision_1, precision_2, is_inf, is_nan) \
276 { \
277 constexpr TEST_VAL_TYPES val_1 = vals_inp_1[j]; \
278 constexpr TEST_VAL_TYPES val_2 = vals_inp_2[j]; \
279 constexpr TEST_VAL_TYPES val_3 = vals_inp_3[j]; \
280 \
281 TEST_VAL_TYPES f_val = print_test_3(fn_name,val_1,val_2,val_3,fn_eval,false,extra_space,precision_1,precision_2); \
282 \
283 bool test_pass = false; \
284 \
285 printf(" -"); \
286 if (!is_nan && !is_inf) { \
287 TEST_VAL_TYPES err_val = std::abs(f_val - expected_val); \
288 PRINT_ERR(err_val); \
289 test_pass = (err_val < TEST_ERR_TOL) ? true : false; \
290 } else if (is_nan) { \
291 if (TEST_IS_NAN(f_val)) { \
292 test_pass = true; \
293 } \
294 } else if (is_inf) { \
295 if (TEST_IS_INF(f_val)) { \
296 test_pass = true; \
297 } \
298 } else { \
299 printf("unknown error!"); \
300 } \
301 \
302 if (test_pass) { \
303 std::cout << "\033[32m OK.\033[0m" << std::endl; \
304 } else { \
305 std::cout << "\033[31m FAIL.\033[0m" << std::endl; \
306 } \
307 \
308 if (new_line) std::cout << std::endl; \
309 } \
310
File vector/gcem/tests/incomplete_beta.cpp added (mode: 100644) (index 0000000..1b9d864)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin incomplete_beta test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double, long double, long double)> test_fn = gcem::incomplete_beta<long double,long double,long double>;
30 std::string test_fn_name = "gcem::incomplete_beta";
31
32 //
33
34 static constexpr long double test_vals_1[] = { 0.9L, 0.9L, 1.0L, 2.0L, 3.0L, 2.0L, 3.0L, 2.0L }; // a
35 static constexpr long double test_vals_2[] = { 0.9L, 0.9L, 1.0L, 2.0L, 2.0L, 3.0L, 2.0L, 2.0L }; // b
36 static constexpr long double test_vals_3[] = { 0.1L, 0.8L, 0.8L, 0.8L, 0.8L, 0.8L, 0.001L, 0.4L }; // x
37
38 static constexpr long double expected_vals[] = { 0.11464699677582491921L, \
39 0.78492840804657726395L, \
40 0.80000000000000004441L, \
41 0.89600000000000001865L, \
42 0.81920000000000003926L, \
43 0.97279999999999999805L, \
44 3.9970000000000084279e-09L,\
45 0.35200000000000003508L };
46
47
48 PRINT_TEST_3_EXPECT(test_fn_name,test_vals_1,test_vals_2,test_vals_3,0,test_fn,expected_vals[0],true," ",3,18,false,false);
49 PRINT_TEST_3_EXPECT(test_fn_name,test_vals_1,test_vals_2,test_vals_3,1,test_fn,expected_vals[1],true," ",3,18,false,false);
50 PRINT_TEST_3_EXPECT(test_fn_name,test_vals_1,test_vals_2,test_vals_3,2,test_fn,expected_vals[2],true," ",3,18,false,false);
51 PRINT_TEST_3_EXPECT(test_fn_name,test_vals_1,test_vals_2,test_vals_3,3,test_fn,expected_vals[3],true," ",3,18,false,false);
52 PRINT_TEST_3_EXPECT(test_fn_name,test_vals_1,test_vals_2,test_vals_3,4,test_fn,expected_vals[4],true," ",3,18,false,false);
53 PRINT_TEST_3_EXPECT(test_fn_name,test_vals_1,test_vals_2,test_vals_3,5,test_fn,expected_vals[5],true," ",3,18,false,false);
54 PRINT_TEST_3_EXPECT(test_fn_name,test_vals_1,test_vals_2,test_vals_3,6,test_fn,expected_vals[6],true," ",3,18,false,false);
55 PRINT_TEST_3_EXPECT(test_fn_name,test_vals_1,test_vals_2,test_vals_3,7,test_fn,expected_vals[7],false," ",3,18,false,false);
56
57 //
58
59 std::cout << "\n*** end incomplete_beta test ***\n" << std::endl;
60
61 return 0;
62 }
File vector/gcem/tests/incomplete_beta_inv.cpp added (mode: 100644) (index 0000000..6a799c0)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin incomplete_beta_inv test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double, long double, long double)> test_fn = gcem::incomplete_beta_inv<long double,long double,long double>;
30 std::string test_fn_name = "gcem::incomplete_beta_inv";
31
32 //
33
34 static constexpr long double test_vals_1[] = { 0.9L, 0.9L, 1.0L, 2.0L, 3.0L, 2.0L, 3.0L, 2.0L }; // a
35 static constexpr long double test_vals_2[] = { 0.9L, 0.9L, 1.0L, 2.0L, 2.0L, 3.0L, 2.0L, 2.0L }; // b
36 static constexpr long double test_vals_3[] = { 0.1L, 0.8L, 0.8L, 0.8L, 0.8L, 0.8L, 0.001L, 0.4L }; // x
37
38 static constexpr long double expected_vals[] = { 0.085977260425697907276L, \
39 0.81533908558467627081L, \
40 0.80000000000000004441L, \
41 0.71285927458325959449L, \
42 0.78768287172204876079L, \
43 0.58245357452433332845L, \
44 0.064038139102833388505L, \
45 0.43293107714773171324L };
46
47
48 PRINT_TEST_3_EXPECT(test_fn_name,test_vals_1,test_vals_2,test_vals_3,0,test_fn,expected_vals[0],true," ",3,18,false,false);
49 PRINT_TEST_3_EXPECT(test_fn_name,test_vals_1,test_vals_2,test_vals_3,1,test_fn,expected_vals[1],true," ",3,18,false,false);
50 PRINT_TEST_3_EXPECT(test_fn_name,test_vals_1,test_vals_2,test_vals_3,2,test_fn,expected_vals[2],true," ",3,18,false,false);
51 PRINT_TEST_3_EXPECT(test_fn_name,test_vals_1,test_vals_2,test_vals_3,3,test_fn,expected_vals[3],true," ",3,18,false,false);
52 PRINT_TEST_3_EXPECT(test_fn_name,test_vals_1,test_vals_2,test_vals_3,4,test_fn,expected_vals[4],true," ",3,18,false,false);
53 PRINT_TEST_3_EXPECT(test_fn_name,test_vals_1,test_vals_2,test_vals_3,5,test_fn,expected_vals[5],true," ",3,18,false,false);
54 PRINT_TEST_3_EXPECT(test_fn_name,test_vals_1,test_vals_2,test_vals_3,6,test_fn,expected_vals[6],true," ",3,18,false,false);
55 PRINT_TEST_3_EXPECT(test_fn_name,test_vals_1,test_vals_2,test_vals_3,7,test_fn,expected_vals[7],false," ",3,18,false,false);
56
57 //
58
59 std::cout << "\n*** end incomplete_beta_inv test ***\n" << std::endl;
60
61 return 0;
62 }
File vector/gcem/tests/incomplete_gamma.cpp added (mode: 100644) (index 0000000..c4ab0ff)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin incomplete_gamma test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double, long double)> test_fn = gcem::incomplete_gamma<long double,long double>;
30 std::string test_fn_name = "gcem::incomplete_gamma";
31
32 //
33
34 static constexpr long double test_vals_1[] = { \
35 2.0L, 1.5L, 2.0L, 2.0L, 2.0L, 0.0L, 2.0L, 0.0L, 11.5L, 15.5L, 19.0L, 20.0L,\
36 38.0L, 56.0L, 98.0L, 102.0L, 298.0L, 302.0L, 498.0L, 502.0L, 798.0L, 801.0L, 997.0L, 1005.0L, -0.1L }; // shape
37 static constexpr long double test_vals_2[] = { \
38 1.0L, 1.0L, 3.0L, 5.0L, 9.0L, 9.0L, 0.0L, 0.0L, 11.0L, 18.0L, 18.0L, 19.0L,\
39 39.0L, 55.0L, 99.0L, 101.0L, 297.0L, 301.0L, 497.0L, 501.0L, 799.0L, 800.0L, 999.0L, 1001.0L, 0.0L }; // x
40
41 static constexpr long double expected_vals[] = { 0.26424111765711527644L,
42 0.42759329552912134220L,
43 0.80085172652854419439L,
44 0.95957231800548714595L,
45 0.99876590195913317327L,
46 1.0L,
47 0.0L,
48 0.0L,
49 0.47974821959920432857L,
50 0.75410627202774938027L,
51 0.43775501395596266851L,
52 0.43939261060849132967L,
53 0.58504236243630125536L,
54 0.46422093592347296598L,
55 0.55342727426212001696L,
56 0.47356929040257916830L,
57 0.48457398488934400049L,
58 0.48467673854389853316L,
59 0.48807306199561317772L,
60 0.48812074555706047585L,
61 0.51881664512582725823L,
62 0.49059834200005758564L,
63 0.52943655952003709775L,
64 0.45389544705967349580L };
65
66 //
67
68 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,0,test_fn,expected_vals[0],true,"",3,18,false,false);
69 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,1,test_fn,expected_vals[1],true,"",3,18,false,false);
70 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,2,test_fn,expected_vals[2],true,"",3,18,false,false);
71 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,3,test_fn,expected_vals[3],true,"",3,18,false,false);
72 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,4,test_fn,expected_vals[4],true,"",3,18,false,false);
73 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,5,test_fn,expected_vals[5],true,"",3,18,false,false);
74 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,6,test_fn,expected_vals[6],true,"",3,18,false,false);
75 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,7,test_fn,expected_vals[7],true,"",3,18,false,false);
76 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,8,test_fn,expected_vals[8],true,"",3,18,false,false);
77 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,9,test_fn,expected_vals[9],true,"",3,18,false,false);
78 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,10,test_fn,expected_vals[10],true,"",3,18,false,false);
79 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,11,test_fn,expected_vals[11],true,"",3,18,false,false);
80 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,12,test_fn,expected_vals[12],true,"",3,18,false,false);
81 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,13,test_fn,expected_vals[13],true,"",3,18,false,false);
82 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,14,test_fn,expected_vals[14],true,"",3,18,false,false);
83 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,15,test_fn,expected_vals[15],true,"",3,18,false,false);
84 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,16,test_fn,expected_vals[16],true,"",3,18,false,false);
85 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,17,test_fn,expected_vals[17],true,"",3,18,false,false);
86 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,18,test_fn,expected_vals[18],true,"",3,18,false,false);
87 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,19,test_fn,expected_vals[19],true,"",3,18,false,false);
88 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,20,test_fn,expected_vals[20],true,"",3,18,false,false);
89 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,21,test_fn,expected_vals[21],true,"",3,18,false,false);
90 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,22,test_fn,expected_vals[22],true,"",3,18,false,false);
91 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,23,test_fn,expected_vals[23],true,"",3,18,false,false);
92 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,24,test_fn,0.0L,true,"",3,18,false,true);
93
94 //
95
96 std::cout << "\n*** end incomplete_gamma test ***\n" << std::endl;
97
98 return 0;
99 }
File vector/gcem/tests/incomplete_gamma_inv.cpp added (mode: 100644) (index 0000000..de14919)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #ifndef _WIN32
22 #define TEST_ERR_TOL 1e-12
23 #endif
24
25 #include "gcem_tests.hpp"
26
27 int main()
28 {
29 std::cout << "\n*** begin incomplete_gamma_inv test ***\n" << std::endl;
30
31 //
32
33 std::function<long double (long double, long double)> test_fn = gcem::incomplete_gamma_inv<long double,long double>;
34 std::string test_fn_name = "gcem::incomplete_gamma_inv";
35
36 //
37
38 static constexpr long double test_vals_1[] = { \
39 2.0L, 1.5L, 2.0L, 2.0L, 2.0L, 0.0L, 2.0L, 0.0L, 11.5L, 15.5L, 19.0L, 20.0L,\
40 38.0L, 56.0L, 98.0L, 102.0L, 298.0L, 302.0L, 498.0L, 502.0L, 798.0L, 801.0L, 997.0L, 1005.0L }; // shape
41
42 static constexpr long double test_vals_2[] = { 0.26424111765711527644L, \
43 0.42759329552912134220L, \
44 0.80085172652854419439L, \
45 0.95957231800548714595L, \
46 0.99876590195913317327L, \
47 1.0L, \
48 0.0L,\
49 0.0L,
50 0.47974821959920432857L,
51 0.75410627202774938027L,
52 0.43775501395596266851L,
53 0.43939261060849132967L,
54 0.58504236243630125536L,
55 0.46422093592347296598L,
56 0.55342727426212001696L,
57 0.47356929040257916830L,
58 0.48457398488934400049L,
59 0.48467673854389853316L,
60 0.48807306199561317772L,
61 0.48812074555706047585L,
62 0.51881664512582725823L,
63 0.49059834200005758564L,
64 0.52943655952003709775L,
65 0.45389544705967349580L };
66
67 static constexpr long double expected_vals[] = { \
68 1.0L, 1.0L, 3.0L, 5.0L, 9.0L, 9.0L, 0.0L, 0.0L, 11.0L, 18.0L, 18.0L, 19.0L,\
69 39.0L, 55.0L, 99.0L, 101.0L, 297.0L, 301.0L, 497.0L, 501.0L, 799.0L, 800.0L, 999.0L, 1001.0L }; // x
70
71 //
72
73 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,0,test_fn,expected_vals[0],true,"",3,18,false,false);
74 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,1,test_fn,expected_vals[1],true,"",3,18,false,false);
75 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,2,test_fn,expected_vals[2],true,"",3,18,false,false);
76 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,3,test_fn,expected_vals[3],true,"",3,18,false,false);
77 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,4,test_fn,expected_vals[4],true,"",3,18,false,false);
78 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,5,test_fn,expected_vals[5],true,"",3,18,true,false);
79 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,6,test_fn,expected_vals[6],true,"",3,18,false,false);
80 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,7,test_fn,expected_vals[7],true,"",3,18,false,false);
81 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,8,test_fn,expected_vals[8],true,"",3,18,false,false);
82 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,9,test_fn,expected_vals[9],true,"",3,18,false,false);
83 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,10,test_fn,expected_vals[10],true,"",3,18,false,false);
84 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,11,test_fn,expected_vals[11],true,"",3,18,false,false);
85 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,12,test_fn,expected_vals[12],true,"",3,18,false,false);
86 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,13,test_fn,expected_vals[13],true,"",3,18,false,false);
87 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,14,test_fn,expected_vals[14],true,"",3,18,false,false);
88 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,15,test_fn,expected_vals[15],true,"",3,18,false,false);
89 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,16,test_fn,expected_vals[16],true,"",3,18,false,false);
90 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,17,test_fn,expected_vals[17],true,"",3,18,false,false);
91 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,18,test_fn,expected_vals[18],true,"",3,18,false,false);
92 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,19,test_fn,expected_vals[19],true,"",3,18,false,false);
93 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,20,test_fn,expected_vals[20],true,"",3,18,false,false);
94 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,21,test_fn,expected_vals[21],true,"",3,18,false,false);
95 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,22,test_fn,expected_vals[22],true,"",3,18,false,false);
96 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,23,test_fn,expected_vals[23],false,"",3,18,false,false);
97
98 //
99
100 std::cout << "\n*** end incomplete_gamma_inv test ***\n" << std::endl;
101
102 return 0;
103 }
File vector/gcem/tests/is_odd.cpp added (mode: 100644) (index 0000000..61e235d)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin is_odd test ***\n" << std::endl;
26
27 //
28
29 int run_val = 0;
30
31 run_val += gcem::internal::is_odd(1);
32 run_val += gcem::internal::is_odd(3);
33 run_val += gcem::internal::is_odd(-5);
34 run_val += gcem::internal::is_even(10UL);
35 run_val += gcem::internal::is_odd(-400009L);
36 run_val += gcem::internal::is_even(100000000L);
37
38 if (run_val == 6)
39 std::cout << "\033[32m All OK.\033[0m" << std::endl;
40 else
41 std::cout << "\033[32m Fail.\033[0m" << std::endl;
42
43 //
44
45 std::cout << "\n*** end is_odd test ***\n" << std::endl;
46
47 return 0;
48 }
File vector/gcem/tests/lcm.cpp added (mode: 100644) (index 0000000..4d81a84)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #define TEST_VAL_TYPES int
22
23 #include "gcem_tests.hpp"
24
25 int main()
26 {
27 std::cout << "\n*** begin lcm test ***\n" << std::endl;
28
29 //
30
31 std::function<int (int, int)> test_fn = gcem::lcm<int,int>;
32 std::string test_fn_name = "gcem::lcm";
33
34 //
35
36 static constexpr int test_vals_1[] = { 3, 12, 17 }; // shape
37 static constexpr int test_vals_2[] = { 4, 15, 81 }; // x
38
39 static constexpr int expected_vals[] = { 12, 60, 1377 };
40
41 //
42
43 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,0,test_fn,expected_vals[0],true,"",3,18,false,false);
44 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,1,test_fn,expected_vals[1],true,"",3,18,false,false);
45 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,2,test_fn,expected_vals[2],false,"",3,18,false,false);
46
47 //
48
49 std::cout << "\n*** end lcm test ***\n" << std::endl;
50
51 return 0;
52 }
File vector/gcem/tests/lgamma.cpp added (mode: 100644) (index 0000000..ce3dab0)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin lgamma test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double)> test_fn = gcem::lgamma<long double>;
30 std::string test_fn_name = "gcem::lgamma";
31
32 std::function<long double (long double)> std_fn = [] (long double x) -> long double { return std::lgamma(x); };
33 std::string std_fn_name = "std::lgamma";
34
35 //
36
37 static constexpr long double test_vals[] = { 1.5L, 0.7L, 1.0L, 0.0L, -1.0L };
38
39 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,0,test_fn,std_fn,true," ",3,18,false,false);
40 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,1,test_fn,std_fn,true," ",3,18,false,false);
41 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,2,test_fn,std_fn,true," ",3,18,false,false);
42 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,3,test_fn,std_fn,true," ",3,18,true,false);
43 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,4,test_fn,std_fn,false," ",3,18,true,false);
44
45 //
46
47 std::cout << "\n*** end lgamma test ***\n" << std::endl;
48
49 return 0;
50 }
File vector/gcem/tests/log.cpp added (mode: 100644) (index 0000000..96f4951)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 // g++-mp-7 -O3 -Wall -std=c++11 -fconstexpr-depth=20 -fconstexpr-steps=1271242 -I./../include log.cpp -o log.test -framework Accelerate
22
23 #include "gcem_tests.hpp"
24
25 int main()
26 {
27 std::cout << "\n*** begin log test ***\n" << std::endl;
28
29 //
30
31 std::function<long double (long double)> test_fn = gcem::log<long double>;
32 std::string test_fn_name = "gcem::log";
33
34 std::function<long double (long double)> std_fn = [] (long double x) -> long double { return std::log(x); };
35 std::string std_fn_name = "std::log";
36
37 //
38
39 static constexpr long double test_vals[] = { 0.5L, 0.00199900000000000208L, 1.5L, 41.5L, 0.0L, -1.0L,
40 - std::numeric_limits<long double>::infinity(),
41 std::numeric_limits<long double>::infinity(),
42 std::numeric_limits<long double>::quiet_NaN() };
43
44 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,0,test_fn,std_fn,true," ",6,18,false,false);
45 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,1,test_fn,std_fn,true," ",6,18,false,false);
46 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,2,test_fn,std_fn,true," ",6,18,false,false);
47 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,3,test_fn,std_fn,true," ",6,18,false,false);
48 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,4,test_fn,std_fn,true," ",6,18,true,false);
49 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,5,test_fn,std_fn,true," ",6,18,false,true);
50 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,6,test_fn,std_fn,true," ",6,18,false,true);
51 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,7,test_fn,std_fn,true," ",6,18,true,false);
52 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,8,test_fn,std_fn,false," ",6,18,false,true);
53
54 //
55
56 std::cout << "\n*** end log test ***\n" << std::endl;
57
58 return 0;
59 }
File vector/gcem/tests/log1p.cpp added (mode: 100644) (index 0000000..a14d1f9)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin log1p test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double)> test_fn = gcem::log1p<long double>;
30 std::string test_fn_name = "gcem::log1p";
31
32 std::function<long double (long double)> std_fn = [] (long double x) -> long double { return std::log1p(x); };
33 std::string std_fn_name = "std::log1p";
34
35 //
36
37 static constexpr long double test_vals[] = { 1.0L, 0.0L, 1e-04L, -1e-04L, 1e-05L, 1e-06L, 1e-22L };
38
39 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,0,test_fn,std_fn,true," ",5,18,false,false);
40 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,1,test_fn,std_fn,true," ",5,18,false,false);
41 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,2,test_fn,std_fn,true," ",5,18,false,false);
42 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,3,test_fn,std_fn,true," ",5,18,false,false);
43 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,4,test_fn,std_fn,true," ",5,18,false,false);
44 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,5,test_fn,std_fn,true," ",5,18,false,false);
45 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,6,test_fn,std_fn,false," ",5,18,false,false);
46
47 //
48
49 std::cout << "\n*** end log1p test ***\n" << std::endl;
50
51 return 0;
52 }
File vector/gcem/tests/log_binomial_coef.cpp added (mode: 100644) (index 0000000..37f88ec)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin log_binomial_coef test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double, long double)> test_fn = gcem::log_binomial_coef<long double, long double>;
30 std::string test_fn_name = "gcem::log_binomial_coef";
31
32 //
33
34 static constexpr long double test_vals_1[] = { 0.0L, 0.0L, 1.0L, 1.0L, 5.0L, 10.0L, 10.0L, 10.0L };
35 static constexpr long double test_vals_2[] = { 0.0L, 1.0L, 0.0L, 1.0L, 2.0L, 8.0L, 9.0L, 10.0L };
36
37 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,0,test_fn,0.0L,true,"",2,2,false,false);
38 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,1,test_fn,.0L,true,"",2,2,true,false); // ignore input value
39 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,2,test_fn,0.0L,true,"",2,2,false,false);
40 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,3,test_fn,0.0L,true,"",2,2,false,false);
41 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,4,test_fn,std::log(10.0L),true,"",2,2,false,false);
42 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,5,test_fn,std::log(45.0L),true,"",2,2,false,false);
43 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,6,test_fn,std::log(10.0L),true,"",2,2,false,false);
44 PRINT_TEST_2_EXPECT(test_fn_name,test_vals_1,test_vals_2,7,test_fn,0.0L,false,"",2,2,false,false);
45
46 //
47
48 std::cout << "\n*** end log_binomial_coef test ***\n" << std::endl;
49
50 return 0;
51 }
File vector/gcem/tests/other.cpp added (mode: 100644) (index 0000000..84c2e0a)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include <iostream>
22 #include "gcem.hpp"
23
24 int main()
25 {
26 double x = 1.5;
27
28 gcem::sgn(x);
29 gcem::sgn(-x);
30 gcem::internal::find_fraction(x);
31 gcem::internal::find_whole(x);
32
33 return 0;
34 }
File vector/gcem/tests/pow.cpp added (mode: 100644) (index 0000000..e80b05d)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin pow test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double, long double)> test_fn_int = [] (long double x, long double y) -> long double \
30 { return gcem::pow<long double>(x,size_t(y)); };
31
32 std::function<long double (long double, long double)> test_fn = gcem::pow<long double, long double>;
33 std::string test_fn_name = "gcem::pow";
34
35 std::function<long double (long double, long double)> std_fn = [] (long double x, long double y) -> long double { return std::pow(x,y); };
36 std::string std_fn_name = "std::pow";
37
38 //
39
40 static constexpr long double test_vals_1[] = { 0.199900000000000208L, 0.5L, 1.5L, 41.5L };
41 static constexpr long double test_vals_2[] = { 3.5L, 2.0L, 0.99L, 7.0L };
42
43 PRINT_TEST_2_COMPARE(test_fn_name,std_fn_name,test_vals_1,test_vals_2,0,test_fn,std_fn,true," ",5,18,false,false);
44 PRINT_TEST_2_COMPARE(test_fn_name,std_fn_name,test_vals_1,test_vals_2,1,test_fn_int,std_fn,true," ",3,18,false,false);
45 PRINT_TEST_2_COMPARE(test_fn_name,std_fn_name,test_vals_1,test_vals_2,2,test_fn,std_fn,true," ",3,18,false,false);
46 PRINT_TEST_2_COMPARE(test_fn_name,std_fn_name,test_vals_1,test_vals_2,3,test_fn_int,std_fn,false," ",3,18,false,false);
47
48 //
49
50 std::cout << "\n*** end pow test ***\n" << std::endl;
51
52 return 0;
53 }
File vector/gcem/tests/run_tests added (mode: 100755) (index 0000000..10f0e48)
1
2 for t in ./*.test; do
3 "$t"
4 done
File vector/gcem/tests/sin.cpp added (mode: 100644) (index 0000000..1b4e303)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin sin test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double)> test_fn = gcem::sin<long double>;
30 std::string test_fn_name = "gcem::sin";
31
32 std::function<long double (long double)> std_fn = [] (long double x) -> long double { return std::sin(x); };
33 std::string std_fn_name = "std::sin";
34
35 //
36
37 static constexpr long double test_vals[] = { 0.0L, 0.001L, 1.001L, 1.5L, 11.1L, 50.0L, -1.5L };
38
39 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,0,test_fn,std_fn,true," ",6,18,false,false);
40 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,1,test_fn,std_fn,true," ",6,18,false,false);
41 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,2,test_fn,std_fn,true," ",6,18,false,false);
42 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,3,test_fn,std_fn,true," ",6,18,false,false);
43 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,4,test_fn,std_fn,true," ",6,18,false,false);
44 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,5,test_fn,std_fn,true," ",6,18,false,false);
45 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,6,test_fn,std_fn,false," ",6,18,false,false);
46
47 //
48
49 std::cout << "\n*** end sin test ***\n" << std::endl;
50
51 return 0;
52 }
File vector/gcem/tests/sinh.cpp added (mode: 100644) (index 0000000..e73b95a)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin sinh test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double)> test_fn = gcem::sinh<long double>;
30 std::string test_fn_name = "gcem::sinh";
31
32 std::function<long double (long double)> std_fn = [] (long double x) -> long double { return std::sinh(x); };
33 std::string std_fn_name = "std::sinh";
34
35 //
36
37 static constexpr long double test_vals[] = { 0.0L, 0.001L, 0.5L, -0.5L, 0.7568025L, 1.0L, 5.0L };
38
39 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,0,test_fn,std_fn,true," ",6,18,false,false);
40 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,1,test_fn,std_fn,true," ",6,18,false,false);
41 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,2,test_fn,std_fn,true," ",6,18,false,false);
42 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,3,test_fn,std_fn,true," ",6,18,false,false);
43 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,4,test_fn,std_fn,true," ",6,18,false,false);
44 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,5,test_fn,std_fn,true," ",6,18,false,false);
45 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,6,test_fn,std_fn,false," ",6,18,false,false);
46
47 //
48
49 std::cout << "\n*** end sinh test ***\n" << std::endl;
50
51 return 0;
52 }
File vector/gcem/tests/sqrt.cpp added (mode: 100644) (index 0000000..b1414c3)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 // g++-mp-7 -O3 -Wall -std=c++11 -fconstexpr-depth=20 -fconstexpr-steps=1271242 -I./../include sqrt.cpp -o sqrt.test -framework Accelerate
22
23 #include "gcem_tests.hpp"
24
25 int main()
26 {
27 std::cout << "\n*** begin sqrt test ***\n" << std::endl;
28
29 //
30
31 std::function<long double (long double)> test_fn = gcem::sqrt<long double>;
32 std::string test_fn_name = "gcem::sqrt";
33
34 std::function<long double (long double)> std_fn = [] (long double x) -> long double { return std::sqrt(x); };
35 std::string std_fn_name = "std::sqrt";
36
37 //
38
39 static constexpr long double test_vals[] = { 0.00199900000000000208L, 0.5L, 1.5L, 2.0L, 41.5L, 0.0L, -1.0L };
40
41 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,0,test_fn,std_fn,true," ",6,18,false,false);
42 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,1,test_fn,std_fn,true," ",6,18,false,false);
43 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,2,test_fn,std_fn,true," ",6,18,false,false);
44 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,3,test_fn,std_fn,true," ",6,18,false,false);
45 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,4,test_fn,std_fn,true," ",6,18,false,false);
46 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,5,test_fn,std_fn,true," ",6,18,false,false);
47 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,6,test_fn,std_fn,false," ",6,18,false,true);
48
49 //
50
51 std::cout << "\n*** end sqrt test ***\n" << std::endl;
52
53 return 0;
54 }
File vector/gcem/tests/tan.cpp added (mode: 100644) (index 0000000..df5cdcd)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin tan test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double)> test_fn = gcem::tan<long double>;
30 std::string test_fn_name = "gcem::tan";
31
32 std::function<long double (long double)> std_fn = [] (long double x) -> long double { return std::tan(x); };
33 std::string std_fn_name = "std::tan";
34
35 //
36
37 static constexpr long double lval = std::numeric_limits<int>::max()*100.0L;
38
39 static constexpr long double test_vals[] = { 0.0L, 0.001L, 1.001L, 1.5L, 11.1L, 50.0L, lval, -1.5L };
40
41 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,0,test_fn,std_fn,true," ",6,18,false,false);
42 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,1,test_fn,std_fn,true," ",6,18,false,false);
43 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,2,test_fn,std_fn,true," ",6,18,false,false);
44 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,3,test_fn,std_fn,true," ",6,18,false,false);
45 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,4,test_fn,std_fn,true," ",6,18,false,false);
46 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,5,test_fn,std_fn,true," ",6,18,false,false);
47 // PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,6,test_fn,std_fn,true," ",6,18,false,false);
48 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,7,test_fn,std_fn,false," ",6,18,false,false);
49
50 //
51
52 std::cout << "\n*** end tan test ***\n" << std::endl;
53
54 return 0;
55 }
File vector/gcem/tests/tanh.cpp added (mode: 100644) (index 0000000..9c5b41f)
1 /*################################################################################
2 ##
3 ## Copyright (C) 2016-2019 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21 #include "gcem_tests.hpp"
22
23 int main()
24 {
25 std::cout << "\n*** begin tanh test ***\n" << std::endl;
26
27 //
28
29 std::function<long double (long double)> test_fn = gcem::tanh<long double>;
30 std::string test_fn_name = "gcem::tanh";
31
32 std::function<long double (long double)> std_fn = [] (long double x) -> long double { return std::tanh(x); };
33 std::string std_fn_name = "std::tanh";
34
35 //
36
37 static constexpr long double test_vals[] = { 0.0L, 0.001L, 0.5L, -0.5L, 0.7568025L, 1.0L, 5.0L };
38
39 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,0,test_fn,std_fn,true," ",6,18,false,false);
40 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,1,test_fn,std_fn,true," ",6,18,false,false);
41 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,2,test_fn,std_fn,true," ",6,18,false,false);
42 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,3,test_fn,std_fn,true," ",6,18,false,false);
43 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,4,test_fn,std_fn,true," ",6,18,false,false);
44 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,5,test_fn,std_fn,true," ",6,18,false,false);
45 PRINT_TEST_1_COMPARE(test_fn_name,std_fn_name,test_vals,6,test_fn,std_fn,false," ",6,18,false,false);
46
47 //
48
49 std::cout << "\n*** end tanh test ***\n" << std::endl;
50
51 return 0;
52 }
File vector/math.h copied from file math.h (similarity 100%)
File vector/matrix/base.h copied from file matrix/base.h (similarity 100%)
File vector/matrix/base.hpp copied from file matrix/base.hpp (similarity 100%)
File vector/matrix/matrix.h copied from file matrix/matrix.h (similarity 100%)
File vector/matrix/matrix_functions.h copied from file matrix/matrix_functions.h (similarity 100%)
File vector/matrix/matrix_functions.hpp copied from file matrix/matrix_functions.hpp (similarity 100%)
File vector/matrix/type_defs.h copied from file matrix/type_defs.h (similarity 100%)
File vector/misc.h copied from file misc.h (similarity 100%)
File vector/type_defs.h changed (mode: 100644 -> 100755)
File vector/vector.h changed (mode: 100644 -> 100755)
File vector/vector/base.h copied from file vector/base.h (similarity 100%)
File vector/vector/base.hpp copied from file vector/base.hpp (similarity 100%)
File vector/vector/type_defs.h copied from file vector/type_defs.h (similarity 100%)
File vector/vector/vector.h copied from file vector/vector.h (similarity 100%)
File vector/vector/vector_functions.h copied from file vector/vector_functions.h (similarity 100%)
File vector/vector/vector_functions.hpp copied from file vector/vector_functions.hpp (similarity 100%)
File vector/vector_functions.h changed (mode: 100644 -> 100755)
File vector/vector_functions.hpp changed (mode: 100644 -> 100755)
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/Jackalope/jmath

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/Jackalope/jmath

Clone this repository using git:
git clone git://git.rocketgit.com/user/Jackalope/jmath

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main