When is min(a, b) != min(b, a)?

Robert Kern robert.kern at gmail.com
Wed Jan 23 16:29:50 EST 2008


Russell E. Owen wrote:
> In article <mailman.993.1201117814.896.python-list at python.org>,
>  Christian Heimes <lists at cheimes.de> wrote:
> 
>> Grant Edwards wrote:
>>> In many applications (e.g. process control) propogating NaN
>>> values are way too useful to avoid.  Avoiding NaN would make a
>>> lot of code far more complicated than would using them.
>> NaNs are very useful for experienced power users but they are very
>> confusing for newbies or developers without a numerical background.
>>
>> It's very easy to create an inf or nan in Python:
>>
>> inf = 1E+5000
>> ninf = -inf
>> nan = inf * 0.
>>
>> 1E5000 creates a nan because it is *much* bigger than DBL_MAX (around
>> 1E+308). In fact it is even larger than LDBL_MAX (around 1E+4932).
> 
> Isn't it safer to use float("inf"), float("-inf") and float("nan") to 
> create the necessary items?

In currently-released versions of Python, these are not portable. 
float(some_string) just passes the string to the platform's conversion function. 
There is no standard defining what to do with "nan" or "inf". On Linux, these 
work as intended, but on Windows, they are errors.

Christian is working on a branch to standardize these forms for Python 2.6. See 
"math and numerical fixes" in this thread.

-- 
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