From e3871abe95446658383ec3576f473a5f1005736e Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 18 Jun 2014 09:35:53 -0300 Subject: [PATCH] 'math.ifloor' is back --- lmathlib.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lmathlib.c b/lmathlib.c index 6ba1b3f5..711f1d3a 100644 --- a/lmathlib.c +++ b/lmathlib.c @@ -1,5 +1,5 @@ /* -** $Id: lmathlib.c,v 1.101 2014/05/26 17:13:52 roberto Exp roberto $ +** $Id: lmathlib.c,v 1.102 2014/06/02 23:09:28 roberto Exp roberto $ ** Standard mathematical library ** See Copyright Notice in lua.h */ @@ -76,6 +76,19 @@ static int math_atan (lua_State *L) { } +static int math_ifloor (lua_State *L) { + int valid; + lua_Integer n = lua_tointegerx(L, 1, &valid); + if (valid) + lua_pushinteger(L, n); /* floor computed by Lua */ + else { + luaL_checktype(L, 1, LUA_TNUMBER); /* argument must be a number */ + lua_pushnil(L); /* number is not convertible to integer */ + } + return 1; +} + + static int math_floor (lua_State *L) { int valid; lua_Integer n = lua_tointegerx(L, 1, &valid); @@ -326,6 +339,7 @@ static const luaL_Reg mathlib[] = { {"cos", math_cos}, {"deg", math_deg}, {"exp", math_exp}, + {"ifloor", math_ifloor}, {"floor", math_floor}, {"fmod", math_fmod}, {"log", math_log},