text:
Floating-point arithmetic

In computing, floating-point arithmetic (FP) is arithmetic that represents subsets of real numbers using an integer with a fixed precision, called the significand, scaled by an integer exponent of a fixed base. Numbers of this form are called floating-point numbers. For example, 12.345 is a floating-point number in base ten with five digits of precision:

$$12.345 = \! \underbrace{12345}_\text{significand} \! \times \! \underbrace{10}_\text{base}\!\!\!\!\!\!\!\overbrace{{}^{-3}}^{\text{exponent}}$$

However, unlike 12.345, 12.3456 is not a floating-point number in base ten with five digits of precision—it needs six digits of precision; the nearest floating-point number with only five digits is 12.346. In practice, most floating-point systems use 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. For example, in a floating-point arithmetic with five base-ten digits of precision, 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 — such as the number of meters between galaxies or 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.

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.

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 "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 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 is $152,853.505$ seconds, a value that would be represented in standard-form scientific notation as $1.529$ 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 base (or radix). This digit string is referred to as the significand, mantissa, or coefficient. 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), 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 notation) as an example, the number $152,853.505$, which has ten decimal digits of precision, is represented as the significand $1,528,535,047$ 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 to give $1.529$, or $152,853.505$. 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: $$\frac{s}{b^{\,p-1}} \times b^e,$$

where $s$ is the significand (ignoring any implied decimal point), $p$ is the precision (the number of digits in the significand), $b$ is the base (in our example, this is the number ten), and $e$ is the exponent.

Historically, several number bases have been used for representing floating-point numbers, with base two (binary) being the most common, followed by base ten (decimal floating point), and other less common varieties, such as base sixteen (hexadecimal floating point  ), base eight (octal floating point     ), base four (quaternary floating point   ), base three (balanced ternary floating point ) and even base 256  and base $65,536$.

A floating-point number is a rational number, because it can be represented as one integer divided by another; for example $1.45$ is (145/100)×1000 or $145,000$/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 ($0.2$, or $2$). However, 1/3 cannot be represented exactly by either binary (0.010101...) or decimal (0.333...), but in base 3, it is trivial (0.1 or 1×3−1). The occasions on which infinite expansions occur depend on the base and its prime factors.

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, $$p = 24$$, and so the significand is a string of 24 bits. For instance, the number π's first 33 bits are: $$11001001\ 00001111\ 1101101\underline{0}\ 10100010\ 0.$$

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 $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 specific rules for halfway values, which is not the case here). This bit, which is $1$ in this example, is added to the integer formed by the leftmost 24 bits, yielding: $$11001001\ 00001111\ 1101101\underline{1}.$$

When this is stored in memory using the IEEE 754 encoding, this becomes the significand $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: $$\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.5707964 \times 2 \\ \approx{} &3.1415928 \end{align}$$

