Page 1 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types Floating-Point (real) numbers Consider the Number:4,321.42.

Slides:



Advertisements
Similar presentations
Topics covered: Floating point arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Advertisements

2-1 Chapter 2 - Data Representation Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Computer Architecture.
Floating Point Numbers
Faculty of Computer Science © 2006 CMPUT 229 Floating Point Representation Operating with Real Numbers.
Chapter 1.7 Storing Fractions. Excess Notation, continued… In this notation, "m" indicates the total number of bits. For us (working with 8 bits), it.
Chapter 5 Floating Point Numbers. Real Numbers l Floating point representation is used whenever the number to be represented is outside the range of integer.
Number Systems Standard positional representation of numbers:
Representing Real Numbers Using Floating Point Notation Lecture 6 CSCI 1405, CSCI 1301 Introduction to Computer Science Fall 2009.
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
CSE 378 Floating-point1 How to represent real numbers In decimal scientific notation –sign –fraction –base (i.e., 10) to some power Most of the time, usual.
Floating Point Numbers
ECEN 248 Integer Multiplication, Number Format Adopted from Copyright 2002 David H. Albonesi and the University of Rochester.
Computer ArchitectureFall 2008 © August 27, CS 447 – Computer Architecture Lecture 4 Computer Arithmetic (2)
Multiplying, Dividing, and Simplifying Radicals
1 Binary Numbers Again Recall that N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to bits.
Floating Point Numbers.  Floating point numbers are real numbers.  In Java, this just means any numbers that aren’t integers (whole numbers)  For example…
Page 1 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types Note that the methods we used to convert from decimal.
Binary Number Systems.
Topic 4 Computer Mathematics and Logic
Binary Representation and Computer Arithmetic
Data Representation Number Systems.
Page 1 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Strings Do we need to convert integers (or longs, or floats) to strings.
Simple Data Type Representation and conversion of numbers
Scientific Notation Recognize and use scientific notation.
Binary Representation. Binary Representation for Numbers Assume 4-bit numbers 5 as an integer  as an integer  How? 5.0 as a real number  How?
Page 1 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Bits and Bytes There was one other problem with bytes: Compatibility Compatibility.
Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways:  Fixed-point  Floating-point.
Information Representation (Level ISA3) Floating point numbers.
Computer Arithmetic Nizamettin AYDIN
Chapter 2.2 Scientific Notation. Expresses numbers in two parts: A number between 1 and 10 Ten raised to a power Examples: 2.32 x x
Page 1 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types Chapter 2 Basic Data Types.
1 Lecture 5 Floating Point Numbers ITEC 1000 “Introduction to Information Technology”
NUMBER REPRESENTATION CHAPTER 3 – part 3. ONE’S COMPLEMENT REPRESENTATION CHAPTER 3 – part 3.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Information Representation: Negative and Floating Point.
Fixed-Point Arithmetics: Part II
Number Systems So far we have studied the following integer number systems in computer Unsigned numbers Sign/magnitude numbers Two’s complement numbers.
Page 1 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Bits and Bytes How Many bits (or ‘doughnuts’) do we really need? Good question!
College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 1 COE1361:
Floating Point (a brief look) We need a way to represent –numbers with fractions, e.g., –very small numbers, e.g., –very large numbers,
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
CPS120: Introduction to Computer Science Computer Math: Signed Numbers.
Page 1 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types Remember when we first talked about the different combinations.
BR 8/99 Binary Numbers Again Recall than N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to 255.
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.
COMP201 Computer Systems Floating Point Numbers. Floating Point Numbers  Representations considered so far have a limited range dependent on the number.
Page 1 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types Characters vs. Numbers Adding in Binary: There are only.
Page 1 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft RAM Allocation Chapter 3.
Digital Representations ME 4611 Binary Representation Only two states (0 and 1) Easy to implement electronically %0= (0) 10 %1= (1) 10 %10= (2) 10 %11=
1. Computing Systems Lecture 3 Binary Representation & Boolean Logic Binary and Logic 2.
Floating Point Numbers
Representation of Data (Part II) Computer Studies Notes: chapter 19 Ma King Man.
Lecture 6: Floating Point Number Representation Information Representation: Floating Point Number Representation Lecture # 7.
Page 1 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Bits & Bytes OR OffOn Bit = Binary Digit (or Binary Digit) = {0, 1} Bits.
Binary & Normalization What is Normalization? We discussed this the other day (special review session slides, near the end) Can someone tell us.
Software Design and Development Storing Data Computing Science.
Starter Using two’s Complement form convert the following from Denary to Binary using 8 bits. Answer on mini whiteboard Using two’s.
Cosc 2150: Computer Organization Chapter 9, Part 3 Floating point numbers.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Floating Point Numbers
Floating Point Representations
Objectives Today: P4 Data Types – Floating Points P4 Variable Quiz P3 Iteration and Selection Practical Are you logged on? Then come around the table Unit.
Backgrounder: Binary Math
A brief comparison of integer and double representation
How to represent real numbers
How to represent real numbers
Floating Point Binary Part 1
靜夜思 床前明月光, 疑是地上霜。 舉頭望明月, 低頭思故鄉。 ~ 李白 李商隱.
1.6) Storing Integer: 1.7) storing fraction:
Presentation transcript:

