Why does the hash of infinity have the digits of π?What does the “yield” keyword do?How do I parse a string to a float or int in Python?Does Python have a ternary conditional operator?Secure hash and salt for PHP passwordsHow can I generate an MD5 hash?What does if __name__ == “__main__”: do?Random string generation with upper case letters and digitsDoes Python have a string 'contains' substring method?Why doesn't GCC optimize a*a*a*a*a*a to (a*a*a)*(a*a*a)?Why does changing 0.1f to 0 slow down performance by 10x?

Negative impact of having the launch pad away from the Equator

Is a world with one country feeding everyone possible?

Moons and messages

Why was this character made Grand Maester?

Is there an idiom that means that you are in a very strong negotiation position in a negotiation?

Was this scene in S8E06 added because of fan reactions to S8E04?

How to create a `range`-like iterable object of floats?

How do you earn the reader's trust?

How to deceive the MC

Why do the i8080 I/O instructions take a byte-sized operand to determine the port?

Why'd a rational buyer offer to buy with no conditions precedent?

Python script to extract text from PDF with images

ifconfig shows UP while ip link shows DOWN

Knight's Tour on a 7x7 Board starting from D5

The disk image is 497GB smaller than the target device

Did Game of Thrones end the way that George RR Martin intended?

Possibility of faking someone's public key

Using too much dialogue?

Is keeping the forking link on a true fork necessary (Github/GPL)?

Are runways booked by airlines to land their planes?

Why did it take so long for Germany to allow electric scooters / e-rollers on the roads?

Storing voxels for a voxel Engine in C++

Why do testers need root cause analysis?

One word for 'the thing that attracts me'?



Why does the hash of infinity have the digits of π?


What does the “yield” keyword do?How do I parse a string to a float or int in Python?Does Python have a ternary conditional operator?Secure hash and salt for PHP passwordsHow can I generate an MD5 hash?What does if __name__ == “__main__”: do?Random string generation with upper case letters and digitsDoes Python have a string 'contains' substring method?Why doesn't GCC optimize a*a*a*a*a*a to (a*a*a)*(a*a*a)?Why does changing 0.1f to 0 slow down performance by 10x?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








14















The hash of infinity in Python has digits matching pi:



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


Is that just a coincidence or is that intentional?










share|improve this question






















  • Not certain, but my guess would be that it's as deliberate as hash(float('nan')) being 0.

    – cs95
    3 hours ago











  • Hmm, no mention about that in sys.hash_info. Easter egg?

    – wim
    3 hours ago











  • Seems like someone was in a frivolous mood one day. But -- why not?

    – John Coleman
    3 hours ago






  • 4





    Ask Tim Peters. Here's the commit where he introduced this constant, 19 years ago: github.com/python/cpython/commit/…. I kept those special values when I reworked the numeric hash in bugs.python.org/issue8188

    – Mark Dickinson
    2 hours ago












  • @MarkDickinson Thanks. It looks like Tim may have also used the digits of e for hash of -inf originally.

    – wim
    2 hours ago


















14















The hash of infinity in Python has digits matching pi:



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


Is that just a coincidence or is that intentional?










share|improve this question






















  • Not certain, but my guess would be that it's as deliberate as hash(float('nan')) being 0.

    – cs95
    3 hours ago











  • Hmm, no mention about that in sys.hash_info. Easter egg?

    – wim
    3 hours ago











  • Seems like someone was in a frivolous mood one day. But -- why not?

    – John Coleman
    3 hours ago






  • 4





    Ask Tim Peters. Here's the commit where he introduced this constant, 19 years ago: github.com/python/cpython/commit/…. I kept those special values when I reworked the numeric hash in bugs.python.org/issue8188

    – Mark Dickinson
    2 hours ago












  • @MarkDickinson Thanks. It looks like Tim may have also used the digits of e for hash of -inf originally.

    – wim
    2 hours ago














14












14








14


2






The hash of infinity in Python has digits matching pi:



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


Is that just a coincidence or is that intentional?










share|improve this question














The hash of infinity in Python has digits matching pi:



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


Is that just a coincidence or is that intentional?







python math hash floating-point pi






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 3 hours ago









wimwim

171k54327464




