Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Division by zero
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Computer arithmetic== === Floating-point arithmetic === In computing, most numerical calculations are done with [[floating-point arithmetic]], which since the 1980s has been standardized by the [[IEEE 754]] specification. In IEEE floating-point arithmetic, numbers are represented using a sign (positive or negative), a fixed-precision [[significand]] and an integer [[exponent]]. Numbers whose exponent is too large to represent instead "overflow" to positive or negative [[infinity]] (+β or ββ), while numbers whose exponent is too small to represent instead "[[Arithmetic underflow|underflow]]" to [[signed zero|positive or negative zero]] (+0 or β0). A [[NaN]] (not a number) value represents undefined results. In IEEE arithmetic, division of 0/0 or β/β results in NaN, but otherwise division always produces a well-defined result. Dividing any non-zero number by positive zero (+0) results in an infinity of the same sign as the dividend. Dividing any non-zero number by [[negative zero]] (β0) results in an infinity of the opposite sign as the dividend. This definition preserves the sign of the result in case of [[arithmetic underflow]].<ref>{{citation|last=Cody|first=W. J.|title=Analysis of Proposals for the Floating-Point Standard|journal=Computer|date=March 1981 |volume=14|issue=3|pages=65|doi=10.1109/C-M.1981.220379|s2cid=9923085|quote=With appropriate care to be certain that the algebraic signs are not determined by rounding error, the affine mode preserves order relations while fixing up overflow. Thus, for example, the reciprocal of a negative number which underflows is still negative.}}</ref> For example, using single-precision IEEE arithmetic, if {{nowrap|1=''x'' = β2<sup>β149</sup>}}, then ''x''/2 underflows to β0, and dividing 1 by this result produces 1/(''x''/2) = ββ. The exact result β2<sup>150</sup> is too large to represent as a single-precision number, so an infinity of the same sign is used instead to indicate overflow. === Integer arithmetic === [[File:TI86 Calculator DivByZero.jpg|thumb|Handheld calculators, such as this [[TI-86]], typically halt and display an error message after an attempt to divide by zero.]] [[Integer (computer science)|Integer]] division by zero is usually handled differently from floating point since there is no integer representation for the result. [[Central processing unit|CPUs]] differ in behavior: for instance [[x86]] processors trigger a [[Interrupt|hardware exception]], while [[PowerPC]] processors silently generate an incorrect result for the division and continue, and [[ARM architecture family|ARM]] processors can either cause a hardware exception or return zero.<ref>{{citation |title=Divide instructions |work=ARMv7-M Architecture Reference Manual |publisher=Arm Limited |url=https://developer.arm.com/documentation/ddi0403/d/Application-Level-Architecture/The-ARMv7-M-Instruction-Set/Data-processing-instructions/Divide-instructions |access-date=2024-06-12 |edition=Version D |year=2010 }}</ref> Because of this inconsistency between platforms, the [[C (programming language)|C]] and [[C++]] [[programming language]]s consider the result of dividing by zero [[undefined behavior]].<ref> {{cite conference |mode=cs2 |last1=Wang |first1=Xi |last2=Chen |first2=Haogang |last3=Cheung |first3=Alvin |last4=Jia |first4=Zhihao |last5=Zeldovich |first5=Nickolai |last6=Kaashoek |first6=M. Frans |contribution=Undefined behavior: what happened to my code? |title=APSYS '12: Proceedings of the Asia-Pacific Workshop on Systems |conference=APSYS '12, Seoul, 23β24 July 2012 |location=New York |publisher=Association for Computing Machinery |isbn=978-1-4503-1669-9 |doi=10.1145/2349896.2349905 |doi-access=free |hdl=1721.1/86949|hdl-access=free }}</ref> In typical [[high-level programming language|higher-level programming languages]], such as [[Python (programming language)|Python]],<ref>{{citation |title=Python 3 Library Reference |chapter=Built-in Exceptions |chapter-url=https://docs.python.org/3/library/exceptions.html#ZeroDivisionError |publisher=Python Software Foundation |at=Β§ "Concrete exceptions β exception <code>ZeroDivisionError</code>" |access-date=2024-01-22 }}</ref> an [[Exception handling (programming)|exception]] is raised for attempted division by zero, which can be handled in another part of the program. === In proof assistants === Many [[proof assistant]]s, such as [[Rocq (software)|Rocq]] (previously known as ''Coq'') and [[Lean (proof assistant)|Lean]], define 1/0 = 0. This is due to the requirement that all functions are [[Total functional programming|total]]. Such a definition does not create contradictions, as further manipulations (such as [[cancelling out]]) still require that the divisor is non-zero.<ref>{{cite conference |mode=cs2 |last1=Tanter |first1=Γric |last2=Tabareau |first2=Nicolas |title=Gradual certified programming in coq |year=2015 |publisher=Association for Computing Machinery |book-title=DLS 2015: Proceedings of the 11th Symposium on Dynamic Languages |doi=10.1145/2816707.2816710 |quote=The standard division function on natural numbers in Coq, div, is total and pure, but incorrect: when the divisor is 0, the result is 0.|arxiv=1506.04205 }}</ref><ref>{{citation |last1=Buzzard |first1=Kevin |title=Division by zero in type theory: a FAQ |type=Blog |url=https://xenaproject.wordpress.com/2020/07/05/division-by-zero-in-type-theory-a-faq/ |website=Xena Project |date=5 July 2020 |access-date=2024-01-21}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)