Floating Point Example
Floating Point Example
For posting on the resources page to help with the floating-point math assignments.
Problem
Add the floating point numbers 3.75 and 5.125 to get 8.875 by directly manipulating the numbers in IEEE format.
For 3.75, the sign bit is 0 (+), the exponent is 128 (1 unbiased), the mantissa (including the implicit 1 shown in bold) is:
0000 0000 1111 0000 0000 0000 0000 0000 = 0x00f00000
For 5.125, the sign bit is 0 (+), the exponent is 129 (2 unbiased), the mantissa (including the implicit 1 shown in bold) is:
0000 0000 1010 0100 0000 0000 0000 0000 = 0x00a40000
Note that we could end up shifting all the bits off the right side, leaving a zero? How do floating-point units handle this?
How about operands with the value 0.0, is that a special case?
For this example the first exponent is 128, second exponent is 129, absolute difference is 1, so first exponent is smaller, so
we must adjust the first mantissa and exponent, and leave the second mantissa and exponent unchanged.
0x00780000 + 0x00a40000 = 0x011c0000 = 0000 0001 0001 1100 0000 0000 0000 0000
Note that the leftmost 1 bit is no longer in bit 23, as required for the IEEE format!
BEFORE NORMALIZATION
Sign of result = 0
Exponent of result = 129
Mantissa of result = 0000 0001 0001 1100 0000 0000 0000 0000 = 0x011c0000
The leftmost 1 bit is bit 24, so we must shift the mantissa right by 1 and add 1 to the exponent:
AFTER NORMALIZATION
Sign of result = 0
Exponent of result = 129 + 1 = 130 = 100000010
Mantissa of result = 0x011c0000 >> 1 = 0x008e0000 = 0000 0000 1000 1110 0000 0000 0000 0000
So final result is: 0 10000010 000 1110 0000 0000 0000 0000 = 0x410e0000, as confirmed by the h-schmidt converter: