[Python-ideas] math.inf and math.nan constants
Chris Barker
chris.barker at noaa.gov
Wed Jan 7 17:25:22 CET 2015
On Wed, Jan 7, 2015 at 8:09 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> import math
> process(math.inf)
>
> or
>
> inf = float('inf')
> process(inf)
>
> is much the same effort. At worst, we might say that it is a matter of
> personal taste which you prefer. But frankly, the difference is trivial.
>
exactly -- but the cost is trivial too. Note that numpy provides np.inf and
np.nan for a reason, and it s a nice thing to have.
> - offering a math.inf is harmless but not especially useful;
>
but nice.
- offering a single math.nan is harmful and I strongly oppose it.
defining math.nan as a singleton could be considered harmful, but I don't
see any harm at all in offering it as a pre-defined constant. We NEED to
have a way to create a NaN-valued float in any case (and do with
float('nan')) -- this would be no different.
And as nan (and inf, and -inf) can result from computation, rather than
python-level object creation, they are different than None anyway (they are
also particular values or a float, rather than a particular type).
+1
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
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/20150107/d5814905/attachment.html>
More information about the Python-ideas
mailing list