Module:Utils: Difference between revisions

m No semi-colon needed at the end...
Bug fixing
Line 2: Line 2:


-- return logarithm base b of x
-- return logarithm base b of x
local function log(x, b)
function p.log(x, b)
b = b or 2 -- defaults to base 2 (octave) if b is omitted
b = b or 2 -- defaults to base 2 (octave) if b is omitted
return math.log(x)/math.log(b)
return math.log(x)/math.log(b)
Line 8: Line 8:


-- return x rounded to a precision of p decimal places
-- return x rounded to a precision of p decimal places
local function round(x, p)
function p.round(x, prec)
p = p or 3 -- default to 3 decimal places if p is omitted
prec = prec or 3 -- default to 3 decimal places if prec is omitted
return math.floor(x*10^p+0.5)/10^p
return math.floor(x*10^prec+0.5)/10^prec
end
end


return p
return p