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

Function _divmod_pos

Lib/_pylong.py:511–525  ·  view source on GitHub ↗

Divide a non-negative integer a by a positive integer b, giving quotient and remainder.

(a, b)

Source from the content-addressed store, hash-verified

509
510
511def _divmod_pos(a, b):
512 """Divide a non-negative integer a by a positive integer b, giving
513 quotient and remainder."""
514 # Use grade-school algorithm in base 2**n, n = nbits(b)
515 n = b.bit_length()
516 a_digits = _int2digits(a, n)
517
518 r = 0
519 q_digits = []
520 for a_digit in reversed(a_digits):
521 q_digit, r = _div2n1n((r << n) + a_digit, b, n)
522 q_digits.append(q_digit)
523 q_digits.reverse()
524 q = _digits2int(q_digits, n)
525 return q, r
526
527
528def int_divmod(a, b):

Callers 1

int_divmodFunction · 0.85

Calls 6

_int2digitsFunction · 0.85
_div2n1nFunction · 0.85
_digits2intFunction · 0.85
bit_lengthMethod · 0.80
appendMethod · 0.45
reverseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…