Floating Point Numbers

Slides:



Advertisements
Similar presentations
Computer Engineering FloatingPoint page 1 Floating Point Number system corresponding to the decimal notation 1,837 * 10 significand exponent A great number.
Advertisements

Topics covered: Floating point arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Floating Point Numbers
1 IEEE Floating Point Revision Guide for Phase Test Week 5.
CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (2)
Floating Point Numbers. CMPE12cGabriel Hugh Elkaim 2 Floating Point Numbers Registers for real numbers usually contain 32 or 64 bits, allowing 2 32 or.
Computer ArchitectureFall 2007 © September 5, 2007 Karem Sakallah CS 447 – Computer Architecture.
Floating Point Numbers. CMPE12cCyrus Bazeghi 2 Floating Point Numbers Registers for real numbers usually contain 32 or 64 bits, allowing 2 32 or 2 64.
Booth’s Algorithm.
Signed Numbers.
2-1 Computer Organization Part Fixed Point Numbers Using only two digits of precision for signed base 10 numbers, the range (interval between lowest.
COE 308: Computer Architecture (T032) Dr. Marwan Abu-Amara Integer & Floating-Point Arithmetic (cont.) (Appendix A, Computer Architecture: A Quantitative.
Floating Point Numbers
Floating Point Numbers
Signed Numbers CS208. Signed Numbers Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers.
Computer ArchitectureFall 2008 © August 27, CS 447 – Computer Architecture Lecture 4 Computer Arithmetic (2)
Number Representation Rizwan Rehman, CCS, DU. Convert a number from decimal to binary notation and vice versa. Understand the different representations.
Computer Science 210 Computer Organization Floating Point Representation.
Floating Point Numbers.  Floating point numbers are real numbers.  In Java, this just means any numbers that aren’t integers (whole numbers)  For example…
The Binary Number System
Data Representation Number Systems.
Numbering Systems CS208.
Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways:  Fixed-point  Floating-point.
Computer Arithmetic Nizamettin AYDIN
Factional Values What is 0.75 in binary?. How could we represent fractions? In decimal: – As fractions : 1/5.
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Chapter Contents.
1 Lecture 5 Floating Point Numbers ITEC 1000 “Introduction to Information Technology”
NUMBER REPRESENTATION CHAPTER 3 – part 3. ONE’S COMPLEMENT REPRESENTATION CHAPTER 3 – part 3.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Information Representation: Negative and Floating Point.
Chapter 1 Data Storage(3) Yonsei University 1 st Semester, 2015 Sanghyun Park.
Data Representation - Part II. Characters A variable may not be a non-numerical type Character is the most common non- numerical type in a programming.
Floating Point. Agenda  History  Basic Terms  General representation of floating point  Constructing a simple floating point representation  Floating.
S. Rawat I.I.T. Kanpur. Floating-point representation IEEE numbers are stored using a kind of scientific notation. ± mantissa * 2 exponent We can represent.
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
Oct. 18, 2007SYSC 2001* - Fall SYSC2001-Ch9.ppt1 See Stallings Chapter 9 Computer Arithmetic.
Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number Columns to the right of the radix have negative.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Chapter 3 Number Representation. Convert a number from decimal to binary notation and vice versa. Understand the different representations of an integer.
Fixed and Floating Point Numbers Lesson 3 Ioan Despi.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI N305 Information Representation: Floating Point Representation.
Number Systems & Operations
Computer Engineering FloatingPoint page 1 Floating Point Number system corresponding to the decimal notation 1,837 * 10 significand exponent A great number.
Introduction To Number Systems Binary System M. AL-Towaileb1.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
R EPRESENTATION OF REAL NUMBER Presented by: Pawan yadav Puneet vinayak.
Lecture 6: Floating Point Number Representation Information Representation: Floating Point Number Representation Lecture # 7.
Fixed-point and floating-point numbers Ellen Spertus MCS 111 October 4, 2001.
Learning Objectives 3.3.1f - Describe the nature and uses of floating point form 3.3.1h - Convert a real number to floating point form Learn how to normalise.
Floating Point Numbers Dr. Mohsen NASRI College of Computer and Information Sciences, Majmaah University, Al Majmaah
Floating Point Arithmetic – Part I
Introduction To Computer Science
Floating Point Number system corresponding to the decimal notation
William Stallings Computer Organization and Architecture 7th Edition
Data Structures Mohammed Thajeel To the second year students
Number Representation
Starter Using the fingers on only one hand, what is the highest number you can count to? Rules: You must start at 1 You must count sequentially (i.e.
OBJECTIVES After reading this chapter, the reader should be able to :
1.6) Storing Integer: 1.7) storing fraction:
Presentation transcript:

Floating Point Numbers CS208

Floating Point Numbers Now you've seen unsigned and signed integers. In real life we also need to be able represent numbers with fractional parts (like: - 12.5 & 45.39). Called Floating Point numbers. You will learn the IEEE 32-bit floating point representation.

Floating Point Numbers In the decimal system, a decimal point (radix point) separates the whole numbers from the fractional part Examples: 37.25 ( whole = 37, fraction = 25/100) 123.567 10.12345678

Floating Point Numbers For example, 37.25 can be analyzed as:   101 100 10-1 10-2 Tens Units Tenths Hundredths 3 7 2 5 37.25 = (3 x 10) + (7 x 1) + (2 x 1/10) + (5 x 1/100)

Binary Equivalence The binary equivalent of a floating point number can be determined by computing the binary representation for each part separately. 1) For the whole part: Use subtraction or division method previously learned. 2) For the fractional part: Use the subtraction or multiplication method (to be shown next)  

Fractional Part – Multiplication Method In the binary representation of a floating point number the column values will be as follows: … 25 24 23 22 21 20 . 2-1 2-2 2-3 2-4 … … 32 16 8 4 2 1 . 1/2 1/4 1/8 1/16… … 32 16 8 4 2 1 . .5 .25 .125 .0625…  

Fractional Part – Multiplication Method Ex 1. Find the binary equivalent of 0.25 Step 1: Multiply the fraction by 2 until the fractional part becomes 0 .25 x 2 0.5 1.0 Step 2: Collect the whole parts in forward order. Put them after the radix point . .5 .25 .125 .0625 . 0 1

Fractional Part – Multiplication Method Ex 2. Find the binary equivalent of 0.625 Step 1: Multiply the fraction by 2 until the fractional part becomes 0 .625 x 2 1.25 0.50 1.0 Step 2: Collect the whole parts in forward order. Put them after the radix point . .5 .25 .125 .0625 . 1 0 1

Fractional Part – Subtraction Method Start with the column values again, as follows: … 20 . 2-1 2-2 2-3 2-4 2-5 2-6… … 1 . 1/2 1/4 1/8 1/16 1/32 1/64… … 1 . .5 .25 .125 .0625 .03125 .015625…  

Fractional Part – Subtraction Method Starting with 0.5, subtract the column values from left to right. Insert a 0 in the column if the value cannot be subtracted or 1 if it can be. Continue until the fraction becomes .0 Ex 1. .25 .5 .25 .125 .0625 - .25 .0 1 .0

Binary Equivalent of FP number Ex 2. Convert 37.25, using subtraction method.  64 32 16 8 4 2 1 . .5 .25 .125 .0625 26 25 24 23 22 21 20 . 2-1 2-2 2-3 2-4 1 0 0 1 0 1 37 - 32 5 - 4 1 -1 . 0 1 .25 - .25 .0 37.2510 = 100101.012

Binary Equivalent of FP number Ex 3. Convert 18.625, using subtraction method.  64 32 16 8 4 2 1 . .5 .25 .125 .0625 26 25 24 23 22 21 20 . 2-1 2-2 2-3 2-4 1 0 0 1 0 1 0 1 18 .625 - 16 - .5 2 .125 - 2 - .125 0 0 18.62510 = 10010.1012

Try It Yourself Convert the following decimal numbers to binary: 60.7510 190.562510 (Answers on next page)

Answers 60.7510 = 111100.112 190.562510 = 10111110.10012

Problem storing binary form We have no way to store the radix point! Standards committee came up with a way to store floating point numbers (that have a decimal point)

IEEE Floating Point Representation Floating point numbers can be stored into 32-bits, by dividing the bits into three parts: the sign, the exponent, and the mantissa.   1 2 9 10 32

IEEE Floating Point Representation The first (leftmost) field of our floating point representation will STILL be the sign bit: 0 for a positive number, 1 for a negative number.

Storing the Binary Form How do we store a radix point? - All we have are zeros and ones… Make sure that the radix point is ALWAYS in the same position within the number. Use the IEEE 32-bit standard  the leftmost digit must be a 1

Solution is Normalization Every binary number, except the one corresponding to the number zero, can be normalized by choosing the exponent so that the radix point falls to the right of the leftmost 1 bit. 37.2510 = 100101.012 = 1.0010101 x 25 7.62510 = 111.1012 = 1.11101 x 22 0.312510 = 0.01012 = 1.01 x 2-2

IEEE Floating Point Representation The second field of the floating point number will be the exponent. The exponent is stored as an unsigned 8-bit number, RELATIVE to a bias of 127. Exponent 5 is stored as (127 + 5) or 132 132 = 10000100 Exponent -5 is stored as (127 + (-5)) or 122 122 = 01111010

Try It Yourself How would the following exponents be stored (8-bits, 127-biased): 2-10 28 (Answers on next slide)

Answers 2-10 exponent -10 8-bit bias +127 value 117  01110101 28 117  01110101 28 exponent 8 8-bit 135  10000111