where $p$ is the precision ($24$ in this example), $n$ is the position of the bit of the significand from the left (starting at $0$ and finishing at $23$ here) and $e$ is the exponent ($1$ in this example).

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 $0$ and $1$), this non-zero digit is necessarily $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, 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 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 systems (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 (LI and SLI) of Charles Clenshaw, Frank Olver and Peter Turner is a scheme based on a generalized logarithm representation.
 * Tapered floating-point representation, which does not appear to be used in practice.
 * 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 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 systems such as Mathematica, Maxima, and Maple can often handle irrational numbers like $$\pi$$ or $$\sqrt{3}$$ in a completely "formal" way (symbolic computation), without dealing with a specific encoding of the significand. Such a program can evaluate expressions like "$$\sin (3\pi)$$" exactly, because it is programmed to process the underlying mathematics directly, instead of using approximate values for each intermediate calculation.

History
In 1914, the Spanish engineer Leonardo Torres Quevedo published Essays on Automatics, 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 x 10$$^m$$, 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 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 Electromechanical Arithmometer in 1920.

In 1938, Konrad Zuse of Berlin completed the Z1, the first binary, programmable mechanical computer; 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. The more reliable relay-based Z3, completed in 1941, has representations for both positive and negative infinities; in particular, it implements defined operations with infinity, such as $$^1/_\infty = 0$$, and it stops on undefined operations, such as $$0 \times \infty$$.

Zuse also proposed, but did not complete, carefully rounded floating-point arithmetic that includes $$\pm\infty$$ and NaN representations, anticipating features of the IEEE Standard by four decades. In contrast, von Neumann recommended against floating-point numbers for the 1951 IAS machine, arguing that fixed-point arithmetic is preferable.

The first commercial computer with floating-point hardware was Zuse's Z4 computer, designed in 1942–1945. In 1946, Bell Laboratories introduced the Model V, which implemented decimal floating-point numbers.

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 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 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 had become commonplace. This standard was significantly based on a proposal from Intel, which was designing the i8087 numerical coprocessor; Motorola, which was designing the 68000 around the same time, gave significant input as well.

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

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 exceptional conditions (overflow, 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 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 (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 210 = 1024, the complete range of the positive normal floating-point numbers in this format is from 2−1022 ≈ 2 × 10−308 to approximately 21024 ≈ 2 × 10308.

The number of normal floating-point numbers in a system (B, P, L, U) where is $$2 \left(B - 1\right) \left(B^{P-1}\right) \left(U - L + 1\right)$$.
 * 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,

There is a smallest positive normal floating-point number,
 * Underflow level = UFL = $$B^L$$,

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 = $$\left(1 - B^{-P}\right)\left(B^{U + 1}\right)$$,

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, positive and negative zeros, as well as subnormal numbers.

IEEE 754: floating point in modern computers
The 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 revised in 2008. IBM mainframes support 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 SV1 still uses Cray floating-point format.

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:
 * Single precision (binary32), usually used to represent the "float" 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 (binary64), usually used to represent the "double" 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).
 * 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 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". 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. For alignment purposes, many tools store this 80-bit value in a 96-bit or 128-bit space. On other processors, "long double" may stand for a larger format, such as quadruple precision, or just double precision, if any form of extended precision is not available.

Increasing the precision of the floating-point representation generally reduces the amount of accumulated round-off error caused by intermediate calculations. Other IEEE formats include:

 * Decimal64 and decimal128 floating-point formats. These formats (especially decimal128) are pervasive in financial transactions because, along with the decimal32 format, they allow correct decimal rounding.
 * 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, also called binary16, a 16-bit floating-point value. It is being used in the NVIDIA Cg graphics language, and in the openEXR standard (where it actually predates the introduction in the IEEE 754 standard).

Any integer with absolute value less than 224 can be exactly represented in the single-precision format, and any integer with absolute value less than 253 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 ($+∞$), negative infinity ($−∞$), a negative zero (−0) distinct from ordinary ("positive") zero, and "not a number" values (NaNs).

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 $+∞$ and strictly greater than $−∞$, 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 the significand or mantissa, from left to right. For the IEEE 754 binary formats (basic and extended) which have extant hardware implementations, they are apportioned as follows:

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 numbers; 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 1 bit of a normalized significand is not actually stored in the computer datum. 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, and quad has 113.

For example, it was shown above that π, rounded to 24 bits of precision, has: The sum of the exponent bias (127) and the exponent (1) is 128, so this is represented in the single-precision format as
 * sign = 0 ; e = 1 ; s = 110010010000111111011011 (including the hidden bit)
 * 0 10000000 10010010000111111011011 (excluding the hidden bit) = 40490FDB as a hexadecimal number.

An example of a layout for 32-bit floating point is and the 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 (MBF) was developed for the Microsoft BASIC language products, including Microsoft's first ever product the Altair BASIC (1975), 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 //, 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"),  the MBF extended-precision format (40 bits, "9-digit BASIC"), and the MBF double-precision format (64 bits);  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 format requires the same amount of memory (16 bits) as the IEEE 754 half-precision format, but allocates 8 bits to the exponent instead of 5, thus providing the same range as a 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 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 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.
 * The 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).

Representable numbers, conversion and rounding
By their nature, all numbers expressed in floating-point format are rational numbers 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 π or √2, 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 × 101 or 12345679 × 101), the same applies to 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.

As a further example, the real number π, 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.1415927410125732421875,

whereas a more accurate approximation of the true value of π is
 * 3.14159265358979323846264338327950...

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.45a70c22hex and 1.45a70c24hex, the ULP is 2×16−8, or 2−31. 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−23 or about 10−7 in single precision, and exactly 2−53 or about 10−16 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 (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. 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.

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.
 * Grisu3, with a 4× speedup as it removes the use of bignums. Must be used with a fallback, as it fails for ~0.5% of cases.
 * Errol3, an always-succeeding algorithm similar to, but slower than, Grisu3. Apparently not as good as an early-terminating Grisu with fallback.
 * Ryū, an always-succeeding algorithm that is faster and simpler than Grisu3.
 * Schubfach, an always-succeeding algorithm that is based on a similar idea to Ryū, developed almost simultaneously and independently. Performs better than Ryū and Grisu3 in certain benchmarks.

Many modern language runtimes use Grisu3 with a Dragon4 fallback.

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). Further work has likewise progressed in the direction of faster parsing.

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

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

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. In practice, the way these operations are carried out in digital logic can be quite complex (see Booth's multiplication algorithm and Division algorithm). For a fast, simple method, see the Horner method.

Literal syntax
Literals for floating-point numbers depend on languages. They typically use  or   to denote scientific notation. The C programming language and the IEEE 754 standard also define a hexadecimal literal syntax with a base-2 exponent instead of 10. In languages like 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). In these cases, digit strings such as  may also be floating-point literals.

