mirror of https://github.com/rusefi/lua.git
another way to normalize -0 that avoids problems with very small
numbers (adding 1 turns them all into 1)
This commit is contained in:
parent
619be354c8
commit
ae00b3a76f
6
ltable.c
6
ltable.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: ltable.c,v 2.35 2006/09/11 14:07:24 roberto Exp roberto $
|
** $Id: ltable.c,v 2.36 2007/04/10 12:18:17 roberto Exp roberto $
|
||||||
** Lua tables (hash)
|
** Lua tables (hash)
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -84,8 +84,8 @@ static const Node dummynode_ = {
|
||||||
static Node *hashnum (const Table *t, lua_Number n) {
|
static Node *hashnum (const Table *t, lua_Number n) {
|
||||||
unsigned int a[numints];
|
unsigned int a[numints];
|
||||||
int i;
|
int i;
|
||||||
n += 1; /* normalize number (avoid -0) */
|
if (luai_numeq(n, 0)) /* avoid problems with -0 */
|
||||||
lua_assert(sizeof(a) <= sizeof(n));
|
return gnode(t, 0);
|
||||||
memcpy(a, &n, sizeof(a));
|
memcpy(a, &n, sizeof(a));
|
||||||
for (i = 1; i < numints; i++) a[0] += a[i];
|
for (i = 1; i < numints; i++) a[0] += a[i];
|
||||||
return hashmod(t, a[0]);
|
return hashmod(t, a[0]);
|
||||||
|
|
Loading…
Reference in New Issue