-- Convert standard numbers to greek numerals, and vice versa-- Gts-tg@el wiki, Aug. 2017
local p =
local greek_numerals =
-- used for math graph templatelocal numeral_latin_transliteration =
-- return number corresponding to letter-- params: letter (string)-- return: numberlocal function value(letter) if letter ~= 'Ϛ' and letter ~= 'ϟ' and letter ~= 'ϡ' then letter = mw.ustring.lower(letter) end return greek_numerals[letter]end
-- letter value * 1000-- params: letter (string), total (number)-- return: numberlocal function thousandth(letter, total) if letter ~= false then total = total - value(letter) -- remove previous addition as simple number total = total + (value(letter) * 1000) end return totalend
-- reverse table (index to values, values to index)-- params: tbl (table)-- return: tablelocal function reverse_table(tbl) local reversedTable =
for letter, value in pairs(tbl) do reversedTable[value] = letter end return reversedTable end
-- special notation for numbers > 9999local function mu_notation(greek_number, digits) local result = local postfix = -- digits greater than 9999 for index, digit in pairs(digits) do -- mw.log(digit) result = result .. '\\' .. numeral_latin_transliteration[digit] greek_number = greek_number:gsub(digit, "", 1) end if greek_number ~= then -- if not all digits are multiples of myriad postfix = "͵" .. greek_number .. "´" end result = '
\\stackrel{'..result..'}{\\Mu}
-- convert standard number to greek-- params: frame (obj)-- return: stringfunction p.to_greek(frame) local number = frame.args[1] local tbl = null local result = local big_values = local m_notation = false if tonumber(number) > 9999 then m_notation = true end tbl = reverse_table(greek_numerals) -- reverse to [<number>] = '
nil then index = index / 10000 else result = result .. tostring(tbl[tonumber(index)]) match = true end end if highest_numeric_position > 3 then table.insert(big_values, tbl[tonumber(index)]) end else result = result .. tostring(tbl[tonumber(index)]) end end end --local d = require "Module:Debugging" --mw.log(result) --mw.log(d.dump(big_values)) end if m_notation
-- convert greek number to standard-- greek number sample for testing: αωκα´ = 1821-- params: frame (obj)-- return: numberfunction p.to_standard(frame) local greek_number = frame.args[1] local total = 0 local thousand_flag = false local prev_letter = false greek_number = greek_number:gsub("´", "") if type(greek_number) ~= 'string' then return 'Error: value ' .. greek_number .. ' is ' .. type(greek_number) .. ' instead of expected string' end -- iterate through letters for letter in mw.ustring.gmatch(greek_number, ".") do -- check if thousand marker exists if letter
true then total = thousandth(letter, total) thousand_flag = false end total = total + value(letter) prev_letter = letter end end if thousand_flag
return p