Go - Split big.Float

I am dealing with numbers that require the big.Float type, and I need to separate them. I know that big.Int has a .Div() function, but if I'm right, it truncates the value and loses the precision obtained with big.Float .

Corresponding code

 func e(prec int64) (res *big.Float) { res = big.NewFloat(float64(1.0)) base := big.NewInt(prec) for i := base; i.Cmp(big.NewInt(int64(0))) == 1; _ = i.Sub(i, big.NewInt(1)) { d := big.NewFloat(float64(1.0)) _ = d.Div(fact(i)) // error here res.Add(d) } return } 
+5
source share
1 answer

Use Float.Quo for the big.Float section:

 x, y := big.NewFloat(10), big.NewFloat(3) z := new(big.Float).Quo(x, y) 

http://play.golang.org/p/GRPAKQNkq0

+10
source

Source: https://habr.com/ru/post/1247737/


All Articles