IEEE Floating Point Numbers Overview

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

Floating Point Numbers

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

COMP2611: Computer Organization. Data Representation

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

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

Giving credit where credit is due

Data Representation Floating Point

Giving credit where credit is due

Floating Point Numbers. Lecture 9 CAP

Data Representation Floating Point

Floating Point Numbers

Floating Point Numbers

Floating Point Arithmetic

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

Floating Point January 24, 2008

ECE232: Hardware Organization and Design

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

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

System Programming CISC 360. Floating Point September 16, 2008

FLOATING POINT NUMBERS

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

Numeric Encodings Prof. James L. Frankel Harvard University

15213 Recitation 2: Floating Point

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

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

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

Computer Systems C S Cynthia Lee

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

IEEE Standard 754 Floating Point Numbers

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

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

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

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

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

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

Computer Organization: A Programmer's Perspective

CS429: Computer Organization and Architecture

Data Representation Floating Point

Foundations of Computer Systems

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

Floating Point Arithmetic

INTEGER REPRESENTATIONS

Characters, Strings, and Floats

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

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

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

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.

Floating Point Numbers

3.5 Floating Point: Overview

Divide: Paper & Pencil

Topic Notes: Bits and Bytes and Numbers

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

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

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Representing and Manipulating Floating Points. Jo, Heeseung

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

Representing and Manipulating Floating Points

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

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

Inf2C - Computer Systems Lecture 2 Data Representation

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Bits and Bytes and Numbers

Real Numbers finite subset real numbers floating point numbers Scientific Notation fixed point numbers

COMP2121: Microprocessors and Interfacing. Number Systems

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

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

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

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

Representing and Manipulating Floating Points

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

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

Set Theory in Computer Science. Binary Numbers. Base 10 Number. What is a Number? = Binary Number Example

unused unused unused unused unused unused

Representing and Manipulating Floating Points. Computer Systems Laboratory Sungkyunkwan University

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

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

What we need to know about error: Class Outline. Computational Methods CMSC/AMSC/MAPL 460. Errors in data and computation

Floating Point. EE 109 Unit 20. Floating Point Representation. Fixed Point

Computational Methods CMSC/AMSC/MAPL 460. Representing numbers in floating point and associated issues. Ramani Duraiswami, Dept. of Computer Science

Chapter Three. Arithmetic

IEEE-754 floating-point

CS101 Introduction to computing Floating Point Numbers

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

Systems Programming and Computer Architecture ( )

Representing and Manipulating Floating Points

UNIT 7A Data Representation: Numbers and Text. Digital Data

Computational Methods CMSC/AMSC/MAPL 460. Representing numbers in floating point and associated issues. Ramani Duraiswami, Dept. of Computer Science

Chapter 2. Data Representation in Computer Systems

Topic Notes: Bits and Bytes and Numbers

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

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

Signed umbers. Sign/Magnitude otation

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

CO212 Lecture 10: Arithmetic & Logical Unit

MA 1128: Lecture 02 1/22/2018

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

Math 340 Fall 2014, Victor Matveev. Binary system, round-off errors, loss of significance, and double precision accuracy.

Floating-Point Arithmetic

Floating-Point Numbers in Digital Computers

Bindel, Fall 2016 Matrix Computations (CS 6210) Notes for

Transcription:

COMP 40: Machine Structure and Assembly Language Programming (Fall 2015) IEEE Floating Point Numbers Overview Noah Mendelsohn Tufts University Email: noah@cs.tufts.edu Web: http://www.cs.tufts.edu/~noah

Note: There are excellent detailed descriptions in Bryant and O Hallaron. These slides are designed to give you an introduction, and some intuition about why IEEE floating point works the way it does.

What s Wrong with Integers?

Big numbers Estimated US National Debt as of 7 Oct 2013: $16,753,342,516,305.38* What if we had only limited space in which to write? Besides, do we really think the 38 cents are meaningful? We re more likely to say informally: $16.8 trillion A scientist would of course write this as: 1.68 x 10 13 * Source: http://www.brillig.com/debt_clock/ 4

Big numbers Key intuition: we can approximate a very large range of numbers using Estimated US National Debt as of 7 very Oct few 2013: digits $16,753,342,516,305.38* if we re willing to lose the less significant digits. What if we had only limited space in which to write? Besides, do we really think the 38 cents are meaningful? We re more likely to say informally: $16.8 trillion A scientist would of course write this as: 1.68 x 10 13 * Source: http://www.brillig.com/debt_clock/ 5