Examples of floating-point literals are:
 * in C and IEEE 754
 * in C and IEEE 754
 * in C and IEEE 754
 * in C and IEEE 754
 * in C and IEEE 754

Dealing with exceptional cases
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 numbers).
 * 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), underflow (exponent too small) or denormalization (precision loss).

Prior to the IEEE standard, such conditions usually caused the program to terminate, or triggered some kind of trap that the programmer might be able to catch. How this worked was system-dependent, meaning that floating-point programs were not 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" 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 means outside of the standard (e.g. 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"): 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. 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 $$R_\text{tot}=1/(1/R_1+1/R_2+\cdots+1/R_n)$$. If a short-circuit develops with $$R_1$$ set to 0, $$1/R_1$$ will return +infinity which will give a final $$R_{tot}$$ of 0, as expected (see the continued fraction example of 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 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.
 * 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 real-valued result cannot be returned e.g. sqrt(−1) or 0/0, returning a quiet NaN.

Accuracy problems
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 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 $e = −4$; $s = 110011001100110011001101$, which is

0.100000001490116119384765625 exactly.

Squaring this number gives

0.010000000298023226097399174250313080847263336181640625 exactly.

Squaring it with rounding to the 24-bit precision gives

But the representable number closest to 0.01 is

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: will give a result of 16331239353195370.0. In single precision (using the  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 in double precision, or −0.8742 in single precision.

While floating-point addition and multiplication are both commutative ($a + b = b + a$ and $a × b = b × a$), they are not necessarily associative. That is, $(a + b) + c$ is not necessarily equal to $a + (b + 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. That is, $(a + b) × c$ may not be the same as $a × c + b × 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:

Incidents

 * On 25 February 1991, a loss of significance in a MIM-104 Patriot missile battery prevented it from intercepting an incoming Scud missile in Dhahran, Saudi Arabia, contributing to the death of 28 soldiers from the U.S. Army's 14th Quartermaster Detachment.

Machine precision and backward error analysis
Machine precision is a quantity that characterizes the accuracy of a floating-point system, and is used in backward error analysis of floating-point algorithms. It is also known as unit roundoff or machine epsilon. Usually denoted $h$, its value depends on the particular rounding being used.

With rounding to zero, $$\Epsilon_\text{mach} = B^{1-P},\,$$ whereas rounding to nearest, $$\Epsilon_\text{mach} = \tfrac{1}{2} B^{1-P},$$ 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 $h$ within the normalized range of a floating-point system: $$\left| \frac{\operatorname{fl}(x) - x}{x} \right| \le \Epsilon_\text{mach}.$$

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

As a trivial example, consider a simple expression giving the inner product of (length two) vectors $$x$$ and $$y$$, then $$\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}$$ and so $$\operatorname{fl}(x \cdot y) = \hat{x} \cdot \hat{y},$$

where

$$\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}$$

where

$$\delta_n \leq \Epsilon_\text{mach}$$

by definition, which is the sum of two slightly perturbed (on the order of Εmach) input data, and so is backward stable. For more realistic examples in numerical linear algebra, see 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 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 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 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, which can remove, or reduce by orders of magnitude, such risk: IEEE 754 quadruple precision and extended precision are designed for this purpose when computing at double precision.

For example, the following algorithm is a direct implementation to compute the function $f(a + h)$ which is well-conditioned at 1.0, 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.

If, however, intermediate computations are all performed in extended precision (e.g. by setting line [1] to C99 long double), then up to full precision in the final double result can be maintained. Alternatively, a numerical analysis of the algorithm reveals that if the following non-obvious change to line [2] is made: 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, and the other references at the bottom of this article. Kahan suggests several rules of thumb that can substantially decrease by orders of magnitude 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 ); 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: 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. An example of the latter case is financial calculations. For this reason, financial software tends not to use a binary floating-point number representation. The "decimal" data type of the C# and 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 $$(x+y)(x-y) = x^2-y^2\,$$, and that $$\sin^2{\theta}+\cos^2{\theta} = 1\,$$, however these facts cannot be relied on when the quantities involved are the result of floating-point computation.

