Closest integer to a/b, a and b positive integers; rounds to even in the case of a tie.
(a, b)
| 5728 | return q + (2*(x & (b-1)) + (q&1) > b) |
| 5729 | |
| 5730 | def _div_nearest(a, b): |
| 5731 | """Closest integer to a/b, a and b positive integers; rounds to even |
| 5732 | in the case of a tie. |
| 5733 | |
| 5734 | """ |
| 5735 | q, r = divmod(a, b) |
| 5736 | return q + (2*r + (q&1) > b) |
| 5737 | |
| 5738 | def _ilog(x, M, L = 8): |
| 5739 | """Integer approximation to M*log(x/M), with absolute error boundable |