Inconsistency producing constant for float "infinity"
Peter Hansen
peter at engcorp.com
Fri Aug 11 11:26:48 EDT 2006
Sybren Stuvel wrote:
> Peter Hansen enlightened us with:
>
>>I'm investigating a puzzling problem involving an attempt to
>>generate a constant containing an (IEEE 754) "infinity" value. (I
>>understand that special float values are a "platform-dependent
>>accident" etc...)
>
> Why aren't you simply using the fpconst package?
Probably because it's not in the stdlib yet, assuming that's still true.
(Using it might be an option anyway. I'm investigating a problem on
Win32 with simplejson, so it would be Bob Ippolito's choice whether
fpconst is a reasonable solution to the problem.)
My guess about marshal was correct. The problem (value becoming 1.0)
appears when running from .pyc files. Immediately after the source code
is changed, the code works, since it doesn't unmarshal the .pyc file but
just works from the bytecode freshly compiled in memory.
This demonstrates what would be the heart of the problem, which I guess
means this is not surprising to almost anyone, but perhaps will be a
wakeup call to anyone who might still be unaware and has code that
relies on constants like 1e6666 producing infinities:
>>> import marshal
>>> marshal.dumps(1e666)
'f\x061.#INF'
>>> marshal.loads(marshal.dumps(1e666))
1.0
-Peter
More information about the Python-list
mailing list