Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

IEEE 754-1985

From Wikipedia, the free encyclopedia
First edition of the IEEE 754 floating-point standard
Main article:IEEE 754

IEEE 754-1985[1] is a historic industrystandard for representingfloating-point numbers incomputers, officially adopted in 1985 and superseded in 2008 byIEEE 754-2008, and then again in 2019 by minor revisionIEEE 754-2019.[2] During its 23 years, it was the most widely used format for floating-point computation. It was implemented in software, in the form of floating-pointlibraries, and in hardware, in theinstructions of manyCPUs andFPUs. The firstintegrated circuit to implement the draft of what was to become IEEE 754-1985 was theIntel 8087.

IEEE 754-1985 represents numbers inbinary, providing definitions for four levels of precision, of which the two most commonly used are:

LevelWidthRange at fullprecisionPrecision[a]
Single precision32 bits±1.18×10−38 to ±3.4×1038Approximately 7 decimal digits
Double precision64 bits±2.23×10−308 to ±1.80×10308Approximately 16 decimal digits

The standard also defines representations for positive and negativeinfinity, a "negative zero", five exceptions to handle invalid results likedivision by zero, special values calledNaNs for representing those exceptions,denormal numbers to represent numbers smaller than shown above, and fourrounding modes.

Representation of numbers

[edit]
The number 0.15625 represented as a single-precision IEEE 754-1985 floating-point number. See text for explanation.
The three fields in a 64bit IEEE 754 float

Floating-point numbers in IEEE 754 format consist of three fields: asign bit, abiased exponent, and a fraction. The following example illustrates the meaning of each.

The decimal number 0.1562510 represented in binary is 0.001012 (that is, 1/8 + 1/32). (Subscripts indicate the numberbase.) Analogous toscientific notation, where numbers are written to have a single non-zero digit to the left of the decimal point, we rewrite this number so it has a single 1 bit to the left of the "binary point". We simply multiply by the appropriate power of 2 to compensate for shifting the bits left by three positions:

0.001012=1.012×23{\displaystyle 0.00101_{2}=1.01_{2}\times 2^{-3}}

Now we can read off the fraction and the exponent: the fraction is .012 and the exponent is −3.

As illustrated in the pictures, the three fields in the IEEE 754 representation of this number are:

sign = 0, because the number is positive. (1 indicates negative.)
biased exponent = −3 + the "bias". Insingle precision, the bias is127, so in this example the biased exponent is 124; indouble precision, the bias is1023, so the biased exponent in this example is 1020.
fraction = .01000…2.

IEEE 754 adds abias to the exponent so that numbers can in many cases be compared conveniently by the same hardware that compares signed2's-complement integers. Using a biased exponent, the lesser of two positive floating-point numbers will come out "less than" the greater following the same ordering as forsign and magnitude integers. If two floating-point numbers have different signs, the sign-and-magnitude comparison also works with biased exponents. However, if both biased-exponent floating-point numbers are negative, then the ordering must be reversed. If the exponent were represented as, say, a 2's-complement number, comparison to see which of two numbers is greater would not be as convenient.

The leading 1 bit is omitted since all numbers except zero start with a leading 1; the leading 1 is implicit and doesn't actually need to be stored which gives an extra bit of precision for "free."

Zero

[edit]

The number zero is represented specially:

sign = 0 forpositive zero, 1 fornegative zero.
biased exponent = 0.
fraction = 0.

Denormalized numbers

[edit]

The number representations described above are callednormalized, meaning that the implicit leading binary digit is a 1. To reduce the loss of precision when anunderflow occurs, IEEE 754 includes the ability to represent fractions smaller than are possible in the normalized representation, by making the implicit leading digit a 0. Such numbers are calleddenormal. They don't include as manysignificant digits as a normalized number, but they enable a gradual loss of precision when the result of anoperation is not exactly zero but is too close to zero to be represented by a normalized number.

A denormal number is represented with a biased exponent of all 0 bits, which represents an exponent of −126 in single precision (not −127), or −1022 in double precision (not −1023).[3] In contrast, the smallest biased exponent representing a normal number is 1 (seeexamples below).

Representation of non-numbers

[edit]

The biased-exponent field is filled with all 1 bits to indicate either infinity or an invalid result of a computation.

Positive and negative infinity

[edit]

Positive and negative infinity are represented thus:

sign = 0 for positive infinity, 1 for negative infinity.
biased exponent = all 1 bits.
fraction = all 0 bits.