The use of the equality test requires care when dealing with floating-point numbers. Even simple expressions like  will, on most computers, fail to be true (in IEEE 754 double precision, for example,   is approximately equal to -4.44089209850063e-16). Consequently, such tests are sometimes replaced with "fuzzy" comparisons (, 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. 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. 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.

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.

Summation of a vector of floating-point values is a basic algorithm in 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.

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:
 * $t_0 = \frac{1}{\sqrt{3}}$
 * First form: $t_{i+1} = \frac{\sqrt{t_i^2+1}-1}{t_i}$
 * second form: $t_{i+1} = \frac{t_i}{\sqrt{t_i^2+1}+1}$
 * $$\pi \sim 6 \times 2^i \times t_i$$, converging as $$i \rightarrow \infty$$

Here is a computation using IEEE "double" (a significand with 53 bits of precision) arithmetic:

i  6 × 2i × ti, first form    6 × 2i × ti, second form - 0   '.4641016151377543863      '.4641016151377543863  1   '.2153903091734710173      '.2153903091734723496  2   '596599420974940120      '596599420975006733  3   '60862151314012979      '60862151314352708  4   '27145996453136334      '27145996453689225  5   '8730499801259536      '8730499798241950  6   '6627470548084133      '6627470568494473  7   '6101765997805905      '6101766046906629  8   '70343230776862      '70343215275928  9   '37488171150615      '37487713536668 10   '9278733740748      '9273850979885 11   '7256228504127      '7220386148377 12   '717412858693      '707019992125 13   '189011456060      '78678454728 14   '717412858693      '46593073709 15   '19358822321783      '8571730119 16   '717412858693      '6566394222 17   '810075796233302      '6065061913 18   '717412858693      '939728836 19   '4061547378810956      '908393901 20   '05434924008406305      '900560168 21   '00068646912273617      '8608396 22   '349453756585929919      '8122118 23   '00068646912273617      '95552 24   '.2245152435345525443      '68907 25                              '62246 26                              '62246 27                              '62246 28                              '62246               The true value is

While the two forms of the recurrence formula are clearly mathematically equivalent, the first subtracts 1 from a number extremely close to 1, leading to an increasingly problematic loss of significant digits. 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 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-vectorization. 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.

In some compilers (GCC and Clang), turning on "fast" math may cause the program to 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.

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. Intel Fortran Compiler is a notable outlier.

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.

title: Floating-point arithmetic


text:
First Epistle to the Corinthians

The First Epistle to the Corinthians (Α΄ ᾽Επιστολὴ πρὸς Κορινθίους) is one of the Pauline epistles, part of the New Testament of the Christian Bible. The epistle is attributed to Paul the Apostle and a co-author, Sosthenes, and is addressed to the Christian church in Corinth. Despite the name, it is not believed to be the first such letter. Scholars believe that Sosthenes was the amanuensis who wrote down the text of the letter at Paul's direction. It addresses various issues that had arisen in the Christian community at Corinth and is composed in a form of Koine Greek.

Authorship
There is a consensus among historians and theologians that Paul is the author of the First Epistle to the Corinthians (c. AD 53–54). The letter is quoted or mentioned by the earliest of sources and is included in every ancient canon, including that of Marcion of Sinope. Some scholars point to the epistle's potentially embarrassing references to the existence of sexual immorality in the church as strengthening the case for the authenticity of the letter.

However, the epistle does contain a passage that is widely believed to have been interpolated into the text by a later scribe:

"As in all the churches of the saints, women should be silent in the churches. For they are not permitted to speak, but should be subordinate, as the law also says. If there is anything they desire to know, let them ask their husbands at home. For it is shameful for a woman to speak in church."

Verses 34–35 are included in all extant manuscripts. Part of the reason for suspecting that this passage is an interpolation is that in several manuscripts in the Western tradition, it is placed at the end of chapter 14 instead of at its canonical location. This kind of variability is generally considered by textual critics to be a sign that a note, initially placed in the margins of the document, has been copied into the body of the text by a scribe. As E. Earle Ellis and Daniel B. Wallace note, however, a marginal note may well have been written by Paul himself. The loss of marginal arrows or other directional devices could explain why the scribe of the Western Vorlage placed it at the end of the chapter. The absence of an asterisk or obelisk in the margin of any manuscript – a common way of indicating doubt of authenticity – they argue, a strong argument that Paul wrote the passage and intended it in its traditional place. The passage has also been taken to contradict 11:5, where women are described as praying and prophesying in church.

Furthermore, some scholars believe that the passage 1 Corinthians 10:1–22 constitutes a separate letter fragment or scribal interpolation because it equates the consumption of meat sacrificed to idols with idolatry, while Paul seems to be more lenient on this issue in 8:1–13 and 10:23–11:1. Such views are rejected by other scholars who give arguments for the unity of 8:1–11:1.

Composition
About the year AD 50, towards the end of his second missionary journey, Paul founded the church in Corinth before moving on to Ephesus, a city on the west coast of today's Turkey, about 290 km by sea from Corinth. From there he traveled to Caesarea and Antioch. Paul returned to Ephesus on his third missionary journey and spent approximately three years there. It was while staying in Ephesus that he received disconcerting news of the community in Corinth regarding jealousies, rivalry, and immoral behavior. It also appears that, based on a letter the Corinthians sent Paul, the congregation was requesting clarification on a number of matters, such as marriage and the consumption of meat previously offered to idols.

By comparing Acts of the Apostles 18:1–17 and mentions of Ephesus in the Corinthian correspondence, scholars suggest that the letter was written during Paul's stay in Ephesus, which is usually dated as being in the range of AD 53–57.

Anthony C. Thiselton suggests that it is possible that 1 Corinthians was written during Paul's first (brief) stay in Ephesus, at the end of his second journey, usually dated to early AD 54. However, it is more likely that it was written during his extended stay in Ephesus, where he refers to sending Timothy to them.

Despite the attributed title "1 Corinthians", this letter was not the first written by Paul to the church in Corinth, only the first canonical letter. 1 Corinthians is the second known letter of four from Paul to the church in Corinth, as evidenced by Paul's mention of his previous letter in 1 Corinthians 5:9. The other two being what is called the Second Epistle to the Corinthians and a "tearful, severe" letter mentioned in 2 Corinthians 2:3–4. The book called the Third Epistle to the Corinthians is generally not believed by scholars to have been written by Paul, as the text claims.

Surviving early manuscripts
The original manuscript of this book is lost, and the text of surviving manuscripts varies. The oldest manuscripts containing some or all of the text of this book include:
 * Papyrus 46 (AD 175–225)
 * Codex Vaticanus (AD 325–350)
 * Codex Sinaiticus (330–360)
 * Papyrus 123 (4th century)
 * Codex Alexandrinus (400–440)
 * Codex Ephraemi Rescriptus (~450)
 * Codex Freerianus (~450)
 * Codex Claromontanus (~550)
 * Codex Coislinianus (~550)
 * Papyrus 14 (6th century)
 * Papyrus 11 (7th century;)

Structure

The epistle may be divided into seven parts:

 * 1) Salutation (1:1–3)
 * 2) Paul addresses the issue regarding challenges to his apostleship and defends the issue by claiming that it was given to him through a revelation from Christ. The salutation (the first section of the letter) reinforces the legitimacy of Paul's apostolic claim.
 * 3) Thanksgiving (1:4–9)
 * 4) The thanksgiving part of the letter is typical of Hellenistic letter writing. In a thanksgiving recitation the writer thanks God for health, a safe journey, deliverance from danger, or good fortune.
 * 5) In this letter, the thanksgiving "introduces charismata and gnosis, topics to which Paul will return and that he will discuss at greater length later in the letter".
 * 6) Division in Corinth (1:10–4:21)
 * 7) Facts of division
 * 8) Causes of division
 * 9) Cure for division
 * 10) Immorality in Corinth (5:1–6:20)
 * 11) Discipline an immoral Brother
 * 12) Resolving personal disputes
 * 13) Sexual purity
 * 14) Difficulties in Corinth (7:1–14:40)
 * 15) Marriage
 * 16) Christian liberty
 * 17) Worship
 * 18) Doctrine of Resurrection (15:1–58)
 * 19) Closing (16:1–24)
 * 20) Paul's closing remarks in his letters usually contain his intentions and efforts to improve the community. He would first conclude with his paraenesis and wish them peace by including a prayer request, greet them with his name and his friends with a holy kiss, and offer final grace and benediction:"Now concerning the contribution for the saints: as I directed the churches of Galatia[...] Let all your things be done with charity. Greet one another with a holy kiss[...] I, Paul, write this greeting with my own hand. If any man love not the Lord Jesus Christ, let him be Anathema Maranatha. The grace of the Lord Jesus be with you. My love be with you all in Christ Jesus. Amen."

