Carnegie Mellon 1 Representing Data 15-213: Introduction to Computer Systems Recitation 3: Monday, Sept. 9 th, 2013 Marjorie Carlson Section A.

Slides:



Advertisements
Similar presentations
Fabián E. Bustamante, Spring 2007 Floating point Today IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Next time.
Advertisements

Computer Engineering FloatingPoint page 1 Floating Point Number system corresponding to the decimal notation 1,837 * 10 significand exponent A great number.
– 1 – CS213, S’06 Floating Point 4/5/2006 Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties CS213.
Floating Point Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties CS 367.
Carnegie Mellon Instructors: Dave O’Hallaron, Greg Ganger, and Greg Kesden Floating Point : Introduction to Computer Systems 4 th Lecture, Sep 6,
1 Binghamton University Floating Point CS220 Computer Systems II 3rd Lecture.
Carnegie Mellon Instructors: Randy Bryant & Dave O’Hallaron Floating Point : Introduction to Computer Systems 3 rd Lecture, Aug. 31, 2010.
Topics covered: Floating point arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
15213 Recitation Fall 2014 Section A, 8 th September Vinay Bhat.
Floating Point Numbers
University of Washington Today: Floats! 1. University of Washington Today Topics: Floating Point Background: Fractional binary numbers IEEE floating point.
University of Washington Today Topics: Floating Point Background: Fractional binary numbers IEEE floating point standard: Definition Example and properties.
1 Lecture 9: Floating Point Today’s topics:  Division  IEEE 754 representations  FP arithmetic Reminder: assignment 4 will be posted later today.
CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (2)
Computer ArchitectureFall 2007 © September 5, 2007 Karem Sakallah CS 447 – Computer Architecture.
Floating Point Numbers
Computer ArchitectureFall 2008 © August 27, CS 447 – Computer Architecture Lecture 4 Computer Arithmetic (2)
Binary Arithmetic Math For Computers.
FLOATING POINT COMPUTER ARCHITECTURE AND ORGANIZATION.
Floating Point Sept 6, 2006 Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties class03.ppt “The course.
Data Representation Number Systems.
IEEE Floating Point Numbers Overview Noah Mendelsohn Tufts University Web: COMP.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Information Representation: Negative and Floating Point.
Floating Point Numbers Topics –IEEE Floating Point Standard –Rounding –Floating Point Operations –Mathematical properties.
Carnegie Mellon Instructors: Seth Copen Goldstein, Anthony Rowe, Greg Kesden Floating Point : Introduction to Computer Systems 4 th Lecture, Jan.
Instructor: Andrew Case Floating Point Slides adapted from Randy Bryant & Dave O’Hallaron.
Carnegie Mellon Instructors: Greg Ganger, Greg Kesden, and Dave O’Hallaron Floating Point : Introduction to Computer Systems 4 th Lecture, Sep 4,
Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Carnegie Mellon Instructor: San Skulrattanakulchai Floating Point MCS-284:
Fixed and Floating Point Numbers Lesson 3 Ioan Despi.
Lecture 9: Floating Point
CSC 221 Computer Organization and Assembly Language
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI N305 Information Representation: Floating Point Representation.
Data Representation : Introduction to Computer Systems Recitation 2: Monday, Jan. 29th, 2015 Dhruven Shah.
1 Carnegie Mellon Welcome to recitation! : Introduction to Computer Systems 3 rd Recitation, Sept. 10, 2012 Instructor: Adrian Trejo (atrejo) Section.
Carnegie Mellon Instructors: Randy Bryant, Dave O’Hallaron, and Greg Kesden Floating Point : Introduction to Computer Systems 4 th Lecture, Sep 5,
Carnegie Mellon 1 Midterm Review : Introduction to Computer Systems Recitation 8: Monday, Oct. 14, 2013 Marjorie Carlson Section A.
Floating Point Sept 9, 2004 Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties class04.ppt “The course.
1 University of Washington Fractional binary numbers What is ?
1 Floating Point. 2 Topics Fractional Binary Numbers IEEE 754 Standard Rounding Mode FP Operations Floating Point in C Suggested Reading: 2.4.
Floating Point Carnegie Mellon /18-243: Introduction to Computer Systems 4 th Lecture, 26 May 2011 Instructors: Gregory Kesden.
Lecture 4 IEEE 754 Floating Point Topics IEEE 754 standard Tiny float January 25, 2016 CSCE 212 Computer Architecture.
Floating Point Topics IEEE Floating-Point Standard Rounding Floating-Point Operations Mathematical Properties CS 105 “Tour of the Black Holes of Computing!”
Floating Point Representations
Floating Point Representations
Floating Point Borrowed from the Carnegie Mellon (Thanks, guys!)
Floating Point Numbers
CS 105 “Tour of the Black Holes of Computing!”
2.4. Floating Point Numbers
CSCI206 - Computer Organization & Programming
Integer Division.
Lecture 9: Floating Point
Topics IEEE Floating Point Standard Rounding Floating Point Operations
Floating Point Number system corresponding to the decimal notation
CS 367 Floating Point Topics (Ch 2.4) IEEE Floating Point Standard
Topic 3d Representation of Real Numbers
Recitation: Data Lab The TAs Sep 11, 2017.
CS201 - Lecture 5 Floating Point
CS 105 “Tour of the Black Holes of Computing!”
CS 105 “Tour of the Black Holes of Computing!”
Floating Point Arithmetic August 31, 2009
CS 105 “Tour of the Black Holes of Computing!”
CS213 Floating Point Topics IEEE Floating Point Standard Rounding
Topic 3d Representation of Real Numbers
CS 105 “Tour of the Black Holes of Computing!”
Presentation transcript:

