Home  

Random  

Nearby  



Log in  



Settings  



Donate  



About Wikipedia  

Disclaimers  



Wikipedia





Module:Val





Module  

Talk  



Language  

Watch  

View source  



This is an old revision of this page, as edited by The Mol Man (talk | contribs)at03:12, 8 January 2015. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff)  Previous revision | Latest revision (diff) | Newer revision  (diff)
 


This module implements {{Val}}.

The following modules are developed:

Use {{val/sandbox}} for testing, for example:

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

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 or '', nocat=args.nocategory}
 return p._main(number,uncertainty,u_tbl,misc_tbl)
end

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

 local paren_wrap = misc_tbl.e and (not uncL and (uncU and not uncU:find('%(')))
 
 if u_tbl.u then
  units = makeunit(u_tbl.u,
      {link=u_tbl.ul,
       per=u_tbl.p,
       per_link=u_tbl.pl})
 end
 if uncU then
  if uncL then
   uncU = delimit(uncU,fmt)
   uncL = delimit(uncL,fmt)
   if not e_10 and units then
    uncU = uncU..units
    uncL = uncL..units
   end
   uncU = uncU..(uncertainty.upperend or '')
   uncL = uncL..(uncertainty.lowerend or '')
   unc = '<span style="margin-left:0.3em;">'..mSu(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;margin-right:0.15em">±</span>'..delimit(uncU_n,fmt)
    if not e_10 and units then
     unc = unc..units
    end
    unc = unc..'</span>'
   else
    unc = '('..delimit(uncU_n,fmt)..')'
   end
   if not e_10 and units then
    unc = unc..units
   end
  end
 end

 if not e_10 and units and not mw.ustring.match(uncU,('%((.+)%)')) then
  n = n..units
 end
 
 if e_10 then
  e_10 = '<span style="margin-left:0.25em;margin-right:0.15em">×</span>10<sup>'..delimit(misc_tbl.e)..'</sup>'
  if units then
   e_10 = e_10..units
  end
 else
  e_10 = ''
 end
 local ret = { 
    misc_tbl.pre or '',
    paren_wrap and '(' or '',
    n,
    misc_tbl.nend or '',
    unc or '',
    paren_wrap and ')' or '',
    e_10,
    misc_tbl.suf or ''
   }
 ret = table.concat(ret)
 return ret
end

-- TODO: Add other format options
function delimit(n,fmt)
 local prefix,num
 if not fmt then fmt = '' end
 if n:find('[%-%+]') then
  prefix,num = mw.ustring.match(n,'([-+])([%d.]+)')
 else
  num = n
 end
 local ipart, dpart = delimit_groups(num)
 if fmt:lower() == 'commas' then
  num = table.concat(ipart,',')
  if dpart then
   dpart = table.concat(dpart)
   num = num..'.'..dpart
  end
 else
  num = {}
  num[1] = table.remove(ipart,1)
  for _, v in ipairs(ipart) do
   table.insert(num,'<span style="margin-left:.25em">'..v..'</span>')
  end
  if dpart then
   table.insert(num,'.'..table.remove(dpart,1))
   for _, v in ipairs(dpart) do
    table.insert(num,'<span style="margin-left:.25em">'..v..'</span>')
   end
  end
  num = table.concat(num)
 end
 if prefix then
  if prefix == '-' then
   prefix = '&minus;'
  end
  num = prefix..num
 end
 return num
end

return p

Retrieved from "https://en.wikipedia.org/w/index.php?title=Module:Val&oldid=641521765"
 



View edit history of this page.  


Languages

 


Аԥсшәа
العربية

Azərbaycanca
تۆرکجه
Basa Bali

Беларуская (тарашкевіца)

Буряад
Català
Чӑвашла
Čeština
الدارجة
Euskara
فارسی
Gaeilge
Galego

Hausa
Հայերեն
ि
Ilokano
Bahasa Indonesia
Italiano
Jawa

Lietuvių
Ligure
ि
Македонски


 / Mìng-dĕ̤ng-nḡ
Мокшень

Na Vosa Vakaviti


Oʻzbekcha / ўзбекча

Português
Română
Scots
Shqip
Simple English
Slovenščina
کوردی
Српски / srpski
Suomi
Svenska
ி
Taqbaylit
 
Tetun

Türkçe
Українська
اردو
Vèneto
Tiếng Vit


 

Wikipedia


This page was last edited on 8 January 2015, at 03:12 (UTC).

This version of the page has been revised. Besides normal editing, the reason for revision may have been that this version contains factual inaccuracies, vandalism, or material not compatible with the Creative Commons Attribution-ShareAlike License.



Privacy policy

About Wikipedia

Disclaimers

Contact Wikipedia

Code of Conduct

Developers

Statistics

Cookie statement

Terms of Use

Desktop