bit.idiv¶

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 macro.
@NOTE: this division implementation is WASTEFUL in space, yet saves running time, compared to div_loop.

@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 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 61–94 (view on GitHub).

Complexity¶

  • Time: n^2(10@+20)

  • Space: n^2(11@+22)

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

Depends on¶