Floating-Point Arithmetic

Similar documents
Floating-Point Arithmetic

Floating-Point Arithmetic

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

ECE232: Hardware Organization and Design

Scientific Computing. Error Analysis

15213 Recitation 2: Floating Point

Numeric Encodings Prof. James L. Frankel Harvard University

Floating Point Arithmetic

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

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

COMP2611: Computer Organization. Data Representation

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

CS429: Computer Organization and Architecture

IEEE-754 floating-point

Number Systems. Both numbers are positive

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

Floating-point Error

Chapter 3: Arithmetic for Computers

Representing and Manipulating Floating Points. Jo, Heeseung

CO212 Lecture 10: Arithmetic & Logical Unit

Representing and Manipulating Floating Points

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

Data Representation Floating Point

Chapter Three. Arithmetic

Data Representation Floating Point

Floating Point Numbers

FLOATING POINT NUMBERS

Representing and Manipulating Floating Points

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

Representing and Manipulating Floating Points. Computer Systems Laboratory Sungkyunkwan University

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

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

Representing and Manipulating Floating Points

Arithmetic for Computers. Hwansoo Han

3.1 DATA REPRESENTATION (PART C)

Inf2C - Computer Systems Lecture 2 Data Representation

Floating Point. CENG331 - Computer Organization. Instructors: Murat Manguoglu (Section 1)

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Floating Point Arithmetic

unused unused unused unused unused unused

Divide: Paper & Pencil

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

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Foundations of Computer Systems

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

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

Divide: Paper & Pencil CS152. Computer Architecture and Engineering Lecture 7. Divide, Floating Point, Pentium Bug. DIVIDE HARDWARE Version 1

Ints and Floating Point

Signed umbers. Sign/Magnitude otation

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

Chapter 2 Bits, Data Types, and Operations

COMP Overview of Tutorial #2

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

Floating Point Numbers. Lecture 9 CAP

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

CS101 Lecture 04: Binary Arithmetic

ECE331: Hardware Organization and Design

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

Floating Point Numbers

Floating Point Numbers

IEEE Standard for Floating-Point Arithmetic: 754

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

Finite arithmetic and error analysis

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