171k54327464












  • Not certain, but my guess would be that it's as deliberate as hash(float('nan')) being 0.

    – cs95
    3 hours ago











  • Hmm, no mention about that in sys.hash_info. Easter egg?

    – wim
    3 hours ago











  • Seems like someone was in a frivolous mood one day. But -- why not?

    – John Coleman
    3 hours ago






  • 4





    Ask Tim Peters. Here's the commit where he introduced this constant, 19 years ago: github.com/python/cpython/commit/…. I kept those special values when I reworked the numeric hash in bugs.python.org/issue8188

    – Mark Dickinson
    2 hours ago












  • @MarkDickinson Thanks. It looks like Tim may have also used the digits of e for hash of -inf originally.

    – wim
    2 hours ago


















  • Not certain, but my guess would be that it's as deliberate as hash(float('nan')) being 0.

    – cs95
    3 hours ago











  • Hmm, no mention about that in sys.hash_info. Easter egg?

    – wim
    3 hours ago











  • Seems like someone was in a frivolous mood one day. But -- why not?

    – John Coleman
    3 hours ago






  • 4





    Ask Tim Peters. Here's the commit where he introduced this constant, 19 years ago: github.com/python/cpython/commit/…. I kept those special values when I reworked the numeric hash in bugs.python.org/issue8188

    – Mark Dickinson
    2 hours ago












  • @MarkDickinson Thanks. It looks like Tim may have also used the digits of e for hash of -inf originally.

    – wim
    2 hours ago

















Not certain, but my guess would be that it's as deliberate as hash(float('nan')) being 0.

– cs95
3 hours ago





Not certain, but my guess would be that it's as deliberate as hash(float('nan')) being 0.

– cs95
3 hours ago













Hmm, no mention about that in sys.hash_info. Easter egg?

– wim
3 hours ago





Hmm, no mention about that in sys.hash_info. Easter egg?

– wim
3 hours ago













Seems like someone was in a frivolous mood one day. But -- why not?

– John Coleman
3 hours ago





Seems like someone was in a frivolous mood one day. But -- why not?

– John Coleman
3 hours ago




4




4





Ask Tim Peters. Here's the commit where he introduced this constant, 19 years ago: github.com/python/cpython/commit/…. I kept those special values when I reworked the numeric hash in bugs.python.org/issue8188

– Mark Dickinson
2 hours ago






Ask Tim Peters. Here's the commit where he introduced this constant, 19 years ago: github.com/python/cpython/commit/…. I kept those special values when I reworked the numeric hash in bugs.python.org/issue8188

– Mark Dickinson
2 hours ago














@MarkDickinson Thanks. It looks like Tim may have also used the digits of e for hash of -inf originally.

– wim
2 hours ago






@MarkDickinson Thanks. It looks like Tim may have also used the digits of e for hash of -inf originally.

– wim
2 hours ago













2 Answers
2






active

oldest

votes


















10














It's not a coincidence; it's explicitly defined that way in the default CPython implementation of Python, and in fact you can even examine this from a Python 3 shell:



>>> import sys
>>> sys.hash_info
sys.hash_info(width=64, modulus=2305843009213693951, inf=314159, nan=0, imag=1000003, algorithm='siphash24', hash_bits=64, seed_bits=128, cutoff=0)
>>> sys.hash_info.inf
314159


Above, the fact that sys.hash_info.inf is 314159 means that 314159 is the hash value returned for positive infinity. (Same results with PyPy too.)




In terms of code, hash is a built-in function. Calling it on a Python float object invokes the function whose pointer is given by the tp_hash attribute of the built-in float type (PyTypeObject PyFloat_Type), which is the float_hash function, defined as return _Py_HashDouble(v->ob_fval), which in turn has



 if (Py_IS_INFINITY(v))
return v > 0 ? _PyHASH_INF : -_PyHASH_INF;


where _PyHASH_INF is defined as 314159:



#define _PyHASH_INF 314159



In terms of history, the first mention of 314159 in this context in the Python code (you can find this with git bisect or git log -S 314159 -p) was added by Tim Peters in August 2000, in what is now commit 39dce293 in the cpython git repository.



The commit message says:




Fix for http://sourceforge.net/bugs/?func=detailbug&bug_id=111866&group_id=5470.
This was a misleading bug -- the true "bug" was that hash(x) gave an error
return when x is an infinity. Fixed that. Added new Py_IS_INFINITY macro to
pyport.h. Rearranged code to reduce growing duplication in hashing of float and
complex numbers, pushing Trent's earlier stab at that to a logical conclusion.
Fixed exceedingly rare bug where hashing of floats could return -1 even if there
wasn't an error (didn't waste time trying to construct a test case, it was simply
obvious from the code that it *could* happen). Improved complex hash so that
hash(complex(x, y)) doesn't systematically equal hash(complex(y, x)) anymore.



In particular, in this commit he ripped out the code of static long float_hash(PyFloatObject *v) in Objects/floatobject.c and made it just return _Py_HashDouble(v->ob_fval);, and in the definition of long _Py_HashDouble(double v) in Objects/object.c he added the lines:



 if (Py_IS_INFINITY(intpart))
/* can't convert to long int -- arbitrary */
v = v < 0 ? -271828.0 : 314159.0;


So as mentioned, it was an arbitrary choice. Note that 271828 is formed from the first few decimal digits of e.



Related later commits:



  • By Mark Dickinson in Apr 2010 (also), making the Decimal type behave similarly


  • Same, moving the code to the top and adding test cases (also)


  • By Mark Dickinson in May 2010, giving the constant a name _PyHASH_INF (also removed the 271828 which is why in Python 3 hash(float('-inf')) returns -314159 rather than -271828 as it does in Python 2)


  • By Raymond Hettinger in Jan 2011, adding an explicit example in the "What's new" for Python 3.2 of sys.hash_info showing the above value. (See here.)


  • By Stefan Krah in Mar 2012 modifying the Decimal module but keeping this hash.


  • By Christian Heimes in Nov 2013, moved the definition of _PyHASH_INF from Include/pyport.h to Include/pyhash.h where it now lives.