IEEE Floating Point Representation The mantissa is the set of 0’s and 1’s to the left of the radix point of the normalized (when the digit to the left of the radix point is 1) binary number. Ex: 1.00101 X 23 (The mantissa is 00101) The mantissa is stored in a 23 bit field, so we add zeros to the right side and store: 00101000000000000000000

Decimal Floating Point to IEEE standard Conversion  Ex 1: Find the IEEE FP representation of 40.15625 Step 1. Compute the binary equivalent of the whole part and the fractional part. (i.e. convert 40 and .15625 to their binary equivalents)

Decimal Floating Point to IEEE standard Conversion   40 .15625 - 32 Result: -.12500 Result: 8 101000 .03125 .00101 - 8 -.03125 0 .0   So: 40.1562510 = 101000.001012

Decimal Floating Point to IEEE standard Conversion Step 2. Normalize the number by moving the decimal point to the right of the leftmost one. 101000.00101 = 1.0100000101 x 25  

Decimal Floating Point to IEEE standard Conversion Step 3. Convert the exponent to a biased exponent 127 + 5 = 132 And convert biased exponent to 8-bit unsigned binary: 13210 = 100001002  

Decimal Floating Point to IEEE standard Conversion Step 4. Store the results from steps 1-3: Sign Exponent Mantissa (from step 3) (from step 2) 0 10000100 01000001010000000000000  

Decimal Floating Point to IEEE standard Conversion Ex 2: Find the IEEE FP representation of –24.75  Step 1. Compute the binary equivalent of the whole part and the fractional part.  24 .75 - 16 Result: - .50 Result: 8 11000 .25 .11 - 8 - .25 0 .0   So: -24.7510 = -11000.112  

Decimal Floating Point to IEEE standard Conversion   Step 2. Normalize the number by moving the decimal point to the right of the leftmost one. -11000.11 = -1.100011 x 24  

Decimal Floating Point to IEEE standard Conversion. Step 3. Convert the exponent to a biased exponent 127 + 4 = 131 ==> 13110 = 100000112   Step 4. Store the results from steps 1-3 Sign Exponent mantissa 1 10000011 1000110..0

Try It Yourself Convert the following numbers to IEEE floating point representation: 60.7510 -190.562510

Answers 60.7510 = 0 10000100 11100110..0 -190.562510 = 1 10000110 011111010010..0

IEEE standard to Decimal Floating Point Conversion. Do the steps in reverse order In reversing the normalization step move the radix point the number of digits equal to the exponent: If exponent is positive, move to the right If exponent is negative, move to the left

IEEE standard to Decimal Floating Point Conversion. Ex 1:  Convert the following 32-bit binary number to its decimal floating point equivalent: Sign Exponent Mantissa   1 01111101 010..0

IEEE standard to Decimal Floating Point Conversion.. Step 1: Extract the biased exponent and unbias it Biased exponent = 011111012 = 12510 Unbiased Exponent: 125 – 127 = -2

IEEE standard to Decimal Floating Point Conversion.. Step 2: Write Normalized number in the form: 1 . ____________ x 2 ---- For our number: -1. 01 x 2 –2   Exponent Mantissa

IEEE standard to Decimal Floating Point Conversion. Step 3: Denormalize the binary number from step 2 (i.e. move the decimal and get rid of (x 2n) part): -0.01012 (negative exponent – move left)   Step 4: Convert binary number to the FP equivalent (i.e. Add all column values with 1s in them) -0.01012 = - ( 0.25 + 0.0625) = -0.312510

IEEE standard to Decimal Floating Point Conversion. Ex 2: Convert the following 32 bit binary number to its decimal floating point equivalent: Sign Exponent Mantissa 0 10000011 10011000..0  

IEEE standard to Decimal Floating Point Conversion.. Step 1: Extract the biased exponent and unbias it Biased exponent = 10000112 = 13110 Unbiased Exponent: 131 – 127 = 4

IEEE standard to Decimal Floating Point Conversion.. Step 2: Write Normalized number in the form: 1 . ____________ x 2 ---- For our number: 1.10011 x 2 4 Exponent Mantissa

IEEE standard to Decimal Floating Point Conversion. Step 3: Denormalize the binary number from step 2 (i.e. move the decimal and get rid of (x 2n) part: 11001.12 (positive exponent – move right)   Step 4: Convert binary number to the FP equivalent (i.e. Add all column values with 1s in them) 11001.1 = 16 + 8 + 1 +.5 = 25.510

Try It Yourself Convert the following IEEE floating point numbers to decimal: 0 10000010 1110010..0 0 10000110 01010..0 1 01111101 10100..0

Answers 0 10000010 1110010..0 = 15.12510 0 10000110 01010..0 = 168.010 1 01111101 10100 = -0.4062510