bit.div_loop¶

if b==0: goto end (do nothing)
q = a/b  (unsigned division)
r = a%b  (unsigned modulo)
@NOTE: a,b are UNSIGNED numbers. If you want a division with signed ints, use the idiv_loop macro.
@NOTE: this division implementation saves space, yet is slower, compared to div.

@NOTE: There is a better version: This one is slow, big, and doesn’t error on b==0.
For a faster division see hex.div, hex.idiv.
q,a,b,r are bit[:n].

Signature¶

def div_loop n, a, b, q, r @ loop, do_sub, loop_end, after_loop, A, Q, R, i, end { ... }

Defined in bit/div.fj — lines 204–240 (view on GitHub).

Complexity¶

  • Time: n^2(18@+18)

  • Space: n(25@+22)

See the complexity glossary for what @, w, dw, dbit, n mean.

Depends on¶

Used by¶