From 64d9a00a9934cd06401f4b9ec2e14950a4423a87 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Mon, 26 Oct 2009 04:52:07 +0000 Subject: nixio: store stats and other number information as integer, which works better when lua number support is downgraded from double to float --- libs/nixio/src/bit.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'libs/nixio/src/bit.c') diff --git a/libs/nixio/src/bit.c b/libs/nixio/src/bit.c index 9991a7ca4..5b41e91aa 100644 --- a/libs/nixio/src/bit.c +++ b/libs/nixio/src/bit.c @@ -21,19 +21,19 @@ #include /* 52 bit maximum precision */ -#define NIXIO_BIT_BMAX 52 -#define NIXIO_BIT_NMAX 0xfffffffffffff +#define NIXIO_BIT_BMAX 32 +#define NIXIO_BIT_NMAX 0xffffffff #define NIXIO_BIT_XOP(BIT_XOP) \ - uint64_t oper = luaL_checknumber(L, 1); \ + uint64_t oper = luaL_checkinteger(L, 1); \ const int args = lua_gettop(L); \ \ for (int i = 2; i <= args; i++) { \ - uint64_t oper2 = luaL_checknumber(L, i); \ + uint64_t oper2 = luaL_checkinteger(L, i); \ oper BIT_XOP oper2; \ } \ \ - lua_pushnumber(L, oper); \ + lua_pushinteger(L, oper); \ return 1; \ @@ -54,30 +54,30 @@ static int nixio_bit_unset(lua_State *L) { } static int nixio_bit_not(lua_State *L) { - lua_pushnumber(L, (~((uint64_t)luaL_checknumber(L, 1))) & NIXIO_BIT_NMAX); + lua_pushinteger(L, (~((uint64_t)luaL_checkinteger(L, 1))) & NIXIO_BIT_NMAX); return 1; } static int nixio_bit_shl(lua_State *L) { - uint64_t oper = luaL_checknumber(L, 1); + uint64_t oper = luaL_checkinteger(L, 1); oper <<= luaL_checkinteger(L, 2); if (oper > NIXIO_BIT_NMAX) { return luaL_error(L, "arithmetic overflow"); } else { - lua_pushnumber(L, oper); + lua_pushinteger(L, oper); return 1; } } static int nixio_bit_ashr(lua_State *L) { - int64_t oper = luaL_checknumber(L, 1); - lua_pushnumber(L, oper >> luaL_checkinteger(L, 2)); + int64_t oper = luaL_checkinteger(L, 1); + lua_pushinteger(L, oper >> luaL_checkinteger(L, 2)); return 1; } static int nixio_bit_shr(lua_State *L) { - uint64_t oper = luaL_checknumber(L, 1); - lua_pushnumber(L, oper >> luaL_checkinteger(L, 2)); + uint64_t oper = luaL_checkinteger(L, 1); + lua_pushinteger(L, oper >> luaL_checkinteger(L, 2)); return 1; } @@ -86,21 +86,21 @@ static int nixio_bit_div(lua_State *L) { } static int nixio_bit_check(lua_State *L) { - uint64_t oper = luaL_checknumber(L, 1); - uint64_t oper2 = luaL_checknumber(L, 2); + uint64_t oper = luaL_checkinteger(L, 1); + uint64_t oper2 = luaL_checkinteger(L, 2); lua_pushboolean(L, (oper & oper2) == oper2); return 1; } static int nixio_bit_cast(lua_State *L) { - lua_pushnumber(L, ((uint64_t)luaL_checknumber(L, 1)) & NIXIO_BIT_NMAX); + lua_pushinteger(L, ((uint64_t)luaL_checkinteger(L, 1)) & NIXIO_BIT_NMAX); return 1; } static int nixio_bit_swap(lua_State *L) { - uint64_t op = luaL_checknumber(L, 1); + uint64_t op = luaL_checkinteger(L, 1); op = (op >> 24) | ((op >> 8) & 0xff00) | ((op & 0xff00) << 8) | (op << 24); - lua_pushnumber(L, op); + lua_pushinteger(L, op); return 1; } @@ -126,9 +126,9 @@ static const luaL_reg R[] = { void nixio_open_bit(lua_State *L) { lua_newtable(L); luaL_register(L, NULL, R); - lua_pushnumber(L, NIXIO_BIT_BMAX); + lua_pushinteger(L, NIXIO_BIT_BMAX); lua_setfield(L, -2, "bits"); - lua_pushnumber(L, NIXIO_BIT_NMAX); + lua_pushinteger(L, NIXIO_BIT_NMAX); lua_setfield(L, -2, "max"); lua_setfield(L, -2, "bit"); } -- cgit v1.2.3