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

Lecture - 2 Number systems and computer data formats
Topics covered: Floating point arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Floating Point (FLP) Representation A Floating Point value: f = m*r**e Where: m – mantissa or fractional r – base or radix, usually r = 2 e - exponent.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Datorteknik FloatingPoint bild 1 Floating point Number system corresponding to the decimal notation 1,837 * 10 significand exponent a great number of corresponding.
Floating Point Numbers
1 IEEE Floating Point Revision Guide for Phase Test Week 5.
Chapter 1.7 Storing Fractions. Excess Notation, continued… In this notation, "m" indicates the total number of bits. For us (working with 8 bits), it.
CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (2)
Floating Point Numbers
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
Computer ArchitectureFall 2008 © August 27, CS 447 – Computer Architecture Lecture 4 Computer Arithmetic (2)
Computer Science 210 Computer Organization Floating Point Representation.
The IEEE Format for storing float (single precision) data type Use the “enter” key to proceed through the show.
Binary Representation and Computer Arithmetic
The Binary Number System
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.
Floating Point. Agenda  History  Basic Terms  General representation of floating point  Constructing a simple floating point representation  Floating.
Floating Point (a brief look) We need a way to represent –numbers with fractions, e.g., –very small numbers, e.g., –very large numbers,
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
Data Representation Dr. Ahmed El-Bialy Dr. Sahar Fawzy.
©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.
COMP201 Computer Systems Floating Point Numbers. Floating Point Numbers  Representations considered so far have a limited range dependent on the number.
Floating Point Arithmetic
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.
©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.
Floating Point Numbers Dr. Mohsen NASRI College of Computer and Information Sciences, Majmaah University, Al Majmaah
Floating Point Arithmetic – Part I
Chapter 9 Computer Arithmetic
FLOATING-POINT NUMBER REPRESENTATION
Floating Point Representations
Programming and Data Structure
Introduction To Computer Science
Floating Point Representations
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
Data Representation Data Types Complements Fixed Point Representation
Number Representation
Numbers with fractions Could be done in pure binary
OBJECTIVES After reading this chapter, the reader should be able to :
1.6) Storing Integer: 1.7) storing fraction:
Presentation transcript:

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) 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 Equivalent The binary equivalent of a floating point number can be computed by computing the binary representation for each part separately. whole part: subtraction or division Fractional part: subtraction or multiplication  

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

Finding Binary Equivalent of fraction part Converting .25 using Multiplication method. Step 1 : multiply fraction by 2 until fraction becomes 0   .25 x 2 0.5 1.0 Step 2 Collect the whole parts and place them after the radix point 64 32 16 8 4 2 1 . .5 .25 .125 .0625 . 0 1

Finding Binary Equivalent of fraction part Converting .25 using subtraction method. Step 1: write positional powers of two and column values for the fractional part   . 2-1 2-2 2-3 2-4 2 -5 . ½ ¼ 1/8 1/16 1/32 . .5 .25 .125 .0625 0.03125

Finding Binary Equivalent of fraction part Converting .25 using subtraction method. Step 2: start subtracting the column values from left to right, place a 0 if the value cannot be subtracted or 1 if it can until the fraction becomes .0 . .25 2 1 . .5 .25 .125 .0625 - .25 . 0 1 .0

Binary Equivalent of FP number Given 37.25, convert 37 and .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 . 0 1 37 .25 - 32 - .25 5 .0 - 4 1 37.2510 = 100101.012 -1

So what is the Problem? Given the following binary representation: 37.2510 = 100101.012 7.62510 = 111.1012 0.312510 = 0.01012 How we can represent the whole and fraction part of the binary rep. in 4 bytes?

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

So what Happened ? After normalizing, the numbers now have different mantissas and exponents. 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 Floating point numbers can be represented by binary codes by dividing them into three parts: the sign, the exponent, and the mantissa.   1 2 9 10 32

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

