> [Bignum] isn’t yet implemented widely enough, but happily there are plenty of languages such as Python that give bignums by default.
This was news to me, and when I looked it up I found out why: that's only the case in Python 3. Python 2 has a type called int that's implemented as a C long and a type called long that's a bignum [0]; Python 3 just has the latter and it's called int [1].
They both give you bignums by default. They only differ slightly in implementation.
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> type(10)
<type 'int'>
>>> type(10 ** 100)
<type 'long'>
Well, not quite. The documentation summarizes what your experiment showed.
> Unadorned integer literals (including binary, hex, and octal numbers) yield plain integers unless the value they denote is too large to be represented as a plain integer, in which case they yield a long integer.
That's not a literal. The result of an expression that overflows int is a long. 'int' is merely an efficient way of storing small integers as part of the larger bignum scheme.
All 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
This was news to me, and when I looked it up I found out why: that's only the case in Python 3. Python 2 has a type called int that's implemented as a C long and a type called long that's a bignum [0]; Python 3 just has the latter and it's called int [1].
[0] https://docs.python.org/2/library/stdtypes.html#numeric-type...
[1] https://docs.python.org/3/library/stdtypes.html#numeric-type...