Not infinite sex number. Only integer underflow sex number. I know this because I accidentally wrote nested for-loops yesterday where I incremented the bound instead of the iterator.
.NET dev, integers can overflow and cause an overflow exception when adding to an integer at its max value which can be either positive or negative. I’m not a Python dev but I am interested in knowing if the compiler does the same, and if not, how does it handle it?
Python integers are objects and have no statically alocated memory. They just take as much memory as they need to store their value. So their maximum value is only given by the memory available and they don't over/underflow. Once the number gets too big, the interpreter runs out of memory and the program stops with a MemoryError. But it will take a many magnitudes larger number than 2 billion.
I can now see why Python is slow. That’s a lot of work for a processor to do. Seems like the compiler is doing a lot of under the hood trickery and conversions to get that to work.
Python is relatively slow, but in this case, cant the interpreter just check whether the new integer can fit in the amount of allocated bytes, and if not, add another byte(s)?
1
u/Sparkplug1034 Dec 03 '19
Not infinite sex number. Only integer underflow sex number. I know this because I accidentally wrote nested for-loops yesterday where I incremented the bound instead of the iterator.