Strange behaviour with numbers in exponential notation
Christian Gollwitzer
auriocus at gmx.de
Sun Sep 4 11:27:59 EDT 2016
Am 04.09.16 um 10:29 schrieb Nobody:
> On Fri, 02 Sep 2016 18:18:08 +0200, Christian Gollwitzer wrote:
>
>> 1e26 denotes a *floating point number* Floating point has finite
>> precision, in CPython it is a 64bit IEEE number. The largest exact
>> integer there is 2**53 (~10^16), everything beyond cannot be accurately
>> represented.
>
> Uh, that's wrong. All integers smaller than 2**53 can be represented
> exactly. Some, but not all, of the integers above 2**53 can be represented
> exactly.
Agreed. That's what I wanted to say. Of course you can represent 2**327
exactly in 64 bit binary floating point. The point is, that you can't
sensibly assumy to get exact integer results for numbers beyond 2**53 -
except for special cases. For example, 133 * 2**53 is exactly
representable in FP, but 2**53+1 is not.
Christian
More information about the Python-list
mailing list