Content deleted Content added
update from sandbox per Template talk:Convert#Module version 25 |
update from sandbox per Template talk:Convert#Module version 27 |
||
Line 411:
-- If no altitude given, use default (zero altitude = sea level).
-- Table gives speed of sound in miles per hour at various altitudes:
-- altitude = -17,499 to
-- mach_table[a + 4] = s where
-- a = (altitude / 5000) rounded to nearest integer (-3 to
-- s = speed of sound (mph) at that altitude
-- LATER: Should calculate result from an interpolation between the next
Line 423:
660.1, 660.1, 660.1, 662.0, 664.3, 666.5, 668.9, 671.1, 673.4, 675.6, -- 11 to 20
677.9, 683.7, 689.9, 696.0, 702.1, 708.1, 714.0, 719.9, 725.8, 731.6, -- 21 to 30
737.3, 737.7, 737.7, 736.2, 730.5, 724.6, 718.8, 712.9, 707.0, 701.
695.0, 688.9, 682.8, 676.6, 670.4, 664.1, 657.8, 652.9, 648.3, 643.7, -- 41 to 50
639.1, 634.4, 629.6, 624.8, 620.0, 615.2, 613.2, 613.2, 613.2, 613.5, -- 51 to 60
614.4, 615.3, 616.7, 619.8, 623.4, 629.7, 635.0, 641.1, 650.6, 660.0, -- 61 to 70
672.5, 674.3, 676.1, 677.9, 679.7, 681.5, 683.3, 685.1, 686.8, 688.6, -- 71 to 80
}
altitude = altitude or 0
Line 435 ⟶ 437:
if a < -3 then
a = -3
elseif a >
a =
end
return mach_table[a + 4] * 0.44704 -- mph converted to m/s
Line 1,548 ⟶ 1,550:
-- v = value of text (text is a number)
-- f = true if value is an integer
-- Input can use en digits or digits in local language or separators,
-- but
if text then
local number = tonumber(to_en(text))
Line 1,689 ⟶ 1,691:
end
local function range_text(range, want_name, parms, before, after, inout, options)
-- Return before .. rtext .. after
-- where rtext is the text that separates two values in a range.
local rtext, adj_text, exception
options = options or {}
if type(range) == 'table' then
-- Table must specify range text for ('off' and 'on') or ('input' and 'output'),
Line 1,709 ⟶ 1,712:
end
end
if rtext == '–' and (options.spaced or after:sub(1, #MINUS) == MINUS) then
rtext = ' – '
end
Line 1,787 ⟶ 1,790:
-- Return true if successful or return false, t where t is an error message table.
currency_text = nil -- local testing can hold module in memory; must clear globals
if kv_pairs.adj and kv_pairs.sing then
-- For enwiki (before translation), warn if attempt to use adj and sing
Line 1,807 ⟶ 1,802:
local en_name = text_code.en_option_name[loc_name]
if en_name then
local en_value = text_code.en_option_value[en_name]
if
en_value = nil
if loc_value == '' then
add_warning(parms, 2, 'cvt_empty_option', loc_name)
elseif en_name == '$' then▼
-- Value should be a single character like "€" for the euro currency symbol, but anything is accepted.▼
currency_text = (loc_value == 'euro') and '€' or loc_value▼
else
local minimum
local number, is_integer = get_number(loc_value)
if en_name == '
minimum = 1
elseif en_name == 'frac' then
minimum = 2
if number and number < 0 then
Line 1,824 ⟶ 1,819:
end
else
minimum =
end
if number and is_integer and number >= minimum then
en_value = number
else
add_warning(parms, 1, (en_name == 'frac' and 'cvt_bad_frac' or 'cvt_bad_sigfig'), loc_name .. '=' .. loc_value)▼
if en_name == 'frac' then
m = 'cvt_bad_frac'
elseif en_name == 'sigfig' then
m = 'cvt_bad_sigfig'
else▼
m = 'cvt_bad_altitude'
end
▲ add_warning(parms, 1,
end
end
elseif en_value == 'TEXT' then -- $, input, qid, qual, stylein, styleout, tracking
▲ elseif accept_any_text[en_name] then
en_value = loc_value ~= '' and loc_value or nil -- accept non-empty user text with no validation
if not en_value and (en_name == '$' or en_name == 'qid' or en_name == '
add_warning(parms, 2, 'cvt_empty_option', loc_name)
▲ elseif en_name == '$' then
▲ -- Value should be a single character like "€" for the euro currency symbol, but anything is accepted.
▲ currency_text = (loc_value == 'euro') and '€' or loc_value
elseif en_name == 'input' then
-- May have something like {{convert|input=}} (empty input) if source is an infobox
-- with optional fields. In that case, want to output nothing rather than an error.
Line 1,840 ⟶ 1,848:
end
else
en_value =
if en_value and en_value:sub(-1) == '?' then
en_value = en_value:sub(1, -2)
Line 2,192 ⟶ 2,200:
end
if in_unit_table.builtin == 'mach' then
-- As with old template, a number following Mach as the input unit is the altitude
-- That is deprecated: should use altitude_ft=NUMBER or altitude_m=NUMBER.
local success, info
success = tonumber(parms[i]) -- this will often work and will give correct result for values like 2e4 without forcing output scientific notation
if success then
local success, info = extract_number(parms, parms[i], false, true)▼
info = { value = success }
else
end
if success then
i = i + 1
Line 2,424 ⟶ 2,436:
end
if in_builtin == 'mach' or out_builtin == 'mach' then
-- Should check that only one altitude is given but am planning to remove
▲ local adjust
-- in_current.altitude (which can only occur when Mach is the input unit),
-- and out_current.altitude cannot occur.
local alt = parms.altitude_ft or in_current.altitude
if not alt and parms.altitude_m then
alt = parms.altitude_m / 0.3048 -- 1 ft = 0.3048 m
end
if in_builtin == 'mach' then
inscale =
▲ else
▲ outscale = speed_of_sound(out_current.altitude)
adjust = 0.1 / inscale▼
end
outscale = spd
return true, {
outvalue = invalue * (inscale / outscale),
Line 2,631 ⟶ 2,649:
show = format('%.0f', floor((outvalue / n) + 0.5) * n)
end
elseif in_current.builtin == 'mach' then
local sigfig = info.clean:gsub('^[0.]+', ''):gsub('%.', ''):len() + 1
show, exponent = make_sigfig(outvalue, sigfig)
else
local inclean = info.clean
Line 3,254 ⟶ 3,275:
-- For simplicity and because more not needed, handle one range item only.
local prefix2 = make_id(parms, 2, first_unit) .. ' '
result = range_text(range[1], want_name, parms, result, prefix2 .. valinfo[2].show, 'in', {spaced=true})
end
return preunit .. result
Line 3,344 ⟶ 3,365:
if range then
-- For simplicity and because more not needed, handle one range item only.
result = range_text(range[1], want_name, parms, result, prefix .. valinfo[2].show, inout, {spaced=true})
end
return preunit .. result
Line 3,550 ⟶ 3,571:
local success, result2 = make_result(valinfo[i+1])
if not success then return false, result2 end
result = range_text(range[i], want_name, parms, result, result2, inout, {spaced=true})
end
end
|