Content

Some time before 2 Corinthians was written, Paul paid the church at Corinth a second visit to check some rising disorder, and wrote them a letter, now lost. The church had also been visited by Apollos, perhaps by Peter, and by some Jewish Christians who brought with them letters of commendation from Jerusalem.

Paul wrote 1 Corinthians letter to correct what he saw as erroneous views in the Corinthian church. Several sources informed Paul of conflicts within the church at Corinth: Apollos, a letter from the Corinthians, "those of Chloe", and finally Stephanas and his two friends who had visited Paul. Paul then wrote this letter to the Corinthians, urging uniformity of belief ("that ye all speak the same thing and that there be no divisions among you", 1:10) and expounding Christian doctrine. Titus and a brother whose name is not given were probably the bearers of the letter to the church at Corinth.

In general, divisions within the church at Corinth seem to be a problem, and Paul makes it a point to mention these conflicts in the beginning. Specifically, pagan roots still hold sway within their community. Paul wants to bring them back to what he sees as correct doctrine, stating that God has given him the opportunity to be a "skilled master builder" to lay the foundation and let others build upon it.

1 Corinthians 6:9-10 contains a notable condemnation of homosexuality, idolatry, thievery, drunkenness, slandering, swindling, adultery, and other acts the authors consider sexually immoral.

