Floating Point Numbers

Similar documents
FLOATING POINT NUMBERS

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

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

Floating Point Arithmetic

COMP2611: Computer Organization. Data Representation

ECE232: Hardware Organization and Design

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

Floating Point Numbers

Floating Point Numbers

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

15213 Recitation 2: Floating Point

Data Representation Floating Point

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

Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition. Carnegie Mellon

Data Representation Floating Point

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

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

Floating-point representations

Floating-point representations

Divide: Paper & Pencil

Floating Point : Introduction to Computer Systems 4 th Lecture, May 25, Instructor: Brian Railing. Carnegie Mellon

Floating Point. CSE 238/2038/2138: Systems Programming. Instructor: Fatma CORUT ERGİN. Slides adapted from Bryant & O Hallaron s slides

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

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

CS 33. Data Representation (Part 3) CS33 Intro to Computer Systems VIII 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

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

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

Giving credit where credit is due

Giving credit where credit is due

CO212 Lecture 10: Arithmetic & Logical Unit

Floating Point January 24, 2008

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.

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

Foundations of Computer Systems

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

Representing and Manipulating Floating Points

System Programming CISC 360. Floating Point September 16, 2008

Integers and Floating Point

Computer Organization: A Programmer's Perspective

Floating Point Numbers

Floating Point Arithmetic

Today: Floating Point. Floating Point. Fractional Binary Numbers. Fractional binary numbers. bi bi 1 b2 b1 b0 b 1 b 2 b 3 b j

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

Numeric Encodings Prof. James L. Frankel Harvard University

CS429: Computer Organization and Architecture

3.5 Floating Point: Overview

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

Data Representation Floating Point

Finite arithmetic and error analysis

Representing and Manipulating Floating Points

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

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

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Written Homework 3. Floating-Point Example (1/2)

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

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

EE878 Special Topics in VLSI. Computer Arithmetic for Digital Signal Processing

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

IEEE Floating Point Numbers Overview

Floating Point Representation in Computers

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering. Digital Computer Arithmetic ECE 666

Computer Systems C S Cynthia Lee

Floating Point Representation. CS Summer 2008 Jonathan Kaldor

IEEE Standard for Floating-Point Arithmetic: 754

CS Computer Architecture. 1. Explain Carry Look Ahead adders in detail

Representing and Manipulating Floating Points. Jo, Heeseung

Representing and Manipulating Floating Points

Representing and Manipulating Floating Points. Computer Systems Laboratory Sungkyunkwan University

Floating Point COE 308. Computer Architecture Prof. Muhamed Mudawar. Computer Engineering Department King Fahd University of Petroleum and Minerals

Floating Point Numbers. Lecture 9 CAP

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

CS 6210 Fall 2016 Bei Wang. Lecture 4 Floating Point Systems Continued

MIPS Integer ALU Requirements

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

The course that gives CMU its Zip! Floating Point Arithmetic Feb 17, 2000

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

Module 2: Computer Arithmetic

Floating Point Arithmetic

Real Numbers. range -- need to deal with larger range, not just [not just -2^(n-1) to +2^(n-1)-1] - large numbers - small numbers (fractions)

Inf2C - Computer Systems Lecture 2 Data Representation

Arithmetic for Computers. Hwansoo Han

Computer Arithmetic Floating Point

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

IEEE-754 floating-point

Floating Point Arithmetic

CS61c Midterm Review (fa06) Number representation and Floating points From your friendly reader

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

EE260: Logic Design, Spring n Integer multiplication. n Booth s algorithm. n Integer division. n Restoring, non-restoring

CS101 Introduction to computing Floating Point Numbers

Lecture 13: (Integer Multiplication and Division) FLOATING POINT NUMBERS

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

UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering. Digital Computer Arithmetic ECE 666

Chapter 3 Arithmetic for Computers (Part 2)

COMP Overview of Tutorial #2

COMPUTER ORGANIZATION AND DESIGN

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

Chapter 3: Arithmetic for Computers

Chapter 3. Arithmetic Text: P&H rev

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

Transcription:

Floating Point Numbers Summer 8 Fractional numbers Fractional numbers fixed point Floating point numbers the IEEE 7 floating point standard Floating point operations Rounding modes CMPE Summer 8 Slides by ADB

Positional representation of fractional numbers In base - - - - Multiplier Number - - - - Position Decimal point CMPE Summer 8 Slides by ADB Positional representation of fractional numbers In base - - - - Multiplier Number - - - - Position Binary point CMPE Summer 8 Slides by ADB

Fractional numbers fixed point Fixed-point representation How much information is necessary to store? How do you choose a format for the bits? Fixed-point operations Addition Align binary points, and add straight down Multiplication??? CMPE Summer 8 Slides by ADB Decimal to binary conversion Convert A =. to base CMPE Summer 8 Slides by ADB

Fixed-point number density CMPE Summer 8 Slides by ADB 7 Scientific notation In base Example:. 8 In base Example:. (= 8. ) The general form r = Sign significand base Exponent CMPE Summer 8 Slides by ADB 8

Single-precision IEEE 7 floating-point numbers 9 8 7 9 8 7 9 8 7 e x p o n e n t Sign significand One-bit sign Eight-bit exponent -bit significand That s the fractional part CMPE Summer 8 Slides by ADB 9 Single-precision IEEE 7 floating-point numbers Normalized numbers: only one non-zero bit to the left of the binary point Adjust the exponent as needed r = ( ) S F E Implicit leading in the significand (the hidden bit ) r = ( ) S ( + F) E Bias notation to represent the exponent With the bias B = 7 r = ( ) S ( + F) E-B CMPE Summer 8 Slides by ADB

