Jump to content

Module:Convert and Module:Convert/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
m 1 revision imported from wikipedia:Module:Convert
 
m 1 revision imported
 
Line 415: Line 415:
--  a = (altitude / 5000) rounded to nearest integer (-3 to 80)
--  a = (altitude / 5000) rounded to nearest integer (-3 to 80)
--  s = speed of sound (mph) at that altitude
--  s = speed of sound (mph) at that altitude
-- LATER: Should calculate result from an interpolation between the next
-- lower and higher altitudes in table, rather than rounding to nearest.
-- From: http://www.aerospaceweb.org/question/atmosphere/q0112.shtml
-- From: http://www.aerospaceweb.org/question/atmosphere/q0112.shtml
local mach_table = {                                                      -- a =
local mach_table = {                                                      -- a =
Line 427: Line 429:
672.5, 674.3, 676.1, 677.9, 679.7, 681.5, 683.3, 685.1, 686.8, 688.6,  -- 71 to 80
672.5, 674.3, 676.1, 677.9, 679.7, 681.5, 683.3, 685.1, 686.8, 688.6,  -- 71 to 80
}
}
local function lerp(t, v0, v1)
altitude = altitude or 0
return t * v1 + (1 - t) * v0
local a = (altitude < 0) and -altitude or altitude
a = floor(a / 5000 + 0.5)
if altitude < 0 then
a = -a
end
end
altitude = (altitude or 0) / 5000
if a < -3 then
if altitude < -3 then
a = -3
altitude = -3
elseif a > 80 then
elseif altitude > 80 then
a = 80
altitude = 80
end
end
local mach_mph
return mach_table[a + 4] * 0.44704  -- mph converted to m/s
local a = math.floor(altitude)
if a == altitude then
mach_mph = mach_table[a + 4]
else
mach_mph = lerp(altitude - a, mach_table[a + 4], mach_table[a + 5])
end
return mach_mph * 0.44704  -- mph converted to m/s
end
end
-- END: Code required only for built-in units.
-- END: Code required only for built-in units.
Line 735: Line 732:
if not success then return false, result end
if not success then return false, result end
override_from(result, t, { 'customary', 'default', 'link', 'symbol', 'symlink', 'usename' })
override_from(result, t, { 'customary', 'default', 'link', 'symbol', 'symlink', 'usename' })
if t.default then
result.defkey = unitcode  -- so default_exceptions uses the alias code, not the target symbol
end
local multiplier = t.multiplier
local multiplier = t.multiplier
if multiplier then
if multiplier then