Signed zero

Signed zero is zero with an associated sign. In ordinary arithmetic, the number 0 does not have a sign, so that −0, +0 and 0 are equivalent. However, in computing, 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-magnitude and ones' complement signed number representations for integers, and in most floating-point number representations. The number 0 is usually encoded as +0, but can still be represented by +0, −0, or 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. Real arithmetic with signed zeros can be considered a variant of the extended real number line such that 1/−0 = −∞ and 1/+0 = +∞; division is undefined only for ±0/±0 and ±∞/±∞.

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,[1] in particular when computing with complex elementary functions.[2] 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 10000000. In an 8-bit ones' complement representation, negative zero is represented by the bit string 11111111. In all these three encodings, positive or unsigned zero is represented by 00000000. 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.

Negative zero by IEEE 754 representation in binary32

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.

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 settings.

Notation

In systems that include both signed and unsigned zeros, the notation and 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:

  • (for different from ±∞)
  • (for different from 0)

There are special rules for adding or subtracting signed zero:

  • (for different from 0)
  • (for any finite , −0 when rounding toward negative)

Because of negative zero (and also when the rounding mode is upward or downward), the expressions −(xy) and (−x) − (−y), for floating-point variables x and y, cannot be replaced by yx. However (−0) + x can be replaced by x with rounding to nearest (except when x can be a signaling NaN).

Some other special rules:

  • [3]
  • (follows the sign rule for division)
  • (for non-zero , follows the sign rule for division)
  • (Not a Number or interrupt for indeterminate form)

Division of a non-zero number by zero sets the divide by zero flag, and an operation producing a NaN sets the invalid operation flag. An exception handler 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. In those languages, special programming tricks may be needed to distinguish the two values:

  • Type punning 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 exception is not trapped).

Note: Casting 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 equals method in Java's Double wrapper class.[4]

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 temperatures, where a negative sign means below freezing.

In statistical mechanics

In statistical mechanics, one sometimes uses negative temperatures to describe systems with population inversion, 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.[5]

See also

References

  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, p. 10.
  3. ^ Cowlishaw, Mike (7 April 2009). "Decimal Arithmetic: Arithmetic operations – square-root". speleotrove.com (IBM Corporation). Retrieved 7 December 2010.
  4. ^ "Double". Java™ Platform, Standard Edition 6 API Specification. Oracle Help Center. Archived from the original on Aug 4, 2009.
  5. ^ Kittel, Charles and Herbert Kroemer (1980). Thermal Physics (2nd ed.). W. H. Freeman and Company. p. 462. ISBN 0-7167-1088-9.

Further reading

Read other articles:

Marquard Sebastian Schenk von Stauffenberg Marquard Sebastian Schenk von Stauffenberg (* 14. Mai 1644; † 9. Oktober 1693) war von 1683 bis 1693 Fürstbischof von Bamberg. Er entstammte dem schwäbischen Geschlecht der Schenken von Stauffenberg und war Domherr von Bamberg, Würzburg und Augsburg. Leben und Wirken Marquard Sebastian Schenk von Stauffenberg wurde unter Papst Innozenz XI. und Kaiser Leopold I. im Jahr 1683 zum Fürstbischof von Bamberg gewählt. Er war auch Domkantor in Bamberg...

 

Переписна місцевість Те-Галіна-Терріторангл. The Galena Territory Файл:GTA Galena Territory Logo.png Координати 42°23′35″ пн. ш. 90°19′32″ зх. д. / 42.39330000002777865° пн. ш. 90.32580000002778320° зх. д. / 42.39330000002777865; -90.32580000002778320Координати: 42°23′35″ пн. ш. 90°19′32″ зх. д. / &#x...

 

اتفاقية فيينا بشأن حركة المرور على الطرقمعلومات عامةالنوع معاهدة الإيداع أمين عام الأمم المتحدة اللغة  القائمة ... الإنجليزية — الإسبانية — الصينية — الروسية — الفرنسية تعديل - تعديل مصدري - تعديل ويكي بيانات اتفاقية فيينا بشأن حركة المرور على الطرق هي معاهدة دولية تهد...

