Computer Systems C S Cynthia Lee

Similar documents
ECE232: Hardware Organization and Design

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

COMP2611: Computer Organization. Data Representation

Floating Point Numbers

Floating Point Numbers. Lecture 9 CAP

Floating Point Arithmetic

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

15213 Recitation 2: Floating Point

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

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

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

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

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

Data Representation Floating Point

3.5 Floating Point: Overview

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

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

IEEE-754 floating-point

IEEE Standard for Floating-Point Arithmetic: 754

CO212 Lecture 10: Arithmetic & Logical Unit

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

Floating Point Numbers

Floating Point Numbers

Data Representation Floating Point

Inf2C - Computer Systems Lecture 2 Data Representation

Foundations of Computer Systems

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

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

Chapter Three. Arithmetic

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

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

IEEE Floating Point Numbers Overview

Integers and Floating Point

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

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

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

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

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

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

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

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

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

System Programming CISC 360. Floating Point September 16, 2008

FLOATING POINT NUMBERS

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

Floating Point January 24, 2008

Today CISC124. Building Modular Code. Designing Methods. Designing Methods, Cont. Designing Methods, Cont. Assignment 1 due this Friday, 7pm.

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

Giving credit where credit is due

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

Characters, Strings, and Floats

Giving credit where credit is due

Floating Point Representation. CS Summer 2008 Jonathan Kaldor

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

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

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

Floating Point Arithmetic

Administrivia. CMSC 216 Introduction to Computer Systems Lecture 24 Data Representation and Libraries. Representing characters DATA REPRESENTATION

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

Floating Point Arithmetic

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

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

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

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

Floating-point representation

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

Numeric Encodings Prof. James L. Frankel Harvard University

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

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

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

Natural Numbers and Integers. Big Ideas in Numerical Methods. Overflow. Real Numbers 29/07/2011. Taking some ideas from NM course a little further

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

CS101 Lecture 04: Binary Arithmetic

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

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

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

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

Co-processor Math Processor. Richa Upadhyay Prabhu. NMIMS s MPSTME February 9, 2016

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

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

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

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

IEEE Standard 754 Floating Point Numbers

UC Berkeley CS61C : Machine Structures

CS101 Introduction to computing Floating Point Numbers

Chapter 3: Arithmetic for Computers

Scientific Computing. Error Analysis

Time (self-scheduled): Location Schedule Your Exam: What to bring:

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. Jo, Heeseung

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

MATH 353 Engineering mathematics III

Floating-point representations

Floating-point representations

CMPSCI 145 MIDTERM #2 SPRING 2017 April 7, 2017 Professor William T. Verts NAME PROBLEM SCORE POINTS GRAND TOTAL 100

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

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

Transcription:

Computer Systems C S 1 0 7 Cynthia Lee

2 Today s Topics LECTURE: Floating point!

Real Numbers and Approximation MATH TIME!

Some preliminary observations on approximation We know that some non-integer numbers can be represented precisely by a finite-length decimal value 1/5 10 = 0.2 10 and some can t (in base 10) π 1/3 10 =.33333333 10 But this isn t consistent across different bases 1/3 10 = 0.1 3 1/5 10 = 0.012012012 3 And of course even with int, we needed to make choices about which integers make the cut and which don t, when we have only a limited storage space

Real number types: float, double float is 4 bytes = 32 bits 2 32 = 4,294,967,296 possible values (note: obviously same number of possible values as 32-bit int) double is 8 bytes = 64 bits 2 64 = 18,446,744,073,709,551,616 possible This is the same number of different possible representable values as int and long, of course But floating point range goes much higher than max int: Max 32-bit int: 2 31 1 = 2,147,483,647 Max 32-bit float: (2 2 23 ) 2 127 3.402823 10 38

Real number types: float, double If you re deciding how to divide up a large number of possible bit patterns into numbers they can represent, there are any number of ways you cold do this What are your priorities? Do you want to leave space for very big ones? Or very small ones? Do you prefer positive or negative?

The mini-float NOT A REAL TYPE IN C, BUT WILL SHOW US THE PRINCIPLES THAT WILL SCALE UP TO THE ACTUAL BIT SIZES FLOAT AND DOUBLE

IEEE format, squished down to example-size mini-float Sign bit is 1 for negative, 0 for positive Operates completely independently, unlike 2 s complement int The rest of the number is in something like scientific notation: (+/-) M * 2 Exp Mantissa provides the significant digits of the number Note: also called the coefficient or the significand Exponent is used to scale the number up or down to very large or very small values Both exponent and mantissa are binary numbers, 4 bits and 3 bits, respectively but not in normal 2 s complement form!

