{"id":13819158,"url":"https://github.com/kthohr/gcem","last_synced_at":"2025-04-12T17:41:12.021Z","repository":{"id":39801205,"uuid":"95882513","full_name":"kthohr/gcem","owner":"kthohr","description":"A C++ compile-time math library using generalized constant expressions","archived":false,"fork":false,"pushed_at":"2024-06-22T14:53:25.000Z","size":563,"stargazers_count":768,"open_issues_count":14,"forks_count":66,"subscribers_count":29,"default_branch":"master","last_synced_at":"2025-04-03T19:14:41.277Z","etag":null,"topics":["constexpr","cpp","cpp11","cpp14","cpp17","expression-math","math","special-functions"],"latest_commit_sha":null,"homepage":"https://gcem.readthedocs.io/en/latest/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kthohr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-30T11:29:03.000Z","updated_at":"2025-04-03T18:37:34.000Z","dependencies_parsed_at":"2024-05-28T03:15:01.609Z","dependency_job_id":"0750a393-1176-43b6-bb03-1138350162cc","html_url":"https://github.com/kthohr/gcem","commit_stats":{"total_commits":309,"total_committers":11,"mean_commits":28.09090909090909,"dds":"0.40129449838187703","last_synced_commit":"012ae73c6d0a2cb09ffe86475f5c6fba3926e200"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kthohr%2Fgcem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kthohr%2Fgcem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kthohr%2Fgcem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kthohr%2Fgcem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kthohr","download_url":"https://codeload.github.com/kthohr/gcem/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248607789,"owners_count":21132609,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["constexpr","cpp","cpp11","cpp14","cpp17","expression-math","math","special-functions"],"created_at":"2024-08-04T08:00:41.481Z","updated_at":"2025-04-12T17:41:11.989Z","avatar_url":"https://github.com/kthohr.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"# GCE-Math\n[![Build Status](https://github.com/kthohr/gcem/actions/workflows/main.yml/badge.svg)](https://github.com/kthohr/gcem/actions/workflows/main.yml) [![Build status](https://ci.appveyor.com/api/projects/status/5kxxkmisln1j4h6b?svg=true)](https://ci.appveyor.com/project/kthohr/gcem) [![Coverage Status](https://codecov.io/github/kthohr/gcem/coverage.svg?branch=master)](https://codecov.io/github/kthohr/gcem?branch=master) [![Documentation Status](https://readthedocs.org/projects/gcem/badge/?version=latest)](https://gcem.readthedocs.io/en/latest/?badge=latest)\n\nGCE-Math (**G**eneralized **C**onstant **E**xpression Math) is a templated C++ library enabling compile-time computation of mathematical functions.\n\nFeatures:\n\n* The library is written in C++11 `constexpr` format, and is C++11/14/17/20 compatible.\n* Continued fraction expansions and series expansions are implemented using recursive templates.\n* The `gcem::` syntax is identical to that of the C++ standard library (`std::`).\n* Tested and accurate to floating-point precision against the C++ standard library.\n* Released under a permissive, non-GPL license.\n\n**Author**: Keith O'Hara\n\n[![License](https://img.shields.io/badge/Licence-Apache%202.0-blue.svg)](./LICENSE)\n\n### Contents:\n* [Status and Documentation](#status-and-documentation) \n* [Installation](#installation)\n* [Test Suite](#test-suite)\n* [Jupyter Notebook](#jupyter-notebook)\n* [General Syntax](#general-syntax)\n* [Examples](#examples)\n\n## Status and Documentation\n\nThe library is actively maintained and is still being extended. A list of features includes:\n\n* Basic library functions:\n    - `abs`, `max`, `min`, `pow`, `sqrt`, `inv_sqrt`, \n    - `ceil`, `floor`, `round`, `trunc`, `fmod`,\n    - `exp`, `expm1`, `log`, `log1p`, `log2`, `log10`, and more\n* Trigonometric functions:\n    - basic: `cos`, `sin`, `tan`\n    - inverse: `acos`, `asin`, `atan`, `atan2`\n* Hyperbolic (area) functions: \n    - `cosh`, `sinh`, `tanh`, `acosh`, `asinh`, `atanh`\n* Algorithms:\n    - `gcd`, `lcm`\n* Special functions:\n    - factorials and the binomial coefficient: `factorial`, `binomial_coef`\n    - beta, gamma, and multivariate gamma functions: `beta`, `lbeta`, `lgamma`, `tgamma`, `lmgamma`\n    - the Gaussian error function and inverse error function: `erf`, `erf_inv`\n    - (regularized) incomplete beta and incomplete gamma functions: `incomplete_beta`, `incomplete_gamma`\n    - inverse incomplete beta and incomplete gamma functions: `incomplete_beta_inv`, `incomplete_gamma_inv`\n\nFull documentation is available online:\n\n[![Documentation Status](https://readthedocs.org/projects/gcem/badge/?version=latest)](https://gcem.readthedocs.io/en/latest/?badge=latest)\n\nA PDF version of the documentation is available [here](https://buildmedia.readthedocs.org/media/pdf/gcem/latest/gcem.pdf).\n\n## Installation\n\nGCE-Math is a header-only library and does not require any additional libraries or utilities (beyond a C++11 compatible compiler). Simply add the header files to your project using:\n```cpp\n#include \"gcem.hpp\"\n```\n\n### Conda \n\n[![Anaconda-Server Badge](https://anaconda.org/conda-forge/gcem/badges/version.svg)](https://anaconda.org/conda-forge/gcem) [![Anaconda-Server Badge](https://anaconda.org/conda-forge/gcem/badges/platforms.svg)](https://anaconda.org/conda-forge/gcem)\n\nYou can install GCE-Math using the Conda package manager.\n\n```bash\nconda install -c conda-forge gcem\n```\n\n### CMake\n\nYou can also install the library from source using CMake.\n\n```bash\n# clone gcem from GitHub\ngit clone https://github.com/kthohr/gcem ./gcem\n\n# make a build directory\ncd ./gcem\nmkdir build\ncd build\n\n# generate Makefiles and install\ncmake .. -DCMAKE_INSTALL_PREFIX=/gcem/install/location\nmake install\n```\nFor example, `/gcem/install/location` could be `/usr/local/`.\n\n## Test Suite\n\nThere are two ways to build the test suite. On Unix-alike systems, a Makefile is available under `tests/`.\n\n```bash\ncd ./gcem/tests\nmake\n./run_tests\n```\n\nWith CMake, the option `GCEM_BUILD_TESTS=1` generates the necessary Makefiles to build the test suite.\n```bash\ncd ./gcem\nmkdir build\n\ncd build\ncmake ../ -DGCEM_BUILD_TESTS=1 -DCMAKE_INSTALL_PREFIX=/gcem/install/location\nmake gcem_tests\n\ncd tests\n./exp.test\n```\n\n## Jupyter Notebook\n\nYou can test the library online using an interactive Jupyter notebook: \n\n[![Binder](https://mybinder.org/badge.svg)](https://mybinder.org/v2/gh/kthohr/gcem/master?filepath=notebooks%2Fgcem.ipynb)\n\n## General Syntax\n\nGCE-Math functions are written as C++ templates with `constexpr` specifiers, the format of which might appear confusing to users unfamiliar with template-based programming. \n\nFor example, the [Gaussian error function](https://en.wikipedia.org/wiki/Error_function) (`erf`) is defined as:\n```cpp\ntemplate\u003ctypename T\u003e\nconstexpr\nreturn_t\u003cT\u003e\nerf(const T x) noexcept;\n```\nA set of internal templated `constexpr` functions will implement a continued fraction expansion and return a value of type `return_t\u003cT\u003e`. The output type ('`return_t\u003cT\u003e`') is generally determined by the input type, e.g., `int`, `float`, `double`, `long double`, etc.; when `T` is an integral type, the output will be upgraded to `return_t\u003cT\u003e = double`, otherwise `return_t\u003cT\u003e = T`. For types not covered by `std::is_integral`, recasts should be used.\n\n## Examples\n\nTo calculate 10!:\n\n```cpp\n#include \"gcem.hpp\"\n\nint main()\n{\n    constexpr int x = 10;\n    constexpr int res = gcem::factorial(x);\n\n    return 0;\n}\n```\nInspecting the assembly code generated by Clang 7.0.0:\n```assembly\n        push    rbp\n        mov     rbp, rsp\n        xor     eax, eax\n        mov     dword ptr [rbp - 4], 0\n        mov     dword ptr [rbp - 8], 10\n        mov     dword ptr [rbp - 12], 3628800\n        pop     rbp\n        ret\n```\nWe see that a function call has been replaced by a numeric value (10! = 3628800).\n\nSimilarly, to compute the log Gamma function at a point:\n\n```cpp\n#include \"gcem.hpp\"\n\nint main()\n{\n    constexpr long double x = 1.5;\n    constexpr long double res = gcem::lgamma(x);\n\n    return 0;\n}\n```\nAssembly code:\n```assembly\n.LCPI0_0:\n        .long   1069547520              # float 1.5\n.LCPI0_1:\n        .quad   -622431863250842976     # x86_fp80 -0.120782237635245222719\n        .short  49147\n        .zero   6\nmain:                                   # @main\n        push    rbp\n        mov     rbp, rsp\n        xor     eax, eax\n        mov     dword ptr [rbp - 4], 0\n        fld     dword ptr [rip + .LCPI0_0]\n        fstp    tbyte ptr [rbp - 32]\n        fld     tbyte ptr [rip + .LCPI0_1]\n        fstp    tbyte ptr [rbp - 48]\n        pop     rbp\n        ret\n```\n\n## Related libraries\n\n* [StatsLib](https://github.com/kthohr/stats) is built on GCEM's compile-time functionality.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkthohr%2Fgcem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkthohr%2Fgcem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkthohr%2Fgcem/lists"}