Page 1 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types Floating-Point (real) numbers Consider the Number:4, The number could be rewritten as: 4, = * 10 = * 10 1 = E+1 = * 100 = * 10 2 = E+2 = * 1000 = * 10 3 = E+3 = * = * 10 4 = E+4 What Difference does it make??

Page 2 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types If we consider the last notation: E+4 Notice that there are three components: The Sign: In this case plus (implied) The Value (or Mantissa) The Exponent (or Characteristic of the exponent): The power to which we must raise our base (in this case, base 10) How are these components Stored?? When storing real (floating-point) numbers, we MUST keep track of each of the components

Page 3 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types The sign is easy: As with integers, we need only 1 bit. If we use 2-bytes (16-bits), as we did with integers, we have have 15-bits left to distribute among the remaining two components (The Mantissa and the Characteristic of the Exponent) How How to distribute the remaining bits is more complex. THREE There are THREE other considerations: The Mantissa can only take on POSITIVE Values (The Sign-bit will indicate if the value is positive or negative) BOTHThe Characteristic of the Exponent (or Characteristic) can take on BOTH positive and negative values) For every bit we allocate to the Mantissa, there is 1 (one) less bit available for the Characteristic

Page 4 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types What’s the trade-off between allocating bits to the Mantissa or the Characteristic (of the exponent) ??? Consider the following Number:.8072 E+11 Where: MantissaCharacteristic The actual Number is: 80,720,000,000 First, Let’s consider the Mantissa (.8072): To represent the number 8072, we need 13-bits Why ??? Because: 2 12 = 4096 (Meaning the numbers 0 … 4095) 2 13 = 8192 (Meaning the numbers 0 … 8191) 2 14 = (Meaning the numbers 0 … 16383)

Page 5 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types BUT, The Mantissa is a decimal (i.e.,.8072) ???? TRUE.But what if the number were: Which is SMALLER BUT Requires MORE Digits to represent Could We Represent the decimal with 13-bits ??? NO. To Represent the decimal we need: n = log(I) log(2) = = = 17 bits Mantissa The more the number of bits allocated to the Mantissa, The greater the Level of Precision

Page 6 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types IF we allocate 13-bits to the Mantissa: we have 3 decimals of precision IF we allocate 17-bits to the Mantissa: we have 5 decimals of precision That can’t be true! With 13-bits we can represent numbers to There are 4-digits in With 17- bits we can represent numbers to = There are 6-digits in the number YES - That’s True. …. BUT …. …. BUT …. Given 13-bits, can we represent the number 9235 ?? (also a 4-digit Number) Given 17-bits, can we represent the number ?? (also a 6-digit Number)

Page 7 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types How do we interpret the Characteristic ??? Characteristic The more the number of bits allocated to the Characteristic, The greater the Magnitude Assume that we have the choice of allocating EITHER 4 or 5 bits to the Characteristic. Since the characteristic can be either positive or negative, the ranges are: 4-bits Allocated: -2 3 to OR -8 to +7 5-bits Allocated: -2 4 to OR -16 to +15 So ???

