Digest #27 2018-01-23

Contributions

[50] 2018-01-22 15:32:49 NieDzejkob wrote:

referenceImplementation - Implementing FM/MOD with SM/REM

: FM/MOD ( d n -- rem quot )
  DUP >R
  SM/REM
  ( if the remainder is not zero and has a different sign than the divisor )
  OVER DUP 0<> SWAP 0< R@ 0< XOR AND IF
    1- SWAP R> + SWAP
  ELSE
    RDROP
  THEN
;