aboutsummaryrefslogtreecommitdiff
path: root/lmathlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-06-18 09:35:53 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-06-18 09:35:53 -0300
commite3871abe95446658383ec3576f473a5f1005736e (patch)
treef7f9ce63850bbfa850a69347ec55343889afc5d0 /lmathlib.c
parent3fc25ff15b5f7a28bfcc795d220c35ae7b25c6d7 (diff)
downloadlua-e3871abe95446658383ec3576f473a5f1005736e.tar.gz
lua-e3871abe95446658383ec3576f473a5f1005736e.tar.bz2
lua-e3871abe95446658383ec3576f473a5f1005736e.zip
'math.ifloor' is back
Diffstat (limited to 'lmathlib.c')
-rw-r--r--lmathlib.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/lmathlib.c b/lmathlib.c
index 6ba1b3f5..711f1d3a 100644
--- a/lmathlib.c
+++ b/lmathlib.c
@@ -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
79static 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
79static int math_floor (lua_State *L) { 92static 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},