Module:Val: Difference between revisions

Content deleted Content added
handle Module:Su here to slightly reduce overhead, and default to align=right
fix gapnum crash with '1.'; load sandbox data if sandbox; convert should not apply its own scale if a built-in unit has a scale; fmt=gaps puts a gap in a 4-digit integer; avoid overflow with large e
Line 2:
-- Format options include scientific and uncertainty notations.
 
local data_module -- name of module defining units
local delimit_groups = require('Module:Gapnum').groups
 
Line 137 ⟶ 138:
 
local function convert_lookup(ucode, value, scaled_top, want_link, si, options)
local lookup = require('Module:Convert/sandbox')._unit -- TODO remove "/sandbox" when convert updated
return lookup(ucode, {
value = value,
Line 152 ⟶ 153:
want_link = options.want_per_link
end
local data = mw.loadData('Module:Val/units'data_module)
local result = options.want_longscale and
get_builtin_unit(ucode, data.builtin_units_long_scale) or
Line 164 ⟶ 165:
end
if result.scale then
-- Setting si means convert will use the unit as given, and the sort key
-- will be calculated from the value without any extra scaling that may
-- occur if convert found the unit code. For example, if val defines the
-- unit 'year' with a scale and if si were not set, convert would also apply
-- its own scale because convert knows that a year is 31,557,600 seconds.
si = { result.symbol, result.link }
value = value * result.scale
end
Line 225 ⟶ 232:
-- Four-digit integers are not formatted with gaps.
fmt = (fmt or ''):lower()
if fmt == 'none' or (fmt ~== 'commas' and #numstr == 4 and numstr:match('^%d+$')) then
return sign .. numstr
end
Line 245 ⟶ 252:
end
if dpart then
table.insert(groups, '.' .. (table.remove(dpart, 1) or ''))
for _, v in ipairs(dpart) do
table.insert(groups, '<span style="margin-left:.25em">' .. v .. '</span>')
Line 277 ⟶ 284:
local sortkey
local want_sort = not (misc_tbl.sortable == 'off')
local sort_value = want_sort and ((number.value or 1) * (e_10.value and 10^e_10.value or 1)) or 1
if want_sort then
sort_value = number.value or 1
if e_10.value and sort_value ~= 0 then
-- The 'if' avoids {{val|0|e=1234}} giving an invalid sort_value due to overflow.
sort_value = sort_value * 10^e_10.value
end
end
local unit_table = makeunit(sort_value, {
u = unit_spec.u,
Line 367 ⟶ 381:
 
local function main(frame)
data_module = 'Module:Val/units'
if string.find(frame:getTitle(), 'sandbox', 1, true) then
data_module = data_module .. '/sandbox'
end
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame, {wrappers = { 'Template:Val', 'Template:Val/sandboxlua' }})