Lably
Skip to content

Signed zero

Differentiating positive and negative zero

  • 5 min read
  • 4 chapters
  • 6 labs on Lably

Learn it on Lably

The IEEE 754 standard for floating-point arithmetic (presently used by most computers and programming languages that support floating-point numbers) requires both +0 and −0. Its arithmetic can be considered to model a variant of the extended real number line (the real numbers including additional numbers +∞ and −∞). In IEEE 754 arithmetic, ⁠1/−0⁠ = −∞ and ⁠1/+0⁠ = +∞; the divisions ⁠±0/±0⁠ and ⁠±∞/±∞⁠ return "Not a Number" (NaN).

Negatively signed zero echoes the mathematical analysis concept of approaching 0 from below as a one-sided limit, which may be denoted by x → 0−, x → 0−, or x → ↑0. The notation "−0" may be used informally to denote a negative number that has been rounded to zero. The concept of negative zero also has some theoretical applications in statistical mechanics and other disciplines.

It is claimed that the inclusion of signed zero in IEEE 754 makes it much easier to achieve numerical accuracy in some critical problems, in particular when computing with complex elementary functions. On the other hand, the concept of signed zero runs contrary to the usual assumption made in mathematics that negative zero is the same value as zero. Representations that allow negative zero can be a source of errors in programs, if software developers do not take into account that while the two zero representations behave as equal under numeric comparisons, they yield different results in some operations.

Representations

Binary integer formats can use various encodings. In the widely used two's complement encoding, zero is unsigned. In a 1+7-bit sign-and-magnitude representation for integers, negative zero is represented by the bit string 1000 0000. In an 8-bit ones' complement representation, negative zero is represented by the bit string 1111 1111. In all these three encodings, positive or unsigned zero is represented by 0000 0000. However, the latter two encodings (with a signed zero) are uncommon for integer formats. The most common formats with a signed zero are floating-point formats (IEEE 754 formats or similar), described below.

In IEEE 754 binary floating-point formats, zero values are represented by the biased exponent and significand both being zero. Negative zero has the sign bit set to one. One may obtain negative zero as the result of certain computations, for instance as the result of arithmetic underflow on a negative number (other results may also be possible), or −1.0 × 0.0, or simply as −0.0.

In IEEE 754 decimal floating-point formats, a negative zero is represented by an exponent being any valid exponent in the range for the format, the true significand being zero, and the sign bit being one.

Sign in to keep reading

3 more chapters are free with a Lably account.

More in Basics