Why does Python’s hash of infinity have the digits of π?

The hash of infinity in Python has digits matching pi:

>>> inf = float('inf')
>>> hash(inf)
>>> int(math.pi*1e5)

Is that just a coincidence or is it intentional?


_PyHASH_INF is defined as a constant equal to 314159.

I can’t find any discussion about this, or comments giving a reason. I think it was chosen more or less arbitrarily. I imagine that as long as they don’t use the same meaningful value for other hashes, it shouldn’t matter.

Leave a Reply

Your email address will not be published. Required fields are marked *