IEEE format, squished down to example-size mini-float Compare to the bit distribution for 32-bit float: Creative Commons license attribution to user Fresheneesz at https://en.wikipedia.org/wiki/single-precision_floating-point_format#/media/file:float_example.svg

Mini-float : the mantissa A 3-bit binary number representing a number after an implicit 1. What?? Yes, it looks like this: 1.[mantissa digits] Examples: Mantissa = 100 2 1.100 2 = 1 + ½ = 1.5 10 Mantissa = 110 2 1.110 2 = 1 + ½ + ¼ = 1.75 10

Mini-float : the exponent A 4-bit binary number representing the exponent: 0000 reserved 0001-6 0010-5 0011-4 0100-3 0101-2 0110-1 0111 0 1000 1 1001 2 1010 3 1011 4 1100 5 1101 6 1110 7 1111 reserved

Lets do an example! 0 0 0 0 1 0 1 0 This number is: A. Greater than 0 B. Less than 0 C. Help! Extra credit: > 1 or < -1 or in between?

Lets do an example! +/- Exponent Mantissa Value 0 0 0 0 1 0 1 0 10/8 * 2-6 = 10/512 0 0 0 0 1 0 1 1 11/8 * 2-6 = 11/512 0 0 0 0 1 1 0 0 12/8 * 2-6 = 12/512 0 0 0 0 1 1 0 1 13/8 * 2-6 = 13/512 0 0 0 0 1 1 1 0 14/8 * 2-6 = 14/512 0 0 0 0 1 1 1 1 15/8 * 2-6 = 15/512 0 0 0 1 0 0 0 0 1 * 2-5 = 16/512 0 0 0 1 0 0 0 1 9/8 * 2-6 = 18/512

Lets do an example! +/- Exponent Mantissa Value 0 0 0 1 0 0 0 0 1 * 2-5 = 16/512 0 0 0 1 0 0 0 1 9/8 * 2-6 = 18/512 0 1 1 1 0 0 1 0 10/8 * 2 7 = 160 0 1 1 1 0 0 1 1 11/8 * 2 7 = 176 0 1 1 1 0 1 0 0 12/8 * 2 7 = 192 0 1 1 1 0 1 0 1 13/8 * 2 7 = 208 0 1 1 1 0 1 1 0 14/8 * 2 7 = 224 0 1 1 1 0 1 1 1 15/8 * 2 7 = 240

About those reserved exponents DENORMALIZED AND SPECIAL CASES

Reserved exponent values: 0000 and 1111 0000 exponent: If the mantissa is all zeros: +/-0 any 0 0 0 0 0 0 0 If the mantissa is nonzero: denormalized floats any 0 0 0 0 any nonzero 1111 exponent: If the mantissa is all zeros: +/-INF (infinity) any 1 1 1 1 0 0 0 If the mantissa is nonzero: NaN (not a number) any 1 1 1 1 any nonzero

MORE about: the mantissa A 3-bit binary number representing a number after an implicit 1. What?? Yes, it looks like this: 1.[mantissa digits] Examples: Mantissa = 100 2 1.100 2 = 1 + ½ = 1.5 10 Mantissa = 110 2 1.110 2 = 1 + ½ + ¼ = 1.75 10 If the exponent is all zeros, then there is no implicit leading 1 The exponent is implicitly smallest possible exponent (2-6 for mini-float) This allows us to eke out a few numbers that are even (closer to zero) than would otherwise be possible Called denormalized or denorm floats

Comparing float and int ADVANTAGES AND DISADVANTAGES

Comparing float and int 32-bit integer (type int): -2,147,483,648 to 2147483647 Every integer in that range can be represented 64-bit integer (type long): 9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (Even Psy will have a hard time overflowing this!) 32-bit floating point (type float): ~1.7 x10-38 to ~3.4 x10 38 Not all numbers in the range can be represented (obviously uncountable) Not even all integers in the range can be represented! Gaps can get quite large!! (larger the exponent, larger the gap between successive mantissa values) 64-bit floating point (type double): ~9 x10-307 to ~2 x10 308

Doing arithmetic in float FUN TIMES

Adding two mini-floats Your bank account balance on your 12 th birthday was $128.00 Your bank stores this amount as a mini-float: Each week of your childhood, starting at age 12, you deposited your weekly allowance of $8: What was your account balance on the day you turned 18? A. About $10000 B. About $5000 C. About $2500 D. About $100 E. Other

Doing arithmetic in float FUN TIMES

Adding two mini-floats Your bank account balance on your 12 th birthday was $128.00 Your bank stores this amount as a mini-float: Each week, starting at age 12, you deposited your weekly allowance of $14: What was your account balance on the day you turned 18? A. About $10000 B. About $5000 C. About $2500 D. About $100 E. Other