MCPcopy Index your code
hub / github.com/python/cpython / _div_nearest

Function _div_nearest

Lib/_pydecimal.py:5697–5703  ·  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

5695 return q + (2*(x & (b-1)) + (q&1) > b)
5696
5697def _div_nearest(a, b):
5698 """Closest integer to a/b, a and b positive integers; rounds to even
5699 in the case of a tie.
5700
5701 """
5702 q, r = divmod(a, b)
5703 return q + (2*r + (q&1) > b)
5704
5705def _ilog(x, M, L = 8):
5706 """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

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…