Floatingpoint formats 

IEEE 754 

Other 
Alternatives 
The IEEE Standard for FloatingPoint Arithmetic (IEEE 754) is a technical standard for floatingpoint arithmetic established in 1985 by the Institute of Electrical and Electronics Engineers (IEEE). The standard addressed many problems found in the diverse floatingpoint implementations that made them difficult to use reliably and portably. Many hardware floatingpoint units use the IEEE 754 standard.
The standard defines:
IEEE 7542008, published in August 2008, includes nearly all of the original IEEE 7541985 standard, plus the IEEE 8541987 Standard for RadixIndependent FloatingPoint Arithmetic. The current version, IEEE 7542019, was published in July 2019.^{[1]} It is a minor revision of the previous version, incorporating mainly clarifications, defect fixes and new recommended operations.
The need for a floatingpoint standard arose from chaos in the business and scientific computing industry in the 1960s and 1970s. IBM used a hexadecimal floatingpoint format with a longer significand and a shorter exponent^{[clarification needed]}. CDC and Cray computers used one's complement representation, which admits a value of +0 and −0. CDC 60bit computers did not have full 60bit adders, so integer arithmetic was limited to 48 bits of precision from the floatingpoint unit. Exception processing from dividebyzero was different on different computers. Moving data between systems and even repeating the same calculations on different systems was often difficult.
The first IEEE standard for floatingpoint arithmetic, IEEE 7541985, was published in 1985. It covered only binary floatingpoint arithmetic.
A new version, IEEE 7542008, was published in August 2008, following a sevenyear revision process, chaired by Dan Zuras and edited by Mike Cowlishaw. It replaced both IEEE 7541985 (binary floatingpoint arithmetic) and IEEE 8541987 Standard for RadixIndependent FloatingPoint Arithmetic. The binary formats in the original standard are included in this new standard along with three new basic formats, one binary and two decimal. To conform to the current standard, an implementation must implement at least one of the basic formats as both an arithmetic format and an interchange format.
The international standard ISO/IEC/IEEE 60559:2011 (with content identical to IEEE 7542008) has been approved for adoption through ISO/IEC JTC 1/SC 25 under the ISO/IEEE PSDO Agreement^{[2]}^{[3]} and published.^{[4]}
The current version, IEEE 7542019 published in July 2019, is derived from and replaces IEEE 7542008, following a revision process started in September 2015, chaired by David G. Hough and edited by Mike Cowlishaw. It incorporates mainly clarifications (e.g. totalOrder) and defect fixes (e.g. minNum), but also includes some new recommended operations (e.g. augmentedAddition).^{[5]}^{[6]}
The international standard ISO/IEC 60559:2020 (with content identical to IEEE 7542019) has been approved for adoption through ISO/IEC JTC 1/SC 25 and published.^{[7]}
The next projected revision of the standard is in 2028.^{[8]}
An IEEE 754 format is a "set of representations of numerical values and symbols". A format may also include how the set is encoded.^{[9]}
A floatingpoint format is specified by
A format comprises
For example, if b = 10, p = 7, and emax = 96, then emin = −95, the significand satisfies 0 ≤ c ≤ 9999999, and the exponent satisfies −101 ≤ q ≤ 90. Consequently, the smallest nonzero positive number that can be represented is 1×10^{−101}, and the largest is 9999999×10^{90} (9.999999×10^{96}), so the full range of numbers is −9.999999×10^{96} through 9.999999×10^{96}. The numbers −b^{1−emax} and b^{1−emax} (here, −1×10^{−95} and 1×10^{−95}) are the smallest (in magnitude) normal numbers; nonzero numbers between these smallest numbers are called subnormal numbers.
Some numbers may have several possible floatingpoint representations. For instance, if b = 10, and p = 7, then −12.345 can be represented by −12345×10^{−3}, −123450×10^{−4}, and −1234500×10^{−5}. However, for most operations, such as arithmetic operations, the result (value) does not depend on the representation of the inputs.
For the decimal formats, any representation is valid, and the set of these representations is called a cohort. When a result can have several representations, the standard specifies which member of the cohort is chosen.
For the binary formats, the representation is made unique by choosing the smallest representable exponent allowing the value to be represented exactly. Further, the exponent is not represented directly, but a bias is added so that the smallest representable exponent is represented as 1, with 0 used for subnormal numbers. For numbers with an exponent in the normal range (the exponent field being neither all ones nor all zeros), the leading bit of the significand will always be 1. Consequently, a leading 1 can be implied rather than explicitly present in the memory encoding, and under the standard the explicitly represented part of the significand will lie between 0 and 1. This rule is called leading bit convention, implicit bit convention, or hidden bit convention. This rule allows the binary format to have an extra bit of precision. The leading bit convention cannot be used for the subnormal numbers as they have an exponent outside the normal exponent range and scale by the smallest represented exponent as used for the smallest normal numbers.
Due to the possibility of multiple encodings (at least in formats called interchange formats), a NaN may carry other information: a sign bit (which has no meaning, but may be used by some operations) and a payload, which is intended for diagnostic information indicating the source of the NaN (but the payload may have other uses, such as NaNboxing^{[10]}^{[11]}^{[12]}).
The standard defines five basic formats that are named for their numeric base and the number of bits used in their interchange encoding. There are three binary floatingpoint basic formats (encoded with 32, 64 or 128 bits) and two decimal floatingpoint basic formats (encoded with 64 or 128 bits). The binary32 and binary64 formats are the single and double formats of IEEE 7541985 respectively. A conforming implementation must fully implement at least one of the basic formats.
The standard also defines interchange formats, which generalize these basic formats.^{[13]} For the binary formats, the leading bit convention is required. The following table summarizes some of the possible interchange formats (including the basic formats).
Significand  Exponent  Properties^{[b]}  

