-2

What type of int is the result of this calculation? Why isn't there a numerical overflow issue?

>>> 2**500
3273390607896141870013189696827599152216642046043064789483291368096133796404674554883270092325904157150886684127560071009217256545885393053328527589376
>>> type(2**500)
<class 'int'>
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
Alexander Soare
  • 2,825
  • 3
  • 25
  • 53

2 Answers2

1

I think this is implemented as a bignum which can handle arbitrarily large integer. You can find a more detailed discussion here, Handling very large numbers in Python

1

From this link "In Python, integers are implemented as “long” integer objects of arbitrary size", they do not overflow https://docs.python.org/3/c-api/long.html#integer-objects

Achille G
  • 748
  • 6
  • 19