hex.idiv

Signed integer division with configurable remainder convention (rem_opt: 0 = sign(r)==sign(b), Python-style floor division; 1 = sign(r)==sign(a), C-style truncation; 2 = remainder always positive). Jumps to div0 if b==0. q, a are hex[:n]; r, b are hex[:nb].

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)

Source

Depends on


← Previous: hex.div