bit.idiv_loop¶
if b==0: goto end (do nothing)
q = a/b (signed division)
r = a%b (signed modulo - sign(r)==sign(a))
@NOTE: a,b are SIGNED numbers. If you want a division with unsigned ints, use the div_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.
Also it supports only one convention for the sign of the reminder.
For a faster & better division see hex.div, hex.idiv.
q,a,b,r are bit[:n].
Signature¶
def idiv_loop n, a, b, q, r @ negative_a, negative_b, one_negative, neg_b_1, do_div, neg_b_2, neg_ans, end { ... }
Defined in bit/div.fj — lines 157–190 (view on GitHub).
Complexity¶
Time:
n^2(18@+18)Space:
n(37@+58)
See the complexity glossary for what @, w, dw, dbit, n mean.