diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-04-12 11:45:10 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-04-12 11:45:10 -0300 |
commit | ef789d4161b6f2b6c28c28c71268a591e9ec6d42 (patch) | |
tree | 4c5f4ddcf0c9ab3f75e05e270c341ff3826724c6 | |
parent | b390d7c168ac85f5cef85b6a2a5716e5fde388a8 (diff) | |
download | lua-ef789d4161b6f2b6c28c28c71268a591e9ec6d42.tar.gz lua-ef789d4161b6f2b6c28c28c71268a591e9ec6d42.tar.bz2 lua-ef789d4161b6f2b6c28c28c71268a591e9ec6d42.zip |
new global macro 'LUA_MAXUNSIGNED'
-rw-r--r-- | lapi.c | 6 | ||||
-rw-r--r-- | llimits.h | 6 | ||||
-rw-r--r-- | lstrlib.c | 4 |
3 files changed, 6 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.201 2014/03/12 20:57:40 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.202 2014/04/01 18:51:23 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 | */ |
@@ -381,7 +381,7 @@ LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *pisnum) { | |||
381 | break; | 381 | break; |
382 | } | 382 | } |
383 | case LUA_TNUMFLT: { /* compute floor(n) % 2^(numbits in an integer) */ | 383 | case LUA_TNUMFLT: { /* compute floor(n) % 2^(numbits in an integer) */ |
384 | const lua_Number twop = cast_num(MAX_UINTEGER) + cast_num(1); /* 2^n */ | 384 | const lua_Number two2n = cast_num(LUA_MAXUNSIGNED) + cast_num(1); |
385 | lua_Number n = fltvalue(o); /* get value */ | 385 | lua_Number n = fltvalue(o); /* get value */ |
386 | int neg = 0; | 386 | int neg = 0; |
387 | n = l_floor(n); /* get its floor */ | 387 | n = l_floor(n); /* get its floor */ |
@@ -389,7 +389,7 @@ LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *pisnum) { | |||
389 | neg = 1; | 389 | neg = 1; |
390 | n = -n; /* make 'n' positive, so that 'fmod' is the same as '%' */ | 390 | n = -n; /* make 'n' positive, so that 'fmod' is the same as '%' */ |
391 | } | 391 | } |
392 | n = l_mathop(fmod)(n, twop); /* n = n % 2^(numbits in an integer) */ | 392 | n = l_mathop(fmod)(n, two2n); /* n = n % 2^(numbits in an integer) */ |
393 | if (luai_numisnan(n)) /* not a number? */ | 393 | if (luai_numisnan(n)) /* not a number? */ |
394 | break; /* not an integer, too */ | 394 | break; /* not an integer, too */ |
395 | res = cast_unsigned(n); /* 'n' now must fit in an unsigned */ | 395 | res = cast_unsigned(n); /* 'n' now must fit in an unsigned */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llimits.h,v 1.112 2014/04/11 19:02:16 roberto Exp roberto $ | 2 | ** $Id: llimits.h,v 1.113 2014/04/11 19:56:04 roberto Exp roberto $ |
3 | ** Limits, basic types, and some other `installation-dependent' definitions | 3 | ** Limits, basic types, and some other `installation-dependent' definitions |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -27,10 +27,6 @@ typedef LUAI_MEM l_mem; | |||
27 | typedef unsigned char lu_byte; | 27 | typedef unsigned char lu_byte; |
28 | 28 | ||
29 | 29 | ||
30 | /* maximum value for a lua_Unsigned */ | ||
31 | #define MAX_UINTEGER (((lua_Unsigned)LUA_MAXINTEGER << 1) + 1u) | ||
32 | |||
33 | |||
34 | /* maximum value for size_t */ | 30 | /* maximum value for size_t */ |
35 | #define MAX_SIZET ((size_t)(~(size_t)0)-2) | 31 | #define MAX_SIZET ((size_t)(~(size_t)0)-2) |
36 | 32 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstrlib.c,v 1.193 2014/04/10 18:24:12 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.194 2014/04/10 19:45:43 roberto Exp roberto $ |
3 | ** Standard library for string operations and pattern-matching | 3 | ** Standard library for string operations and pattern-matching |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -1008,7 +1008,7 @@ static int dumpint (char *buff, lua_Unsigned n, int littleendian, int size) { | |||
1008 | /* OK if there are only zeros left in higher bytes, | 1008 | /* OK if there are only zeros left in higher bytes, |
1009 | or only ones left (excluding non-signal bits in last byte) */ | 1009 | or only ones left (excluding non-signal bits in last byte) */ |
1010 | return ((n & ~(lua_Integer)MC) == 0 || | 1010 | return ((n & ~(lua_Integer)MC) == 0 || |
1011 | (n | SM) == (~(lua_Unsigned)0 >> ((size - 1) * NB))); | 1011 | (n | SM) == (LUA_MAXUNSIGNED >> ((size - 1) * NB))); |
1012 | } | 1012 | } |
1013 | else return 1; /* no overflow can occur with full size */ | 1013 | else return 1; /* no overflow can occur with full size */ |
1014 | } | 1014 | } |