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

Decimal number displayed differently #718

Open
Duologic opened this issue Aug 3, 2023 · 0 comments
Open

Decimal number displayed differently #718

Duologic opened this issue Aug 3, 2023 · 0 comments

Comments

@Duologic
Copy link

Duologic commented Aug 3, 2023

Downstream issue: CertainLach/jrsonnet#108

Decimal numbers are displayed differently depending on the implementation.

➜ jsonnet -e 0.97
0.96999999999999997

➜ jrsonnet -e 0.97
0.97

Further investigation also showed it depends on which functions used for representation:

# go jsonnet
❯ nix run nixpkgs#go-jsonnet -- -e "std.manifestJson(0.97)"
"0.97"
❯ nix run nixpkgs#go-jsonnet -- -e "std.toString(0.97)"
"0.96999999999999997"
❯ nix run nixpkgs#go-jsonnet -- -e 0.97
0.96999999999999997

# c++ jsonnet
❯ nix run nixpkgs#jsonnet -- -e "std.manifestJson(0.97)"
"0.96999999999999997"
❯ nix run nixpkgs#jsonnet -- -e "std.toString(0.97)"
"0.96999999999999997"
❯ nix run nixpkgs#jsonnet -- -e 0.97
0.96999999999999997

# rust jrsonnet
❯ cargo run -- -e "std.manifestJson(0.97)"
"0.97"
❯ cargo run -- -e "std.toString(0.97)"
"0.97"
❯ cargo run -- -e 0.97
0.97

@sparkprime suggest using the short version in Go:

My preference would be for the shortest exact string. There was no way to do that in C++ and we matched that behaviour in Go. Given we're trying to move people off of C++ to Go it may be a good time to switch Go over to the shorter output.

Initially I've only encountered this when using jrsonnet directly but we are working on a feature in Tanka to use the rust version alongside the Go version and this causes a massive diff on our code base. It would be nice if we could get this fixed in the Go version so we can get rid of the diff and keep our sanity.

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