DarwinBotsManual
Open the app EspañolES

divstore

Divides what is in a cell by a number, rounding to the nearest integer; dividing by 0 leaves the cell at 0.

Facts

Word
divstore
Family
Writing to memory
Integer stack
pops 2, pushes 0
What it does
Pops an address and a value, and divides the cell by the value, rounding to the nearest integer (to the even one on a tie). Dividing by 0 leaves it at 0. With address 0 the value is lost.
Cost
Store divided by the divisor of each one, only if it writes
Cost divisor
÷ 5
Runs
in the body of a gene (start or else), and only if the top of the boolean stack is true or the stack is empty
Marks ties
yes

v d divstore leaves in cell d what it held divided by v. It gives the same as *d v div d store, with fewer words and at one fifth of the cost of a store.

WordStack after
22
502 50
divstore(empty); cell 50 holds half of what it did

The division rounds to the nearest integer, it does not truncate, and on an exact tie it goes to the even one. You can see it well by halving over and over:

' halves cell 50 every cycle
cond
 *.robage 0 =
start
 100 50 store
stop
start
 2 50 divstore
stop

The cell goes through 50, 25, 12, 6, 3, 2, 1 and 0. Note the ties: 12.5 gives 12, 1.5 gives 2 and 0.5 gives 0.

Two traps:

Like store, it notifies the tie system if you write to .tieang1 or .tielen1. Division on the stack, without storing, is div.