diff options
Diffstat (limited to '')
| -rw-r--r-- | lmathlib.c | 15 |
1 files changed, 14 insertions, 1 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmathlib.c,v 1.88 2013/06/25 14:02:18 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.89 2013/06/25 19:37:00 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 | */ |
| @@ -88,6 +88,18 @@ static int math_floor (lua_State *L) { | |||
| 88 | return 1; | 88 | return 1; |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | static int math_ifloor (lua_State *L) { | ||
| 92 | int valid; | ||
| 93 | lua_Integer n = lua_tointegerx(L, 1, &valid); | ||
| 94 | if (valid) | ||
| 95 | lua_pushinteger(L, n); | ||
| 96 | else { | ||
| 97 | luaL_checktype(L, 1, LUA_TNUMBER); /* error if not a number */ | ||
| 98 | lua_pushnil(L); /* number with invalid integer value */ | ||
| 99 | } | ||
| 100 | return 1; | ||
| 101 | } | ||
| 102 | |||
| 91 | static int math_fmod (lua_State *L) { | 103 | static int math_fmod (lua_State *L) { |
| 92 | lua_pushnumber(L, l_mathop(fmod)(luaL_checknumber(L, 1), | 104 | lua_pushnumber(L, l_mathop(fmod)(luaL_checknumber(L, 1), |
| 93 | luaL_checknumber(L, 2))); | 105 | luaL_checknumber(L, 2))); |
| @@ -258,6 +270,7 @@ static const luaL_Reg mathlib[] = { | |||
| 258 | {"deg", math_deg}, | 270 | {"deg", math_deg}, |
| 259 | {"exp", math_exp}, | 271 | {"exp", math_exp}, |
| 260 | {"floor", math_floor}, | 272 | {"floor", math_floor}, |
| 273 | {"ifloor", math_ifloor}, | ||
| 261 | {"fmod", math_fmod}, | 274 | {"fmod", math_fmod}, |
| 262 | {"frexp", math_frexp}, | 275 | {"frexp", math_frexp}, |
| 263 | {"isfloat", math_isfloat}, | 276 | {"isfloat", math_isfloat}, |
