Presentation is loading. Please wait.

Presentation is loading. Please wait.

Floating Point Numbers

Similar presentations


Presentation on theme: "Floating Point Numbers"— Presentation transcript:

1 Floating Point Numbers

2 Topics Covered Fixed point Numbers
Representation of Floating Point Numbers IEEE 32-bit floating point number. Floating point Arithmetic

3 Fixed Point Numbers The binary (or decimal) point is assumed to be in a fixed position Base 10 fixed point arithmetic:

4 Fixed Point (Binary) Numbers
Example: Add and 6.5 Convert the numbers to 8-bit form (4-bit int, 4-bit fraction): 3.625   6.500   Consider the numbers having an imaginary binary point and added in the normal way: = The integer part of the result is converted to 10, and the fractional part is interpreted as Therefore, the result is

5 Problem with Fixed Point (Binary) Numbers
Some systems require a large range of numbers: Mass of sun: grams Requires about 14 bytes Mass of electron: grams Requires about 12 bytes

6 Floating Point Numbers Definitions
Range How small and how large the numbers can be. Precision The number of significant figures used to represent the number. A measure of a number’s exactness. PI = is more precise that PI = 3.14 Accuracy A measure of the correctness of a number. PI = is more precise than PI = 3.14, but PI = 3.14 is more accurate.

7 IEEE Floating Point Numbers Single Precision Format
-1s * 2E-B * 1.F B = 127

8 IEEE Floating Point Numbers Range of Mantissa
A floating point mantissa is limited to one of the three ranges: -2 < x <= -1 x = 0 +1 <= x < +2

9 IEEE Floating Point Numbers Exponent
Binary Value True Exponent Biased Exponent Special Numbers -127 zero -126 1 -125 2 -124 3 . . . 128 125 252 126 253 127 254 255 +- Infinity

10 IEEE Floating Point Numbers Excess - n
The stored exponent is also called excess – n, or excess 127, for the IEEE single precision format. The stored exponent exceeds the true exponent by 127, the bias. b’ = b + 127 where b’ is the biased exponent, and b is the true exponent. Examples: If the true exponent is 2, the exponent is stored in biased form as = If the stored exponent is , the true exponent is 1 – 127 = -126.

11 IEEE Floating Point Numbers Representation of Zero
The smallest stored exponent (in biased form), corresponding to a true exponent of -127, is used to represent zero.

12 IEEE Floating Point Numbers Infinity and Not a Number (NaN)
 used as +- infinity. and Mantissa != 0  used as NaN.

13 IEEE Floating Point Numbers Example Representation
Represent as a single precision IEEE floating point number. = = x 211 S = 1 (negative) The biased exponent is = 138 = The fractional part of the mantissa is Therefore, =

14 IEEE Floating Point Numbers Addition and Subtraction Flowchart

15 IEEE Floating Point Numbers Arithmetic Example #1
Convert the decimal numbers and into the IEEE 32-bit floating point number representation. Then carry out the subtraction of – and express the result as a normalized 32-bit floating point number. = = x 26 The mantissa is positive, and so S = 0. The exponent is +6, which is stored in biased form as = = The mantissa is , which is stored in 23- bits, with the leading ‘1’ suppressed. Therefore, is stored as: IEEE

16 IEEE Floating Point Numbers Arithmetic Example #1 (Continued)
Convert the decimal numbers and into the IEEE 32-bit floating point number representation. Then carry out the subtraction of – and express the result as a normalized 32-bit floating point number. (Continued) = = x 26 The mantissa is positive, and so S = 0. The exponent is +6, which is stored in biased form as = = The mantissa is , which is stored in 23-bits, with the leading ‘1’ suppressed. Therefore, is stored as: IEEE

17 IEEE Floating Point Numbers Arithmetic Example #1 (Continued)
Convert the decimal numbers and into the IEEE 32-bit floating point number representation. Then carry out the subtraction of – and express the result as a normalized 32-bit floating point number. (Continued) The two IEEE numbers are first unpacked: the sign, exponent, and mantissa must be reconstituted. The two exponents are compared. If they are the same, the mantissas are added. If they are not, the number with the smaller exponent is denormalized by shifting its mantissa right (i.e., dividing by 2) and incrementing its exponent (i.e., multiplying by 2) until the two exponents are equal. Then the numbers are added.

18 IEEE Floating Point Numbers Arithmetic Example #1 (Continued)
Convert the decimal numbers and into the 32-bit floating point number representation. Then carry out the subtraction of – and express the result as a normalized 32-bit floating point number. (Continued) After unpacking, insert the leading ‘1’ and perform the subtraction. Normalize the result:

19 IEEE Floating Point Numbers Arithmetic Example #1 (Continued)
Convert the decimal numbers and into the IEEE 32-bit floating point number representation. Then carry out the subtraction of – and express the result as a normalized 32-bit floating point number. (Continued) The exponent must be decreased by 2. – 210 = The result expressed in IEEE format is:

20 IEEE Floating Point Numbers Arithmetic Example #2
Convert the decimal numbers and into the IEEE 32-bit floating point number representation. Then carry out the addition of and – and express the result as a normalized 32-bit floating point number. = = x 25 The mantissa is positive, and so S = 0. The exponent is +5, which is stored in biased form as = = The mantissa is , which is stored in 23-bits, with the leading ‘1’ suppressed. Therefore, is stored as: IEEE

21 IEEE Floating Point Numbers Arithmetic Example #2 (Continued)
Convert the decimal numbers and into the IEEE 32-bit floating point number representation. Then carry out the addition of – and express the result as a normalized 32-bit floating point number (continued). = = -1.1 x 2-4 The mantissa is negative, and so S = 1. The exponent is -4, which is stored in biased form as = = The mantissa is 1.1, which is stored in 23-bits, with the leading ‘1’ suppressed. Therefore, is stored as: IEEE

22 IEEE Floating Point Numbers Arithmetic Example #2 (Continued)
: : In order to perform the addition, the exponents must be the same. Increase the second exponent by 9 and shift the mantissa right 9 times to get: :

23 IEEE Floating Point Numbers Arithmetic Example #2 (Continued)
: : Adding the mantissas, we get: The result is positive with a biased exponent of Therefore, the result is stored as:


Download ppt "Floating Point Numbers"

Similar presentations


Ads by Google