math: Implement tau

This commit is contained in:
Fabian Homborg 2020-08-26 17:30:33 +02:00
parent f14a1d3a27
commit 5eb4de4285
2 changed files with 5 additions and 2 deletions

View File

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

View File

@ -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<const void *>(static_cast<te_fun1>(sinh)), TE_FUNCTION1},
{"sqrt", reinterpret_cast<const void *>(static_cast<te_fun1>(sqrt)), TE_FUNCTION1},
{"tan", reinterpret_cast<const void *>(static_cast<te_fun1>(tan)), TE_FUNCTION1},
{"tanh", reinterpret_cast<const void *>(static_cast<te_fun1>(tanh)), TE_FUNCTION1}};
{"tanh", reinterpret_cast<const void *>(static_cast<te_fun1>(tanh)), TE_FUNCTION1},
{"tau", reinterpret_cast<const void *>(static_cast<te_fun0>(tau)), TE_FUNCTION0},
};
static const te_builtin *find_builtin(const char *name, int len) {
const auto end = std::end(functions);