aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/lapi.c b/lapi.c
index a4b51194..c5d90ac4 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.218 2014/06/12 19:07:30 roberto Exp roberto $ 2** $Id: lapi.c,v 2.219 2014/06/19 18:27:20 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -372,6 +372,11 @@ LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) {
372} 372}
373 373
374 374
375#if !defined(LUAI_FTWO2N)
376/* 2.0^(numbits in an integer), computed without roundings */
377#define LUAI_FTWO2N (cast_num(LUA_MININTEGER) * cast_num(-2))
378#endif
379
375LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *pisnum) { 380LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *pisnum) {
376 lua_Unsigned res = 0; 381 lua_Unsigned res = 0;
377 const TValue *o = index2addr(L, idx); 382 const TValue *o = index2addr(L, idx);
@@ -383,7 +388,7 @@ LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *pisnum) {
383 break; 388 break;
384 } 389 }
385 case LUA_TNUMFLT: { /* compute floor(n) % 2^(numbits in an integer) */ 390 case LUA_TNUMFLT: { /* compute floor(n) % 2^(numbits in an integer) */
386 const lua_Number two2n = cast_num(LUA_MAXUNSIGNED) + cast_num(1); 391 const lua_Number two2n = LUAI_FTWO2N;
387 lua_Number n = fltvalue(o); /* get value */ 392 lua_Number n = fltvalue(o); /* get value */
388 int neg = 0; 393 int neg = 0;
389 n = l_floor(n); /* get its floor */ 394 n = l_floor(n); /* get its floor */