CertainLach/jrsonnet

Decimal number displayed differently

Duologic opened this issue · 5 comments

Just a difference I found but this time I actually like this change but it does make it harder to switch back/forth between versions. Perhaps this is something that needs fixing in the go version? 🤷

➜ jsonnet -e 0.97
0.96999999999999997

➜ jrsonnet -e 0.97
0.97

❯ 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

❯ 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

❯ 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

Well... It looks like an inconsistency, but I wonder how/should it be fixed in jrsonnet?
In jrsonnet, -e output is serialized in the same way as std.manifestJson does.

This turns out to be more interesting than I expected, @sparkprime wdyt?

FYI, I've brought this up on the #jsonnet Slack channel on Kubernetes public Slack, Dave found more inconsistencies.

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.

I've made an upstream issue (google/go-jsonnet#718), I think it should be fixed there, closing this issue.