diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-05-06 14:22:55 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-05-06 14:22:55 -0300 |
commit | 0233ce08151e1f826fed3d0c3bc13da05c277811 (patch) | |
tree | b6667c720ccf8b6174a0301aa6e704923de9bd6d | |
parent | 1f2b82bf25e8893add740a0b4cdb9c54fc9f6053 (diff) | |
download | lua-0233ce08151e1f826fed3d0c3bc13da05c277811.tar.gz lua-0233ce08151e1f826fed3d0c3bc13da05c277811.tar.bz2 lua-0233ce08151e1f826fed3d0c3bc13da05c277811.zip |
new function 'math.numbits' (not a final decision)
-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.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 | |||
240 | static 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 | |||
239 | static const luaL_Reg mathlib[] = { | 252 | static 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}, |