From 96f05a55a63ec28f423e204d8e66a94c9f605e61 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 15 Jul 2015 00:11:15 +0100 Subject: Add util.tanh lua utility. --- src/lua/lua_util.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src') diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c index 8d5686f7c..ff061a927 100644 --- a/src/lua/lua_util.c +++ b/src/lua/lua_util.c @@ -69,6 +69,13 @@ LUA_FUNCTION_DEF (util, decode_base64); */ LUA_FUNCTION_DEF (util, tokenize_text); LUA_FUNCTION_DEF (util, process_message); +/*** + * @function util.tanh(num) + * Calculates hyperbolic tanhent of the specified floating point value + * @param {number} num input number + * @return {number} hyperbolic tanhent of the variable + */ +LUA_FUNCTION_DEF (util, tanh); static const struct luaL_reg utillib_f[] = { LUA_INTERFACE_DEF (util, create_event_base), @@ -78,6 +85,7 @@ static const struct luaL_reg utillib_f[] = { LUA_INTERFACE_DEF (util, encode_base64), LUA_INTERFACE_DEF (util, decode_base64), LUA_INTERFACE_DEF (util, tokenize_text), + LUA_INTERFACE_DEF (util, tanh), {NULL, NULL} }; @@ -425,6 +433,16 @@ lua_util_tokenize_text (lua_State *L) return 1; } +static gint +lua_util_tanh (lua_State *L) +{ + gdouble in = luaL_checknumber (L, 1); + + lua_pushnumber (L, tanh (in)); + + return 1; +} + static gint lua_load_util (lua_State * L) { -- cgit v1.2.3