[Python-ideas] math.nextafter

Chris Barker chris.barker at noaa.gov
Tue Feb 28 12:55:06 EST 2017


On Fri, Feb 24, 2017 at 6:43 PM, Nathaniel Smith <njs at pobox.com> wrote:

> On Feb 24, 2017 5:29 PM, "David Mertz" <mertz at gnosis.cx> wrote:
>
> Marc-André slightly misspelled the recent-ish addition of math.isclose(),
> but I agree that it is absolutely where a "nextafter" belongs.
>
>

> My 2c: I disagree -- numerical tolerance based closeness is fundamentally
> different than floating point representation based closeness
>

agreed -- isclose() is a convenience function to provide folks a way to "do
a reasonable thing" without delving into floating point representation
issues, etc. INdeed, essentially the same approach could be used for
Decimal and Fraction, though they aren't supported by math.isclose() due to
the math module being written in C, and the rest of math being all about
floats.

It's also a little weird to jump from nextafter to isclose, since AFAIK
> they have pretty much non-overlapping use cases...
>

Exactly -- and you can tell by this this thread that confusion is easy with
this stuff -- putting them together will only sow more confusion.

"Floating Point is Hard"

Note how many really smart people on this list say things like " I'm no
expert in numerical analysis.. "

* nextafter
> * a function for counting the number of ulps between two floats
> * a function for checking that two floats differ by at most N ulps
>
> I'm not enough of an expert on numerical analysis to have an opinion on
> how useful these would be for Python itself. They certainly are part of a
> complete IEEE754 implementation, and useful for exploring the details of
> how floats work, if nothing else.
>

I think there is little question that these are useful for numerical
analysis. I think the question is if enough people want to use Python for
that kind of analysis to add it to the stdlib.

My tendency is to say yes -- if someone wants to write the code, it
shouldn't be that hard to maintain -- it's mostly going to be calls to the
underlying C lib, yes?

-CHB


-- 

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/20170228/7edd6156/attachment-0001.html>


More information about the Python-ideas mailing list