Tim Peters wrote: > 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 which probably represents very close to 100% of all python interpreter instances out there. making floats behave the same on standard builds for windows, mac os x, and linux would be a great step forward. +1.0 from me. >> 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. yeah, but the problem here is that MSVC cannot read its own NaN:s; float() checks for that, but loads doesn't. compare and contrast: >>> float(str(1e10000)) Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: invalid literal for float(): 1.#INF >>> import marshal >>> marshal.loads(marshal.dumps(1e10000)) 1.0 on the other hand, >>> marshal.loads("\f\x01x") Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: bad marshal data adding basic error checking shouldn't be very hard (you could probably call the string->float converter in the float object module, and just map any exceptions to "bad marshal data") </F>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4