DarwinBotsManual
Open the app EspañolES

sqrstore

Replaces what's in a cell with its rounded square root; if it isn't positive, it leaves it at 0.

Facts

Word
sqrstore
Family
Writing to memory
Integer stack
pops 1, pushes 0
What it does
Pops an address and leaves in the cell its square root, rounded to the nearest integer. If it held 0 or a negative, it ends at 0.
Cost
Store divided by the divisor of each one, only if it writes
Cost divisor
÷ 7
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
no

d sqrstore pops the address d and leaves in the cell the square root of what it held, rounded to the nearest integer. It takes no value from the stack.

WordStack afterwards
5050
sqrstore(empty); if cell 50 held 50, it now holds 7

The root is useful for shrinking big numbers without losing their order: 3000 becomes 55 and 30000 becomes 173.

' pushes forward according to the root of its energy
cond
start
 *.nrg 50 store
 50 sqrstore
 *50 .up store
stop

With 3000 energy (.nrg) the bot asks for 55 with .up; with less energy, less. In the first cycle it asks for 0, because the senses haven't been published yet and *.nrg reads 0 (see Execution and costs).

If the cell holds 0 or a negative, it ends up at 0: it's not an error. It's the same as *50 sqr 50 store (see sqr), with fewer words and at a seventh of the cost of a store.