什么是内分泌失调| 一般手脚慢进什么工厂| 对眼是什么意思| 哔哩哔哩是什么网站| 炼乳是什么| 鼠妇是什么动物| 腹部胀气吃什么药| 溜达鸡是什么意思| ua是什么| 女性尿路感染吃什么药| 紫茉莉什么时候开花| 三月份是什么季节| 100年前是什么朝代| 额头上长痘是因为什么| 懵圈是什么意思| lu是什么单位| 拟物是什么意思| 子宫内膜厚是什么原因引起的| 最熟悉的陌生人是什么意思| 臭鼬是什么动物| 1月1日是什么节| 湿气重喝什么| 冬至要注意什么| 什么化妆品好用哪个牌子的| 病历是什么| 异常出汗是什么原因| 心脏病有什么症状| geforce是什么牌子| 西红柿对人体有什么好处| 相向是什么意思| 梦见蛇是什么预兆| 鸳鸯是什么意思| 哈密瓜不能和什么一起吃| 鬼针草有什么作用| 法尔如是是什么意思| 脂肪肝吃什么食物好| 1月30号是什么星座| 查宝宝五行八字缺什么| 木驴是什么| 红日是什么意思| 吃生蚝有什么好处| 做梦捡到钱是什么预兆| 肚子大挂什么科| 汉菜不能和什么一起吃| 马齿苋是什么| 凉糕是什么做的| 停胎是什么原因造成的| 什么菜不能吃| 首饰是什么意思| 党内的最高处分是什么| 什么是无性婚姻| 为什么耳朵后面会臭| 回民不能吃什么| 阴虚火旺吃什么药| 王力是什么字| 果肉属于什么组织| 乳房头疼是什么原因| 胃出血恢复期吃什么好| 月经期间不能吃什么水果| 安享晚年是什么意思| 蜂蜜有什么作用| 汗蒸是什么意思| 口腔溃疡什么样| 雷锋是什么生肖| 吃雪燕有什么好处| 出现幻觉幻听是什么心理疾病| 什么是横纹肌溶解| 降压药什么时候吃| 被蜜蜂蛰了涂什么药膏| 贫血四项是指什么检查| 为什么老是梦见一个人| 宫颈鳞状上皮增生是什么意思| 避重就轻是什么意思| 幽门螺旋杆菌弱阳性是什么意思| 什么是bl| 为什么手指会发麻| 杰克琼斯属于什么档次| 坐北朝南是什么意思| 未土是什么土| 50分贝相当于什么声音| 珠联璧合是什么意思| 手足口病是什么原因引起的| 新生儿ad滴剂什么时候吃最好| 摩羯座跟什么星座最配| 儿童肚子痛挂什么科| 尿里带血是什么原因女性| 什么是乳胶床垫| 腿部发痒是什么原因引起的| 10月24是什么星座| 月经和怀孕的症状有什么不同| 做梦梦到理发是什么征兆| 长红痣是什么原因| 吃什么补充维生素b1| 甲木是什么意思| 提是什么生肖| 喘是什么意思| 什么水果含糖量低| 哽咽是什么意思| 梦见恐龙是什么意思| 甩货是什么意思| 甲状腺挂什么科| 头抖是什么原因| 矢气是什么意思| 胆在什么位置图片| 小孩肠胃炎吃什么药| 制动是什么意思| esmara是什么品牌| 胆囊炎不能吃什么食物| 慢慢地什么填词语| 上眼药什么意思| 光年是什么单位| 大专什么专业就业前景好| 1208是什么星座| 股票洗盘是什么意思| 甘露醇有什么作用| 1970年属什么生肖| 痘痘里面挤出来的白色东西是什么| 龋齿是什么原因造成的| 什么是马上风| 勾芡用什么粉最好| 手抖看什么科| 甲醛什么味道| 盆腔炎是什么原因引起的| 西楼是什么意思| 艾草长什么样| 什么茶下火| 梦见头上长虱子是什么意思| 吃什么菜对肝好怎么养肝| 脚底拔罐对女人有什么好处| EE什么意思| 喉咙痒想咳嗽吃什么药| 知音是什么意思| 种牙和假牙有什么区别| 发烧白细胞高是什么原因| 过期的洗面奶可以用来做什么| 苡字取名寓意是什么| ig什么意思| 大便化验隐血阳性什么意思| 排卵是什么意思啊| 疾苦的疾是什么意思| kerry英文名什么意思| 什么叫潮吹| 中暑了吃什么药| 正常白带是什么颜色| 金牛座是什么性格| 补中益气丸治什么病| 锑对人体有什么危害| 百香果什么时候成熟| 什么的芦花| 欺骗餐是什么意思| 什么才是真正的爱情| 什么| 单亲家庭是指什么| 发飙是什么意思| 三点水的字大多与什么有关| 舔是什么意思| 避孕套是什么材质| 产后恶露是什么| 毕生是什么意思| 白莲子和红莲子有什么区别| 月经不调是什么症状| 频发室性早搏吃什么药| 血脂四项包括什么| 拉拉秧学名叫什么| 女生被插是什么感觉| 丙肝为什么会自愈| 清款是什么意思| smile是什么意思| 舌苔厚黄吃什么药| 首长是什么意思| 脖子上长个包挂什么科| 1004是什么星座| 谢娜人气为什么那么高| 吃完螃蟹不能吃什么| 头伏二伏三伏吃什么| 孕妇感冒挂什么科| 相伴是什么意思| 办理护照需要什么手续| 1月22日是什么星座| 健康证需要什么材料| 港澳通行证签注是什么意思| 肌酐低是什么意思啊| 血虚肝旺有什么症状有哪些| 鼻咽癌是什么| 什么是钙化点| qeelin是什么牌子| 吃什么对肺最好| 像什么| 火可以加什么偏旁| 为什么老流鼻血| 心肾不交是什么意思| 中国四大发明是什么| 数农是什么| 子宫内膜3mm意味着什么| 腰上长痘痘是什么原因| 跳槽是什么意思| 1920年属什么生肖| 十月二十七是什么星座| 暗卫是什么意思| 什么啤酒最好喝| 儿童水痘吃什么药| olay是什么品牌| 胃炎能吃什么水果| 腰酸胀是什么原因男性| 失眠吃什么中成药效果最好| 2012年是什么命| dm代表什么| 扁桃体发炎是什么引起的| 手指麻木是什么原因引起的| 脸上长痘是什么原因| 蘑菇和什么不能一起吃| 梦见胡萝卜是什么意思| 闪婚是什么意思| 罢免是什么意思| 附属医院是什么意思| 水泻拉肚子是什么原因| 瑞夫泰格手表什么档次| 女性尿酸低是什么原因| 瓦特发明了什么| 芥末是什么植物| aojo眼镜什么档次| 什么是宾格| 美满霉素又叫什么名字| 有胃火口臭怎么办吃什么药| 1987年属什么的| 为什么一个月来两次姨妈| 怂恿是什么意思| 梦见恐龙是什么意思| hpv是什么检查| 什么是毛囊炎及症状图片| 吃什么补肾气| 茶话会是什么意思| 歌字五行属什么| 小孩拉肚子吃什么药好| 户籍地是什么| inshop女装中文叫什么| 九死一生是什么生肖| 吃苹果是什么意思| 手足口是什么病毒| 市局副局长什么级别| 猪精是什么| 五月天主唱叫什么名字| 瘴气是什么意思| 家里出现蛇是什么征兆| 为什么会上火| 银屑病用什么药膏| 阳痿是什么原因造成的| 比细菌还小的东西是什么| tomboy是什么意思| 滚去掉三点水念什么| 花开富贵是什么生肖| 一热就咳嗽是什么原因| 乙肝1245阳性什么意思| faleda是什么牌子的手表| 为什么会近视| 缺血灶是什么意思| 后脑勺白头发多是什么原因| 院子里有蛇是什么征兆| 草长莺飞是什么生肖| 唇钉是干什么用的| 拔苗助长告诉我们什么道理| 胸痛挂什么科| 头发汗多是什么原因| 减肥去医院挂什么科| 百度Saltar para o conteúdo

