Floating Point Arithmetic

Slides:



Advertisements
Similar presentations
Binary Arithmetic Binary addition Binary subtraction
Advertisements

Representing fractions – Fixed point The problem: How to represent fractions with finite number of bits ?
Floating Point Numbers
CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (2)
Computer ArchitectureFall 2007 © September 5, 2007 Karem Sakallah CS 447 – Computer Architecture.
Booth’s Algorithm.
Chapter 5 Floating Point Numbers. Real Numbers l Floating point representation is used whenever the number to be represented is outside the range of integer.
1 Lecture 3 Bit Operations Floating Point – 32 bits or 64 bits 1.
Integer Arithmetic Floating Point Representation Floating Point Arithmetic Topics.
Floating Point Numbers
1 Module 2: Floating-Point Representation. 2 Floating Point Numbers ■ Significant x base exponent ■ Example:
Floating Point Numbers
CS1104: Computer Organisation comp. nus. edu
Computer ArchitectureFall 2008 © August 27, CS 447 – Computer Architecture Lecture 4 Computer Arithmetic (2)
Floating Point Numbers.  Floating point numbers are real numbers.  In Java, this just means any numbers that aren’t integers (whole numbers)  For example…
Binary Number Systems.
School of Computer Science G51CSA 1 Computer Arithmetic.
Chapter 3 Data Representation part2 Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
CS1104-2aNumber Systems Supplementary Notes 1 Lecture 2: Number Systems Supplementary Notes  Complements Complements  Floating-point Numbers Floating-point.
Chapter3 Fixed Point Representation Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
The Binary Number System
Simple Data Type Representation and conversion of numbers
ELEN 5346/4304 DSP and Filter Design Fall Lecture 12: Number representation and Quantization effects Instructor: Dr. Gleb V. Tcheslavski Contact:
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
Number Systems II Prepared by Dr P Marais (Modified by D Burford)
NUMBER REPRESENTATION CHAPTER 3 – part 3. ONE’S COMPLEMENT REPRESENTATION CHAPTER 3 – part 3.
Chapter 1 Data Storage(3) Yonsei University 1 st Semester, 2015 Sanghyun Park.
Computer Architecture
Floating Point. Agenda  History  Basic Terms  General representation of floating point  Constructing a simple floating point representation  Floating.
Data Representation in Computer Systems
Complement Numbers. Outline  Negative Numbers Representation  Sign-and-magnitude  1s Complement  2s Complement  Comparison of Sign-and-Magnitude.
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
9.4 FLOATING-POINT REPRESENTATION
Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.
ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations.
Number Systems and Codes. CS2100 Number Systems and Codes 2 NUMBER SYSTEMS & CODES Information Representations Number Systems Base Conversion Negative.
CSC 221 Computer Organization and Assembly Language
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Integer & Floating Point Representations CDA 3101 Discussion Session 05.
Lecture notes Reading: Section 3.4, 3.5, 3.6 Multiplication
Integer and Fixed Point P & H: Chapter 3
Computer Architecture Lecture 22 Fasih ur Rehman.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Representation of Data (Part II) Computer Studies Notes: chapter 19 Ma King Man.
Fixed-point and floating-point numbers Ellen Spertus MCS 111 October 4, 2001.
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
COSC2410: LAB 2 BINARY ARITHMETIC SIGNED NUMBERS FLOATING POINT REPRESENTATION BOOLEAN ALGEBRA 1.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Floating Point Arithmetic – Part I
Chapter 9 Computer Arithmetic
CS2100 Computer Organisation
Department of Computer Science Georgia State University
William Stallings Computer Organization and Architecture 7th Edition
CS1010 Programming Methodology
Number Representations
ECEG-3202 Computer Architecture and Organization
Chapter 8 Computer Arithmetic
Chapter3 Fixed Point Representation
Number Representations
1.6) Storing Integer: 1.7) storing fraction:
Presentation transcript:

Floating Point Arithmetic Morgan Kaufmann Publishers 24 April, 2017 Floating Point Arithmetic Chapter 4 — The Processor

Outline Overflow Fixed Point Numbers Floating Point Numbers Excess Representation Arithmetic with Floating Point Numbers

Outline Overflow Fixed Point Numbers Floating Point Numbers Excess Representation Arithmetic with Floating Point Numbers

Overflow Signed binary numbers are of a fixed range. If the result of addition/subtraction goes beyond this range, overflow occurs. Two conditions under which overflow can occur are: (i) positive add positive gives negative (ii) negative add negative gives positive

