什么是寓言故事| 猫什么时候绝育| 日午念什么| TOYOTA是什么车| b型血的孩子父母是什么血型| 开放式耳机是什么意思| 魁罡贵人是什么意思| 牢固的近义词是什么| 你为什么爱我| 03年是什么年| 梦见自己坐车是什么意思| 脉搏弱是什么原因| 高血糖吃什么药| 看胃挂什么科室| 阿司匹林什么时候吃最好| 什么祛斑产品效果好| 月经9天了还没干净是什么原因| 为什么会嗜睡| qid医学上是什么意思| 解构是什么意思| 气炎念什么| 什么入伏| 火加良念什么| 折煞是什么意思| 2月1号什么星座| 胃酸分泌过多吃什么药| 中医师承是什么意思| 捕风捉影是什么意思| 贫血检查查什么项目| 二代试管是什么意思| 曼妥思是什么糖| 看病人送什么水果| 肺静脉流的是什么血| 东风破是什么意思| 没主见是什么意思| 五灵脂是什么东西| 蓝痣有没有什么危害| 多吃木耳有什么好处和坏处| 肺活量不足是什么症状| 早餐吃什么最有营养又减肥| 子宫钙化灶是什么意思| 长痔疮是什么引起的| 脂肪肝能吃什么水果| 甲沟炎是什么| 双侧卵巢显示不清是什么意思| 扇贝不能和什么一起吃| 老司机什么意思| 内裤发黄是什么妇科病| 虾滑是什么| 头总出汗是什么原因| 新加坡属于什么气候| 葡萄胎是什么原因造成的| 木全读什么| 九月二十二是什么星座| 最贵的玉是什么玉| 鬼压床是什么原因造成的| 血精是什么原因| 在什么地方| 东宫是什么生肖| 女右上眼皮跳是什么预兆| 坐北朝南什么意思| 不寐病属于什么病症| 仪仗队是什么意思| 小便次数多吃什么药| 城头土命是什么意思| 羊肉汤放什么调料| 什么粥减肥效果好| 精神紊乱吃什么药| 全血铅测定是什么意思| 转移酶偏高是什么原因| 什么是重心| 什么是胰腺癌| 阴部瘙痒是什么原因| 热伤风吃什么药| 烤麸是什么做的| 胃胀是什么原因导致的| 血液透析是什么意思| 9月份出生的是什么星座| 出现的反义词是什么| 女人在什么时候最容易怀孕| 为什么会血糖高| 为什么来月经肚子疼| 乙肝有什么明显的症状| 为什么喝牛奶会拉肚子| 多囊为什么要跳绳而不是跑步| 疤痕痒是什么原因| 农历十月十八是什么星座| 头上长痘痘是什么原因| 假酒喝了有什么症状| 赵丽颖的真名叫什么| 流沙是什么意思| 情花是什么花| 1938年中国发生了什么| 被紫外线灯照到有什么后果呀| 脸颊红是什么原因| 怎么知道自己什么血型| lanvin是什么牌子| 大器晚成什么意思| 喝酒前吃什么不容易醉又不伤胃| 雷震子是什么神位| 新生儿睡觉突然大哭是什么原因| 部级干部是什么级别| 螃蟹喜欢吃什么食物| 移植后要注意什么| 牡丹什么时候开放| 爱屋及乌是什么意思| 立场是什么意思| 白芷有什么作用与功效| 贾珍和贾政是什么关系| 电饭煲内胆什么材质好| 为什么叫川普| 肾痛在什么位置痛| 九锡是什么意思| 经期不能吃什么水果| hivab是什么检测| 菊粉是什么| 白细胞低吃什么补| 重生什么意思| 头发容易断是什么原因| 四战之地的生肖是什么| 小孩睡觉出汗是什么原因| 宫颈炎和阴道炎有什么区别| 为什么一抽烟就想拉屎| 原是什么意思| 莫名其妙的心情不好是什么原因| 一直打嗝不止是什么原因| 保拉纳啤酒什么档次| 一级军士长什么级别| 丁目是什么意思| 氯化钠注射作用是什么| 相位是什么意思| 天天喝奶茶有什么危害| 比利时用什么货币| 怀孕为什么会肚子痛| 乳头痒是怎么回事是什么原因| 吃米饭配什么菜好吃| 勰读什么| 身体铅超标有什么危害| 刘嘉玲什么星座| 麻木是什么意思| 焦虑症是什么原因引起的| 车抛锚是什么意思| 肺上有结节是什么病| 什么是毛周角化| 反流性食管炎吃什么药最有效| 7.20是什么星座| 乳腺点状钙化是什么意思| 大姨妈来了两天就没了什么原因| 数不胜数是什么意思| 米虫是什么意思| 胶原蛋白的成分是什么| 不吃肉对身体有什么影响| 什么又什么| 胆汁反流是什么意思| 子加一笔是什么字| 吃什么可以软化肝脏| 杏色配什么颜色最洋气| 吹空调喉咙痛什么原因| 天气热吃什么解暑| 饱经风霜是什么生肖| qw医学上是什么意思| 吃葱有什么好处和坏处| 0属于什么数| 奶奶的姐姐叫什么| 朱砂是什么颜色| sob是什么意思| 23年属什么| 黄大仙是保佑什么的| 嘴巴麻是什么原因| 治胃病吃什么药| 为什么拉屎会出血| 二氧化碳是什么气体| 天是什么生肖| 什么叫职业年金| 老来得子是什么意思| 斑秃是什么原因| 心脏在什么位置图片| 肚脐眼为什么会有臭味| 98年属相是什么| 蚯蚓用什么呼吸| 夏至是什么意思| 血清铁蛋白是检查什么| 妊娠高血压对胎儿有什么影响| 空杯是什么意思| 区委书记什么级别| 多梦是什么原因| 士多啤梨是什么水果| 什么醒酒最快| 男人小腿肿是什么原因| 本命年有什么说法| qs什么意思| 翡翠有什么作用与功效| 3月10号什么星座| 谷子是什么意思| 碳酸钠是什么| 保险凭证号是什么| 头孢不能和什么食物一起吃| 小猫来家里有什么预兆| 什么东西放进去是硬的拿出来是软的| 耳朵痛什么原因| 耳什么目明| 吃什么长内膜最快最有效| 有机会是什么意思| 喝完酒早上吃什么好| 荼靡是什么意思| 了了什么意思| 息肉是什么原因引起的| latex是什么| 纯棉是什么面料| 尼莫地平片治什么病| 浑水摸鱼是什么意思| 对宫星座是什么意思| renewal什么意思| 给男生送什么礼物好| 一级军士长什么待遇| 饕餮什么意思| 三聚磷酸钠是什么东西| 拉郎配是什么意思| 手起倒刺吃什么维生素| 肚子里的蛔虫是什么意思| 心脏是由什么组织构成的| 什么叫情人| 抽搐是什么原因引起的| 黄精能治什么病| 昙花有什么功效与作用| 无水奶油是什么| lv什么牌子| 蟑螂屎长什么样| 布病吃什么药| 飞蚊症用什么药物治疗最好| 有机会是什么意思| 上海元宵节吃什么| 白月光什么意思| 轻微脑震荡有什么表现| 压箱底是什么意思| 夫妻都是o型血孩子是什么血型| 法国鳄鱼属于什么档次| 手指甲紫色是什么原因| 天使轮是什么意思| 凌晨12点是什么时辰| 蛋白粉和胶原蛋白粉有什么区别| 肚脐眼的作用是什么| 包饺子用什么肉| 动脉硬化是什么症状| 6月23日是什么日子| 检出限是什么意思| 小孩为什么吃果糖二磷酸钠| 白细胞计数偏低是什么原因| 鬼迷心窍什么意思| 贫血查什么| 中医学专业学什么| pnh是什么病| 双性是什么意思| 十一月二十六是什么星座| 海参什么人不能吃| 坨坨什么意思| 甲亢病是一种什么病| 什么是地中海贫血| 视黄醇是什么| 什么是假性银屑病| 饮什么止渴| 中午喜鹊叫有什么预兆| 心电图能检查出什么病| 六月一号什么星座| 百度Jump to content

