diff --git a/doc_src/cmds/math.rst b/doc_src/cmds/math.rst index d6d466065..cb4041c08 100644 --- a/doc_src/cmds/math.rst +++ b/doc_src/cmds/math.rst @@ -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``) diff --git a/src/tinyexpr.cpp b/src/tinyexpr.cpp index edff3c6c1..7ba06235d 100644 --- a/src/tinyexpr.cpp +++ b/src/tinyexpr.cpp @@ -202,6 +202,7 @@ static const te_builtin functions[] = { {L"ln", reinterpret_cast(static_cast(log)), TE_FUNCTION1}, {L"log", reinterpret_cast(static_cast(log10)), TE_FUNCTION1}, {L"log10", reinterpret_cast(static_cast(log10)), TE_FUNCTION1}, + {L"log2", reinterpret_cast(static_cast(log2)), TE_FUNCTION1}, {L"ncr", reinterpret_cast(static_cast(ncr)), TE_FUNCTION2}, {L"npr", reinterpret_cast(static_cast(npr)), TE_FUNCTION2}, {L"pi", reinterpret_cast(static_cast(pi)), TE_FUNCTION0}, diff --git a/tests/checks/math.fish b/tests/checks/math.fish index 26746717f..2a410cbc6 100644 --- a/tests/checks/math.fish +++ b/tests/checks/math.fish @@ -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