diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-06-18 09:35:53 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-06-18 09:35:53 -0300 |
commit | e3871abe95446658383ec3576f473a5f1005736e (patch) | |
tree | f7f9ce63850bbfa850a69347ec55343889afc5d0 /lmathlib.c | |
parent | 3fc25ff15b5f7a28bfcc795d220c35ae7b25c6d7 (diff) | |
download | lua-e3871abe95446658383ec3576f473a5f1005736e.tar.gz lua-e3871abe95446658383ec3576f473a5f1005736e.tar.bz2 lua-e3871abe95446658383ec3576f473a5f1005736e.zip |
'math.ifloor' is back
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}, |