I want to serialize a floating point so that sign information is not lost. In particular, I would like to distinguish the negative zero of IEEE-754 from the usual zero.
language specification speaks
The result of floating point division by zero is not specified outside the IEEE-754 standard; whether panic occurs at runtime is implementation-specific.
which suggests that I cannot do
n == 0 && (float64(1) / n) < 0
and I tried math.Copysign and math.Signbit which says
func Signbit(x float64) bool
Signbit returns true if x is negative or negative.
but
n == 0 && math.Signbit(n)
doesn't seem to work for
n := -float64(0)
Any ideas?
EDIT:
I registered issue 2196 to keep track of what I think is the confused difference between
nz := -float64(0)
and
pz := float64(0) nz := -pz
as suggested by peterSO.
source share