[Python-ideas] math.nextafter
Juraj Sukop
juraj.sukop at gmail.com
Mon Feb 6 07:22:02 EST 2017
On Mon, Feb 6, 2017 at 11:29 AM, M.-A. Lemburg <mal at egenix.com> wrote:
>
> Juraj: Could you provide some use cases, where such a function
> would help in Python applications ? (I can see use cases
> written in C, but due to the low level, find it hard to
> believe that people would use this at the Python level)
>
In my case, `nextafter` would be used to check if a number is close to
polynomial zero, e.g.:
def f(x):
return 2.0*x**3 - 3.0*x**2 + 5.0*x - 7.0
# x = 1.4455284586795218
x = 1.445528458679522
# x = 1.4455284586795223
# x = 1.4455284586795225
left = nextafter(x, -float('inf'))
right = nextafter(x, float('inf'))
print((f(left) < 0.0) != (f(x) < 0.0) or (f(x) < 0.0) != (f(right) <
0.0))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170206/40ed2ab5/attachment.html>
More information about the Python-ideas
mailing list