Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility with the standard library #467

Open
sitnikovv opened this issue Aug 24, 2023 · 0 comments
Open

Incompatibility with the standard library #467

sitnikovv opened this issue Aug 24, 2023 · 0 comments

Comments

@sitnikovv
Copy link

sitnikovv commented Aug 24, 2023

big.Int values are incorrectly encoded:

  • Golang 1.20.4
  • Ubuntu 20.04.6 LTS
  • goccy/go-json 0.10.2
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"math/big"

	gojson "github.com/goccy/go-json"
)

func main() {
	a := big.NewInt(123567890)
	for i := 0; i < 6; i++ {
		a = a.Mul(a, a)
	}
	buf := bytes.Buffer{}
	enc := json.NewEncoder(&buf)
	if err := enc.Encode(a); err != nil {
		fmt.Println("failed to encode standard lib, err:", err)
		return
	}
	fmt.Println("Standard library OK")

	buf = bytes.Buffer{}
	encGo := gojson.NewEncoder(&buf)
	if err := encGo.Encode(a); err != nil {
		fmt.Println("failed to encode gojson, err:", err)
	}
}
Standard library OK
failed to encode gojson, err: json: error calling MarshalJSON for type *big.Int: strconv.ParseFloat: parsing "76200948414809119462531517826850960536131686363643267779709124660654187935282503001491794421771859987339009662441641350849331462938930835750824029814149852045881073085880629334064792752258111170220340054386254402830248902603478625028789666943107329593265071439381436119961510836736786097741991680557441102980977291137567585278607104182762284525606679219639314814207975210733462121321620125633045954506623680366327265258003639207705816681123566475526950410000000000000000000000000000000000000000000000000000000000000000": value out of range
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant