aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lapi.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/lapi.c b/lapi.c
index 73573c3d..8515f5a0 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.180 2013/05/14 16:00:11 roberto Exp roberto $ 2** $Id: lapi.c,v 2.181 2013/06/04 19:34:51 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*/
@@ -389,13 +389,17 @@ LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *pisnum) {
389 case LUA_TNUMFLT: { 389 case LUA_TNUMFLT: {
390 const lua_Number twop = (~(lua_Unsigned)0) + cast_num(1); 390 const lua_Number twop = (~(lua_Unsigned)0) + cast_num(1);
391 lua_Number n = fltvalue(o); 391 lua_Number n = fltvalue(o);
392 n = l_mathop(fmod)(n, twop); 392 int neg = 0;
393 n = l_mathop(floor)(n); 393 n = l_mathop(floor)(n);
394 if (n < 0) {
395 neg = 1;
396 n = -n;
397 }
398 n = l_mathop(fmod)(n, twop);
394 if (luai_numisnan(L,n)) /* not a number? */ 399 if (luai_numisnan(L,n)) /* not a number? */
395 break; /* not an integer, too */ 400 break; /* not an integer, too */
396 if (n < 0)
397 n += twop; /* correct 'mod' */
398 res = cast_unsigned(n); 401 res = cast_unsigned(n);
402 if (neg) res = -res;
399 isnum = 1; 403 isnum = 1;
400 break; 404 break;
401 } 405 }