commit e3871abe95446658383ec3576f473a5f1005736e
parent 3fc25ff15b5f7a28bfcc795d220c35ae7b25c6d7
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Wed, 18 Jun 2014 09:35:28 -0300
'math.ifloor' is back
Diffstat:
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git 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},