Computer Architecture, Lecture 14: Does your computer know how to add?

Size: px
Start display at page:

Download "Computer Architecture, Lecture 14: Does your computer know how to add?"

Transcription

1 Computer Architecture, Lecture 14: Does your computer know how to add? Hossam A. H. Fahmy Cairo University Electronics and Communications Engineering 1 / 25

2 A strange behavior What do you expect from this code? 1 #include<s t d i o. h> 2 3 int main ( void ) 4 { 5 f l o a t x=+0.0, y= 0.0; 6 7 p r i n t f ( \n\ t \ t The amazing r e s u l t s : \n ) ; 8 p r i n t f ( \n 10ˆ30 = %f, E30 ) ; 9 p r i n t f ( \n 10ˆ30 10ˆ30 = 0= %f, E E30 ) ; 10 p r i n t f ( \n 10ˆ60 = 10ˆ30 10ˆ30 = %f, E E30 ) ; 11 p r i n t f ( \n 10ˆ60 = 10ˆ30 10ˆ30 = %f, ( f l o a t ) ( E E30 ) ) ; 12 p r i n t f ( \n 1. 0 / ( ) = %f, 1. 0 / x ) ; 13 p r i n t f ( \n 1. 0 / ( 0. 0 ) = %f, 1. 0 / y ) ; 14 p r i n t f ( \n ( 0.0)= %f, x+y ) ; 15 p r i n t f ( \n 0.0 ( 0.0)= %f, y y ) ; 16 p r i n t f ( \n 1. 0 / ( ) + 1/( 0.0)= %f, ( 1. 0 / x ) +(1.0/ y ) ) ; 17 p r i n t f ( \n\n\ t+ /+ /+ /+ /+ /+ /+ /+ /+ /+ /\n\n ) ; 18 } 2 / 25

3 Simple results! Here is the output. 1 The amazing r e s u l t s : ˆ30 = ˆ30 10ˆ30 = 0= ˆ60 = 10ˆ30 10ˆ30 = ˆ60 = 10ˆ30 10ˆ30 = i n f / ( ) = i n f / ( 0. 0 ) = i n f ( 0.0)= ( 0.0)= / ( ) + 1/( 0.0)= nan /+ /+ /+ /+ /+ /+ /+ /+ /+ / 3 / 25

4 Scientific notation The value of a number in scientific notation has six attributes: ± d 0 d 1 d 2 d t β ±exp The computer representation of floating point numbers is similar. 4 / 25

5 Simple tests Consider the following C code 1 #include <s t d i o. h> 2 3 int main ( void ) 4 { 5 double x, y ; 6 double twox, threex ; 7 double z1, z2 ; 8 9 x = 0. 1 ; y = 0. 3 ; twox = 2. 0 x ; t h r e e x = 3. 0 x ; z1= t h r e e x y ; 14 z2= twox y + x ; p r i n t f ( \n 3x y = %e, z1 ) ; 17 p r i n t f ( \n 3x y = %f, z1 ) ; 18 p r i n t f ( \n 3x y = %40.40 f, z1 ) ; 19 p r i n t f ( \n 3x y = %e \n, 3. 0 x y ) ; p r i n t f ( \n 2x y+x= %e \n, z2 ) ; p r i n t f ( \n ( 3 x y ) /(2 x y+x )= %e or %e \n, z1 / z2, ( 3. 0 x y ) / ( 2. 0 x y+ x ) ) ; p r i n t f ( \n (4/3 1) 3 1 = %e \n\n, ( 4. 0 / ) ) ; 26 } 5 / 25

6 Results of simple tests Once we compile and run this code the result is: 1 2 3x y = e x y = x y = x y = e x y+x= e (3x y ) /(2x y+x )= e+00 or e (4/3 1) 3 1 = e 16 6 / 25

7 Do we need decimal? (1/10) β=10 = (0.1) β=10 but in binary it is ( ) β=2 which the computer rounds into a finite representation. For a computer using binary64, if y = 0.30 and x = 0.10 then 3x y = Furthermore, 2x y + x = Leading to the wonderful surprise that 3x y 2x y + x = 2! (x=0.1,y=0.3) For a human, is kg = 0.05 kg? 7 / 25

8 Humans and decimal numbers If both measurements are normalized to and stored in a format with 16 digits as ( ) they are indistinguishable and give the incorrect impression of a much higher accuracy ( kg). To maintain the distinction, we should store first measurement second measurement with all those leading zeros. Both are members of the same cohort. 8 / 25

9 IEEE standard The old IEEE 754 standard of 1985 had only binary floating point formats. The revised IEEE standard includes also decimal64 and decimal128 formats. Sign Combination Trailing Significand ± exponent and MSD t = 10J bits 64 bits: 1 bit 13 bits, bias = bits, digits 128 bits: 1 bit 17 bits, bias = bits, digits The IEEE standard specifies five exceptional conditions that may occur during an arithmetic operation: invalid, division by zero, overflow, underflow, and inexact result. It also specifies five rounding directions for inexact results. 9 / 25

10 Real numbers to floating numbers RA RZ x x x x + odd even 0 even odd RNE RNA RNZ Note the difference between RNE, RNA, and RNZ in tie cases. 10 / 25

11 Back to addition Decimal examples: ? = / 25

12 Multiplication 1 No alignment is necessary. 2 Multiply the significands. 3 Add the exponents. 4 The sign bit of the result is the XOR of the two operand signs. Is it really that simple? 12 / 25

13 Division 1 No alignment is necessary. 2 Divide the significands. 3 Subtract the exponents. 4 The sign bit of the result is the XOR of the two operand signs. You know it is not that simple! 13 / 25

14 What is different in DFP? Decimal formats may have leading zeros, and may be in either binary integer decimal (BID) or densely packed decimal (DPD) encoding. 14 / 25

15 Energy The use of hardware for decimal operations instead of software leads to a much shorter time to finish the arithmetic operation (factor may be 100 to 1 or more) and no energy consumed in overheads such as fetching and decoding of software instructions. However, the additional circuits consume static power when idle and burn energy. In general, the use of decimal HW is much more energy efficient than SW. 15 / 25

16 Verification Produce high quality test vectors for the various arithmetic operations Our test vectors discovered bugs in several designs: in all the decimal64 and decimal128 designs of SilMinds floating point arithmetic operations. In fact this project started in order to verify those specific designs which were subsequently corrected. in the FMA and Sqrt operations of the decimal floating point library decnumber developed by Dr. Mike Cowlishaw while at IBM. We reported the FMA errors in July and August of 2010 and the SQRT error in December 2010 all against version in the FMA for decimal128 in the Intel decimal floating-point math library developed by Dr. Marius Cornea from Intel. We reported the errors in July 2011 against version 2.0 which was subsequently fixed in version 2.0 update 1 of August (See 16 / 25

17 World published research Universities (representative list) Wisconsin, USA: DPD add, mul, div, sqrt. SDC, Spain: DPD mul, elementary functions. Malaca, Spain: rounding for BID, mul, add. Sh-B, Iran: redundant decimal. Cairo, Egypt: DPD add, mul, div, sqrt, fma, energy, verification. Sask., Canada: DPD log and antilog. Utah, USA: Complete SW decimal library and adaptation of gcc. Companies (complete list) IBM, UK: SW implementation of DPD. IBM, USA: DPD HW add, mul, div, sqrt, and SW DFPAL. Intel, USA: SW implementation of BID. SAP, Germany: All internal representations are now DPD. SilMinds, Egypt: DPD HW for add, mul, div, sqrt, fma, pow,.... Fujitsu, Japan: DPD HW add, mul, and div. 17 / 25

18 Patents in USA 1 R. Samy, H. A. H. Fahmy, T. Eldeeb, R. Raafat, Y. Farouk, M. Elkhouly, and A. Mohamed, Decimal floating-point fused multiply-add unit, Apr US Patent number 8,694, A. Mohamed, H. A. H. Fahmy, R. Raafat, Y. Farouk, M. Elkhouly, R. Samy, and T. Eldeeb, Rounding unit for decimal floating-point division, June US Patent number 8,751, T. ElDeeb, H. A. H. Fahmy, and M. Y. Hassan, Decimal elementary functions computation, July US Patent number 8,788, A. Mohamed, R. Raafat, H. A. H. Fahmy, T. Eldeeb, Y. Farouk, R. Samy, and M. Elkhouly, Parallel redundant decimal fused-multiply-add circuit, Aug US Patent number 8,805, R. Raafat, A. Mohamed, H. A. H. Fahmy, Y. Farouk, M. Elkhouly, T. Eldeeb, and R. Samy, Decimal floating-point square-root unit using Newton-Raphson iterations, Aug US Patent number 8,812, A. A. Ayoub and H. A. H. Fahmy, BID to BCD/DPD converters, Sept US Patent number 9,134, A. A. Ayoub, H. A. H. Fahmy, and T. Eldeeb, DPD/BCD to BID converters, Sept US Patent number 9,143, T. Eldeeb, H. A. H. Fahmy, A. Elhosiny, M. Y. Hassan, Y. Aly, and R. Raafat, Decimal floating-point processor, Apr US Patent number 9,323, / 25

19 Decimal future Inclusion in language standards (already in C, Fortran, Python, and COBOL). Wider adoption in industry. Use of decimal in new applications. HW implementation of decimal elementary functions. Units combining binary and decimal. Verification engines for compliance. 19 / 25

20 Real world problems Check for some disasters caused by numerical errors. 1 Patriot Missile Failure 2 Explosion of the Ariane 5 3 The Vancouver Stock Exchange 4 Rounding error changes Parliament makeup / 25

21 Optimization! Check this code: (adapted from The pitfalls of verifying floating-point computations by David Monniaux) 1 #include<s t d i o. h> 2 3 #include<math. h> 4 5 double modulo ( double x, double mini, double maxi ) { 6 double d e l t a = maxi mini ; 7 double d e c l = x mini ; 8 double q = decl / delta ; 9 return x f l o o r ( q ) d e l t a ; 10 } int main ( ) { 13 double r = modulo ( n e x t a f t e r ( , 0. 0 ), 180.0, ) ; 14 p r i n t f ( \n The v a l u e i s %40.40 f \n, r ) ; 15 } 21 / 25

22 Optimization! Check this code: (adapted from The pitfalls of verifying floating-point computations by David Monniaux) 1 #include<s t d i o. h> 2 3 #include<math. h> 4 5 double modulo ( double x, double mini, double maxi ) { 6 double d e l t a = maxi mini ; 7 double d e c l = x mini ; 8 double q = decl / delta ; 9 return x f l o o r ( q ) d e l t a ; 10 } int main ( ) { 13 double r = modulo ( n e x t a f t e r ( , 0. 0 ), 180.0, ) ; 14 p r i n t f ( \n The v a l u e i s %40.40 f \n, r ) ; 15 } With gcc -O0 we get: With gcc -O1 we get: / 25

23 You cannot always optimize! 1 #include<s t d i o. h> 2 3 #include<math. h> 4 5 double modulo ( double x, double mini, double maxi ) { 6 double d e l t a = maxi mini ; 7 double d e c l = x mini ; 8 p r i n t f ( \n d e c l=%f \n, d e c l ) ; 9 double q = decl / delta ; 10 return x f l o o r ( q ) d e l t a ; 11 } int main ( ) { 14 double r = modulo ( n e x t a f t e r ( , 0. 0 ), 180.0, ) ; 15 p r i n t f ( \n The v a l u e i s %40.40 f \n, r ) ; 16 } With gcc -O0 we get: With gcc -O1 we get: / 25

24 Solution? The problem disappears in 1 double modulo ( double x, double mini, double maxi ) { 2 double d e l t a = maxi mini ; 3 return x f l o o r ( ( x mini ) / d e l t a ) d e l t a ; 4 } Quote: If hundreds of thousands of systems featuring a defective component are manufactured every year, there will be real failures happening when the systems are deployed and they will be very difficult to recreate and diagnose. If the system is implemented in single precision, the odds are considerably higher with the same probabilistic assumptions: a single 100 Hz system would break down twice a day. 24 / 25

25 Summary Arithmetic blocks are everywhere in digital circuits. It is possible to change the representation in order to ease the implementation of certain tasks. Floating point programs and circuits are tricky : hard to design and hard to verify. 25 / 25

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

Computer Architecture and IC Design Lab. Chapter 3 Part 2 Arithmetic for Computers Floating Point Chapter 3 Part 2 Arithmetic for Computers Floating Point Floating Point Representation for non integral numbers Including very small and very large numbers 4,600,000,000 or 4.6 x 10 9 0.0000000000000000000000000166

More information

Arithmetic for Computers. Hwansoo Han

Arithmetic for Computers. Hwansoo Han Arithmetic for Computers Hwansoo Han Arithmetic for Computers Operations on integers Addition and subtraction Multiplication and division Dealing with overflow Floating-point real numbers Representation

More information

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

Floating point. Today! IEEE Floating Point Standard! Rounding! Floating Point Operations! Mathematical properties. Next time. ! Floating point Today! IEEE Floating Point Standard! Rounding! Floating Point Operations! Mathematical properties Next time! The machine model Chris Riesbeck, Fall 2011 Checkpoint IEEE Floating point Floating

More information

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

COSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture) COSC 243 Data Representation 3 Lecture 3 - Data Representation 3 1 Data Representation Test Material Lectures 1, 2, and 3 Tutorials 1b, 2a, and 2b During Tutorial a Next Week 12 th and 13 th March If you