Page 8 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types Which is the larger Number ??.124E+7 = (The largest characteristic available with 4-bits) OR.124E+15 = (The largest characteristic available with 5-bits) REMEMBER: DOUBLE Each time we add 1 additional bit, we DOUBLE the size of the number as can represent

Page 9 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types Which is the SMALLER Number ??.124E-8 = (The largest negative characteristic available with 4-bits) OR.124E-16 = (The largest negative characteristic available with 5-bits)..... SIMILARLY..... Large OR Small Magnitude refers to how Large OR How Small the numbers which can represent are.

Page 10 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types What’s More Important: Precision OR Magnitude ?? Depends on Individual Needs: When Dealing with Measures such as PI (  ), Precision. When Dealing with (e.g) Number of atoms in a jar: Magnitude How ARE the bits allocated ??? FIRST, we have to determine how many bits we should use Let’s assume that 16-bits (the same number we used for integers) is sufficient

Page 11 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types ALL Let’s look at ALL possible combinations: Mantissa Bits 1 Mantissa Range 0 … => Characteristic Bits 14 Characteristic Range = -8,192 to 8, … => = -4,096 to 4, … => = -2,048 to 2, … => = -1,024 to 1, … => = -512 to … => = -256 to … => = -128 to … => = -64 to … => = -32 to … => 0.. 1, = -16 to … => 0.. 2, = -8 to … => 0.. 4, = -4 to … => 0.. 8, = -2 to … => , = -1 to 0 What’s the Solution ???

Page 12 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types ALL ALL of the combinations are Inadequate: We Need More bits How Many More ??? It would make sense to see what would happen if we added on another 16-bits (2-bytes) How will that change things ??? What can we do ??? We still need 1 (one) bit for the Sign, but we will now have the remaining 31-bits (4-bytes - 1-bit = 32-bits - 1 = 31-bits) to distribute between the Mantissa and the Characteristic.

Page 13 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types SOME Let’s look at SOME combinations if 31-bits are allocated: Mantissa Bits 15 Precision (decimals) 32,767 (4 decimalss) Characteristic Bits 16 Magnitude (E-Vals) = -32,786 to 32, ,535 (4 decimals) = -16,384 to 16, ,071 (5 decimals) = to 8, ,143 (5 decimals) = -4,096 to 4, ,288 (5 decimals) = -2,048 to 2, ,048,576 (6 decimals) = -1,024 to 1, ,097,152 (6 decimals) = -512 to ,194,304 (6 decimals) = -256 to ,388,608 (6 decimals) = -128 to ,777,216 (7 decimals) = -64 to ,554,432 (7 decimals) = -32 to ,108,864 (7 decimals) = -16 to ,217,728 (8 decimals) = -8 to ,435,456 (8 decimals) = -4 to 3

Page 14 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types What’s the best Combination ??? There is no clear-cut answer. One common allocation scheme is: 1 - bit7 - bits24 - bits Sign Characteristic of the Exponent Mantissa What Range of Numbers can we represent ??? Real Numbers are characterized by their LEVEL OF PRECISION, PRECISION, Not range This scheme allows for 7 decimals of precision

Page 15 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Basic Data Types OK - But what is the LARGEST (positive) number we can represent ???.( ) E (26 (26 -1) = E 63 = 167,772,160,000,000,000,000,000,000,000,000,000,000,000, 000,000,000,000,000,000,000 What is the SMALLEST number we can represent ??? -.1 E -(2 6 ) =.1 E -64 = And In Between ??? ALL values: B BB BUT only to 7 (or 8) decimals of precision.

Page 16 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft  Repeat Slides for this SectionRepeat Slides for this Section  Go To Next Set of Slides For this ChapterGo To Next Set of Slides For this Chapter  Go To Slide Index For Chapter 2Go To Slide Index For Chapter 2  Go To Slide Index For Chapter 3Go To Slide Index For Chapter 3  Go To Slide Index For TextbookGo To Slide Index For Textbook  Go To Home PageGo To Home Page This Concludes The Slides for this Section Choose an Option: