Python question about exponents and int

Out of curiosity, I ran the following:

>>> int(1e100) 

And, the result was:

 10000000000000000159028911097599180468360808563945281389781327557747838772170381060813469985856815104L 

Why? Why it does not look:

 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000L 

Is this the product of an int function or storing a large long ?

+6
source share
3 answers

1e100 is a floating point number, with 53 bits of precision in significant . The integer you are trying to represent requires 333 bits for accuracy, so there is some rounding. The lower bits are replaced to make the closest base number 2 to your desired result.

See: http://docs.python.org/tutorial/floatingpoint.html#representation-error

+8
source

It is converted to a float and then displayed as an integer. So welcome to the inaccurate world of rounding

+1
source

1e100 is a float (in general, using e means float):

 >>> type (1e100) <type 'float'> 
0
source

Source: https://habr.com/ru/post/894758/


All Articles