math.log

Natural log

Prototype

v = math.log (v)

Description

Natural log of v (that is, to the base e). Note that math.exp is the inverse operation.

math.log (123456) --> 11.723640096265
math.exp (math.log (123456))  --> 123456
You can get the log to any base by dividing the log of the number by the log of the desired base. For example:

-- calculate log of 16 to the base 2 (2^4 = 16)
math.log (16) / math.log (2)  --> 4

-- calculate log of 666 to the base 10
math.log (666) / math.log (10)  --> 2.8234742291703

-- alternative method using math.log10 gives same results
math.log10 (666)  --> 2.8234742291703

Lua functions

Topics