All Projects → kthohr → Gcem

kthohr / Gcem

Licence: apache-2.0
A C++ compile-time math library using generalized constant expressions

Programming Languages

cpp
1120 projects
cpp11
221 projects
cpp17
186 projects
cpp14
131 projects

Labels

Projects that are alternatives of or similar to Gcem

Mathmodel
研究生数学建模,本科生数学建模、数学建模竞赛优秀论文,数学建模算法,LaTeX论文模板,算法思维导图,参考书籍,Matlab软件教程,PPT
Stars: ✭ 3,834 (+1421.43%)
Mutual labels:  math
Mathsass
A Sass implementation of mathematical functions.
Stars: ✭ 221 (-12.3%)
Mutual labels:  math
Xaos
Real-time interactive fractal zoomer
Stars: ✭ 239 (-5.16%)
Mutual labels:  math
Mir
Mir (backports): Sparse tensors, Hoffman
Stars: ✭ 204 (-19.05%)
Mutual labels:  math
Mathutilities
A collection of some of the neat math and physics tricks that I've collected over the last few years.
Stars: ✭ 2,815 (+1017.06%)
Mutual labels:  math
Stdlib
✨ Standard library for JavaScript and Node.js. ✨
Stars: ✭ 2,749 (+990.87%)
Mutual labels:  math
Expressionevaluator
A Simple Math and Pseudo C# Expression Evaluator in One C# File. Can also execute small C# like scripts
Stars: ✭ 194 (-23.02%)
Mutual labels:  math
Ta Rs
Technical analysis library for Rust language
Stars: ✭ 248 (-1.59%)
Mutual labels:  math
Mathnet Numerics
Math.NET Numerics
Stars: ✭ 2,688 (+966.67%)
Mutual labels:  math
Julia Set Playground
A Swift playground that generates beautiful Julia set fractal images.
Stars: ✭ 236 (-6.35%)
Mutual labels:  math
Csharpmath
LaTeX. in C#. (ported from the wonderful iosMath project).
Stars: ✭ 205 (-18.65%)
Mutual labels:  math
Tutorials
AI-related tutorials. Access any of them for free → https://towardsai.net/editorial
Stars: ✭ 204 (-19.05%)
Mutual labels:  math
Simple Statistics
simple statistics for node & browser javascript
Stars: ✭ 2,679 (+963.1%)
Mutual labels:  math
Jekyll Spaceship
🚀 A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, mermaid, emoji, video, audio, youtube, vimeo, dailymotion, soundcloud, spotify, etc.
Stars: ✭ 196 (-22.22%)
Mutual labels:  math
Fouriertalkoscon
Presentation Materials for my "Sound Analysis with the Fourier Transform and Python" OSCON Talk.
Stars: ✭ 244 (-3.17%)
Mutual labels:  math
Mppp
Multiprecision for modern C++
Stars: ✭ 196 (-22.22%)
Mutual labels:  math
Math Science Video Lectures
List of Science courses with video lectures
Stars: ✭ 219 (-13.1%)
Mutual labels:  math
Polyhedra Viewer
Explore the relationships between convex regular-faced polyhedra.
Stars: ✭ 253 (+0.4%)
Mutual labels:  math
Mathnet Spatial
Math.NET Spatial
Stars: ✭ 246 (-2.38%)
Mutual labels:  math
Upmath.me
Markdown and LaTeX online editor - create text for web with equations and diagrams
Stars: ✭ 234 (-7.14%)
Mutual labels:  math

GCE-Math

Build Status Build status Coverage Status Codacy Badge Language grade: C/C++ Documentation Status

GCE-Math (Generalized Constant Expression Math) is a templated C++ library enabling compile-time computation of mathematical functions.

Features:

  • The library is written in C++11 constexpr format, and is C++11/14/17 compatible.
  • Continued fraction expansions and series expansions are implemented using recursive templates.
  • The gcem:: syntax is identical to the C++ standard library (std::).
  • Tested and accurate to floating-point precision against the C++ standard library.
  • Released under a permissive, non-GPL license.

Author: Keith O'Hara

License

Contents:

Status and Documentation

