diff options
Diffstat (limited to 'lmathlib.c')
-rw-r--r-- | lmathlib.c | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmathlib.c,v 1.101 2014/05/26 17:13:52 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.102 2014/06/02 23:09:28 roberto Exp roberto $ |
3 | ** Standard mathematical library | 3 | ** Standard mathematical library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -76,6 +76,19 @@ static int math_atan (lua_State *L) { | |||
76 | } | 76 | } |
77 | 77 | ||
78 | 78 | ||
79 | static int math_ifloor (lua_State *L) { | ||
80 | int valid; | ||
81 | lua_Integer n = lua_tointegerx(L, 1, &valid); | ||
82 | if (valid) | ||
83 | lua_pushinteger(L, n); /* floor computed by Lua */ | ||
84 | else { | ||
85 | luaL_checktype(L, 1, LUA_TNUMBER); /* argument must be a number */ | ||
86 | lua_pushnil(L); /* number is not convertible to integer */ | ||
87 | } | ||
88 | return 1; | ||
89 | } | ||
90 | |||
91 | |||
79 | static int math_floor (lua_State *L) { | 92 | static int math_floor (lua_State *L) { |
80 | int valid; | 93 | int valid; |
81 | lua_Integer n = lua_tointegerx(L, 1, &valid); | 94 | lua_Integer n = lua_tointegerx(L, 1, &valid); |
@@ -326,6 +339,7 @@ static const luaL_Reg mathlib[] = { | |||
326 | {"cos", math_cos}, | 339 | {"cos", math_cos}, |
327 | {"deg", math_deg}, | 340 | {"deg", math_deg}, |
328 | {"exp", math_exp}, | 341 | {"exp", math_exp}, |
342 | {"ifloor", math_ifloor}, | ||
329 | {"floor", math_floor}, | 343 | {"floor", math_floor}, |
330 | {"fmod", math_fmod}, | 344 | {"fmod", math_fmod}, |
331 | {"log", math_log}, | 345 | {"log", math_log}, |