samp.directory
← Scripts e bibliotecas

Y-Less/roman-numerals

Code using Roman numerals (I, V, X, etc.) instead of silly Arabic ones.

Biblioteca★ 11atualizado mai. de 2022MPL-2.0Pawnsampctl
Abrir no GitHub

Instalar com o sampctl

sampctl package install Y-Less/roman-numerals

Execute na pasta do seu projeto. O sampctl baixa o pacote e as dependências dele.

README.md

roman-numerals

Installation

Simply install to your project:

sampctl package install Y-Less/roman-numerals

Include in your code and begin using the library:

#include <roman-numerals>

Usage

There are two ways to use this include - prefixed and unprefixed (default):

#define ROMAN_LITERALS

#include <roman-numerals>
#include <a_samp>

#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:

#define ROMAN_PREFIX
#define ROMAN_LITERALS

#include <roman-numerals>
#include <a_samp>

#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:

// Remove this for much faster compiling.
//#define ROMAN_LITERALS

#include <a_samp>
#include "roman-numerals.inc"

main()
{
	printf("%d", FromRomanNumeral("MCCVIIII"))
	new str[32];

	ToRomanNumeral(54, str, .subtractive = false);
	printf(str); // LIIII

	ToRomanNumeral(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 Ms, 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:

sampctl package run

Esta página é montada com o que o GitHub publica sobre o repositório. O samp.directory não hospeda o código. Avisar de um problema com esta página