The majority of early manuscripts end chapter 6 with the words δοξάσατε δὴ τὸν Θεὸν ἐν τῷ σώματι ὑμῶν. The Textus Receptus adds καὶ ἐν τῷ πνεύματι ὑμῶν, ἅτινά ἐστι τοῦ Θεοῦ, which the New King James Version translates as "and in your spirit, which are (i.e. body and spirit) God's". The Cambridge Bible for Schools and Colleges notes that "these words are not found in many of the best MSS. and versions, and they somewhat weaken the force of the argument, which is intended to assert the dignity of the body. They were perhaps inserted by some who, missing the point of the Apostle's argument, thought that the worship of the spirit was unduly passed over."

Later, Paul wrote about immorality in Corinth by discussing an immoral brother, how to resolve personal disputes, and sexual purity. Regarding marriage, Paul states that it is better for Christians to remain unmarried, but that if they lacked self-control, it is better to marry than "burn" (πυροῦσθαι). The epistle may include marriage as an apostolic practice in 1 Corinthians 9:5, "Do we not have the right to be accompanied by a believing wife, as do the other apostles and the brothers of the Lord and Cephas (Peter)?" (In the last case, the letter concurs with Matthew 8:14, which mentions Peter having a mother-in-law and thus, by inference, a wife.) However, the Greek word for 'wife' is the same word for 'woman'. The Early Church Fathers, including Tertullian, Jerome, and Augustine state the Greek word is ambiguous and the women in 1 Corinthians 9:5 were women ministering to the Apostles as women ministered to Christ, and were not wives, and assert they left their "offices of marriage" to follow Christ. Paul also argues that married people must please their spouses, just as every Christian must please God.

Throughout the letter, Paul presents issues that are troubling the community in Corinth and offers ways to fix them. Paul states that this letter is to "admonish" them as beloved children. They are expected to become imitators of Jesus and follow the ways in Christ as he, Paul, teaches in all his churches.

This epistle contains some well-known phrases, including: "all things to all men", "through a glass, darkly", and:

"When I was a child, I spoke as a child, I understood as a child, I thought as a child: but when I became a man, I put away childish things."

- 1 Corinthians 13:11, King James Version.

"Through a glass, darkly"
1 Corinthians 13:12 contains the phrase βλέπομεν γὰρ ἄρτι δι' ἐσόπτρου ἐν αἰνίγματι, which was translated in the 1560 Geneva Bible as "For now we see through a glass darkly" (without a comma). This wording was used in the 1611 KJV, which added a comma before "darkly". This passage has inspired the titles of many works, with and without the comma.

The Greek word ἐσόπτρου (genitive; nominative: ἔσοπτρον), here translated "glass", is ambiguous, possibly referring to a mirror or a lens. Influenced by Strong's Concordance, many modern translations conclude that this word refers specifically to a mirror. Example English language translations include:

 * "Now we see but a poor reflection as in a mirror" (New International Version)
 * "What we see now is like a dim image in a mirror" (Good News Bible)

