[Python-ideas] math.inf and math.nan constants

Chris Barker chris.barker at noaa.gov
Mon Jan 12 17:54:00 CET 2015


Mark Lawrence wrote:

> as "Although practicality beats purity." can we move on now please?


Adding math.nan and math.inf is great, nothing else to do.

Feel free to read more below, if you're as obsessed by this as I am.....

On Mon, Jan 12, 2015 at 8:05 AM, Stephen J. Turnbull <stephen at xemacs.org>

> AFAIK, the proposed math.nan is *not* a bunch of values.

correct -- math.nan is a particular one of those values.

The thing is, in common usage, one often needs to know if a given float is
one of the nan values -- it is very rare that anyone knows or cares which

So you need a good way to ask that question, and:

x == math.nan

does not work, due to how IEEE defined NaN.

So we have math.isnan(x), which is the right thing to do, and the most
common question people would ask.

Being able to do x is math.nan, and have that give the answer most commonly
wanted would be a nice way to spell, but, again, not worth breaking the now
clear definition of "is".

So -- sorry to bring it up -- I was just enjoying the what if game (and
genuinely curious about whether it was possible in the current python
implementation to overload is like that.

I take it the answer is: "no, and that's a good thing."

> particular float value that happens to be a NaN, just as math.pi is a
> particular float value that happens not to be a NaN.  The use cases
> are very different, however.  math.pi is used when you want a value
> that is a close IEEE 754 float approximation to mathematical pi in
> concrete computations, while math.nan is used when you want a value
> that "takes you out" of the world of concrete computation and can be
> interpreted as an "error value".

sure, but the bigger difference is that

math.pi == math.pi returns True


x == math.pi returns True is x has the exact same values as math.pi

math.isnan(x) is, in more analogous to

a < x < b

i.e., a specific range of values.

Anyway,  I'm done.



Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150112/64b1f572/attachment.html>

More information about the Python-ideas mailing list