diff options
| author | Mistivia <i@mistivia.com> | 2025-11-02 15:27:18 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-11-02 15:27:18 +0800 |
| commit | e9c24f4af7ed56760f6db7941827d09f6db9020b (patch) | |
| tree | 62128c43b883ce5e3148113350978755779bb5de /teleirc/matterbridge/vendor/github.com/av-elier/go-decimal-to-rational/README.md | |
| parent | 58d5e7cfda4781d8a57ec52aefd02983835c301a (diff) | |
add matterbridge
Diffstat (limited to 'teleirc/matterbridge/vendor/github.com/av-elier/go-decimal-to-rational/README.md')
| -rw-r--r-- | teleirc/matterbridge/vendor/github.com/av-elier/go-decimal-to-rational/README.md | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/teleirc/matterbridge/vendor/github.com/av-elier/go-decimal-to-rational/README.md b/teleirc/matterbridge/vendor/github.com/av-elier/go-decimal-to-rational/README.md new file mode 100644 index 0000000..6a5abe9 --- /dev/null +++ b/teleirc/matterbridge/vendor/github.com/av-elier/go-decimal-to-rational/README.md @@ -0,0 +1,54 @@ +# go-decimal-to-rational + +[](https://travis-ci.org/av-elier/go-decimal-to-rational) + +Go library to convert decimal (float64) to rational fraction with required precision + +Relies on [Continued Fraction](http://mathworld.wolfram.com/ContinuedFraction.html) algorythm. + +It's sometimes more appropriate than default big.Rat SetString, because +you can get `2/3` from `0.6666` by specifiing required precision. In big.Rat SetString +you can only get `3333/50000`, and have no way to manipulate than (as of go 1.11). + +# Example +```go +func ExampleNewRatP() { + fmt.Println(NewRatP(0.6666, 0.01).String()) + fmt.Println(NewRatP(0.981, 0.001).String()) + fmt.Println(NewRatP(0.75, 0.01).String()) + // Output: + // 2/3 + // 981/1000 + // 3/4 +} +``` +```go +func ExampleNewRatI() { + fmt.Println(NewRatI(0.6667, 3).String()) + fmt.Println(NewRatI(0.6667, 4).String()) + // Output: + // 2/3 + // 6667/10000 +} +``` + +# Docs +``` +import dectofrac "github.com/av-elier/go-decimal-to-rational" +``` + +#### func NewRatI + +```go +func NewRatI(val float64, iterations int64) *big.Rat +``` +NewRatI returns rational from decimal using `iterations` number of +iterations in Continued Fraction algorythm + +#### func NewRatP + +```go +func NewRatP(val float64, stepPrecision float64) *big.Rat +``` +NewRatP returns rational from decimal by going as mush iterations, until +next fraction is less than `stepPrecision` |