NaN

[edit]

Some operations offloating-point arithmetic are invalid, such as taking the square root of a negative number. The act of reaching an invalid result is called a floating-pointexception. An exceptional result is represented by a special code called a NaN, for "Not a Number". All NaNs in IEEE 754-1985 have this format:

sign = either 0 or 1.
biased exponent = all 1 bits.
fraction = anything except all 0 bits (since all 0 bits represents infinity).

Range and precision

[edit]
Relative precision of single (binary32) and double precision (binary64) numbers, compared with decimal representations using a fixed number ofsignificant digits. Relative precision is defined here as ulp(x)/x, where ulp(x) is theunit in the last place in the representation ofx, i.e. the gap betweenx and the next representable number.

Precision is defined as the minimum difference between two successive mantissa representations; thus it is a function only in the mantissa; while the gap is defined as the difference between two successive numbers.[4]

Single precision

[edit]

Single-precision numbers occupy 32 bits. In single precision:

  • The positive and negative numbers closest to zero (represented by the denormalized value with all 0s in the exponent field and the binary value 1 in the fraction field) are
    ±2−23 × 2−126 ≈ ±1.40130×10−45
  • The positive and negative normalized numbers closest to zero (represented with the binary value 1 in the exponent field and 0 in the fraction field) are
    ±1 × 2−126 ≈ ±1.17549×10−38
  • The finite positive and finite negative numbers furthest from zero (represented by the value with 254 in the exponent field and all 1s in the fraction field) are
    ±(2−2−23) × 2127[5] ≈ ±3.40282×1038

Some example range and gap values for given exponents in single precision:

Actual Exponent (unbiased)Exp (biased)MinimumMaximumGap
−11260.5≈ 0.999999940395≈ 5.96046e-8
01271≈ 1.999999880791≈ 1.19209e-7
11282≈ 3.999999761581≈ 2.38419e-7
21294≈ 7.999999523163≈ 4.76837e-7
101371024≈ 2047.999877930≈ 1.22070e-4
111382048≈ 4095.999755859≈ 2.44141e-4
231508388608167772151
2415116777216335544302
127254≈ 1.70141e38≈ 3.40282e38≈ 2.02824e31

As an example, 16,777,217 cannot be encoded as a 32-bit float as it will be rounded to 16,777,216. However, all integers within the representable range that are a power of 2 can be stored in a 32-bit float without rounding.

Double precision

[edit]

Double-precision numbers occupy 64 bits. In double precision:

  • The positive and negative numbers closest to zero (represented by the denormalized value with all 0s in the Exp field and the binary value 1 in the Fraction field) are
    ±2−52 × 2−1022 ≈ ±4.94066×10−324
  • The positive and negative normalized numbers closest to zero (represented with the binary value 1 in the Exp field and 0 in the fraction field) are
    ±1 × 2−1022 ≈ ±2.22507×10−308
  • The finite positive and finite negative numbers furthest from zero (represented by the value with 2046 in the Exp field and all 1s in the fraction field) are
    ±(2−2−52) × 21023[5] ≈ ±1.79769×10308

Some example range and gap values for given exponents in double precision:

Actual Exponent (unbiased)Exp (biased)MinimumMaximumGap
−110220.5≈ 0.999999999999999888978≈ 1.11022e-16
010231≈ 1.999999999999999777955≈ 2.22045e-16
110242≈ 3.999999999999999555911≈ 4.44089e-16
210254≈ 7.999999999999999111822≈ 8.88178e-16
1010331024≈ 2047.999999999999772626≈ 2.27374e-13
1110342048≈ 4095.999999999999545253≈ 4.54747e-13
521075450359962737049690071992547409911
5310769007199254740992180143985094819822
10232046≈ 8.98847e307≈ 1.79769e308≈ 1.99584e292

Extended formats

[edit]

The standard also recommends extended format(s) to be used to perform internal computations at a higher precision than that required for the final result, to minimise round-off errors: the standard only specifies minimum precision and exponent requirements for such formats. Thex8780-bit extended format is the most commonly implemented extended format that meets these requirements.

Examples

[edit]

Here are some examples of single-precision IEEE 754 representations:

