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 | ||
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 | ||
function p.round(x, prec) | |||
prec = prec or 3 -- default to 3 decimal places if prec is omitted | |||
return math.floor(x*10^ | return math.floor(x*10^prec+0.5)/10^prec | ||
end | end | ||
return p | return p | ||