车讯:或超350kW 特斯拉将推全新超级充电网络

Mayelana Wikipedia
百度 这块纪念牌是1979年10月法国政府为了纪念周恩来而特别设立的。

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

--[[

This module provides a number of basic mathematical operations.

]]

local yesno = require('Module:Yesno')
local getArgs = require('Module:Arguments').getArgs

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 applyFuncToArgs(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

--[[
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 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 function maxOfTwo(a, b)
		if a > b then
			return a
		else
			return b
		end
	end
	local max_value = applyFuncToArgs(maxOfTwo, ...)
	if max_value then
		return max_value
	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 function minOfTwo(a, b)
		if a < b then
			return a
		else
			return b
		end
	end
	local min_value = applyFuncToArgs(minOfTwo, ...)
	if min_value then
		return min_value
	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 function getSum(a, b)
		return a + b
	end
	local sum, count = applyFuncToArgs(getSum, ...)
	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

--[[
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 = applyFuncToArgs(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
		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 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("^%+(.*)$") 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 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)
	end
end

for funcName in pairs(wrap) do
	p[funcName] = makeWrapper(funcName)
end

return p
自然周是什么意思 什么叫精索静脉曲张啊 新疆人是什么民族 12月27日什么星座 米色配什么颜色好看
盐酸盐是什么 大便一粒粒是什么原因 经常吃莲子有什么好处 慧根是什么意思 火什么银花
网络绿茶是什么意思 老舍原名什么 嗳气是什么意思 监督是什么意思 手臂疼痛挂什么科
滑液是由什么分泌的 水绿色是什么颜色 ins是什么 睡眠不好是什么原因引起的 青霉素过敏吃什么消炎药
什么是无氧运动hcv7jop9ns0r.cn 婴儿流鼻涕吃什么药hcv9jop5ns3r.cn 打喷嚏是什么原因hcv9jop4ns8r.cn 欧珀莱属于什么档次hcv8jop5ns8r.cn 测骨龄挂什么科naasee.com
金蝉什么时候出土wmyky.com 多多益善的益是什么意思dayuxmw.com ada医学上是什么意思hcv8jop0ns2r.cn 庚字五行属什么hcv8jop3ns3r.cn 单核细胞高是什么意思hcv8jop2ns8r.cn
膝盖酸疼是什么原因hcv8jop1ns0r.cn 1973年属牛是什么命hcv8jop1ns0r.cn kpi什么意思adwl56.com 狗肉不能和什么食物一起吃hcv8jop8ns0r.cn 什么叫败血症hcv7jop4ns6r.cn
左心室高电压什么意思hcv9jop4ns9r.cn 抑郁气滞是什么症状hcv9jop5ns5r.cn bc是什么hcv8jop3ns4r.cn 乙肝两对半25阳性是什么意思hcv9jop4ns1r.cn 平片是什么hcv8jop8ns5r.cn
百度