]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Add util.tanh lua utility.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 14 Jul 2015 23:11:15 +0000 (00:11 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 14 Jul 2015 23:11:15 +0000 (00:11 +0100)
src/lua/lua_util.c

index 8d5686f7c1442f79cbc3f1d5fbfb0b93585ee2c1..ff061a9275e8c7287ef8ba39881cbac7d85ba827 100644 (file)
@@ -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)
 {