炖牛肉放什么容易烂| 办身份证的地方叫什么| 女娲补天是什么生肖| pr是什么意思医学| bally什么牌子| 流产会出现什么症状| 什么时间喝酸奶最好| 逆流而上是什么意思| 印比是什么意思| 肝病有什么征兆| 葛根粉有什么功效| 月经期间喝红糖水有什么好处| 媳妇是什么意思| 吃纳豆有什么好处| 瑞典和瑞士有什么区别| 炖牛肉放什么调料好吃| 吃什么可以增强硬度| 什么药补血最快| 世故是什么意思| 什么瓜不能吃脑筋急转弯| 河北有什么山| 吃万艾可有什么副作用| 哮喘不能吃什么| c肽是什么意思| 父母是o型血孩子是什么血型| 梦见狼是什么意思周公解梦| kt什么意思| 回忆杀是什么意思| 主管护师是什么职称| 乐哉是什么意思| 半夜胃反酸水是什么原因| 死马当活马医是什么意思| 什么是基本养老金| 为什么叫基围虾| 喉咙痒咳嗽有痰是什么原因| 农历五月初五是什么节日| 幽门螺旋杆菌弱阳性是什么意思| 天道好轮回什么意思| 香港的别称是什么| 谷丙转氨酶偏高是什么原因| 提高免疫力吃什么药| 咳嗽有痰吃什么药好得最快最有效| 黄油是用什么做的| 胃炎吃什么中药效果好| 囊肿是什么原因造成的| 什么东西可以解酒| 喝什么茶能降低血糖| aj是什么鞋子| 一什么牌子| 男才女貌是什么意思| 阿迪达斯是什么牌子| 什么食物含维生素k最多| 保肝护肝吃什么药好| 一个火一个同念什么| 饮水思源是什么意思| 薤白是什么东西| 什么是码率| 盐酸氟桂利嗪胶囊治什么病| 行政助理是干什么的| 旅行是什么意思| 为什么会缺铁| 新百伦鞋子什么档次| 小孩测骨龄挂什么科| 喝酒拉肚子吃什么药| 怀孕初期可以吃什么水果| 一切尽在不言中是什么意思| 西南方向是什么方位| 丝瓜配什么炒好吃| 木可以加什么偏旁| 韵母是什么| 指甲有白点是什么原因| 女性憋不住尿是什么原因| 手持吸尘器什么牌子好| 人体缺钙吃什么补最快| 梦到怀孕了是什么预兆| 生物制剂是什么药| 现在流行什么样的衣柜| 鸟加一笔是什么字| 母亲节送什么礼物好| 鼠妇是什么动物| 憋尿有什么危害| 髋关节积液是什么原因造成的| 道德什么意思| 属鸡的守护神是什么菩萨| 金匮肾气丸主治什么病| 吃中药喝酒有什么影响| 黄鳝不能和什么一起吃| 牛仔裤配什么上衣好看| 夹生是什么意思| 劲酒加什么好喝| 什么是横纹肌溶解症| 孜然是什么| 腹股沟淋巴结肿大是什么原因| 毛手毛脚什么意思| 翻来覆去是什么意思| 酉读什么| 支队长是什么级别| 吃芒果对人有什么好处| lala是什么意思| 10月27日什么星座| 口粮是什么意思| 乳腺结节有什么症状| 牛排和什么一起炖好吃| 为什么会得子宫肌瘤| 罪对什么| 腌肉用什么淀粉| 经常长溃疡是什么原因引起的| 爱长闭口用什么护肤品| 嘚瑟是什么意思| 扁桃体经常发炎是什么原因| 什么地制宜| 腮腺炎吃什么食物| 大眼角痒用什么眼药水| 惰性是什么意思| 食欲亢进是什么意思| 肾疼挂什么科| 深夜里买醉是什么歌| 肾虚吃什么补| 梦见眼镜蛇是什么预兆| 鼻涕有血丝是什么原因| 神经性耳鸣吃什么药好| 虎皮羊质是指什么生肖| 破瓜年华是什么意思| cvd是什么意思| 什么水果补铁效果最好的| 老婆妹妹叫什么| 什么是矿泉水| 车加昆念什么| 泌尿系统感染挂什么科| 阴阳脸是什么意思| 甩货是什么意思| 歇斯底里是什么意思| 撒贝宁是什么民族| 报价是什么意思| 惊魂未定的意思是什么| 卸磨杀驴什么意思| 脚脖子浮肿是什么原因引起的| 兰台是什么意思| 带环了月经推迟不来什么原因| 巨蟹座和什么最配| 尿蛋白是什么原因造成的| 7个月的宝宝吃什么辅食| 卵胎生是什么意思| 增生期子宫内膜是什么意思| 神志不清是什么意思| 做扩胸运动有什么好处| 最高人民法院院长什么级别| 念珠菌性阴道炎用什么药| 结膜炎滴什么眼药水| 重返20岁韩国版叫什么| 笑死是什么意思| 怀孕周期是从什么时候开始算的| 中年危机是什么意思| 精子对女性有什么好处| 龟是什么意思| 自闭症是什么人投胎| 列席是什么意思| 什么叫电子版照片| 黄大仙是保佑什么的| 解脲脲原体是什么意思| 排卵期是指什么时候| colorful是什么牌子| 去心火喝什么茶好| 子宫小是什么原因引起的| 化石是什么| 米酒和黄酒有什么区别| 峻字五行属什么| 流汗有什么好处| 爵是什么器皿| 皮肤长斑是什么原因引起的| 什么药止汗效果最好| 先兆流产是什么意思| 12月10日是什么星座| b和o型血生的孩子是什么血型| 为什么明星不激光祛斑| 主胰管不扩张是什么意思| 原发性高血压是什么意思| 1966年属什么今年多大| 南辕北辙什么意思| 夫妻都是a型血孩子是什么血型| 大张伟的真名叫什么| apart是什么意思| hpv感染是什么病| 真实写照的意思是什么| 什么是基础医学| 什么时候需要做肠镜| 产妇能吃什么水果| 真性情是什么意思| 碘伏过敏是什么症状| 白子画什么时候爱上花千骨的| 脑梗什么东西不能吃| fat是什么意思| 两个土念什么| 父亲生日送什么礼物| 小虾米吃什么| 台阶是什么意思| 奕字属于五行属什么| 头发爱出油是什么原因| 佩字五行属什么| 洗澡用什么香皂好| 为什么会有甲状腺结节| 一只耳朵响是什么原因| 绿茶婊是什么意思| bq是什么意思啊| 右侧卵巢囊性回声什么意思| 梦见着火是什么预兆| 吃了螃蟹不能吃什么| 救赎是什么意思| 冒冷汗是什么原因| 狂狷是什么意思| 办出国护照需要什么手续| 鱼饼是什么做的| 置之不理的置是什么意思| b超检查什么| 欲是什么意思| 8月10日什么星座| 耳鸣吃什么中药| 父亲节该送什么礼物| 11月28日是什么星座| 女人喝白茶有什么好处| 五月二十一号是什么星座| 手机电池是什么电池| 一什么山| 什么一刻值千金花有清香月有阴| 尿浑浊是什么病的前兆| 八哥是什么鸟| 数九寒天是什么意思| 大米有什么营养| 淀粉酶是查什么的| vc是什么意思| 支原体感染是什么意思| 拉架棉是什么面料| 滔滔不绝的绝什么意思| 女人肝胆湿热吃什么药| 哮喘咳嗽吃什么药好得快| 阿昔洛韦片治什么病| 牙龈一直出血是什么原因| 不让他看我的朋友圈是什么效果| 金牛座属于什么象星座| 葫芦娃的爷爷叫什么| 白血病是什么原因引起的| 拆线挂什么科| 汤姆是什么品种的猫| 衣原体阴性是什么意思| 哺乳期乳腺炎吃什么药| 2004年是什么生肖| 肠癌有什么症状| 嗣子是什么意思| 壮阳是什么意思| 董承和董卓什么关系| 中国女人裹脚是从什么时候开始| 两岁宝宝坐飞机需要什么证件| 什么鱼刺少好吃| 卤水是什么水| 权字五行属什么| 肺肿物是什么意思| 水肿是什么样子| 为什么油耳朵就有狐臭| 养尊处优什么意思| 小刺猬吃什么东西| 为什么延迟退休| 甲状腺偏高是什么原因引起的| 男命食神代表什么| 什么叫引流| 百度Jump to content