TypeSignActual ExponentExp (biased)Exponent fieldFraction fieldValue
Zero0−12600000 0000000 0000 0000 0000 0000 00000.0
Negative zero1−12600000 0000000 0000 0000 0000 0000 0000−0.0
One001270111 1111000 0000 0000 0000 0000 00001.0
Minus One101270111 1111000 0000 0000 0000 0000 0000−1.0
Smallestdenormalized number*−12600000 0000000 0000 0000 0000 0000 0001±2−23 × 2−126 = ±2−149 ≈ ±1.4×10−45
"Middle" denormalized number*−12600000 0000100 0000 0000 0000 0000 0000±2−1 × 2−126 = ±2−127 ≈ ±5.88×10−39
Largest denormalized number*−12600000 0000111 1111 1111 1111 1111 1111±(1−2−23) × 2−126 ≈ ±1.18×10−38
Smallest normalized number*−12610000 0001000 0000 0000 0000 0000 0000±2−126 ≈ ±1.18×10−38
Largest normalized number*1272541111 1110111 1111 1111 1111 1111 1111±(2−2−23) × 2127 ≈ ±3.4×1038
Positive infinity01282551111 1111000 0000 0000 0000 0000 0000+∞
Negative infinity11282551111 1111000 0000 0000 0000 0000 0000−∞
Not a number*1282551111 1111non zeroNaN
* Sign bit can be either 0 or 1 .

Comparing floating-point numbers

[edit]

Every possible bit combination is either a NaN or a number with a unique value in theaffinely extended real number system with its associated order, except for the two combinations of bits for negative zero and positive zero, which sometimes require special attention (see below). Thebinary representation has the special property that, excluding NaNs, any two numbers can be compared assign and magnitude integers (endianness issues apply). When comparing as2's-complement integers: If the sign bits differ, the negative number precedes the positive number, so 2's complement gives the correct result (except that negative zero and positive zero should be considered equal). If both values are positive, the 2's complement comparison again gives the correct result. Otherwise (two negative numbers), the correct FP ordering is the opposite of the 2's complement ordering.

Rounding errors inherent to floating point calculations may limit the use of comparisons for checking the exact equality of results. Choosing an acceptable range is a complex topic. A common technique is to use a comparison epsilon value to perform approximate comparisons.[6] Depending on how lenient the comparisons are, common values include1e-6 or1e-5 for single-precision, and1e-14 for double-precision.[7][8] Another common technique is ULP, which checks what the difference is in the last place digits, effectively checking how many steps away the two values are.[9]

Although negative zero and positive zero are generally considered equal for comparison purposes, someprogramming languagerelational operators and similar constructs treat them as distinct. According to theJava Language Specification,[10] comparison and equality operators treat them as equal, butMath.min() andMath.max() distinguish them (officially starting with Java version 1.1 but actually with 1.1.1), as do the comparison methodsequals(),compareTo() and evencompare() of classesFloat andDouble.

Rounding floating-point numbers

[edit]

The IEEE standard has four different rounding modes; the first is the default; the others are calleddirected roundings.

  • Round to Nearest – rounds to the nearest value; if the number falls midway it is rounded to the nearest value with an even (zero) least significant bit, which means it is rounded up 50% of the time (inIEEE 754-2008 this mode is calledroundTiesToEven to distinguish it from another round-to-nearest mode)
  • Round toward 0 – directed rounding towards zero
  • Round toward +∞ – directed rounding towards positive infinity
  • Round toward −∞ – directed rounding towards negative infinity.

Extending the real numbers

[edit]

The IEEE standard employs (and extends) theaffinely extended real number system, with separate positive and negative infinities. During drafting, there was a proposal for the standard to incorporate theprojectively extended real number system, with a single unsigned infinity, by providing programmers with a mode selection option. In the interest of reducing the complexity of the final standard, the projective mode was dropped, however. TheIntel 8087 andIntel 80287 floating point co-processors both support this projective mode.[11][12][13]

Functions and predicates

[edit]

Standard operations

[edit]

The following functions must be provided:

  • Add, subtract, multiply, divide
  • Square root
  • Floating point remainder. This is not like a normalmodulo operation, it can be negative for two positive numbers. It returns the exact value ofx–(round(x/y)·y).
  • Round to nearest integer. For undirected rounding when halfway between two integers the even integer is chosen.
  • Comparison operations. Besides the more obvious results, IEEE 754 defines that −∞ = −∞, +∞ = +∞ andx ≠ NaN for anyx (includingNaN).

Recommended functions and predicates

