Module:Roman/doc: Difference between revisions
More actions
No edit summary |
Remove {{DateRelatedModules}} (not available on this wiki) |
||
| (4 intermediate revisions by one other user not shown) | |||
| Line 2: | Line 2: | ||
{{Module rating|release}}{{Module rating|protected}} | {{Module rating|release}}{{Module rating|protected}} | ||
{{lua|Module:Arguments}} | {{lua|Module:Arguments}} | ||
== Summary == | == Summary == | ||
This module contains functions for working with Roman numerals. Currently used by: | This module contains functions for working with Roman numerals. Currently used by: | ||
| Line 10: | Line 11: | ||
=== Numeral === | === Numeral === | ||
This function converts an Arabic numeral into a Roman numeral. | This function converts an Arabic numeral into a Roman numeral. It works for values between 0 (N) and 4999999999 (M̿M̿M̿M̿C̿M̿X̿C̿I̿X̿C̅M̅X̅C̅I̅X̅CMXCIX): this includes the whole range of unsigned 32-bit integers. The output string no longer contain HTML tags. If needed you can add external CSS formatting using a serif font family, or a small-caps font variant. Arabic numeral zero is output as 'N' (for Classical Latin adverbs "Nec" or "non"), like in standard CLDR Data. | ||
The output string no longer contain HTML tags. If needed you can add external CSS formatting using a serif font family, or a small-caps font variant. | |||
Arabic numeral zero is output as 'N' (for Classical Latin adverbs "Nec" or "non"), like in standard CLDR Data. | |||
If the input does not look like it contains a number or the number is outside of the supported range an error message is returned. | If the input does not look like it contains a number or the number is outside of the supported range, an error message is returned. If an error message is returned, the error message will contain code to categorize pages into [[:Category:Errors reported by Module Roman]]. | ||
Usage: | Usage: | ||
| Line 20: | Line 19: | ||
Example: | Example: | ||
<syntaxhighlight lang="wikitext" inline="yes">{{#invoke:Roman|Numeral|8}}</syntaxhighlight> produces {{#invoke:Roman|Numeral|8}} | <syntaxhighlight lang="wikitext" inline="yes">{{#invoke:Roman|Numeral|8}}</syntaxhighlight> produces {{#invoke:Roman|Numeral|8}}. | ||
=== Arabic === | |||
This function converts a Roman numeral into an Arabic numeral. It works for values between 0 (N) and 4999999999 (M̿M̿M̿M̿C̿M̿X̿C̿I̿X̿C̅M̅X̅C̅I̅X̅CMXCIX): this includes the whole range of unsigned 32-bit integers. | |||
If the input does not look like it contains a number or the number is outside of the supported range, an error message is returned. If an error message is returned, the error message will contain code to categorize pages into [[:Category:Errors reported by Module Roman]]. | |||
Usage: | |||
<syntaxhighlight lang="wikitext">{{#invoke:Roman|Arabic|''value''}}</syntaxhighlight> | |||
Example: | |||
<syntaxhighlight lang="wikitext" inline="yes">{{#invoke:Roman|Arabic|viii}}</syntaxhighlight> produces {{#invoke:Roman|Arabic|viii}}. | |||
== Using this module from Lua code == | == Using this module from Lua code == | ||
| Line 31: | Line 42: | ||
=== _Numeral === | === _Numeral === | ||
This function converts an Arabic numeral into a Roman numeral. | This function converts an Arabic numeral into a Roman numeral. It works for values between 0 and 4999999. The output string may contain HTML tags. Arabic numeral zero is output as an empty string. If the input does not look like it contains a number or the number is outside of the supported range an error message is returned. If an error message is returned, the error message will contain code to categorize pages into [[:Category:Errors reported by Module Roman]]. | ||
Usage: | Usage: | ||
| Line 38: | Line 49: | ||
=== isRoman === | === isRoman === | ||
Tests if the input is a valid Roman numeral. | Tests if the input is a valid Roman numeral. Returns true if so, false if not. For the purposes of this function, the empty string is not a valid Roman numeral. | ||
Usage: | Usage: | ||
| Line 45: | Line 56: | ||
=== toArabic === | === toArabic === | ||
This function converts a Roman numeral into an Arabic numeral. | This function converts a Roman numeral into an Arabic numeral. It works for values between 0 and 4999999999. The string 'N' is converted to zero. If the input is not a valid Roman numeral this function attempts to parse it as an Arabic number and returns nil if it also fails. | ||
Usage: | Usage: | ||
<syntaxhighlight lang="lua">arabic_value = roman.toArabic(value)</syntaxhighlight> | <syntaxhighlight lang="lua">arabic_value = roman.toArabic(value)</syntaxhighlight> | ||
Latest revision as of 16:14, 12 August 2026
Summary
editThis module contains functions for working with Roman numerals. Currently used by:
Using this module from templates
editNumeral
editThis function converts an Arabic numeral into a Roman numeral. It works for values between 0 (N) and 4999999999 (M̿M̿M̿M̿C̿M̿X̿C̿I̿X̿C̅M̅X̅C̅I̅X̅CMXCIX): this includes the whole range of unsigned 32-bit integers. The output string no longer contain HTML tags. If needed you can add external CSS formatting using a serif font family, or a small-caps font variant. Arabic numeral zero is output as 'N' (for Classical Latin adverbs "Nec" or "non"), like in standard CLDR Data.
If the input does not look like it contains a number or the number is outside of the supported range, an error message is returned. If an error message is returned, the error message will contain code to categorize pages into Category:Errors reported by Module Roman.
Usage:
{{#invoke:Roman|Numeral|''value''}}
Example:
{{#invoke:Roman|Numeral|8}} produces VIII.
Arabic
editThis function converts a Roman numeral into an Arabic numeral. It works for values between 0 (N) and 4999999999 (M̿M̿M̿M̿C̿M̿X̿C̿I̿X̿C̅M̅X̅C̅I̅X̅CMXCIX): this includes the whole range of unsigned 32-bit integers.
If the input does not look like it contains a number or the number is outside of the supported range, an error message is returned. If an error message is returned, the error message will contain code to categorize pages into Category:Errors reported by Module Roman.
Usage:
{{#invoke:Roman|Arabic|''value''}}
Example:
{{#invoke:Roman|Arabic|viii}} produces 8.
Using this module from Lua code
editIn order to use the functions in this module from another Lua module you first have to import this module.
Example:
local roman = require('Module:Roman')
_Numeral
editThis function converts an Arabic numeral into a Roman numeral. It works for values between 0 and 4999999. The output string may contain HTML tags. Arabic numeral zero is output as an empty string. If the input does not look like it contains a number or the number is outside of the supported range an error message is returned. If an error message is returned, the error message will contain code to categorize pages into Category:Errors reported by Module Roman.
Usage:
roman_value = roman._Numeral(value)
isRoman
editTests if the input is a valid Roman numeral. Returns true if so, false if not. For the purposes of this function, the empty string is not a valid Roman numeral.
Usage:
if roman.isRoman(roman_value) then
toArabic
editThis function converts a Roman numeral into an Arabic numeral. It works for values between 0 and 4999999999. The string 'N' is converted to zero. If the input is not a valid Roman numeral this function attempts to parse it as an Arabic number and returns nil if it also fails.
Usage:
arabic_value = roman.toArabic(value)