]]
local yesno = require('Module:Yesno')local getArgs = require('Module:Arguments')., getArgs-- lazily initialized
local p = {} -- Holds functions to be returned from #invoke, and functions to make available to other Lua modules.
end
local function applyFuncToArgsfold(func, ...)
-- Use a function on all supplied arguments, and return the result. The function must accept two numbers as parameters,
-- and must return a number as an output. This number is then supplied as input to the next function call.
end
return ret, count
end
--[[
Fold arguments by selectively choosing values (func should return when to choose the current "dominant" value).
]]
local function binary_fold(func, ...)
local value = fold((function(a, b) if func(a, b) then return a else return b end end), ...)
return value
end
local input_number;
if not yesno then
yesno = require('Module:Yesno')
end
if yesno(trap_fraction, true) then -- Returns true for all input except nil, false, "no", "n", "0" and a few others. See [[Module:Yesno]].
local pos = string.find(input_string, '/', 1, true);
return result
end
--[[
function p._max(...)
local max_value = binary_fold((function maxOfTwo(a, b) if return a > b then return a else return b end end local max_value = applyFuncToArgs(maxOfTwo), ...)
if max_value then
return max_value
end
end
--[[
median
Find the median of set of numbers
Usage:
{{#invoke:Math | median | number1 | number2 | ...}}
OR
{{#invoke:Math | median }}
]]
function wrap.median(args)
return p._median(unpackNumberArgs(args))
end
function p._median(...)
local vals = makeArgArray(...)
local count = #vals
table.sort(vals)
if count == 0 then
return 0
end
if p._mod(count, 2) == 0 then
return (vals[count/2] + vals[count/2+1])/2
else
return vals[math.ceil(count/2)]
end
end
function p._min(...)
local min_value = binary_fold((function minOfTwo(a, b) if return a < b then return a else return b end end local min_value = applyFuncToArgs(minOfTwo), ...)
if min_value then
return min_value
end
end
--[[
sum
Finds the sum
Usage:
{{#invoke:Math| sum | value1 | value2 | ... }}
OR
{{#invoke:Math| sum }}
Note, any values that do not evaluate to numbers are ignored.
]]
function wrap.sum(args)
return p._sum(unpackNumberArgs(args))
end
function p._sum(...)
local sums, count = fold((function(a, b) return a + b end), ...)
if not sums then
return 0
else
return sums
end
end
function p._average(...)
local sum, count = fold((function getSum(a, b) return a + b end local sum, count = applyFuncToArgs(getSum), ...)
if not sum then
return 0
local rescale = math.pow(10, precision or 0);
return math.floor(value * rescale + 0.5) / rescale;
end
--[[
log10
returns the log (base 10) of a number
Usage:
{{#invoke:Math | log10 | x }}
]]
function wrap.log10(args)
return math.log10(args[1])
end
return oldr
end
local result, count = applyFuncToArgsfold(findGcd, ...)
return result
end
-- If failed, attempt to evaluate input as an expression
if number == nil then
local frame success, result = pcall(mw.getCurrentFrame() local attempt = frame:callParserFunction('#ext.ParserFunctions.expr', number_string) attempt = tonumber(attempt) if attempt ~= nil success then number = attempttonumber(result)
number_string = tostring(number)
else
]]
local mt = { __index = function makeWrapper(funcNamet, k) return function (frame) local args if not getArgs then getArgs = require('Module:Arguments').getArgs end return wrap[k](getArgs(frame) ) -- Argument processing is left to Module:Arguments. Whitespace is trimmed and blank arguments are removed. return wrap[funcName](args)
end
end for funcName in pairs(wrap) do p[funcName] = makeWrapper(funcName)end}
return setmetatable(p, mt)