Carnegie Mellon 1 Representing Data : Introduction to Computer Systems Recitation 3: Monday, Sept. 9 th, 2013 Marjorie Carlson Section A

Carnegie Mellon 2 Welcome to (Belatedly!) Yay ! My advice on doing well in this course:  Labs: start early.  Exams: you should already be doing practice exam questions.  Previous exam questions and answers are all online.  Questions don’t change much from semester to semester.  If you do the exam questions related to each week’s topic as you go, you’ll know all the material by exam time.  The textbook is actually really useful. (!)  General advice: this course is a good place to get more comfortable with UNIX and C, if you aren’t already.

Carnegie Mellon 3 Welcome to Recitation Recitation is a place for interaction  If you have questions, please ask.  If you want to go over an example not planned for recitation, let me know. Each week we’ll cover:  A quick recap of topics from class, especially ones we have found students struggled with in the past.  Tips for labs.  Sample problems to reinforce the main ideas and prepare for exams.

Carnegie Mellon 4 Agenda How Do I Data Lab? Integers  Biasing division Floats  Binary fractions  IEEE standard  Example problem

Carnegie Mellon 5 How Do I Data Lab? (due Thursday at 11:59 pm) Step 1: Download lab files  All lab files are on autolab  Remember to also read the lab handout (“view writeup” link) Step 2: Work on the right machines  Remember to do all your lab work on Shark machines  This includes untarring the handout. Otherwise, you may lose some permissions bits  If you get a permission denied error, try “chmod +x filename”  Do your work in bits.c

Carnegie Mellon 6 How Do I Data Lab? Step 3: Test test test! We have given you FOUR WAYS to test your code before submitting! ./btest lets you debug (printf, test single inputs). Type make before using it. . /dlc bits.c enforces the coding rules (number of operations). ./bddcheck/check.pl tests definitively for correctness. ./driver.pl uses both DLC and the BDD checker – this is what Autolab uses. Code that passes btest will not necessarily pass autolab!

Carnegie Mellon 7 How Do I Data Lab? Step 4: Submit to Autolab  Unlimited submissions, but please don’t use autolab in place of driver.pl  Must submit via web form  To package/download files to your computer, use tar -cvzf out.tar.gz in1 in2 … (if relevant) and your favorite file transfer protocol

Carnegie Mellon 8 How Do I Data Lab? – Tips! Write C like it’s 1989 (for DLC – only used in data lab)  Declare variable at top of function  Make sure closing brace (“}”) is in 1 st column Be careful of operator precedence  Do you know what order ~a+1+b*c<<3*2 will execute in?  Neither do I. Use parentheses: (~a)+1+(b*(c<<3)*2) Take advantage of special values like 0, -1, and T min Operations with undefined behavior in C may have defined behavior on our architecture. (Examples: addition overflow, bit-shifting by 32.) It’s OK to use them. Reducing operations once you’re under the threshold won’t get you extra points (just more glory).

Carnegie Mellon 9 Where Can I Get Help? The assignment writeup The assignment writeup! The assignment writeup!!!!!!!! FAQ: Lecture notes and the textbook Staff list: Office hours: Sun-Thu, 5:30-8:30 pm, in Wean 5027 Peer tutoring: Tue 8:30-11, Mudge Reading Room

Carnegie Mellon 10 Agenda How Do I Data Lab? Integers  Biasing division Floats  Binary fractions  IEEE standard  Example problem

Carnegie Mellon 11 Integers – Biasing You can multiply and divide by powers of 2 with bitshifts As you’ll see when we learn assembly, your computer does this a lot!  Multiply:  Left shift by k to multiply by 2 k  Let’s try this with binary  Divide:  Right shift by k to divide by 2 k … sort of  Let’s try this with binary  How about binary  Uh-oh!  Shifting rounds down, but we want to round toward zero.  Solution: biasing when the number is negative

Carnegie Mellon 12 Integers – Biasing Divisor: Dividend: x 2k2k /  x / 2 k  k Binary Point k –1 1 Biasing adds 1 to final result … this is incremented by 1 Incremented by 1 If this contains a 1…Remember biasing flips rounding direction; only use when dividend is negative

Carnegie Mellon 13 Agenda How Do I Data Lab? Integers  Biasing division Floats  Binary fractions  IEEE standard  Example problem

