logx
Gives the logarithm of the lower number in the base of the upper one, rounded: 1000 10 logx gives 3.
Facts
- Word
logx- Family
- Advanced
- Integer stack
- pops 2, pushes 1
- What it does
- Pops two numbers a and b, drops their signs and pushes the logarithm of a in base b, rounded. With b below 2 or a equal to 0 it gives 0.
- Cost
- Advanced command; debugint and debugbool are free
- Runs
- inside a gene: in the condition (cond) and in the body (start or else)
a b logx leaves the logarithm of a in base b: the exponent you have to raise b to in order to get a. 1000 10 logx gives 3 and 8 2 logx gives
- As always, the result is rounded:
100 2 logxgives 7 (it is 6.64…).
The rules for the odd cases:
- The sign is dropped from both numbers before calculating.
- If the base is less than 2 (0 or 1), or if
ais 0, it gives 0.
It's useful for working with orders of magnitude, when it matters more how many digits a number has than the exact number. This bot keeps in cell 50 the order of magnitude of its energy: 3 as long as it's between about 320 and 3160, 2 below that and 4 above (the rounding changes value halfway):
cond
start
*.nrg 10 logx 50 store
stopThe inverse operation is pow: 10 3 pow gives 1000.