STINNER Victor <vstin...@python.org> added the comment:

> NumPy has nextafter.

That's why I proposed math.nextafter() name.

Moreover, in the math module, most functions reuse the same names than C 
function names: expm1(), atan2(), erf(), etc.


> IEEE 754, on the other hand, requires instead nextUp and nextDown, which take 
> a single argument and move towards +inf or -inf (respectively).

When I played with bpo-39277, I used nextafter() to try to implement manually a 
conversion from an integer to a float using rounding towards zero. So I prefer 
nextafter() than nextUp()/nextDown(): it gives more features.


> but nextAwayFromZero doesn't match any of these

It seems easy to reimplement it using nextafter(), no?

def nextAwayFromZero(x):
    if x < 0:
        return math.nextafter(x, -float("inf"))
    else:
        return math.nextafter(x, +float("inf"))


> Python's Decimal type has a two-argument next_toward method.

It also has next_minus() and next_plus() which don't match "nextUp and 
nextDown" names requires by IEEE 754.

I'm not comfortable with math.next_after() or math.next_toward() name: use a 
different than the libc function name (add an underscore). For me, the math 
module is a thin wrapper to libm function, as the os module is a thin wrapper 
to libc functions.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39288>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to