https://github.com/y-less/roman-numerals
Code using Roman numerals (I, V, X, etc.) instead of silly Arabic ones.
https://github.com/y-less/roman-numerals
Last synced: about 2 months ago
JSON representation
Code using Roman numerals (I, V, X, etc.) instead of silly Arabic ones.
- Host: GitHub
- URL: https://github.com/y-less/roman-numerals
- Owner: Y-Less
- License: mpl-2.0
- Created: 2019-05-02T15:00:11.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-05-06T17:56:10.000Z (about 3 years ago)
- Last Synced: 2025-01-30T17:39:22.963Z (4 months ago)
- Language: Pawn
- Size: 689 KB
- Stars: 11
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# roman-numerals
[](https://github.com/Y-Less/roman-numerals)
## Installation
Simply install to your project:
```bash
sampctl package install Y-Less/roman-numerals
```Include in your code and begin using the library:
```pawn
#include
```## Usage
There are two ways to use this include - prefixed and unprefixed (default):
```pawn
#define ROMAN_LITERALS#include
#include#undef MAX_PLAYERS
#define MAX_PLAYERS (CC)main()
{
for (new i = nulla; i != XCIV; ++i)
{
printf("i + CIII = %d", i + CIII);
}
}
```Prefixed mode requires `0r` in front of the numbers, but improves compatibility:
```pawn
#define ROMAN_PREFIX
#define ROMAN_LITERALS#include
#include#undef MAX_PLAYERS
#define MAX_PLAYERS (0rCC)main()
{
for (new i = 0rN; i != 0rXCIV; ++i)
{
printf("i + 0rCIII = %d", i + 0rCIII);
}
}
```Note that there's no Roman numeral for zero, use `nulla` or `0rN` instead. `ROMAN_LITERALS` includes the defines to make the numbers work (since there are several thousand of them). Without this you can't use the literals, but can still use the two functions for converting to and from strings:
```pawn
// Remove this for much faster compiling.
//#define ROMAN_LITERALS#include
#include "roman-numerals.inc"main()
{
printf("%d", FromRomanNumeral("MCCVIIII"))
new str[32];ToRomanNumeral(54, str, .subtractive = false);
printf(str); // LIIIIToRomanNumeral(54, str, .subtractive = true);
printf(str); // LIV
}
```## Numbers
Contrary to popular belief, there is no fixed standard on how to write certain numbers. These are all valid versions of `449`:
```
CCCCXXXXVIIII
CCCCXLVIIII
CDXXXXVIIII
CCCCXXXXIX
CDXLVIIII
CDXXXXIX
CCCCXLIX
CDXLVIII
CCCCIL
CDIL
```Normally it is only `4` and `9` that has this ambiguity, so this library handles every variant of those. There is some evidence that any number can use this scheme, so `8` could be `IIX`, but these extra extended numbers are not yet handled. Unsurprisingly, Tom Scott has a relevant video:
https://www.youtube.com/watch?v=jMxoGqsmk5Y
There is also no standard for numbers over 3000, since there is no symbol for 5000. Two methods are to simply use more `M`s, or to add a bar over numbers indicating `* 1000`. This library uses the former, up to pawn symbol limits (31 characters). Thus the largest possible number you can represent without modifying the compiler is in unprefixed mode and is `31000` (`MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM`).
## Testing
To test, simply run the package:
```bash
sampctl package run
```