[Python-Dev] marshal / unmarshal

Tim Peters tim.peters at gmail.com
Sat Apr 9 01:38:24 CEST 2005


[Scott David Daniels]
> What should marshal / unmarshal do with floating point NaNs (the case we
> are worrying about is Infinity) ?  The current behavior is not perfect.

All Python behavior in the presence of a NaN, infinity, or signed zero
is a platform-dependent accident.  This is because C89 has no such
concepts, and Python is written to the C89 standard.  It's not easy to
fix across all platforms (because there is no portable way to do so in
standard C), although it may be reasonably easy to fix if all anyone
cares about is gcc and MSVC (every platform C compiler has its own set
of gimmicks for "dealing with" these things).

If marshal could reliably detect a NaN, then of course unmarshal
should reliably reproduce the NaN -- provided the platform on which
it's unpacked supports NaNs.

> Should loads raise an exception?

Never for a quiet NaN, unless the platform doesn't support NaNs.  It's
harder to know what to with a signaling NaN, because Python doesn't
have any of 754's trap-enable or exception status flags either (the
new ``decimal`` module does, but none of that is integrated with the
_rest_ of Python yet).

Should note that what the fp literal 1e10000 does across boxes is also
an accident -- Python defers to the platform C libraries for
string<->float conversions.


More information about the Python-Dev mailing list