Module:tengwar/numbers

Hello, you have come here looking for the meaning of the word Module:tengwar/numbers. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:tengwar/numbers, but we will also tell you about its etymology, its characteristics and you will know how to say Module:tengwar/numbers in singular and plural. Everything you need to know about the word Module:tengwar/numbers you have here. The definition of the word Module:tengwar/numbers will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:tengwar/numbers, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local export = {}

function basen(n,b)
    n = math.floor(n)
    if not b or b == 10 then return tostring(n) end
    local digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    local t = {}
    local sign = ""
    if n < 0 then
        sign = "-"
    n = -n
    end
    repeat
        local d = (n % b) + 1
        n = math.floor(n / b)
        table.insert(t, 1, digits:sub(d,d))
    until n == 0
    return sign .. table.concat(t,"")
end

function export.ar2teng(number, base, font)
	local digits = {}
	local decmark, dozmark, dozlast
	if font == 'annatar' or not font then
		digits = {'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', '÷', 'ø', 'ù', 'ú', 'û'}
		digits = 'ð'
		decmark = 'T'
		dozmark = 'Ê'
		dozlast = '™'
	elseif font == 'telcontar' then
		digits = {'', '', '', '', '', '', '', '', '', '', ''}
		digits = ''
		decmark = ''
		dozmark = ''
		dozlast = ''
	else
		error ('invalid font, must be annatar or telcontar')
	end
	
	if base == 10 or not base then
		if key < 10 then
			number = digits
		else
			local outp = {}
			for i = 0, #number do
		    	local pos = #number + 1 - i
		    	table.insert(outp, digits..decmark)
			end
			number = table.concat(outp)
		end
	elseif base == 12 then
		if key < 12 then
			number = digits
		else
			number = basen(number, 12)
			local outp = {}
			for i = 0, #number do
		    	local pos = #number + 1 - i
		    	local cdig = string.gsub(string.gsub(string.sub(number, pos, pos), 'A', '10'), 'B', '11')
		    	if (i == #number) then
		    		table.insert(outp, digits..dozlast)
		    	else
		    		table.insert(outp, digits..dozmark)
		    	end
			end
			number = table.concat(outp)
		end
	else
		error ('invalid base, must be 10 or 12')
	end

	return number
end
return export