mirror of
https://github.com/42wim/matterbridge.git
synced 2024-11-22 20:19:35 +01:00
53cafa9f3d
This commit adds support for go/cgo tgs conversion when building with the -tags `cgo` The default binaries are still "pure" go and uses the old way of converting. * Move lottie_convert.py conversion code to its own file * Add optional libtgsconverter * Update vendor * Apply suggestions from code review * Update bridge/helper/libtgsconverter.go Co-authored-by: Wim <wim@42.be> |
||
---|---|---|
.. | ||
.travis.yml | ||
frac.go | ||
LICENSE | ||
README.md |
go-decimal-to-rational
Go library to convert decimal (float64) to rational fraction with required precision
Relies on Continued Fraction 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
func ExampleNewRatP() {
.Println(NewRatP(0.6666, 0.01).String())
fmt.Println(NewRatP(0.981, 0.001).String())
fmt.Println(NewRatP(0.75, 0.01).String())
fmt// Output:
// 2/3
// 981/1000
// 3/4
}
func ExampleNewRatI() {
.Println(NewRatI(0.6667, 3).String())
fmt.Println(NewRatI(0.6667, 4).String())
fmt// Output:
// 2/3
// 6667/10000
}
Docs
import dectofrac "github.com/av-elier/go-decimal-to-rational"
func NewRatI
func NewRatI(val float64, iterations int64) *big.Rat
NewRatI returns rational from decimal using iterations
number of iterations in Continued Fraction algorythm
func NewRatP
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