Big numbers Estimated US National Debt as of 7 Oct 2013: $16,753,342,516,305.38* Warning: What this means if we had we only may limited treat space in which to write? $16,753,342,516,305.38 and Besides, do we really think the 38 cents are meaningful? $16,753,976,632,595.72 as the same number! We re more likely to say informally: $16.8 trillion A scientist would of course write this as: 1.68 x 10 13 * Source: http://www.brillig.com/debt_clock/ 6

Starting with Decimal IEEE floating point uses binary for both fractions and exponents. Students typically have more intuition for decimal, so we ll introduce the concepts with decimal first.

Scientific Notation Let s approximate: $16,753,342,516,305.38 using Scientific Notation 1.6753 x 10 13 8

Scientific Notation Let s approximate: $16,753,342,516,305.38 using Scientific Notation 1.6753 x 10 13 Significand Exponent Negative numbers: significand is negative Very small numbers: exponent is negative * You may see references to the word mantissa it s another term for significand 9

Normalization All of these represent the same number:.16753 x 10 14.016753. x 10 15 1.6753 x 10 13 16.753 x 10 12 16753. x 10 9 Normalized (One non-zero digit left of decimal point) Whenever possible IEEE floating point numbers are normalized 10

Normalization: Any time we have many equivalent elements and want to compare them Equivalence class of objects/values all of which map to same thing in the world of ideas Pick a canonical, normal, representative element of set based on some criterion Whenever you generate or manipulate something, convert it to normal/canonical form Comparison is now easy 11

Floating Point Computer Data Types

Why floating point types? Need a way to work with very wide range of values Willing to make same tradeoff as scientific notation We only carry the high order digits nearby values not distinguished What we need Standardized encoding in bits Arithmetic and other operations IEEE 754 floating point is a cross industry standard* 32 and 64 bit encodings: latter carries more digits & wider range of exponents Standardized arithmetic including edge cases usually in hardware Includes special NaN values for error cases (+/- INFinity) etc. Subnormal numbers implement gradual underflow (advanced topic) Most software systems provide math functions (sqrt, sin, cos, atan, etc., etc.) The IA64 machines we use all implement IEEE floating point which are used for the float (32 bit) and double (64 bit) C types 13

Reminder: how it worked in decimal Decimal 1/10 1/100 1/1000 1/10000.2375 x 10 1 (2/10 + 3/100 + 7/1000 + 5/10000) * 10 2 3/8 14

but we need to do it in binary! Binary 1/2 1/4 1/8 1/16 1.0011 x 2 1 ( 1 0/2 0/4 1/8 1/16) * 2 2 3/8 15

Decimal and binary compared 16

IEEE single precision floating point encodes this in 32 bits Huh? That doesn t look right! +1.0011 x 2 1 0 10000000 00110000000000000000000 32 bits 17

The encoding is a bit tricky Sign: 1 bit (0 = positive, 1 = negative) Exponent 8 bits (true exponent + bias of 127) Significand: 23 bits (as you would expect but without the leading 1 bit) Let s use our example to make this clearer 18

IEEE floating point encodes this in 32 bits +1.0011 x 2 1 Sign bit: 0 = positive 0 10000000 00110000000000000000000 32 bits 19

IEEE floating point encodes this in 32 bits +1.0011 x 2 1 Exponent is 1 but we need to add bias 1 + 127 = 128 Binary: 10000000 0 10000000 00110000000000000000000 32 bits 20

IEEE floating point encodes this in 32 bits +1.0011 x 2 1 Remember, there is always a 1 here for normalized numbers we don t waste a bit storing it 0 10000000 00110000000000000000000 32 bits 21

IEEE floating point encodes this in 32 bits +1.0011 x 2 1 The fraction is stored left aligned 0 10000000 00110000000000000000000 32 bits 22

IEEE floating point encodes this in 32 bits +1.0011 x 2 1 Implied binary point is left of the fraction 0 10000000 00110000000000000000000 32 bits 23

A few more details Why all this trickiness? Saving bits (e.g. not saving the invariant 1) Integer compares put positive floating point numbers in sorted order! There s also a 64 bit format (the C double type) 1 bit sign 11 bit exponent (bias is 1023) 52 bit fraction There are some details we haven t covered Exponent of 0 means denormalized number: provides useful values close to zero. There is no implied 1 and the exponent is fixed at -126 for 32 bit and -1022 for 64 bit). These values have less precision. All zeros is zero. If only sign bit on, then negative zero! (yes there is -0!) Exponent of all 1 s denotes special values: +/- Infinity, Exception values, etc. You should read about this in B&O. You may be tested on both 32 & 64 bit formats 24