Paul's usage is in keeping with rabbinic use of the term, a borrowing from the Latin specularia. This has the same ambiguous meaning, although Adam Clarke concluded that it was a reference to specularibus lapidibus, clear polished stones used as lenses or windows. One way to preserve this ambiguity is to use the English cognate, speculum. Rabbi Judah ben Ilai (2nd century) was quoted as saying "All the prophets had a vision of God as He appeared through nine specula" while "Moses saw God through one speculum." The Babylonian Talmud states similarly "All the prophets gazed through a speculum that does not shine, while Moses our teacher gazed through a speculum that shines."

Women must remain silent
The letter is also notable for mentioning the role of women in churches, that for instance they must remain silent, and yet they have a role of prophecy and apparently speaking tongues in churches. If verse 14:34–35 is not an interpolation, certain scholars resolve the tension between these texts by positing that wives were either contesting their husband's inspired speeches at church, or the wives/women were chatting and asking questions in a disorderly manner when others were giving inspired utterances. Their silence was unique to the particular situation in the Corinthian gatherings at that time, and on this reading, Paul did not intend his words to be universalized for all women of all churches of all eras.

Head covering
1 Corinthians 11:2–16 contains an admonishment that Christian women cover their hair while praying and that Christian men leave their heads uncovered while praying. These practices were countercultural; the surrounding pagan Greek women prayed unveiled and Jewish men prayed with their heads covered.

The King James Version of 1 Corinthians 11:10 reads "For this cause ought the woman to have power on her head because of the angels." Other versions translate "power" as "authority". In many early biblical manuscripts (such as certain Vulgate, Coptic, and Armenian manuscripts), is rendered with the word "veil" (κάλυμμα) rather than the word "authority" (ἐξουσία); the Revised Standard Version reflects this, displaying 1 Corinthians 11:10 as follows: "That is why a woman ought to have a veil on her head, because of the angels." Similarly, a scholarly footnote in the New American Bible notes that presence of the word "authority may possibly be due to mistranslation of an Aramaic word for veil". This mistranslation may be due to "the fact that in Aramaic the roots of the word power and veil are spelled the same." The last-known living connection to the apostles, Irenaeus, penned verse 10 using the word "veil" (κάλυμμα) instead of "authority" (ἐξουσία) in Against Heresies, as did other Church Fathers in their writings, including Hippolytus, Origen, Chrysostom, Jerome, Epiphanius, Augustine, and Bede.

This ordinance continued to be handed down after the apostolic era to the next generations of Christians; writing 150 years after Paul, the early Christian apologist Tertullian stated that the women of the church in Corinth—both virgins and married—practiced veiling, given that Paul the Apostle delivered the teaching to them: "the Corinthians themselves understood him in this manner. In fact, at this very day, the Corinthians do veil their virgins. What the apostles taught, their disciples approve." From the period of the early Church to the late modern period, 1 Corinthians 11 was universally understood to enjoin the wearing of the headcovering throughout the day—a practice that has since waned in Western Europe but has continued in certain parts of the world, such as in the Middle East, Eastern Europe, Northern Africa and the Indian subcontinent,     as well as everywhere by Conservative Anabaptists (such as the Conservative Mennonite Churches and the Dunkard Brethren Church), who count veiling as being one of the ordinances of the Church. The early Church Father John Chrysostom explicates that 1 Corinthians 11 enjoins the continual wearing the headcovering by referencing Paul the Apostle's view that being shaven is always dishonourable and his pointing to the angels:

Agape
Chapter 13 of 1 Corinthians is one of many definitional sources for the original Greek word ἀγάπη. In the original Greek, the word ἀγάπη is used throughout chapter 13. This is translated into English as "charity" in the King James version; but the word "love" is preferred by most other translations, both earlier and more recent.

1 Corinthians 11:17-34 contains a condemnation of what the authors consider inappropriate behavior at Corinthian gatherings that appeared to be agape feasts.

Resurrection of Jesus
After discussing his views on worshipping idols, Paul ends the letter with his views on resurrection and the Resurrection of Jesus. Key verses are often cited as a concise summary of core Christian doctrine or kerygma, and are used in the construction of various Christian creeds:

"3 For I handed on to you as of first importance what I in turn had received: that Christ died for our sins in accordance with the scriptures 4 and that he was buried and that he was raised on the third day in accordance with the scriptures 5 and that he appeared to Cephas, then to the twelve. 6 Then he appeared to more than five hundred brothers and sisters at one time, most of whom are still alive, though some have died. 7 Then he appeared to James, then to all the apostles."

