Module:Utils: Difference between revisions

Fredg999 (talk | contribs)
m Forgot p
+gcd function
Line 1: Line 1:
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local p = {}
local p = {}
 
-- check if a table contains x
-- check if a table contains x
function p.table_contains(tbl, x)
function p.table_contains(tbl, x)
Line 54: Line 54:
b = p.eval_num_arg(b, 2)
b = p.eval_num_arg(b, 2)
return math.log(x)/math.log(b)
return math.log(x)/math.log(b)
end
-- return greatest common divisor of a and b
function p.gcd(frame)
local args = getArgs(frame)
return p._gcd(args[1], args[2])
end
function _gcd(a, b)
if b ~= 0 then
return _gcd(b, a % b)
else
return math.abs (a)
end
end
end