IEEE Floating Point Representation The second field of the floating point number will be the exponent. Since we must be able to represent both positive and negative exponents, we will use a convention which uses a value known as a bias of 127 to determine the representation of the exponent. An exponent of 5 is therefore stored as 127 + 5 or 132; an exponent of -5 is stored as 127 + (-5) OR 122. The biased exponent, the value actually stored, will range from 0 through 255. This is the range of values that can be represented by 8-bit, unsigned binary numbers.

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 stored in a 23 bit field,

Example: Find the IEEE FP representation of 40.15625. Converting decimal floating point values to stored IEEE standard values.  Example: Find the IEEE FP representation of 40.15625. Step 1. Compute the binary equivalent of the whole part and the fractional part. ( convert 40 and .15625. to their binary equivalents)  

Converting decimal floating point values to stored IEEE standard values.   40 .15625 - 32 Result: - .12500 Result: 8 101000 .03125 .00101 - 8 - .03125 0 .0   So: 40.1562510 = 101000.001012

Converting decimal floating point values to stored IEEE standard values.   Step 2. Normalize the number by moving the decimal point to the right of the leftmost one. 101000.00101 = 1.0100000101 x 25  

Step 3. Convert the exponent to a biased exponent Converting decimal floating point values to stored IEEE standard values.   Step 3. Convert the exponent to a biased exponent 127 + 5 = 132 ==> 13210 = 100001002  

Step 4. Store the results from above Converting decimal floating point values to stored IEEE standard values.   Step 4. Store the results from above Sign Exponent (from step 3) Mantissa ( from step 2) 0 10000100 01000001010 .. 0  

Ex : Find the IEEE FP representation of –24.75 Converting decimal floating point values to stored IEEE standard values.   Ex : 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  

Converting decimal floating point values to stored IEEE standard values.   Step 2. Normalize the number by moving the decimal point to the right of the leftmost one. -11000.11 = -1.100011 x 24  

Step 3. Convert the exponent to a biased exponent 127 + 4 = 131 Converting decimal floating point values to stored IEEE standard values. Step 3. Convert the exponent to a biased exponent 127 + 4 = 131 ==> 13110 = 100000112   Step 4. Store the results from above Sign Exponent mantissa 1 10000011 1000110..0

Converting from IEEE format to the decimal floating point values. 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 +ve move to the right, if –ve move to the left.

Converting from IEEE format to the decimal floating point values. Ex:  Convert the following 32 bit binary numbers to their decimal floating point equivalents. Sign Exponent Mantissa   a. 1 01111101 010..0

Converting from IEEE format to the decimal floating point values. Step 1 Extract exponent (unbias exponent) biased exponent = 01111101 = 125 exponent: 125 - 127= -2

Converting from IEEE format to the decimal floating point values. Step 2 Write Normalized number 1 . ____________ x 2 ---- -1. 01 x 2 –2   Exponent mantissa

Converting from IEEE format to the decimal floating point values. Step 3: Write the binary number (denormalize value from step2)   -0.01012 Step 4: Convert binary number to FP equivalent ( add column values) -0.01012 = - ( 0.25 + 0.0625) = -0.3125

Converting from IEEE format to the decimal floating point values. Ex: Convert the following 32 bit binary numbers to their decimal floating point equivalents. Sign Exponent Mantissa 0 10000011 1101010..0  

Converting from IEEE format to the decimal floating point values. Step 1 Extract exponent (unbias exponent) biased exponent = 10000011 = 131 exponent: 131 - 127= 4

Converting from IEEE format to the decimal floating point values. Step 2 Write Normalized number 1 . ____________ x 2 ---- 1. 110101 x 2 4   Exponent mantissa

Converting from IEEE format to the decimal floating point values. Step 3 Write the binary number (denormailze value from step 2)   11101.012 Step 4 Convert binary number to FP equivalent ( add column values) 11101.012 = 16 + 8 + 4 + 1 + 0.25 = 29.2510