https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3ABaseConvert%2FGreek_sandboxModule:BaseConvert/Greek sandbox - Revision history2025-06-06T13:01:41ZRevision history for this page on the wikiMediaWiki 1.45.0-wmf.4https://en.wikipedia.org/w/index.php?title=Module:BaseConvert/Greek_sandbox&diff=1112721064&oldid=prev40bus: ←Created page with 'local p = {} local digits = '0123456789ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ' local function normalizeFullWidthChars(s) return mw.ustring.gsub(s, '[!-~]', function(s) return mw.ustring.char(mw.ustring.codepoint(s, 1) - 0xFEE0) end) end local function _convert(n, base, from, precision, width, default, prefix, suffix) n = tostring(n) -- strip off any leading '0x' (unless x is a valid digit in the input base) from = tonumber(from) if...'2022-09-27T18:36:56Z<p><a href="/wiki/Wikipedia:AES" class="mw-redirect" title="Wikipedia:AES">←</a>Created page with 'local p = {} local digits = '0123456789ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ' local function normalizeFullWidthChars(s) return mw.ustring.gsub(s, '[!-~]', function(s) return mw.ustring.char(mw.ustring.codepoint(s, 1) - 0xFEE0) end) end local function _convert(n, base, from, precision, width, default, prefix, suffix) n = tostring(n) -- strip off any leading '0x' (unless x is a valid digit in the input base) from = tonumber(from) if...'</p>
<p><b>New page</b></p><div>local p = {}<br />
<br />
local digits = '0123456789ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ'<br />
<br />
local function normalizeFullWidthChars(s)<br />
return mw.ustring.gsub(s, '[!-~]', function(s)<br />
return mw.ustring.char(mw.ustring.codepoint(s, 1) - 0xFEE0)<br />
end)<br />
end<br />
<br />
local function _convert(n, base, from, precision, width, default, prefix, suffix)<br />
n = tostring(n)<br />
<br />
-- strip off any leading '0x' (unless x is a valid digit in the input base)<br />
from = tonumber(from)<br />
if not from or from < 34 then<br />
local c<br />
n, c = n:gsub('^(-?)0[Xx]', '%1')<br />
if c > 0 and not from then from = 16 end<br />
end<br />
<br />
-- check for a negative sign. Do this while the input is still in string form,<br />
-- because tonumber doesn't support negative numbers in non-10 bases.<br />
local sign = ''<br />
local c<br />
n, c = n:gsub('^-', '')<br />
if c > 0 then sign = '-' end<br />
<br />
-- replace any full-width Unicode characters in the string with their ASCII equivalents<br />
n = normalizeFullWidthChars(n)<br />
<br />
-- handle scientific notation with whitespace around the 'e' e.g. '5 e7'<br />
n = n:gsub('%s*[eE]%s*', 'e')<br />
<br />
from = from or 10<br />
local num = tonumber(n, from)<br />
base = tonumber(base)<br />
precision = tonumber(precision)<br />
width = tonumber(width)<br />
<br />
if not num or not base then return default or n end<br />
<br />
local i, f = math.modf(num)<br />
<br />
local t = {}<br />
repeat<br />
local d = (i % base) + 1<br />
i = math.floor(i / base)<br />
table.insert(t, 1, digits:sub(d, d))<br />
until i == 0<br />
while #t < (width or 0) do<br />
table.insert(t, 1, '0')<br />
end<br />
local intPart = table.concat(t, '')<br />
<br />
-- compute the fractional part<br />
local tf = {}<br />
while f > 0 and #tf < (precision or 10) do<br />
f = f * base<br />
i, f = math.modf(f)<br />
table.insert(tf, digits:sub(i + 1, i + 1))<br />
end<br />
<br />
-- add trailing zeros if needed<br />
if precision and #tf < precision then<br />
for i = 1, precision - #tf do<br />
table.insert(tf, '0')<br />
end<br />
end<br />
<br />
local fracPart = table.concat(tf, '')<br />
<br />
-- remove trailing zeros if not needed<br />
if not precision then<br />
fracPart = fracPart:gsub('0*$', '')<br />
end<br />
<br />
-- add the radix point if needed<br />
if #fracPart > 0 then<br />
fracPart = '.' .. fracPart<br />
end<br />
<br />
return (prefix or '') .. sign .. intPart .. fracPart .. (suffix or '')<br />
end<br />
<br />
function p.convert(frame)<br />
-- Allow for invocation via #invoke or directly from another module<br />
local args<br />
if frame == mw.getCurrentFrame() then<br />
args = frame.args<br />
else<br />
args = frame<br />
end<br />
<br />
local n = args.n<br />
local base = args.base<br />
local from = args.from<br />
local precision = args.precision<br />
local width = args.width<br />
local default = args.default<br />
local prefix = args.prefix<br />
local suffix = args.suffix<br />
return _convert(n, base, from, precision, width, default, prefix, suffix)<br />
end<br />
<br />
setmetatable(p, {<br />
__index = function(t, k)<br />
local from, base = k:match('^([0-9]+)to([0-9]+)$')<br />
if not from then return nil end<br />
return function(frame)<br />
local args = frame.args<br />
return _convert(mw.text.trim(args[1]), base, from, args.precision, args.width,<br />
args.default, args.prefix, args.suffix)<br />
end<br />
end<br />
})<br />
<br />
return p</div>40bus