Asymptotically fast replacement for divmod, for 'int'. Its time complexity is O(n**1.58), where n = #bits(a) + #bits(b).
(a, b)
| 526 | |
| 527 | |
| 528 | def int_divmod(a, b): |
| 529 | """Asymptotically fast replacement for divmod, for 'int'. |
| 530 | Its time complexity is O(n**1.58), where n = #bits(a) + #bits(b). |
| 531 | """ |
| 532 | if b == 0: |
| 533 | raise ZeroDivisionError('division by zero') |
| 534 | elif b < 0: |
| 535 | q, r = int_divmod(-a, -b) |
| 536 | return q, -r |
| 537 | elif a < 0: |
| 538 | q, r = int_divmod(~a, b) |
| 539 | return ~q, b + ~r |
| 540 | else: |
| 541 | return _divmod_pos(a, b) |
| 542 | |
| 543 | |
| 544 | # Notes on _dec_str_to_int_inner: |
nothing calls this directly
no test coverage detected
searching dependent graphs…