Why isn't Python throwing an overflow error? -


i'm learning python , have question range of data types.

this program:

print("8 bits:", pow(2, 8)-1) print("16 bits:", pow(2, 16)-1) print("32 bits:", pow(2, 32)-1) print("64 bits:", pow(2, 64)-1)  print( pow(18446744073709551615+18446744073709551615+2, 9) ) 

produces following output:

8 bits: 255 16 bits: 65535 32 bits: 4294967295 64 bits: 18446744073709551615 12663316555422952143897729076205936129798725073982046203600028471956337925454431 59912019973433564390346740077701202633417478988975650566195033836314121693019733 02667340133957632 

my question is: how can python calculate result of last call pow()? cpu cannot handle integers more 64 bits, expect operation produce overflow.

the python long integer type limited available memory. until run out of memory, digits keep on coming.

quoting numeric types documentation:

long integers have unlimited precision.

python transparently use long integers when need unlimited precision. in python 3, integers long integers; there no distinction.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -