Skip to content

constant-negative-zero

Detect constant expressions that cannot represent negative zero.

Updated View as Markdown

Default severity: warning

Go’s ideal constants do not preserve a zero sign. Literal forms such as -0.0, -float64(0), and float32(-0) therefore produce positive zero at runtime. Use math.Copysign when a true IEEE negative zero is required.

Bad

negativeZero := -0.0

Good

negativeZero := math.Copysign(0, -1)
Navigation

Type to search…

↑↓ navigate↵ selectEsc close