google / google/go-jsonnet

Decimal number displayed differently

Open
#718 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Go
Stars
1.8k
Forks
263
PR merge metrics
No merged PRs in 30d

Description

Downstream issue: https://github.com/CertainLach/jrsonnet/issues/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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.