Module:Convert: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
(update from sandbox per Template talk:Convert#Module version 12)
(update from sandbox per Template talk:Convert#Module version 13)
Line 911: Line 911:
end
end
return sep .. id .. mid
return sep .. id .. mid
end

local function change_sign(text)
-- Change sign of text for correct appearance because it is negated.
if text:sub(1, 1) == '-' then
return text:sub(2)
end
return '-' .. text
end
end


Line 1,279: Line 1,271:
-- with the hands unit (not worth adding code to enforce that).
-- with the hands unit (not worth adding code to enforce that).
------------------------------------------------------------------------
------------------------------------------------------------------------
local numstr, whole
local leading_plus, prefix, numstr, slashes, denstr =
local leading_plus, prefix, numstr, slashes, denstr =
text:match('^%s*(%+?)%s*(.-)%s*(%d+)%s*(/+)%s*(%d+)%s*$')
text:match('^%s*(%+?)%s*(.-)%s*(%d+)%s*(/+)%s*(%d+)%s*$')
Line 1,293: Line 1,284:
return nil
return nil
end
end
local wholestr
local whole, wholestr
if prefix == '' then
if prefix == '' then
wholestr = ''
wholestr = ''
Line 1,359: Line 1,350:
while #remainder > 0 do
while #remainder > 0 do
local ref, spaces
local ref, spaces
ref, spaces, remainder = remainder:match('^(\127UNIQ[^\127]*%-ref%-%x+%-QINU\127)(%s*)(.*)')
ref, spaces, remainder = remainder:match('^(\127[^\127]*UNIQ[^\127]*%-ref[^\127]*\127)(%s*)(.*)')
if ref then
if ref then
table.insert(refs, ref)
table.insert(refs, ref)
Line 1,460: Line 1,451:
end
end
end
end
local altvalue = altvalue or value
if isnegative and (value ~= 0) then
if isnegative and (value ~= 0) then
value = -value
value = -value
altvalue = -altvalue
altvalue = -(altvalue or value)
end
end
return true, {
return true, {
value = value,
value = value,
altvalue = altvalue,
altvalue = altvalue or value,
singular = singular,
singular = singular,
clean = clean,
clean = clean,
Line 1,486: Line 1,476:
local number = tonumber(to_en(text))
local number = tonumber(to_en(text))
if number then
if number then
local integer, fracpart = math.modf(number)
local _, fracpart = math.modf(number)
return number, (fracpart == 0)
return number, (fracpart == 0)
end
end
Line 2,168: Line 2,158:
local fudge = 1e-14 -- {{Order of magnitude}} adds this, so we do too
local fudge = 1e-14 -- {{Order of magnitude}} adds this, so we do too
local prec, minprec, adjust
local prec, minprec, adjust
local utype = out_current.utype
local subunit_ignore_trailing_zero
local subunit_ignore_trailing_zero
local subunit_more_precision -- kludge for "in" used in input like "|2|ft|6|in"
local subunit_more_precision -- kludge for "in" used in input like "|2|ft|6|in"
Line 2,468: Line 2,457:
outvalue = -outvalue
outvalue = -outvalue
end
end
local numerator, precision, success, show, exponent
local precision, show, exponent
local denominator = out_current.frac
local denominator = out_current.frac
if denominator then
if denominator then
Line 2,936: Line 2,925:
local abbr_org = parms.abbr_org
local abbr_org = parms.abbr_org
local adjectival = parms.opt_adjectival
local adjectival = parms.opt_adjectival
local disp = parms.disp
local lk = parms.lk
local lk = parms.lk
local want_link = (lk == 'on' or lk == inout)
local want_link = (lk == 'on' or lk == inout)
Line 3,514: Line 3,502:
local success, parms, in_unit_table = get_parms(frame:getParent().args)
local success, parms, in_unit_table = get_parms(frame:getParent().args)
if success then
if success then
for i = 1, 2 do -- use counter so cannot get stuck repeating convert
for _ = 1, 2 do -- use counter so cannot get stuck repeating convert
success, result, out_unit_table = process(parms, in_unit_table, out_unit_table)
success, result, out_unit_table = process(parms, in_unit_table, out_unit_table)
if success and parms.do_convert_again then
if success and parms.do_convert_again then