# [Python-ideas] math.nextafter

Chris Barker chris.barker at noaa.gov
Fri Feb 24 13:12:53 EST 2017

```On Fri, Feb 24, 2017 at 1:40 AM, Juraj Sukop <juraj.sukop at gmail.com> wrote:

>
>
> On Fri, Feb 24, 2017 at 5:01 AM, Chris Barker <chris.barker at noaa.gov>
> wrote:
>
>> cause if your computation was that perfect, why not just check for zero?
>>
>>
> A polynomial root may simply be not representable in double precision
> floating-point format.
>

Indeed.

> Per the example I posted above, the best one can hope for in such
> situation is to find (x, nextafter(x, float('inf'))) interval which has
> opposite function value signs.
>

I'm not much of a numerical analyst, but I think the number of applications
in which the computation is accurate to the limit of float precision is
vanishingly small -- so you need something larger than the smallest
representable non-zero value anyway.

Also many time when one is looking for a "zero", you are really looking for
the difference between two values to be zero -- in which case isclose() is
the right tool for the job.

Thus this kind of thing is useful primarily for "exploring the behaviour of
numerical algorithm implementations" as Nick said.

Which doesn't mean it wouldn't' be useful to have in Python.

Someone said: " it's very much tied to whatever float type Python happens
to use on a platform."

Which is the whole point -- if one could assume that Python is using IEEE
754 64 bit floats, then you could write these functions yourself but it's
built-in then the implementation can make sure it's correct for the
platform/etc that you are currently running on.

By the way, it looks like math doesn't have machine epsilon either:

https://en.wikipedia.org/wiki/Machine_epsilon

which would be handy as well.

-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/20170224/f449167c/attachment.html>
```