title: Distinguishing sign of zero : -float64(0) from float64(0) in Go
body: <p>I want to serialize a floating point in such a way that sign info is not lost.  Specifically, I would like to distinguish IEEE-754 negative zero from regular zero.</p>
  <p>The <a href="http://golang.org/doc/go_spec.html#Arithmetic_operators" rel="nofollow noreferrer">language spec</a> says</p>
  <blockquote>
  <p>The result of a floating-point division by zero is not specified beyond the IEEE-754 standard; whether a run-time panic occurs is implementation-specific.</p>
  </blockquote>
  <p>which suggests that I cannot do</p>
  <pre><code>n == 0 &amp;&amp; (float64(1) / n) &lt; 0
  </code></pre>
  <p>and I tried <code>math.Copysign</code> and <a href="http://golang.org/pkg/math/#Signbit" rel="nofollow noreferrer"><code>math.Signbit</code></a> which says</p>
  <blockquote>
  <pre><code>func Signbit(x float64) bool
  </code></pre>
  <p><code>Signbit</code> returns <code>true</code> if x is negative or negative zero.</p>
  </blockquote>
  <p>but</p>
  <pre><code>n == 0 &amp;&amp; math.Signbit(n)
  </code></pre>
  <p>doesn't seem to work for</p>
  <pre><code>n := -float64(0)
  </code></pre>
  <p>Any ideas?</p>
  <p>EDIT:</p>
  <p>I filed <a href="http://code.google.com/p/go/issues/detail?id=2196" rel="nofollow noreferrer">issue 2196</a> to track what I think is a confusing difference between</p>
  <pre><code>nz := -float64(0)
  </code></pre>
  <p>and</p>
  <pre><code>pz := float64(0)
  nz := -pz
  </code></pre>
  <p>as suggested by peterSO.</p>