[edit]
  • copysign(x,y) returns x with the sign of y, soabs(x) equalscopysign(x,1.0). This is one of the few operations which operates on a NaN in a way resembling arithmetic. The functioncopysign is new in the C99 standard.
  • −x returns x with the sign reversed. This is different from 0−x in some cases, notably when x is 0. So −(0) is −0, but the sign of 0−0 depends on the rounding mode.
  • scalb(y, N)
  • logb(x)
  • finite(x) apredicate for "x is a finite value", equivalent to −Inf < x < Inf
  • isnan(x) a predicate for "x is a NaN", equivalent to "x ≠ x"
  • x <> y (x .LG. y inFortran), which turns out to have different behavior thanNOT(x = y) (x .NE. y in Fortran,x != y inC)[14] due to NaN.
  • unordered(x, y) is true when "x is unordered with y", i.e., either x or y is a NaN.
  • class(x)
  • nextafter(x,y) returns the next representable value from x in the direction towards y

History

[edit]

In 1976,Intel was starting the development of a floating-pointcoprocessor.[15][16] Intel hoped to be able to sell a chip containing good implementations of all the operations found in the widely varying maths software libraries.[15][17]

John Palmer, who managed the project, believed the effort should be backed by a standard unifying floating point operations across disparate processors. He contactedWilliam Kahan of theUniversity of California, who had helped improve the accuracy ofHewlett-Packard's calculators. Kahan suggested that Intel use the floating point ofDigital Equipment Corporation's (DEC) VAX. The first VAX, theVAX-11/780 had just come out in late 1977, and its floating point was highly regarded. However, seeking to market their chip to the broadest possible market, Intel wanted the best floating point possible, and Kahan went on to draw up specifications.[15] Kahan initially recommended that the floating point base be decimal[18][unreliable source?] but the hardware design of the coprocessor was too far along to make that change.

The work within Intel worried other vendors, who set up a standardization effort to ensure a "level playing field". Kahan attended the second IEEE 754 standards working group meeting, held in November 1977. He subsequently received permission from Intel to put forward a draft proposal based on his work for their coprocessor; he was allowed to explain details of the format and its rationale, but not anything related to Intel's implementation architecture. The draft was co-written with Jerome Coonen andHarold Stone, and was initially known as the "Kahan-Coonen-Stone proposal" or "K-C-S format".[15][16][17][19]

As an 8-bit exponent was not wide enough for some operations desired for double-precision numbers, e.g. to store the product of two 32-bit numbers,[20] both Kahan's proposal and a counter-proposal by DEC therefore used 11 bits, like the time-tested60-bit floating-point format of theCDC 6600 from 1965.[16][19][21] Kahan's proposal also provided for infinities, which are useful when dealing with division-by-zero conditions; not-a-number values, which are useful when dealing with invalid operations;denormal numbers, which help mitigate problems caused by underflow;[19][22][23] and a better balancedexponent bias, which can help avoid overflow and underflow when taking the reciprocal of a number.[24][25]

Even before it was approved, the draft standard had been implemented by a number of manufacturers.[26][27] The Intel 8087, which was announced in 1980, was the first chip to implement the draft standard.

Intel 8087 floating-point coprocessor

In 1980, theIntel 8087 chip was already released,[28] but DEC remained opposed, to denormal numbers in particular, because of performance concerns and since it would give DEC a competitive advantage to standardise on DEC's format.

The arguments overgradual underflow lasted until 1981 when an expert hired byDEC to assess it sided against the dissenters. DEC had the study done in order to demonstrate that gradual underflow was a bad idea, but the study concluded the opposite, and DEC gave in. In 1985, the standard was ratified, but it had already become the de facto standard a year earlier, implemented by many manufacturers.[16][19][5]

See also

[edit]

Notes

[edit]
  1. ^Precision: The number of decimal digits precision is calculated via number_of_mantissa_bits * Log10(2). Thus ~7.2 and ~15.9 for single and double precision respectively.

References