share|improve this answer
































    6














    _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.






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56227419%2fwhy-does-the-hash-of-infinity-have-the-digits-of-%25cf%2580%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      10














      It's not a coincidence; it's explicitly defined that way in the default CPython implementation of Python, and in fact you can even examine this from a Python 3 shell:



      >>> import sys
      >>> sys.hash_info
      sys.hash_info(width=64, modulus=2305843009213693951, inf=314159, nan=0, imag=1000003, algorithm='siphash24', hash_bits=64, seed_bits=128, cutoff=0)
      >>> sys.hash_info.inf
      314159


      Above, the fact that sys.hash_info.inf is 314159 means that 314159 is the hash value returned for positive infinity. (Same results with PyPy too.)




      In terms of code, hash is a built-in function. Calling it on a Python float object invokes the function whose pointer is given by the tp_hash attribute of the built-in float type (PyTypeObject PyFloat_Type), which is the float_hash function, defined as return _Py_HashDouble(v->ob_fval), which in turn has



       if (Py_IS_INFINITY(v))
      return v > 0 ? _PyHASH_INF : -_PyHASH_INF;


      where _PyHASH_INF is defined as 314159:



      #define _PyHASH_INF 314159



      In terms of history, the first mention of 314159 in this context in the Python code (you can find this with git bisect or git log -S 314159 -p) was added by Tim Peters in August 2000, in what is now commit 39dce293 in the cpython git repository.



      The commit message says:




      Fix for http://sourceforge.net/bugs/?func=detailbug&bug_id=111866&group_id=5470.
      This was a misleading bug -- the true "bug" was that hash(x) gave an error
      return when x is an infinity. Fixed that. Added new Py_IS_INFINITY macro to
      pyport.h. Rearranged code to reduce growing duplication in hashing of float and
      complex numbers, pushing Trent's earlier stab at that to a logical conclusion.
      Fixed exceedingly rare bug where hashing of floats could return -1 even if there
      wasn't an error (didn't waste time trying to construct a test case, it was simply
      obvious from the code that it *could* happen). Improved complex hash so that
      hash(complex(x, y)) doesn't systematically equal hash(complex(y, x)) anymore.



      In particular, in this commit he ripped out the code of static long float_hash(PyFloatObject *v) in Objects/floatobject.c and made it just return _Py_HashDouble(v->ob_fval);, and in the definition of long _Py_HashDouble(double v) in Objects/object.c he added the lines:



       if (Py_IS_INFINITY(intpart))
      /* can't convert to long int -- arbitrary */
      v = v < 0 ? -271828.0 : 314159.0;


      So as mentioned, it was an arbitrary choice. Note that 271828 is formed from the first few decimal digits of e.



      Related later commits:



      • By Mark Dickinson in Apr 2010 (also), making the Decimal type behave similarly


      • Same, moving the code to the top and adding test cases (also)


      • By Mark Dickinson in May 2010, giving the constant a name _PyHASH_INF (also removed the 271828 which is why in Python 3 hash(float('-inf')) returns -314159 rather than -271828 as it does in Python 2)


      • By Raymond Hettinger in Jan 2011, adding an explicit example in the "What's new" for Python 3.2 of sys.hash_info showing the above value. (See here.)


      • By Stefan Krah in Mar 2012 modifying the Decimal module but keeping this hash.


      • By Christian Heimes in Nov 2013, moved the definition of _PyHASH_INF from Include/pyport.h to Include/pyhash.h where it now lives.






      share|improve this answer





























        10














        It's not a coincidence; it's explicitly defined that way in the default CPython implementation of Python, and in fact you can even examine this from a Python 3 shell:



        >>> import sys
        >>> sys.hash_info
        sys.hash_info(width=64, modulus=2305843009213693951, inf=314159, nan=0, imag=1000003, algorithm='siphash24', hash_bits=64, seed_bits=128, cutoff=0)
        >>> sys.hash_info.inf
        314159


        Above, the fact that sys.hash_info.inf is 314159 means that 314159 is the hash value returned for positive infinity. (Same results with PyPy too.)




        In terms of code, hash is a built-in function. Calling it on a Python float object invokes the function whose pointer is given by the tp_hash attribute of the built-in float type (PyTypeObject PyFloat_Type), which is the float_hash function, defined as return _Py_HashDouble(v->ob_fval), which in turn has



         if (Py_IS_INFINITY(v))
        return v > 0 ? _PyHASH_INF : -_PyHASH_INF;


        where _PyHASH_INF is defined as 314159:



        #define _PyHASH_INF 314159



        In terms of history, the first mention of 314159 in this context in the Python code (you can find this with git bisect or git log -S 314159 -p) was added by Tim Peters in August 2000, in what is now commit 39dce293 in the cpython git repository.



        The commit message says:




        Fix for http://sourceforge.net/bugs/?func=detailbug&bug_id=111866&group_id=5470.
        This was a misleading bug -- the true "bug" was that hash(x) gave an error
        return when x is an infinity. Fixed that. Added new Py_IS_INFINITY macro to
        pyport.h. Rearranged code to reduce growing duplication in hashing of float and
        complex numbers, pushing Trent's earlier stab at that to a logical conclusion.
        Fixed exceedingly rare bug where hashing of floats could return -1 even if there
        wasn't an error (didn't waste time trying to construct a test case, it was simply
        obvious from the code that it *could* happen). Improved complex hash so that
        hash(complex(x, y)) doesn't systematically equal hash(complex(y, x)) anymore.



        In particular, in this commit he ripped out the code of static long float_hash(PyFloatObject *v) in Objects/floatobject.c and made it just return _Py_HashDouble(v->ob_fval);, and in the definition of long _Py_HashDouble(double v) in Objects/object.c he added the lines:



         if (Py_IS_INFINITY(intpart))
        /* can't convert to long int -- arbitrary */
        v = v < 0 ? -271828.0 : 314159.0;


        So as mentioned, it was an arbitrary choice. Note that 271828 is formed from the first few decimal digits of e.



        Related later commits:



        • By Mark Dickinson in Apr 2010 (also), making the Decimal type behave similarly


        • Same, moving the code to the top and adding test cases (also)


        • By Mark Dickinson in May 2010, giving the constant a name _PyHASH_INF (also removed the 271828 which is why in Python 3 hash(float('-inf')) returns -314159 rather than -271828 as it does in Python 2)


        • By Raymond Hettinger in Jan 2011, adding an explicit example in the "What's new" for Python 3.2 of sys.hash_info showing the above value. (See here.)


        • By Stefan Krah in Mar 2012 modifying the Decimal module but keeping this hash.


        • By Christian Heimes in Nov 2013, moved the definition of _PyHASH_INF from Include/pyport.h to Include/pyhash.h where it now lives.






        share|improve this answer



























          10












          10








          10







          It's not a coincidence; it's explicitly defined that way in the default CPython implementation of Python, and in fact you can even examine this from a Python 3 shell:



          >>> import sys
          >>> sys.hash_info
          sys.hash_info(width=64, modulus=2305843009213693951, inf=314159, nan=0, imag=1000003, algorithm='siphash24', hash_bits=64, seed_bits=128, cutoff=0)
          >>> sys.hash_info.inf
          314159


          Above, the fact that sys.hash_info.inf is 314159 means that 314159 is the hash value returned for positive infinity. (Same results with PyPy too.)




          In terms of code, hash is a built-in function. Calling it on a Python float object invokes the function whose pointer is given by the tp_hash attribute of the built-in float type (PyTypeObject PyFloat_Type), which is the float_hash function, defined as return _Py_HashDouble(v->ob_fval), which in turn has



           if (Py_IS_INFINITY(v))
          return v > 0 ? _PyHASH_INF : -_PyHASH_INF;


          where _PyHASH_INF is defined as 314159:



          #define _PyHASH_INF 314159



          In terms of history, the first mention of 314159 in this context in the Python code (you can find this with git bisect or git log -S 314159 -p) was added by Tim Peters in August 2000, in what is now commit 39dce293 in the cpython git repository.



          The commit message says:




          Fix for http://sourceforge.net/bugs/?func=detailbug&bug_id=111866&group_id=5470.
          This was a misleading bug -- the true "bug" was that hash(x) gave an error
          return when x is an infinity. Fixed that. Added new Py_IS_INFINITY macro to
          pyport.h. Rearranged code to reduce growing duplication in hashing of float and
          complex numbers, pushing Trent's earlier stab at that to a logical conclusion.
          Fixed exceedingly rare bug where hashing of floats could return -1 even if there
          wasn't an error (didn't waste time trying to construct a test case, it was simply
          obvious from the code that it *could* happen). Improved complex hash so that
          hash(complex(x, y)) doesn't systematically equal hash(complex(y, x)) anymore.



          In particular, in this commit he ripped out the code of static long float_hash(PyFloatObject *v) in Objects/floatobject.c and made it just return _Py_HashDouble(v->ob_fval);, and in the definition of long _Py_HashDouble(double v) in Objects/object.c he added the lines:



           if (Py_IS_INFINITY(intpart))
          /* can't convert to long int -- arbitrary */
          v = v < 0 ? -271828.0 : 314159.0;


          So as mentioned, it was an arbitrary choice. Note that 271828 is formed from the first few decimal digits of e.



          Related later commits:



          • By Mark Dickinson in Apr 2010 (also), making the Decimal type behave similarly


          • Same, moving the code to the top and adding test cases (also)


          • By Mark Dickinson in May 2010, giving the constant a name _PyHASH_INF (also removed the 271828 which is why in Python 3 hash(float('-inf')) returns -314159 rather than -271828 as it does in Python 2)


          • By Raymond Hettinger in Jan 2011, adding an explicit example in the "What's new" for Python 3.2 of sys.hash_info showing the above value. (See here.)


          • By Stefan Krah in Mar 2012 modifying the Decimal module but keeping this hash.


          • By Christian Heimes in Nov 2013, moved the definition of _PyHASH_INF from Include/pyport.h to Include/pyhash.h where it now lives.






          share|improve this answer















          It's not a coincidence; it's explicitly defined that way in the default CPython implementation of Python, and in fact you can even examine this from a Python 3 shell:



          >>> import sys
          >>> sys.hash_info
          sys.hash_info(width=64, modulus=2305843009213693951, inf=314159, nan=0, imag=1000003, algorithm='siphash24', hash_bits=64, seed_bits=128, cutoff=0)
          >>> sys.hash_info.inf
          314159


          Above, the fact that sys.hash_info.inf is 314159 means that 314159 is the hash value returned for positive infinity. (Same results with PyPy too.)




          In terms of code, hash is a built-in function. Calling it on a Python float object invokes the function whose pointer is given by the tp_hash attribute of the built-in float type (PyTypeObject PyFloat_Type), which is the float_hash function, defined as return _Py_HashDouble(v->ob_fval), which in turn has



           if (Py_IS_INFINITY(v))
          return v > 0 ? _PyHASH_INF : -_PyHASH_INF;


          where _PyHASH_INF is defined as 314159:



          #define _PyHASH_INF 314159



          In terms of history, the first mention of 314159 in this context in the Python code (you can find this with git bisect or git log -S 314159 -p) was added by Tim Peters in August 2000, in what is now commit 39dce293 in the cpython git repository.



          The commit message says:




          Fix for http://sourceforge.net/bugs/?func=detailbug&bug_id=111866&group_id=5470.
          This was a misleading bug -- the true "bug" was that hash(x) gave an error
          return when x is an infinity. Fixed that. Added new Py_IS_INFINITY macro to
          pyport.h. Rearranged code to reduce growing duplication in hashing of float and
          complex numbers, pushing Trent's earlier stab at that to a logical conclusion.
          Fixed exceedingly rare bug where hashing of floats could return -1 even if there
          wasn't an error (didn't waste time trying to construct a test case, it was simply
          obvious from the code that it *could* happen). Improved complex hash so that
          hash(complex(x, y)) doesn't systematically equal hash(complex(y, x)) anymore.



          In particular, in this commit he ripped out the code of static long float_hash(PyFloatObject *v) in Objects/floatobject.c and made it just return _Py_HashDouble(v->ob_fval);, and in the definition of long _Py_HashDouble(double v) in Objects/object.c he added the lines:



           if (Py_IS_INFINITY(intpart))
          /* can't convert to long int -- arbitrary */
          v = v < 0 ? -271828.0 : 314159.0;


          So as mentioned, it was an arbitrary choice. Note that 271828 is formed from the first few decimal digits of e.



          Related later commits:



          • By Mark Dickinson in Apr 2010 (also), making the Decimal type behave similarly


          • Same, moving the code to the top and adding test cases (also)


          • By Mark Dickinson in May 2010, giving the constant a name _PyHASH_INF (also removed the 271828 which is why in Python 3 hash(float('-inf')) returns -314159 rather than -271828 as it does in Python 2)


          • By Raymond Hettinger in Jan 2011, adding an explicit example in the "What's new" for Python 3.2 of sys.hash_info showing the above value. (See here.)


          • By Stefan Krah in Mar 2012 modifying the Decimal module but keeping this hash.


          • By Christian Heimes in Nov 2013, moved the definition of _PyHASH_INF from Include/pyport.h to Include/pyhash.h where it now lives.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 1 hour ago

























          answered 2 hours ago









          ShreevatsaRShreevatsaR

          30.9k1388113




          30.9k1388113























              6














              _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.






              share|improve this answer



























                6














                _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.






                share|improve this answer

























                  6












                  6








                  6







                  _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.






                  share|improve this answer













                  _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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 2 hours ago









                  Patrick HaughPatrick Haugh

                  32.5k92849




                  32.5k92849



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56227419%2fwhy-does-the-hash-of-infinity-have-the-digits-of-%25cf%2580%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Log på Navigationsmenu

                      Wonderful Copenhagen (sang) Eksterne henvisninger | NavigationsmenurSide på frankloesser.comWonderful Copenhagen

                      Detroit Tigers Spis treści Historia | Skład zespołu | Sukcesy | Członkowie Baseball Hall of Fame | Zastrzeżone numery | Przypisy | Menu nawigacyjneEncyclopedia of Detroit - Detroit TigersTigers Stadium, Detroit, MITigers Timeline 1900sDetroit Tigers Team History & EncyclopediaTigers Timeline 1910s1935 World Series1945 World Series1945 World Series1984 World SeriesComerica Park, Detroit, MI2006 World Series2012 World SeriesDetroit Tigers 40-Man RosterDetroit Tigers Coaching StaffTigers Hall of FamersTigers Retired Numberse