Message244952
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. |
|
Date |
User |
Action |
Args |
2015-06-07 11:51:34 | mark.dickinson | set | recipients:
+ mark.dickinson, priska |
2015-06-07 11:51:34 | mark.dickinson | set | messageid: <1433677894.6.0.894860364466.issue24403@psf.upfronthosting.co.za> |
2015-06-07 11:51:34 | mark.dickinson | link | issue24403 messages |
2015-06-07 11:51:34 | mark.dickinson | create | |
|