中超现莱斯特式黑马 最强人:我们能干出更大事业

Permanently protected module
Origem: Wikipédia, a enciclopédia livre.

--[[

This module provides a number of basic mathematical operations.

]]

local yesno, getArgs -- lazily initialized

local p = {} -- Holds functions to be returned from #invoke, and functions to make available to other Lua modules.
local wrap = {} -- Holds wrapper functions that process arguments from #invoke. These act as intemediary between functions meant for #invoke and functions meant for Lua.

--[[
Helper functions used to avoid redundant code.
]]

local function err(msg)
	-- Generates wikitext error messages.
	return mw.ustring.format('<strong class="error">Erro de formata??o: %s</strong>', msg)
end

local function unpackNumberArgs(args)
	-- Returns an unpacked list of arguments specified with numerical keys.
	local ret = {}
	for k, v in pairs(args) do
		if type(k) == 'number' then
			table.insert(ret, v)
		end
	end
	return unpack(ret)
end

local function makeArgArray(...)
	-- Makes an array of arguments from a list of arguments that might include nils.
	local args = {...} -- Table of arguments. It might contain nils or non-number values, so we can't use ipairs.
	local nums = {} -- Stores the numbers of valid numerical arguments.
	local ret = {}
	for k, v in pairs(args) do
		v = p._cleanNumber(v)
		if v then
			nums[#nums + 1] = k
			args[k] = v
		end
	end
	table.sort(nums)
	for i, num in ipairs(nums) do
		ret[#ret + 1] = args[num]
	end
	return ret
end

local function fold(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.
	local vals = makeArgArray(...)	
	local count = #vals -- The number of valid arguments
	if count == 0 then return
		-- Exit if we have no valid args, otherwise removing the first arg would cause an error.
		nil, 0
	end 
	local ret = table.remove(vals, 1)
	for _, val in ipairs(vals) do
		ret = func(ret, val)
	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

--[[
random

Generate a random number

Usage:
{{#invoke: Math | random }}
{{#invoke: Math | random | maximum value }}
{{#invoke: Math | random | minimum value | maximum value }}
]]

function wrap.random(args)
	local first = p._cleanNumber(args[1])
	local second = p._cleanNumber(args[2])
	return p._random(first, second)
end

function p._random(first, second)
	math.randomseed(mw.site.stats.edits + mw.site.stats.pages + os.time() + math.floor(os.clock() * 1000000000))
	-- math.random will throw an error if given an explicit nil parameter, so we need to use if statements to check the params.
	if first and second then
		if first <= second then -- math.random doesn't allow the first number to be greater than the second.
			return math.random(first, second)
		end
	elseif first then
		return math.random(first)
	else
		return math.random()
	end
end

--[[
order

Determine order of magnitude of a number

Usage:
{{#invoke: Math | order | value }}
]]

function wrap.order(args)
	local input_string = (args[1] or args.x or '0');
	local input_number = p._cleanNumber(input_string);
	if input_number == nil then
		return err('dados de entrada de ordem de magnitude n?o parecem ser numéricos')
	else
		return p._order(input_number)
	end    
end

function p._order(x)
	if x == 0 then return 0 end
	return math.floor(math.log10(math.abs(x)))
end

--[[
precision

Detemines the precision of a number using the string representation

Usage:
{{ #invoke: Math | precision | value }}
]]

function wrap.precision(args)
	local input_string = (args[1] or args.x or '0');
	local trap_fraction = args.check_fraction;
	local input_number;

	if not yesno then
		yesno = require('Módulo: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);
		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 = p._cleanNumber(input_string);
	if input_string == nil then
		return err('dados de entrada de precision n?o parecem ser numéricos')
	else
		return p._precision(input_string)
	end    
end

function p._precision(x)
	if type(x) == 'number' then
		x = tostring(x)
	end
	x = string.upper(x)

	local decimal = x:find('%.')
	local exponent_pos = x:find('E')
	local result = 0;

	if exponent_pos ~= nil then
		local exponent = string.sub(x, exponent_pos + 1)
		x = string.sub(x, 1, exponent_pos - 1)
		result = result - tonumber(exponent)
	end    

	if decimal ~= nil then
		result = result + string.len(x) - decimal
		return result
	end

	local pos = string.len(x);
	while x:byte(pos) == string.byte('0') do
		pos = pos - 1
		result = result - 1
		if pos <= 0 then
			return 0
		end
	end

	return result
end


--[[
max

Finds the maximum argument

Usage:
{{#invoke:Math| max | value1 | value2 | ... }}

Note, any values that do not evaluate to numbers are ignored.
]]

function wrap.max(args)
	return p._max(unpackNumberArgs(args))
end

function p._max(...)
	local max_value = binary_fold((function(a, b) return a > b end), ...)
	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

--[[
min 

Finds the minimum argument

Usage:
{{#invoke:Math| min | value1 | value2 | ... }}
OR
{{#invoke:Math| min }}

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 wrap.min(args)
	return p._min(unpackNumberArgs(args))
end

function p._min(...)
	local min_value = binary_fold((function(a, b) return a < b end), ...)
	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

--[[
average 

Finds the average

Usage:
{{#invoke:Math| average | value1 | value2 | ... }}
OR
{{#invoke:Math| average }}

Note, any values that do not evaluate to numbers are ignored.
]]

function wrap.average(args)
	return p._average(unpackNumberArgs(args))
end

function p._average(...)
	local sum, count = fold((function(a, b) return a + b end), ...)
	if not sum then
		return 0
	else
		return sum / count
	end
end

--[[
round

Rounds a number to specified precision

Usage:
{{#invoke:Math | round | value | precision }}

--]]

function wrap.round(args)
	local value = p._cleanNumber(args[1] or args.value or 0)
	local precision = p._cleanNumber(args[2] or args.precision or 0)
	if value == nil or precision == nil then
		return err('dados de entrada de ?round? n?o parecem ser numéricos')
	else
		return p._round(value, precision)
	end    
end

function p._round(value, precision)
	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

--[[
mod

Implements the modulo operator

Usage:
{{#invoke:Math | mod | x | y }}

--]]

function wrap.mod(args)
	local x = p._cleanNumber(args[1])
	local y = p._cleanNumber(args[2])
	if not x then
		return err('primeiro argumento para ?mod? n?o parece ser numérico')
	elseif not y then
		return err('segundo argumento para ?mod? n?o parece ser numérico')
	else
		return p._mod(x, y)
	end    
end

function p._mod(x, y)
	local ret = x % y
	if not (0 <= ret and ret < y) then
		ret = 0
	end
	return ret
end

--[[
gcd

Calculates the greatest common divisor of multiple numbers

Usage:
{{#invoke:Math | gcd | value 1 | value 2 | value 3 | ... }}
--]]

function wrap.gcd(args)
	return p._gcd(unpackNumberArgs(args))
end

function p._gcd(...)
	local function findGcd(a, b)
		local r = b
		local oldr = a
		while r ~= 0 do
			local quotient = math.floor(oldr / r)
			oldr, r = r, oldr - quotient * r
		end
		if oldr < 0 then
			oldr = oldr * -1
		end
		return oldr
	end
	local result, count = fold(findGcd, ...)
	return result
end

--[[
precision_format

Rounds a number to the specified precision and formats according to rules 
originally used for {{template:Rnd}}.  Output is a string.

Usage:
{{#invoke: Math | precision_format | number | precision }}
]]

function wrap.precision_format(args)
	local value_string = args[1] or 0
	local precision = args[2] or 0
	return p._precision_format(value_string, precision)
end

function p._precision_format(value_string, precision)
	-- For access to Mediawiki built-in formatter.
	local lang = mw.getContentLanguage();

	local value
	value, value_string = p._cleanNumber(value_string)
	precision = p._cleanNumber(precision)

	-- Check for non-numeric input
	if value == nil or precision == nil then
		return err('dados de entrada inválidos ao arredondar')
	end

	local current_precision = p._precision(value)
	local order = p._order(value)

	-- Due to round-off effects it is neccesary to limit the returned precision under
	-- some circumstances because the terminal digits will be inaccurately reported.
	if order + precision >= 14 then
		orig_precision = p._precision(value_string)
		if order + orig_precision >= 14 then
			precision = 13 - order;        
		end        
	end

	-- If rounding off, truncate extra digits
	if precision < current_precision then
		value = p._round(value, precision)
		current_precision = p._precision(value)
	end    

	local formatted_num = lang:formatNum(math.abs(value))
	local sign

	-- Use proper unary minus sign rather than ASCII default
	if value < 0 then
		sign = '?'
	else
		sign = ''
	end    

	-- Handle cases requiring scientific notation
	if string.find(formatted_num, 'E', 1, true) ~= nil or math.abs(order) >= 9 then
		value = value * math.pow(10, -order)
		current_precision = current_precision + order
		precision = precision + order
		formatted_num = lang:formatNum(math.abs(value))
	else
		order = 0;        
	end
	formatted_num = sign .. formatted_num

	-- Pad with zeros, if needed    
	if current_precision < precision then
		local padding
		if current_precision <= 0 then
			if precision > 0 then
				local zero_sep = lang:formatNum(1.1)
				formatted_num = formatted_num .. zero_sep:sub(2,2)

				padding = precision
				if padding > 20 then
					padding = 20
				end

				formatted_num = formatted_num .. string.rep('0', padding)
			end            
		else                   
			padding = precision - current_precision
			if padding > 20 then
				padding = 20
			end
			formatted_num = formatted_num .. string.rep('0', padding)
		end
	end

	-- Add exponential notation, if necessary.
	if order ~= 0 then
		-- Use proper unary minus sign rather than ASCII default
		if order < 0 then
			order = '?' .. lang:formatNum(math.abs(order))
		else
			order = lang:formatNum(order)
		end    

		formatted_num = formatted_num .. '<span style="margin:0 .15em 0 .25em">×</span>10<sup>' .. order .. '</sup>'
	end

	return formatted_num
end

--[[
Helper function that interprets the input numerically.  If the 
input does not appear to be a number, attempts evaluating it as
a parser functions expression.
]]

function p._cleanNumber(number_string)
	if type(number_string) == '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:find('%S') 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 success, result = pcall(mw.ext.ParserFunctions.expr, number_string)
		if success then
			number = tonumber(result)
			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("^%+(.*)$") 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 current
frame or the parent frame, and it also trims whitespace for all arguments and removes blank arguments.
]]

local mt = { __index = function(t, k)
	return function(frame)
		if not getArgs then
			getArgs = require('Módulo:Arguments').getArgs
		end
		return wrap[k](getArgs(frame))  -- Argument processing is left to Module:Arguments. Whitespace is trimmed and blank arguments are removed.
	end
end }

return setmetatable(p, mt)
后循环缺血是什么意思 公费是什么意思 脂肪肝可以吃什么水果 温度计里面红色液体是什么 2016年属猴是什么命
正骨有什么好处和坏处 12月18是什么星座 6月12是什么星座 9527是什么意思 阴气重是什么意思
村支书是什么级别 网球大满贯什么意思 流鼻血不止是什么原因 brunch是什么意思 血压高吃什么
血管堵塞吃什么药 甲状腺炎是什么引起的 脑垂体在什么位置图片 费洛蒙是什么 尿不净是什么原因
艾灸为什么不能天天灸hcv8jop8ns2r.cn 篱笆是什么hcv8jop6ns4r.cn 慢热型是什么意思hcv9jop6ns5r.cn 柠檬茶喝了有什么好处hcv8jop4ns7r.cn hyundai是什么牌子hcv7jop9ns0r.cn
早上起床咳嗽是什么原因hcv9jop5ns9r.cn 26度穿什么衣服合适hcv9jop6ns4r.cn 何曾是什么意思hcv8jop6ns8r.cn 聪明的动物是什么生肖hcv9jop3ns0r.cn 睡觉张嘴巴是什么原因hcv9jop3ns8r.cn
嗓子不舒服吃什么药hcv7jop9ns1r.cn 马跟什么生肖最配hcv8jop8ns3r.cn 吃什么容易长胖hcv9jop1ns7r.cn 前列腺不能吃什么食物hcv8jop7ns9r.cn 红花泡水喝有什么功效hcv9jop8ns0r.cn
因为我们没有什么不同hcv9jop8ns3r.cn 十九岁属什么hcv8jop6ns4r.cn ceo是什么意思hcv7jop9ns9r.cn 宫颈糜烂用什么药好hcv7jop6ns0r.cn 来大姨妈不能吃什么水果hcv9jop2ns2r.cn
百度