Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

Jump to content

Module:Sandbox/Squc/Roman/doc

From Wikipedia, the free encyclopedia

This module converts Roman numerals to decimal form, and rejects invalid ones. It can be used normally, or through another module. This is still under construction, check back in a few days!

This module is intended to run through a template, which is still under construction.

To convert Roman numerals to decimal form, use {{#invoke:Sandbox/Squc/Roman/doc|todecimal|MMXIII}}, which outputs 2013. If the Roman numeral is invalid, it will throw an error. If JavaScript is enabled, you can click the Script error link, and the first sentence should show the cause of the error. The final value will still be given in brackets after the error messages.

To force no errors, use {{#invoke:Sandbox/Squc/Roman/doc|todecimal|MMXIII}}.

To output errors directly into the text, use {{#invoke:Sandbox/Squc/Roman/doc|todecimal|MMXIII}}.

To use this through another module, use something like this:

local roman = require( "Module:Sandbox/Squc/Roman" )

local romannum = "MMXIII"
local value = roman.todecimald( romannum )


Error demonstration
function No errors Warnings Invalid Errors
Example MMXIII XXXXX XCC ABC
todecimal 2013 50 Roman numeral usage errors: More than four X in a row, suggestion: L? - roman numeral 5, char 5 190 Roman numeral usage errors: Repeat after subtraction - XCC - roman numeral 3, char 3 100 Syntax errors: Unknown character "A" found - char 1; Unknown character "B" found - char 2
todecimal|mode=1 2013 50 190 100
todecimal|mode=2|disp=Decimal ... Decimal number: 2013, Errors , Time 0.00638 Decimal number: 50, Errors Roman numeral usage errors: More than four X in a row, suggestion: L? - roman numeral 5, char 5, Time 0.0066 Decimal number: 190, Errors Roman numeral usage errors: Repeat after subtraction - XCC - roman numeral 3, char 3, Time 0.0068 Decimal number: 100, Errors Syntax errors: Unknown character "A" found - char 1; Unknown character "B" found - char 2, Time 0.007
todecimald Intended for use only from other modules. See below for more details.

Errors will be combined, e.g. "XXXXXXCC" gives:

Decimal number: 140, Errors Roman numeral usage errors: More than four X in a row, suggestion: L? - roman numeral 5, char 5; More than four X in a row, suggestion: L? - roman numeral 6, char 6; Number of X before X must be at most two - roman numeral 7, char 7; Repeat after subtraction - XCC - roman numeral 8, char 8, Time 0.00722

or with mode=2|disp=0 (default):

[num]140 [err]Roman numeral usage errors: More than four X in a row, suggestion: L? - roman numeral 5, char 5; More than four X in a row, suggestion: L? - roman numeral 6, char 6; Number of X before X must be at most two - roman numeral 7, char 7; Repeat after subtraction - XCC - roman numeral 8, char 8 [time]0.00768

todecimald

The function todecimald (direct) is only intended for use in other modules. The output will be in the form (comma-separated list): Decimal, Error message, Time taken

The decimal will be a number, it will be the converted number if there are no errors or if it is a warning (it is invalid but still can be converted), it will be -1 if there is an error (cannot be converted). The error message is a string and will always exist, it will be "" if no error is found.