Rappresenting infinite
Robert Kern
robert.kern at gmail.com
Mon Jul 2 15:37:13 EDT 2007
avassalotti at gmail.com wrote:
> float('inf') works well, no?
>
> >>> inf = float('inf')
> >>> inf / inf
> nan
> >>> -inf
> -inf
> >>> inf / 0
> ZeroDivisionError: float division
> >>> 1 / inf
> 0.0
> >>> 0 * float('inf')
> nan
It is not cross-platform. The parsing of strings into floats and the string
representation of floats is dependent on your system's C library. For these
special values, this differs across platforms. Your code won't work on Windows,
for example. Fortunately, it doesn't matter all that much (at least for those
who just need to create such values; parsing them from files is another matter)
since infs and nans can be constructed in a cross-platform way (at least for
IEEE-754 platforms where these values make sense).
inf = 1e200 * 1e200
nan = inf / inf
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list
mailing list