Floating-point Arithmetic. where you sum up the integer to the left of the decimal point and the fraction to the right.

Similar documents
Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers

ECE232: Hardware Organization and Design

CSCI 402: Computer Architectures. Arithmetic for Computers (3) Fengguang Song Department of Computer & Information Science IUPUI.

Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Lecture 3

COMP2611: Computer Organization. Data Representation

Numeric Encodings Prof. James L. Frankel Harvard University

Floating Point Arithmetic

15213 Recitation 2: Floating Point

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:

Divide: Paper & Pencil

Number Systems. Both numbers are positive

IEEE Standard for Floating-Point Arithmetic: 754

IEEE-754 floating-point

Floating Point Numbers

Computer Architecture and IC Design Lab. Chapter 3 Part 2 Arithmetic for Computers Floating Point

Floating Point. The World is Not Just Integers. Programming languages support numbers with fraction

Floating Point Arithmetic

INTEGER REPRESENTATIONS

CO212 Lecture 10: Arithmetic & Logical Unit

Floating Point Numbers. Lecture 9 CAP

FLOATING POINT NUMBERS

Signed Multiplication Multiply the positives Negate result if signs of operand are different

Chapter Three. Arithmetic

Integers and Floating Point

Floating Point Arithmetic. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

Inf2C - Computer Systems Lecture 2 Data Representation

Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

The Sign consists of a single bit. If this bit is '1', then the number is negative. If this bit is '0', then the number is positive.

ECE331: Hardware Organization and Design

Floating point. Today! IEEE Floating Point Standard! Rounding! Floating Point Operations! Mathematical properties. Next time. !

Floating-Point Arithmetic

Introduction to Computer Systems Recitation 2 May 29, Marjorie Carlson Aditya Gupta Shailin Desai

Data Representation Floating Point

Floating Point (with contributions from Dr. Bin Ren, William & Mary Computer Science)

CS101 Lecture 04: Binary Arithmetic

Floating Point Numbers

Floating Point Numbers

EE 109 Unit 19. IEEE 754 Floating Point Representation Floating Point Arithmetic

Data Representation Floating Point

Signed umbers. Sign/Magnitude otation

CHW 261: Logic Design

Representing and Manipulating Floating Points. Jo, Heeseung

Number Systems and Binary Arithmetic. Quantitative Analysis II Professor Bob Orr

3.5 Floating Point: Overview

IEEE Standard 754 Floating Point Numbers

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

ecture 25 Floating Point Friedland and Weaver Computer Science 61C Spring 2017 March 17th, 2017

Chapter 2 Float Point Arithmetic. Real Numbers in Decimal Notation. Real Numbers in Decimal Notation

Homework 1 graded and returned in class today. Solutions posted online. Request regrades by next class period. Question 10 treated as extra credit

CS 61C: Great Ideas in Computer Architecture Floating Point Arithmetic

Numerical computing. How computers store real numbers and the problems that result

9/3/2015. Data Representation II. 2.4 Signed Integer Representation. 2.4 Signed Integer Representation

Computer Architecture Chapter 3. Fall 2005 Department of Computer Science Kent State University

8/30/2016. In Binary, We Have A Binary Point. ECE 120: Introduction to Computing. Fixed-Point Representations Support Fractions

C NUMERIC FORMATS. Overview. IEEE Single-Precision Floating-point Data Format. Figure C-0. Table C-0. Listing C-0.

CS 101: Computer Programming and Utilization

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754

Characters, Strings, and Floats

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two Solutions 26 February 2014

Foundations of Computer Systems

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

ECE 331 Hardware Organization and Design. Professor Jay Taneja UMass ECE - Discussion 5 2/22/2018

IEEE Floating Point Numbers Overview

Floating-Point Arithmetic

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Chapter 4: Data Representations

Representing and Manipulating Floating Points

Floating Point January 24, 2008

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

Floating Point Arithmetic

CS 261 Fall Floating-Point Numbers. Mike Lam, Professor.

COSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture)

Introduction to Computers and Programming. Numeric Values

Module 2: Computer Arithmetic

UNIT-III COMPUTER ARTHIMETIC

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Recap from Last Time. CSE 2021: Computer Organization. It s All about Numbers! 5/12/2011. Text Pictures Video clips Audio

Chapter 3: Arithmetic for Computers

Finite arithmetic and error analysis

Floating Point Puzzles The course that gives CMU its Zip! Floating Point Jan 22, IEEE Floating Point. Fractional Binary Numbers.

Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation

CS 261 Fall Floating-Point Numbers. Mike Lam, Professor.

CS 61C: Great Ideas in Computer Architecture Performance and Floating Point Arithmetic

Floating point. Today. IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Next time.

Systems I. Floating Point. Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties

Floating-point representations

Floating-point representations

Floating-Point Arithmetic

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

Outline. What is Performance? Restating Performance Equation Time = Seconds. CPU Performance Factors

CS 61C: Great Ideas in Computer Architecture Performance and Floating-Point Arithmetic

The Perils of Floating Point

Chapter 4 Section 2 Operations on Decimals

Computer (Literacy) Skills. Number representations and memory. Lubomír Bulej KDSS MFF UK