Belief in the death, burial, resurrection, and reappearance to Peter and the Twelve in verses 3–5, are assumed to be an early pre-Pauline kerygma or creedal statement. Biblical scholars note the antiquity of the creed, possibly transmitted from the Jerusalem apostolic community. though the core formula may have originated in Damascus, with the specific appearances reflecting the Jerusalem community. It may be one of the earliest kerygmas about Jesus' death and resurrection, though it is also possible that Paul himself joined together the various statements, as proposed by Urich Wilckens. It is also possible that "he appeared" was not specified in the core formula, and that the specific appearances are additions. According to Hannack, line 3b-4 form the original core, while line 5 and line 7 contain competing statements from two different factions. Prive also argues that line 5 and line 7 reflect the tensions between Petrus and James.

The kerygma has often been dated to no more than five years after Jesus' death by Biblical scholars. Bart Ehrman dissents, saying that "Among scholars I personally know, except for evangelicals, I don't now[sic] anyone who thinks this at all." Gerd Lüdemann however, maintains that "the elements in the tradition are to be dated to the first two years after the crucifixion of Jesus[...] not later than three years".

For orthodox Christians, the resurrection, believed by them to be a physical resurrection, is the central event of the Christian faith. While the authenticity of line 6a and 7 is disputed, MacGregor argues that linguistic analysis suggests that the version received by Paul seems to have included verses 3b–6a and 7. According to Gary R. Habermas, in "Corinthians 15:3–8, Paul records an ancient oral tradition(s) that summarizes the content of the Christian gospel." N.T Wright describes it as "the very early tradition that was common to all Christians."

In dissent from the majority view, Robert M. Price, Hermann Detering, John V. M. Sturdy, and David Oliver Smith have each argued that 1 Corinthians 15:3–7 is a later interpolation. According to Price, the text is not an early Christian creed written within five years of Jesus' death, nor did Paul write these verses. In his assessment, this was an Interpolation possibly dating to the beginning of the 2nd century. Price states that "The pair of words in verse 3a, "received / delivered" (paralambanein / paradidonai) is, as has often been pointed out, technical language for the handing on of rabbinical tradition", so it would contradict Paul's account of his conversion given in Galatians 1:13–24, which explicitly says that Paul had been taught the gospel of Christ by Jesus himself, not by any other man.

Resurrection of the body

Paul then asks: "Now if Christ is preached as raised from the dead, how can some of you say that there is no resurrection of the dead?" Chapter 15 closes with an account of the nature of the resurrection, claiming that in the Last Judgement the dead will be raised and both the living and the dead transformed into "spiritual bodies" (verse 44).

Psalm 8 reference
1 Corinthians 15:27 refers to Psalm 8:6. Ephesians 1:22 also refers to this verse of Psalm 8.

Evil company corrupts good habits
1 Corinthians 15:33 contains the aphorism "evil company corrupts good habits", from classical Greek literature. According to the church historian Socrates of Constantinople it is taken from a Greek tragedy of Euripides, but modern scholarship, following Jerome attributes it to the comedy by Menander, or Menander quoting Euripides. Hans Conzelmann remarks that the quotation was widely known. Whatever the proximate source, this quote does appear in one of the fragments of Euripides' works.

Baptism of the dead
1 Corinthians 15:29 argues it would be pointless to baptise the dead if people are not raised from the dead. This verse suggests that there existed a practice at Corinth whereby a living person would be baptized in the stead of some convert who had recently died. Teignmouth Shore, writing in Ellicott's Commentary for Modern Readers, notes that among the "numerous and ingenious conjectures" about this passage, the only tenable interpretation is that there existed a practice of baptising a living person to substitute those who had died before that sacrament could have been administered in Corinth, as also existed among the Marcionites in the second century, or still earlier than that, among a sect called "the Corinthians". The Jerusalem Bible states that "What this practice was is unknown. Paul does not say if he approved of it or not: he uses it merely for an ad hominem argument".

The Latter Day Saint movement interprets this passage to support the practice of baptism for the dead. This principle of vicarious work for the dead is an important work of the Church of Jesus Christ of Latter-day Saints in the dispensation of the fulness of times. This interpretation is rejected by other denominations of Christianity.

Commentaries
St. John Chrysostom, bishop of Constantinople and Doctor of the Catholic Church, wrote a commentary on 1 Corinthians, formed by 44 homilies.

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

title: First Epistle to the Corinthians