mirror of
https://github.com/rwinkhart/convertroman.git
synced 2026-09-06 08:57:16 -04:00
updated docs
This commit is contained in:
@@ -2,26 +2,40 @@
|
|||||||
|
|
||||||
[](https://pkg.go.dev/github.com/brandenc40/romannumeral)
|
[](https://pkg.go.dev/github.com/brandenc40/romannumeral)
|
||||||
|
|
||||||
Convert to and from roman numerals in Go.
|
Quickly and efficiently convert to and from roman numerals in Go.
|
||||||
|
|
||||||
|
### Benchmark Results
|
||||||
|
|
||||||
|
```sh
|
||||||
|
goos: darwin
|
||||||
|
goarch: arm64
|
||||||
|
pkg: github.com/brandenc40/romannumeral
|
||||||
|
BenchmarkToRomanNumeral
|
||||||
|
BenchmarkToRomanNumeral-8 10997846 108.5 ns/op
|
||||||
|
BenchmarkToInteger
|
||||||
|
BenchmarkToInteger-8 18861016 62.29 ns/op
|
||||||
|
```
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/brandenc40/romannumeral"
|
rom "github.com/brandenc40/romannumeral"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ExampleToInt() {
|
func ExampleRomanToInt() {
|
||||||
integer, err := romannumeral.ToInt("IV")
|
integer, err := rom.ToInt("IV")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
fmt.Println(integer == 4)
|
fmt.Println(integer == 4)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleFromInt() {
|
func ExampleIntToRoman() {
|
||||||
roman, err := romannumeral.FromInt(4)
|
roman, err := rom.FromInt(4)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -1,8 +1,7 @@
|
|||||||
// Converts between integers and Roman Numeral strings.
|
// Converts between integers and Roman Numeral strings.
|
||||||
//
|
//
|
||||||
// Currently only supports Roman Numerals without viniculum (1-3999) and will throw an error for
|
// Currently only supports Roman Numerals without viniculum (1-3999) and will throw an error for
|
||||||
// numbers outside of that range.
|
// numbers outside of that range. See here for details on viniculum:
|
||||||
//
|
|
||||||
// https://en.wikipedia.org/wiki/Roman_numerals#Large_numbers
|
// https://en.wikipedia.org/wiki/Roman_numerals#Large_numbers
|
||||||
package romannumeral
|
package romannumeral
|
||||||
|
|
||||||
@@ -63,7 +62,7 @@ func intToRoman(input int) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ToInt converts a roman numeral string to an integer. Roman numerals for numbers
|
// ToInt converts a roman numeral string to an integer. Roman numerals for numbers
|
||||||
// outside of the range 1 to 3999 will return an error.
|
// outside of the range 1 to 3,999 will return an error.
|
||||||
func ToInt(input string) (int, error) {
|
func ToInt(input string) (int, error) {
|
||||||
if input == "" {
|
if input == "" {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user