diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-04-18 16:24:35 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-04-18 16:24:35 -0300 |
| commit | ae00b3a76f3c24092e79eced42b1dfc7cf36acac (patch) | |
| tree | 0c04788ed4f88b2e76b92ee7949e2505bb07d400 | |
| parent | 619be354c8e38b53d36930dc6f7f1242cd2d853f (diff) | |
| download | lua-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)
| -rw-r--r-- | ltable.c | 6 |
1 files changed, 3 insertions, 3 deletions
| @@ -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_ = { | |||
| 84 | static Node *hashnum (const Table *t, lua_Number n) { | 84 | static 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]); |
