MCPcopy Index your code
hub / github.com/RustPython/RustPython / _div_nearest

Function _div_nearest

Lib/_pydecimal.py:5694–5700  ·  view source on GitHub ↗

Closest integer to a/b, a and b positive integers; rounds to even in the case of a tie.

(a, b)

Source from the content-addressed store, hash-verified

5692 return q + (2*(x & (b-1)) + (q&1) > b)
5693
5694def _div_nearest(a, b):
5695 """Closest integer to a/b, a and b positive integers; rounds to even
5696 in the case of a tie.
5697
5698 """
5699 q, r = divmod(a, b)
5700 return q + (2*r + (q&1) > b)
5701
5702def _ilog(x, M, L = 8):
5703 """Integer approximation to M*log(x/M), with absolute error boundable

Callers 7

_ilogFunction · 0.85
_dlog10Function · 0.85
_dlogFunction · 0.85
getdigitsMethod · 0.85
_iexpFunction · 0.85
_dexpFunction · 0.85
_dpowerFunction · 0.85

Calls 1

divmodFunction · 0.50

Tested by

no test coverage detected