梦见收稻谷有什么预兆| 什么是活性叶酸| 24h是什么意思| 月子吃什么| 苦瓜炒什么好吃| 行气是什么意思| 例假是什么| 华为什么手机好| 脚背痛什么原因| 妨夫是什么意思| 相依相偎是什么意思| 为什么会连续两天遗精| 庹是什么意思| 左手虎口有痣代表什么| 低压高是什么意思| 乙肝五项一五阳性什么意思| 阴虱是什么原因引起的| 脑供血不足吃什么中成药| 猫猴子是什么| 肾上腺素高会导致什么| 什么东西能戒酒| 自我感动是什么意思| 门口放镜子有什么讲究| 小米不能和什么一起吃| 测骨龄去医院挂什么科| 刘邦和项羽是什么关系| 巫师是什么意思| 经常过敏是什么原因| c反应蛋白偏高说明什么| 黄瓜籽粉有什么作用| 诺言背叛诺言是什么歌| 碱是什么东西| hpv病毒是什么病毒| evol是什么意思| 干燥症是什么症状| 牙疼是什么火引起的| 乳酸杆菌阳性什么意思| 韩信点兵什么意思| 为什么打嗝不停| 为什么乳头会痛| 梦到自己杀人是什么意思| 口腔溃疡用什么药| pigeon是什么牌子| 尿带血是什么原因| 小便很黄是什么原因| 万圣节是什么时候| 脚底发烫是什么原因| 脚趾抽筋是什么原因| 什么精神| 适合是什么意思| rf医学上是什么意思| 有偿服务是什么意思| 胎停是什么意思| 北属于五行的什么| 牵牛花是什么颜色| 什么饮料最解渴| 人为什么会哭| 清影是什么意思| 情窦初开什么意思| 须菩提是什么意思| bmg是什么意思| 护理部是干什么的| 两色富足间是什么生肖| 安乃近是什么药| 皮肤擦伤用什么药最好| 摩拳擦掌是什么意思| 不可思议的意思是什么| 鸡蛋吃多了有什么危害| 嘴巴下面长痘痘是什么原因| 三净肉是什么| 毒血症是什么病| 技校是什么| 纪梵希属于什么档次| 复合维生素b什么时候吃最好| 7月1号什么节| 喉咙发炎吃什么水果好| 动车是什么| 甲醛闻多了有什么症状| 腱子肉是什么意思| 宫颈机能不全是什么意思| 靴靴是什么意思| 过肺是什么意思| 殿后和垫后有什么区别| 脑梗灶是什么意思| 血小板降低是什么病| 缢死是什么意思| 无力感是什么意思| 拉屎为什么是绿色的| 排骨搭配什么菜好吃| 什么是网红| 家里为什么会有蟑螂| 做可乐鸡翅用什么可乐| 查性激素六项挂什么科| 梦见买狗是什么意思| 月经期间吃什么水果好| 地主代表什么生肖| 加湿器用什么水比较好| 人类是什么时候出现的| 男人做什么运动能提高性功能| 小郡肝是什么部位| 雪菊有什么功效| 什么动物吃蚊子| 脑萎缩是什么病| ip是什么意思| 肚子胀疼是什么原因| 什么叫胰岛素抵抗| 腹泻用什么药| 国资委主任是什么级别| 一度房室传导阻滞是什么意思| 阴阳人是什么意思| 茯苓什么味道| 做爱时间短吃什么药| 九月二十九号是什么星座| 西安吃什么| 嗓子有黄痰是什么原因| 从胃到小腹连着疼是什么原因| 白萝卜什么时候种| 飞蚊症是什么原因造成的能治愈吗| 肺部钙化灶是什么意思| 阴道炎吃什么消炎药| 一什么羊| 溢于言表是什么意思| 减肥晚餐吃什么| 4月9号是什么星座| 啐是什么意思| ph阳性是什么意思| 行尸走肉是什么动物| 中耳炎用什么药最好| 真知灼见什么意思| 什么是跳蛋| 港澳通行证办理需要什么证件| 查激素挂什么科| 阴虚吃什么调理| 9号来的月经什么时候是排卵期| 舌苔厚白腻是什么原因引起的| 音高是什么意思| 蛊虫是什么| 家里停电了打什么电话| 办身份证需要准备什么| vad是什么意思| 姐夫的爸爸叫什么| 1998年属什么生肖| 振幅是什么意思| 人缺钾有什么症状| Valentino什么牌子| 绿豆什么人不能吃| 1993年属什么| 复方甘草酸苷片治什么病| 女人出虚汗失眠吃什么药| 女人左下巴有痣代表什么| 九月十号什么星座| 灶王爷叫什么名字| 男同叫什么| 外聘是什么意思| 不全纵隔子宫是什么意思| 腰不好挂什么科| 十二月是什么星座| 艾滋病的症状是什么| 屏气是什么意思| 什么东西可以代替阴茎| 胃酸不能吃什么食物| 龙利鱼是什么鱼| 蛋白质是什么| 一月30号是什么星座| 金戊念什么| 为什么家里会有蚂蚁| 癌胚抗原是什么意思| 海底椰是什么东西| 魔芋长什么样子| 成全是什么意思| 乌龟为什么会叫| 什么是低保| 2月9号什么星座| 嗓子有黄痰是什么原因| 忙碌的动物是什么生肖| 盆腔炎吃什么药有效| 喝紫苏水有什么功效| 小孩睡觉磨牙是什么原因| 喉咙突然哑了什么原因| 猛虎下山是什么意思| 为什么会得幽门螺旋杆菌| 无赖不还钱最怕什么| 什么食物是碱性的| 身份证最后一位代表什么| 三伏天晒背有什么好处| 714什么星座| 乙肝两对半阴性是什么意思| 肝内低密度灶什么意思| 属猴女和什么属相最配| 249是什么意思| mr检查是什么| 神经肌电图检查什么| clinic是什么意思| 三个力念什么| 苹果醋什么时候喝最好| 头七需要做什么| 吃桑葚有什么好处| 16年是什么年| 药流后需要注意什么| 幼犬拉稀吃什么药最好| 五月初五是什么星座| 怀孕初期吃什么蔬菜好| 下午两点多是什么时辰| 那是什么呢| 阿贝数是什么意思| 合胞病毒是什么| 什么是纤维瘤| fsw是什么意思| 镜花水月是什么意思| 1887年属什么生肖| 牛的本命佛是什么佛| 头晕是什么症状| 医院康复科是干什么的| 名字为什么不能叫安然| bq是什么意思| 膝盖疼痛什么原因| 尿隐血弱阳性是什么意思| 转氨酶高是什么病| 什么时候可以查高考成绩| 什么是数字货币| 我要的是什么| 我国四大发明是什么| 人夫是什么意思| 头胀痛什么原因| 心脏肿大是什么原因| 广东人吃什么| 青瓜是什么瓜| 饿死是什么感觉| 什么满园| 肋骨中间是什么器官| 面瘫是什么原因引起的| 三国时期是什么朝代| 小便失禁是什么原因男性| 拌黄瓜需要什么调料| 投诉护士找什么部门| 水过鸭背是什么意思| 鸡奸什么意思| 狮子被称为什么| 得了性疾病有什么症状| 早上尿黄是什么原因| 怦然心动什么意思| 喜筵和喜宴是什么意思| 香蕉为什么是弯的| 检查肝肾功能挂什么科| 前方高能是什么意思| 什么是透析| 聿五行属什么| 剁椒鱼头是什么鱼头| 又吐又拉是什么原因| 吃完虾不能吃什么水果| 武汉有什么好吃的| 招采是什么意思| 鸟加一笔是什么字| 2020年是什么年| 肝阴虚吃什么中成药| 舌苔发黑是什么病的前兆| 久坐脚肿是什么原因| 朗格手表什么档次| 吃什么有助于骨头恢复| 啤酒对身体有什么好处| 绝经后子宫内膜增厚是什么原因| cvm是什么意思| 七月三十是什么星座| 脑供血不足检查什么项目| 百度Jump to content