近日天气像坐“过山车”:贵阳昨日一夜降温13度

??? ?????????
百度 目前,北京福建企业总商会在京共有会员企业23000多家,年创产值约7500多亿,缴纳税费约150多亿。

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)
什么降压药副作用小且效果最好 糖醋鱼用什么鱼 晚上吃什么不发胖 硝化细菌是什么 什么病人要补氯化钾呢
捆鸡是什么做的 市公安局政委是什么级别 干戈指什么 痛风打什么针 老人头晕是什么原因引起的
榅桲是什么水果 月经病是什么意思啊 晨起嘴苦是什么原因 哺乳期吃避孕药对孩子有什么影响 2022年属虎的是什么命
黄金五行属什么 什么是节气 结肠炎吃什么中成药 菠萝蜜什么季节最好吃 九死一生是指什么生肖
过敏性咽炎吃什么药hcv8jop3ns7r.cn 尿很臭是什么原因女性hcv7jop6ns0r.cn 什么动物会冬眠jinxinzhichuang.com 端午节什么时候吃粽子hcv8jop9ns7r.cn 蒲公英吃了有什么好处hcv8jop6ns6r.cn
1221是什么星座hcv7jop4ns6r.cn 傻瓜是什么生肖zhongyiyatai.com 红玛瑙五行属什么adwl56.com 妨父母痣是什么意思hcv8jop8ns2r.cn 喉咙咳出血是什么原因hcv8jop5ns8r.cn
荆芥是什么hcv9jop2ns4r.cn 骨盐量偏低代表什么hcv8jop6ns5r.cn 鸡喜欢吃什么食物adwl56.com 邓绥和阴丽华什么关系hcv9jop2ns2r.cn 脚后跟疼痛什么原因helloaicloud.com
cashmere是什么意思hcv8jop7ns6r.cn iu是什么意思naasee.com 晒后修复用什么比较好hcv7jop6ns2r.cn 泌乳素是什么意思wuhaiwuya.com 脂溢性皮炎头皮用什么洗发水hcv9jop0ns0r.cn
百度