Signed zero is zero with an associated sign. In ordinary arithmetic, −0 = 0. However, in computing, some number representations allow for the existence of two zeros, often denoted by −0 (negative zero) and +0 (positive zero). This occurs in some signed number representations for integers, and in most floating point number representations. The number 0 is usually encoded as +0, however it can be represented by either +0 and −0.
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. The zeroes can be considered as a variant of the extended real number line such that 1/−0 = −∞ and 1/+0 = +∞, division by zero is only undefined for ±0/±0.
Signed zero echoes the mathematical analysis concept of approaching 0 from below as a onesided 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,^{[1]}, in particular when computing with complex elementary functions.^{[2]} On the other hand, the concept of signed zero runs contrary to the general assumption made in most mathematical fields (and in most mathematics courses) that negative zero is the same thing as zero. Representations that allow negative zero can be a source of errors in programs, as software developers do not realize (or may forget) that, while the two zero representations behave as equal under numeric comparisons, they are different bit patterns and yield different results in some operations.
Contents 
The widely used two's complement encoding does not allow a negative zero. In a 1+7bit signandmagnitude representation for integers, negative zero is represented by the bit string 10000000. In an 8bit one's complement representation, negative zero is represented by the bit string 11111111. In both encodings, positive zero is represented by 00000000.
In IEEE
754 binary floating point numbers, 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, or −1.0*0.0
, or simply as
−0.0
.
In IEEE 754 and in IBM's General Decimal Arithmetic encoding specification, a floatingpoint representation that uses decimal arithmetic, negative zero is represented by an exponent being any valid exponent in the range for the encoding, the true significand being zero, and the sign bit being one.
The IEEE 754 floating point standard specifies the behavior of positive zero and negative zero under various operations. The outcome may depend on the current IEEE rounding mode settings.
Multiplication and division follow their usual rules for combining signs:
Addition and subtraction are handled specially if the values could cancel:
Because of negative zero (and only because of it), the
statements z = (x  y)
and z = (x) 
(y)
, for floatingpoint variables x
,
y
, and z
, cannot be optimized to z
= y  x
.
Some other special rules:
According to the IEEE 754 standard, negative zero and positive
zero should compare as equal with the usual (numerical) comparison
operators, like the ==
operators of C and Java. In
those languages, special programming tricks may be needed to
distinguish the two values:
copysign()
function to copy the
sign of the zero to some nonzero number;However, some programming languages may provide alternative
comparison operators that do distinguish the two zeros. This is the
case, for example, of the equals method in Java's
Double
class.
Informally, one may use the notation "−0" for a negative value that was rounded to zero. This notation may be useful when a negative sign is significant; for example, when tabulating Celsius temperatures, where a negative sign means "below freezing".
In statistical mechanics, one sometimes uses negative absolute temperatures to describe systems with population inversion, which can be considered to have a temperature greater than positive infinity. In this context, a temperature of "negative zero" is a (theoretical) temperature larger than any other negative temperature, corresponding to the (theoretical) maximum conceivable extent of population inversion.
SIGN
function in Fortran 95 to accommodate negative
zero