Table : IEEE Single Format ± a a 2 a 3 :::a 8 b b 2 b 3 :::b 23 If exponent bitstring a :::a 8 is Then numerical value represented is ( ) 2 = (

Integer Multiplication. Back to Arithmetic. Integer Multiplication. Example (Fig 4.25)

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

Floating Point January 24, 2008

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

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

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

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

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

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

Computer Organization: A Programmer's Perspective

CPS 101 Introduction to Computational Science

Organisasi Sistem Komputer

CS 101: Computer Programming and Utilization

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

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

Floating Point Arithmetic

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Computer Arithmetic Ch 8

Computer Arithmetic Ch 8

Floating Point Considerations

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

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

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

Computer Arithmetic Floating Point

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

The Perils of Floating Point

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

Thomas Polzer Institut für Technische Informatik

Description Hex M E V smallest value > largest denormalized negative infinity number with hex representation 3BB0 ---

Floating Point. CSC207 Fall 2017

Lecture 5. Computer Arithmetic. Ch 9 [Stal10] Integer arithmetic Floating-point arithmetic

Floating-point representations

Giving credit where credit is due

Transcription:

Floating-Point Arithmetic if ((A + A) - A == A) { SelfDestruct() } Reading: Study Chapter 3. L12 Multiplication 1

Approximating Real Numbers on Computers Thus far, we ve entirely ignored one of the most prevalent data types used in computation floating point numbers Floating-point Facts used to be an option used primarily in scientific applications, but now it is a commodity even on low-end computers is only a crude approximation to the mathematical abstraction of real numbers is overused by programmers, since it makes the finiteness of the representation less apparent arithmetic is approximate whereas integer arithmetic is exact Programmers who assume that floating point numbers are real numbers, do so at their peril L12 Multiplication 2

Floating Point Disasters Scud Missiles get through, 28 die In 1991, during the 1 st Gulf War, a Patriot missile defense system let a Scud get through, hit a barracks, and kill 28 people. The problem was due to a floatingpoint error when taking the difference of a converted & scaled integer. (Source: Robert Skeel, "Round-off error cripples Patriot Missile", SIAM News, July 1992.) $7B Rocket crashes (Ariane 5) When the first ESA Ariane 5 was launched on June 4, 1996, it lasted only 39 seconds, then the rocket veered off course and self-destructed. An inertial system, produced an floating-point exception while trying to convert a 64-bit floating-point number to an integer. Ironically, the same code was used in the Ariane 4, but the larger values were never generated (http://www.around.com/ariane.html). Intel Ships and Denies Bugs In 1994, Intel shipped its first Pentium processors with a floating-point divide bug. The bug was due to bad look-up tables used in to speed up quotient calculations. After months of denials, Intel adopted a no-questions replacement policy, costing $300M. (http://www.intel.com/support/processors/pentium/fdiv/) L12 Multiplication 3

Recall Scientific Notation Let s start our discussion of floating point by recalling scientific notation from high school Numbers represented in parts: Arithmetic is done in pieces 1024 1.024 x 10 3-42 - 0.042 x 10 3 982 0.982 x 10 3 42 = 4.200 x 10 1 1024 = 1.024 x 10 3-0.0625 = -6.250 x 10-2 9.820 x 10 2 Significant Digits Exponent Before adding, we must match the exponents, effectively denormalizing the smaller magnitude number We then normalize the final result so there is one digit to the left of the decimal point and adjust the exponent accordingly. L12 Multiplication 4

Multiplication in Scientific Notation Is straightforward: Multiply together the significant parts Add the exponents Normalize if required Examples: 1024 1.024 x 10 3 In multiplication, how far is the most you will ever normalize? In addition? x 0.0625 6.250 x 10-2 64 6.400 x 10 1 42 4.200 x 10 1 x 0.0625 6.250 x 10-2 2.625 26.250 x 10-1 2.625 x 10 0 (Normalized) L12 Multiplication 5

FP == Binary Scientific Notation IEEE single precision floating-point format 0 1 0000 1 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 S Sign Bit E Exponent + 127 F Significand (Mantissa) - 1 0x42280000 in hexadecimal Exponent: Unsigned Bias 127 8-bit integer E = Exponent + 127 Exponent = 10000100 (132) 127 = 5 Significand: Unsigned fixed binary point with hidden-one Significand = 1 + 0.01010000000000000000000 = 1.3125 Putting it all together N = -1 S (1 + F ) x 2 E-127 = -1 0 (1.3125) x 2 5 = 42 L12 Multiplication 6

Example Numbers One Sign = +, Exponent = 0, Significand = 1.0-1 0 (1.0) x 2 0 = 1 S = 0, E = 0 + 127, F = 1.0 1 0 01111111 00000000000000000000000 0x3f800000 One-half Sign = +, Exponent = -1, Significand = 1.0-1 0 (1.0) x 2-1 = ½ S = 0, E = -1 + 127, F = 1.0 1 0 01111110 00000000000000000000000 0x3f000000 Minus Two Sign = -, Exponent = 1, Significand = 1.0 1 10000000 00000000000000000000000 0xc0000000 L12 Multiplication 7

Zeros How do you represent 0? Zero Sign =?, Exponent =?, Significand =? Here s where the hidden 1 comes back to bite you Hint: Zero is small. What s the smallest number you can generate? E = Exponent + 127, Exponent = -127, Signficand = 1.0 1 0 (1.0) x 2-127 = 5.87747 x 10-39 IEEE Convention When E = 0 (Exponent = -127), we ll interpret numbers differently 0 00000000 00000000000000000000000 = 0 not 1.0 x 2-127 1 00000000 00000000000000000000000 = -0 not -1.0 x 2-127 Yes, there are 2 zeros. Setting E=0 is also used to represent a few other small numbers besides 0. In all of these numbers there is no hidden one assumed in F, and they are called the unnormalized numbers. WARNING: If you rely these values you are skating on thin ice! L12 Multiplication 8

Infinities IEEE floating point also reserves the largest possible exponent to represent unrepresentable large numbers Positive Infinity S = 0, E = 255, F = 0 0 11111111 00000000000000000000000 = + 0x7f800000 Negative Infinity -- S = 1, E = 255, F = 0 1 11111111 00000000000000000000000 = - 0xff800000 Other numbers with E = 255 (F 0) are used to represent exceptions or Not-A-Number (NAN) -1, - x 42, 0/0, /, log(-5) It does, however, attempt to handle a few special cases: 1/0 = +, -1/0 = -, log(0) = - L12 Multiplication 9

Low-End of the IEEE Spectrum denorm 0 2 -bias gap 2 1-bias 2-bias 2 normal numbers with hidden bit The gap between 0 and the next representable normalized number is much larger than the gaps between nearby representable numbers. IEEE standard uses denormalized numbers to fill in the gap, making the distances between numbers near 0 more alike. 0 2 -bias 2 1-bias 2-bias 2 p-1 bits of precision p bits of precision Denormalized numbers have a hidden 0 and a fixed exponent of -126 S -126 X = (-1) 2 (0.F) NOTE: Zero is represented using 0 for the exponent and 0 for the mantissa. Either, +0 or -0 can be represented, based on the sign bit. L12 Multiplication 10

Floating-Point Addition L12 Multiplication 11

Floating-Point Multiplication S E F S E F Step 1: Multiply significands Add exponents Small ADDER Subtract 127 Subtract 1 Control S E F 24 by 24 round Mux (Shift Right by 1) E R = E 1 + E 2-127 Exponent R + 127 = Exponent 1 + 127 + Exponent 2 + 127 127 Step 2: Normalize result (Result of [1,2) *[1.2) = [1,4) at most we shift right one bit, and fix exponent L12 Multiplication 12