4 ms·
Point taken. So if I'm understanding right, Python 2 converts int to long when necessary, whereas in Python 3 int is already a long to begin with.
by justinlardinois 10y ago
Point taken. So if I'm understanding right, Python 2 converts int to long when necessary, whereas in Python 3 int is already a long to begin with.
- Dylan16807 10y agoThe distinction is probably still there but slightly more hidden from view. It's a good optimization, no reason to throw it out. It would take some prodding around to find out.
- __s 10y agoAll python ints/longs are boxed (there's a cache for like -5 to 256). The interpreter often checks if the digit count is 1, in which case it can fall into basic integer addition of C. This is an implementation detail tho; if I do type(x) I shouldn't have to check for both int & long. So they store that information as part of the object type, rather than in the type of the object In the past some have implemented tagged integers for Python, good benchmarking results but the devs argue 'Good Python code should be more symbolic; it shouldn't be doing too much integer math' which also comes up where the interpreter doesn't implement specialized code for floats, instead they argue that if you need fast floating point you should be using numpy or a C extension Tagged ints: https://mail.python.org/pipermail/python-dev/2004-July/046139.html https://mail.python.org/pipermail/python-dev/2004-July/04613...