How to convert a base- number into IEEE 7 single-precision floating point Convert the number to binary The big part And the fractional part Normalize Isolate the hidden one Remove the significand s hidden one Add bias to the exponent Represent the number CMPE Summer 8 Slides by ADB Example:. 9 8 7 9 8 7 9 8 7 Sign Convert to binary Normalize Remove hidden one Add bias to exponent The end significand CMPE Summer 8 Slides by ADB

Double-precision IEEE 7 floating-point numbers 9 8 7 9 8 7 9 8 7 e x p o n e n t Sign significand 9 8 7 9 8 7 9 8 7 significand, continued One-bit sign Eleven-bit exponent -bit significand That s the fractional part CMPE Summer 8 Slides by ADB Summary of IEEE 7 formats Precision Parameter Single Single Ext. Double Double Ext. Bits for F Bits for E 8 E max +7 + + +8 E min 8 Total bits 79 For every precision, there are reserved exponents, used for special quantities: E min (i.e., E=) is used for zero and denorms E max + (i.e., E= or E=7, with bias) is used for NaN and infinity CMPE Summer 8 Slides by ADB 7

Special quantities: Infinity This special quantity avoids halt on overflow Much safer than returning the largest possible number Representation: E = E max + E = in single precision with bias E = 7 in double precision with bias F = Sign (+ or ) 9 8 7 9 8 7 9 8 7 Sign significand CMPE Summer 8 Slides by ADB Special quantities: Infinity Examples of operations that return ±Inf Operation / / Inf Sqrt (+Inf) / Inf Result CMPE Summer 8 Slides by ADB 8

Special quantities: NaN (Not a Number) This special quantity avoids halt on invalid operations Representation: E = E max + E = in single precision with bias E = 7 in double precision with bias F 9 8 7 9 8 7 9 8 7 Sign significand CMPE Summer 8 Slides by ADB 7 Special quantities: NaN (Not a Number) Examples of operations that return NaN Operation Result +/ / /+ / / Inf log(+) log( ) CMPE Summer 8 Slides by ADB 8 9

Special quantities: Zero Representation: E = E min (i.e., E = ) F = Sign: + or 9 8 7 9 8 7 9 8 7 Sign significand CMPE Summer 8 Slides by ADB 9 Special quantities: Zero Examples of operations that involve ± Operation + / Sqrt NaN produced by CMPE Summer 8 Slides by ADB

Floating point numbers range What is the largest number we can represent in IEEE 7 single-precision floating point? What is the smallest number? 9 8 7 9 8 7 9 8 7 Sign significand CMPE Summer 8 Slides by ADB Floating point numbers range What is the largest number we can represent in IEEE 7 double-precision floating point? What is the smallest number? CMPE Summer 8 Slides by ADB

Floating point numbers: density Fact : Floats are not reals E.g., / Fact : Floats are not decimals E.g.,. (base ) =. (base ) Fact : Not even all the integers in the range are represented E.g.,,, (base ) = (base ) CMPE Summer 8 Slides by ADB Floating point numbers: density Close to : high density Far from : low density CMPE Summer 8 Slides by ADB

Special quantities: Denormals These are numbers smaller than ^(E min ) Fill the gap between ^(E min ) and (gradual underflow) Representation: E = E min (i.e., E = ) F The number represented is.f - f - f - ^(E min ) 9 8 7 9 8 7 9 8 7 Sign significand CMPE Summer 8 Slides by ADB Special quantities: Denormals From to ^(E min ) CMPE Summer 8 Slides by ADB

Summary of IEEE 7 numbers Single precision Exponent Significand Double precision Exponent Significand Object anything anything 7 7 CMPE Summer 8 Slides by ADB 7 Floating point operations: addition Addition: C = A + B Step : Align the significands Are the exponents different? Shift the smaller number to the right and adjust the exponent Step : Add the significands Don t forget the sign Step : Normalize the sum Check for overflow or underflow CMPE Summer 8 Slides by ADB 8

Floating point operations: addition A =. (base ) B =. (base ) Step : Align the significands Step : Add the significands Step : Normalize the sum CMPE Summer 8 Slides by ADB 9 Floating point operations: multiplication C = A B Step : Add the exponents Step : Multiply the significands Without the sign Step : Normalize the product Step : Set the sign of the product Both positive? Result is positive Both negative? Result is positive Different signs? Result is negative CMPE Summer 8 Slides by ADB

Floating point operations: multiplication A =. (base ) B =. (base ) Step : Add the exponents Step : Multiply the significands Step : Normalize the product Step : Set the sign of the product CMPE Summer 8 Slides by ADB Rounding What is rounding, and when do we need to round? Numbers that we can represent, and numbers that we can not represent: What is fair? CMPE Summer 8 Slides by ADB

Rounding modes IEEE 7 defines four rounding modes Towards +Inf Towards Inf Towards To nearest CMPE Summer 8 Slides by ADB Rounding modes We need some extra bits In IEEE-7, the internal representation uses at least more bits in the significand Guard Round Sticky CMPE Summer 8 Slides by ADB 7

Rounding modes CMPE Summer 8 Slides by ADB Recommended exercises Ex. A: Represent the binary number A =. in IEEE 7 single-precision and double-precision. Ex. B: Give the IEEE 7 single-precision representation of the number (thirty-four million and one). Give its rounded representation using all four rounding modes, and for each one, give the decimal value of the number actually represented. CMPE Summer 8 Slides by ADB 8