.. Copyright (c) 2016-2020 Keith O'Hara

   Distributed under the terms of the Apache License, Version 2.0.

   The full license is in the file LICENSE, distributed with this software.

Examples
===========

To calculate 10!:

.. code:: cpp

    #include "gcem.hpp"

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

        return 0;
    }

Inspecting the assembly code generated by Clang:

.. code:: asm

        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:

.. code:: cpp

    #include "gcem.hpp"

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

        return 0;
    }

Assembly code:

.. code:: asm

    .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:

.. code:: bash

    # clone gcem from GitHub
    git clone -b master --single-branch https://github.com/kthohr/gcem ./gcem
    # compile tests
    cd ./gcem/tests
    make
    ./run_tests
