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)
>>> "%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
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
Expected (Python reference)
Analysis
The issue is that the sign detection uses
s < 0, which returnsfalsefor-0.0in IEEE 754 floating point (-0.0 < 0isfalse). The fix is to check the sign bit directly, e.g. usingmath.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