'math.ifloor' is back

This commit is contained in:
Roberto Ierusalimschy 2014-06-18 09:35:53 -03:00
parent 3fc25ff15b
commit e3871abe95
1 changed files with 15 additions and 1 deletions

View File

@ -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},