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

Paddy paddy3118 at googlemail.com
Sun Jan 20 23:16:18 EST 2008


On Jan 21, 3:15 am, Albert Hopkins <mar... at python.invalid> wrote:
> This issue may have been referred to in
> <news:mailman.1864.1196703799.13605.python-list at python.org> but I didn't
> entirely understand the explanation.  Basically I have this:
>
>     >>> a = float(6)
>     >>> b = float('nan')
>     >>> min(a, b)
>     6.0
>     >>> min(b, a)
>     nan
>     >>> max(a, b)
>     6.0
>     >>> max(b, a)
>     nan
>
> Before I did not know what to expect, but I certainly didn't expect
> this.  So my question is what is the min/max of a number and NaN or is it
> not defined (for which I would have expected either an exception to be
> raised or NaN returned in each case).
>
> As a corrollary would I be able to rely on the above behavior or is it
> subject to change (to fix a bug in min/max perhaps :-)?

I am definitely NOT a floating point expert, but I did find this:
http://en.wikipedia.org/wiki/IEEE_754r#min_and_max

P.S. What platform /Compiler are you using for Python?

- Paddy.



More information about the Python-list mailing list