Standard library / math/big
big.Rat.GobEncode()
Encode a rational for gob round trips without binary floating-point conversion. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func (x *Rat) 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.NewRat(2, 3) b, e := x.GobEncode() check(e) z := new(big.Rat) check(z.GobDecode(b)) fmt.Println(z.Cmp(x) == 0)}