4 ms·
"Normal" ints in Python are certainly native. You don't get bignums until you need them. I think, on 32bit platforms (though we're about 10 years removed from
by TylerE 6y ago
"Normal" ints in Python are certainly native. You don't get bignums until you need them.
I think, on 32bit platforms (though we're about 10 years removed from actual expirence) they'd go int -> long -> bignum as needed.
- toolslive 6y agobut... are they unboxed?
- AlexanderDhoore 6y agoIn python everything is boxed. EDIT See https://news.ycombinator.com/item?id=12418985 https://news.ycombinator.com/item?id=12418985
- pansa2 6y agoNothing is unboxed in CPython. Other implementations differ - for example, MicroPython supports several encodings for unboxed values. https://github.com/micropython/micropython/blob/4fc2866f45692b05829d71b636724e690b786307/py/mpconfig.h#L68 https://github.com/micropython/micropython/blob/4fc2866f4569...
- pansa2 6y ago> IIRC, both (well, CPython and MRI) internally use distinct “small integer” and “big integer" representations, but that is transparent to the user. This seems to be correct for MRI. Before Ruby 2.4, both `Fixnum` and `Bignum` were exposed to the programmer. In 2016 these were unified into `Integer` from the programmer's point of view, but with "no internal representation change" [0]. > "Normal" ints in Python are certainly native. You don't get bignums until you need them. However, I don't think this is true for current versions of Python. As part of the 2.x => 3.0 transition, Python underwent a similar unification of integer types. Python 2.x exposes both `int` and `long`, and Python 3.x has only `int`. However, internally, 3.x's `int` is represented by `PyLongObject` and the old `PyIntObject` has been removed. Even the small integer cache (which holds the values -5 to 256) was changed from holding `PyIntObject`s in 2.x [1] to hold `PyLongObject`s [2]. So it looks like in Python 3.x, all integers are arbitrary-precision. I believe this was a significant contributor to early versions of Python 3.x being slower than 2.x. [0] https://rubykaigi.org/2016/presentations/tanaka_akr.html https://rubykaigi.org/2016/presentations/tanaka_akr.html [1] https://github.com/python/cpython/blob/8d21aa21f2cbc6d50aab3f420bb23be1d081dac4/Objects/intobject.c#L79 https://github.com/python/cpython/blob/8d21aa21f2cbc6d50aab3... [2] https://github.com/python/cpython/blob/39f643614d03748a5fad462fe7ed26a174a522fa/Include/internal/pycore_interp.h#L306 https://github.com/python/cpython/blob/39f643614d03748a5fad4...