Portably generating infinity and NaN
"Martin v. Löwis"
martin at v.loewis.de
Thu Apr 12 17:16:22 EDT 2007
Michael Hoffman schrieb:
> What's the best way to portably generate binary floating point infinity
> and NaNs? I only know two solutions:
>
> 1. Using the fpconst module proposed in IEEE 754, which I believe shifts
> bits around.
>
> 2. Using an extension module (for example, numarray.ieeespecial will do
> it).
Use the struct module to pack/unpack a double value. On an IEEE 754
system, this should work - on a non-IEEE-754 system, it's not clear
that +/-inf and NaN actually exist.
Regards,
Martin
More information about the Python-list
mailing list