Professional Documents
Culture Documents
#3 - Floating Point
#3 - Floating Point
IEEE 754
he range is effectivel& determined '& the n!m'er of digits in the exponent. he precision is determined '& the n!m'er of digits in the fraction. (ore 'its for significand gives more acc!rac& (ore 'its for exponent increases range
)or *inar&
Exponential Notation
The following are eq i!alent representations of "#$%&
123,400.0 12,340.0 1,234.0 123.4 12.34 1.234 0.1234 x x x x x x x 10-2 10-1 100 101 102 103 104
The representations differ in that the decimal place the point -- floats to the left or right (with the appropriate adjustment in the exponent).
-0.9876 x 10-3
Sign of mantissa Location of decimal point
!xponent
antissa
Nor'ali)ation
/ floating point n!m'er is said to 'e normali0ed if the most significant digit of the mantissa is non0ero )or example the decimal n!m'er "50 is normali0ed '!t 000"5 is not. 1egardless of where the position of the radix point is ass!med to 'e in the mantissa, the n!m'er is normali0ed onl& if its leftmost digit is non0ero.
Example2
(2.0) x 10-9 3ormali0ed (0.2) x 10-8 3ot4normali0ed (20.0) x 10-10 3ot4normali0ed
5omp!ters s!pport floating4point arithmetic he fractional point is called the 7'inar& point8
3ormali0ed n!m'ers are generall& prefera'le to !nnormali0ed n!m'ers, 'eca!se there is onl& one normali0ed form, whereas there are man& !nnormali0ed forms.
IEEE ./& 0tan-ar Most co''on stan-ar- for representing floating point n '(ers 0ingle precision1 %$ (its# consisting of222 0ign (it 3" (it4 Exponent 35 (its4 Mantissa 3$% (its4 6o (le precision1 7& (its# consisting of8 0ign (it 3" (it4 Exponent 3"" (its4 Mantissa 3/$ (its4
IEEE FP*./& 0tan-ar =reatl& improved porta'ilit& and >!alit& of comp!ter arithmetic (a?es the leading 1 'it of normali0ed 'inar& n!m'ers implicit
=@ 3!m'ers are expanded '& 1 'it
3!m'ers .4 'its long for single precision+1 implied A ." fraction 3!m'ers are 5" 'its long for do!'le4precision +1 implied A 5. fraction-
Bero is represented as 00 C 00two <as a s&m'ol +NaN = 3ot a n!m'er- for invalid operations +e.g. 0D0 or s!'tracting infinit& from infinit& /llows programmers to postpone some tests and decisions to a later time in the program
/ll other n!m'ers are represented !sing the following form!la2 +41-s x +1 A )raction- x .E
Examples2
En'iased representation2
41 will 'e represented as +41 A 1.7- = 1.$ten = 0111 1110two 40.75 ten = 4 0.11two = 4 1.1two x .41
% "
% 9
$ :
$ 5
$ .
$ 7
$ /
$ &
$ %
$ $
$ "
$ 9
" :
" 5
" .
" 7
" /
" &
" %
" $
" "
" 9
&
"
"
"
"
"
"
9 9
9 9
9 9
9 9
#$ %its
antissa ($# %its) !xponent (& %its) Sign of mantissa (' %it)
where s is the sign of the n!m'er, e represents the 'iased exponent +G 'its- and m represents the mantissa or significand +." 'its ".4'it val!es range in magnit!de from 104"G to 10"G.
%" %9 2 2 2 $% s exponent $$ 222 9
0ignifican- 3Mantissa;Fraction4
he range in magnit!de is from 104"0G to 10"0G he growth of significand and exponent is a compromise 'etween acc!rac& and range.
%" %9 2 2 2 $9 ": s exponent 222 9
0ignifican- 3Mantissa;Fraction4
Nor'ali)ation
The 'antissa is normalized =as an i'plie- -eci'al place on left =as an i'plie- >"? on left of the -eci'al place E2g2#
Mantissa @epresents8
10100000000000000000000 1.1012 = 1.62510
+iase- Exponent
Exponents can 'e 'oth positive ad negative giving rise to a need of sign 'it in exponents.
eg. Exponents ranging from 50 to 49 need 2 digits for t e !a"#e and one $it for t e sign.
*iased Exponent eliminates the need for sign '& adding a positive >!antit& to the exponent so that it is alwa&s positive
%dding 50 to o#r examp"e exponent ma&es t e range as 0 to 99' !a"#e re(#iring 2 digits and no sign $it needed.
Excess Notation
To incl -e A!e an- B!e exponents# >excess? notation is se 0ingle precision1 excess "$. 6o (le precision1 excess "9$% The !al e of the exponent store- is larger than the act al exponent E2g2# excess "$.#10000111
Exponent @epresents8
135 127 = 8
% "
% 9
$ :
$ 5
$ .
$ 7
$ /
$ &
$ %
$ $
$ "
$ 9
" :
" 5
" .
" 7
" /
" &
" %
" $
" "
" 9
&
"
"
" 9
9 "
"
9 9
9 9
9 9
9 9
3*"4s x 3" A Fraction4 x $3Exponent B +ias4 C 3*"4" x 3" A 92$/4 x $3"$: B "$.4 C *" x "2$/ x $$
Exa'ple
0ingle precision
0 10000010 11000000000000000000000 '.''$ '#( '$) * # ( * positi+e mantissa
=exa-eci'al
It is con!enient an- co''on to represent the original floating point n '(er in hexa-eci'al The prece-ing exa'ple8
0 10000010 11000000000000000000000
0 0 0
E2g2# Dhat -eci'al !al e is represente(, the following %$*(it floating point n '(erE
C17B000016
0tep "
Express in (inar, an- fin- 0# E# an- M
C17B000016 = 1 10000010 111101100000000000000002 S !
0tep $
Fin- >real? exponent# n n C E B "$. C "99999"9$ B "$. C "%9 B "$. C%
0tep %
P t 0# M# an- n together to for' (inar, res lt 36onFt forget the i'plie- >"2? on the left of the 'antissa24
-1.11110112 x 2n = -1.11110112 x 23 = -1111.10112
0tep &
Express res lt in -eci'al
-1111.10112 -'. $-' * (.. $-# * (.'$. $-- * (.(/$. (./&).
0nswer1 -'../&).
0tep "
Express original !al e in (inar,
36.562510 = 100100.10012
0tep $
Nor'ali)e
100100.10012 = 1.0010010012 x 25
0tep %
6eter'ine 0# E# an- M
+1.0010010012 x 25 n S
0tep &
P t 0# E# an- M together to for' %$*(it (inar, res lt
0 10000100 001001001000000000000002 S !
0tep /
Express in hexa-eci'al
0 10000100 001001001000000000000002 = 0100 0010 0001 0010 0100 0000 0000 00002 = 4 2 1 2 4 0 0 016
0nswer1 -$'$-((('/
Exponent (ias for nor'ali)e- Is is "9$% The -enor' (iase- exponent of 9 correspon-s to an n(iaseexponent of *"9$$ Infinit, an- NaNs ha!e a (iase- exponent of $9&. @ange increases fro' a(o t "9*%5JKxKJ"9%5 to a(o t "9*%95JKxK J"9%95
@egisters 1
Algorith's
"2 $2 %2 &2 <hecM for )eros Align the 'antissas A-- or s (tract the 'antissas Nor'ali)e the res lt
Operands Alignment Normalize & round 1.076 10-7 1.076 10-7 7.7300 10-9 -9.987 10-8 -0.9987 10-7 + .0005 10-9 0.0773 10-7 7.730 10-9