mirror of
https://github.com/rwinkhart/convertroman.git
synced 2026-08-29 21:36:29 -04:00
updated docs and readme
This commit is contained in:
@@ -3,7 +3,10 @@
|
||||
[](https://pkg.go.dev/github.com/brandenc40/romannumeral)
|
||||
[](https://codecov.io/gh/brandenc40/romannumeral)
|
||||
|
||||
Quickly and efficiently convert to and from roman numerals in Go.
|
||||
## Quickly and efficiently convert to and from roman numerals in Go.
|
||||
|
||||
A reliable module using the most efficient methods possible for converting between
|
||||
roman numerals and integers in Go. Algorithms adopted from [here](https://rosettacode.org/wiki/Roman_numerals).
|
||||
|
||||
### Benchmark Results
|
||||
|
||||
|
||||
+2
-2
@@ -44,7 +44,7 @@ var _numerals = []numeral{
|
||||
}
|
||||
|
||||
// lookup arrays used for converting from an int to a roman numeral extremely quickly.
|
||||
// inspired from https://rosettacode.org/wiki/Roman_numerals/Encode#Go
|
||||
// method from here: https://rosettacode.org/wiki/Roman_numerals/Encode#Go
|
||||
var (
|
||||
m0 = []string{"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}
|
||||
m1 = []string{"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}
|
||||
@@ -75,7 +75,7 @@ func outOfBounds(input int) bool {
|
||||
}
|
||||
|
||||
func intToRoman(n int) string {
|
||||
// this is efficient in Go. the seven operands are evaluated,
|
||||
// This is efficient in Go. The 4 operands are evaluated,
|
||||
// then a single allocation is made of the exact size needed for the result.
|
||||
return m3[n%1e4/1e3] + m2[n%1e3/1e2] + m1[n%100/10] + m0[n%10]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user