DarwinBotsManual
Open the app EspañolES

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

  1. As always, the result is rounded: 100 2 logx gives 7 (it is 6.64…).

The rules for the odd cases:

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
stop

The inverse operation is pow: 10 3 pow gives 1000.