Help language development. Donate to The Perl Foundation

## Math::Roman cpan:TITSUKI last updated on 2020-09-09

Math-Roman-0.0.1/

# NAME

Math::Roman - A roman numerals converter

# SYNOPSIS

```use Math::Roman;

10R.say; # X
1996R.say; # MCMXCVI
(1000R + 996R)R.say; # MCMXCVI
(Math::Roman.new: "MCMXCVI").as-arabic.say; # 1996
```

# DESCRIPTION

Math::Roman is a roman numerals converter

## CONSTRUCTOR

Defined as:

``````multi method new(Str \$roman) { self.bless(value => to-arabic(\$roman)) }
multi method new(Int \$arabic) { self.bless(value => \$arabic) }
method Bridge { \$!value }
sub postfix:<R> is export { Math::Roman.new: \$^value };
``````

Creates a `Math::Roman` instance internally and returns it as an integer or a str corresponding with the context. Postfix `R` provides a syntactic sugar for converting arabic numerals into roman numerals (e.g., `10R` returns `X`).

## METHODS

### as-arabic

Defined as:

``````method as-arabic(--> Int)
``````

Returns the instance as an arabic numeral.

## SUBS

### to-roman

Defined as:

``````sub to-roman(Int \$n where \$n >= 0 --> Str) ix export
``````

Returns the roman numeral form of the integer `\$n`.

### to-arabic

Defined as:

``````sub to-arabic(Str \$r, \$pos = 0 --> Int) is export
``````

Returns the arabic numeral form of the roman numeral `\$r`.

# AUTHOR

Itsuki Toyota [email protected]