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
Floating-point arithmetic
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!
{{Redirect|Floating point}} {{Short description|Computer approximation for real numbers}} {{Use dmy dates|date=May 2019|cs1-dates=y}} [[File:Z3 Deutsches Museum.JPG|thumb|200px|An early electromechanical programmable computer, the [[Z3 (computer)|Z3]], included floating-point arithmetic (replica on display at [[Deutsches Museum]] in [[Munich]]).]] {{Floating-point}} In [[computing]], '''floating-point arithmetic''' ('''FP''') is [[arithmetic]] on subsets of [[real number]]s formed by a ''[[significand]]'' (a [[Sign (mathematics)|signed]] sequence of a fixed number of digits in some [[Radix|base]]) multiplied by an [[integer power]] of that base. Numbers of this form are called '''floating-point numbers'''.<ref name="Muller_2010"/>{{rp|3}}<ref name="sterbenz1974fpcomp">{{cite book |last1=Sterbenz |first1=Pat H. |title=Floating-Point Computation |date=1974 |publisher=Prentice-Hall |location=Englewood Cliffs, NJ, United States |isbn=0-13-322495-3 |url=https://archive.org/details/SterbenzFloatingPointComputation/mode/2up}}</ref>{{rp|10}} For example, the number 2469/200 is a floating-point number in base ten with five digits: <math display=block>2469/200 = 12.345 = \! \underbrace{12345}_\text{significand} \! \times \! \underbrace{10}_\text{base}\!\!\!\!\!\!\!\overbrace{{}^{-3}}^{\text{exponent}}</math> However, 7716/625 = 12.3456 is not a floating-point number in base ten with five digits—it needs six digits. The nearest floating-point number with only five digits is 12.346. And 1/3 = 0.3333… is not a floating-point number in base ten with any finite number of digits. In practice, most floating-point systems use [[Binary number|base two]], though base ten ([[decimal floating point]]) is also common. Floating-point arithmetic operations, such as addition and division, approximate the corresponding real number arithmetic operations by [[rounding]] any result that is not a floating-point number itself to a nearby floating-point number.<ref name="Muller_2010"/>{{rp|22}}<ref name="sterbenz1974fpcomp"/>{{rp|10}} For example, in a floating-point arithmetic with five base-ten digits, the sum 12.345 + 1.0001 = 13.3451 might be rounded to 13.345. The term ''floating point'' refers to the fact that the number's [[radix point]] can "float" anywhere to the left, right, or between the [[significant digits]] of the number. This position is indicated by the exponent, so floating point can be considered a form of [[scientific notation]]. A floating-point system can be used to represent, with a fixed number of digits, numbers of very different [[Orders of magnitude (numbers)|orders of magnitude]] — such as the number of meters [[Orders of magnitude (length)#100_zettametres|between galaxies]] or [[Orders of magnitude (length)#10_femtometres|between protons in an atom]]. For this reason, floating-point arithmetic is often used to allow very small and very large real numbers that require fast processing times. The result of this [[dynamic range]] is that the numbers that can be represented are not uniformly spaced; the difference between two consecutive representable numbers varies with their exponent.<ref name="Smith_1997"/> [[File:A number line representing single-precision floating point's numbers and numbers that it cannot display.png|500x500px|thumb|right|Single-precision floating-point numbers on a [[number line]]: the green lines mark representable values.]] [[File:FloatingPointPrecisionAugmented.png|500x500px|thumb|right|Augmented version above showing both [[Signed number representations|signs]] of representable values]] Over the years, a variety of floating-point representations have been used in computers. In 1985, the [[IEEE 754]] Standard for Floating-Point Arithmetic was established, and since the 1990s, the most commonly encountered representations are those defined by the IEEE. The speed of floating-point operations, commonly measured in terms of [[FLOPS]], is an important characteristic of a [[computer system]], especially for applications that involve intensive mathematical calculations. A [[floating-point unit]] (FPU, colloquially a math [[coprocessor]]) is a part of a computer system specially designed to carry out operations on floating-point numbers. == Overview == === Floating-point numbers === A [[number representation]] specifies some way of encoding a number, usually as a string of digits. There are several mechanisms by which strings of digits can represent numbers. In standard mathematical notation, the digit string can be of any length, and the location of the [[radix point]] is indicated by placing an explicit [[Decimal separator|"point" character]] (dot or comma) there. If the radix point is not specified, then the string implicitly represents an [[integer]] and the unstated radix point would be off the right-hand end of the string, next to the least significant digit. In [[fixed-point arithmetic|fixed-point]] systems, a position in the string is specified for the radix point. So a fixed-point scheme might use a string of 8 decimal digits with the decimal point in the middle, whereby "00012345" would represent 0001.2345. In [[scientific notation]], the given number is scaled by a [[power of 10]], so that it lies within a specific range—typically between 1 and 10, with the radix point appearing immediately after the first digit. As a power of ten, the scaling factor is then indicated separately at the end of the number. For example, the orbital period of [[Jupiter]]'s moon [[Io (moon)|Io]] is {{val|152853.5047|fmt=commas}} seconds, a value that would be represented in standard-form scientific notation as {{val|1.528535047|e=5|fmt=commas}} seconds. Floating-point representation is similar in concept to scientific notation. Logically, a floating-point number consists of: * A signed (meaning positive or negative) digit string of a given length in a given [[radix]] (or base). This digit string is referred to as the ''[[significand]]'', ''mantissa'', or ''coefficient''.<ref group="nb" name="NB_Significand"/> The length of the significand determines the ''precision'' to which numbers can be represented. The radix point position is assumed always to be somewhere within the significand—often just after or just before the most significant digit, or to the right of the rightmost (least significant) digit. This article generally follows the convention that the radix point is set just after the most significant (leftmost) digit. * A signed integer [[exponent]] (also referred to as the ''characteristic'', or ''scale''),<ref group="nb" name="NB_Exponent"/> which modifies the magnitude of the number. To derive the value of the floating-point number, the ''significand'' is multiplied by the ''base'' raised to the power of the ''exponent'', equivalent to shifting the radix point from its implied position by a number of places equal to the value of the exponent—to the right if the exponent is positive or to the left if the exponent is negative. Using base-10 (the familiar [[Decimal representation|decimal]] notation) as an example, the number {{val|152853.5047|fmt=commas}}, which has ten decimal digits of precision, is represented as the significand {{val|1528535047|fmt=commas}} together with 5 as the exponent. To determine the actual value, a decimal point is placed after the first digit of the significand and the result is multiplied by {{10^|5}} to give {{val|1.528535047|e=5|fmt=commas}}, or {{val|152853.5047|fmt=commas}}. In storing such a number, the base (10) need not be stored, since it will be the same for the entire range of supported numbers, and can thus be inferred. Symbolically, this final value is: <math display=block>\frac{s}{b^{\,p-1}} \times b^e,</math> where {{mvar|s}} is the significand (ignoring any implied decimal point), {{mvar|p}} is the precision (the number of digits in the significand), {{mvar|b}} is the base (in our example, this is the number ''ten''), and {{mvar|e}} is the exponent. {{anchor|Base-4|Base-8|Base-256|Base-65536}}Historically, several number bases have been used for representing floating-point numbers, with base two ([[Binary numeral system|binary]]) being the most common, followed by base ten ([[decimal floating point]]), and other less common varieties, such as base sixteen ([[hexadecimal floating point]]<ref name="Zehendner_2008"/><ref name="Beebe_2017"/><ref group="nb" name="NB_9"/>), base eight (octal floating point<ref name="Muller_2010"/><ref name="Beebe_2017"/><ref name="Savard_2018"/><ref name="Zehendner_2008"/><ref group="nb" name="NB_8"/>), base four (quaternary floating point<ref name="Parkinson_2000"/><ref name="Beebe_2017"/><ref group="nb" name="NB_11"/>), base three ([[balanced ternary floating point]]<ref name="Muller_2010"/>) and even base 256<ref name="Beebe_2017"/><ref group="nb" name="NB_12"/> and base {{val|65536|fmt=commas}}.<ref name="Lazarus_1956"/><ref group="nb" name="NB_10"/> A floating-point number is a [[rational number]], because it can be represented as one integer divided by another; for example {{val|1.45|e=3}} is (145/100)×1000 or {{val|145000|fmt=commas}}/100. The base determines the fractions that can be represented; for instance, 1/5 cannot be represented exactly as a floating-point number using a binary base, but 1/5 can be represented exactly using a decimal base ({{val|0.2}}, or {{val|2|e=-1}}). However, 1/3 cannot be represented exactly by either binary (0.010101...) or decimal (0.333...), but in [[ternary numeral system|base 3]], it is trivial (0.1 or 1×3<sup>−1</sup>) . The occasions on which infinite expansions occur [[positional notation#Infinite representations|depend on the base and its prime factors]]. <!-- Note: The following text contains information about how a number can be rounded to nearest. Such information may come too early in this article. Then, it could be more detailed: rounding can yield an increase of the exponent, and a possible overflow. Moreover, in general, one does not necessarily know the first N bits of a number, but just an approximation (this is not equivalent when the Table maker's dilemma occurs). Thus the text below might be misleading. --> The way in which the significand (including its sign) and exponent are stored in a computer is implementation-dependent. The common IEEE formats are described in detail later and elsewhere, but as an example, in the binary single-precision (32-bit) floating-point representation, <math>p = 24</math>, and so the significand is a string of 24 [[bit]]s. For instance, the number [[Pi|π]]'s first 33 bits are: <math display=block>11001001\ 00001111\ 1101101\underline{0}\ 10100010\ 0.</math> In this binary expansion, let us denote the positions from 0 (leftmost bit, or most significant bit) to 32 (rightmost bit). The 24-bit significand will stop at position 23, shown as the underlined bit {{val|0}} above. The next bit, at position 24, is called the ''round bit'' or ''rounding bit''. It is used to round the 33-bit approximation to the nearest 24-bit number (there are [[rounding#Tie-breaking|specific rules for halfway values]], which is not the case here). This bit, which is {{val|1=1}} in this example, is added to the integer formed by the leftmost 24 bits, yielding: <math display=block>11001001\ 00001111\ 1101101\underline{1}.</math> When this is stored in memory using the IEEE 754 encoding, this becomes the [[significand]] {{mvar|s}}. The significand is assumed to have a binary point to the right of the leftmost bit. So, the binary representation of π is calculated from left-to-right as follows: <math display=block>\begin{align} &\left(\sum_{n=0}^{p-1} \text{bit}_n \times 2^{-n}\right) \times 2^e \\ ={} &\left(1 \times 2^{-0} + 1 \times 2^{-1} + 0 \times 2^{-2} + 0 \times 2^{-3} + 1 \times2^{-4} + \cdots + 1 \times 2^{-23}\right) \times 2^1 \\ \approx{} &1.57079637 \times 2 \\ \approx{} &3.1415927 \end{align}</math><!-- Ensure correct rounding by taking one more digit for the intermediate decimal approximation. --> where {{mvar|p}} is the precision ({{val|24}} in this example), {{mvar|n}} is the position of the bit of the significand from the left (starting at {{val|0}} and finishing at {{val|23}} here) and {{mvar|e}} is the exponent ({{val|1=1}} in this example). {{anchor|Hidden bit}}It can be required that the most significant digit of the significand of a non-zero number be non-zero (except when the corresponding exponent would be smaller than the minimum one). This process is called ''normalization''. For binary formats (which uses only the digits {{val|0}} and {{val|1=1}}), this non-zero digit is necessarily {{val|1}}. Therefore, it does not need to be represented in memory, allowing the format to have one more bit of precision. This rule is variously called the ''leading bit convention'', the ''implicit bit convention'', the ''hidden bit convention'',<ref name="Muller_2010"/> or the ''assumed bit convention''. === Alternatives to floating-point numbers === The floating-point representation is by far the most common way of representing in computers an approximation to real numbers. However, there are alternatives: * [[Fixed-point arithmetic|Fixed-point]] representation uses integer hardware operations controlled by a software implementation of a specific convention about the location of the binary or decimal point, for example, 6 bits or digits from the right. The hardware to manipulate these representations is less costly than floating point, and it can be used to perform normal integer operations, too. Binary fixed point is usually used in special-purpose applications on embedded processors that can only do integer arithmetic, but decimal fixed point is common in commercial applications. * [[Logarithmic number system]]s (LNSs) represent a real number by the logarithm of its absolute value and a sign bit. The value distribution is similar to floating point, but the value-to-representation curve (''i.e.'', the graph of the logarithm function) is smooth (except at 0). Conversely to floating-point arithmetic, in a logarithmic number system multiplication, division and exponentiation are simple to implement, but addition and subtraction are complex. The ([[symmetric level-index arithmetic|symmetric]]) [[level-index arithmetic]] (LI and SLI) of Charles Clenshaw, [[Frank William John Olver|Frank Olver]] and Peter Turner is a scheme based on a [[generalized logarithm]] representation. * [[Tapered floating-point representation]], used in [[Unum (number format)|Unum]]. * Some simple rational numbers (''e.g.'', 1/3 and 1/10) cannot be represented exactly in binary floating point, no matter what the precision is. Using a different radix allows one to represent some of them (''e.g.'', 1/10 in decimal floating point), but the possibilities remain limited. Software packages that perform [[fraction|rational arithmetic]] represent numbers as fractions with integral numerator and denominator, and can therefore represent any rational number exactly. Such packages generally need to use "[[bignum]]" arithmetic for the individual integers. * [[Interval arithmetic]] allows one to represent numbers as intervals and obtain guaranteed bounds on results. It is generally based on other arithmetics, in particular floating point. * [[Computer algebra system]]s such as [[Mathematica]], [[Maxima (software)|Maxima]], and [[Maple (software)|Maple]] can often handle irrational numbers like <math>\pi</math> or <math>\sqrt{3}</math> in a completely "formal" way ([[symbolic computation]]), without dealing with a specific encoding of the significand. Such a program can evaluate expressions like "<math>\sin (3\pi)</math>" exactly, because it is programmed to process the underlying mathematics directly, instead of using approximate values for each intermediate calculation. == History == {{see also|IEEE 754#History}} [[File:Quevedo 1917.jpg|thumb|upright=0.7|[[Leonardo Torres Quevedo]], in 1914, published an analysis of floating point based on the [[analytical engine]].]] In 1914, the Spanish engineer [[Leonardo Torres Quevedo]] published ''Essays on Automatics'',<ref>Torres Quevedo, Leonardo. [https://quickclick.es/rop/pdf/publico/1914/1914_tomoI_2043_01.pdf Automática: Complemento de la Teoría de las Máquinas, (pdf)], pp. 575–583, Revista de Obras Públicas, 19 November 1914.</ref> where he designed a special-purpose electromechanical calculator based on [[Charles Babbage]]'s [[analytical engine]] and described a way to store floating-point numbers in a consistent manner. He stated that numbers will be stored in exponential format as ''n'' × 10<math>^m</math>, and offered three rules by which consistent manipulation of floating-point numbers by machines could be implemented. For Torres, "''n'' will always be the same number of [[Numerical digit|digits]] (e.g. six), the first digit of ''n'' will be of order of tenths, the second of hundredths, etc, and one will write each quantity in the form: ''n''; ''m''." The format he proposed shows the need for a fixed-sized significand as is presently used for floating-point data, fixing the location of the decimal point in the significand so that each representation was unique, and how to format such numbers by specifying a syntax to be used that could be entered through a [[typewriter]], as was the case of his [[Leonardo Torres y Quevedo#Analytical machines|Electromechanical Arithmometer]] in 1920.<ref>Ronald T. Kneusel. ''[https://books.google.com/books?id=eq4ZDgAAQBAJ&dq=leonardo+torres+quevedo++electromechanical+machine+essays&pg=PA84 Numbers and Computers],'' Springer, pp. 84–85, 2017. {{ISBN|978-3319505084}}</ref>{{Sfn|Randell|1982|pp=6, 11–13}}<ref>Randell, Brian. [https://dl.acm.org/doi/pdf/10.5555/1074100.1074334 Digital Computers, History of Origins, (pdf)], p. 545, Digital Computers: Origins, Encyclopedia of Computer Science, January 2003.</ref> [[File:Konrad Zuse (1992).jpg|thumb|upright=0.7|right|[[Konrad Zuse]], architect of the [[Z3 (computer)|Z3]] computer, which uses a 22-bit binary floating-point representation]] In 1938, [[Konrad Zuse]] of Berlin completed the [[Z1 (computer)|Z1]], the first binary, programmable [[mechanical computer]];<ref name="Rojas_1997"/> it uses a 24-bit binary floating-point number representation with a 7-bit signed exponent, a 17-bit significand (including one implicit bit), and a sign bit.<ref name="Rojas_2014"/> The more reliable [[relay]]-based [[Z3 (computer)|Z3]], completed in 1941, has representations for both positive and negative infinities; in particular, it implements defined operations with infinity, such as <math>^1/_\infty = 0</math>, and it stops on undefined operations, such as <math>0 \times \infty</math>. Zuse also proposed, but did not complete, carefully rounded floating-point arithmetic that includes <math>\pm\infty</math> and NaN representations, anticipating features of the IEEE Standard by four decades.<ref name="Kahan_1997_JVNL"/> In contrast, [[John von Neumann|von Neumann]] recommended against floating-point numbers for the 1951 [[IAS machine]], arguing that fixed-point arithmetic is preferable.<ref name="Kahan_1997_JVNL"/> The first ''commercial'' computer with floating-point hardware was Zuse's [[Z4 (computer)|Z4]] computer, designed in 1942–1945. In 1946, Bell Laboratories introduced the [[Model V|Model V]], which implemented [[decimal floating point|decimal floating-point numbers]].<ref name="Randell_1982_2"/> The [[Pilot ACE]] has binary floating-point arithmetic, and it became operational in 1950 at [[National Physical Laboratory, UK]]. Thirty-three were later sold commercially as the [[English Electric DEUCE]]. The arithmetic is actually implemented in software, but with a one megahertz clock rate, the speed of floating-point and fixed-point operations in this machine were initially faster than those of many competing computers. The mass-produced [[IBM 704]] followed in 1954; it introduced the use of a [[Exponent bias|biased exponent]]. For many decades after that, floating-point hardware was typically an optional feature, and computers that had it were said to be "scientific computers", or to have "[[scientific computation]]" (SC) capability (see also [[Extensions for Scientific Computation]] (XSC)). It was not until the launch of the Intel i486 in 1989 that ''general-purpose'' personal computers had floating-point capability in hardware as a standard feature. The [[UNIVAC 1100/2200 series]], introduced in 1962, supported two floating-point representations: * ''Single precision'': 36 bits, organized as a 1-bit sign, an 8-bit exponent, and a 27-bit significand. * ''Double precision'': 72 bits, organized as a 1-bit sign, an 11-bit exponent, and a 60-bit significand. The [[IBM 7094]], also introduced in 1962, supported single-precision and double-precision representations, but with no relation to the UNIVAC's representations. Indeed, in 1964, IBM introduced [[IBM hexadecimal floating-point|hexadecimal floating-point representations]] in its [[System/360]] mainframes; these same representations are still available for use in modern [[z/Architecture]] systems. In 1998, IBM implemented IEEE-compatible binary floating-point arithmetic in its mainframes; in 2005, IBM also added IEEE-compatible decimal floating-point arithmetic. Initially, computers used many different representations for floating-point numbers. The lack of standardization at the mainframe level was an ongoing problem by the early 1970s for those writing and maintaining higher-level source code; these manufacturer floating-point standards differed in the word sizes, the representations, and the rounding behavior and general accuracy of operations. Floating-point compatibility across multiple computing systems was in desperate need of standardization by the early 1980s, leading to the creation of the [[IEEE 754]] standard once the 32-bit (or 64-bit) [[Word (computer architecture)|word]] had become commonplace. This standard was significantly based on a proposal from Intel, which was designing the [[Intel 8087|i8087]] numerical coprocessor; Motorola, which was designing the [[68000]] around the same time, gave significant input as well. [[File:William Kahan 2008.jpg|thumb|upright=0.7|right|[[William Kahan]], principal architect of the [[IEEE 754]] floating-point standard]] In 1989, mathematician and computer scientist [[William Kahan]] was honored with the [[Turing Award]] for being the primary architect behind this proposal; he was aided by his student Jerome Coonen and a visiting professor, [[Harold S. Stone|Harold Stone]].<ref name="Severance_1998"/> Among the x86 innovations are these: * A precisely specified floating-point representation at the bit-string level, so that all compliant computers interpret bit patterns the same way. This makes it possible to accurately and efficiently transfer floating-point numbers from one computer to another (after accounting for [[endianness]]). * A precisely specified behavior for the arithmetic operations: A result is required to be produced as if infinitely precise arithmetic were used to yield a value that is then rounded according to specific rules. This means that a compliant computer program would always produce the same result when given a particular input, thus mitigating the almost mystical reputation that floating-point computation had developed for its hitherto seemingly non-deterministic behavior. * The ability of [[IEEE 754#Exception handling|exceptional conditions]] (overflow, [[Division by zero|divide by zero]], etc.) to propagate through a computation in a benign manner and then be handled by the software in a controlled fashion. == Range of floating-point numbers == A floating-point number consists of two [[Fixed-point arithmetic|fixed-point]] components, whose range depends exclusively on the number of bits or digits in their representation. Whereas components linearly depend on their range, the floating-point range linearly depends on the significand range and exponentially on the range of exponent component, which attaches outstandingly wider range to the number. On a typical computer system, a ''[[Double-precision floating-point format|double-precision]]'' (64-bit) binary floating-point number has a coefficient of 53 bits (including 1 implied bit), an exponent of 11 bits, and 1 sign bit. Since 2<sup>10</sup> = 1024, the complete range of the positive normal floating-point numbers in this format is from 2<sup>−1022</sup> ≈ 2 × 10<sup>−308</sup> to approximately 2<sup>1024</sup> ≈ 2 × 10<sup>308</sup>. The number of normal floating-point numbers in a system (''B'', ''P'', ''L'', ''U'') where * ''B'' is the base of the system, * ''P'' is the precision of the significand (in base ''B''), * ''L'' is the smallest exponent of the system, * ''U'' is the largest exponent of the system, is <math>2 \left(B - 1\right) \left(B^{P-1}\right) \left(U - L + 1\right)</math>. There is a smallest positive normal floating-point number, : Underflow level = UFL = <math>B^L</math>, which has a 1 as the leading digit and 0 for the remaining digits of the significand, and the smallest possible value for the exponent. There is a largest floating-point number, : Overflow level = OFL = <math>\left(1 - B^{-P}\right)\left(B^{U + 1}\right)</math>, which has ''B'' − 1 as the value for each digit of the significand and the largest possible value for the exponent. In addition, there are representable values strictly between −UFL and UFL. Namely, [[signed zero|positive and negative zeros]], as well as [[subnormal number]]s. == IEEE 754: floating point in modern computers {{anchor|IEEE 754}} == {{Main|IEEE 754}} {{Floating-point}} The [[Institute of Electrical and Electronics Engineers|IEEE]] standardized the computer representation for binary floating-point numbers in [[IEEE 754]] (a.k.a. IEC 60559) in 1985. This first standard is followed by almost all modern machines. It was [[IEEE 754-2008 revision|revised in 2008]]. IBM mainframes support [[IBM hexadecimal floating point|IBM's own hexadecimal floating point format]] and IEEE 754-2008 [[decimal floating point]] in addition to the IEEE 754 binary format. The [[Cray T90]] series had an IEEE version, but the [[Cray SV1|SV1]] still uses Cray floating-point format.{{Citation needed|date=July 2020}} The standard provides for many closely related formats, differing in only a few details. Five of these formats are called ''basic formats'', and others are termed ''extended precision formats'' and ''extendable precision format''. Three formats are especially widely used in computer hardware and languages:{{Citation needed|reason=Possibly wrong for double extended: OK for hardware, but for languages? Note that in C, long double may not correspond to double extended (see 32-bit ARM and PowerPC).|date=July 2020}} * [[Single-precision floating-point format|Single precision]] (binary32), usually used to represent the "float" [[C data types#Basic types|type in the C language]] family. This is a binary format that occupies 32 bits (4 bytes) and its significand has a precision of 24 bits (about 7 decimal digits). * [[Double-precision floating-point format|Double precision]] (binary64), usually used to represent the "double" [[C data types#Basic types|type in the C language]] family. This is a binary format that occupies 64 bits (8 bytes) and its significand has a precision of 53 bits (about 16 decimal digits). * [[Extended precision|Double extended]], also ambiguously called "extended precision" format. This is a binary format that occupies at least 79 bits (80 if the hidden/implicit bit rule is not used) and its significand has a precision of at least 64 bits (about 19 decimal digits). The [[C99]] and [[C11 (C standard revision)|C11]] standards of the C language family, in their annex F ("IEC 60559 floating-point arithmetic"), recommend such an extended format to be provided as "[[long double]]".<ref name="C99"/> A format satisfying the minimal requirements (64-bit significand precision, 15-bit exponent, thus fitting on 80 bits) is provided by the [[x86]] architecture. Often on such processors, this format can be used with "long double", though extended precision is not available with MSVC.<ref name="MSVC"/> For [[Data structure alignment|alignment]] purposes, many tools store this 80-bit value in a 96-bit or 128-bit space.<ref name="GCC"/><ref name="float_128"/> On other processors, "long double" may stand for a larger format, such as quadruple precision,<ref name="ARM_2013_AArch64"/> or just double precision, if any form of extended precision is not available.<ref name="ARM_2013_Compiler"/> Increasing the precision of the floating-point representation generally reduces the amount of accumulated [[round-off error]] caused by intermediate calculations.<ref name="Kahan_2004"/> Other IEEE formats include: * [[Decimal64 floating-point format|Decimal64]] and [[decimal128 floating-point format|decimal128]] floating-point formats. These formats (especially decimal128) are pervasive in financial transactions because, along with the [[Decimal32 floating-point format|decimal32]] format, they allow correct decimal rounding. * [[Quadruple-precision floating-point format#IEEE 754 quadruple-precision binary floating-point format: binary128|Quadruple precision]] (binary128). This is a binary format that occupies 128 bits (16 bytes) and its significand has a precision of 113 bits (about 34 decimal digits). * [[Half-precision floating-point format|Half precision]], also called binary16, a 16-bit floating-point value. It is being used in the NVIDIA [[Cg (programming language)|Cg]] graphics language, and in the openEXR standard (where it actually predates the introduction in the IEEE 754 standard).<ref name="OpenEXR"/><ref name="OpenEXR-half"/> <!--In addition, some platforms use the non-IEEE "double-double" format, where the number is represented as unevaluated sum of two double-precision numbers. It can have some strange properties, unlike other formats. http://aggregate.org/NPAR/iccs2006.pdf--> Any integer with absolute value less than 2<sup>24</sup> can be exactly represented in the single-precision format, and any integer with absolute value less than 2<sup>53</sup> can be exactly represented in the double-precision format. Furthermore, a wide range of powers of 2 times such a number can be represented. These properties are sometimes used for purely integer data, to get 53-bit integers on platforms that have double-precision floats but only 32-bit integers. The standard specifies some special values, and their representation: positive [[infinity]] ({{math|+∞}}), negative infinity ({{math|−∞}}), a [[negative zero]] (−0) distinct from ordinary ("positive") zero, and "not a number" values ([[NaN]]s). Comparison of floating-point numbers, as defined by the IEEE standard, is a bit different from usual integer comparison. Negative and positive zero compare equal, and every NaN compares unequal to every value, including itself. All finite floating-point numbers are strictly smaller than {{math|+∞}} and strictly greater than {{math|−∞}}, and they are ordered in the same way as their values (in the set of real numbers). === Internal representation === Floating-point numbers are typically packed into a computer datum as the sign bit, the exponent field, and a field for the significand, from left to right. For the [[IEEE 754]] binary formats (basic and extended) that have extant hardware implementations, they are apportioned as follows: {| class="wikitable" style="text-align:right; border:0" |- !rowspan="2" |Format !colspan="4" |Bits for the encoding<!-- Since this is about the encoding, it should be clear that the number given for the significand below excludes the implicit bit, when this is used. --> | rowspan="8" style="background:white; border:0"| !rowspan="2" |Exponent<br>bias !rowspan="2" |Bits<br>precision !rowspan="2" |Number of<br>decimal digits |- !Sign !Exponent !Significand !Total |- |[[Half-precision floating-point format|Half]] (binary16) |1 |5 |10 |16 |15 |11 |~3.3 |- |[[Single-precision floating-point format|Single]] (binary32) |1 |8 |23 |32 |127 |24 |~7.2 |- |[[Double-precision floating-point format|Double]] (binary64) |1 |11 |52 |64 |1023 |53 |~15.9 |- |[[Extended precision#x86 extended-precision format|x86 extended]] |1 |15 |64 |80 |16383 |64 |~19.2 |- |[[Quadruple-precision floating-point format|Quadruple]] (binary128) |1 |15 |112 |128 |16383 |113 |~34.0 |- |[[Octuple-precision floating-point format|Octuple]] (binary256) |1 |19 |236 |256 |262143 |237 |~71.3 |} While the exponent can be positive or negative, in binary formats it is stored as an unsigned number that has a fixed "bias" added to it. Values of all 0s in this field are reserved for the zeros and [[subnormal number]]s; values of all 1s are reserved for the infinities and NaNs. The exponent range for normal numbers is [−126, 127] for single precision, [−1022, 1023] for double, or [−16382, 16383] for quad. Normal numbers exclude subnormal values, zeros, infinities, and NaNs. In the IEEE binary interchange formats the leading bit of a normalized significand is not actually stored in the computer datum, since it is always 1. It is called the "hidden" or "implicit" bit. Because of this, the single-precision format actually has a significand with 24 bits of precision, the double-precision format has 53, quad has 113, and octuple has 237. For example, it was shown above that π, rounded to 24 bits of precision, has: * sign = 0 ; ''e'' = 1 ; ''s'' = 110010010000111111011011 (including the hidden bit) The sum of the exponent bias (127) and the exponent (1) is 128, so this is represented in the single-precision format as * 0 10000000 10010010000111111011011 (excluding the hidden bit) = 40490FDB<ref name="IEEE-754_Analysis"/> as a [[hexadecimal]] number. An example of a layout for [[Single-precision floating-point format|32-bit floating point]] is [[File:Float example.svg|none]] and the [[Double-precision floating-point format|64-bit ("double")]] layout is similar. == Other notable floating-point formats == In addition to the widely used [[IEEE 754]] standard formats, other floating-point formats are used, or have been used, in certain domain-specific areas. * The [[Microsoft Binary Format|Microsoft Binary Format (MBF)]] was developed for the Microsoft BASIC language products, including Microsoft's first ever product the [[Altair BASIC]] (1975), [[TRS-80|TRS-80 LEVEL II]], [[CP/M]]'s [[MBASIC]], [[IBM PC 5150]]'s [[BASICA]], [[MS-DOS]]'s [[GW-BASIC]] and [[QuickBASIC]] prior to version 4.00. QuickBASIC version 4.00 and 4.50 switched to the IEEE 754-1985 format but can revert to the MBF format using the /MBF command option. MBF was designed and developed on a simulated [[Intel 8080]] by [[Monte Davidoff]], a dormmate of [[Bill Gates]], during spring of 1975 for the [[MITS Altair 8800]]. The initial release of July 1975 supported a single-precision (32 bits) format due to cost of the [[MITS Altair 8800]] 4-kilobytes memory. In December 1975, the 8-kilobytes version added a double-precision (64 bits) format. A single-precision (40 bits) variant format was adopted for other CPU's, notably the [[MOS 6502]] ([[Apple II]], [[Commodore PET]], [[Atari]]), [[Motorola 6800]] (MITS Altair 680) and [[Motorola 6809]] ([[TRS-80 Color Computer]]). All Microsoft language products from 1975 through 1987 used the [[Microsoft Binary Format]] until Microsoft adopted the IEEE 754 standard format in all its products starting in 1988 to their current releases. MBF consists of the MBF single-precision format (32 bits, "6-digit BASIC"),<ref name="Borland_1994_MBF"/><ref name="Steil_2008_6502"/> the MBF extended-precision format (40 bits, "9<!-- is it really 9 digits, not 8? -->-digit BASIC"),<ref name="Steil_2008_6502"/> and the MBF double-precision format (64 bits);<ref name="Borland_1994_MBF"/><ref name="Microsoft_2006_KB35826"/> each of them is represented with an 8-bit exponent, followed by a sign bit, followed by a significand of respectively 23, 31, and 55 bits. * The [[bfloat16 floating-point format|bfloat16 format]] requires the same amount of memory (16 bits) as the [[Half-precision floating-point format|IEEE 754 half-precision format]], but allocates 8 bits to the exponent instead of 5, thus providing the same range as a [[Single-precision floating-point format|IEEE 754 single-precision]] number. The tradeoff is a reduced precision, as the trailing significand field is reduced from 10 to 7 bits. This format is mainly used in the training of [[machine learning]] models, where range is more valuable than precision. Many machine learning accelerators provide hardware support for this format. * The TensorFloat-32<ref name="Kharya_2020"/> format combines the 8 bits of exponent of the bfloat16 with the 10 bits of trailing significand field of half-precision formats, resulting in a size of 19 bits. This format was introduced by [[Nvidia]], which provides hardware support for it in the Tensor Cores of its [[Graphics processing unit|GPUs]] based on the Nvidia Ampere architecture. The drawback of this format is its size, which is not a power of 2. However, according to Nvidia, this format should only be used internally by hardware to speed up computations, while inputs and outputs should be stored in the 32-bit single-precision IEEE 754 format.<ref name="Kharya_2020"/> * The [[Hopper (microarchitecture)|Hopper]] architecture GPUs provide two FP8 formats: one with the same numerical range as half-precision (E5M2) and one with higher precision, but less range (E4M3).<ref name="NVIDIA_Hopper"/><ref name="Micikevicius_2022"/> * The [[Blackwell (microarchitecture)|Blackwell]] GPU architecture includes support for FP6 (E3M2 and E2M3) and FP4 (E2M1) formats. FP4 is the smallest floating-point format which allows for all IEEE 754 principles (see [[minifloat]]). {| class="wikitable" |+ Comparison of common floating-point formats !Type !Sign !Exponent !Significand !Total bits |- |FP4 |1 |2 |1 |4 |- |FP6 (E2M3) |1 |2 |3 |6 |- |FP6 (E3M2) |1 |3 |2 |6 |- |FP8 (E4M3) |1 |4 |3 |8 |- |FP8 (E5M2) |1 |5 |2 |8 |- |[[Half-precision floating-point format|Half-precision]] |1 |5 |10 |16 |- |[[bfloat16 floating-point format|bfloat16]] |1 |8 |7 |16 |- |[[TensorFloat-32]] |1 |8 |10 |19 |- |[[Single-precision floating-point format|Single-precision]] |1 |8 |23 |32 |- |[[Double-precision floating-point format|Double-precision]] |1 |11 |52 |64 |- |[[Quadruple-precision floating-point format|Quadruple-precision]] |1 |15 |112 |128 |- |[[Octuple-precision floating-point format|Octuple-precision]] |1 |19 |236 |256 |} ==Representable numbers, conversion and rounding {{anchor|Representable numbers}}== By their nature, all numbers expressed in floating-point format are [[rational number]]s with a terminating expansion in the relevant base (for example, a terminating decimal expansion in base-10, or a terminating binary expansion in base-2). Irrational numbers, such as [[Pi|π]] or <math display=inline>\sqrt{2}</math>, or non-terminating rational numbers, must be approximated. The number of digits (or bits) of precision also limits the set of rational numbers that can be represented exactly. For example, the decimal number 123456789 cannot be exactly represented if only eight decimal digits of precision are available (it would be rounded to one of the two straddling representable values, 12345678 × 10<sup>1</sup> or 12345679 × 10<sup>1</sup>), the same applies to [[Repeating decimal|non-terminating digits]] (.{{overline|5}} to be rounded to either .55555555 or .55555556). When a number is represented in some format (such as a character string) which is not a native floating-point representation supported in a computer implementation, then it will require a conversion before it can be used in that implementation. If the number can be represented exactly in the floating-point format then the conversion is exact. If there is not an exact representation then the conversion requires a choice of which floating-point number to use to represent the original value. The representation chosen will have a different value from the original, and the value thus adjusted is called the ''rounded value''. Whether or not a rational number has a terminating expansion depends on the base. For example, in base-10 the number 1/2 has a terminating expansion (0.5) while the number 1/3 does not (0.333...). In base-2 only rationals with denominators that are powers of 2 (such as 1/2 or 3/16) are terminating. Any rational with a denominator that has a prime factor other than 2 will have an infinite binary expansion. This means that numbers that appear to be short and exact when written in decimal format may need to be approximated when converted to binary floating-point. For example, the decimal number 0.1 is not representable in binary floating-point of any finite precision; the exact binary representation would have a "1100" sequence continuing endlessly: : ''e'' = −4; ''s'' = 1100110011001100110011001100110011..., where, as previously, ''s'' is the significand and ''e'' is the exponent. When rounded to 24 bits this becomes : ''e'' = −4; ''s'' = 110011001100110011001101, which is actually 0.100000001490116119384765625 in decimal. <!-- Edit/rearrange this if you want, but please leave the 0.1 example in. (My previous reference to pi being more "sophisticated" than 0.1 was admittedly not artful.) I have known professional software engineers (who should have known better!) who believed that numbers with short decimal representations could always be represented exactly. Putting the many f.p. fallacies/superstitions to rest is important. --> As a further example, the real number [[Pi|π]], represented in binary as an infinite sequence of bits is : 11.0010010000111111011010101000100010000101101000110000100011010011... but is : 11.0010010000111111011011 when approximated by [[rounding]] to a precision of 24 bits. In binary single-precision floating-point, this is represented as ''s'' = 1.10010010000111111011011 with ''e'' = 1. This has a decimal value of : '''3.141592'''7410125732421875, whereas a more accurate approximation of the true value of π is : '''3.14159265358979323846264338327950'''... <!-- Before changing the above numbers, please discuss on talk page. Giving the actual value 10 more digits than the single-precision floating-point value is plenty – more digits do not help the reader --> The result of rounding differs from the true value by about 0.03 parts per million, and matches the decimal representation of π in the first 7 digits. The difference is the [[discretization error]] and is limited by the [[machine epsilon]]. The arithmetical difference between two consecutive representable floating-point numbers which have the same exponent is called a [[unit in the last place]] (ULP). For example, if there is no representable number lying between the representable numbers 1.45A70C22<sub>16</sub> and 1.45A70C24<sub>16</sub>, the ULP is 2×16<sup>−8</sup>, or 2<sup>−31</sup>. For numbers with a base-2 exponent part of 0, i.e. numbers with an absolute value higher than or equal to 1 but lower than 2, an ULP is exactly 2<sup>−23</sup> or about 10<sup>−7</sup> in single precision, and exactly 2<sup>−53</sup> or about 10<sup>−16</sup> in double precision. The mandated behavior of IEEE-compliant hardware is that the result be within one-half of a ULP. === Rounding modes === Rounding is used when the exact result of a floating-point operation (or a conversion to floating-point format) would need more digits than there are digits in the significand. IEEE 754 requires ''correct rounding'': that is, the rounded result is as if infinitely precise arithmetic was used to compute the value and then rounded (although in implementation only three extra bits are needed to ensure this). There are several different [[rounding]] schemes (or ''rounding modes''). Historically, [[truncation]] was the typical approach. Since the introduction of IEEE 754, the default method (''[[rounding|round to nearest, ties to even]]'', sometimes called Banker's Rounding) is more commonly used. This method rounds the ideal (infinitely precise) result of an arithmetic operation to the nearest representable value, and gives that representation as the result.<ref group="nb" name="NB_1"/> In the case of a tie, the value that would make the significand end in an even digit is chosen. The IEEE 754 standard requires the same rounding to be applied to all fundamental algebraic operations, including square root and conversions, when there is a numeric (non-NaN) result. It means that the results of IEEE 754 operations are completely determined in all bits of the result, except for the representation of NaNs. ("Library" functions such as cosine and log are not mandated.) Alternative rounding options are also available. IEEE 754 specifies the following rounding modes: * round to nearest, where ties round to the nearest even digit in the required position (the default and by far the most common mode) * round to nearest, where ties round away from zero (optional for binary floating-point and commonly used in decimal) * round up (toward +∞; negative results thus round toward zero) * round down (toward −∞; negative results thus round away from zero) * round toward zero (truncation; it is similar to the common behavior of float-to-integer conversions, which convert −3.9 to −3 and 3.9 to 3) Alternative modes are useful when the amount of error being introduced must be bounded. Applications that require a bounded error are multi-precision floating-point, and [[interval arithmetic]]. The alternative rounding modes are also useful in diagnosing numerical instability: if the results of a subroutine vary substantially between rounding to + and − infinity then it is likely numerically unstable and affected by round-off error.<ref name="Kahan_2006_Mindless"/> === Binary-to-decimal conversion with minimal number of digits === Converting a double-precision binary floating-point number to a decimal string is a common operation, but an algorithm producing results that are both accurate and minimal did not appear in print until 1990, with Steele and White's Dragon4. Some of the improvements since then include: * David M. Gay's ''dtoa.c'', a practical open-source implementation of many ideas in Dragon4.<ref name="Gay_1990"/> * Grisu3, with a 4× speedup as it removes the use of [[bignum]]s. Must be used with a fallback, as it fails for ~0.5% of cases.<ref name="Loitsch_2010"/> * Errol3, an always-succeeding algorithm similar to, but slower than, Grisu3. Apparently not as good as an early-terminating Grisu with fallback.<ref name="mazong"/> * Ryū, an always-succeeding algorithm that is faster and simpler than Grisu3.<ref name="Adams_2018"/> * Schubfach, an always-succeeding algorithm that is based on a similar idea to Ryū, developed almost simultaneously and independently.<ref name="Giulietti"/> Performs better than Ryū and Grisu3 in certain benchmarks.<ref name="abolz"/> Many modern language runtimes use Grisu3 with a Dragon4 fallback.<ref name="double_conversion_2020"/> === Decimal-to-binary conversion === The problem of parsing a decimal string into a binary FP representation is complex, with an accurate parser not appearing until Clinger's 1990 work (implemented in dtoa.c).<ref name="Gay_1990"/> Further work has likewise progressed in the direction of faster parsing.<ref name="Lemire_2021"/> == Floating-point operations == For ease of presentation and understanding, decimal [[radix]] with 7 digit precision will be used in the examples, as in the IEEE 754 ''decimal32'' format. The fundamental principles are the same in any [[radix]] or precision, except that normalization is optional (it does not affect the numerical value of the result). Here, ''s'' denotes the significand and ''e'' denotes the exponent. === Addition and subtraction === A simple method to add floating-point numbers is to first represent them with the same exponent. In the example below, the second number (with the smaller exponent) is shifted right by three digits, and one then proceeds with the usual addition method: 123456.7 = 1.234567 × 10^5 101.7654 = 1.017654 × 10^2 = 0.001017654 × 10^5 Hence: 123456.7 + 101.7654 = (1.234567 × 10^5) + (1.017654 × 10^2) = (1.234567 × 10^5) + (0.001017654 × 10^5) = (1.234567 + 0.001017654) × 10^5 = 1.235584654 × 10^5 In detail: e=5; s=1.234567 (123456.7) + e=2; s=1.017654 (101.7654) e=5; s=1.234567 + e=5; s=0.001017654 (after shifting) -------------------- e=5; s=1.235584654 (true sum: 123558.4654) This is the true result, the exact sum of the operands. It will be rounded to seven digits and then normalized if necessary. The final result is e=5; s=1.235585 (final sum: 123558.5) The lowest three digits of the second operand (654) are essentially lost. This is [[round-off error]]. In extreme cases, the sum of two non-zero numbers may be equal to one of them: e=5; s=1.234567 + e=−3; s=9.876543 e=5; s=1.234567 + e=5; s=0.00000009876543 (after shifting) ---------------------- e=5; s=1.23456709876543 (true sum) e=5; s=1.234567 (after rounding and normalization) In the above conceptual examples it would appear that a large number of extra digits would need to be provided by the adder to ensure correct rounding; however, for binary addition or subtraction using careful implementation techniques only a ''guard'' bit, a ''rounding'' bit and one extra ''sticky'' bit need to be carried beyond the precision of the operands.<ref name="Goldberg_1991"/><ref name="Patterson-Hennessy_2014"/>{{rp|218–220}} Another problem of loss of significance occurs when ''approximations'' to two nearly equal numbers are subtracted. In the following example ''e'' = 5; ''s'' = 1.234571 and ''e'' = 5; ''s'' = 1.234567 are approximations to the rationals 123457.1467 and 123456.659. e=5; s=1.234571 − e=5; s=1.234567 ---------------- e=5; s=0.000004 e=−1; s=4.000000 (after rounding and normalization) The floating-point difference is computed exactly because the numbers are close—the [[Sterbenz lemma]] guarantees this, even in case of underflow when [[gradual underflow]] is supported. Despite this, the difference of the original numbers is ''e'' = −1; ''s'' = 4.877000, which differs more than 20% from the difference ''e'' = −1; ''s'' = 4.000000 of the approximations. In extreme cases, all significant digits of precision can be lost.<ref name="Goldberg_1991"/><ref name="Sierra_1962"/> This ''[[Catastrophic cancellation|cancellation]]'' illustrates the danger in assuming that all of the digits of a computed result are meaningful. Dealing with the consequences of these errors is a topic in [[numerical analysis]]; see also [[#Accuracy problems|Accuracy problems]]. === Multiplication and division === To multiply, the significands are multiplied while the exponents are added, and the result is rounded and normalized. e=3; s=4.734612 × e=5; s=5.417242 ----------------------- e=8; s=25.648538980104 (true product) e=8; s=25.64854 (after rounding) e=9; s=2.564854 (after normalization) Similarly, division is accomplished by subtracting the divisor's exponent from the dividend's exponent, and dividing the dividend's significand by the divisor's significand. There are no cancellation or absorption problems with multiplication or division, though small errors may accumulate as operations are performed in succession.<ref name="Goldberg_1991"/> In practice, the way these operations are carried out in digital logic can be quite complex (see [[Booth's multiplication algorithm]] and [[Division algorithm]]).<ref group="nb" name="NB_2"/> === Literal syntax === Literals for floating-point numbers depend on languages. They typically use <code>e</code> or <code>E</code> to denote [[scientific notation]]. The [[C (programming language)|C programming language]] and the [[IEEE 754]] standard also define a [[IEEE 754#Hexadecimal literals|hexadecimal literal syntax]] with a base-2 exponent instead of 10.<!-- Also in [[Hexadecimal#Hexadecimal exponential notation]] --> In languages like [[C (programming language)|C]], when the decimal exponent is omitted, a decimal point is needed to differentiate them from integers. Other languages do not have an integer type (such as [[JavaScript]]), or allow overloading of numeric types (such as [[Haskell (programming language)|Haskell]]). In these cases, digit strings such as <code>123</code> may also be floating-point literals. Examples of floating-point literals are: * <code>99.9</code> * <code>-5000.12</code><!-- do not use ndash, as that isn't part of a literal(?)--> * <code>6.02e23</code> * <code>-3e-45</code> * <code>0x1.fffffep+127</code> in C and IEEE 754 ==Dealing with exceptional cases {{anchor|Floating point exception|Exception handling}}== <!-- linked from a couple of places within the article --> {{further|IEEE 754#Exception handling}} Floating-point computation in a computer can run into three kinds of problems: * An operation can be mathematically undefined, such as ∞/∞, or [[division by zero]]. * An operation can be legal in principle, but not supported by the specific format, for example, calculating the [[square root]] of −1 or the inverse sine of 2 (both of which result in [[complex number]]s). * An operation can be legal in principle, but the result can be impossible to represent in the specified format, because the exponent is too large or too small to encode in the exponent field. Such an event is called an overflow (exponent too large), [[arithmetic underflow|underflow]] (exponent too small) or [[Subnormal number|denormalization]] (precision loss). Prior to the IEEE standard, such conditions usually caused the program to terminate, or triggered some kind of [[trap (computing)|trap]] that the programmer might be able to catch. How this worked was system-dependent, meaning that floating-point programs were not [[porting|portable]]. (The term "exception" as used in IEEE 754 is a general term meaning an exceptional condition, which is not necessarily an error, and is a different usage to that typically defined in programming languages such as a C++ or Java, in which an "[[Exception handling|exception]]" is an alternative flow of control, closer to what is termed a "trap" in IEEE 754 terminology.) Here, the required default method of handling exceptions according to IEEE 754 is discussed (the IEEE 754 optional trapping and other "alternate exception handling" modes are not discussed). Arithmetic exceptions are (by default) required to be recorded in "sticky" status flag bits. That they are "sticky" means that they are not reset by the next (arithmetic) operation, but stay set until explicitly reset. The use of "sticky" flags thus allows for testing of exceptional conditions to be delayed until after a full floating-point expression or subroutine: without them exceptional conditions that could not be otherwise ignored would require explicit testing immediately after every floating-point operation. By default, an operation always returns a result according to specification without interrupting computation. For instance, 1/0 returns +∞, while also setting the divide-by-zero flag bit (this default of ∞ is designed to often return a finite result when used in subsequent operations and so be safely ignored). The original IEEE 754 standard, however, failed to recommend operations to handle such sets of arithmetic exception flag bits. So while these were implemented in hardware, initially programming language implementations typically did not provide a means to access them (apart from assembler). Over time some programming language standards (e.g., [[C99]]/C11 and Fortran) have been updated to specify methods to access and change status flag bits. The 2008 version of the IEEE 754 standard now specifies a few operations for accessing and handling the arithmetic flag bits. The programming model is based on a single thread of execution and use of them by multiple threads has to be handled by a [[Concurrency (computer science)|means]] outside of the standard (e.g. [[C11 (C standard revision)|C11]] specifies that the flags have [[thread-local storage]]). IEEE 754 specifies five arithmetic exceptions that are to be recorded in the status flags ("sticky bits"): * '''inexact''', set if the rounded (and returned) value is different from the mathematically exact result of the operation. * '''underflow''', set if the rounded value is tiny (as specified in IEEE 754) ''and'' inexact (or maybe limited to if it has denormalization loss, as per the 1985 version of IEEE 754), returning a subnormal value including the zeros. * '''overflow''', set if the absolute value of the rounded value is too large to be represented. An infinity or maximal finite value is returned, depending on which rounding is used. * '''divide-by-zero''', set if the result is infinite given finite operands, returning an infinity, either +∞ or −∞. * '''invalid''', set if a finite or infinite result cannot be returned e.g. sqrt(−1) or 0/0, returning a quiet NaN. [[File:Resistors in Parallel.svg|thumb|left|200px|Fig. 1: resistances in parallel, with total resistance <math>R_{tot}</math>]]The default return value for each of the exceptions is designed to give the correct result in the majority of cases such that the exceptions can be ignored in the majority of codes. ''inexact'' returns a correctly rounded result, and ''underflow'' returns a value less than or equal to the smallest positive normal number in magnitude and can almost always be ignored.<ref name="Kahan_1997_Status"/> ''divide-by-zero'' returns infinity exactly, which will typically then divide a finite number and so give zero, or else will give an ''invalid'' exception subsequently if not, and so can also typically be ignored. For example, the effective resistance of n resistors in parallel (see fig. 1) is given by <math>R_\text{tot}=1/(1/R_1+1/R_2+\cdots+1/R_n)</math>. If a short-circuit develops with <math>R_1</math> set to 0, <math>1/R_1</math> will return +infinity which will give a final <math>R_{tot}</math> of 0, as expected<ref name="Intel"/> (see the continued fraction example of [[Floating point#IEEE 754: floating point in modern computers|IEEE 754 design rationale]] for another example). ''Overflow'' and ''invalid'' exceptions can typically not be ignored, but do not necessarily represent errors: for example, a [[Zero of a function|root-finding]] routine, as part of its normal operation, may evaluate a passed-in function at values outside of its domain, returning NaN and an ''invalid'' exception flag to be ignored until finding a useful start point.<ref name="Kahan_1997_Status"/> == Accuracy problems == <!-- internally linked --> The fact that floating-point numbers cannot accurately represent all real numbers, and that floating-point operations cannot accurately represent true arithmetic operations, leads to many surprising situations. This is related to the finite [[Precision (computer science)|precision]] with which computers generally represent numbers. For example, the decimal numbers 0.1 and 0.01 cannot be represented exactly as binary floating-point numbers. In the IEEE 754 binary32 format with its 24-bit significand, the result of attempting to square the approximation to 0.1 is neither 0.01 nor the representable number closest to it. The decimal number 0.1 is represented in binary as {{math|1={{var|e}} = −4}}; {{math|1={{var|s}} = 110011001100110011001101}}, which is {{block indent|1=0.100000001490116119384765625 exactly.}} Squaring this number gives {{block indent|1=0.010000000298023226097399174250313080847263336181640625 exactly.}} Squaring it with rounding to the 24-bit precision gives {{block indent|0.010000000707805156707763671875 exactly.}} But the representable number closest to 0.01 is {{block indent|0.009999999776482582092285156250 exactly.}} Also, the non-representability of π (and π/2) means that an attempted computation of tan(π/2) will not yield a result of infinity, nor will it even overflow in the usual floating-point formats (assuming an accurate implementation of tan). It is simply not possible for standard floating-point hardware to attempt to compute tan(π/2), because π/2 cannot be represented exactly. This computation in C: <syntaxhighlight lang="c"> /* Enough digits to be sure we get the correct approximation. */ double pi = 3.1415926535897932384626433832795; double z = tan(pi/2.0); </syntaxhighlight> will give a result of 16331239353195370.0. In single precision (using the <code>tanf</code> function), the result will be −22877332.0. By the same token, an attempted computation of sin(π) will not yield zero. The result will be (approximately) 0.1225{{e|−15}} in double precision, or −0.8742{{e|−7}} in single precision.<ref group="nb" name="NB_3"/> While floating-point addition and multiplication are both [[commutative]] ({{math|{{var|a}} + {{var|b}} {{=}} {{var|b}} + {{var|a}}}} and {{math|{{var|a}} × {{var|b}} {{=}} {{var|b}} × {{var|a}}}}), they are not necessarily [[Associative property|associative]]. That is, {{math|({{var|a}} + {{var|b}}) + {{var|c}}}} is not necessarily equal to {{math|{{var|a}} + ({{var|b}} + {{var|c}})}}. Using 7-digit significand decimal arithmetic: a = 1234.567, b = 45.67834, c = 0.0004 (a + b) + c: 1234.567 (a) + 45.67834 (b) ____________ 1280.24534 rounds to 1280.245 1280.245 (a + b) + 0.0004 (c) ____________ 1280.2454 rounds to '''1280.245''' ← (a + b) + c a + (b + c): 45.67834 (b) + 0.0004 (c) ____________ 45.67874 1234.567 (a) + 45.67874 (b + c) ____________ 1280.24574 rounds to '''1280.246''' ← a + (b + c) They are also not necessarily [[distributive property|distributive]]. That is, {{math|({{var|a}} + {{var|b}}) × {{var|c}}}} may not be the same as {{math|{{var|a}} × {{var|c}} + {{var|b}} × {{var|c}}}}: 1234.567 × 3.333333 = 4115.223 1.234567 × 3.333333 = 4.115223 4115.223 + 4.115223 = 4119.338 but 1234.567 + 1.234567 = 1235.802 1235.802 × 3.333333 = 4119.340 In addition to loss of significance, inability to represent numbers such as π and 0.1 exactly, and other slight inaccuracies, the following phenomena may occur: {{ulist |1= [[Catastrophic cancellation|Cancellation]]: subtraction of nearly equal operands may cause extreme loss of accuracy.<ref name="Harris"/><ref name="Sierra_1962"/> When we subtract two almost equal numbers we set the most significant digits to zero, leaving ourselves with just the insignificant, and most erroneous, digits.<ref name="Muller_2010"/>{{rp|124}} For example, when determining a [[derivative]] of a function the following formula is used: <math display=block>Q(h) = \frac{f(a + h) - f(a)}{h}.</math> Intuitively one would want an {{math|{{var|h}}}} very close to zero; however, when using floating-point operations, the smallest number will not give the best approximation of a derivative. As {{math|{{var|h}}}} grows smaller, the difference between {{math|{{var|f}}({{var|a}} + {{var|h}})}} and {{math|{{var|f}}({{var|a}})}} grows smaller, cancelling out the most significant and least erroneous digits and making the most erroneous digits more important. As a result the smallest number of {{math|{{var|h}}}} possible will give a more erroneous approximation of a derivative than a somewhat larger number. This is perhaps the most common and serious accuracy problem. |2=Conversions to integer are not intuitive: converting (63.0/9.0) to integer yields 7, but converting (0.63/0.09) may yield 6. This is because conversions generally truncate rather than round. [[Floor and ceiling functions]] may produce answers which are off by one from the intuitively expected value. |3=Limited exponent range: results might overflow yielding infinity, or underflow yielding a [[subnormal number]] or zero. In these cases precision will be lost. |4=Testing for [[Division by zero#Computer arithmetic|safe division]] is problematic: Checking that the divisor is not zero does not guarantee that a division will not overflow. |5=Testing for equality is problematic. Two computational sequences that are mathematically equal may well produce different floating-point values.<ref name="Barker"/> }} === Incidents === * On 25 February 1991, a [[loss of significance]] in a [[MIM-104 Patriot]] missile battery [[MIM-104 Patriot#Failure at Dhahran|prevented it from intercepting]] an incoming [[Al Hussein (missile)|Scud]] missile in [[Dhahran]], [[Saudi Arabia]], contributing to the death of 28 soldiers from the U.S. Army's [[14th Quartermaster Detachment]].<ref name="GAO report IMTEC 92-26"/> The error was actually introduced by a [[Fixed-point arithmetic|fixed-point]] computation,<ref name="Skeel"/> but the underlying issue would have been the same with floating-point arithmetic. * {{Clarify|date=November 2024|reason=It is not clear how this is an incident (the section title may have to be modified to cover more than incidents) and how this is due to floating-point arithmetic (rather than number approximations in general). The term 'invisible' may also be misleading without following explanations. |text=[[Salami slicing tactics#Financial schemes|Salami slicing]] is the practice of removing the 'invisible' part of a transaction into a separate account.}} === Machine precision and backward error analysis === ''Machine precision'' is a quantity that characterizes the accuracy of a floating-point system, and is used in [[error analysis (mathematics)#Error analysis in numerical modeling|backward error analysis]] of floating-point algorithms. It is also known as unit roundoff or ''[[machine epsilon]]''. Usually denoted {{math|{{var|Ε}}<sub>mach</sub>}}, its value depends on the particular rounding being used. With rounding to zero, <math display=block>\Epsilon_\text{mach} = B^{1-P},\,</math> whereas rounding to nearest, <math display=block>\Epsilon_\text{mach} = \tfrac{1}{2} B^{1-P},</math> where ''B'' is the base of the system and ''P'' is the precision of the significand (in base ''B''). This is important since it bounds the ''[[relative error]]'' in representing any non-zero real number {{math|{{var|x}}}} within the normalized range of a floating-point system: <math display=block>\left| \frac{\operatorname{fl}(x) - x}{x} \right| \le \Epsilon_\text{mach}.</math> Backward error analysis, the theory of which was developed and popularized by [[James H. Wilkinson]], can be used to establish that an algorithm implementing a numerical function is numerically stable.<ref name="RalstonReilly2003"/> The basic approach is to show that although the calculated result, due to roundoff errors, will not be exactly correct, it is the exact solution to a nearby problem with slightly perturbed input data. If the perturbation required is small, on the order of the uncertainty in the input data, then the results are in some sense as accurate as the data "deserves". The algorithm is then defined as ''[[numerical stability#Forward, backward, and mixed stability|backward stable]]''. Stability is a measure of the sensitivity to rounding errors of a given numerical procedure; by contrast, the [[condition number]] of a function for a given problem indicates the inherent sensitivity of the function to small perturbations in its input and is independent of the implementation used to solve the problem.<ref name="Einarsson_2005"/> As a trivial example, consider a simple expression giving the inner product of (length two) vectors <math>x</math> and <math>y</math>, then <math display=block>\begin{align} \operatorname{fl}(x \cdot y) &= \operatorname{fl}\big(\operatorname{fl}(x_1 \cdot y_1) + \operatorname{fl}(x_2 \cdot y_2)\big), && \text{ where } \operatorname{fl}() \text{ indicates correctly rounded floating-point arithmetic} \\ &= \operatorname{fl}\big((x_1 \cdot y_1)(1 + \delta_1) + (x_2 \cdot y_2)(1 + \delta_2)\big), && \text{ where } \delta_n \leq \Epsilon_\text{mach}, \text{ from above} \\ &= \big((x_1 \cdot y_1)(1 + \delta_1) + (x_2 \cdot y_2)(1 + \delta_2)\big)(1 + \delta_3) \\ &= (x_1 \cdot y_1)(1 + \delta_1)(1 + \delta_3) + (x_2 \cdot y_2)(1 + \delta_2)(1 + \delta_3), \end{align}</math> and so <math display=block>\operatorname{fl}(x \cdot y) = \hat{x} \cdot \hat{y},</math> where <math display=block>\begin{align} \hat{x}_1 &= x_1(1 + \delta_1); & \hat{x}_2 &= x_2(1 + \delta_2);\\ \hat{y}_1 &= y_1(1 + \delta_3); & \hat{y}_2 &= y_2(1 + \delta_3),\\ \end{align}</math> where <math display=block>\delta_n \leq \Epsilon_\text{mach}</math> by definition, which is the sum of two slightly perturbed (on the order of Ε<sub>mach</sub>) input data, and so is backward stable. For more realistic examples in [[numerical linear algebra]], see Higham 2002<ref name="Higham_2002"/> and other references below. === Minimizing the effect of accuracy problems === Although individual arithmetic operations of IEEE 754 are guaranteed accurate to within half a [[unit in the last place|ULP]], more complicated formulae can suffer from larger errors for a variety of reasons. The loss of accuracy can be substantial if a problem or its data are [[condition number|ill-conditioned]], meaning that the correct result is hypersensitive to tiny perturbations in its data. However, even functions that are well-conditioned can suffer from large loss of accuracy if an algorithm [[numerical stability|numerically unstable]] for that data is used: apparently equivalent formulations of expressions in a programming language can differ markedly in their numerical stability. One approach to remove the risk of such loss of accuracy is the design and analysis of numerically stable algorithms, which is an aim of the branch of mathematics known as [[numerical analysis]]. Another approach that can protect against the risk of numerical instabilities is the computation of intermediate (scratch) values in an algorithm at a higher precision than the final result requires,<ref name="OliveiraStewart_2006"/> which can remove, or reduce by orders of magnitude,<ref name="Kahan_2005_ARITH17"/> such risk: [[Quadruple-precision floating-point format|IEEE 754 quadruple precision]] and [[extended precision]] are designed for this purpose when computing at double precision.<ref name="Kahan_2011_Debug"/><ref group="nb" name="NB_4"/> For example, the following algorithm is a direct implementation to compute the function {{math|{{var|A}}({{var|x}}) {{=}} ({{var|x}}−1) / (exp({{var|x}}−1) − 1)}} which is well-conditioned at 1.0,<ref group="nb" name="NB_5"/> however it can be shown to be numerically unstable and lose up to half the significant digits carried by the arithmetic when computed near 1.0.<ref name="Kahan_2001_JavaHurt"/> <syntaxhighlight lang="c" line highlight="3,7"> double A(double X) { double Y, Z; // [1] Y = X - 1.0; Z = exp(Y); if (Z != 1.0) Z = Y / (Z - 1.0); // [2] return Z; } </syntaxhighlight> If, however, intermediate computations are all performed in extended precision (e.g. by setting line [1] to [[C99]] {{code|long double}}), then up to full precision in the final double result can be maintained.<ref group="nb" name="NB_6"/> Alternatively, a numerical analysis of the algorithm reveals that if the following non-obvious change to line [2] is made: <syntaxhighlight lang="c"> Z = log(Z) / (Z - 1.0); </syntaxhighlight> then the algorithm becomes numerically stable and can compute to full double precision. To maintain the properties of such carefully constructed numerically stable programs, careful handling by the [[compiler]] is required. Certain "optimizations" that compilers might make (for example, reordering operations) can work against the goals of well-behaved software. There is some controversy about the failings of compilers and language designs in this area: C99 is an example of a language where such optimizations are carefully specified to maintain numerical precision. See the external references at the bottom of this article. A detailed treatment of the techniques for writing high-quality floating-point software is beyond the scope of this article, and the reader is referred to,<ref name="Higham_2002"/><ref name="Kahan_2000_Marketing"/> and the other references at the bottom of this article. Kahan suggests several rules of thumb that can substantially decrease by orders of magnitude<ref name="Kahan_2000_Marketing"/> the risk of numerical anomalies, in addition to, or in lieu of, a more careful numerical analysis. These include: as noted above, computing all expressions and intermediate results in the highest precision supported in hardware (a common rule of thumb is to carry twice the precision of the desired result, i.e. compute in double precision for a final single-precision result, or in double extended or quad precision for up to double-precision results<ref name="Kahan_1981_WhyIEEE"/>); and rounding input data and results to only the precision required and supported by the input data (carrying excess precision in the final result beyond that required and supported by the input data can be misleading, increases storage cost and decreases speed, and the excess bits can affect convergence of numerical procedures:<ref name="Kahan_2001_LN"/> notably, the first form of the iterative example given below converges correctly when using this rule of thumb). Brief descriptions of several additional issues and techniques follow. As decimal fractions can often not be exactly represented in binary floating-point, such arithmetic is at its best when it is simply being used to measure real-world quantities over a wide range of scales (such as the orbital period of a moon around Saturn or the mass of a [[proton]]), and at its worst when it is expected to model the interactions of quantities expressed as decimal strings that are expected to be exact.<ref name="Kahan_2005_ARITH17"/><ref name="Kahan_2000_Marketing"/> An example of the latter case is financial calculations. For this reason, financial software tends not to use a binary floating-point number representation.<ref name="Speleotrove_2012"/> The "decimal" data type of the [[C Sharp (programming language)|C#]] and [[Python (programming language)|Python]] programming languages, and the decimal formats of the [[IEEE 754-2008]] standard, are designed to avoid the problems of binary floating-point representations when applied to human-entered exact decimal values, and make the arithmetic always behave as expected when numbers are printed in decimal. Expectations from mathematics may not be realized in the field of floating-point computation. For example, it is known that <math>(x+y)(x-y) = x^2-y^2\,</math>, and that <math>\sin^2{\theta}+\cos^2{\theta} = 1\,</math>, however these facts cannot be relied on when the quantities involved are the result of floating-point computation. The use of the equality test (<code>if (x==y) ...</code>) requires care when dealing with floating-point numbers. Even simple expressions like <code>0.6/0.2-3==0</code> will, on most computers, fail to be true<ref name="Christiansen_Perl"/> (in IEEE 754 double precision, for example, <code>0.6/0.2 - 3</code> is approximately equal to {{val|-4.44089209850063e-16}}). Consequently, such tests are sometimes replaced with "fuzzy" comparisons (<code>if (abs(x-y) < epsilon) ...</code>, where epsilon is sufficiently small and tailored to the application, such as 1.0E−13). The wisdom of doing this varies greatly, and can require numerical analysis to bound epsilon.<ref name="Higham_2002"/> Values derived from the primary data representation and their comparisons should be performed in a wider, extended, precision to minimize the risk of such inconsistencies due to round-off errors.<ref name="Kahan_2000_Marketing"/> It is often better to organize the code in such a way that such tests are unnecessary. For example, in [[computational geometry]], exact tests of whether a point lies off or on a line or plane defined by other points can be performed using adaptive precision or exact arithmetic methods.<ref name="Shewchuk"/> Small errors in floating-point arithmetic can grow when mathematical algorithms perform operations an enormous number of times. A few examples are [[matrix inversion]], [[eigenvector]] computation, and differential equation solving. These algorithms must be very carefully designed, using numerical approaches such as [[iterative refinement]], if they are to work well.<ref name="Kahan_1997_Cantilever"/> Summation of a vector of floating-point values is a basic algorithm in [[Computational science|scientific computing]], and so an awareness of when loss of significance can occur is essential. For example, if one is adding a very large number of numbers, the individual addends are very small compared with the sum. This can lead to loss of significance. A typical addition would then be something like 3253.671 + 3.141276 ----------- 3256.812 The low 3 digits of the addends are effectively lost. Suppose, for example, that one needs to add many numbers, all approximately equal to 3. After 1000 of them have been added, the running sum is about 3000; the lost digits are not regained. The [[Kahan summation algorithm]] may be used to reduce the errors.<ref name="Higham_2002"/> Round-off error can affect the convergence and accuracy of iterative numerical procedures. As an example, [[Archimedes]] approximated π by calculating the perimeters of polygons inscribing and circumscribing a circle, starting with hexagons, and successively doubling the number of sides. As noted above, computations may be rearranged in a way that is mathematically equivalent but less prone to error ([[numerical analysis]]). Two forms of the recurrence formula for the circumscribed polygon are:{{citation needed|reason=Not obvious formulas|date=June 2016}} * <math display="inline">t_0 = \frac{1}{\sqrt{3}}</math> * First form: <math display=inline>t_{i+1} = \frac{\sqrt{t_i^2+1}-1}{t_i}</math> * Second form: <math display=inline>t_{i+1} = \frac{t_i}{\sqrt{t_i^2+1}+1}</math> * <math>\pi \sim 6 \times 2^i \times t_i</math>, converging as <math>i \rightarrow \infty</math> Here is a computation using IEEE "double" (a significand with 53 bits of precision) arithmetic: i 6 × 2<sup>i</sup> × t<sub>i</sub>, first form 6 × 2<sup>i</sup> × t<sub>i</sub>, second form --------------------------------------------------------- 0 '''{{Fontcolor|purple|3}}'''.4641016151377543863 '''{{Fontcolor|purple|3}}'''.4641016151377543863 1 '''{{Fontcolor|purple|3}}'''.2153903091734710173 '''{{Fontcolor|purple|3}}'''.2153903091734723496 2 '''{{Fontcolor|purple|3.1}}'''596599420974940120 '''{{Fontcolor|purple|3.1}}'''596599420975006733 3 '''{{Fontcolor|purple|3.14}}'''60862151314012979 '''{{Fontcolor|purple|3.14}}'''60862151314352708 4 '''{{Fontcolor|purple|3.14}}'''27145996453136334 '''{{Fontcolor|purple|3.14}}'''27145996453689225 5 '''{{Fontcolor|purple|3.141}}'''8730499801259536 '''{{Fontcolor|purple|3.141}}'''8730499798241950 6 '''{{Fontcolor|purple|3.141}}'''6627470548084133 '''{{Fontcolor|purple|3.141}}'''6627470568494473 7 '''{{Fontcolor|purple|3.141}}'''6101765997805905 '''{{Fontcolor|purple|3.141}}'''6101766046906629 8 '''{{Fontcolor|purple|3.14159}}'''70343230776862 '''{{Fontcolor|purple|3.14159}}'''70343215275928 9 '''{{Fontcolor|purple|3.14159}}'''37488171150615 '''{{Fontcolor|purple|3.14159}}'''37487713536668 10 '''{{Fontcolor|purple|3.141592}}'''9278733740748 '''{{Fontcolor|purple|3.141592}}'''9273850979885 11 '''{{Fontcolor|purple|3.141592}}'''7256228504127 '''{{Fontcolor|purple|3.141592}}'''7220386148377 12 '''{{Fontcolor|purple|3.1415926}}'''717412858693 '''{{Fontcolor|purple|3.1415926}}'''707019992125 13 '''{{Fontcolor|purple|3.1415926}}'''189011456060 '''{{Fontcolor|purple|3.14159265}}'''78678454728 14 '''{{Fontcolor|purple|3.1415926}}'''717412858693 '''{{Fontcolor|purple|3.14159265}}'''46593073709 15 '''{{Fontcolor|purple|3.14159}}'''19358822321783 '''{{Fontcolor|purple|3.141592653}}'''8571730119 16 '''{{Fontcolor|purple|3.1415926}}'''717412858693 '''{{Fontcolor|purple|3.141592653}}'''6566394222 17 '''{{Fontcolor|purple|3.1415}}'''810075796233302 '''{{Fontcolor|purple|3.141592653}}'''6065061913 18 '''{{Fontcolor|purple|3.1415926}}'''717412858693 '''{{Fontcolor|purple|3.1415926535}}'''939728836 19 '''{{Fontcolor|purple|3.141}}'''4061547378810956 '''{{Fontcolor|purple|3.1415926535}}'''908393901 20 '''{{Fontcolor|purple|3.14}}'''05434924008406305 '''{{Fontcolor|purple|3.1415926535}}'''900560168 21 '''{{Fontcolor|purple|3.14}}'''00068646912273617 '''{{Fontcolor|purple|3.141592653589}}'''8608396 22 '''{{Fontcolor|purple|3.1}}'''349453756585929919 '''{{Fontcolor|purple|3.141592653589}}'''8122118 23 '''{{Fontcolor|purple|3.14}}'''00068646912273617 '''{{Fontcolor|purple|3.14159265358979}}'''95552 24 '''{{Fontcolor|purple|3}}'''.2245152435345525443 '''{{Fontcolor|purple|3.14159265358979}}'''68907 25 '''{{Fontcolor|purple|3.14159265358979}}'''62246 26 '''{{Fontcolor|purple|3.14159265358979}}'''62246 27 '''{{Fontcolor|purple|3.14159265358979}}'''62246 28 '''{{Fontcolor|purple|3.14159265358979}}'''62246 The true value is '''{{Fontcolor|purple|3.14159265358979323846264338327...}}''' While the two forms of the recurrence formula are clearly mathematically equivalent,<ref group="nb" name="NB_7"/> the first subtracts 1 from a number extremely close to 1, leading to an increasingly problematic loss of [[significant digit]]s. As the recurrence is applied repeatedly, the accuracy improves at first, but then it deteriorates. It never gets better than about 8 digits, even though 53-bit arithmetic should be capable of about 16 digits of precision. When the second form of the recurrence is used, the value converges to 15 digits of precision. === "Fast math" optimization === The aforementioned lack of [[Associative property|associativity]] of floating-point operations in general means that [[compilers]] cannot as effectively reorder arithmetic expressions as they could with integer and fixed-point arithmetic, presenting a roadblock in optimizations such as [[common subexpression elimination]] and auto-[[Single instruction, multiple data|vectorization]].<ref name="Vectorizers"/> The "fast math" option on many compilers (ICC, GCC, Clang, MSVC...) turns on reassociation along with unsafe assumptions such as a lack of NaN and infinite numbers in IEEE 754. Some compilers also offer more granular options to only turn on reassociation. In either case, the programmer is exposed to many of the precision pitfalls mentioned above for the portion of the program using "fast" math.<ref name="FPM"/> In some compilers (GCC and Clang), turning on "fast" math may cause the program to [[Subnormal_number#Disabling_subnormal_floats_at_the_code_level|disable subnormal floats]] at startup, affecting the floating-point behavior of not only the generated code, but also any program using such code as a [[Library (computing)|library]].<ref name="harmful"/> In most [[Fortran]] compilers, as allowed by the ISO/IEC 1539-1:2004 Fortran standard, reassociation is the default, with breakage largely prevented by the "protect parens" setting (also on by default). This setting stops the compiler from reassociating beyond the boundaries of parentheses.<ref name="Gen"/> [[Intel Fortran Compiler]] is a notable outlier.<ref name="zheevd"/> A common problem in "fast" math is that subexpressions may not be optimized identically from place to place, leading to unexpected differences. One interpretation of the issue is that "fast" math as implemented currently has a poorly defined semantics. One attempt at formalizing "fast" math optimizations is seen in ''Icing'', a verified compiler.<ref name="Becker-Darulova-Myreen-Tatlock_2019"/> == See also == {{div col|colwidth=20em}} * [[Arbitrary-precision arithmetic]] * [[C99#IEEE 754 floating-point support|C99]] for code examples demonstrating access and use of IEEE 754 features. * [[Computable number]] * [[Coprocessor]] * [[Decimal floating point]] * [[Double-precision floating-point format]] * [[Experimental mathematics]] – utilizes high precision floating-point computations * [[Fixed-point arithmetic]] * [[Floating-point error mitigation]] * [[FLOPS]] * [[Gal's accurate tables]] * [[GNU MPFR]] * [[Half-precision floating-point format]] * [[IEEE 754]] – Standard for Binary Floating-Point Arithmetic * [[IBM hexadecimal floating-point|IBM Floating Point Architecture]] * [[Kahan summation algorithm]] * [[Microsoft Binary Format]] (MBF) * [[Minifloat]] * [[Q (number format)]] for constant resolution * [[Quadruple-precision floating-point format]] (including double-double) * [[Significant figures]] * [[Single-precision floating-point format]] * [[Standard Apple Numerics Environment|Standard Apple Numerics Environment (SANE)]] {{div col end}} == Notes == {{reflist|group="nb"|refs= <ref group="nb" name="NB_1">Computer hardware does not necessarily compute the exact value; it simply has to produce the equivalent rounded result as though it had computed the infinitely precise result.</ref> <ref group="nb" name="NB_2">The enormous complexity of modern [[division algorithm]]s once led to a famous error. An early version of the [[Intel Pentium]] chip was shipped with a [[FDIV|division instruction]] that, on rare occasions, gave slightly incorrect results. Many computers had been shipped before the error was discovered. Until the defective computers were replaced, patched versions of compilers were developed that could avoid the failing cases. See ''[[Pentium FDIV bug]]''.</ref> <ref group="nb" name="NB_3">But an attempted computation of cos(π) yields −1 exactly. Since the derivative is nearly zero near π, the effect of the inaccuracy in the argument is far smaller than the spacing of the floating-point numbers around −1, and the rounded result is exact.</ref> <ref group="nb" name="NB_4">[[William Morton Kahan|William Kahan]] notes: "Except in extremely uncommon situations, extra-precise arithmetic generally attenuates risks due to roundoff at far less cost than the price of a competent error-analyst."</ref> <ref group="nb" name="NB_5">The [[Taylor expansion]] of this function demonstrates that it is well-conditioned near 1: A(x) = 1 − (x−1)/2 + (x−1)^2/12 − (x−1)^4/720 + (x−1)^6/30240 − (x−1)^8/1209600 + ... for |x−1| < π.</ref> <ref group="nb" name="NB_6">If [[long double]] is [[IEEE quad precision]] then full double precision is retained; if long double is [[IEEE double extended precision]] then additional, but not full precision is retained.</ref> <ref group="nb" name="NB_7">The equivalence of the two forms can be verified algebraically by noting that the [[denominator]] of the fraction in the second form is the [[conjugate (algebra)|conjugate]] of the [[numerator]] of the first. By multiplying the top and bottom of the first expression by this conjugate, one obtains the second expression.</ref> <ref group="nb" name="NB_8">Octal (base-8) floating-point arithmetic is used in the [[Ferranti Atlas]] (1962)<!-- Beebe -->, [[Burroughs B5500]] (1964), [[Burroughs B5700]] (1971)<!-- Beebe -->, [[Burroughs B6700]] (1971)<!-- Beebe --> and [[Burroughs B7700]] (1972)<!-- Beebe --> computers.</ref> <ref group="nb" name="NB_9">[[Hexadecimal floating-point|Hexadecimal (base-16) floating-point]] arithmetic is used in the [[IBM System 360]] (1964) and [[IBM System 370|370]] (1970) as well as various newer IBM machines, in the [[RCA Spectra 70]] (1964), the Siemens 4004 (1965), 7.700 (1974), 7.800, 7.500 (1977) series mainframes and successors, the Unidata 7.000 series mainframes, the [[Manchester MU5]] (1972), the [[Heterogeneous Element Processor|HEP]] (1982) computers, and in 360/370-compatible mainframe families made by Fujitsu, Amdahl and Hitachi. It is also used<!-- according to Beebe --> in the [[Illinois ILLIAC III]] (1966), [[Data General Eclipse S/200]] (ca. 1974), [[Gould Powernode 9080]] (1980s), [[Interdata 8/32]] (1970s), the [[SEL System 85|SEL Systems 85]] and [[SEL System 86|86]] as well as the [[SDS Sigma 5]] (1967), [[SDS Sigma 7|7]] (1966) and [[Xerox Sigma 9]] (1970).</ref> <ref group="nb" name="NB_10">Base-65536 floating-point arithmetic is used in the [[MANIAC II]] (1956)<!-- Los Alamos --> computer.</ref> <ref group="nb" name="NB_11">Quaternary (base-4) floating-point arithmetic is used in the [[Illinois ILLIAC II]] (1962) computer.<!-- according to Beebe --> It is also used in the Digital Field System DFS IV and V high-resolution site survey systems.</ref> <ref group="nb" name="NB_12">Base-256 floating-point arithmetic is used in the [[Rice Institute R1]] computer (since 1958).<!-- according to Beebe --></ref> <ref group="nb" name="NB_Significand">{{anchor|NB-Significand}}The ''[[significand]]'' of a floating-point number is also called ''mantissa'' by some authors—not to be confused with the [[mantissa (logarithm)|mantissa]] of a [[logarithm]]. Somewhat vague, terms such as ''coefficient'' or ''argument'' are also used by some. The usage of the term ''fraction'' by some authors is potentially misleading as well. The term ''characteristic'' (as used e.g. by [[Control Data Corporation|CDC]]) is ambiguous, as it was historically also used to specify some form of [[#NB-Exponent|exponent]] of floating-point numbers.</ref> <ref group="nb" name="NB_Exponent">{{anchor|NB-Exponent}}The ''[[exponent]]'' of a floating-point number is sometimes also referred to as ''scale''. The term ''characteristic'' (for ''[[biased exponent]]'', ''exponent bias'', or ''excess n representation'') is ambiguous, as it was historically also used to specify the [[#NB-Significand|significand]] of floating-point numbers.</ref> }} == References == {{reflist|30em|refs= <ref name="Smith_1997">{{cite book |last=Smith |first=Steven W. |title=The Scientist and Engineer's Guide to Digital Signal Processing |chapter-url=http://www.dspguide.com/ch28/4.htm |access-date=2012-12-31 |date=1997 |publisher=California Technical Pub |isbn=978-0-9660176-3-2 |page=514 |chapter=Chapter 28, Fixed versus Floating Point}}</ref> <ref name="Rojas_1997">{{cite journal |title=Konrad Zuse's Legacy: The Architecture of the Z1 and Z3 |last=Rojas |first=Raúl |author-link=Raúl Rojas |journal=[[IEEE Annals of the History of Computing]] |volume=19 |number=2 |date=April–June 1997 |pages=5–16 |doi=10.1109/85.586067 |url=http://ed-thelen.org/comp-hist/Zuse_Z1_and_Z3.pdf |access-date=2022-07-03 |url-status=live |archive-url=https://web.archive.org/web/20220703082408/http://ed-thelen.org/comp-hist/Zuse_Z1_and_Z3.pdf |archive-date=2022-07-03}} (12 pages)</ref> <ref name="Rojas_2014">{{cite arXiv |eprint=1406.1886 |title=The Z1: Architecture and Algorithms of Konrad Zuse's First Computer |first=Raúl |last=Rojas |author-link=Raúl Rojas |date=2014-06-07|class=cs.AR }}</ref> <ref name="Kahan_1997_JVNL">{{cite web |url=https://people.eecs.berkeley.edu/~wkahan/SIAMjvnl.pdf |archive-url=https://web.archive.org/web/20080905103125/http://www.cs.berkeley.edu/~wkahan/SIAMjvnl.pdf |archive-date=2008-09-05 |url-status=live |title=The Baleful Effect of Computer Languages and Benchmarks upon Applied Mathematics, Physics and Chemistry. John von Neumann Lecture |first=William Morton |last=Kahan |author-link=William Morton Kahan |date=1997-07-15 |page=3}}</ref> <ref name="Randell_1982_2">{{cite book |editor-last=Randell |editor-first=Brian |editor-link=Brian Randell |title=The Origins of Digital Computers: Selected Papers |edition=3rd |publisher=[[Springer-Verlag]] |date=1982 |orig-date=1973 |location=Berlin; New York |page=244 |isbn=978-3-540-11319-5}}</ref> <ref name="Kahan_2001_JavaHurt">{{cite web |first1=William Morton |last1=Kahan |author-link1=William Morton Kahan |first2=Joseph |last2=Darcy |date=2001 |orig-date=1998-03-01 |url=https://people.eecs.berkeley.edu/~wkahan/JAVAhurt.pdf |archive-url=https://web.archive.org/web/20000816043653/http://www.cs.berkeley.edu/~wkahan/JAVAhurt.pdf |archive-date=2000-08-16 |url-status=live |title=How Java's floating-point hurts everyone everywhere |access-date=2003-09-05}}</ref> <ref name="Kahan_2004">{{cite web |url=https://people.eecs.berkeley.edu/~wkahan/Qdrtcs.pdf |archive-url=https://web.archive.org/web/20060525111157/http://www.cs.berkeley.edu/~wkahan/Qdrtcs.pdf |archive-date=2006-05-25 |url-status=live |first=William Morton |last=Kahan |author-link=William Morton Kahan |title=On the Cost of Floating-Point Computation Without Extra-Precise Arithmetic |date=2004-11-20 |access-date=2012-02-19}}</ref> <ref name="Kahan_2006_Mindless">{{cite web |url=https://people.eecs.berkeley.edu/~wkahan/Mindless.pdf |archive-url=https://web.archive.org/web/20041221020332/http://www.cs.berkeley.edu/~wkahan/Mindless.pdf |archive-date=2004-12-21 |url-status=live |title=How Futile are Mindless Assessments of Roundoff in Floating-Point Computation? |first=William Morton |last=Kahan |author-link=William Morton Kahan |date=2006-01-11}}</ref> <ref name="Severance_1998">{{cite web |url=https://people.eecs.berkeley.edu/~wkahan/ieee754status/754story.html |title=An Interview with the Old Man of Floating-Point |first=Charles |last=Severance |author-link=Charles Severance (computer scientist) |date=1998-02-20}}</ref> <ref name="Kahan_1997_Status">{{cite web |url=https://people.eecs.berkeley.edu/~wkahan/ieee754status/IEEE754.PDF |archive-url=https://web.archive.org/web/20020622093102/http://www.cs.berkeley.edu/~wkahan/ieee754status/IEEE754.PDF |archive-date=2002-06-22 |url-status=live |title=Lecture Notes on the Status of IEEE Standard 754 for Binary Floating-Point Arithmetic |first=William Morton |last=Kahan |author-link=William Morton Kahan |date=1997-10-01 |page=9}}</ref> <ref name="Intel">{{cite book |chapter-url=http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html |title=Intel 64 and IA-32 Architectures Software Developers' Manuals |volume=1 |chapter=D.3.2.1}}</ref> <ref name="Higham_2002">{{cite book |title=Accuracy and Stability of Numerical Algorithms |edition=2nd |first=Nicholas John |author-link=Nicholas Higham |last=Higham |publisher=[[Society for Industrial and Applied Mathematics]] (SIAM) |date=2002 |isbn=978-0-89871-521-7 |id=0-89871-355-2 |pages=27–28, 110–123, 493 |url=https://books.google.com/books?id=epilvM5MMxwC}}</ref> <ref name="OpenEXR">{{cite web |url=http://www.openexr.com/about.html |title=openEXR |publisher=openEXR |access-date=2012-04-25 |archive-date=2013-05-08 |archive-url=https://web.archive.org/web/20130508221152/http://www.openexr.com/about.html |url-status=dead |quote=Since the IEEE-754 floating-point specification does not define a 16-bit format, ILM created the "half" format. Half values have 1 sign bit, 5 exponent bits, and 10 mantissa bits.}}</ref><!-- Note: As this can be deduced from the documentation, "10 mantissa bits" excludes the implicit bit. So this 16-bit format was not in IEEE 754 at its creation, but it actually corresponds to the now existing binary16 format. --> <ref name="OpenEXR-half">{{cite web |url=https://openexr.com/en/latest/TechnicalIntroduction.html#the-half-data-type |title=Technical Introduction to OpenEXR – The half Data Type |publisher=openEXR |access-date=2024-04-16}}</ref> <ref name="IEEE-754_Analysis">{{cite web|url=https://christophervickery.com/IEEE-754/|title=IEEE-754 Analysis|access-date=2024-08-29}}</ref> <ref name="Goldberg_1991">{{cite journal |first=David |last=Goldberg |author-link=David Goldberg (PARC) |title=What Every Computer Scientist Should Know About Floating-Point Arithmetic |journal=[[ACM Computing Surveys]] |date=March 1991 |volume=23 |issue=1 |pages=5–48 |doi=10.1145/103162.103163 |doi-access=free |s2cid=222008826}} (With the addendum "Differences Among IEEE 754 Implementations": [https://web.archive.org/web/20171011072644/http://www.cse.msu.edu/~cse320/Documents/FloatingPoint.pdf], [https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html])</ref> <ref name="Harris">{{Cite journal |title=You're Going To Have To Think! |first=Richard |last=Harris |journal=[[Overload (magazine)|Overload]] |issue=99 |date=October 2010 |issn=1354-3172 |pages=5–10 |url=http://accu.org/index.php/journals/1702 |access-date=2011-09-24 |quote=Far more worrying is cancellation error which can yield catastrophic loss of precision.}} [http://accu.org/var/uploads/journals/overload99.pdf]</ref> <ref name="GAO report IMTEC 92-26">{{cite web |url=http://www.gao.gov/products/IMTEC-92-26 |title=Patriot missile defense, Software problem led to system failure at Dharhan, Saudi Arabia |id=GAO report IMTEC 92-26 |publisher=[[US Government Accounting Office]]}}</ref> <ref name="Skeel">{{citation |url=https://www-users.cse.umn.edu/~arnold/disasters/Patriot-dharan-skeel-siam.pdf |title=Roundoff Error and the Patriot Missile |last=Skeel |first=Robert |journal=SIAM News |volume=25 |issue=4 |page=11 |date=July 1992 |access-date=2024-11-15}}</ref> <ref name="RalstonReilly2003">{{cite book |first=James Hardy |last=Wilkinson |author-link=James Hardy Wilkinson |editor-first1=Anthony |editor-last1=Ralston |editor-first2=Edwin D. |editor-last2=Reilly |editor-first3=David |editor-last3=Hemmendinger |chapter=Error Analysis |title=Encyclopedia of Computer Science |pages=669–674 |url=https://books.google.com/books?id=OLRwQgAACAAJ |access-date=2013-05-14 |date=2003-09-08 |publisher=[[Wiley (publisher)|Wiley]] |isbn=978-0-470-86412-8}}</ref> <ref name="Einarsson_2005">{{cite book |first=Bo |last=Einarsson |title=Accuracy and reliability in scientific computing |url=https://books.google.com/books?id=sh4orx_qB_QC&pg=PA50 |access-date=2013-05-14 |date=2005 |publisher=[[Society for Industrial and Applied Mathematics]] (SIAM) |isbn=978-0-89871-815-7 |pages=50–}}</ref> <ref name="Kahan_2005_ARITH17">{{cite conference |first=William Morton |last=Kahan |author-link=William Morton Kahan |date=2005-07-15 |title=Floating-Point Arithmetic Besieged by "Business Decisions" |type=Keynote Address |conference=IEEE-sponsored [[ARITH 17]], Symposium on Computer Arithmetic |pages=6, 18 |url=https://people.eecs.berkeley.edu/~wkahan/ARITH_17.pdf |access-date=2013-05-23 |url-status=live |archive-url=https://web.archive.org/web/20060317103619/http://www.cs.berkeley.edu/~wkahan/ARITH_17.pdf |archive-date=2006-03-17}} (NB. Kahan estimates that the incidence of excessively inaccurate results near singularities is reduced by a factor of approx. 1/2000 using the 11 extra bits of precision of [[extended precision|double extended]].)</ref> <ref name="OliveiraStewart_2006">{{cite book |first1=Suely |last1=Oliveira |first2=David E. |last2=Stewart |title=Writing Scientific Software: A Guide to Good Style |url=https://books.google.com/books?id=E6a8oZOS8noC&pg=PA10 |date=2006-09-07 |publisher=[[Cambridge University Press]] |isbn=978-1-139-45862-7 |pages=10–}}</ref> <ref name="Kahan_2011_Debug">{{cite conference |url=https://people.eecs.berkeley.edu/~wkahan/Boulder.pdf |archive-url=https://web.archive.org/web/20130620140729/http://www.eecs.berkeley.edu/~wkahan/Boulder.pdf |archive-date=2013-06-20 |url-status=live |title=Desperately Needed Remedies for the Undebuggability of Large Floating-Point Computations in Science and Engineering |conference=IFIP/SIAM/NIST Working Conference on Uncertainty Quantification in Scientific Computing, Boulder, CO |page=33 |first=William Morton |last=Kahan |author-link=William Morton Kahan |date=2011-08-03}}</ref> <ref name="Kahan_1981_WhyIEEE">{{cite web |url=https://people.eecs.berkeley.edu/~wkahan/ieee754status/why-ieee.pdf |archive-url=https://web.archive.org/web/20041204070746/http://www.cs.berkeley.edu/~wkahan/ieee754status/why-ieee.pdf |archive-date=2004-12-04 |url-status=live |title=Why do we need a floating-point arithmetic standard? |page=26 |first=William Morton |last=Kahan |author-link=William Morton Kahan |date=1981-02-12}}</ref> <ref name="Kahan_2001_LN">{{cite web|url=http://www.cims.nyu.edu/~dbindel/class/cs279/notes-06-04.pdf |archive-url=https://web.archive.org/web/20130517181356/http://www.cims.nyu.edu/~dbindel/class/cs279/notes-06-04.pdf |archive-date=2013-05-17 |url-status=live |first=William Morton |last=Kahan |author-link=William Morton Kahan |editor-first=David |editor-last=Bindel |title=Lecture notes of System Support for Scientific Computation |date=2001-06-04}}</ref> <ref name="Speleotrove_2012">{{cite web |url=https://speleotrove.com/decimal/ |title=General Decimal Arithmetic |publisher=Speleotrove.com |access-date=2012-04-25}}</ref> <ref name="Kahan_2000_Marketing">{{cite web |url=https://people.eecs.berkeley.edu/~wkahan/MktgMath.pdf |archive-url=https://web.archive.org/web/20030815150333/http://www.cs.berkeley.edu/~wkahan/MktgMath.pdf |archive-date=2003-08-15 |url-status=live |title=Marketing versus Mathematics |pages=15, 35, 47 |first=William Morton |last=Kahan |author-link=William Morton Kahan |date=2000-08-27}}</ref> <ref name="Shewchuk">{{cite journal | title=Adaptive Precision Floating-Point Arithmetic and Fast Robust Geometric Predicates | journal=[[Discrete & Computational Geometry]] | volume=18 | pages=305–363 |first=Jonathan Richard |last=Shewchuk |date=1997 | issue=3 | doi=10.1007/PL00009321 | doi-access=free}}</ref> <ref name="Christiansen_Perl">{{cite web |url=https://perldoc.perl.org/5.8.8/perlfaq4#Why-is-int()-broken? |title=perlfaq4 / Why is int() broken? |first1=Tom |last1=Christiansen |first2=Nathan |last2=Torkington |date=2006 |publisher=perldoc.perl.org |access-date=2011-01-11 |display-authors=etal}}</ref> <ref name="Kahan_1997_Cantilever">{{cite web |url=https://people.eecs.berkeley.edu/~wkahan/Cantilever.pdf |archive-url=https://web.archive.org/web/20031205191038/http://www.cs.berkeley.edu/~wkahan/Cantilever.pdf |archive-date=2003-12-05 |url-status=live |title=Roundoff Degrades an Idealized Cantilever |first1=William Morton |last1=Kahan |author-link1=William Morton Kahan |first2=Melody Y. |last2=Ivory |date=1997-07-03}}</ref> <ref name="Muller_2010">{{cite book |last1=Muller |first1=Jean-Michel |last2=Brisebarre |first2=Nicolas |last3=de Dinechin |first3=Florent |last4=Jeannerod |first4=Claude-Pierre |last5=Lefèvre |first5=Vincent |last6=Melquiond |first6=Guillaume |last7=Revol |first7=Nathalie|author7-link=Nathalie Revol |last8=Stehlé |first8=Damien |last9=Torres |first9=Serge |title=Handbook of Floating-Point Arithmetic<!-- |chapter=Chapter 2, Definitions and Basic Notions--> |date=2010 |publisher=[[Birkhäuser]] |edition=1st |isbn=978-0-8176-4704-9<!-- print --> |doi=10.1007/978-0-8176-4705-6 |lccn=2009939668 <!-- |page=16 --> |ref=muller_et_al_pg_16 |url=https://books.google.com/books?id=baFvrIOPvncC&pg=PA16}}</ref> <ref name="Savard_2018">{{citation |title=The Decimal Floating-Point Standard |first=John J. G. |last=Savard |date=2018 |orig-date=2007 |work=quadibloc |url=http://www.quadibloc.com/comp/cp020302.htm |access-date=2018-07-16 |url-status=live |archive-url=https://web.archive.org/web/20180703002322/http://www.quadibloc.com/comp/cp020302.htm |archive-date=2018-07-03}}</ref> <ref name="Zehendner_2008">{{cite web |type=Lecture script |title=Rechnerarithmetik: Fest- und Gleitkommasysteme |date=Summer 2008 |first=Eberhard |last=Zehendner |language=de |publisher=[[Friedrich-Schiller-Universität Jena]] |page=2 |url=https://users.fmi.uni-jena.de/~nez/rechnerarithmetik_5/folien/Rechnerarithmetik.2008.05.handout.pdf |access-date=2018-08-07 |url-status=live |archive-url=https://web.archive.org/web/20180807062449/https://users.fmi.uni-jena.de/~nez/rechnerarithmetik_5/folien/Rechnerarithmetik.2008.05.handout.pdf |archive-date=2018-08-07}} [https://web.archive.org/web/20180806175620/https://users.fmi.uni-jena.de/~nez/rechnerarithmetik_5/folien/Rechnerarithmetik.2008.komplett.pdf] (NB. This reference incorrectly gives the MANIAC II's floating point base as 256, whereas it actually is 65536.)</ref> <ref name="Lazarus_1956">{{cite web |title=MANIAC II |first=Roger B. |last=Lazarus |date=1957-01-30 |orig-date=1956-10-01 |publisher=Los Alamos Scientific Laboratory of the University of California |location=Los Alamos, NM, USA |id=LA-2083 |page=14 |url=http://bitsavers.org/pdf/lanl/LA-2083_MANIAC_II_Oct56.pdf |access-date=2018-08-07 |archive-url=https://web.archive.org/web/20180807200914/http://bitsavers.org/pdf/lanl/LA-2083_MANIAC_II_Oct56.pdf |archive-date=2018-08-07 |url-status=live |quote=[…] the Maniac's floating base, which is 2<sup>16</sup> = 65,536. […] The Maniac's large base permits a considerable increase in the speed of floating point arithmetic. Although such a large base implies the possibility of as many as 15 lead zeros, the large word size of 48 bits guarantees adequate significance. […]}}</ref> <ref name="Beebe_2017">{{cite book |first=Nelson H. F. |last=Beebe |title=The Mathematical-Function Computation Handbook - Programming Using the MathCW Portable Software Library |chapter=Chapter H. Historical floating-point architectures |date=2017-08-22 |location=Salt Lake City, UT, USA |publisher=[[Springer International Publishing AG]] |edition=1st |lccn=2017947446 |isbn=978-3-319-64109-6 |doi=10.1007/978-3-319-64110-2 |page=948|s2cid=30244721 }}</ref> <ref name="Parkinson_2000">{{cite book |title=High Resolution Site Surveys |first=Roger |last=Parkinson |publisher=[[CRC Press]] |date=2000-12-07 |chapter=Chapter 2 - High resolution digital site survey systems - Chapter 2.1 - Digital field recording systems |edition=1st |isbn=978-0-20318604-6 |page=24 |chapter-url=https://books.google.com/books?id=Ocip5vpLD4wC&pg=PA24 |access-date=2019-08-18 |quote=[…] Systems such as the [Digital Field System] DFS IV and DFS V were quaternary floating-point systems and used gain steps of 12 dB. […]}} (256 pages)</ref> <ref name="MSVC">{{cite web |url=https://learn.microsoft.com/en-us/cpp/build/ieee-floating-point-representation |title=IEEE Floating-Point Representation |date=2021-08-03}}</ref> <ref name="GCC">[https://gcc.gnu.org/onlinedocs/gcc/i386-and-x86-64-Options.html Using the GNU Compiler Collection, i386 and x86-64 Options] {{Webarchive |url=https://web.archive.org/web/20150116065447/http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86-64-Options.html |date=2015-01-16}}.</ref> <ref name="float_128">{{cite web |url=https://stackoverflow.com/questions/13516476 |title=long double (GCC specific) and __float128 |website=StackOverflow}}</ref> <ref name="ARM_2013_AArch64">{{cite web |title=Procedure Call Standard for the ARM 64-bit Architecture (AArch64) |url=http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055b/IHI0055B_aapcs64.pdf |archive-url=https://web.archive.org/web/20130731181404/http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055b/IHI0055B_aapcs64.pdf |archive-date=2013-07-31 |url-status=live |date=2013-05-22 |access-date=2019-09-22}}</ref> <ref name="ARM_2013_Compiler">{{cite web |title=ARM Compiler toolchain Compiler Reference, Version 5.03 |url=http://infocenter.arm.com/help/topic/com.arm.doc.dui0491i/DUI0491I_arm_compiler_reference.pdf |archive-url=https://web.archive.org/web/20150627210618/http://infocenter.arm.com/help/topic/com.arm.doc.dui0491i/DUI0491I_arm_compiler_reference.pdf |archive-date=2015-06-27 |url-status=live |at=Section 6.3 ''Basic data types'' |date=2013 |access-date=2019-11-08}}</ref> <ref name="Kharya_2020">{{Cite web |title=TensorFloat-32 in the A100 GPU Accelerates AI Training, HPC up to 20x |url=https://blogs.nvidia.com/blog/2020/05/14/tensorfloat-32-precision-format/ |last=Kharya |first=Paresh |date=May 14, 2020 |access-date=May 16, 2020}}</ref> <ref name="Sierra_1962">{{US patent reference |number=3037701A |issue-date=1962-06-05 |inventor=Huberto M Sierra |title=Floating decimal point arithmetic control means for calculator}}</ref> <ref name="Barker">Christopher Barker: [https://www.python.org/dev/peps/pep-0485/ ''PEP 485 -- A Function for testing approximate equality'']</ref> <ref name="C99">{{cite book |title=ISO/IEC 9899:1999 - Programming languages - C |publisher=Iso.org |at=§F.2, note 307 |quote="Extended" is IEC 60559's double-extended data format. Extended refers to both the common 80-bit and quadruple 128-bit IEC 60559 formats.}}</ref> <ref name="Microsoft_2006_KB35826">{{cite web |title=IEEE vs. Microsoft Binary Format; Rounding Issues (Complete) |publisher=[[Microsoft]] |work=Microsoft Support |id=Article ID KB35826, Q35826 |date=2006-11-21 |url=https://www.betaarchive.com/wiki/index.php/Microsoft_KB_Archive/35826#IEEE_vs._Microsoft_Binary_Format.3B_Rounding_Issues_.28Complete.29 |access-date=2010-02-24 |url-status=live |archive-url=https://web.archive.org/web/20200828130651/https://www.betaarchive.com/wiki/index.php/Microsoft_KB_Archive/35826 |archive-date=2020-08-28}}</ref> <ref name="Steil_2008_6502">{{cite web |title=Create your own Version of Microsoft BASIC for 6502 |first=Michael |last=Steil |publisher=pagetable.com |date=2008-10-20 |url=http://www.pagetable.com/?p=46 |access-date=2016-05-30 |url-status=live |archive-url=https://web.archive.org/web/20160530092603/http://www.pagetable.com/?p=46 |archive-date=2016-05-30}}</ref> <ref name="Borland_1994_MBF">{{cite web |title=Converting between Microsoft Binary and IEEE formats |date=1998-07-02 |orig-date=1994-03-10 |id=ID 1400 |author=Borland staff |publisher=[[Embarcadero USA]] / [[Inprise]] (originally: [[Borland]]) |work=Technical Information Database |type=TI1431C.txt |url=https://community.embarcadero.com/index.php/article/technical-articles/162-programming/14799-converting-between-microsoft-binary-and-ieee-forma |access-date=2016-05-30 |url-status=live |archive-url=https://web.archive.org/web/20190220230417/https://community.embarcadero.com/index.php/article/technical-articles/162-programming/14799-converting-between-microsoft-binary-and-ieee-forma |archive-date=2019-02-20 |quote=[…] _fmsbintoieee(float *src4, float *dest4) […] MS Binary Format […] byte order => m3 {{!}} m2 {{!}} m1 {{!}} exponent […] m1 is [[most significant byte]] => sbbb{{!}}bbbb […] m3 is the [[least significant byte]] […] m = mantissa byte […] s = sign bit […] b = bit […] MBF is bias 128 and IEEE is bias 127. […] MBF places the [[decimal point]] before the [[assumed bit]], while IEEE places the decimal point after the assumed bit. […] ieee_exp = msbin[3] - 2; /* actually, msbin[3]-1-128+127 */ […] _dmsbintoieee(double *src8, double *dest8) […] MS Binary Format […] byte order => m7 {{!}} m6 {{!}} m5 {{!}} m4 {{!}} m3 {{!}} m2 {{!}} m1 {{!}} exponent […] m1 is most significant byte => smmm{{!}}mmmm […] m7 is the least significant byte […] MBF is bias 128 and IEEE is bias 1023. […] MBF places the decimal point before the assumed bit, while IEEE places the decimal point after the assumed bit. […] ieee_exp = msbin[7] - 128 - 1 + 1023; […]}}</ref> <ref name="NVIDIA_Hopper">{{cite web |title=NVIDIA Hopper Architecture In-Depth |date=22 March 2022 |url=https://developer.nvidia.com/blog/nvidia-hopper-architecture-in-depth/}}</ref> <ref name="Micikevicius_2022">{{cite arXiv |last1=Micikevicius |first1=Paulius |last2=Stosic |first2=Dusan |last3=Burgess |first3=Neil |last4=Cornea |first4=Marius |last5=Dubey |first5=Pradeep |last6=Grisenthwaite |first6=Richard |last7=Ha |first7=Sangwon |last8=Heinecke |first8=Alexander |last9=Judd |first9=Patrick |last10=Kamalu |first10=John |last11=Mellempudi |first11=Naveen |last12=Oberman |first12=Stuart |last13=Shoeybi |first13=Mohammad |last14=Siu |first14=Michael |last15=Wu |first15=Hao |eprint=2209.05433 |title=FP8 Formats for Deep Learning |class=cs.LG |date=2022-09-12}}</ref> <ref name="Gay_1990">{{cite tech report |last=Gay |first=David M. |title=Correctly Rounded Binary-Decimal and Decimal-Binary Conversions |date=1990 |institution=NUMERICAL ANALYSIS MANUSCRIPT 90-10, AT&T BELL LABORATORIES |citeseerx=10.1.1.31.4049}} ([http://www.netlib.org/fp/dtoa.c dtoa.c in netlab])</ref> <ref name="Loitsch_2010">{{cite conference |last=Loitsch |first=Florian |title=Printing floating-point numbers quickly and accurately with integers |conference=PLDI '10: ACM SIGPLAN Conference on Programming Language Design and Implementation |book-title=Proceedings of the 31st ACM SIGPLAN Conference on Programming Language Design and Implementation |date=2010 |pages=233–243 |doi=10.1145/1806596.1806623 |isbn=978-1-45030019-3 |s2cid=910409 |url=https://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf |archive-url=https://web.archive.org/web/20140729005717/http://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf |archive-date=2014-07-29 |url-status=live }}</ref> <ref name="mazong">{{cite web |title=Added Grisu3 algorithm support for double.ToString(). by mazong1123 · Pull Request #14646 · dotnet/coreclr |url=https://github.com/dotnet/coreclr/pull/14646 |website=GitHub |language=en}}</ref> <ref name="Adams_2018">{{cite journal |last=Adams |first=Ulf |title=Ryū: fast float-to-string conversion |journal=ACM SIGPLAN Notices |date=2 December 2018 |volume=53 |issue=4 |pages=270–282 |doi=10.1145/3296979.3192369 |s2cid=218472153 |doi-access=free}}</ref> <ref name="Giulietti">{{cite web |last=Giulietti |first=Rafaello |title=The Schubfach way to render doubles |url=https://drive.google.com/file/d/1IEeATSVnEE6TkrHlCYNY2GjaraBjOT4f}}</ref> <ref name="abolz">{{cite web |title=abolz/Drachennest |website=[[GitHub]] |url=https://github.com/abolz/Drachennest |date=10 November 2022}}</ref> <ref name="double_conversion_2020">{{cite web |title=google/double-conversion |website=[[GitHub]] |url=https://github.com/google/double-conversion |date=21 September 2020}}</ref> <ref name="Lemire_2021">{{cite journal |last=Lemire |first=Daniel |title=Number parsing at a gigabyte per second |journal=Software: Practice and Experience |date=22 March 2021 |volume=51 |issue=8 |pages=1700–1727 |doi=10.1002/spe.2984 |arxiv=2101.11408 |s2cid=231718830}}</ref> <ref name="Patterson-Hennessy_2014">{{cite book |last1=Patterson |first1=David A. |last2=Hennessy |first2=John L. |title=Computer Organization and Design, The Hardware/Software Interface |publisher=Elsevier |series=The Morgan Kaufmann series in computer architecture and design |edition=5th |date=2014 |location=Waltham, Massachusetts, USA |pages=793 |language=en |isbn=978-9-86605267-5}}<!-- {{rp|218–220}} --></ref> <ref name="Vectorizers">{{cite web |title=Auto-Vectorization in LLVM |url=https://llvm.org/docs/Vectorizers.html |website=LLVM 13 documentation |quote=We support floating point reduction operations when -ffast-math is used.}}</ref> <ref name="FPM">{{cite web |title=FloatingPointMath |url=https://gcc.gnu.org/wiki/FloatingPointMath |website=GCC Wiki}}</ref> <ref name="harmful">{{cite web |title=55522 – -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared |url=https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55522 |website=gcc.gnu.org}}</ref> <ref name="Gen">{{cite web |title=Code Gen Options (The GNU Fortran Compiler) |url=https://gcc.gnu.org/onlinedocs/gfortran/Code-Gen-Options.html |website=gcc.gnu.org}}</ref> <ref name="zheevd">{{cite web |title=Bug in zheevd · Issue #43 · Reference-LAPACK/lapack |url=https://github.com/Reference-LAPACK/lapack/issues/43 |website=GitHub |language=en}}</ref> <ref name="Becker-Darulova-Myreen-Tatlock_2019">{{cite conference |last1=Becker |first1=Heiko |last2=Darulova |first2=Eva |last3=Myreen |first3=Magnus O. |last4=Tatlock |first4=Zachary |title=Icing: Supporting Fast-Math Style Optimizations in a Verified Compiler |conference=CAV 2019: Computer Aided Verification |date=2019 |volume=11562 |pages=155–173 |doi=10.1007/978-3-030-25543-5_10 |doi-access=free}}</ref> }} == Further reading == * {{cite book |first=James Hardy |last=Wilkinson |author-link=James Hardy Wilkinson |title=Rounding Errors in Algebraic Processes |date=1963 |publisher=[[Prentice-Hall, Inc.]] |location=Englewood Cliffs, New Jersey, USA |edition=1st |mr=161456 |url=https://books.google.com/books?id=yFogU9Ot-qsC |isbn=9780486679990}} (NB. Classic influential treatises on floating-point arithmetic.) * {{cite book |first=James Hardy |last=Wilkinson |author-link=James Hardy Wilkinson |title=The Algebraic Eigenvalue Problem |series=Monographs on Numerical Analysis |date=1965 |edition=1st |publisher=[[Oxford University Press]] / [[Clarendon Press]] |url=https://books.google.com/books?id=N98IAQAAIAAJ&q=editions:ISBN0198534183 |access-date=2016-02-11|isbn=9780198534037 }} * {{cite book |first=Pat H. |last=Sterbenz |title=Floating-Point Computation |date=1974 |edition=1st |series=Prentice-Hall Series in Automatic Computation |publisher=[[Prentice Hall]] |location=Englewood Cliffs, New Jersey, USA |isbn=978-0-13-322495-5}} * {{cite book |first1=Gene F. |last1=Golub |first2=Charles F. |last2=van Loan |title=Matrix Computations |edition=3rd |publisher=[[Johns Hopkins University Press]] |date=1986 |isbn=978-0-8018-5413-2}} * {{cite book |title=Numerical Recipes - The Art of Scientific Computing |title-link=Numerical Recipes |first1=William Henry |last1=Press |author-link1=William Henry Press |first2=Saul A. |last2=Teukolsky |author-link2=Saul A. Teukolsky |first3=William T. |last3=Vetterling |author-link3=William T. Vetterling |first4=Brian P. |last4=Flannery |author-link4=Brian P. Flannery |edition=3rd |date=2007 |orig-date=1986 |isbn=978-0-521-88407-5 |publisher=[[Cambridge University Press]]}} (NB. Edition with source code CD-ROM.) * {{cite book |first=Donald Ervin |last=Knuth |author-link=Donald Ervin Knuth |title=[[The Art of Computer Programming]]'', Vol. 2: ''Seminumerical Algorithms |edition=3rd |publisher=[[Addison-Wesley]] |date=1997 |isbn=978-0-201-89684-8 |chapter=Section 4.2: Floating-Point Arithmetic |pages=214–264}} * {{cite book |first1=Gerrit Anne |last1=Blaauw |author-link1=Gerrit Anne Blaauw |first2=Frederick Phillips |last2=Brooks, Jr. |author-link2=Frederick Phillips Brooks, Jr. |title=Computer Architecture: Concepts and Evolution |publisher=[[Addison-Wesley]] |date=1997 |edition=1st |isbn=0-201-10557-8}} (1213 pages) (NB. This is a single-volume edition. This work was also available in a two-volume version.) * {{cite book | first1=Peter | last1=Kornerup | first2=David W. | last2=Matula | date=2010 | title=Finite Precision Number Systems and Arithmetic | isbn=978-0-521-76135-2 | publisher=[[Cambridge University Press]]}} * {{citation |title=Floating-Point Formats |first=John J. G. |last=Savard |date=2018 |orig-date=2005 |work=quadibloc |url=http://www.quadibloc.com/comp/cp0201.htm |access-date=2018-07-16 |url-status=live |archive-url=https://web.archive.org/web/20180703001709/http://www.quadibloc.com/comp/cp0201.htm |archive-date=2018-07-03}} * {{cite book |last1=Muller |first1=Jean-Michel |last2=Brunie |first2=Nicolas |last3=de Dinechin |first3=Florent |last4=Jeannerod |first4=Claude-Pierre |first5=Mioara |last5=Joldes |last6=Lefèvre |first6=Vincent |last7=Melquiond |first7=Guillaume |last8=Revol |first8=Nathalie|author8-link=Nathalie Revol |last9=Torres |first9=Serge |title=Handbook of Floating-Point Arithmetic |date=2018 |orig-date=2010 |publisher=[[Birkhäuser]] |edition=2nd |isbn=978-3-319-76525-9 |lccn=2018935254 |doi=10.1007/978-3-319-76526-6 |url=https://books.google.com/books?id=h3ZZDwAAQBAJ}} == External links == * {{cite web |url=http://www.mrob.com/pub/math/floatformats.html |title=Survey of Floating-Point Formats}} (NB. This page gives a very brief summary of floating-point formats that have been used over the years.) * {{cite journal |url=https://hal.science/hal-00128124/en/ |title=The pitfalls of verifying floating-point computations |first=David |last=Monniaux |journal=ACM Transactions on Programming Languages and Systems |publisher=[[Association for Computing Machinery]] (ACM) Transactions on programming languages and systems (TOPLAS) |date=May 2008 |volume=30 |issue=3 |pages=1–41 |doi=10.1145/1353445.1353446 |arxiv=cs/0701192 |s2cid=218578808}} (NB. A compendium of non-intuitive behaviors of floating point on popular architectures, with implications for program verification and testing.) * [https://opencores.org/ OpenCores]. (NB. This website contains open source floating-point IP cores for the implementation of floating-point operators in FPGA or ASIC devices. The project ''double_fpu'' contains verilog source code of a double-precision floating-point unit. The project ''fpuvhdl'' contains vhdl source code of a single-precision floating-point unit.) * {{cite web |url=http://msdn.microsoft.com/en-us/library/aa289157(v=vs.71).aspx |title=Microsoft Visual C++ Floating-Point Optimization |first=Eric |last=Fleegal |publisher=[[Microsoft Developer Network]] |date=2004 |archive-url=https://web.archive.org/web/20170706020455/http://msdn.microsoft.com/en-us/library/aa289157(v=vs.71).aspx |url-status=dead |archive-date=2017-07-06}} {{Data types}} [[Category:Floating point| ]] [[Category:Computer arithmetic]] [[Category:Articles with example C code]]
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)
Pages transcluded onto the current version of this page
(
help
)
:
Template:10^
(
edit
)
Template:Anchor
(
edit
)
Template:Block indent
(
edit
)
Template:Citation
(
edit
)
Template:Citation needed
(
edit
)
Template:Cite book
(
edit
)
Template:Cite journal
(
edit
)
Template:Cite web
(
edit
)
Template:Clarify
(
edit
)
Template:Code
(
edit
)
Template:Data types
(
edit
)
Template:Div col
(
edit
)
Template:Div col end
(
edit
)
Template:E
(
edit
)
Template:Floating-point
(
edit
)
Template:Fontcolor
(
edit
)
Template:Further
(
edit
)
Template:ISBN
(
edit
)
Template:Main
(
edit
)
Template:Math
(
edit
)
Template:Mvar
(
edit
)
Template:Overline
(
edit
)
Template:Redirect
(
edit
)
Template:Reflist
(
edit
)
Template:Rp
(
edit
)
Template:See also
(
edit
)
Template:Sfn
(
edit
)
Template:Short description
(
edit
)
Template:Ulist
(
edit
)
Template:Use dmy dates
(
edit
)
Template:Val
(
edit
)