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:
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
Test suite¶
To build the full test suite:
# clone gcem from GitHub
git clone -b master --single-branch https://github.com/kthohr/gcem ./gcem
# compile tests
cd ./gcem/tests
make
./run_tests