Standard library / math/big

big.Float.GobEncode()

Encode value and attributes including precision, rounding mode and accuracy for gob round trips. Expected stdout: 'true 20\n'.

Formal Syntax & Structure

go syntaxgo
func (x *Float) GobEncode() ([]byte, error)

Return Value

([]byte, error)

Returns the result described above; see the example for the observed behavior.

Working Example

Example Snippetgo
package main
import (  "fmt"  "math/big")
func check(err error) {  if err != nil {    panic(err)  }}func main() {  x := big.NewFloat(1.25).SetPrec(20)  b, e := x.GobEncode()  check(e)  z := new(big.Float)  check(z.GobDecode(b))  fmt.Println(z.Cmp(x) == 0, z.Prec())}
Go Reference