MACHINE LEVEL REPRESENTATION OF DATA

Representing and Manipulating Floating Points. Computer Systems Laboratory Sungkyunkwan University

A. Incorrect! To simplify this expression you need to find the product of 7 and 4, not the sum.

Transcription:

Floating-point Arithmetic Reading: pp. 312-328 Floating-Point Representation Non-scientific floating point numbers: A non-integer can be represented as: 2 4 2 3 2 2 2 1 2 0.2-1 2-2 2-3 2-4 where you sum up the integer to the left of the decimal point and the fraction to the right. So, what is -1101.0101 in decimal? 13 3/8 = 13.375 = 8 + 4 + 1 + 1/4 + 1/8 in binary is: 1101.011 What about repeating decimals? i.e. 0.3333333333 In general, the way to convert decimals into binary is the following: 1. Convert whole number part (if >1) using repeated division by two 2. Multiply the remaining fraction by the radix to get first digit right of the radix 3. Repeat step 2 until a. result is a whole number or b. a recognizable pattern emerges or c. you have extended the binary number to an acceptable precision Examples: 1. What is 6.5859375 in binary using the above representation? 2. What is 1/3 = 0.3333333 in binary? 1

Scientific Notation: You use floating point notation to represent very large or very small numbers. Rewrite 53,760,000 using scientific notation: Rewrite.00005376 using scientific notation: The same thing can be done with binary numbers. The notation for this is: ± m B The binary number 1101.011 is the same as 1.101011 x 2 3 Let us now consider 16 bit floating point numbers in the following format: Bit Number 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 Contents s e e 4 e 3 e 2 e 1 e 0 s m m 1 m 2 m 3 m 4 m 5 m 6 m 7 m 8 m 9 Where: s e : is the sign of the exponent e 4 e 3 e 2 e 1 e 0 : is the exponent s m : is the sign of the mantissa (significand) m 1 m 2 m 3 m 4 m 5 m 6 m 7 m 8 m 9 is the mantissa or significand digits ± e With this breakdown of the 16 bits, our number is: s m.m 1 m 2 m 3 m 4 m 5 m 6 m 7 m 8 m 9 x 2 se e4e3e2e1e0 The requirements that the first bit in the mantissa is nonzero and follows the radix point results in what is known as a normalized number. This normalization ensures that all numbers have a unique representation. To decode a floating point number in the above format, consider the following example: 0 0 0 1 0 1 1 1 0 1 1 1 0 0 0 0 This pattern corresponds to -.10111 x 2 5 (note: the exponent of 00101 is 5 in decimal notation). At this point we can either decode the mantissa and multiply by 2 5 or simplify things a bit by moving around the radix point. -.10111 x 2 5 = -10111. x 2 0 = -23 in base 10 2

To encode a number in floating point notation, we simply reverse the process (remember to normalize the number): 3/8 is.011 in binary, so we have.011 x 2 0 =.11 x 2-1 (the right-hand term is the normalized form of the number) and so we encode the number as: 1 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 Examples for you: P1. Encode -46 as a 16-bit normalized floating point number using the above format. P2. Decode the following 16-bit floating point number using the above format: 0 0 0 1 1 1 1 1 0 0 1 0 1 1 0 0 3

Q1: What is the range of the exponent using the above format? Q2: What is the range of the mantissa using the above format? Q3: What is the largest number that can be represented by this 16-bit floating-point number? IEEE Standard 754 Floating-point format This standard was developed to allow portability of programs among various computers and also allow complex numerical programs. This standard has been widely adopted and therefore can be found in most programming environments. There is a 32-bit and 64-bit representation. The principal feature of this representation features the hidden 1 since the numbers are all normalized. We will discuss this in greater detail later on. Single-precision format - -------- ----------------------- S E F where S is the sign bit, E is a binary integer (8 bits), and F is a binary fraction (23 bits). The value of this number is: (-1)S x 2 E-127 x 1.F The representation used for the exponent is called a "biased representation." This means that a fixed value called the bias is subtracted from the binary value of E to get the actual value. Q6: What is the bias of the IEEE 754 fp format? What are the ranges that the exponent can represent? 4

P3: Find what value C03E0000 represents using the IEEE 754 FP format. For double-precison, the value of this number is: (-1) S x2 E-1023 x1.f P4: Find the value C03E000000000000 represents using the IEEE 754 double-precision FP format. It is important to note that not all bit patterns in the IEEE format are interpreted in the same way. I will discuss the single-precision examples and you can extend this to include double-precision. The following are some exceptions: An exponent of 0 with a fraction of 0 represents +0 or -0 depending on the sign bit. An exponent of all 1's with a fraction of 0 represents positive or negative infinity. An exponent of 0 with a nonzero fraction represents a denormalized number. An exponent of all 1's with a nonzero fraction represents a NaN (not a number) and is used to represent various exceptions. Exponents in the range of 1-254 with normalized fractions implies the resulting exponent value will be in the range of -126 to +127. Since the number is normalized, we do not need to represent the 1. This bit is implied and called the hidden 1. It is actually a way of adding one more bit of precision to the fraction. 5

P5: Let's go the other way and find the representation of -1.0 in IEEE 754 FP singleprecision format. Express your result in hex only. 6