Overflow Examples: 4-bit numbers (in 2s complement) Range : (1000)2s to (0111)2s or (-810 to 710) (i) (0101)2s + (0110)2s= (1011)2s (5)10 + (6)10= -(5)10 ?! (overflow!) (ii) (1001)2s + (1101)2s = (10110)2s discard end-carry = (0110)2s (-7)10 + (-3)10 = (6)10 ?! (overflow!)

Outline Overflow Fixed Point Numbers Floating Point Numbers Excess Representation Arithmetic with Floating Point Numbers

Fixed Point Numbers The signed and unsigned numbers representation given are fixed point numbers. The binary point is assumed to be at a fixed location, say, at the end of the number: Can represent all integers between –128 to 127 (for 8 bits). binary point

Fixed Point Numbers In general, other locations for binary points possible. Examples: If two fractional bits are used, we can represent: (001010.11)2s = (10.75)10 (111110.11)2s = -(000001.01)2 = -(1.25)10 binary point integer part fraction part

Outline Overflow Fixed Point Numbers Floating Point Numbers Excess Representation Arithmetic with Floating Point Numbers

Floating Point Numbers Fixed point numbers have limited range. To represent very large or very small numbers, we use floating point numbers (cf. scientific numbers). Examples: 0.23 x 1023 (very large positive number) 0.5 x 10-32 (very small positive number) -0.1239 x 10-18 (very small negative number)

Floating Point Numbers Floating point numbers have three parts: sign, mantissa, and exponent The base (radix) is assumed (usually base 2). The sign is a single bit (0 for positive number, 1 for negative). mantissa exponent sign

Floating Point Numbers Mantissa is usually in normalised form: (base 10) 23 x 1021 normalised to 0.23 x 1023 (base 10) -0.0017 x 1021 normalised to -0.17 x 1019 (base 2) 0.01101 x 23 normalised to 0.1101 x 22 Normalised form: The fraction portion cannot begin with zero. More bits in exponent gives larger range. More bits for mantissa gives better precision.

Floating Point Numbers Exponent is usually expressed in complement or excess form. Example: Express -(6.5)10 in base-2 normalised form -(6.5)10 = -(110.1)2 = -0.1101 x 23 Assuming that the floating-point representation contains 1-bit sign, 5-bit normalised mantissa, and 4-bit exponent. The above example will be represented as 1 11010 0011

Floating Point Numbers Example: Express (0.1875)10 in base-2 normalised form (0.1875)10 = (0.0011)2 = 0.11 x 2-2 Assuming that the floating-pt rep. contains 1-bit sign, 5-bit normalized mantissa, and 4-bit exponent. The above example will be represented as 11000 1101 1110 0110 If exponent is in 1’s complement. If exponent is in 2’s complement. If exponent is in excess-8.

Outline Overflow Fixed Point Numbers Floating Point Numbers Excess Representation Arithmetic with Floating Point Numbers

Excess Representation The excess representation allows the range of values to be distributed evenly among the positive and negative value, by a simple translation (addition/subtraction). Example: For a 3-bit representation, we may use excess-4. Excess-4 Representation Value 000 -4 001 -3 010 -2 011 -1 100 101 1 110 2 111 3

Excess Representation Example: For a 4-bit representation, we may use excess-8. Excess-8 Representation Value 0000 -8 0001 -7 0010 -6 0011 -5 0100 -4 0101 -3 0110 -2 0111 -1 Excess-8 Representation Value 1000 1001 1 1010 2 1011 3 1100 4 1101 5 1110 6 1111 7

Outline Overflow Fixed Point Numbers Floating Point Numbers Excess Representation Arithmetic with Floating Point Numbers

Arithmetic with Floating Point Numbers Arithmetic is more difficult for floating point numbers. MULTIPLICATION Steps: (i) multiply the mantissa (ii) add-up the exponents (iii) normalize Example: (0.12 x 102)10 x (0.2 x 1030)10 = (0.12 x 0.2)10 x 102+30 = (0.024)10 x 1032 (normalize) = (0.24 x 1031)10

Arithmetic with Floating Point Numbers ADDITION Steps: (i) equalize the exponents (ii) add-up the mantissa (iii) normalize Example: (0.12 x 103)10 + (0.2 x 102)10 = (0.12 x 103)10 + (0.02 x 103)10 (equalize exponents) = (0.12 + 0.02)10 x 103 (add mantissa) = (0.14 x 103)10 Can you figure out how to do perform SUBTRACTION and DIVISION for (binary/decimal) floating-point numbers?