Name  Common name  Radix  Digits^{[c]}  Decimal digits^{[d]}  Min  Max  MAXVAL  log_{10} MAXVAL  MINVAL>0 (normal)  MINVAL>0 (subnorm)  Notes 
binary16  Half precision  2  11  3.31  −14  15  65504  4.816  6.10·10^{−5}  5.96·10^{−8}  Interchange 
binary32  Single precision  2  24  7.22  −126  +127  3.40·10^{38}  38.532  1.18·10^{−38}  1.40·10^{−45}  Basic 
binary64  Double precision  2  53  15.95  −1022  +1023  1.80·10^{308}  308.255  2.23·10^{−308}  4.94·10^{−324}  Basic 
binary128  Quadruple precision  2  113  34.02  −16382  +16383  1.19·10^{4932}  4932.075  3.36·10^{−4932}  6.48·10^{−4966}  Basic 
binary256  Octuple precision  2  237  71.34  −262142  +262143  1.61·10^{78913}  78913.207  2.48·10^{−78913}  2.25·10^{−78984}  Interchange 
decimal32  10  7  7  −95  +96  1.0·10^{97}  97 − 4.34·10^{−8}  1·10^{−95}  1·10^{−101}  Interchange  
decimal64  10  16  16  −383  +384  1.0·10^{385}  385 − 4.34·10^{−17}  1·10^{−383}  1·10^{−398}  Basic  
decimal128  10  34  34  −6143  +6144  1.0·10^{6145}  6145 − 4.34·10^{−35}  1·10^{−6143}  1·10^{−6176}  Basic 
In the table above, integer values are exact, whereas values in decimal notation (e.g. 1.0) are rounded values. The minimum exponents listed are for normal numbers; the special subnormal number representation allows even smaller (in magnitude) numbers to be represented with some loss of precision. For example, the smallest positive number that can be represented in binary64 is 2^{−1074}; contributions to the −1074 figure include the emin value −1022 and all but one of the 53 significand bits (2^{−1022 − (53 − 1)} = 2^{−1074}).
Decimal digits is the precision of the format expressed in terms of an equivalent number of decimal digits. It is computed as digits × log_{10} base. E.g. binary128 has approximately the same precision as a 34 digit decimal number.
log_{10} MAXVAL is a measure of the range of the encoding. Its integer part is the largest exponent shown on the output of a value in scientific notation with one leading digit in the significand before the decimal point (e.g. 1.698·10^{38} is near the largest value in binary32, 9.999999·10^{96} is the largest value in decimal32).
The binary32 (single) and binary64 (double) formats are two of the most common formats used today. The figure below shows the absolute precision for both formats over a range of values. This figure can be used to select an appropriate format given the expected value of a number and the required precision.
An example of a layout for 32bit floating point is
and the 64 bit layout is similar.
The standard specifies optional extended and extendable precision formats, which provide greater precision than the basic formats.^{[14]} An extended precision format extends a basic format by using more precision and more exponent range. An extendable precision format allows the user to specify the precision and exponent range. An implementation may use whatever internal representation it chooses for such formats; all that needs to be defined are its parameters (b, p, and emax). These parameters uniquely describe the set of finite numbers (combinations of sign, significand, and exponent for the given radix) that it can represent.
The standard recommends that language standards provide a method of specifying p and emax for each supported base b.^{[15]} The standard recommends that language standards and implementations support an extended format which has a greater precision than the largest basic format supported for each radix b.^{[16]} For an extended format with a precision between two basic formats the exponent range must be as great as that of the next wider basic format. So for instance a 64bit extended precision binary number must have an 'emax' of at least 16383. The x87 80bit extended format meets this requirement.
The original IEEE 7541985 standard also had the concept of extended formats, but without any mandatory relation between emin and emax. For example, the Motorola 68881 80bit format,^{[17]} where emin = − emax, was a conforming extended format, but it became nonconforming in the 2008 revision.
Interchange formats are intended for the exchange of floatingpoint data using a bit string of fixed length for a given format.
For the exchange of binary floatingpoint numbers, interchange formats of length 16 bits, 32 bits, 64 bits, and any multiple of 32 bits ≥ 128^{[e]} are defined. The 16bit format is intended for the exchange or storage of small numbers (e.g., for graphics).
The encoding scheme for these binary interchange formats is the same as that of IEEE 7541985: a sign bit, followed by w exponent bits that describe the exponent offset by a bias, and p − 1 bits that describe the significand. The width of the exponent field for a kbit format is computed as w = round(4 log_{2}(k)) − 13. The existing 64 and 128bit formats follow this rule, but the 16 and 32bit formats have more exponent bits (5 and 8 respectively) than this formula would provide (3 and 7 respectively).
As with IEEE 7541985, the biasedexponent field is filled with all 1 bits to indicate either infinity (trailing significand field = 0) or a NaN (trailing significand field ≠ 0). For NaNs, quiet NaNs and signaling NaNs are distinguished by using the most significant bit of the trailing significand field exclusively,^{[f]} and the payload is carried in the remaining bits.
For the exchange of decimal floatingpoint numbers, interchange formats of any multiple of 32 bits are defined. As with binary interchange, the encoding scheme for the decimal interchange formats encodes the sign, exponent, and significand. Two different bitlevel encodings are defined, and interchange is complicated by the fact that some external indicator of the encoding in use may be required.
The two options allow the significand to be encoded as a compressed sequence of decimal digits using densely packed decimal or, alternatively, as a binary integer. The former is more convenient for direct hardware implementation of the standard, while the latter is more suited to software emulation on a binary computer. In either case, the set of numbers (combinations of sign, significand, and exponent) that may be encoded is identical, and special values (±zero with the minimum exponent, ±infinity, quiet NaNs, and signaling NaNs) have identical encodings.
The standard defines five rounding rules. The first two rules round to a nearest value; the others are called directed roundings:
At the extremes, a value with a magnitude strictly less than will be rounded to the minimum or maximum finite number (depending on the value's sign). Any numbers with exactly this magnitude are considered ties; this choice of tie may be conceptualized as the midpoint between and , which, were the exponent not limited, would be the next representable floatingpoint numbers larger in magnitude. Numbers with a magnitude strictly larger than k are rounded to the corresponding infinity.^{[18]}
"Round to nearest, ties to even" is the default for binary floating point and the recommended default for decimal. "Round to nearest, ties to away" is only required for decimal implementations.^{[19]}
Mode  Example value  

+11.5  +12.5  −11.5  −12.5  
to nearest, ties to even  +12.0  +12.0  −12.0  −12.0 
to nearest, ties away from zero  +12.0  +13.0  −12.0  −13.0 
toward 0  +11.0  +12.0  −11.0  −12.0 
toward +∞  +12.0  +13.0  −11.0  −12.0 
toward −∞  +11.0  +12.0  −12.0  −13.0 
Unless specified otherwise, the floatingpoint result of an operation is determined by applying the rounding function on the infinitely precise (mathematical) result. Such an operation is said to be correctly rounded. This requirement is called correct rounding.^{[20]}
Required operations for a supported arithmetic format (including the basic formats) include:
The standard provides comparison predicates to compare one floatingpoint datum to another in the supported arithmetic format.^{[32]} Any comparison with a NaN is treated as unordered. −0 and +0 compare as equal.
The standard provides a predicate totalOrder, which defines a total ordering on canonical members of the supported arithmetic format.^{[33]} The predicate agrees with the comparison predicates (see section § Comparison predicates) when one floatingpoint number is less than the other. The main differences are:^{[34]}
The totalOrder predicate does not impose a total ordering on all encodings in a format. In particular, it does not distinguish among different encodings of the same floatingpoint representation, as when one or both encodings are noncanonical.^{[33]} IEEE 7542019 incorporates clarifications of totalOrder.
For the binary interchange formats whose encoding follows the IEEE 7542008 recommendation on placement of the NaN signaling bit, the comparison is identical to one that type puns the floatingpoint numbers to a sign–magnitude integer (assuming a payload ordering consistent with this comparison), an old trick for FP comparison without an FPU.^{[35]}
The standard defines five exceptions, each of which returns a default value and has a corresponding status flag that is raised when the exception occurs.^{[g]} No other exception handling is required, but additional nondefault alternatives are recommended (see § Alternate exception handling).
The five possible exceptions are
These are the same five exceptions as were defined in IEEE 7541985, but the division by zero exception has been extended to operations other than the division.
Some decimal floatingpoint implementations define additional exceptions,^{[36]}^{[37]} which are not part of IEEE 754:
Additionally, operations like quantize when either operand is infinite, or when the result does not fit the destination format, will also signal invalid operation exception.^{[38]}
In the IEEE 754 standard, zero is signed, meaning that there exist both a "positive zero" (+0) and a "negative zero" (−0). In most runtime environments, positive zero is usually printed as "0
" and the negative zero as "0
". The two values behave as equal in numerical comparisons, but some operations return different results for +0 and −0. For instance, 1/(−0) returns negative infinity, while 1/(+0) returns positive infinity (so that the identity 1/(1/±∞) = ±∞ is maintained). Other common functions with a discontinuity at x=0 which might treat +0 and −0 differently include log(x), signum(x), and the principal square root of y + xi for any negative number y. As with any approximation scheme, operations involving "negative zero" can occasionally cause confusion. For example, in IEEE 754, x = y does not always imply 1/x = 1/y, as 0 = −0 but 1/0 ≠ 1/(−0).^{[39]}
Subnormal values fill the underflow gap with values where the absolute distance between them is the same as for adjacent values just outside the underflow gap. This is an improvement over the older practice to just have zero in the underflow gap, and where underflowing results were replaced by zero (flush to zero).^{[40]}
Modern floatingpoint hardware usually handles subnormal values (as well as normal values), and does not require software emulation for subnormals.
The infinities of the extended real number line can be represented in IEEE floatingpoint datatypes, just like ordinary floatingpoint values like 1, 1.5, etc. They are not error values in any way, though they are often (depends on the rounding) used as replacement values when there is an overflow. Upon a dividebyzero exception, a positive or negative infinity is returned as an exact result. An infinity can also be introduced as a numeral (like C's "INFINITY" macro, or "∞" if the programming language allows that syntax).
IEEE 754 requires infinities to be handled in a reasonable way, such as
IEEE 754 specifies a special value called "Not a Number" (NaN) to be returned as the result of certain "invalid" operations, such as 0/0, ∞×0, or sqrt(−1). In general, NaNs will be propagated, i.e. most operations involving a NaN will result in a NaN, although functions that would give some defined result for any given floatingpoint value will do so for NaNs as well, e.g. NaN ^ 0 = 1. There are two kinds of NaNs: the default quiet NaNs and, optionally, signaling NaNs. A signaling NaN in any arithmetic operation (including numerical comparisons) will cause an "invalid operation" exception to be signaled.
The representation of NaNs specified by the standard has some unspecified bits that could be used to encode the type or source of error; but there is no standard for that encoding. In theory, signaling NaNs could be used by a runtime system to flag uninitialized variables, or extend the floatingpoint numbers with other special values without slowing down the computations with ordinary values, although such extensions are not common.
It is a common misconception that the more esoteric features of the IEEE 754 standard discussed here, such as extended formats, NaN, infinities, subnormals etc., are only of interest to numerical analysts, or for advanced numerical applications. In fact the opposite is true: these features are designed to give safe robust defaults for numerically unsophisticated programmers, in addition to supporting sophisticated numerical libraries by experts. The key designer of IEEE 754, William Kahan notes that it is incorrect to "... [deem] features of IEEE Standard 754 for Binary FloatingPoint Arithmetic that ...[are] not appreciated to be features usable by none but numerical experts. The facts are quite the opposite. In 1977 those features were designed into the Intel 8087 to serve the widest possible market... Erroranalysis tells us how to design floatingpoint arithmetic, like IEEE Standard 754, moderately tolerant of wellmeaning ignorance among programmers".^{[41]}
A property of the single and doubleprecision formats is that their encoding allows one to easily sort them without using floatingpoint hardware, as if the bits represented signmagnitude integers, although it is unclear whether this was a design consideration (it seems noteworthy that the earlier IBM hexadecimal floatingpoint representation also had this property for normalized numbers). With the prevalent two'scomplement representation, interpreting the bits as signed integers sorts the positives correctly, but with the negatives reversed; as one possible correction for that, with an xor to flip the sign bit for positive values and all bits for negative values, all the values become sortable as unsigned integers (with −0 < +0).^{[35]}
The standard recommends optional exception handling in various forms, including presubstitution of userdefined default values, and traps (exceptions that change the flow of control in some way) and other exception handling models that interrupt the flow, such as try/catch. The traps and other exception mechanisms remain optional, as they were in IEEE 7541985.
Clause 9 in the standard recommends additional mathematical operations^{[45]} that language standards should define.^{[46]} None are required in order to conform to the standard.
The following are recommended arithmetic operations, which must round correctly:^{[47]}
The , and functions were not part of the IEEE 7542008 standard because they were deemed less necessary.^{[49]} and were mentioned, but this was regarded as an error.^{[5]} All three were added in the 2019 revision.
The recommended operations also include setting and accessing dynamic mode rounding direction,^{[50]} and implementationdefined vector reduction operations such as sum, scaled product, and dot product, whose accuracy is unspecified by the standard.^{[51]}
As of 2019^{[update]}, augmented arithmetic operations^{[52]} for the binary formats are also recommended. These operations, specified for addition, subtraction and multiplication, produce a pair of values consisting of a result correctly rounded to nearest in the format and the error term, which is representable exactly in the format. At the time of publication of the standard, no hardware implementations are known, but very similar operations were already implemented in software using wellknown algorithms. The history and motivation for their standardization are explained in a background document.^{[53]}^{[54]}
As of 2019, the formerly required minNum, maxNum, minNumMag, and maxNumMag in IEEE 7542008 are now deprecated due to their nonassociativity. Instead, two sets of new minimum and maximum operations are recommended.^{[55]} The first set contains minimum, minimumNumber, maximum and maximumNumber. The second set contains minimumMagnitude, minimumMagnitudeNumber, maximumMagnitude and maximumMagnitudeNumber. The history and motivation for this change are explained in a background document.^{[56]}
The standard recommends how language standards should specify the semantics of sequences of operations, and points out the subtleties of literal meanings and optimizations that change the value of a result. By contrast, the previous 1985 version of the standard left aspects of the language interface unspecified, which led to inconsistent behavior between compilers, or different optimization levels in an optimizing compiler.
Programming languages should allow a user to specify a minimum precision for intermediate calculations of expressions for each radix. This is referred to as preferredWidth in the standard, and it should be possible to set this on a perblock basis. Intermediate calculations within expressions should be calculated, and any temporaries saved, using the maximum of the width of the operands and the preferred width if set. Thus, for instance, a compiler targeting x87 floatingpoint hardware should have a means of specifying that intermediate calculations must use the doubleextended format. The stored value of a variable must always be used when evaluating subsequent expressions, rather than any precursor from before rounding and assigning to the variable.
The IEEE 7541985 version of the standard allowed many variations in implementations (such as the encoding of some values and the detection of certain exceptions). IEEE 7542008 has reduced these allowances, but a few variations still remain (especially for binary formats). The reproducibility clause recommends that language standards should provide a means to write reproducible programs (i.e., programs that will produce the same result in all implementations of a language) and describes what needs to be done to achieve reproducible results.
The standard requires operations to convert between basic formats and external character sequence formats.^{[57]} Conversions to and from a decimal character format are required for all formats. Conversion to an external character sequence must be such that conversion back using round to nearest, ties to even will recover the original number. There is no requirement to preserve the payload of a quiet NaN or signaling NaN, and conversion from the external character sequence may turn a signaling NaN into a quiet NaN.
The original binary value will be preserved by converting to decimal and back again using:^{[58]}
For other binary formats, the required number of decimal digits is^{[h]}
where p is the number of significant bits in the binary format, e.g. 237 bits for binary256.
When using a decimal floatingpoint format, the decimal representation will be preserved using:
Algorithms, with code, for correctly rounded conversion from binary to decimal and decimal to binary are discussed by Gay,^{[59]} and for testing – by Paxson and Kahan.^{[60]}
The standard recommends providing conversions to and from external hexadecimalsignificand character sequences, based on C99's hexadecimal floating point literals. Such a literal consists of an optional sign (+
or 
), the indicator "0x", a hexadecimal number with or without a period, an exponent indicator "p", and a decimal exponent with optional sign. The syntax is not casesensitive.^{[61]} The decimal exponent scales by powers of 2, so for example 0x0.1p4
is 1/256.^{[62]}
Since growth rates can't be less than 1, such rates signal invalid exceptions.
((cite book))
: CS1 maint: numeric names: authors list (link)((cite book))
: CS1 maint: numeric names: authors list (link)Current  

802 series 
 
Proposed  
Superseded  