macros for all arithmetic operations over lua_Numbers
This commit is contained in:
10
ltable.c
10
ltable.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ltable.c,v 2.13 2005/01/04 15:55:12 roberto Exp roberto $
|
||||
** $Id: ltable.c,v 2.14 2005/01/05 18:20:51 roberto Exp roberto $
|
||||
** Lua tables (hash)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -119,7 +119,7 @@ static int arrayindex (const TValue *key) {
|
||||
lua_Number n = nvalue(key);
|
||||
int k;
|
||||
lua_number2int(k, n);
|
||||
if (cast(lua_Number, k) == nvalue(key))
|
||||
if (num_eq(cast(lua_Number, k), nvalue(key)))
|
||||
return k;
|
||||
}
|
||||
return -1; /* `key' did not match some condition */
|
||||
@@ -436,7 +436,7 @@ const TValue *luaH_getnum (Table *t, int key) {
|
||||
lua_Number nk = cast(lua_Number, key);
|
||||
Node *n = hashnum(t, nk);
|
||||
do { /* check whether `key' is somewhere in the chain */
|
||||
if (ttisnumber(gkey(n)) && nvalue(gkey(n)) == nk)
|
||||
if (ttisnumber(gkey(n)) && num_eq(nvalue(gkey(n)), nk))
|
||||
return gval(n); /* that's it */
|
||||
else n = gnext(n);
|
||||
} while (n);
|
||||
@@ -469,7 +469,7 @@ const TValue *luaH_get (Table *t, const TValue *key) {
|
||||
case LUA_TNUMBER: {
|
||||
int k;
|
||||
lua_number2int(k, (nvalue(key)));
|
||||
if (cast(lua_Number, k) == nvalue(key)) /* is an integer index? */
|
||||
if (num_eq(cast(lua_Number, k), nvalue(key))) /* is an integer index? */
|
||||
return luaH_getnum(t, k); /* use specialized version */
|
||||
/* else go through */
|
||||
}
|
||||
@@ -493,7 +493,7 @@ TValue *luaH_set (lua_State *L, Table *t, const TValue *key) {
|
||||
return cast(TValue *, p);
|
||||
else {
|
||||
if (ttisnil(key)) luaG_runerror(L, "table index is nil");
|
||||
else if (ttisnumber(key) && nvalue(key) != nvalue(key))
|
||||
else if (ttisnumber(key) && !num_eq(nvalue(key), nvalue(key)))
|
||||
luaG_runerror(L, "table index is NaN");
|
||||
return newkey(L, t, key);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user