-2

I have also seen other programming language by Python have a very huge integer range , even Java don't have , how ? How it's made possible?

  • 2
    In Java you have a `BigInteger`... – Willem Van Onsem Mar 11 '17 at 20:59
  • consider: instead of a block of memory stating the number, a block of memory stating how many digits the number has then the space for those digits be dynamically allocated. Basically if python runs out of room to store a number it literally adds more space. – Tadhg McDonald-Jensen Mar 11 '17 at 21:08
  • The majority of languages have an arbitrary sized integer type built into the language, including Java. https://en.wikipedia.org/wiki/Comparison_of_programming_languages_(basic_instructions) – Paul Hankin Mar 11 '17 at 21:17

1 Answers1

0

Most programming languages offer integers based on the underlying CPU's machine word length, using single CPU instructions for e.g. add, in the interest of speed. It's always possible to provide a longer integer size by using multiple words and the carry/overflow flags in the hardware, but it's slower to do so and uses more memory.

This is very similar to how you do math on paper when you're given operands which are too big for you to multiply in your head.

Python prioritizes programmer convenience over raw speed, so it simply makes its integers as big as they need to be, on-demand.

Russell Borogove
  • 18,516
  • 4
  • 43
  • 50