[edit]
  1. ^IEEE Standard for Binary Floating-Point Arithmetic. 1985.doi:10.1109/IEEESTD.1985.82928.ISBN 0-7381-1165-1.
  2. ^"ANSI/IEEE Std 754-2019".754r.ucbtest.org. Retrieved2019-08-06.
  3. ^Hennessy (2009).Computer Organization and Design. Morgan Kaufmann. p. 270.ISBN 9780123744937.
  4. ^Hossam A. H. Fahmy; Shlomo Waser; Michael J. Flynn,Computer Arithmetic(PDF), archived fromthe original(PDF) on 2010-10-08, retrieved2011-01-02
  5. ^abcWilliam Kahan (October 1, 1997)."Lecture Notes on the Status of IEEE 754"(PDF). University of California, Berkeley. Retrieved2007-04-12.
  6. ^"Godot math_funcs.h".GitHub.com. 30 July 2022.
  7. ^"Godot math_defs.h".GitHub.com. 30 July 2022.
  8. ^"Godot MathfEx.cs".GitHub.com.
  9. ^"Comparing Floating Point Numbers, 2012 Edition".randomascii.wordpress.com. 26 February 2012.
  10. ^"Java Language and Virtual Machine Specifications".Java Documentation.
  11. ^John R. Hauser (March 1996)."Handling Floating-Point Exceptions in Numeric Programs"(PDF).ACM Transactions on Programming Languages and Systems.18 (2):139–174.doi:10.1145/227699.227701.S2CID 9820157.
  12. ^David Stevenson (March 1981). "IEEE Task P754: A proposed standard for binary floating-point arithmetic".IEEE Computer.14 (3):51–62.doi:10.1109/C-M.1981.220377.S2CID 15523399.
  13. ^William Kahan and John Palmer (1979). "On a proposed floating-point standard".SIGNUM Newsletter.14 (Special):13–21.doi:10.1145/1057520.1057522.S2CID 16981715.
  14. ^ISO/IEC 9899:1999 - Programming languages - C. Iso.org. §7.12.14.
  15. ^abcd"Intel and Floating-Point - Updating One of the Industry's Most Successful Standards - The Technology Vision for the Floating-Point Standard"(PDF).Intel. 2016. Archived fromthe original(PDF) on 2016-03-04. Retrieved2016-05-30. (11 pages)
  16. ^abcd"An Interview with the Old Man of Floating-Point". cs.berkeley.edu. 1998-02-20. Retrieved2016-05-30.
  17. ^abWoehr, Jack, ed. (1997-11-01)."A Conversation with William Kahan".Dr. Dobb's. drdobbs.com. Retrieved2016-05-30.
  18. ^W. Kahan 2003, pers. comm. toMike Cowlishaw and others after an IEEE 754 meeting
  19. ^abcd"IEEE 754: An Interview with William Kahan"(PDF).dr-chuck.com. Retrieved2016-06-02.
  20. ^"IEEE vs. Microsoft Binary Format; Rounding Issues (Complete)".Microsoft Support.Microsoft. 2006-11-21. Article ID KB35826, Q35826.Archived from the original on 2020-08-28. Retrieved2010-02-24.
  21. ^Thornton, James E. (1970). Written at Advanced Design Laboratory, Control Data Corporation.Design of a Computer: The Control Data 6600(PDF) (1 ed.). Glenview, Illinois, USA:Scott, Foresman and Company.LCCN 74-96462.Archived(PDF) from the original on 2020-08-28. Retrieved2016-06-02. (1+13+181+2+2 pages)
  22. ^Kahan, William Morton."Why do we need a floating-point arithmetic standard?"(PDF).cs.berkeley.edu. Retrieved2016-06-02.
  23. ^Kahan, William Morton; Darcy, Joseph D."How Java's Floating-Point Hurts Everyone Everywhere"(PDF).cs.berkeley.edu. Retrieved2016-06-02.
  24. ^Turner, Peter R. (2013-12-21).Numerical Analysis and Parallel Processing: Lectures given at The Lancaster …. Springer.ISBN 978-3-66239812-8. Retrieved2016-05-30.
  25. ^"Names for Standardized Floating-Point Formats"(PDF).cs.berkeley.edu. Retrieved2016-06-02.
  26. ^Charles Severance (20 February 1998)."An Interview with the Old Man of Floating-Point".
  27. ^Charles Severance."History of IEEE Floating-Point Format". Connexions. Archived fromthe original on 2009-11-20.
  28. ^"Molecular Expressions: Science, Optics & You - Olympus MIC-D: Integrated Circuit Gallery - Intel 8087 Math Coprocessor". micro.magnet.fsu.edu. Retrieved2016-05-30.

Further reading

[edit]

External links

[edit]
Current
802 series
802
802.1
802.3
(Ethernet)
802.11
(Wi-Fi)
802.15
Proposed
Superseded
Retrieved from "https://en.wikipedia.org/w/index.php?title=IEEE_754-1985&oldid=1328049132"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp