hex/math_basic.fj

———- Basic Mathematics:

View source on GitHub

Macros

hex

  • hex.add_count_bits — dst[:n] += src.#on-bits (between 0->4)

  • hex.count_bits — dst[:small_n] = x[:n].#on-bits

  • hex.inc1 — hex++ (if overflows - jump to carry1; else jump to carry0)

  • hex.inc — hex[:n]++

  • hex.dec1 — hex-- (if underflows - jump to borrow1; else jump to borrow0)

  • hex.dec — hex[:n]--

  • hex.neg — x[:n] = -x[:n]

  • hex.abs — x[:n] = |x[:n]| (two’s complement; the minimal value -2^(4n-1) stays itself)

  • hex.sign_extend — sign-extends hex[:signed_n] into hex[:full_n]

hex.inc

  • hex.inc.step — One nibble of a propagating increment: increment hex by 1; on overflow continue to the next nibble, else jump to end.

hex.dec

  • hex.dec.step — One nibble of a propagating decrement: decrement hex by 1; on underflow continue to the next nibble, else jump to end.