Module:TemplateMath
From EverybodyWiki Bios & Wiki
| This module is rated as alpha. It is ready for third-party input, and may be used on a few pages to see if problems arise, but should be watched. Suggestions for new features or changes in their input and output mechanisms are welcome. |
Usage
{{#invoke:TemplateMath|function_name}}
TemplateMath allows templates to calculate mathematical operations.
Usage
{{&35;invoke:TemplateMath|doOp|(first operand)|(operator)|(second operand)}}
As of now, the operator can be +, -, *, /, ^, r(This will return the first operand root of the second operand), and l(This will return the second operand base logarithm of the first operand). If an invalid operation is given, the module will return a question mark.
Example:
{{&35;invoke:TemplateMath|doOp|2|^|12}} returns 4096.
local p = {}
function p.doOp(frame)
local n = 1
local op1 = frame.args[1]
local op = frame.args[2]
local op2 = frame.args[3]
if op == "+" then
n = op1 + op2
elseif op == "-" then
n = op1 - op2
elseif op == "*" then
n = op1 * op2
elseif op == "/" then
n = op1 / op2
elseif op == "^" then
n = op1 ^ op2
elseif op == 'r' then
n = op2 ^ (1 / op1)
elseif op == "l" then
n = math.log(op1) / math.log(op2)
else
n = "?"
end
return n
end
return p
