Module:TableTools: Difference between revisions

fix the valueUnion function for NaNs (and make it a lot simpler to boot)
(remove shallowClone - hardly worth having this in here)
(fix the valueUnion function for NaNs (and make it a lot simpler to boot))
Line 17:
local infinity = math.huge
local checkType = libraryUtil.checkType
 
-- Define a unique value to represent NaN. This is because NaN cannot be used as a table key.
local nan = {}
 
--[[
Line 140 ⟶ 137:
function p.valueUnion(...)
local lim = select('#', ...)
if lim ==< 02 then
error("nolim arguments.. ' argument' .. (lim == 1 and '' or 's') .. " passed to 'valueUnion' (minimum is 2)", 2)
end
local vals, retisNan = {}, {}p.isNan
local nanret, exists = {}, {}
for i = 1, lim do
local t = select(i, ...)
checkType('valueUnion', i, t, 'table')
for k, v in pairs(t) do
if typeisNan(v) == 'number' and tostring(v) == '-nan' then
ret[#ret + 1] = valv
v = nan -- NaN cannot be a table key, so use a proxy variable.
elseif not exists[v] then
ret[#ret + 1] = v
vals exists[v] = true
end
vals[v] = true
end
end
for val in pairs(vals) do
if val == nan then
-- This ensures that we output a NaN when we had one as input, although
-- they may have been generated in a completely different way.
val = 0/0
end
ret[#ret + 1] = val
end
return ret
Anonymous user