Why does Python's native hash()
generate a collision for -1
and -2
?
>>>> hash(-1)
-2
>>>> hash(-2)
-2
My understanding is that Python's hash
will simply output the exact value of the number fed in - this seems to hold upto 2^60
and -2^60
:
>>>> hash(2**8)
256
>>>> hash(-2**8)
-256
>>> hash(2**60)
1152921504606846976
>>> hash(-2**60)
-1152921504606846976
What is special about -1
in this instance?