mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Oct 2006
Posts: 48
G
Ghozer Offline OP
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Oct 2006
Posts: 48
ok, a little background first, im using hash tables to store data from a text based, dcc chat game... part of the game im tracking a total.. and i found a bug, but im not 100% sure on the threshold...

is there a max value for a hash table entry?? if so, what is it? how can I avoid this? or is it indeed, a bug?

NOTE: it doesnt matter on the table, or item name, but I have put down here what im using...

Create a table, and an entry... set the value for the entry as 2099721840

/hmake stats 1000
/hadd stats tfactprod 2099721840

increse the item "tfactprod" by X (which is tallyd up in a while loop)

var %tot = $calc(%tot + %playertot)
(in this case, %tot = 74040191)

increse the hash table entry by %tot

/hinc stats tfactprod %tot
(have also used /hadd stats tfactprod $calc($hget(stats,tfactprod) + %tot) with the same outcome)

how echo back the table item...

/echo -a $hget(stats,tfactprod)

it will reply with -2121205265

WHY is it coming back with a minus figure??

2099721840 + 74040191 = 2173762031

even the figure, ignoring the minus is low..

any ideas?? wink -- can anyone find the threshold where it goes into minus figures etc?? .. basically, i need help :P

Joined: Dec 2002
Posts: 503
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
Welcome to 32bit signed integers. This appears to be a bug with 'hinc' wink

Reproduced here, v6.3 (XPSP2)

Joined: Jun 2006
Posts: 508
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 508
Quote:
(have also used /hadd stats tfactprod $calc($hget(stats,tfactprod) + %tot) with the same outcome)

Hm, I can use hadd with $calc() and get the right result
Code:
//var %a = 2099721840,%b = 74040191 |  hadd -m test a %a | hadd test a $calc($hget(test,a) + %b) | echo -ag * $hget(test,a) == $calc(%a + %b) | hfree test

* 2173762031 == 2173762031

Joined: Oct 2003
Posts: 313
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Oct 2003
Posts: 313
Confirmed. You cannot hinc past 2147483647 (0x7FFFFFFF)

I assume $calc uses maths routines that allow for higher precision.

As you found, hadd table entry $calc(%val + %inc) will work correctly...at least up to the limits of $calc's precision! I guess this is because it's hadd'ing a string of digits, rather than performing calculation internally.

Last edited by Sais; 26/09/07 10:34 AM.

Sais
Joined: Oct 2006
Posts: 48
G
Ghozer Offline OP
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Oct 2006
Posts: 48
but using $calc() diddnt work for me, i still ended up with the same negative number in the hash table entry...

Joined: Jun 2006
Posts: 508
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 508
Yet it works for me with the code I posted...

Joined: Dec 2002
Posts: 5,420
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,420
Thanks this has been fixed for the next version.


Link Copied to Clipboard