I'm attempting to port this C hashing function to Perl but it's not working:
c static inline uint64_t hash64(uint64_t val, unsigned bits) { return (val * 0x61c8864680b583ebull) >> (64 - bits); }
Here is what I came up with:
``` sub hash64 { my ($val, $bits) = @_; my $magic_constant = 0x61c8864680b583eb;
# Perform the hash computation my $hashed = ($val * $magic_constant) >> (64 - $bits); return $hashed;
} ```
My hashed values aren't matching what I'm seeing from C. I suspect it has to do with how Perl handles numbers larger than 64bit? C would truncate them (I think) but Perl will happily work with larger numbers?
12345 hashed to 64bits should output 6832837858993532755 according to the C version. Am I missing something obvious?
submitted by /u/scottchiefbaker
[link] [comments]