−0 (number)
   HOME

TheInfoList



OR:

Signed zero is
zero 0 (zero) is a number representing an empty quantity. In place-value notation Positional notation (or place-value notation, or positional numeral system) usually denotes the extension to any base of the Hindu–Arabic numeral system (or ...
with an associated
sign A sign is an object, quality, event, or entity whose presence or occurrence indicates the probable presence or occurrence of something else. A natural sign bears a causal relation to its object—for instance, thunder is a sign of storm, or me ...
. In ordinary arithmetic, the number 0 does not have a sign, so that −0, +0 and 0 are identical. However, in
computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes, and development of both hardware and software. Computing has scientific, e ...
, some number representations allow for the existence of two zeros, often denoted by −0 (negative zero) and +0 (positive zero), regarded as equal by the numerical comparison operations but with possible different behaviors in particular operations. This occurs in the ''
sign and magnitude In computing, signed number representations are required to encode negative numbers in binary number systems. In mathematics, negative numbers in any base are represented by prefixing them with a minus sign ("−"). However, in RAM or CPU regist ...
'' and ''
ones' complement The ones' complement of a binary number is the value obtained by inverting all the bits in the binary representation of the number (swapping 0s and 1s). The name "ones' complement" (''note this is possessive of the plural "ones", not of a sing ...
''
signed number representation In computing, signed number representations are required to encode negative numbers in binary number systems. In mathematics, negative numbers in any base are represented by prefixing them with a minus sign ("−"). However, in RAM or CPU regist ...
s for integers, and in most
floating-point number In computing, floating-point arithmetic (FP) is arithmetic that represents real numbers approximately, using an integer with a fixed precision, called the significand, scaled by an integer exponent of a fixed base. For example, 12.345 can be r ...
representations. The number 0 is usually encoded as +0, but can be represented by either +0 or −0. The
IEEE 754 The IEEE Standard for Floating-Point Arithmetic (IEEE 754) is a technical standard for floating-point arithmetic established in 1985 by the Institute of Electrical and Electronics Engineers (IEEE). The standard addressed many problems found i ...
standard for floating-point arithmetic (presently used by most computers and programming languages that support floating-point numbers) requires both +0 and −0. Real arithmetic with signed zeros can be considered a variant of the
extended real number line In mathematics, the affinely extended real number system is obtained from the real number system \R by adding two infinity elements: +\infty and -\infty, where the infinities are treated as actual numbers. It is useful in describing the algebra ...
such that 1/−0 = −
∞ The infinity symbol (\infty) is a mathematical symbol representing the concept of infinity. This symbol is also called a lemniscate, after the lemniscate curves of a similar shape studied in algebraic geometry, or "lazy eight", in the terminol ...
and 1/+0 = +∞;
division Division or divider may refer to: Mathematics *Division (mathematics), the inverse of multiplication *Division algorithm, a method for computing the result of mathematical division Military *Division (military), a formation typically consisting ...
is only
undefined Undefined may refer to: Mathematics * Undefined (mathematics), with several related meanings ** Indeterminate form, in calculus Computing * Undefined behavior, computer code whose behavior is not specified under certain conditions * Undefined v ...
for ±0/±0 and ±∞/±∞. Negatively signed zero echoes the
mathematical analysis Analysis is the branch of mathematics dealing with continuous functions, limit (mathematics), limits, and related theories, such as Derivative, differentiation, Integral, integration, measure (mathematics), measure, infinite sequences, series (m ...
concept of approaching 0 from below as a
one-sided limit In calculus, a one-sided limit refers to either one of the two limits of a function f(x) of a real variable x as x approaches a specified point either from the left or from the right. The limit as x decreases in value approaching a (x approaches ...
, 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 In physics, statistical mechanics is a mathematical framework that applies statistical methods and probability theory to large assemblies of microscopic entities. It does not assume or postulate any natural laws, but explains the macroscopic be ...
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 Complex commonly refers to: * Complexity, the behaviour of a system whose components interact in multiple ways so possible interactions are difficult to describe ** Complex system, a system composed of many components which may interact with each ...
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 Two's complement is a mathematical operation to reversibly convert a positive binary number into a negative binary number with equivalent (but negative) value, using the binary digit with the greatest place value (the leftmost bit in big- endian ...
encoding, zero is unsigned. In a 1+7-bit
sign-and-magnitude In computing, signed number representations are required to encode negative numbers in binary number systems. In mathematics, negative numbers in any base are represented by prefixing them with a minus sign ("−"). However, in RAM or CPU regist ...
representation for integers, negative zero is represented by the bit string . In an 8-bit
ones' complement The ones' complement of a binary number is the value obtained by inverting all the bits in the binary representation of the number (swapping 0s and 1s). The name "ones' complement" (''note this is possessive of the plural "ones", not of a sing ...
representation, negative zero is represented by the bit string . In all these three encodings, positive or unsigned zero is represented by . 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 The IEEE Standard for Floating-Point Arithmetic (IEEE 754) is a technical standard for floating-point arithmetic established in 1985 by the Institute of Electrical and Electronics Engineers (IEEE). The standard addressed many problems found i ...
formats or similar), described below. In IEEE 754 binary floating-point formats, zero values are represented by the biased exponent and
significand The significand (also mantissa or coefficient, sometimes also argument, or ambiguously fraction or characteristic) is part of a number in scientific notation or in floating-point representation, consisting of its significant digits. Depending on ...
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 The term arithmetic underflow (also floating point underflow, or just underflow) is a condition in a computer program where the result of a calculation is a number of more precise absolute value than the computer can actually represent in memory o ...
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.


Properties and handling

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 IEEE 754-1985 was an industry standard for representing floating-point numbers in computers, officially adopted in 1985 and superseded in 2008 by IEEE 754-2008, and then again in 2019 by minor revision IEEE 754-2019. During its 23 years, it was the ...
settings.


Notation

In systems that include both signed and unsigned zeros, the notation 0^+ and 0^- is sometimes used for signed zeros.


Arithmetic

Addition and multiplication are commutative, but there are some special rules that have to be followed, which mean the usual mathematical rules for algebraic simplification may not apply. The = sign below shows the obtained floating-point results (it is not the usual equality operator). The usual rule for signs is always followed when multiplying or dividing: * (-0) \cdot \left, x \ = -0\,\! (for x different from ±∞) * \frac = -0\,\! (for x different from 0) * (-0) \cdot (-0) = +0\,\! There are special rules for adding or subtracting signed zero: * x + (\pm 0) = x\,\! (for x different from 0) * (-0) + (-0) = (-0) - (+0) = -0\,\! * (+0) + (+0) = (+0) - (-0) = +0\,\! * x - x = x + (-x) = +0\,\! (for any finite x, −0 when rounding toward negative) Because of negative zero (and also when the rounding mode is upward or downward), the expressions and , for floating-point variables ''x'' and ''y'', cannot be replaced by . However can be replaced by ''x'' with rounding to nearest (except when ''x'' can be a signaling NaN). Some other special rules: * \left, -0 \ = +0\,\! * \sqrt = -0\,\! * \frac = +0\,\! (follows the sign rule for division) * \frac = -\infty\,\! (for non-zero x, follows the sign rule for division) * \times = \mbox\,\! (
Not a Number Nan or NAN may refer to: Places China * Nan County, Yiyang, Hunan, China * Nan Commandery, historical commandery in Hubei, China Thailand * Nan Province ** Nan, Thailand, the administrative capital of Nan Province * Nan River People Given name ...
or interrupt for
indeterminate form In calculus and other branches of mathematical analysis, limits involving an algebraic combination of functions in an independent variable may often be evaluated by replacing these functions by their limits; if the expression obtained after this su ...
) * \frac = \mbox\,\! Division of a non-zero number by zero sets the divide by zero
flag A flag is a piece of fabric (most often rectangular or quadrilateral) with a distinctive design and colours. It is used as a symbol, a signalling device, or for decoration. The term ''flag'' is also used to refer to the graphic design empl ...
, and an operation producing a NaN sets the invalid operation flag. An
exception handler In computing and computer programming, exception handling is the process of responding to the occurrence of ''exceptions'' – anomalous or exceptional conditions requiring special processing – during the Execution (computing), execution of a C ...
is called if enabled for the corresponding flag.


Comparisons

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 Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
. In those languages, special programming tricks may be needed to distinguish the two values: *
Type punning In computer science, a type punning is any programming technique that subverts or circumvents the type system of a programming language in order to achieve an effect that would be difficult or impossible to achieve within the bounds of the formal ...
the number to an integer type, so as to look at the sign bit in the bit pattern; * using the ISO C copysign() function (IEEE 754 copySign operation) to copy the sign of the zero to some non-zero number; * using the ISO C signbit() macro (IEEE 754 isSignMinus operation) that returns whether the sign bit of a number is set; * taking the reciprocal of the zero to obtain either 1/(+0) = +∞ or 1/(−0) = âˆ’∞ (if the
division by zero In mathematics, division by zero is division (mathematics), division where the divisor (denominator) is 0, zero. Such a division can be formally expression (mathematics), expressed as \tfrac, where is the dividend (numerator). In ordinary ari ...
exception is not trapped). Note:
Casting Casting is a manufacturing process in which a liquid material is usually poured into a mold, which contains a hollow cavity of the desired shape, and then allowed to solidify. The solidified part is also known as a ''casting'', which is ejected ...
to integral type will not always work, especially on two's complement systems. However, some programming languages may provide alternative comparison operators that do distinguish the two zeros. This is the case, for example, of the method in Java's Double
wrapper class In object-oriented programming, a wrapper class is a class (computer programming), class that Encapsulation (computer programming), encapsulates data type, types, so that those types can be used to create object (computer science), object instance ( ...
.


In rounded values such as temperatures

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 The degree Celsius is the unit of temperature on the Celsius scale (originally known as the centigrade scale outside Sweden), one of two temperature scales used in the International System of Units (SI), the other being the Kelvin scale. The ...
temperatures, where a negative sign means ''below freezing''.


In statistical mechanics

In
statistical mechanics In physics, statistical mechanics is a mathematical framework that applies statistical methods and probability theory to large assemblies of microscopic entities. It does not assume or postulate any natural laws, but explains the macroscopic be ...
, one sometimes uses
negative temperature Certain systems can achieve negative thermodynamic temperature; that is, their temperature can be expressed as a negative quantity on the Kelvin or Rankine scales. This should be distinguished from temperatures expressed as negative numbers ...
s to describe systems with
population inversion In science, specifically statistical mechanics, a population inversion occurs while a system (such as a group of atoms or molecules) exists in a state in which more members of the system are in higher, excited states than in lower, unexcited energ ...
, which can be considered to have a temperature greater than positive infinity, because the coefficient of energy in the population distribution function is −1/Temperature. In this context, a temperature of −0 is a (theoretical) temperature larger than any other negative temperature, corresponding to the (theoretical) maximum conceivable extent of population inversion, the opposite extreme to +0.


See also

*
Line with two origins In geometry and topology, it is a usual axiom of a manifold to be a Hausdorff space. In general topology, this axiom is relaxed, and one studies non-Hausdorff manifolds: spaces locally homeomorphic to Euclidean space, but not necessarily Hausdorff. ...
*
Extended real number line In mathematics, the affinely extended real number system is obtained from the real number system \R by adding two infinity elements: +\infty and -\infty, where the infinities are treated as actual numbers. It is useful in describing the algebra ...


References

* * * * a ''decimal'' floating-point specification that includes negative zero


Further reading

* the changes in the Fortran SIGN function in Fortran 95 to accommodate negative zero * JScript's floating-point type with negative zero by definition * representation of negative zero in the
Java virtual machine A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally describes ...
* how to handle negative zero when comparing floating-point numbers * one's complement numbers on the
UNIVAC UNIVAC (Universal Automatic Computer) was a line of electronic digital stored-program computers starting with the products of the Eckert–Mauchly Computer Corporation. Later the name was applied to a division of the Remington Rand company an ...
1100 family computers {{refend Computer arithmetic 0 (number)