Format operator does not detect negative zero (-0.0) sign
- Dominant language
- Go
- Stars
- 1.8k
- Forks
- 263
- PR merge metrics
- No merged PRs in 30d
Description
## Summary
The format operator (`%`) does not correctly detect the sign of negative zero (`-0.0`). All format specifiers (`%f`, `%e`, `%g`) produce output without a minus sign for `-0.0`, while Python's equivalent produces `-0.000000`.
## Reproduction
```
$ go-jsonnet -e '"%f" % (-0.0)'
"0.000000"
$ go-jsonnet -e '"%+f" % (-0.0)'
"+0.000000"
```
## Expected (Python reference)
```python
>>> "%f" % (-0.0)
'-0.000000'
>>> "%+f" % (-0.0)
'-0.000000'
```
## Analysis
The issue is that the sign detection uses `s < 0`, which returns `false` for `-0.0` in IEEE 754 floating point (`-0.0 < 0` is `false`). The fix is to check the sign bit directly, e.g. using `math.Signbit(s)` in Go.
This affects `%f`, `%e`, `%g`, and their uppercase variants, as well as the `+` and ` ` (space) sign flags.
## Version
go-jsonnet v0.22.0
Contributor guide
Research direction
Start with the format operator implementation exercised by the `go-jsonnet -e` reproductions, focusing on sign handling for `%f`, `%e`, `%g`, and their uppercase variants. Verify that negative zero retains its minus sign, including with the `+` and space flags, and run the relevant formatter tests if present.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100