{log:num:base}

Description

Returns the logarithm of num. When a base is given, it is the logarithm of num in that base; when base is omitted it returns the natural logarithm (base e), the same as PHP log() called with one argument. Both num and base are treated as floating-point numbers. A num of 0 returns -INF and a negative num returns NAN, since the logarithm is undefined there. This is the AA counterpart of PHP log().

Parameters

num required default (none)

The value whose logarithm is computed. Treated as a floating-point number. A value of 0 yields -INF and a negative value yields NAN, since the logarithm is undefined there.

base optional default (empty: natural log, base e)

The logarithm base, treated as a floating-point number. When omitted, the natural logarithm (base e) is returned, matching PHP log() called with a single argument.

Examples

test[{log:{math:2*128}:2}]
Expected[8]
Actual[8]
The number argument can come from a nested expression. Here math computes 2*128 = 256, and log base 2 of 256 is 8.
test[{log:100}]
Expected[4.6051701859881]
Actual[4.6051701859881]
For most inputs the natural logarithm is an irrational number. AA prints it with PHP default float precision.
test[{log:1000:10}]
Expected[3]
Actual[3]
Logarithm of 1000 in base 10. Since 10 cubed is 1000, the result is 3.
test[{log:256:2}]
Expected[8]
Actual[8]
Logarithm in base 2 gives how many times you double from 1 to reach the number. 2 to the 8th is 256.
test[{log:81:3}]
Expected[4]
Actual[4]
Logarithm in base 3. 3 to the 4th is 81.
test[{log:0}]
Expected[-INF]
Actual[-INF]
The logarithm of 0 is undefined; PHP returns negative infinity, printed as -INF.
test[{log:1:10}]
Expected[0]
Actual[0]
The logarithm of 1 is 0 in every base, because any base raised to the power 0 is 1.
test[{log:2.718281828459045}]
Expected[1]
Actual[1]
The natural logarithm of e (about 2.718281828459045) is 1.
test[{log:1}]
Expected[0]
Actual[0]
With the base omitted, log returns the natural logarithm (base e). The natural log of 1 is 0.
test[{log:-1}]
Expected[NAN]
Actual[NAN]
The logarithm of a negative number is undefined; PHP returns NAN (not a number).