Carnegie Mellon 14 2i2i 2 i /2 1/4 1/8 2 -j bibi b i-1 b2b2 b1b1 b0b0 b -1 b -2 b -3 b -j Floating Point – Fractions in Binary Representation  Bits to right of “binary point” represent fractional powers of 2  Represents rational number:

Carnegie Mellon 15 Floating Point – Fractions in Binary Convert binary to decimal:  1.1   Convert decimal to binary:  3 3/4  2 3/32  5.875

Carnegie Mellon 16 How Can We Represent Numbers Efficiently? What do we do if we want to convey in 10 digits?

Carnegie Mellon 17 How Can We Represent Numbers Efficiently? What do we do if we want to convey in 10 digits? Hint: -_ _ _ _ _ _ * _ _ _ _

Carnegie Mellon 18 How Can We Represent Numbers Efficiently? What do we do if we want to convey in 10 digits? * sign mantissa exponent

Carnegie Mellon 19 Floating Point – Scientific Notation So, how can we put binary numbers into scientific notation? * 2 2 Numerical form: (–1) S M 2 E sign (S) mantissa (M) exponent (E)

Carnegie Mellon 20 Floating Point – IEEE Standard Floating points are basically a way to encode binary scientific notation. But exp ≠ E and frac ≠ M, because IEEE format optimizes to increase the range of numbers that can be represented.  If numbers are always in the format 1.xxxx (we’ll revisit this!), encoding the 1 is unnecessary. So frac is simply M without the leading 1. M = 1 + frac  exp is unsigned and can represent the numbers 0 to 255. We’d rather have it represent -127(ish) to 128(ish), so we subtract a bias of 127 (2 k-1 -1) get from E to get exp. E = exp - bias sexpfrac 18 bits23 bits

Carnegie Mellon 21 Floating Point – IEEE Standard * 2 2 S = +so s = 0 E = 2so exp = M = so frac = sign (S) mantissa (M) exponent (E) Remember! M = 1 + frac E = exp – bias Bias = 127

Carnegie Mellon 22 Floating Point – IEEE Standard * 2 2 S = +so s = 0 E = 2so exp = 129 (2 + bias) M = so frac = sign (S) mantissa (M) exponent (E) Remember! M = 1 + frac E = exp – bias Bias = 127

Carnegie Mellon 23 Floating Point – IEEE Standard * 2 2 S = +so s = 0 E = 2so exp = 129 (2 + bias) M = so frac = sign (S) mantissa (M) exponent (E) Remember! M = 1 + frac E = exp – bias Bias = 127

Carnegie Mellon 24 Floating Point – Example Consider the following 5‐bit floating point representation based on the IEEE floating point format. This format does not have a sign bit – it can only represent nonnegative numbers.  There are k=3 exponent bits.  There are n=2 fraction bits. What’s the bias? What does represent? What does represent? How would you represent 6? How would you represent ¼? expfrac

Carnegie Mellon 25 Floating Point – Denormalized Range If that was all there was to it, the smallest number representable would be 2 -bias, which is not that small. And it would be represented by Hmm… IEEE uses a trick to give us numbers closer to 0: drop the implied leading 1. NormalizedDenormalized exp ≠ 0exp = 0 implied leading 1no implied leading 1 E = exp - biasE = 1 – bias denser near originevenly spaced represents most numbersrepresents very small numbers

Carnegie Mellon 26 Floating Point – Special Cases Well, denormalizing got us our 0. Now how about infinity? The largest exponent is coopted to encode special cases:  exp = all 1s frac = all 0s represents infinity (+ or -)  exp = all 1s frac isn’t all 0s represents NaN

Carnegie Mellon 27 Floating Point – Special Case Examples Back to our mini-floats:  There are k=3 exponent bits.  There are n=2 fraction bits.  Bias = 3 What does represent? What’s the smallest representable nonzero value? What’s the largest representable finite number? What’s the smallest normalized number? What’s the largest denormalized number? expfrac

Carnegie Mellon 28 Two More Tips and You Can Convert Anything! Decimal  float is a little trickier because you have to figure out whether it has to be encoded as normalized or denormalized.  Strategy 1: compare your number to the smallest normalized number before converting it.  Strategy 2: try to encode it as normalized; if your exponent doesn’t fit in exp, change exp to 0 and shift your decimal point accordingly. You need to know how to round!

Carnegie Mellon 29 Floating Point – Rounding Floats round to even  Why? Avoid statistical bias of always rounding up or down.  How? Like this: truncate below half; round down interesting case; round to even above half; round up truncate below half; round down Interesting case; round to even above half; round up truncate

Carnegie Mellon 30 Floating Point – Rounding Examples Back to our mini-floats:  There are k=3 exponent bits.  There are n=2 fraction bits.  Bias = expfrac ValueFloating Point BitsRounded Value 9/

Carnegie Mellon 31 Floating Point – Rounding Examples Back to our mini-floats:  There are k=3 exponent bits.  There are n=2 fraction bits.  Bias = expfrac ValueFloating Point BitsRounded Value 9/ / inf

Carnegie Mellon 32 Questions?