Module:Calculator widget: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 39:
local s = 2^startIndex
local e = 2^(endIndex-startIndex)
return "floor((abs(reg)/"..s..")%"..e..")"
end
 
Line 60:
exp_start = X_EXP_START
exp_end = X_EXP_END
elseif reg == 'Y' then
main_start = Y_START
main_end = Y_END
exp_start = Y_EXP_START
exp_end = Y_EXP_END
elseif reg == 'MEM' then
main_start = MEM_START
main_end = MEM_END
exp_start = MEM_EXP_START
exp_end = MEM_EXP_END
else
error( "unknown register" )
Line 84 ⟶ 94:
.. ')'
 
end
 
local function getDisplay()
return 'ifpositive(reg,' .. get('X') .. ',' .. get('Y') .. ')'
end
 
Line 139 ⟶ 153:
}
 
local calc = '<div class="calculator" style="display:grid;grid-template-columns:repeat(4, 1fr);grid-gap:5px;min-width:256px;width:20ch;border:thin solid gray"><div style="grid-column:1/5;padding:5px">{{Calculator codex text|default=0|id=ans|formula=' .. getDisplay() .. '|style=text-align:right|readonly=1|NaN-text=Error}}</div>'
for i, v in ipairs(buttons) do
local type = v[1] == 'C' and 'destructive' or 'default'
Line 145 ⟶ 159:
calc = calc .. '{{calculator button|type='.. type ..'|weight=normal|for=reg|formula=' .. v[2] .. '|contents='.. v[1] .. '}}'
end
clac = calc .. '{{calculator|type=hidden|id=reg}}'
calc = calc .. '</div>'
return frame:preprocess(calc)