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

Big integers are unmarshalled to float with precision of 16 #703

Open
andrehaland opened this issue Feb 22, 2021 · 1 comment
Open

Big integers are unmarshalled to float with precision of 16 #703

andrehaland opened this issue Feb 22, 2021 · 1 comment

Comments

@andrehaland
Copy link

When trying to unmarshal a big integer the value is converted to a float with precision of 16.

Reproduce

https://play.golang.org/p/EJSeNwrMxVK

package main

import (
	"fmt"
	"gopkg.in/yaml.v3"
)

func main() {

	y := []byte("x: 123456789123456789123")
	var yamlObj interface{}
	err := yaml.Unmarshal(y, &yamlObj)
	if err != nil {
		panic(err)
	}
	fmt.Println("Before unmarshal: ", string(y))
	fmt.Println("After unmarshal: ", yamlObj)
}

Actual

Before unmarshal:  x: 123456789123456789123
After unmarshal:  map[x:1.234567891234568e+20]

Expected

Before unmarshal:  x: 123456789123456789123
After unmarshal:  map[x:12345678912345689123]
@taliastocks
Copy link

It's unfortunate that this and #435 are still unresolved. My guess is this is complicated because the library doesn't want to deal with integer wraparound, but it even selects the tag incorrectly when unmarshalling into a yaml.Node. I wish there were a way to change the library behavior to select the tag according to the Yaml spec so that I could avoid checking if !!float nodes are parsable as integers myself.

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

2 participants