Explain IEEE-754 standard for floating point representation. Express (314.175)10 in all the IEEE-754 models.
Explain IEEE-754 standard for floating point representation. Express (314.175)10 in all the IEEE-754 models.
IEEE 754 is the standard format for real numbers in almost every computer. A number is stored as $(-1)^s \times 1.f \times 2^{e}$ in three fields: the sign bit $s$ (0 for positive, 1 for negative), the biased exponent $E = e + \text{bias}$, and the fraction $f$. The leading 1 is implied and not stored.
| Model | Total bits | Sign | Exponent | Fraction | Bias |
|---|---|---|---|---|---|
| Single precision | 32 | 1 | 8 | 23 | 127 |
| Double precision | 64 | 1 | 11 | 52 | 1023 |
The bias keeps the stored exponent positive, so numbers can be compared like integers. The all-0 and all-1 exponent patterns are kept for special values.
| Exponent | Fraction | Meaning |
|---|---|---|
| all 0 | 0 | zero |
| all 0 | not 0 | denormal number |
| all 1 | 0 | infinity |
| all 1 | not 0 | NaN (not a number) |
Normal numbers use the stored exponents 1 to 254 in single precision and 1 to 2046 in double precision. Rounding to the nearest value is the default way to fit a long fraction into the fraction field, and it keeps the error below half of the last bit.
Representing 314.175
The number is positive, so $s = 0$. The integer part is $314 = 100111010_2$. For the fraction, we double $0.175$ again and again and note the digits:
$$0.175 = 0.001011,0011,0011\ldots_2$$
So the number is $100111010.0010110011\ldots_2$. Move the point 8 places left to normalise:
$$314.175 = 1.001110100010110011\ldots_2 \times 2^{8}$$
The true exponent is $e = 8$. The fraction starts with $00111010$ (from the integer part) and then continues with the digits of $0.175$.
Single precision. The stored exponent is:
$$E = 8 + 127 = 135 = 10000111_2$$
The fraction takes 23 bits. The bits after the 23rd are $0110\ldots$, which are less than half, so we round down. Therefore:
| Sign | Exponent | Fraction |
|---|---|---|
| 0 | 10000111 | 00111010001011001100110 |
In hexadecimal this is $\text{0x439D1666}$.
Double precision. The stored exponent is:
$$E = 8 + 1023 = 1031 = 10000000111_2$$
The fraction takes 52 bits. The bits after the 52nd are $1100\ldots$, which is more than half, so the last bit is rounded up. Therefore:
| Sign | Exponent | Fraction |
|---|---|---|
| 0 | 10000000111 | 0011101000101100110011001100110011001100110011001101 |
In hexadecimal this is $\text{0x4073A2CCCCCCCCCD}$.
Neither answer is exact, because $0.175$ has a repeating binary fraction. The error is about $10^{-5}$ in single precision and about $10^{-14}$ in double precision. To check the single answer, decode it: $E = 135$ gives $e = 8$, and the value is $1.00111010001011001100110_2 \times 2^8 \approx 314.17499$.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.
Up nextExplain the concept of pipelining and also explain types of pipelining.