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

Antoine Pitrou solipsis at pitrou.net
Wed Jan 7 19:31:00 CET 2015


On Wed, 07 Jan 2015 18:23:37 +0000
MRAB <python at mrabarnett.plus.com> wrote:
> 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()?

If it returns always the same NaN it won't make a difference.
However we could have a random.nan() function to get random NaNs
(perhaps with different distributions).

Regards

Antoine.




More information about the Python-ideas mailing list