Strange behaviour with numbers in exponential notation

Random832 random832 at fastmail.com
Fri Sep 2 12:17:19 EDT 2016



On Fri, Sep 2, 2016, at 11:51, Marco Sulla wrote:
> >>> 10**26 - 1
> 99999999999999999999999999
> >>> 1e26 - 1
> 1e+26
> 
> 
> Why?


Exponential notation creates floating point numbers, which have a
limited amount of precision in binary.

Specifically (on my system which, as most modern computers do, use IEEE
double precision numbers for the python float type), 

0x52b7d2dcc80cd400000000 is the value of 1e26, whereas.
0x52b7d2dcc80cd2e4000000 is the valoe of 10**26.

Trying to add 1 gets it rounded off again, and the value is simply
printed as 1e+26 by default because this is the shortest representation
that gives the same number, even if "100000000000000004764729344.0"
would be more accurate.



More information about the Python-list mailing list