diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-07-03 14:23:19 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-07-03 14:23:19 -0300 |
commit | cbe164191c6c3510e225a43c935c6cc3e2da2cd4 (patch) | |
tree | 47efd728a0b82a58d8b7ccf4fa55cfa04c128c20 /lmathlib.c | |
parent | 66d046833d39b6e33be4d3e10ce5c718d283caef (diff) | |
download | lua-cbe164191c6c3510e225a43c935c6cc3e2da2cd4.tar.gz lua-cbe164191c6c3510e225a43c935c6cc3e2da2cd4.tar.bz2 lua-cbe164191c6c3510e225a43c935c6cc3e2da2cd4.zip |
new function 'ifloor'
Diffstat (limited to 'lmathlib.c')
-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}, |