Belo Polje Бело ПољеKotaCountrySerbiaDistrikDistrik PčinjaKotamadyaSurdulicaPopulasi (2002)[1] • Total545Zona waktuUTC+1 (CET) • Musim panas (DST)UTC+2 (CEST) Belo Polje (Serbian Cyrillic : Бело Поље) adalah sebuah kota di Serbia. Terletak di kotamadya Surdulica, di Distrik Pčinja. Jumlah penduduk kota adalah 545 jiwa (sensus 2002). Referensi ^ 2011 Census of Population, Households and Dwellings in the Republic of Serbia: Comparative...

 

International sporting eventBoxing at the 1975 Pan American Games«1971 1979» The Men's Boxing Tournament at the 1975 Pan American Games was held in Mexico City, Mexico, from October 12 to October 26. Medal winners Event Gold Silver Bronze Light Flyweight(– 48 kilograms) Jorge HernándezCuba Miguel MercedesDominican Republic Reinaldo BecerraVenezuela Arturo UrruzquietaMexico Flyweight(– 51 kilograms) Ramon DuvalonCuba Victor VinuesaEcuador Roberto EspinosaEl Salvador Alfredo Pér...

 

Pertempuran KeramaiaBagian dari Peperangan Romawi Timur-ArabPeta Pertempuran Armada Arab–Bizantium di laut Mediterania, Abad ke 7–11Tanggal746LokasiKeramaia, SiprusHasil Kemenangan Kekaisaran Romawi TimurPihak terlibat Kekaisaran Romawi Timur Kekhalifahan UmayyahTokoh dan pemimpin Strategos of the Cibyrrhaeots tidak diketahuiKekuatan tidak diketahui 30 kapal lbsPerangArab – Romawi TimurKonflik-konflik perdana Mu'tah Datsin Firadh Penaklukan Kaum Muslim atas Syam Qaryatain Busrah Ajnadai...

American subscription streaming TV service Not to be confused with Google TV (disambiguation). YouTube TVLogo used since 2017FoundedFebruary 28, 2017; 6 years ago (2017-02-28)Headquarters901 Cherry Avenue, San Bruno, California, United StatesArea servedUnited StatesOwnerAlphabet Inc.IndustryPay televisionServicesStreaming televisionParentGoogleURLtv.youtube.com/welcomeUsers 6,600,000 subscribers (as of August 1, 2023[update])[1] YouTube TV is an...

 

Thomas HammarbergPhoto: Bengt Oberger トマス・ハマーベリ(Thomas Hammarberg、1942年1月2日 - )は、スウェーデンの外交官、人権活動家 (Human rights activist) 。エルンシェルツビクの生まれ。 2006年4月1日から2012年3月31日まで、初代委員のアルバロ・ヒル=ロブレス (Álvaro Gil-Robles) の後任として、ストラスブールの欧州評議会の第2代人権委員を務めた。後任はラトビア国籍...

 

В Википедии есть статьи о других людях с такой фамилией, см. Рахимов.Батыр Рахимовузб. Botir Rahimov Имя при рождении Батыр Икрамжанович Рахимов Дата рождения 30 июня 1966(1966-06-30) (57 лет) Место рождения Коканд, Узбекская ССР, СССР Образование Государственный юридический университет...

Serbian banking and financial services company Not to be confused with OTP banka Srbija a.d., which merged into the bank in 2021. OTP Banka SrbijaOfficial logoNative nameОТП Банка СрбијаFormerlyVojvođanska banka (2019–2021)OTP banka Srbija (2007–2019)TypeJoint-stock companyIndustryFinance and insurancePredecessorNiška Banka a.d. NišZepter banka a.d. BeogradKulska banka a.d. Novi Sad(until 2017)Founded30 April 2021; 2 years ago (2021-04-30) (Current form)...

 

County in West Virginia, United States County in West VirginiaBarbour CountyCountyBarbour County Courthouse in PhilippiAudra State ParkAdalandPhilippi Covered Bridge FlagLocation of Tucker County in West VirginiaWest Virginia's location within the U.S.Coordinates: 39°08′N 80°00′W / 39.13°N 80°W / 39.13; -80Country United StatesState West VirginiaFoundedMarch 3, 1843Named forPhilip P. BarbourSeatPhilippiand largest city Government • County ...

 

