https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3ABaseConvert%2FGreek_sandbox Module:BaseConvert/Greek sandbox - Revision history 2025-06-06T13:01:41Z Revision history for this page on the wiki MediaWiki 1.45.0-wmf.4 https://en.wikipedia.org/w/index.php?title=Module:BaseConvert/Greek_sandbox&diff=1112721064&oldid=prev 40bus: ←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 &#039;local p = {} local digits = &#039;0123456789ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ&#039; local function normalizeFullWidthChars(s) return mw.ustring.gsub(s, &#039;[!-~]&#039;, 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 &#039;0x&#039; (unless x is a valid digit in the input base) from = tonumber(from) if...&#039;</p> <p><b>New page</b></p><div>local p = {}<br /> <br /> local digits = &#039;0123456789ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ&#039;<br /> <br /> local function normalizeFullWidthChars(s)<br /> return mw.ustring.gsub(s, &#039;[!-~]&#039;, 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 &#039;0x&#039; (unless x is a valid digit in the input base)<br /> from = tonumber(from)<br /> if not from or from &lt; 34 then<br /> local c<br /> n, c = n:gsub(&#039;^(-?)0[Xx]&#039;, &#039;%1&#039;)<br /> if c &gt; 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&#039;t support negative numbers in non-10 bases.<br /> local sign = &#039;&#039;<br /> local c<br /> n, c = n:gsub(&#039;^-&#039;, &#039;&#039;)<br /> if c &gt; 0 then sign = &#039;-&#039; 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 &#039;e&#039; e.g. &#039;5 e7&#039;<br /> n = n:gsub(&#039;%s*[eE]%s*&#039;, &#039;e&#039;)<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 &lt; (width or 0) do<br /> table.insert(t, 1, &#039;0&#039;)<br /> end<br /> local intPart = table.concat(t, &#039;&#039;)<br /> <br /> -- compute the fractional part<br /> local tf = {}<br /> while f &gt; 0 and #tf &lt; (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 &lt; precision then<br /> for i = 1, precision - #tf do<br /> table.insert(tf, &#039;0&#039;)<br /> end<br /> end<br /> <br /> local fracPart = table.concat(tf, &#039;&#039;)<br /> <br /> -- remove trailing zeros if not needed<br /> if not precision then<br /> fracPart = fracPart:gsub(&#039;0*$&#039;, &#039;&#039;)<br /> end<br /> <br /> -- add the radix point if needed<br /> if #fracPart &gt; 0 then<br /> fracPart = &#039;.&#039; .. fracPart<br /> end<br /> <br /> return (prefix or &#039;&#039;) .. sign .. intPart .. fracPart .. (suffix or &#039;&#039;)<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(&#039;^([0-9]+)to([0-9]+)$&#039;)<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