The library is actively maintained and is still being extended. A list of features includes:

  • Basic library functions:
    • abs, max, min, pow, sqrt,
    • ceil, floor, round, trunc, fmod,
    • exp, expm1, log, log1p, log2, and more
  • Trigonometric functions:
    • basic: cos, sin, tan
    • inverse: acos, asin, atan, atan2
  • Hyperbolic (area) functions:
    • cosh, sinh, tanh, acosh, asinh, atanh
  • Algorithms:
    • gcd, lcm
  • Special functions:
    • factorials and the binomial coefficient: factorial, binomial_coef
    • beta, gamma, and multivariate gamma functions: beta, lbeta, lgamma, tgamma, lmgamma
    • the Gaussian error function and inverse error function: erf, erf_inv
    • (regularized) incomplete beta and incomplete gamma functions: incomplete_beta, incomplete_gamma
    • inverse incomplete beta and incomplete gamma functions: incomplete_beta_inv, incomplete_gamma_inv

Full documentation is available online:

Documentation Status

A PDF version of the documentation is available here.

Installation

GCE-Math is a header-only library and does not require any additional libraries or utilities (beyond a C++11 compatible compiler). Simply add the header files to your project using:

#include "gcem.hpp"

Conda

Anaconda-Server Badge Anaconda-Server Badge

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

conda install -c kthohr gcem

CMake

You can also install the library from source using CMake.

# clone gcem from GitHub
git clone https://github.com/kthohr/gcem ./gcem

# make a build directory
cd ./gcem
mkdir build
cd build

# generate Makefiles and install
cmake .. -DCMAKE_INSTALL_PREFIX=/gcem/install/location
make install

For example, /gcem/install/location could be /usr/local/.

Test Suite

There are two ways to build the test suite. On Unix-alike systems, a Makefile is available under tests/.

cd ./gcem/tests
make
./run_tests

With CMake, the option GCEM_BUILD_TESTS=1 generates the necessary Makefiles to build the test suite.

cd ./gcem
mkdir build

cd build
cmake ../ -DGCEM_BUILD_TESTS=1 -DCMAKE_INSTALL_PREFIX=/gcem/install/location
make gcem_tests

cd tests
./exp.test

Jupyter Notebook

You can test the library online using an interactive Jupyter notebook:

Binder

General Syntax

GCE-Math functions are written as C++ templates with constexpr specifiers, the format of which might appear confusing to users unfamiliar with template-based programming.

For example, the Gaussian error function (erf) is defined as:

template<typename T>
constexpr
return_t<T>
erf(const T x) noexcept;

A set of internal templated constexpr functions will implement a continued fraction expansion and return a value of type return_t<T>. The output type ('return_t<T>') is generally determined by the input type, e.g., int, float, double, long double, etc.; when T is an intergral type, the output will be upgraded to return_t<T> = double, otherwise return_t<T> = T. For types not covered by std::is_integral, recasts should be used.

Examples

To calculate 10!:

#include "gcem.hpp"

int main()
{
    constexpr int x = 10;
    constexpr int res = gcem::factorial(x);

    return 0;
}

Inspecting the assembly code generated by Clang 7.0.0:

        push    rbp
        mov     rbp, rsp
        xor     eax, eax
        mov     dword ptr [rbp - 4], 0
        mov     dword ptr [rbp - 8], 10
        mov     dword ptr [rbp - 12], 3628800
        pop     rbp
        ret

We see that a function call has been replaced by a numeric value (10! = 3628800).

Similarly, to compute the log Gamma function at a point:

#include "gcem.hpp"

int main()
{
    constexpr long double x = 1.5;
    constexpr long double res = gcem::lgamma(x);

    return 0;
}

Assembly code:

.LCPI0_0:
        .long   1069547520              # float 1.5
.LCPI0_1:
        .quad   -622431863250842976     # x86_fp80 -0.120782237635245222719
        .short  49147
        .zero   6
main:                                   # @main
        push    rbp
        mov     rbp, rsp
        xor     eax, eax
        mov     dword ptr [rbp - 4], 0
        fld     dword ptr [rip + .LCPI0_0]
        fstp    tbyte ptr [rbp - 32]
        fld     tbyte ptr [rip + .LCPI0_1]
        fstp    tbyte ptr [rbp - 48]
        pop     rbp
        ret

Related libraries

  • StatsLib is built on GCEM's compile-time functionality.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].