aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-05-06 14:22:55 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-05-06 14:22:55 -0300
commit0233ce08151e1f826fed3d0c3bc13da05c277811 (patch)
treeb6667c720ccf8b6174a0301aa6e704923de9bd6d
parent1f2b82bf25e8893add740a0b4cdb9c54fc9f6053 (diff)
downloadlua-0233ce08151e1f826fed3d0c3bc13da05c277811.tar.gz
lua-0233ce08151e1f826fed3d0c3bc13da05c277811.tar.bz2
lua-0233ce08151e1f826fed3d0c3bc13da05c277811.zip
new function 'math.numbits' (not a final decision)
-rw-r--r--lmathlib.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/lmathlib.c b/lmathlib.c
index b07048c7..4eeaae9e 100644
--- a/lmathlib.c
+++ b/lmathlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmathlib.c,v 1.83 2013/03/07 18:21:32 roberto Exp roberto $ 2** $Id: lmathlib.c,v 1.84 2013/05/02 17:31:54 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*/
@@ -236,6 +236,19 @@ static int math_isfloat (lua_State *L) {
236 return 1; 236 return 1;
237} 237}
238 238
239
240static int math_numbits (lua_State *L) {
241 const char *s = luaL_checkstring(L, 1);
242 if (*s == 'i')
243 lua_pushinteger(L, sizeof(lua_Integer) * CHAR_BIT);
244 else if (*s == 'f')
245 lua_pushinteger(L, sizeof(lua_Number) * CHAR_BIT);
246 else
247 luaL_argerror(L, 1, lua_pushfstring(L, "invalid option '%s'", s));
248 return 1;
249}
250
251
239static const luaL_Reg mathlib[] = { 252static const luaL_Reg mathlib[] = {
240 {"abs", math_abs}, 253 {"abs", math_abs},
241 {"acos", math_acos}, 254 {"acos", math_acos},
@@ -265,6 +278,7 @@ static const luaL_Reg mathlib[] = {
265 {"randomseed", math_randomseed}, 278 {"randomseed", math_randomseed},
266 {"sinh", math_sinh}, 279 {"sinh", math_sinh},
267 {"sin", math_sin}, 280 {"sin", math_sin},
281 {"numbits", math_numbits},
268 {"sqrt", math_sqrt}, 282 {"sqrt", math_sqrt},
269 {"tanh", math_tanh}, 283 {"tanh", math_tanh},
270 {"tan", math_tan}, 284 {"tan", math_tan},