DarwinBotsManual
Open the app EspañolES

sgnstore

Replaces what's in a cell with its sign: −1 if negative, 0 if zero, 1 if positive.

Facts

Word
sgnstore
Family
Writing to memory
Integer stack
pops 1, pushes 0
What it does
Pops an address and leaves only the sign of the cell: −1, 0 or 1.
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 sgnstore pops the address d and leaves in the cell only the sign of what it held: −1, 0 or 1. It takes no value from the stack.

WordStack afterwards
5151
sgnstore(empty); if cell 51 held −77, it now holds −1

It's useful for keeping the direction of a change and forgetting the size:

' cell 51 ends up at -1, 0 or 1 depending on whether energy went down, stayed the same or went up
cond
start
 *.nrg *50 sub 51 store
 51 sgnstore
 *.nrg 50 store
stop

Cell 50 keeps the energy (.nrg) from the previous cycle. The difference goes to cell 51 and sgnstore reduces it to its sign. A bot that is spending energy sees −1 there almost every cycle. The value, now turned into −1, 0 or 1, can then be multiplied by whatever you like.

It's the same as *51 sgn 51 store (see sgn), with fewer words and at a seventh of the cost of a store.