math: Add log2

This was already in the documentation as an example, now it is
actually working.

Fixes #7734
This commit is contained in:
Fabian Homborg 2021-02-21 08:48:38 +01:00
parent dc417f58ae
commit cbd8f5f63e
3 changed files with 5 additions and 0 deletions

View File

@ -87,6 +87,7 @@ Functions
- ``floor`` - round number down to nearest integer
- ``ln`` - the base-e logarithm
- ``log`` or ``log10`` - the base-10 logarithm
- ``log2`` - the base-2 logarithm
- ``ncr`` - "from n choose r" combination function - how many subsets of size r can be taken from n (order doesn't matter)
- ``npr`` - the number of subsets of size r that can be taken from a set of n elements (including different order)
- ``pow(x,y)`` returns x to the y (and can be written as ``x ^ y``)

View File

@ -202,6 +202,7 @@ static const te_builtin functions[] = {
{L"ln", reinterpret_cast<const void *>(static_cast<te_fun1>(log)), TE_FUNCTION1},
{L"log", reinterpret_cast<const void *>(static_cast<te_fun1>(log10)), TE_FUNCTION1},
{L"log10", reinterpret_cast<const void *>(static_cast<te_fun1>(log10)), TE_FUNCTION1},
{L"log2", reinterpret_cast<const void *>(static_cast<te_fun1>(log2)), TE_FUNCTION1},
{L"ncr", reinterpret_cast<const void *>(static_cast<te_fun2>(ncr)), TE_FUNCTION2},
{L"npr", reinterpret_cast<const void *>(static_cast<te_fun2>(npr)), TE_FUNCTION2},
{L"pi", reinterpret_cast<const void *>(static_cast<te_fun0>(pi)), TE_FUNCTION0},

View File

@ -186,3 +186,6 @@ math --base notabase
# CHECKERR: math: 'notabase' is not a valid base value
echo $status
# CHECK: 2
math 'log2(8)'
# CHECK: 3