/ 2/ MOD /MOD */MOD U/MOD
/ (n1 n2 -- n3)
Divide n1 by n2, giving the single-cell quotient n3
Example:
6 3 / . \ display 2 opération 6/3 7 3 / . \ display 2 opération 7/3 8 3 / . \ display 2 opération 8/3 9 3 / . \ display 3 opération 9/3
The division is not commutative:
15 5 / . \ display 3 5 15 / . \ display 0
2/ ( x1 -- x2)
x2 is the result of shifting x1 one bit toward the least-significant bit, leaving the most-significant bit unchanged.
Example:
24 2/ . \ display 12 25 2/ . \ display 12 26 2/ . \ display 13
MOD ( n1 n2 -- n3)
Divide n1 by n2, giving the single-cell remainder n3.
21 7 mod . \ display 0 22 7 mod . \ display 1 23 7 mod . \ display 2 24 7 mod . \ display 3
The modulo function can be used to determine the divisibility of one number by another:
: DIV? ( n1 n2 ---) OVER OVER MOD CR IF SWAP . ." is not " ELSE SWAP . ." is " THEN ." divisible by " . ;
/MOD ( n1 n2 -- n3 n4 )
Divide n1 by n2, giving the single-cell remainder n3 and the single-cell quotient n4.
22 7 /MOD . . \ display 3 1
*/MOD ( n1 n2 n3 -- n4 n5 )
Multiply n1 by n2 producing the intermediate double-cell result d. Divide d by n3 producing the single-cell remainder n4 and the single-cell quotient n5.
50000 10 4001 */MOD . \ display 124 3876
U/MOD ( u1 u2 -- rem quot )
Unsigned int/int->int division