KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Consider the example: >>> from sys import maxint >>> type(maxint) <type 'int'> >>> print maxint 9223372036854775807 >>> type(maxint+2) <type 'long'> >>> print maxint+2 9223372036854775809 >>> type((maxint+2)+maxint) <type 'long'> >>> print ((maxint+2)+maxint) 18446744073709551616 Python will autopromote from an int , which in this case is a 64 bit integer value (OS X, python 2.6.1) to a python long integer which is of arbitrary precision. Even though the types are not the same, they are similar and Python allows the usual numeric operators to be used. Usually this is helpful, for example to be able to use code that expects 64-bit values on a 32-bit machine. However, the arbitrary precision operations are vastly slower than the native int operations. For example: >>> print maxint**maxint # execution so long it is essentially a crash Is there a way to defeat or disallow the auto-promotion of a Python int to a Python long ?
Tags (comma-separated)
Save Edits
Cancel