DarwinBotsManual
Open the app EspañolES

div

Divides the lower number by the top one and rounds to the nearest integer (to the even one on a tie); dividing by zero gives 0.

Facts

Word
div
Family
Basic
Integer stack
pops 2, pushes 1
What it does
Pops two numbers and pushes the one below divided by the one on top, rounded to the nearest integer (to the even one on a tie). Dividing by 0 gives 0.
Cost
Basic command
Runs
inside a gene: in the condition (cond) and in the body (start or else)

a b div leaves a / b rounded. It has two peculiarities worth knowing by heart:

cond
start
  7 2 div 50 store
  5 2 div 51 store
  10 0 div 52 store
stop

Cells 50, 51 and 52 end up at 4, 2 and 0.

Dividing by zero has a well-known use in the Bestiary: x dup div is 1 if x is not zero and 0 if it is, and with that you build conditions without conditions (Operators by family covers it, with the Bardus example). The rounding matters when converting units: *.nrg 3 div is not the integer division of other languages. If you need the remainder, there is mod.