math.log
Shared
Returns the logarithm of a number in a given base
Syntax
local result = math.log(
value,
base = math.exp(1)
)Parameters
| Type | Name | Description |
|---|---|---|
number | value | Positive number to compute the logarithm of |
number | base | Logarithm base - defaults to e (natural log) |
Returns
| Type | Name | Description |
|---|---|---|
number | result | Logarithm of value in the given base |
Examples
local result = math.log(math.exp(1))
engine.print("info", result) -- 1.0local result = math.log(1)
engine.print("info", result) -- 0.0local result = math.log(1000, 10)
engine.print("info", result) -- 3.0local result = math.log(8, 2)
engine.print("info", result) -- 3.0local n = 12345
local digits = math.floor(math.log(n, 10)) + 1
engine.print("info", digits) -- 5local start = 1
local target = 1024
local doublings = math.ceil(math.log(target / start, 2))
engine.print("info", doublings) -- 10local value = 5.0
local result = math.log(math.exp(value))
engine.print("info", result) -- 5.0