Details, Explanation and Meaning About IEEE floating-point standard

IEEE floating-point standard Guide, Meaning , Facts, Information and Description

The IEEE Standard for Binary Floating-Point Arithmetic (IEEE 754) is the most widely-used standard for floating-point computation, and is followed by many CPU and FPU implementations. The standard defines formats for representing floating-point numbers (including ±zero and denormalss) and special values (infinities and NaNs) together with a set of floating-point operations that operate on these values. It also specifies four rounding modes and five exceptions (and when the exceptions occur, and what happens when they do occur).

IEEE 754 specifies four formats for representing floating-point values: single-precision (32-bit), double-precision (64-bit), single-extended precision (>= 43-bit, not commonly used) and double-extended precision (>= 79-bit, usually implemented with 80 bits). Only 32-bit values are required by the standard, the others are optional. Many languages specify that IEEE formats and arithmetic be implemented, although sometimes it is optional. For example, the C programming language, which pre-dated IEEE 754, now allows but does not require IEEE arithmetic (the C float typically is used for IEEE single-precision and double uses IEEE double-precision).

The full title of the standard is IEEE Standard for Binary Floating-Point Arithmetic (ANSI/IEEE Std 754-1985), and it is also known as IEC 60559:1989, Binary floating-point arithmetic for microprocessor systems (originally the reference number was IEC 559:1989).[1]

Table of contents
1 Anatomy of a floating-point number
2 References
3 Revision of the standard
4 External links

Anatomy of a floating-point number

Following is a description of the standard's format for floating-point numbers.

Bit conventions used in this article

Bits within a word of width W are indexed by integers in the range 0 to W−1 inclusive. Bit 0 is drawn on the right. When considering the word, or regions within the word, as binary numbers then usually the lowest indexed bit will also be the least significant.

Single-precision 32 bit

A single-precision binary floating-point number is stored in a 32 bit word:

 1     8               23              width in bits
+-+--------+-----------------------+
|S|  Exp   |  Fraction             |
+-+--------+-----------------------+
31 30    23 22                    0    bit index (0 on right)
   bias +127

Where S is the sign bit and Exp is the Exponent field.

The exponent is biased in the engineering sense of the word – the value stored is offset (by 127 in this case) from the actual value. Biasing is done because exponents have to be signed values in order to be able to represent both tiny and huge values, but two's complement, the usual representation for signed values, would make comparison harder. To solve this the exponent is biased before being stored, by adjusting its value to put it within an unsigned range suitable for comparison. So, for a single-precision number, an exponent in the range −126 .. +127 is biased by adding 127 to get a value in the range 1 .. 254 (0 and 255 have special meanings described below). When interpreting the floating-point number the bias is subtracted to retrieve the actual exponent.

The set of possible data values can be divided into the following classes:

  • zeroes
  • normalised numbers
  • denormalised numbers
  • infinities
  • NaN (Not a Number)

(NaNs are used to represent undefined or invalid results, such as the square root of a negative number.)

The classes are primarily distinguished by the value of the Exp field, modified by the fraction. Consider the Exp and Fraction fields as unsigned binary integers (Exp will be in the range 0–255):

Class                  Exp     Fraction

Zeroes 0 0 Denormalised numbers 0 non zero Normalised numbers 1-254 any Infinities 255 0 NaN (Not a Number) 255 non zero

For normalised numbers, the most common, Exp is the biased exponent and Fraction is the fractional part of the significand. The number has value v:

v = s × 2e × m

Where

s = +1 (positive numbers) when S is 0

s = −1 (negative numbers) when S is 1

e = Exp − 127 (in other words the exponent is stored with 127 added to it, also called "biased with 127")

m = 1.Fraction in binary (that is, the significand is the binary number 1 followed by the radix point followed by the binary bits of Fraction). Therefore, 1 <= m < 2.

Note:

  1. Denormalised numbers are the same except that e = −126 and m is 0.Fraction
  2. −126 is the smallest exponent for a normalised number
  3. There are two Zeroes, +0 (S is 0) and −0 (S is 1)
  4. There are two Infinities +Inf (S is 0) and −Inf (S is 1)
  5. NaNs may have a sign and a significand, but these have no meaning other than for diagnostics; the first bit of the significand is often used to distinguish signaling NaNs from quiet NaNs
  6. NaNs and Infinities have all 1s in the Exp field.

An example

Let's encode the decimal number −118.625 using the IEEE 754 system.

We need to get the sign, the exponent and the fraction.

Because it is a negative number, the sign is "1". Let's find the others.

First, we write the number (without the sign) using binary notation. Look at binary numeral system to see how to do it. The result is 1110110.101

Now, let's move the radix point left, leaving only a 1 at its left: 1110110.101=1.110110101·26

The fraction is the part at the right of the radix point, filled with 0 on the right until we get all 23 bits. That is 11011010100000000000000.

The exponent is 6, but we need to convert it to binary and bias it (so the most negative exponent is 0, and all exponents are non-negative binary numbers). For the 32-bit IEEE 754 format, the bias is 127 and so 6 + 127 = 133. In binary, this is written as 10000101.

Putting them all together:

 1     8               23              width in bits
+-+--------+-----------------------+
|S|  Exp   |  Fraction             |
|1|10000101|11011010100000000000000|
+-+--------+-----------------------+
31 30    23 22                    0    bit index (0 on right)
   bias +127

Double-precision 64 bit

Double-precision is essentially the same except that the fields are wider:

 1     11                                52
+-+-----------+----------------------------------------------------+
|S|  Exp      |  Fraction                                          |
+-+-----------+----------------------------------------------------+
63 62       52 51                                                 0
   bias +1023

NaNs and Infinities are represented with Exp being all 1s (2047).

For Normalised numbers the exponent bias is +1023 (so e is Exp − 1023). For Denormalised numbers the exponent is −1022 (the minimum exponent for a normalised number). As before, both infinity and zero are signed.

Comparing floating-point numbers

An interesting feature of this particular representation is that it makes comparisons of numbers of the same sign which are not NaNs simple. For positive numbers (the sign bit is 0) a and b, then a < b whenever the unsigned binary integers with the same bit patterns as a and b are also ordered the same way. In other words if you are comparing two positive floating-point numbers (known not to be NaNs) you can just use an unsigned binary integer comparison using the same bits.

References

Revision of the standard

Note that the IEEE 754 standard is currently (2004) under revision. See: IEEE 754r

External links


This is an Article on IEEE floating-point standard. Page Contains Information, Facts Details or Explanation Guide About IEEE floating-point standard


Google
 
Web www.E-paranoids.com

Search Anything