From 5eb4de4285e42b7c792d9eec241c2c92fe637f10 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 26 Aug 2020 17:30:33 +0200 Subject: [PATCH] math: Implement tau --- doc_src/cmds/math.rst | 2 +- src/tinyexpr.cpp | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/doc_src/cmds/math.rst b/doc_src/cmds/math.rst index 468d1b50a..8669b2cbe 100644 --- a/doc_src/cmds/math.rst +++ b/doc_src/cmds/math.rst @@ -61,7 +61,7 @@ Constants ``math`` knows the following constants: - ``e`` - Euler's number. -- ``pi`` - You know that one. Half of Tau. (Tau is not implemented) +- ``pi`` - You know that one. Half of Tau. (``tau`` is also implemented) Use them without a leading ``$`` - ``pi - 3`` should be about 0. diff --git a/src/tinyexpr.cpp b/src/tinyexpr.cpp index a44503b2e..8d0716393 100644 --- a/src/tinyexpr.cpp +++ b/src/tinyexpr.cpp @@ -137,6 +137,7 @@ void te_free(te_expr *n) { } static constexpr double pi() { return M_PI; } +static constexpr double tau() { return 2 * M_PI; } static constexpr double e() { return M_E; } static double fac(double a) { /* simplest version of fac */ @@ -209,7 +210,9 @@ static const te_builtin functions[] = { {"sinh", reinterpret_cast(static_cast(sinh)), TE_FUNCTION1}, {"sqrt", reinterpret_cast(static_cast(sqrt)), TE_FUNCTION1}, {"tan", reinterpret_cast(static_cast(tan)), TE_FUNCTION1}, - {"tanh", reinterpret_cast(static_cast(tanh)), TE_FUNCTION1}}; + {"tanh", reinterpret_cast(static_cast(tanh)), TE_FUNCTION1}, + {"tau", reinterpret_cast(static_cast(tau)), TE_FUNCTION0}, +}; static const te_builtin *find_builtin(const char *name, int len) { const auto end = std::end(functions);