Module:Val: Difference between revisions

From Zoophilia Wiki
Jump to navigationJump to search
meta>The Mol Man
No edit summary
meta>The Mol Man
No edit summary
Line 2: Line 2:
   
   
local getArgs
local getArgs
local gaps = require('Module:Gapnum')._gaps
local delimit_group = require('Module:Gapnum').groups
local makeunit = require('Module:Val/units')
local makeunit = require('Module:Val/units')
local mSu = require('Module:Su')


function p.main(frame)
function p.main(frame)
Line 10: Line 11:
end
end
local args = getArgs(frame, {wrappers = 'Template:Val'})
local args = getArgs(frame, {wrappers = 'Template:Val'})
local n = args[1]
local number = {n=args[1], nend=args['end']}
local unc1,unc2 = args[2], args[3]
local uncertainty = {upper=args[2], lower=args[3],
local unit = args.ul or args.u
errend=args.errend,
local unit_link = args.ul ~= nil
upperend=args['+errend'], lowerend=args['-errend']}
local per_unit = args.upl or args.up
local u_tbl = {u=args.ul or args.u, ul=args.ul ~= nil,
local per_unit_link = args.upl ~= nil
p=args.upl or args.up, pl=args.upl ~= nil}
local prefix = args.p
local misc_tbl = {e=args.e, pre=args.p, suf=args.s, fmt=args.fmt, nocat=args.nocategory}
local suffix = args.u
return p._main(number,uncertainty,u_tbl,misc_tbl)
end
end


function p._main(number,uncertainty,u_tbl,misc_tbl)
local n = delimit(number.n,misc_tbl.fmt)
local unc
local uncU, uncL = uncertainty.upper, uncertainty.lower
if number.nend then
n:wikitext(number.nend)
end
if uncU then
if uncL then
uncU = delimit(uncU)..(uncertainty.upperend or '')
uncL = delimit(uncL)..(uncertainty.lowerend or '')
unc = '<span style="margin-left:0.3em;">'..mSa(uncU,uncL)..'</span>'
else
local uncU_n = mw.ustring.match(uncU,('%((.+)%)')) or uncU
if uncU == uncU_n then
unc = '<span style="margin-left:0.3em;">'..'±'..delimit(uncU_n)
if uncertainty.errend then
unc = unc..errend
end
unc = unc..'</span>'
else
unc = '('..delimit(uncU_n)..')'
end
end
end
local ret = {
misc_tbl.pre or '',
misc_tbl.e and '(' or '',
tostring(n),
misc_tbl.nend or '',
unc or '',
misc_tbl.e and ')' or '',
misc_tbl.e and '<span style="margin-left:0.25em;margin-right:0.15em">×</span>10<sup>'..delimit(misc_tbl.e)..'</sup>' or '',
units or '',
misc_tbl.suf or ''
}
ret = table.concat(ret)
return ret
end
-- TODO: Write this function to format number
-- Notes: look for and remove parentheses and +/-
function delimit(num)
return num
end
return p
return p

Revision as of 21:03, 7 January 2015

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

local p = {}
 
local getArgs
local delimit_group = require('Module:Gapnum').groups
local makeunit = require('Module:Val/units')
local mSu = require('Module:Su')

function p.main(frame)
	if not getArgs then
		getArgs = require('Module:Arguments').getArgs
	end
	local args = getArgs(frame, {wrappers = 'Template:Val'})
	local number = {n=args[1], nend=args['end']}
	local uncertainty = {upper=args[2], lower=args[3],
							errend=args.errend,
							upperend=args['+errend'], lowerend=args['-errend']}
	local u_tbl = {u=args.ul or args.u, ul=args.ul ~= nil,
					p=args.upl or args.up, pl=args.upl ~= nil}
	local misc_tbl = {e=args.e, pre=args.p, suf=args.s, fmt=args.fmt, nocat=args.nocategory}
	return p._main(number,uncertainty,u_tbl,misc_tbl)
end

function p._main(number,uncertainty,u_tbl,misc_tbl)
	local n = delimit(number.n,misc_tbl.fmt)
	local unc
	local uncU, uncL = uncertainty.upper, uncertainty.lower
	if number.nend then
		n:wikitext(number.nend)
	end

	if uncU then
		if uncL then
			uncU = delimit(uncU)..(uncertainty.upperend or '')
			uncL = delimit(uncL)..(uncertainty.lowerend or '')
			unc = '<span style="margin-left:0.3em;">'..mSa(uncU,uncL)..'</span>'
		else
			local uncU_n = mw.ustring.match(uncU,('%((.+)%)')) or uncU
			if uncU == uncU_n then
				unc = '<span style="margin-left:0.3em;">'..'±'..delimit(uncU_n)
				if uncertainty.errend then
					unc = unc..errend
				end
				unc = unc..'</span>'
			else
				unc = '('..delimit(uncU_n)..')'
			end
		end
	end

	local ret = { 
				misc_tbl.pre or '',
				misc_tbl.e and '(' or '',
				tostring(n),
				misc_tbl.nend or '',
				unc or '',
				misc_tbl.e and ')' or '',
				misc_tbl.e and '<span style="margin-left:0.25em;margin-right:0.15em">×</span>10<sup>'..delimit(misc_tbl.e)..'</sup>' or '',
				units or '',
				misc_tbl.suf or ''
			}
	ret = table.concat(ret)
	return ret
end

-- TODO: Write this function to format number
-- Notes: look for and remove parentheses and +/-
function delimit(num)
	return num
end
return p