The Full Wiki

IEEE 754-2008: Wikis

Advertisements
  

Note: Many of our articles have direct quotes from sources you can cite, within the Wikipedia article! This article doesn't yet, but we're working on it! See more info or our list of citable articles.

Encyclopedia

From Wikipedia, the free encyclopedia

The IEEE Standard for Floating-Point Arithmetic (IEEE 754) is the most widely-used standard for floating-point computation, and is followed by many hardware (CPU and FPU) and software implementations. Many computer languages allow or require that some or all arithmetic be carried out using IEEE 754 formats and operations. The current version is IEEE 754-2008, which was published in August 2008; it includes nearly all of the original IEEE 754-1985 (which was published in 1985) and the IEEE Standard for Radix-Independent Floating-Point Arithmetic (IEEE 854-1987).

The standard defines

  • arithmetic formats: sets of binary and decimal floating-point data, which consist of finite numbers (including signed zeros and subnormal numbers), infinities, and special 'not a number' values (NaNs)
  • interchange formats: encodings (bit strings) that may be used to exchange floating-point data in an efficient and compact form
  • rounding algorithms: methods to be used for rounding numbers during arithmetic and conversions
  • operations: arithmetic and other operations on arithmetic formats
  • exception handling: indications of exceptional conditions (such as division by zero, overflow, etc.)

The standard also includes extensive recommendations for advanced exception handling, additional operations (such as trigonometric functions), expression evaluation, and for achieving reproducible results.

The standard is derived from and replaces IEEE 754-1985, the previous version, following a seven-year revision process, chaired by Dan Zuras and edited by Mike Cowlishaw. The binary formats in the original standard are included in the 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.

Contents

Formats

Formats in IEEE 754 describe sets of floating-point data and encodings for interchanging them.

A given format comprises:

  • Finite numbers, which may be either base 2 (binary) or base 10 (decimal). Each finite number is most simply described by three integers: a sign (zero or one), s, a significand (or 'coefficient'), c, and an exponent, q. The numerical value of a finite number is
      (−1)s × c × bq
    where b is the base (2 or 10). For example, if the sign is 1 (indicating negative), the significand is 12345, the exponent is −3, and the base is 10, then the value of the number is −12.345.
  • Two infinities: +∞ and −∞.
  • Two kinds of NaN (quiet and signaling). A NaN may also carry a payload, intended for diagnostic information indicating the source of the NaN. The sign of a NaN has no meaning, but it may be predictable in some circumstances.

The possible finite values that can be represented in a given format are determined by the base (b), the number of digits in the significand (precision, p), and the exponent parameter emax:

  • c must be an integer in the range zero through bp−1 (e.g., if b=10 and p=7 then c is 0 through 9999999)
  • q must be an integer such that 1−emaxq+p−1 ≤ emax (e.g., if p=7 and emax=96 then q is −101 through 90).

Hence (for the example parameters) the smallest non-zero positive number that can be represented is 1×10−101 and the largest is 9999999×1090 (9.999999×1096), and the full range of numbers is −9.999999×1096 through 9.999999×1096. The numbers closest to the inverse of these bounds (−1×10−95 and 1×10−95) are considered to be the smallest (in magnitude) normal numbers; non-zero numbers between these smallest numbers are called subnormal numbers.

Zero values are finite values with significand 0. These are signed zeros, the sign bit specifies if a zero is +0 (positive zero) or −0 (negative zero).

Advertisements

Basic formats

The standard defines five basic formats, named using their base and the number of bits used to encode them. A conforming implementation must fully implement at least one of the basic formats. There are three binary floating-point basic formats (which can be encoded using 32, 64 or 128 bits) and two decimal floating-point basic formats (which can be encoded using 64 or 128 bits). The binary32 and binary64 formats are the single and double formats of IEEE 754-1985.

The precision of the binary formats is one greater than the width of its significand, because there is an implied (hidden) 1 bit.

Name Common name Base Digits E min E max Notes
binary16 Half precision 2 10+1 -14 +15 storage, not basic
binary32 Single precision 2 23+1 -126 +127
binary64 Double precision 2 52+1 -1022 +1023
binary128 Quadruple precision 2 112+1 -16382 +16383
decimal32 10 7 -95 +96 storage, not basic
decimal64 10 16 -383 +384
decimal128 10 34 -6143 +6144

All the basic formats are available in both hardware and software implementations.

Arithmetic formats

A format that is just to be used for arithmetic and other operations need not have an encoding associated with it (that is, an implementation can use whatever internal representation it chooses); 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) that it can represent.

Interchange formats

