Module:Harmonic entropy: Difference between revisions
Jump to navigation
Jump to search
Started a module to work with interval-related math, has a to_cents function for now. |
Bug fixing |
||
| Line 11: | Line 11: | ||
function p._to_cents(ratio, prec) | function p._to_cents(ratio, prec) | ||
-- ratio defaults to 1 | -- ratio defaults to 1 | ||
ratio = u.eval_num_arg( | ratio = u.eval_num_arg(ratio, 1) | ||
-- output without rounding if prec is omitted | -- output without rounding if prec is omitted | ||
if prec then | if prec then | ||
| Line 18: | Line 18: | ||
else | else | ||
-- prec defaults to 3 | -- prec defaults to 3 | ||
prec = u.eval_num_arg( | prec = u.eval_num_arg(prec, 3) | ||
return 1200*u._log(ratio) | return 1200*u._log(ratio) | ||
end | end | ||
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 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