下蛊是什么意思

From Wikispecies
百度 慰问智障儿童家庭2016年8月1日,朱少铭来到溪口村慰问退伍老兵戴毫英。

Documentation for this module may be created at Module:Math/doc

--[[

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">Formatting error: %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('order of magnitude input appears non-numeric')
	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('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);
		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('precision input appears non-numeric')
	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('round input appears non-numeric')
	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('first argument to mod appears non-numeric')
	elseif not y then
		return err('second argument to mod appears non-numeric')
	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('invalid input when rounding')
	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
		if order + p._precision(value_string) >= 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

--[[
divide

Implements the division operator

Usage:
{{#invoke:Math | divide | x | y | round= | precision= }}

--]]
function wrap.divide(args)
	local x = args[1]
	local y = args[2]
	local round = args.round
	local precision =  args.precision
	if not yesno then
		yesno = require('Module:Yesno')
	end
	return p._divide(x, y, yesno(round), precision)
end

function p._divide(x, y, round, precision)
	if y == nil or y == "" then
		return err("Empty divisor")
	elseif not tonumber(y) then
		if type(y) == 'string' and string.sub(y, 1, 1) == '<' then
			return y
		else
			return err("Not a number: " .. y)
		end
	elseif x == nil or x == "" then
		return err("Empty dividend")
	elseif not tonumber(x) then
		if type(x) == 'string' and string.sub(x, 1, 1) == '<' then
			return x
		else
			return err("Not a number: " .. x)
		end
	else
		local z = x / y
		if round then
			return p._round(z, 0)
		elseif precision then
			return p._round(z, precision)
		else
			return z	
		end
	end
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('Module: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)
edifier是什么牌子 钙化灶什么意思 桃子不能和什么水果一起吃 刘备是个什么样的人 什么牌子的空调好
家里出现蛇是什么征兆 全身发烫但不发烧是什么原因 没事找事是什么意思 朴是什么意思 忌日是什么意思
21是什么意思 肚子胀气吃什么药好得快 发物都有什么 为什么睡觉会出汗 cbp是什么意思
小孩拉肚子吃什么药效果好 坐月子什么不可以吃 百日咳是什么引起的 kb什么意思 吃什么对心脏有好处
黑豆加红枣有什么功效hcv9jop6ns9r.cn 痛风可以喝什么饮料hcv8jop2ns0r.cn 酸西地那非片是什么药hcv9jop4ns8r.cn 湿疹是由什么引起的hcv8jop5ns0r.cn 阴道干涩用什么药hcv8jop4ns5r.cn
喝柠檬水有什么好处hcv9jop6ns6r.cn 为什么客厅不能放假花hcv8jop6ns7r.cn 一毛不拔指什么生肖clwhiglsz.com 吃什么补脾hcv7jop7ns2r.cn 银行卡开户名是什么hanqikai.com
85年属牛是什么命hcv9jop0ns5r.cn 思觉失调是什么意思hcv8jop3ns9r.cn 哺乳期可以吃什么消炎药yanzhenzixun.com 故事是什么意思hcv9jop4ns7r.cn 气虚用什么泡水喝好hcv8jop7ns2r.cn
窥视是什么意思zhongyiyatai.com 什么是甲醛hcv9jop0ns0r.cn 梨花压海棠是什么意思hcv7jop6ns8r.cn 啫喱是什么hcv8jop1ns9r.cn 生育险是什么hcv8jop0ns7r.cn
百度