Reputation: 31
Why is Python able to store long-integers of any length were as Java and C only provide 64 bits? If there is a way in Java to do it, please show it.
Upvotes: 0
Views: 2396
Reputation: 14721
There is the BigInteger class in Java.
See this python help file.
Plain integers (also just called integers) are implemented using long in C,
which gives them at least 32 bits of precision
(sys.maxint is always set to the maximum plain integer value for the current platform,
the minimum value is -sys.maxint - 1).
Long integers have unlimited precision.
Basically, it is same. In java you can use.
In python it automatically change its type due to weak typing, see below python code
>>> a = 1000
>>> type(a)
<type 'int'>
>>> a = 1000000000000000000000000000000000000000000000000000000000000000
>>> type(a)
<type 'long'>
In java, you have to change type of variable yourself.
Upvotes: 2
Reputation: 11
Python stores long integers with unlimited percision, allowing you to store large numbers as long as you have available address space.
As for Java, use BigInteger class
Upvotes: 0