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

Nick Coghlan ncoghlan at gmail.com
Fri Jan 9 10:12:30 CET 2015

On 8 January 2015 at 02:07, Alexander Belopolsky
<alexander.belopolsky at gmail.com> wrote:
> On Wed, Jan 7, 2015 at 10:23 AM, Marco Buttu <marco.buttu at gmail.com> wrote:
>> On 07/01/2015 15:58, Todd wrote:
>>> Yes, this would be a shortcut for that.  math.nan and math.inf are less
>>> verbose than float("nan") and float("inf"), even if you aren't already using
>>> the math module (fewer characters total, and in particular fewer special
>>> characters).  It would also, at least in my opinion, be more readable.  Plus
>>> there is already the math.isnan and math.isinf, so I don't think it would be
>>> totally out-of-place.
>> I totally agree. +1
> Another +1.
> Two points:
> 1. The current ways to create inf and nan are not obvious and hard to
> discover.  It will be nice to have these constants discoverable in tab
> completion from math.
> 2. The repr()s of nan and inf are simply 'nan' and 'inf', not 'float("nan")'
> and 'float("inf")', so it is natural to expect nan and inf constants in some
> namespace.

3. Having these as documented constants provides a natural home for
documentation of some of the standard assumptions about the behaviour
of containers and comparisons that they can break (this is mostly NaN
related - off the top of my head, I don't recall any particularly
weird inf-induced behaviour)


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list