More information

Matthieu Lefebvre Princeton University. Monday, 10 July First Computational and Data Science school for HEP (CoDaS-HEP)

Matthieu Lefebvre Princeton University. Monday, 10 July First Computational and Data Science school for HEP (CoDaS-HEP) Matthieu Lefebvre Princeton University Monday, 10 July 2017 First Computational and Data Science school for HEP (CoDaS-HEP) Prerequisites: recent C++ compiler Eventually cmake git clone https://github.com/mpbl/codas_fpa/

More information

Representing and Manipulating Floating Points. Jo, Heeseung

Representing and Manipulating Floating Points. Jo, Heeseung Representing and Manipulating Floating Points Jo, Heeseung The Problem How to represent fractional values with finite number of bits? 0.1 0.612 3.14159265358979323846264338327950288... 2 Fractional Binary

More information

CS429: Computer Organization and Architecture

CS429: Computer Organization and Architecture CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Sciences University of Texas at Austin Last updated: September 18, 2017 at 12:48 CS429 Slideset 4: 1 Topics of this Slideset

More information

Scientific Computing. Error Analysis

Scientific Computing. Error Analysis ECE257 Numerical Methods and Scientific Computing Error Analysis Today s s class: Introduction to error analysis Approximations Round-Off Errors Introduction Error is the difference between the exact solution

More information

Optimized Binary64 and Binary128 Arithmetic with GNU MPFR (common work with Vincent Lefèvre)

Optimized Binary64 and Binary128 Arithmetic with GNU MPFR (common work with Vincent Lefèvre) Arith 24 conference, London, July 24, 2017 Optimized Binary64 and Binary128 Arithmetic with GNU MPFR (common work with Vincent Lefèvre) Paul Zimmermann Introducing the GNU MPFR library a software implementation

