From 54ac5960a800c32d7d9824d15b14a31131301678 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 24 Jun 2014 14:02:00 -0300 Subject: LUA_MAXUNSIGNED was only used to define 2.0^intnumbits (and that definition was not strictly portable), so it was removed and replaced by a more correct and direct definition for 2.0^intnumbits (only where it was needed) --- lapi.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lapi.c') diff --git a/lapi.c b/lapi.c index a4b51194..c5d90ac4 100644 --- a/lapi.c +++ b/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 2.218 2014/06/12 19:07:30 roberto Exp roberto $ +** $Id: lapi.c,v 2.219 2014/06/19 18:27:20 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -372,6 +372,11 @@ LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) { } +#if !defined(LUAI_FTWO2N) +/* 2.0^(numbits in an integer), computed without roundings */ +#define LUAI_FTWO2N (cast_num(LUA_MININTEGER) * cast_num(-2)) +#endif + LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *pisnum) { lua_Unsigned res = 0; const TValue *o = index2addr(L, idx); @@ -383,7 +388,7 @@ LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *pisnum) { break; } case LUA_TNUMFLT: { /* compute floor(n) % 2^(numbits in an integer) */ - const lua_Number two2n = cast_num(LUA_MAXUNSIGNED) + cast_num(1); + const lua_Number two2n = LUAI_FTWO2N; lua_Number n = fltvalue(o); /* get value */ int neg = 0; n = l_floor(n); /* get its floor */ -- cgit v1.2.3-55-g6feb