常用对数

基本类型 / 数字 / 数学运算

local number = 1000
local result = math.log(number, 10)
-- result = 3.0

-- Base 2 is exact too
local bits = math.log(1024, 2)
-- bits = 10.0

-- Dividing two logs is not exact
local via_ln = math.log(number) / math.log(10)
local exact = via_ln == result
-- exact = false

print("result = " .. result)
print("bits = " .. bits)
print("exact = " .. tostring(exact))