ELEC2041 Microprocessors and Interfacing Lectures 19: Floating Point Number Representation - I
ELEC2041 Microprocessors and Interfacing Lectures 19: Floating Point Number Representation - I
au/
April 2006
Saeid Nooshabadi
[email protected]
ELEC2041 lec19-fp-I.1 Saeid Nooshabadi
IEEE-754 Standard
ELEC2041 lec19-fp-I.2
Saeid Nooshabadi
Review of Numbers Computers are made to deal with numbers What can we represent in N bits?
Unsigned integers: 0 -2(N-1) to 2N - 1 to 2(N-1) - 1 Signed Integers (Twos Complement)
ELEC2041 lec19-fp-I.3
Saeid Nooshabadi
Irrationals 21/2
(1.414213562373. . .)
Scientific Notation Review fraction Exponent mantissa/significand 02 x 1023 6 6.02 Integer decimal point radix (base)
Normalized form: no leadings 0s (exactly one digit to left of decimal point)
d3 Example: represent 1.32 as d1d2.f1 x 10 (only one digit after the decimal point)
ELEC2041 lec19-fp-I.6
Saeid Nooshabadi
For simplicity, assume integer Representation for Significand. Represent N by d1d2d3, where
d3 Case 1) N = d1d2 x 10 d2d3 Case 2) N = d1 x 10 d3 Case 3) N = d1d2 x 100
ELEC2041 lec19-fp-I.7
Saeid Nooshabadi
9 10 N = 99 x 10 = 9.9 x 10 N = 9 x 10 99
9 19 N = 99 x 100 = 9.9 x 10
ELEC2041 lec19-fp-I.8
Saeid Nooshabadi
ELEC2041 lec19-fp-I.9
and d2>0
All can represent the same number of different values. Two of the systems can represent an equal number of values, more than the third. #3 can represent more values than the other two. #2 can represent more values than the other two. #1 can represent more values than the other two
Saeid Nooshabadi
Computer arithmetic that supports it is called floating point, because it represents numbers where binary point is not fixed, as it is for integers
Declare such variable in C as float
ELEC2041 lec19-fp-I.11
Saeid Nooshabadi
Easy to do arithmetic ( +, -, *, / )
ELEC2041 lec19-fp-I.12
Saeid Nooshabadi
Floating Point Representation (#1/2) Normal format: +1.xxxxxxxxxxtwo*2yyyytwo Multiple of Word Size (32 bits)
31 30 23 22 S Exponent
1 bit 8 bits Significand 23 bits 0
S represents Sign Exponent represents ys Significand represents xs Leading 1 in Significand is implied Represent numbers as small as 2.0 x 10-38 to as large as 2.0 x 1038
ELEC2041 lec19-fp-I.13 Saeid Nooshabadi
Floating Point Representation (#2/2) What if result too large? (> 2.0x1038 )
Overflow!
Overflow => Exponent larger than represented in 8-bit Exponent field
Double Precision Fl. Pt. Representation Next Multiple of Word Size (64 bits)
31 30 20 19 S Exponent 1 bit 11 bits Significand
ELEC2041 lec19-fp-I.16
IEEE 754 Floating Point Standard (#1/6) Single Precision, (DP similar) Sign bit: Significand:
To pack more bits, leading 1 implicit for normalized numbers. (Hidden Bit)
1 + 23 bits single, 1 + 52 bits double
0 10000 10100
0 11000 01010
Therefore order is Sign Exponent Fraction 1.0 x 1020 > 1.1 x 1010
S Exponent
ELEC2041 lec19-fp-I.19
Significand
Saeid Nooshabadi
Negative Exponent?
2s comp? 1.0 x 2-1 vs 1.0 x2+1 (1/2 vs 2)
1/2 0 1111 1111 000 0000 0000 0000 0000 0000 2 0 0000 0001 000 0000 0000 0000 0000 0000
This notation using integer compare of 1/2 vs 2 makes 1/2 > 2!
ELEC2041 lec19-fp-I.20 Saeid Nooshabadi
IEEE 754 Floating Point Standard (#5/6) Instead, pick notation: 0000 0000 is most negative, 1111 1111 is most positive
Called Biased Notation; bias subtracted to get number 127 in Single Prec. (1023 D.P.)
-127 0000 0000 -126 0000 0001 ... -1 0111 1110 0 0111 1111 +1 1000 0000 ... +127 1111 1110 +128 1111 1111
2s comp? 1.0 x 2-1 vs 1.0 x 2+1 (1/2 vs 2) 1/2 0 0111 1110 000 0000 0000 0000 0000 0000 2 0 1000 0000 000 0000 0000 0000 0000 0000
This notation using integer compare of 1/2 vs 2 makes 2 look greater than 1/2
ELEC2041 lec19-fp-I.21 Saeid Nooshabadi
ELEC2041 lec19-fp-I.22
Saeid Nooshabadi
1 1.000 x 20
1.000 x 2-1
2 1.000 x 21
3 4
-1.000 x 23
And in Conclusion..
Number of digits allocated to significand and exponent, and choice of base, can affect both the number of different representable values and the range of values. Finite precision means we have to cope with roundoff error (arithmetic with inexact values) and truncation error (large values overwhelming small ones).
IEEE 754 Standard allows Single Precision (1 word) and Double Precision (2-word) representation of FP. Nos.
ELEC2041 lec19-fp-I.24 Saeid Nooshabadi