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

MRAB python at mrabarnett.plus.com
Wed Jan 7 19:23:37 CET 2015


On 2015-01-07 16:57, Devin Jeanpierre wrote:
> On Wed, Jan 7, 2015 at 10:25 AM, Chris Barker <chris.barker at noaa.gov> wrote:
>> On Wed, Jan 7, 2015 at 8:09 AM, Steven D'Aprano <steve at pearwood.info> wrote:
>>> - 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.
>
> Maybe this would justify a note in the documentation, that this is one
> NaN, but there are many others that are different.
>
> As long as people know not to rely on math.nan being the same object
> or having the same bits as every nan, then there's no harm.
>
Does that mean it should be a function that returns a NaN, i.e. math.nan()?



More information about the Python-ideas mailing list