style(encode): reword the negative-zero rationale comments

Assisted-by: GLM 5.3
This commit is contained in:
2026-09-17 23:05:41 +02:00
parent 3c1f65038b
commit feef4fe9ea
2 changed files with 3 additions and 2 deletions
+2 -1
View File
@@ -831,7 +831,8 @@ func (e *encoder) writeFloat(v float64) error {
case math.IsInf(v, -1): case math.IsInf(v, -1):
e.buf.WriteString("-inf") e.buf.WriteString("-inf")
case v == 0: case v == 0:
// Normalise negative zero to positive zero (TOML has no -0). // Normalise negative zero to positive zero, the contract the output
// rules in the documentation state.
e.buf.WriteString("0.0") e.buf.WriteString("0.0")
default: default:
s := strconv.FormatFloat(v, 'g', -1, 64) s := strconv.FormatFloat(v, 'g', -1, 64)
+1 -1
View File
@@ -67,7 +67,7 @@ func TestMarshalFloatSpecials(t *testing.T) {
} }
func TestMarshalFloatNormalizesNegativeZero(t *testing.T) { func TestMarshalFloatNormalizesNegativeZero(t *testing.T) {
// TOML has no -0; the emitter must normalise negative zero to "0.0". // The output contract normalises negative zero to "0.0".
type Cfg struct { type Cfg struct {
Z float64 `toml:"z"` Z float64 `toml:"z"`
} }