aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-02-26 09:39:30 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-02-26 09:39:30 -0300
commit87c930676f4aef54054024b73a245a24747aa163 (patch)
tree0eb0e11208ed395a761af21e7e7885156eed7da2
parent11e762dbcd5400b2d53af51cd21ac681f25b9585 (diff)
downloadlua-87c930676f4aef54054024b73a245a24747aa163.tar.gz
lua-87c930676f4aef54054024b73a245a24747aa163.tar.bz2
lua-87c930676f4aef54054024b73a245a24747aa163.zip
detail (comments)
-rw-r--r--lapi.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/lapi.c b/lapi.c
index 05708fe8..cc521b31 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.198 2014/02/19 13:51:09 roberto Exp roberto $ 2** $Id: lapi.c,v 2.199 2014/02/25 14:30:21 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*/
@@ -379,20 +379,20 @@ LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *pisnum) {
379 isnum = 1; 379 isnum = 1;
380 break; 380 break;
381 } 381 }
382 case LUA_TNUMFLT: { 382 case LUA_TNUMFLT: { /* compute floor(n) % 2^(numbits in an integer) */
383 const lua_Number twop = (~(lua_Unsigned)0) + cast_num(1); 383 const lua_Number twop = cast_num(MAX_UINTEGER) + cast_num(1); /* 2^n */
384 lua_Number n = fltvalue(o); 384 lua_Number n = fltvalue(o); /* get value */
385 int neg = 0; 385 int neg = 0;
386 n = l_floor(n); 386 n = l_floor(n); /* get its floor */
387 if (n < 0) { 387 if (n < 0) {
388 neg = 1; 388 neg = 1;
389 n = -n; 389 n = -n; /* make 'n' positive, so that 'fmod' is the same as '%' */
390 } 390 }
391 n = l_mathop(fmod)(n, twop); 391 n = l_mathop(fmod)(n, twop); /* n = n % 2^(numbits in an integer) */
392 if (luai_numisnan(n)) /* not a number? */ 392 if (luai_numisnan(n)) /* not a number? */
393 break; /* not an integer, too */ 393 break; /* not an integer, too */
394 res = cast_unsigned(n); 394 res = cast_unsigned(n); /* 'n' now must fit in an unsigned */
395 if (neg) res = 0u - res; 395 if (neg) res = 0u - res; /* back to negative, if needed */
396 isnum = 1; 396 isnum = 1;
397 break; 397 break;
398 } 398 }