Mark Dickinson added the comment:

This is a bit tricky.  The first expression you suggest doesn't work at all for 
negative numbers (e.g., producing `-3.0` for `round(-1.8)`).

The second expression *mostly* works as you want, but not entirely.  Some 
examples:

>>> def f(n): return float(math.trunc(n + math.copysign(0.5, n)))
... 
>>> x = 0.5 - 2**-54
>>> x
0.49999999999999994
>>> f(x)  # should be 0.0
1.0
>>> x = 5e15 + 3.0
>>> x
5000000000000003.0
>>> f(x)  # should be x again
5000000000000004.0

And neither of these addresses the two-argument case of `round`.

It may be better to simply flag this as something that 2to3 can't handle, and 
that needs a manual check.

----------
nosy: +mark.dickinson

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

Reply via email to