sub
Subtracts the top number of the stack from the one below it: a b sub leaves a − b.
Facts
- Word
sub- Family
- Basic
- Integer stack
- pops 2, pushes 1
- What it does
- Pops two numbers and pushes the one below minus the one on top. With huge numbers it behaves like
add. - Cost
- Basic command
- Runs
- inside a gene: in the condition (cond) and in the body (start or else)
a b sub leaves a − b: the upper one is subtracted from the lower one. 10 3 sub gives 7 and 3 10 sub gives −7. It's the simplest way to turn the difference between two reads into a number, for example how much energy the bot gained or lost.
cond
start
' stack: *.nrg *51 → the difference
*.nrg *51 sub 50 store
*.nrg 51 store
stopThis bot keeps its energy in cell 51 and, in cell 50, how much it changed since the previous cycle (negative if it went down).
It has the same quirks as add with enormous numbers: it loses precision above about 16 million and wraps around when it goes past 2 billion.