More information

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

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754 Floating Point Puzzles Topics Lecture 3B Floating Point IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties For each of the following C expressions, either: Argue that

More information

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

Floating Point Arithmetic. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Floating Point Arithmetic Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Floating Point (1) Representation for non-integral numbers Including very

More information

Giving credit where credit is due

Giving credit where credit is due CSCE 230J Computer Organization Floating Point Dr. Steve Goddard goddard@cse.unl.edu http://cse.unl.edu/~goddard/courses/csce230j Giving credit where credit is due Most of slides for this lecture are based

More information

Giving credit where credit is due

Giving credit where credit is due JDEP 284H Foundations of Computer Systems Floating Point Dr. Steve Goddard goddard@cse.unl.edu Giving credit where credit is due Most of slides for this lecture are based on slides created by Drs. Bryant

More information

Floating Point January 24, 2008

Floating Point January 24, 2008 15-213 The course that gives CMU its Zip! Floating Point January 24, 2008 Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties class04.ppt 15-213, S 08 Floating

More information

Adding Binary Integers. Part 5. Adding Base 10 Numbers. Adding 2's Complement. Adding Binary Example = 10. Arithmetic Logic Unit

Adding Binary Integers. Part 5. Adding Base 10 Numbers. Adding 2's Complement. Adding Binary Example = 10. Arithmetic Logic Unit Part 5 Adding Binary Integers Arithmetic Logic Unit = Adding Binary Integers Adding Base Numbers Computer's add binary numbers the same way that we do with decimal Columns are aligned, added, and "'s"

More information

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

Written Homework 3. Floating-Point Example (1/2) Written Homework 3 Assigned on Tuesday, Feb 19 Due Time: 11:59pm, Feb 26 on Tuesday Problems: 3.22, 3.23, 3.24, 3.41, 3.43 Note: You have 1 week to work on homework 3. 3 Floating-Point Example (1/2) Q:

More information

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

Floating-point Arithmetic. where you sum up the integer to the left of the decimal point and the fraction to the right. 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

More information

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

Systems I. Floating Point. Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Systems I Floating Point Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties IEEE Floating Point IEEE Standard 754 Established in 1985 as uniform standard for

More information

Floating Point Numbers

Floating Point Numbers Floating Point Numbers Computer Systems Organization (Spring 2016) CSCI-UA 201, Section 2 Instructor: Joanna Klukowska Slides adapted from Randal E. Bryant and David R. O Hallaron (CMU) Mohamed Zahran

More information

Floating Point Numbers

Floating Point Numbers Floating Point Numbers Computer Systems Organization (Spring 2016) CSCI-UA 201, Section 2 Fractions in Binary Instructor: Joanna Klukowska Slides adapted from Randal E. Bryant and David R. O Hallaron (CMU)

More information

Foundations of Computer Systems

Foundations of Computer Systems 18-600 Foundations of Computer Systems Lecture 4: Floating Point Required Reading Assignment: Chapter 2 of CS:APP (3 rd edition) by Randy Bryant & Dave O Hallaron Assignments for This Week: Lab 1 18-600

More information

Data Representation Floating Point

Data Representation Floating Point Data Representation Floating Point CSCI 2400 / ECE 3217: Computer Architecture Instructor: David Ferry Slides adapted from Bryant & O Hallaron s slides via Jason Fritts Today: Floating Point Background:

More information

Floating-Point Arithmetic

Floating-Point Arithmetic Floating-Point Arithmetic if ((A + A) - A == A) { SelfDestruct() } Reading: Study Chapter 4. L12 Multiplication 1 Why Floating Point? Aren t Integers enough? Many applications require numbers with a VERY

More information

Representing and Manipulating Floating Points

Representing and Manipulating Floating Points Representing and Manipulating Floating Points Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu The Problem How to represent fractional values with

More information

Data Representation Floating Point

Data Representation Floating Point Data Representation Floating Point CSCI 2400 / ECE 3217: Computer Architecture Instructor: David Ferry Slides adapted from Bryant & O Hallaron s slides via Jason Fritts Today: Floating Point Background:

More information

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

Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Lecture 3 Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Instructor: Nicole Hynes nicole.hynes@rutgers.edu 1 Fixed Point Numbers Fixed point number: integer part

More information

Software Implementation of Decimal Floating-Point

Software Implementation of Decimal Floating-Point 0 Software Implementation of Decimal Floating-Point John Harrison johnh@ichips.intel.com JNAO, 1st June 2006 1 Decimal and binary arithmetic Some early computers like ENIAC used decimal. But nowadays:

More information

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

Signed Multiplication Multiply the positives Negate result if signs of operand are different Another Improvement Save on space: Put multiplier in product saves on speed: only single shift needed Figure: Improved hardware for multiplication Signed Multiplication Multiply the positives Negate result

More information

Floating Point Arithmetic

Floating Point Arithmetic Floating Point Arithmetic Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu)

More information

FLOATING POINT NUMBERS

