我需要 NodeMCU 中的 Lua 数学库
I need the Lua math library in NodeMCU
我需要对热敏电阻进行对数计算,但是 Lua 数学库 (math.log
) 似乎没有实现,或者我做错了什么。它不是 NodeMCU-build.com 或文档中的模块。
任何ideas/suggestions/solutions?
local function log(x)
assert(x > 0)
local a, b, c, d, e, f = x < 1 and x or 1/x, 0, 0, 1, 1
repeat
repeat
c, d, e, f = c + d, b * d / e, e + 1, c
until c == f
b, c, d, e, f = b + 1 - a * c, 0, 1, 1, b
until b <= f
return a == x and -f or f
end
local function log10(x)
return log(x) / 2.3025850929940459
end
我需要对热敏电阻进行对数计算,但是 Lua 数学库 (math.log
) 似乎没有实现,或者我做错了什么。它不是 NodeMCU-build.com 或文档中的模块。
任何ideas/suggestions/solutions?
local function log(x)
assert(x > 0)
local a, b, c, d, e, f = x < 1 and x or 1/x, 0, 0, 1, 1
repeat
repeat
c, d, e, f = c + d, b * d / e, e + 1, c
until c == f
b, c, d, e, f = b + 1 - a * c, 0, 1, 1, b
until b <= f
return a == x and -f or f
end
local function log10(x)
return log(x) / 2.3025850929940459
end