<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://linguifex.com/w/index.php?action=history&amp;feed=atom&amp;title=Module%3Aroman_numerals</id>
	<title>Module:roman numerals - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://linguifex.com/w/index.php?action=history&amp;feed=atom&amp;title=Module%3Aroman_numerals"/>
	<link rel="alternate" type="text/html" href="https://linguifex.com/w/index.php?title=Module:roman_numerals&amp;action=history"/>
	<updated>2026-04-22T00:16:06Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.6</generator>
	<entry>
		<id>https://linguifex.com/w/index.php?title=Module:roman_numerals&amp;diff=494624&amp;oldid=prev</id>
		<title>Sware: Created page with &quot;local roman_dict = {M = 1000, D = 500, C = 100, L = 50, X = 10, V = 5, I = 1} local repeatable = {M = true, C = true, X = true, I = true} local roman_table =  {&#039;M&#039;,  &#039;CM&#039;, &#039;D&#039;, &#039;CD&#039;, &#039;C&#039;, &#039;XC&#039;, &#039;L&#039;, &#039;XL&#039;, &#039;X&#039;, &#039;IX&#039;, &#039;V&#039;, &#039;IV&#039;, &#039;I&#039;} local arabic_table = {1000, 900,  500, 400,  100, 90,   50,  40,   10,  9,    5,   4,    1  }  local export = {}  local function nil_or_error(msg, no_error) 	if no_error then 		return nil 	else 		error(msg, 2) 	end end  function export.arabic_...&quot;</title>
		<link rel="alternate" type="text/html" href="https://linguifex.com/w/index.php?title=Module:roman_numerals&amp;diff=494624&amp;oldid=prev"/>
		<updated>2026-04-21T10:24:51Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;local roman_dict = {M = 1000, D = 500, C = 100, L = 50, X = 10, V = 5, I = 1} local repeatable = {M = true, C = true, X = true, I = true} local roman_table =  {&amp;#039;M&amp;#039;,  &amp;#039;CM&amp;#039;, &amp;#039;D&amp;#039;, &amp;#039;CD&amp;#039;, &amp;#039;C&amp;#039;, &amp;#039;XC&amp;#039;, &amp;#039;L&amp;#039;, &amp;#039;XL&amp;#039;, &amp;#039;X&amp;#039;, &amp;#039;IX&amp;#039;, &amp;#039;V&amp;#039;, &amp;#039;IV&amp;#039;, &amp;#039;I&amp;#039;} local arabic_table = {1000, 900,  500, 400,  100, 90,   50,  40,   10,  9,    5,   4,    1  }  local export = {}  local function nil_or_error(msg, no_error) 	if no_error then 		return nil 	else 		error(msg, 2) 	end end  function export.arabic_...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local roman_dict = {M = 1000, D = 500, C = 100, L = 50, X = 10, V = 5, I = 1}&lt;br /&gt;
local repeatable = {M = true, C = true, X = true, I = true}&lt;br /&gt;
local roman_table =  {&amp;#039;M&amp;#039;,  &amp;#039;CM&amp;#039;, &amp;#039;D&amp;#039;, &amp;#039;CD&amp;#039;, &amp;#039;C&amp;#039;, &amp;#039;XC&amp;#039;, &amp;#039;L&amp;#039;, &amp;#039;XL&amp;#039;, &amp;#039;X&amp;#039;, &amp;#039;IX&amp;#039;, &amp;#039;V&amp;#039;, &amp;#039;IV&amp;#039;, &amp;#039;I&amp;#039;}&lt;br /&gt;
local arabic_table = {1000, 900,  500, 400,  100, 90,   50,  40,   10,  9,    5,   4,    1  }&lt;br /&gt;
&lt;br /&gt;
local export = {}&lt;br /&gt;
&lt;br /&gt;
local function nil_or_error(msg, no_error)&lt;br /&gt;
	if no_error then&lt;br /&gt;
		return nil&lt;br /&gt;
	else&lt;br /&gt;
		error(msg, 2)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function export.arabic_to_roman(arabic, no_error, to_lower, use_j, use_iiii)&lt;br /&gt;
	if arabic == &amp;#039;&amp;#039; or arabic == nil then return nil end&lt;br /&gt;
	&lt;br /&gt;
	arabic = mw.ustring.gsub(arabic, &amp;quot;,&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
	&lt;br /&gt;
	local j = tonumber(arabic)&lt;br /&gt;
	&lt;br /&gt;
	if j == nil then return nil end&lt;br /&gt;
	&lt;br /&gt;
	if j &amp;lt;= 0 or j &amp;gt; 3999 then&lt;br /&gt;
		return nil_or_error(&amp;quot;Out of valid range&amp;quot;, no_error)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local result = {}&lt;br /&gt;
	local a, count&lt;br /&gt;
	&lt;br /&gt;
	for i, r in ipairs(roman_table) do&lt;br /&gt;
		a = arabic_table[i]&lt;br /&gt;
		count = math.floor(j / a)&lt;br /&gt;
		table.insert(result, string.rep(r, count))&lt;br /&gt;
		j = j % a&lt;br /&gt;
		if j &amp;lt;= 0 then break end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local out = table.concat(result)&lt;br /&gt;
	if to_lower then out = mw.ustring.lower(out) end&lt;br /&gt;
	&lt;br /&gt;
	if use_iiii and out:sub(-2, -1) == &amp;quot;IV&amp;quot; then out = out:sub(1, -3) .. &amp;quot;IIII&amp;quot; end&lt;br /&gt;
	if use_iiii and out:sub(-2, -1) == &amp;quot;iv&amp;quot; then out = out:sub(1, -3) .. &amp;quot;iiii&amp;quot; end&lt;br /&gt;
	&lt;br /&gt;
	if use_j and out:sub(-1, -1) == &amp;quot;I&amp;quot; then out = out:sub(1, -2) .. &amp;quot;J&amp;quot; end&lt;br /&gt;
	if use_j and out:sub(-1, -1) == &amp;quot;i&amp;quot; then out = out:sub(1, -2) .. &amp;quot;j&amp;quot; end&lt;br /&gt;
	&lt;br /&gt;
	return out&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function export.roman_to_arabic(roman, no_error)&lt;br /&gt;
	if roman == &amp;#039;&amp;#039; or roman == nil then&lt;br /&gt;
		return nil&lt;br /&gt;
	else&lt;br /&gt;
		roman = mw.ustring.upper(roman):gsub(&amp;quot;J&amp;quot;, &amp;quot;I&amp;quot;)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if not mw.ustring.match(roman, &amp;quot;^[MDCLXVI]+$&amp;quot;) then&lt;br /&gt;
		return nil_or_error(&amp;quot;Illegal Roman numeral format&amp;quot;, no_error)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local result = 0&lt;br /&gt;
	&lt;br /&gt;
	local i = 1&lt;br /&gt;
	local s1, s2, c2&lt;br /&gt;
	local length = #roman&lt;br /&gt;
	&lt;br /&gt;
	while i &amp;lt;= length do&lt;br /&gt;
		s1 = roman_dict[roman:sub(i, i)]&lt;br /&gt;
		if s1 == nil then&lt;br /&gt;
			return nil_or_error(&amp;quot;Unrecognized character in input&amp;quot;, no_error)&lt;br /&gt;
		elseif (i + 1) &amp;lt;= length then&lt;br /&gt;
			c2 = roman:sub(i + 1, i + 1)&lt;br /&gt;
			s2 = roman_dict[c2]&lt;br /&gt;
			if s2 == nil then &lt;br /&gt;
				return nil_or_error(&amp;quot;Unrecognized character in input&amp;quot;, no_error)&lt;br /&gt;
			elseif s1 &amp;gt;= s2 then&lt;br /&gt;
				if s1 == s2 and not repeatable[c2] then&lt;br /&gt;
					return nil_or_error(&amp;quot;Illegal Roman numeral format: “&amp;quot; .. c2 .. &amp;quot;” may not appear adjacent to itself&amp;quot;, no_error)&lt;br /&gt;
				end&lt;br /&gt;
				result = result + s1&lt;br /&gt;
			else&lt;br /&gt;
				result = result + s2 - s1&lt;br /&gt;
				i = i + 1&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			result = result + s1&lt;br /&gt;
		end&lt;br /&gt;
		i = i + 1&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return result&lt;br /&gt;
	&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- implements {{R2A}}&lt;br /&gt;
function export.roman_to_arabic_t(frame)&lt;br /&gt;
	local params = {&lt;br /&gt;
		[1] = {},&lt;br /&gt;
		[&amp;#039;no_error&amp;#039;] = {type = &amp;#039;boolean&amp;#039;},&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	local args = require(&amp;quot;Module:parameters&amp;quot;).process(frame:getParent().args, params)&lt;br /&gt;
	&lt;br /&gt;
	return export.roman_to_arabic(args[1], args.no_error)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- implements {{A2R}}&lt;br /&gt;
function export.arabic_to_roman_t(frame)&lt;br /&gt;
	local params = {&lt;br /&gt;
		[1] = {},&lt;br /&gt;
		[&amp;#039;lower&amp;#039;] = {type = &amp;#039;boolean&amp;#039;},&lt;br /&gt;
		[&amp;#039;j&amp;#039;] = {type = &amp;#039;boolean&amp;#039;},&lt;br /&gt;
		[&amp;#039;iiii&amp;#039;] = {type = &amp;#039;boolean&amp;#039;},&lt;br /&gt;
		[&amp;#039;no_error&amp;#039;] = {type = &amp;#039;boolean&amp;#039;},&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	local args = require(&amp;quot;Module:parameters&amp;quot;).process(frame:getParent().args, params)&lt;br /&gt;
	&lt;br /&gt;
	return export.arabic_to_roman(args[1], args.no_error, args.lower, args.j, args.iiii)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return export&lt;/div&gt;</summary>
		<author><name>Sware</name></author>
	</entry>
</feed>