hasing question- warning possible loss of data

Discussion of chess software programming and technical issues.

Moderator: Ras

adams161
Posts: 626
Joined: Sun May 13, 2007 9:55 pm
Location: Bay Area, CA USA
Full name: Mike Adams

hasing question- warning possible loss of data

Post by adams161 »

hi,

when i hash i use _64bit numbers. the size of my tables, hashmax is measured in long. so if i have an int64 key and a long hashmax and do hashkey=key%hashmax i get a possible loss of data warning. hashkey is long too. but since key an int 64 number is being divided by hashmax to produce a long number i always discounted the warning.

am i correct?

Mike
Dann Corbit
Posts: 12777
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: hasing question- warning possible loss of data

Post by Dann Corbit »

adams161 wrote:hi,

when i hash i use _64bit numbers. the size of my tables, hashmax is measured in long. so if i have an int64 key and a long hashmax and do hashkey=key%hashmax i get a possible loss of data warning. hashkey is long too. but since key an int 64 number is being divided by hashmax to produce a long number i always discounted the warning.

am i correct?

Mike
The remainder after modulus is less than hashmax in size (by definition of modulus). So if hashmax is equal to or smaller than LONG_MAX as defined in <limits.h> with c (or <limits> with C++) then you should be OK.
Probably, if you explicitly cast the assignment, the warning will vanish.