You can edit almost every page by Creating an account and confirming your email.

Module:TemplateMath

From EverybodyWiki Bios & Wiki

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

This module "TemplateMath" is from Wikipedia if otherwise notified