Module:Harmonic entropy: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
Bug fixing
Round to 3 decimal places by default ("no rounding" can be achieved by using prec ≥ 12)
Line 12: Line 12:
-- ratio defaults to 1
-- ratio defaults to 1
ratio = u.eval_num_arg(ratio, 1)
ratio = u.eval_num_arg(ratio, 1)
-- output without rounding if prec is omitted
-- prec defaults to 3
if prec then
prec = u.eval_num_arg(prec, 3)
return u._round(1200*u._log(ratio), prec)
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
end


return p
return p

Revision as of 06:06, 19 August 2022

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
_round
_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(ratio, 1)
	-- prec defaults to 3
	prec = u.eval_num_arg(prec, 3)
	return u._round(1200*u._log(ratio), prec)
end

return p