curious problem with large numbers

Bengt Richter bokr at oz.net
Fri Apr 8 18:51:57 EDT 2005


On Fri, 08 Apr 2005 10:18:05 -0700, Scott David Daniels <Scott.Daniels at Acm.Org> wrote:

>Bengt Richter wrote:
>>>Aha! Same version (2.3.4):
>>>
>>>Idle:
>>>    >>> 1e10000
>>>    1.0
>>>    >>> import struct; struct.pack('d', 1e10000)
>>>    '\x00\x00\x00\x00\x00\x00\xf0?'
>>>(which is actually 1.0)
>>>
>>>python via command line (readline support):
>>>    >>> 1e10000
>>>    1.#INF
>>>    >>> import struct; struct.pack('d', 1e10000)
>>>    '\x00\x00\x00\x00\x00\x00\xf0\x7f'
>>>
>>>Note the difference in the final byte.  Same results (command
>>>line vs. Idle) for 2.4.1.
>>>
>
>> Good aha, but ISTM one of them is more missing than different ;-)
>> (I.e., returned packed string is length 7 vs 8)
>In the first one, the final byte is '?' (I made the same mistake
>myself when I first read it).
>
D'oh. Must always switch from driving glasses to computer glasses when reading NG ;-/

>Also note:
>
>     float('1e10000') is 1.#INF both in Idle and from the command line.
>
>I suspect an Idle bug.
>
I'll trust you this time ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list