2017 studio album by AcceptThe Rise of ChaosStudio album by AcceptReleased4 August 2017 (2017-08-04)Recorded2016–2017GenreHeavy metalLength46:18LabelNuclear BlastProducerAndy Sneap[1]Accept chronology Restless and Live(2017) The Rise of Chaos(2017) Too Mean to Die(2021) Singles from The Rise of Chaos The Rise of ChaosReleased: 2 June 2017 The Rise of Chaos is the 15th studio album by German heavy metal band Accept, released on 4 August 2017.[2] This is...

American filmmaker Caroline GiulianiBornCaroline Rose Giuliani1989 (age 33–34)New York City, New York, U.S.EducationHarvard University (AB)Political partyDemocraticParent(s)Rudy GiulianiDonna HanoverRelativesAndrew Giuliani (brother)WebsiteOfficial website Caroline Rose Giuliani[1] (born 1989) is an American filmmaker, political activist, and writer. She is the daughter of Rudy Giuliani, the former Mayor of New York City. Giuliani has received national media attention for p...

 

Dramatic poem written by Lord ByronFor other uses, see Manfred (disambiguation). 1817 first edition, John Murray, London. Scene from Byron's Manfred, by Thomas Cole, 1833 Manfred: A dramatic poem is a closet drama written in 1816–1817 by Lord Byron. It contains supernatural elements, in keeping with the popularity of the ghost story in England at the time. It is a typical example of a Gothic fiction. Byron commenced this work in late 1816, a few months after the famous ghost-story sessions ...

 

Romanian artistic gymnast Marian DrăgulescuPersonal informationFull nameMarian DrăgulescuNickname(s)The MoroccanCountry represented RomaniaBorn (1980-12-18) 18 December 1980 (age 42)Bucharest, RomaniaDisciplineMen's artistic gymnasticsLevelSenior internationalGymCSA Steaua BucureștiHead coach(es)Danuţ GrecuAssistant coach(es)Stefan GalEponymous skillsDrăgulescu (vault) Medal record Event 1st 2nd 3rd Olympic Games 0 1 2 World Championships 8 2 0 European Champions...

الدورى السعودى الممتاز 1982–83 البلد المملكه العربيه السعوديه  فئة المنافسه كورة القدم للرجال  الرياضه كورة قدم  الموسم 7  عدد المشاركين الفايز نادى الاتفاق  تعديل  الدورى السعودى الممتاز 1982–83 (بالانجليزى: Saudi Premier League 1982–83) هوا موسم رياضى فى كورة قدم اتعمل فى ...

 

  لمعانٍ أخرى، طالع أولاد موسى (توضيح). أولاد موسى تقسيم إداري البلد المغرب  الجهة فاس مكناس الإقليم تاونات الدائرة غفساي الجماعة القروية أورتزاغ المشيخة القصيل السكان التعداد السكاني 118 نسمة (إحصاء 2004)   • عدد الأسر 28 معلومات أخرى التوقيت ت ع م±00:00 (توقيت قياسي)[1...

 

В Википедии есть статьи о других людях с такой фамилией, см. Витковский; Витковский, Владимир. Владимир Константинович Витковский генерал-лейтенант Витковский Дата рождения 21 апреля (3 мая) 1885(1885-05-03) Место рождения Псков, Российская империя Дата смерти 18 января 1978(1978-01-18...

Đế quốc Sasan Tên bản ngữ Ērānshahr[1][2] 224–651 Derafsh Kaviani Simurgh Đế quốc Sassanid vào thời điểm cực thịnh năm 620 CN, dưới triều Khosrau II   Cương vực ban đầu   Lãnh thổ mà Khoraus II chiếm được trong cuộc chiến với Đông La Mã (602-628) Tổng quanThủ đô Istakhr (224–226)[3] Ctesiphon (226–637) Ngôn ngữ thông dụng Tiếng Ba Tư trung ...

 

XIX Torneo de Copa de Costa Rica 1947 Copa Gran Bretaña Sede Costa Rica Costa Rica Fecha 11 de mayo de 194726 de junio de 1947 Cantidad de equipos 8 Podio • Campeón• Subcampeón   Herediano Alajuelense En 1947 la Federación Costarricense de Fútbol organizó la edición 19 de los torneos de Copa de Costa Rica, con el nombre de Copa Gran Bretaña (tercer torneo de copa organizado con este nombre). El Herediano logró anexarse la Copa Gran Bretaña de esa temporada al vencer e...

 

Strategi Solo vs Squad di Free Fire: Cara Menang Mudah!