Presentation on theme: "Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems"— Presentation transcript:
Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems Autumn 2013 Week 4a: Floating Point Notation for Binary Fractions 22 October 2013
Recap: Binary Numbers In the standard notation for binary numbers a string of binary digits such as 1001 stands for a sum of powers of 2: 1x2 3 +0x2 2 +0x2 1 +1x2 0 Binary and Decimal are different names for the same number 22 October 2013Birkbeck College, U. London2
Recap: Binary Addition 22 October 2013Brookshear, Section 1.53 column: ===== There is a carry from column 0 to column 1 and from column 1 to column 2. In tests or examinations, always show the carries.
Recap: Twos Complement Twos complement representations can be added as if they were standard binary numbers. 22 October 2013Brookshear, Section == ====
Numbers in Computing 22 October 2013Birkbeck College, U. London5 cells in table: all numbers *: numbers that can be stored in memory #: numbers that can be referred to in a program *#*# # # ***#*# # ** # *#*# * Example: 0.1 cannot be stored in memory in IEEE double precision floating point, but the following is a correct Java statement t = 0.1;
Spacing Between Numbers 22 October 2013Birkbeck College, U. London6 Twos complement: equally spaced numbers 0 Floating point: big gaps between big numbers, small gaps between small numbers. 0
The Key: Exponents 22 October 2013Birkbeck College, U. London /16 1/8 ¼ ½ big gaps between big numbers small gaps between small numbers
Brookshear, Section 1.78 Example of a Binary Fraction The binary fraction has three parts: The sign – The position of the radix point The bit string October 2013
Brookshear, Section 1.79 Reconstruction of a Binary Fraction The sign is + The position of the radix point is just to the right of the second bit from the left The bit string is What is the binary fraction? 22 October 2013
Brookshear, Section Summary To represent a binary fraction three pieces of information are needed: Sign Position of the radix point Bit string
Brookshear, Section Standard Form for a Binary Fraction Any non-zero binary fraction can be written in the form ±2 r x 0.t where t is a bit string beginning with 1. Examples = +2 2 x = x October 2013
Brookshear, Section Floating Point Representation Write a non-zero binary fraction in the form ± 2 r x 0.t Record the sign – bit string s1 Record r – bit string s2 Record t – bit string s3 Output s1||s2||s3 22 October 2013
Brookshear, Section Floating Point Notation 8 bit floating point: se1e2e3m1m2m3m4 sign exponent mantissa 1 bit 3 bits 4 bits radix r bit string t The exponent is in 3 bit excess notation
22 October 2013Brookshear, Section To Find the Floating Point Notation Write the non-zero number as ± 2 r x 0.t If sign = -1, then s1=1, else s1=0. s2 = 3 bit excess notation for r. s3= rightmost four bits of t.
22 October 2013Birkbeck College, U. London15 Example b= s=1 b= x exponent = -2, s2 =010 Floating point notation
22 October 2013Birkbeck College, U. London16 Second Example Floating point notation: s1=1, therefore negative. s2 = 011, exponent=-1 s3 = 1100 Binary fraction = -3/8
Birkbeck College, U. London17 Class Examples Find the floating point representation of the decimal number -1 1/8 Find the decimal number which has the floating point representation October 2013
Brookshear, Section Round-Off Error 2+5/8= ½ = The 8 bit floating point notations for 2 5/8 and 2 ½ are the same: The error in approximating 2+5/8 with is round-off error or truncation error.
Floating Point Addition Let [x] be the floating point number closest to the number x. Floating point addition, is defined by Each operation w |-> [w] may introduce round off. 22 October 2013Birkbeck College, U. London19
22 October 2013Birkbeck College, U. London20 Examples of Floating Point Addition 2 ½: /8: ¼: ¾: /8)=2 1/4=2 ¾ (2 1/8=2 1/8=2 ½
22 October 2013Birkbeck College, U. London21 Round-Off in Decimal and Binary 1/5=0.2 exactly in decimal notation 1/5= ….. in binary notation 1/5 cannot be represented exactly in binary floating point no matter how many bits are used. Round-off is unavoidable but it is reduced by using more bits.
22 October 2013Birkbeck College, U. London22 Size of Round-Off Error E(x) E(x)/xα where α is constant. If x > 0, y > 0 and |x-y|<α x, then x-y cannot be found accurately using floating point arithmetic.
Birkbeck College, U. London24 Floating Point Errors Overflow: number too large to be represented. Underflow: number <>0 and too small to be represented. Invalid operation: e.g. SquareRoot[-1]. See 22 October 2013
Birkbeck College, U. London25 IEEE Standard for Floating Point Arithmetic For a general discussion of fp arithmetic see 01…89…31 Sign s bit 0 Exponent e bits 1-8 Mantissa m bits 9-31 If 0