FLOATING POINT NUMBERS Exponential Notation FLOATING POINT NUMBERS Englander Ch. 5 The following are equivalent representations of 1,234 123,400.0 x 10-2 12,340.0 x 10-1 1,234.0 x 10 0 123.4 x 10 1 12.34 x 10 2 1.234 x 10 3

More information

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

Floating Point Puzzles The course that gives CMU its Zip! Floating Point Jan 22, IEEE Floating Point. Fractional Binary Numbers. class04.ppt 15-213 The course that gives CMU its Zip! Topics Floating Point Jan 22, 2004 IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Floating Point Puzzles For

More information

Floating Point Numbers. Lecture 9 CAP

Floating Point Numbers. Lecture 9 CAP Floating Point Numbers Lecture 9 CAP 3103 06-16-2014 Review of Numbers Computers are made to deal with numbers What can we represent in N bits? 2 N things, and no more! They could be Unsigned integers:

More information

System Programming CISC 360. Floating Point September 16, 2008

System Programming CISC 360. Floating Point September 16, 2008 System Programming CISC 360 Floating Point September 16, 2008 Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Powerpoint Lecture Notes for Computer Systems:

More information

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

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754 Floating Point Puzzles Topics Lecture 3B Floating Point IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties For each of the following C expressions, either: Argue that

More information

Chapter 3. Arithmetic Text: P&H rev

Chapter 3. Arithmetic Text: P&H rev Chapter 3 Arithmetic Text: P&H rev3.29.16 Arithmetic for Computers Operations on integers Addition and subtraction Multiplication and division Dealing with overflow Floating-point real numbers Representation

More information

Floating-Point Arithmetic

Floating-Point Arithmetic Floating-Point Arithmetic if ((A + A) - A == A) { SelfDestruct() } L11 Floating Point 1 What is the problem? Many numeric applications require numbers over a VERY large range. (e.g. nanoseconds to centuries)

More information

Representing and Manipulating Floating Points. Computer Systems Laboratory Sungkyunkwan University

Representing and Manipulating Floating Points. Computer Systems Laboratory Sungkyunkwan University Representing and Manipulating Floating Points Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu The Problem How to represent fractional values with

More information

ECE232: Hardware Organization and Design

ECE232: Hardware Organization and Design ECE232: Hardware Organization and Design Lecture 11: Floating Point & Floating Point Addition Adapted from Computer Organization and Design, Patterson & Hennessy, UCB Last time: Single Precision Format

More information

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

Computer Architecture Chapter 3. Fall 2005 Department of Computer Science Kent State University Computer Architecture Chapter 3 Fall 2005 Department of Computer Science Kent State University Objectives Signed and Unsigned Numbers Addition and Subtraction Multiplication and Division Floating Point

More information

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

