Module:Harmonic entropy: Difference between revisions
Jump to navigation
Jump to search
Bug fixing |
Bug fixing |
||
| Line 14: | Line 14: | ||
-- output without rounding if prec is omitted | -- output without rounding if prec is omitted | ||
if prec then | if prec then | ||
return | return u._round(1200*u._log(ratio), prec) | ||
-- output with rounding if prec is given | -- output with rounding if prec is given | ||
else | else | ||
Revision as of 06:00, 19 August 2022
- This module primarily serves as a library for other modules and has no corresponding template.
This module provides a means to calculate harmonic Shannon entropy of a particular interval.
| Introspection summary for Module:Harmonic entropy | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||||||||||||||
local getArgs = require('Module:Arguments').getArgs
local u = require('Module:Utils')
local p = {}
-- return measure in cents of an interval ratio, rounded to prec decimal places
function p.to_cents(frame)
local args = getArgs(frame)
return p._to_cents(args[1], args[2])
end
function p._to_cents(ratio, prec)
-- ratio defaults to 1
ratio = u.eval_num_arg(ratio, 1)
-- output without rounding if prec is omitted
if prec then
return u._round(1200*u._log(ratio), prec)
-- output with rounding if prec is given
else
-- prec defaults to 3
prec = u.eval_num_arg(prec, 3)
return 1200*u._log(ratio)
end
end
return p