aboutsummaryrefslogtreecommitdiff
path: root/ltable.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2007-04-18 16:24:35 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2007-04-18 16:24:35 -0300
commitae00b3a76f3c24092e79eced42b1dfc7cf36acac (patch)
tree0c04788ed4f88b2e76b92ee7949e2505bb07d400 /ltable.c
parent619be354c8e38b53d36930dc6f7f1242cd2d853f (diff)
downloadlua-ae00b3a76f3c24092e79eced42b1dfc7cf36acac.tar.gz
lua-ae00b3a76f3c24092e79eced42b1dfc7cf36acac.tar.bz2
lua-ae00b3a76f3c24092e79eced42b1dfc7cf36acac.zip
another way to normalize -0 that avoids problems with very small
numbers (adding 1 turns them all into 1)
Diffstat (limited to 'ltable.c')
-rw-r--r--ltable.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/ltable.c b/ltable.c
index 1b3bc540..def5d581 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 2.35 2006/09/11 14:07:24 roberto Exp roberto $ 2** $Id: ltable.c,v 2.36 2007/04/10 12:18:17 roberto Exp roberto $
3** Lua tables (hash) 3** Lua tables (hash)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -84,8 +84,8 @@ static const Node dummynode_ = {
84static Node *hashnum (const Table *t, lua_Number n) { 84static Node *hashnum (const Table *t, lua_Number n) {
85 unsigned int a[numints]; 85 unsigned int a[numints];
86 int i; 86 int i;
87 n += 1; /* normalize number (avoid -0) */ 87 if (luai_numeq(n, 0)) /* avoid problems with -0 */
88 lua_assert(sizeof(a) <= sizeof(n)); 88 return gnode(t, 0);
89 memcpy(a, &n, sizeof(a)); 89 memcpy(a, &n, sizeof(a));
90 for (i = 1; i < numints; i++) a[0] += a[i]; 90 for (i = 1; i < numints; i++) a[0] += a[i];
91 return hashmod(t, a[0]); 91 return hashmod(t, a[0]);