hex.idiv¶

if b==0: goto div0
q = a/b  (signed division)
r = a%b  (signed modulo - signed according to rem_opt:)
if rem_opt is 0: sign(r)==sign(b)  // Most programming languages implement this option.
if rem_opt is 1: sign(r)==sign(a)
if rem_opt is 2: sign(r) is always positive
(On any other rem_opt value, will jump to "div0". This check is guaranteed to be after the b==0 check).
Anyway, a == q*b + r.
@NOTE: a,b are SIGNED numbers. If you want a division with unsigned ints, use the div macro.

q,a are hex[:n], while r,b are hex[:nb]. div0 is the bit-address this function will jump to in-case b is zero.

Signature¶

def idiv n, nb, q, r, a, b, div0, rem_opt @ set_negative_a, test_b, set_negative_b, update_rem_opt_0, update_rem_opt_2, add_b, sub_b, negative_a, negative_b, one_negative, do_div, neg_b_2, neg_ans, end, fix_rem { ... }

Defined in hex/div.fj — lines 86–150 (view on GitHub).

Complexity¶

  • Time: n^2(2@+8) + n*nb(34@+92)   so if nb==n:  n^2(36@+100)

  • Space: n(8.5@+132)  + nb(21.5@+309)    so if nb==n:  n(30@+441)

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

Requires init¶

The following must be initialised before this macro is invoked:

  • hex.sub.init & hex.cmp.init (or hex.init)

Depends on¶