Anjani Kumar Agrawal
Anjani Kumar Agrawal

Reputation: 375

How come python 3 has no size limit on numbers when all other languages do?

It's really interesting that numbers in python have no size limit. I am trying to understand how is this implemented in python?

Is it just a matter of bytes. Other languages have a byte restriction on types like int, float etc. While python doesn't.

Are there any performance impacts due to this even when my number is small due to some overhead needed for this implementation (when compared with another language like Java, C# etc)?

Can other languages implement this functionality as well by maybe just adding a new type. Or is there something fundamentally different b/w other languages and python that prohibits them from implementing this functionality.

Upvotes: 3

Views: 538

Answers (1)

Kuldeep Singh Sidhu
Kuldeep Singh Sidhu

Reputation: 3856

Actually it is dependent on your computer.

There used to be a limit in earlier versions of Python for int. But, this is dropped as Python treats integers as objects. So, although Python allocates 32 bits for the value object reference is pointing to, as the value goes beyond 2^32 it can keep moving up all the way up to the size of RAM on your computer.

For earlier versions of python:

import sys
dir(sys)
print (sys.maxint)
9007199254740991

Upvotes: 5

Related Questions