Changes
Undid revision 586591521 by Mr. Stradivarius (talk) reinstate the new version - the problem was limited to two modules, which I will now fix
]]
end
Usage:
]]
function zwrap.order(frameargs) local input_string = (frame.args[1] or frame.args.x or '0'); local input_number; input_number = zp._cleanNumber( frame, input_string ); if input_number == nil then return err('<strong class="error">Formatting error: Order order of magnitude input appears non-numeric</strong>') else return zp._order( input_number ) end
end
function zp._order(x) if x == 0 then return 0 end return math.floor(math.log10(math.abs(x)))
end
Usage:
]]
function zwrap.precision( frame args) local input_string = (frame.args[1] or frame.args.x or '0'); local trap_fraction = frame.args.check_fraction or false; local input_number; if typeyesno( trap_fraction , true) == 'string' then trap_fraction = trap_fraction:lower(); if trap_fraction == '-- Returns true for all input except nil, false' or trap_fraction == ', "no", "n", "0' or trap_fraction == 'no' or trap_fraction == '' then trap_fraction = false;" and a few others. See [[Module:Yesno]]. else trap_fraction = true; end end if trap_fraction then local pos = string.find( input_string, '/', 1, true ); if pos ~= nil then if string.find( input_string, '/', pos + 1, true ) == nil then local denominator = string.sub( input_string, pos+1, -1 ); local denom_value = tonumber( denominator ); if denom_value ~= nil then return math.log10(denom_value); end end end end input_number, input_string = zp._cleanNumber( frame, input_string ); if input_string == nil then return err('<strong class="error">Formatting error: Precision precision input appears non-numeric</strong>') else return zp._precision( input_string ) end
end
end
Usage:
]]
function zwrap.max( frame args) local args = frame return p._max(unpackNumberArgs(args;)) end if args[1] == nil then function p._max(...) local parent = frame:getParentfunction maxOfTwo(a, b); args = parent.args; if a > b then end return a local max_value = nil; else return b local i = 1; end while args[i] ~= nil do end local val max_value = z._cleanNumberapplyFuncToArgs( framemaxOfTwo, args[i] ...); if val ~= nil then if max_value == nil or val > max_value then return max_value = val; end end i = i + 1; end return max_value
end
Usage:
OR
When used with no arguments, it takes its input from the parent
frame. Note, any values that do not evaluate to numbers are ignored.
]]
function zwrap.min( frame args) local args = frame return p._min(unpackNumberArgs(args;)) end if args[1] == nil then function p._min(...) local parent = frame:getParentfunction minOfTwo(a, b); args = parent.args; if a < b then end return a local min_value = nil; else return b local i = 1; end while args[i] ~= nil do end local val min_value = z._cleanNumberapplyFuncToArgs( frameminOfTwo, args[i] ...); if val ~= nil then if min_value == nil or val < min_value then return min_value = val; end end i = i + 1; end return min_value
end
--[[
average
Finds the average
Usage:
OR
]]
function zwrap.average( frame args) local args = frame return p._average(unpackNumberArgs(args;)) if args[1] == nil thenend function p._average(...) local parent = frame:getParentfunction getSum(a, b); args = parent.args; return a + b end local sum = 0; local , count = 0; local i = 1; while args[i] ~= nil do local val = z._cleanNumberapplyFuncToArgs( framegetSum, args[i] ...); if val ~= nil not sum then sum = sum + val count = count + 1 return 0 end else i = i + 1; end return (count == 0 and 0 or sum/count) end
end
Usage:
--]]
function zwrap.roundgcd(frameargs) local value, precision; value = z return p._cleanNumber_gcd( frame, frame.args[1] or frame.args.value or 0 ); precision = z._cleanNumberunpackNumberArgs( frame, frame.args[2] or frame.args.precision or 0 ); if value == nil or precision == nil then return '<strong class="error">Formatting error: Round input appears non-numeric</strong>' else return z._round( value, precision ); end
end
function zp._round_gcd( value, precision ...) local rescale = math.powfunction findGcd( 10a, precision b); return local r = b local oldr = a while r ~= 0 do local quotient = math.floor( value oldr / r) oldr, r = r, oldr - quotient * rescale + r end if oldr < 0then oldr = oldr * -1 end return oldr end local result, count = applyFuncToArgs(findGcd, ...5 ) / rescale; return result
end
Usage:
]]
end
]]
function zp._cleanNumber( frame, number_string ) if type(number_string ) == nil 'number' then -- We were passed a number, so we don't need to do any processing. return number_string, tostring(number_string) elseif type(number_string) ~= 'string' or not number_string:lenfind('%S') == 0 then -- We were passed a non-string or a blank string, so exit. return nil, nil; end -- Attempt basic conversion local number = tonumber( number_string ) -- If failed, attempt to evaluate input as an expression if number == nil then local frame = mw.getCurrentFrame() local attempt = frame:preprocess( '{{#expr: ' .. number_string .. '}}' ); attempt = tonumber( attempt ); if attempt ~= nil then number = attempt; number_string = tostring( number ); else number = nil; number_string = nil; end else number_string = number_string:match("^%s*(.-)%s*$") -- String is valid but may contain padding, clean it. number_string = number_string:match( "^%s*+(.-*)%s*$" )or number_string -- Trim any leading + signs. if number_string:find('^%-?0[xX]') then -- Number is using 0xnnn notation to indicate base 16;use the number that Lua detected instead. number_string = tostring(number) end end return number, number_string;end --[[Wrapper function that does basic argument processing. This ensures that all functions from #invoke can use either the currentframe or the parent frame, and it also trims whitespace for all arguments and removes blank arguments.]] local function makeWrapper(funcName) return function (frame) local args = getArgs(frame) -- Argument processing is left to Module:Arguments. Whitespace is trimmed and blank arguments are removed. return wrap[funcName](args) endend for funcName in pairs(wrap) do p[funcName] = makeWrapper(funcName)
end
return zp