Floating Point. The World is Not Just Integers. Programming languages support numbers with fraction 1 Floating Point The World is Not Just Integers Programming languages support numbers with fraction Called floating-point numbers Examples: 3.14159265 (π) 2.71828 (e) 0.000000001 or 1.0 10 9 (seconds in

More information

Floating Point Numbers

Floating Point Numbers 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

More information

Divide: Paper & Pencil

Divide: Paper & Pencil Divide: Paper & Pencil 1001 Quotient Divisor 1000 1001010 Dividend -1000 10 101 1010 1000 10 Remainder See how big a number can be subtracted, creating quotient bit on each step Binary => 1 * divisor or

More information

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

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers Chapter 03: Computer Arithmetic Lesson 09: Arithmetic using floating point numbers Objective To understand arithmetic operations in case of floating point numbers 2 Multiplication of Floating Point Numbers

More information

3.5 Floating Point: Overview

3.5 Floating Point: Overview 3.5 Floating Point: Overview Floating point (FP) numbers Scientific notation Decimal scientific notation Binary scientific notation IEEE 754 FP Standard Floating point representation inside a computer

More information

Representing and Manipulating Floating Points

Representing and Manipulating Floating Points Representing and Manipulating Floating Points Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu The Problem How to represent fractional values with

More information

Floating-Point Arithmetic

Floating-Point Arithmetic 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

More information

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

Chapter 2 Float Point Arithmetic. Real Numbers in Decimal Notation. Real Numbers in Decimal Notation Chapter 2 Float Point Arithmetic Topics IEEE Floating Point Standard Fractional Binary Numbers Rounding Floating Point Operations Mathematical properties Real Numbers in Decimal Notation Representation

More information

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

Floating point. Today. IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Next time. Floating point Today IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Next time The machine model Fabián E. Bustamante, Spring 2010 IEEE Floating point Floating point

More information

COMP2611: Computer Organization. Data Representation

COMP2611: Computer Organization. Data Representation COMP2611: Computer Organization Comp2611 Fall 2015 2 1. Binary numbers and 2 s Complement Numbers 3 Bits: are the basis for binary number representation in digital computers What you will learn here: How

More information

Thomas Polzer Institut für Technische Informatik

Thomas Polzer Institut für Technische Informatik Thomas Polzer tpolzer@ecs.tuwien.ac.at Institut für Technische Informatik Operations on integers Addition and subtraction Multiplication and division Dealing with overflow Floating-point real numbers VO

More information

Design of a Floating-Point Fused Add-Subtract Unit Using Verilog

Design of a Floating-Point Fused Add-Subtract Unit Using Verilog International Journal of Electronics and Computer Science Engineering 1007 Available Online at www.ijecse.org ISSN- 2277-1956 Design of a Floating-Point Fused Add-Subtract Unit Using Verilog Mayank Sharma,

More information

By, Ajinkya Karande Adarsh Yoga

By, Ajinkya Karande Adarsh Yoga By, Ajinkya Karande Adarsh Yoga Introduction Early computer designers believed saving computer time and memory were more important than programmer time. Bug in the divide algorithm used in Intel chips.

More information

Representing and Manipulating Floating Points

Representing and Manipulating Floating Points Representing and Manipulating Floating Points Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu SSE23: Introduction to Computer Systems, Spring 218,

More information

Computer arithmetics: integers, binary floating-point, and decimal floating-point

Computer arithmetics: integers, binary floating-point, and decimal floating-point n!= 0 && -n == n z+1 == z Computer arithmetics: integers, binary floating-point, and decimal floating-point v+w-w!= v x+1 < x Peter Sestoft 2010-02-16 y!= y p == n && 1/p!= 1/n 1 Computer arithmetics Computer

More information

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

Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition. Carnegie Mellon Carnegie Mellon Floating Point 15-213/18-213/14-513/15-513: Introduction to Computer Systems 4 th Lecture, Sept. 6, 2018 Today: Floating Point Background: Fractional binary numbers IEEE floating point

More information

1 class Lecture2 { 2 3 "Elementray Programming" / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch.

1 class Lecture2 { 2 3 Elementray Programming / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 41 / 68 Example Given the radius

More information

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

EE260: Logic Design, Spring n Integer multiplication. n Booth s algorithm. n Integer division. n Restoring, non-restoring EE 260: Introduction to Digital Design Arithmetic II Yao Zheng Department of Electrical Engineering University of Hawaiʻi at Mānoa Overview n Integer multiplication n Booth s algorithm n Integer division

More information

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

CS 261 Fall Floating-Point Numbers. Mike Lam, Professor. CS 261 Fall 2018 Mike Lam, Professor https://xkcd.com/217/ Floating-Point Numbers Floating-point Topics Binary fractions Floating-point representation Conversions and rounding error Binary fractions Now

More information

Bits, Words, and Integers

Bits, Words, and Integers Computer Science 52 Bits, Words, and Integers Spring Semester, 2017 In this document, we look at how bits are organized into meaningful data. In particular, we will see the details of how integers are

More information

Design and Implementation of IEEE-754 Decimal Floating Point Adder, Subtractor and Multiplier

Design and Implementation of IEEE-754 Decimal Floating Point Adder, Subtractor and Multiplier International Journal of Engineering and Advanced Technology (IJEAT) ISSN: 2249 8958, Volume-4 Issue 1, October 2014 Design and Implementation of IEEE-754 Decimal Floating Point Adder, Subtractor and Multiplier

More information

A Decimal Floating Point Arithmetic Unit for Embedded System Applications using VLSI Techniques

A Decimal Floating Point Arithmetic Unit for Embedded System Applications using VLSI Techniques A Decimal Floating Point Arithmetic Unit for Embedded System Applications using VLSI Techniques Rajeshwari Mathapati #1, Shrikant. K.Shirakol *2 # Dept of E&CE, S.D.M. College of Engg. and Tech., Dharwad,

More information

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 = (

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 = ( Floating Point Numbers in Java by Michael L. Overton Virtually all modern computers follow the IEEE 2 floating point standard in their representation of floating point numbers. The Java programming language

More information

Floating-point representations

Floating-point representations Lecture 10 Floating-point representations Methods of representing real numbers (1) 1. Fixed-point number system limited range and/or limited precision results must be scaled 100101010 1111010 100101010.1111010

More information

Floating-point representations

Floating-point representations Lecture 10 Floating-point representations Methods of representing real numbers (1) 1. Fixed-point number system limited range and/or limited precision results must be scaled 100101010 1111010 100101010.1111010

More information

Floating-Point Arithmetic

Floating-Point Arithmetic ENEE446---Lectures-4/10-15/08 A. Yavuz Oruç Professor, UMD, College Park Copyright 2007 A. Yavuz Oruç. All rights reserved. Floating-Point Arithmetic Integer or fixed-point arithmetic provides a complete

More information

VHDL IMPLEMENTATION OF IEEE 754 FLOATING POINT UNIT

VHDL IMPLEMENTATION OF IEEE 754 FLOATING POINT UNIT VHDL IMPLEMENTATION OF IEEE 754 FLOATING POINT UNIT Ms. Anjana Sasidharan Student, Vivekanandha College of Engineering for Women, Namakkal, Tamilnadu, India. Abstract IEEE-754 specifies interchange and

More information

18-642: Floating Point Blues

18-642: Floating Point Blues 18-642: Floating Point Blues 10/23/2017 1 Floating Point Math Anti-Patterns: Not accounting for roundoff errors Tests for floating point equality Not handling special values Float used if integer does

More information

Number Systems CHAPTER Positional Number Systems

Number Systems CHAPTER Positional Number Systems CHAPTER 2 Number Systems Inside computers, information is encoded as patterns of bits because it is easy to construct electronic circuits that exhibit the two alternative states, 0 and 1. The meaning of

More information

IEEE Floating Point Numbers Overview

IEEE Floating Point Numbers Overview 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

More information

Computer Organization: A Programmer's Perspective

Computer Organization: A Programmer's Perspective A Programmer's Perspective Representing Numbers Gal A. Kaminka galk@cs.biu.ac.il Fractional Binary Numbers 2 i 2 i 1 4 2 1 b i b i 1 b 2 b 1 b 0. b 1 b 2 b 3 b j 1/2 1/4 1/8 Representation Bits to right

More information

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

Lecture 13: (Integer Multiplication and Division) FLOATING POINT NUMBERS Lecture 13: (Integer Multiplication and Division) FLOATING POINT NUMBERS Lecture 13 Floating Point I (1) Fall 2005 Integer Multiplication (1/3) Paper and pencil example (unsigned): Multiplicand 1000 8

More information

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

Bindel, Fall 2016 Matrix Computations (CS 6210) Notes for 1 Logistics Notes for 2016-09-07 1. We are still at 50. If you are still waiting and are not interested in knowing if a slot frees up, let me know. 2. There is a correction to HW 1, problem 4; the condition

More information

CS 261 Fall Floating-Point Numbers. Mike Lam, Professor. https://xkcd.com/217/

CS 261 Fall Floating-Point Numbers. Mike Lam, Professor. https://xkcd.com/217/ CS 261 Fall 2017 Mike Lam, Professor https://xkcd.com/217/ Floating-Point Numbers Floating-point Topics Binary fractions Floating-point representation Conversions and rounding error Binary fractions Now

More information

BINARY FLOATING POINT ARITHMETIC VERIFICATION USING A STANDARD LANGUAGE TO SOLVE CONSTRAINTS. Khaled Mohamed Abdel Maksoud Nouh

BINARY FLOATING POINT ARITHMETIC VERIFICATION USING A STANDARD LANGUAGE TO SOLVE CONSTRAINTS. Khaled Mohamed Abdel Maksoud Nouh BINARY FLOATING POINT ARITHMETIC VERIFICATION USING A STANDARD LANGUAGE TO SOLVE CONSTRAINTS By Khaled Mohamed Abdel Maksoud Nouh A Thesis Submitted to the Faculty of Engineering at Cairo University in

More information

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

CSCI 402: Computer Architectures. Arithmetic for Computers (3) Fengguang Song Department of Computer & Information Science IUPUI. CSCI 402: Computer Architectures Arithmetic for Computers (3) Fengguang Song Department of Computer & Information Science IUPUI 3.5 Today s Contents Floating point numbers: 2.5, 10.1, 100.2, etc.. How

More information

Floating Point Arithmetic

Floating Point Arithmetic Floating Point Arithmetic CS 365 Floating-Point What can be represented in N bits? Unsigned 0 to 2 N 2s Complement -2 N-1 to 2 N-1-1 But, what about? very large numbers? 9,349,398,989,787,762,244,859,087,678

More information

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

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions CHAPTER 4 Operations On Data (Solutions to Odd-Numbered Problems) Review Questions 1. Arithmetic operations interpret bit patterns as numbers. Logical operations interpret each bit as a logical values

More information

Chapter 3: Arithmetic for Computers

Chapter 3: Arithmetic for Computers Chapter 3: Arithmetic for Computers Objectives Signed and Unsigned Numbers Addition and Subtraction Multiplication and Division Floating Point Computer Architecture CS 35101-002 2 The Binary Numbering

More information

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

Floating Point COE 308. Computer Architecture Prof. Muhamed Mudawar. Computer Engineering Department King Fahd University of Petroleum and Minerals Floating Point COE 38 Computer Architecture Prof. Muhamed Mudawar Computer Engineering Department King Fahd University of Petroleum and Minerals Presentation Outline Floating-Point Numbers IEEE 754 Floating-Point

More information

Module 2: Computer Arithmetic

Module 2: Computer Arithmetic Module 2: Computer Arithmetic 1 B O O K : C O M P U T E R O R G A N I Z A T I O N A N D D E S I G N, 3 E D, D A V I D L. P A T T E R S O N A N D J O H N L. H A N N E S S Y, M O R G A N K A U F M A N N

More information

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

CSCI 402: Computer Architectures. Arithmetic for Computers (4) Fengguang Song Department of Computer & Information Science IUPUI. CSCI 402: Computer Architectures Arithmetic for Computers (4) Fengguang Song Department of Computer & Information Science IUPUI Homework 4 Assigned on Feb 22, Thursday Due Time: 11:59pm, March 5 on Monday

More information

Chapter 2 Data Representations

Chapter 2 Data Representations Computer Engineering Chapter 2 Data Representations Hiroaki Kobayashi 4/21/2008 4/21/2008 1 Agenda in Chapter 2 Translation between binary numbers and decimal numbers Data Representations for Integers

More information

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

Floating Point (with contributions from Dr. Bin Ren, William & Mary Computer Science) Floating Point (with contributions from Dr. Bin Ren, William & Mary Computer Science) Floating Point Background: Fractional binary numbers IEEE floating point standard: Definition Example and properties

More information

CO212 Lecture 10: Arithmetic & Logical Unit

CO212 Lecture 10: Arithmetic & Logical Unit CO212 Lecture 10: Arithmetic & Logical Unit Shobhanjana Kalita, Dept. of CSE, Tezpur University Slides courtesy: Computer Architecture and Organization, 9 th Ed, W. Stallings Integer Representation For

More information

Real numbers in the real world

Real numbers in the real world 0 Real numbers in the real world Industrial applications of theorem proving John Harrison Intel Corporation 30th May 2006 1 Overview Famous computer arithmetic failures Formal verification and theorem

More information

On a 64-bit CPU. Size/Range vary by CPU model and Word size.

On a 64-bit CPU. Size/Range vary by CPU model and Word size. On a 64-bit CPU. Size/Range vary by CPU model and Word size. unsigned short x; //range 0 to 65553 signed short x; //range ± 32767 short x; //assumed signed There are (usually) no unsigned floats or doubles.

More information

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University Lesson #3 Variables, Operators, and Expressions Variables We already know the three main types of variables in C: int, char, and double. There is also the float type which is similar to double with only

More information

Preliminary Decimal-Floating-Point Architecture

Preliminary Decimal-Floating-Point Architecture z/architecture Preliminary Decimal-Floating-Point Architecture November, 2006 SA23-2232-00 ii Preliminary Decimal-Floating-Point Architecture Note: Before using this information and the product it supports,

More information

1.2 Round-off Errors and Computer Arithmetic

1.2 Round-off Errors and Computer Arithmetic 1.2 Round-off Errors and Computer Arithmetic 1 In a computer model, a memory storage unit word is used to store a number. A word has only a finite number of bits. These facts imply: 1. Only a small set

More information

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

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as: N Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as: a n a a a The value of this number is given by: = a n Ka a a a a a

More information

Inf2C - Computer Systems Lecture 2 Data Representation

Inf2C - Computer Systems Lecture 2 Data Representation Inf2C - Computer Systems Lecture 2 Data Representation Boris Grot School of Informatics University of Edinburgh Last lecture Moore s law Types of computer systems Computer components Computer system stack

More information

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

Floating Point : Introduction to Computer Systems 4 th Lecture, May 25, Instructor: Brian Railing. Carnegie Mellon Floating Point 15-213: Introduction to Computer Systems 4 th Lecture, May 25, 2018 Instructor: Brian Railing Today: Floating Point Background: Fractional binary numbers IEEE floating point standard: Definition

More information

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

false, import, new 1 class Lecture2 { 2 3 Data types, Variables, and Operators 4 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4 5 } 6 7 // Keywords: 8 byte, short, int, long, char, float, double, boolean, true, false, import, new Zheng-Liang Lu Java Programming 44

More information

Data Representations & Arithmetic Operations

Data Representations & Arithmetic Operations Data Representations & Arithmetic Operations Hiroaki Kobayashi 7/13/2011 7/13/2011 Computer Science 1 Agenda Translation between binary numbers and decimal numbers Data Representations for Integers Negative

More information

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

Integer Multiplication. Back to Arithmetic. Integer Multiplication. Example (Fig 4.25) Back to Arithmetic Before, we did Representation of integers Addition/Subtraction Logical ops Forecast Integer Multiplication Integer Division Floating-point Numbers Floating-point Addition/Multiplication

More information

CHW 261: Logic Design

CHW 261: Logic Design CHW 261: Logic Design Instructors: Prof. Hala Zayed Dr. Ahmed Shalaby http://www.bu.edu.eg/staff/halazayed14 http://bu.edu.eg/staff/ahmedshalaby14# Slide 1 Slide 2 Slide 3 Digital Fundamentals CHAPTER

More information

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

false, import, new 1 class Lecture2 { 2 3 Data types, Variables, and Operators 4 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4 5 } 6 7 // Keywords: 8 byte, short, int, long, char, float, double, boolean, true, false, import, new Zheng-Liang Lu Java Programming 44

More information

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.

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. IEEE 754 Standard - Overview Frozen Content Modified by on 13-Sep-2017 Before discussing the actual WB_FPU - Wishbone Floating Point Unit peripheral in detail, it is worth spending some time to look at

More information

IEEE Standard 754 for Binary Floating-Point Arithmetic.

IEEE Standard 754 for Binary Floating-Point Arithmetic. CS61C L11 Floating Point II (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #11 Floating Point II 2005-10-05 There is one handout today at the front and back of the room! Lecturer

More information

CS 101: Computer Programming and Utilization

CS 101: Computer Programming and Utilization CS 101: Computer Programming and Utilization Jul-Nov 2017 Umesh Bellur (cs101@cse.iitb.ac.in) Lecture 3: Number Representa.ons Representing Numbers Digital Circuits can store and manipulate 0 s and 1 s.

More information