Module:Harmonic entropy

From Xenharmonic Wiki
Revision as of 05:59, 19 August 2022 by Fredg999 (talk | contribs) (Started a module to work with interval-related math, has a to_cents function for now.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Module documentation[view] [edit] [history] [purge]
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 
Functions provided (2)
Line Function Params Description
6 to_cents (invokable) (frame)
11 _to_cents (ratio, prec)
Lua modules required (2)
Variable Module Functions used
getArgs Module:Arguments getArgs
u Module:Utils eval_num_arg
_log

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(frame.args[1], 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(frame.args[2], 3)
		return 1200*u._log(ratio)
	end
end

return p