Interchange formats are intended for the exchange of floating-point data using a fixed-length bit-string for a given format.

For the exchange of binary floating-point numbers, interchange formats of length 16 bits, 32 bits, 64 bits, and any multiple of 32 bits ≥128 are defined. The 16-bit 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 754-1985: 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 k-bit format is computed as w = round(4×log2(k))−13. The existing 64- and 128-bit formats follow this rule, but the 16- and 32-bit formats have more exponent bits (5 and 8) than this formula would provide (3 and 7, respectively).

As with IEEE 754-1985, there is some flexibility in the encoding of signaling NaNs.

For the exchange of decimal floating-point numbers, interchange formats of any multiple of 32 bits are defined.

The encoding scheme for the decimal interchange formats similarly encodes the sign, exponent, and significand, but uses a more complex approach to allow the significand to be encoded as a compressed sequence of decimal digits (using Densely Packed Decimal) or as a binary integer. In either case the set of numbers (combinations of sign, significand, and exponent) that may be encoded is identical, and signaling NaNs have a unique encoding (and the same set of possible payloads).

Rounding algorithms

The standard defines five rounding algorithms. The first two round to a nearest value; the others are called directed roundings:

Roundings to nearest

  • Round to nearest, ties to even – 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 occurs 50% of the time; this is the default algorithm for binary floating-point and the recommended default for decimal
  • Round to nearest, ties away from zero – rounds to the nearest value; if the number falls midway it is rounded to the nearest value above (for positive numbers) or below (for negative numbers)

Directed roundings

  • Round toward 0 – directed rounding towards zero (also called truncation)
  • Round toward +∞ – directed rounding towards positive infinity
  • Round toward −∞ – directed rounding towards negative infinity.

Operations

Required operations for a supported arithmetic format (including the basic formats) include:

  • Arithmetic operations (add, subtract, multiply, divide, square root, fused-multiply-add, remainder, etc.)
  • Conversions (between formats, to and from strings, etc.)
  • Scaling and (for decimal) quantizing
  • Copying and manipulating the sign (abs, negate, etc.)
  • Comparisons and total ordering
  • Classification and testing for NaNs, etc.
  • Testing and setting flags
  • Miscellaneous operations.

Exception handling

The standard defines five exceptions, each of which has a corresponding status flag that (except in certain cases of underflow) is raised when the exception occurs. No other action is required, but alternatives are recommended (see below).

The five possible exceptions are:

  • Invalid operation (e.g., square root of a negative number)
  • Division by zero
  • Overflow (a result is too large to be represented correctly)
  • Underflow (a result is very small (outside the normal range) and is inexact)
  • Inexact.

These are the same five exceptions as were defined in IEEE 754-1985.

Recommendations

Alternate exception handling

The standard recommends optional exception handling in various forms, including traps (exceptions that change the flow of control in some way) and other exception handling models which interrupt the flow, such as try/catch. The traps and other exception mechanisms remain optional, as they were in IEEE 754-1985.

Recommended operations

A new clause in the standard recommends fifty operations, including log, power, and trigonometric functions, that language standards should define. These are all optional (none are required in order to conform to the standard). The operations include some on dynamic modes for attributes, and also a set of reduction operations (sum, scaled product, etc.). All are required to supply a correctly rounded result, but they do not have to detect or report inexactness.

Expression evaluation

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.

Reproducibility

The IEEE 754-1985 allowed many variations in implementations (such as the encoding of some values and the detection of certain exceptions). IEEE 754-2008 has tightened up many of these, 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.

Character representation

The standard requires operations to convert between basic formats and external character sequence formats. 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 even will recover the original number. There is no requirement to preserve the payload of a NaN or signaling NaN, and conversion from the external character sequence may turn a signaling NaN into a quiet NaN.

Correctly rounded results can be obtained converting to decimal and back again to the binary format using:

5 decimal digits for binary16
9 decimal digits for binary32
17 decimal digits for binary64
36 decimal digits for binary128

For other binary formats the required number of decimal digits is

1 + ceiling(p×log102)

where p is the number of significant bits in the binary format, e.g. 24 bits for binary32.

The decimal representation will be preserved using:

7 decimal digits for decimal32
16 decimal digits for decimal64
34 decimal digits for decimal128

Correct rounding is only guaranteed for these numbers of decimal digits plus 3. For instance a conversion from an decimal external sequence with 8 decimal digits is guaranteed to be correctly rounded when converted to binary16, but conversion of a sequence of 9 decimal digits is not.

See also

Further reading

External links


Advertisements






Got something to say? Make a comment.
Your name
Your email address
Message