Signed zero

from Wikipedia, the free encyclopedia
−0
+0

In mathematics and computer science, a signed zero is the number zero with an associated sign . In arithmetic , the number zero is neither positive nor negative and therefore has no sign. When it comes to machine numbers, however, +0 ( positive zero ) and −0 ( negative zero ) are often viewed as two different numbers. With the integer data type , the zero in the signed amount representation and with the one's complement is signed, with floating point numbers it is usually the case. The notation is also used in some applications when a negative number has been rounded to zero. The sign of the 0 is also important in infinitesimal calculus .

Representations

Representation of negative zero according to IEEE 754 in single precision

The two's complement that is often used to represent integers does not allow a signed zero, but this is possible in other representations. In the 1 + 7-bit signed amount representation, the negative zero is represented by the bit string 1000 0000. In the 8-bit one's complement , the negative zero is represented by 1111 1111. In all three representations, 0000 0000 stands for a positive zero.

In the IEEE 754 standard for binary floating point numbers , the mantissa and the exponent are zero for both cases of signed zero. The sign bit is set to 1 for the negative zero and to 0. A negative zero can occur through arithmetic underflow with a negative number, through arithmetic operations such as (−1.0)*0.0or through the use of −0.0.

In the IEEE 754-2008 standard for binary floating point number representation, a negative zero is represented by any valid exponent , a mantissa of zero and a sign bit with the value one.

properties

The IEEE 754 standard specifies the behavior of positive and negative zero for numerous operators , but the result also depends on the rounding method used . It is believed that the use of signed zero has helped to achieve higher numerical accuracy in some critical situations, especially with elementary complex functions . On the other hand, many programmers are unaware of the concept of a negative zero, which can lead to unexpected errors. While the two representations of zero are identical in numerical comparisons , they produce different results in some calculations and have different bit patterns .

arithmetic

Multiplication and division follow the usual rules of arithmetic:

  •   (for )

However, addition and subtraction are considered specifically depending on whether values ​​cancel each other out:

  •   (for finite ; when rounded to negative)

Due to the negative zero may equations and for floating-point , and not to be optimized. It is defined as a special case .

Comparison operators

According to the IEEE 754 standard, numerical comparison operators like == in C or Java should regard positive and negative zero as the same. In these cases, the positive and negative zero can be distinguished in the following ways:

  • Type conversions of the number to an integer to compare the bits of the number representation. This does not work with the representation in two's complement .
  • Copying of the sign by the IEEE 754 standardized function copysign()to a number not equal to zero.
  • Calculating the reciprocal gives either or . The signed zeros can thus be viewed as a variant of the extended real numbers . A division by zero is then only for and indefinite , ARISING most NaN .

Some programming languages ​​have alternative comparison operators so that one can distinguish between the two signed zeros. For example, in Java this is the case with the equalsmethod of the Doubleclass.

Use in science

In the scientific environment, the notation is used for a negative number that has been rounded to zero. In some cases, the negative sign is decisive; for temperatures given in Celsius , a negative zero means, for example, a temperature below the freezing point of water.

In statistical mechanics , negative temperatures are sometimes used as a computational aid to describe population inversions . In this context, the temperature −0 is greater than any other temperature and the opposite of +0. The temperature scale from cold to hot is then +0 K, ..., +300 K, ..., + ∞ K, −∞ K, ..., −300 K, ..., −0 K.

literature

Individual evidence

  1. ^ William Kahan , "Branch Cuts for Complex Elementary Functions, or Much Ado About Nothing's Sign Bit," in The State of the Art in Numerical Analysis (eds. Iserles and Powell), Clarendon Press, Oxford, 1987.
  2. William Kahan , Derivatives in the Complex z-plane (PDF; 68 kB), page 10
  3. ^ Mike Cowlishaw : Decimal Arithmetic: Arithmetic operations - square-root . speleotrove.com ( IBM Corporation ). April 7, 2009. Retrieved June 27, 2013.
  4. Java 7 documentation. Retrieved July 27, 2013
  5. ^ Charles Kittel and Herbert Kroemer : Thermal Physics (2nd ed.) . WH Freeman Company, 1980, ISBN 0-7167-1088-9 , p. 462.