# Computer Numbers and their Precision, I Number Storage

Save this PDF as:

Size: px
Start display at page:

## Transcription

1 Computer Numbers and their Precision, I Number Storage Learning goal: To understand how the ways computers store numbers lead to limited precision and how that introduces errors into calculations. Learning objective Computational and mathematical objectives: To understand that exact or whole numbers can be stored as integers. To understand that the division of two integers is always rounded down to a smaller integer. To understand that numbers can also be stored in scientific or engineering notation (floating point numbers). To understand the advantages and disadvantages of floating point numbers. To understand that computer errors occur when an integer becomes too large, or too negative. To understand that computer errors known as overflow occur when the exponent of a floating point number becomes too large. To understand that computer errors known as underflow occur when the exponent of a floating point number becomes too negative. To understand that truncation or roundoff occurs when the mantissa of a floating point number becomes too long. To understand some of the consequences of the roundoff of floating point numbers. Science model/computation objectives: We present a model in which the complexities of the computer storage of floating point numbers are reduced to knowing a single number called the machine precision, which the student is asked to determine empirically.. To understand that just as laboratory experiments always have limits on the precision of their measurements, so too do computer simulations have limits on the precision of their numbers. To understand the difference between precision and accuracy. Students will practice the following scientific skills: o Doing numerical experiments on the computer. Activities In this lesson, students will: Perform calculations on the computer as experiments to determine the computer s limits in regard to the storage of numbers. Perform numerical calculations to see how the rules of mathematics are implemented. Sum the series for the sine function to see the effect of error accumulation. 1

2 Products? Where s Computational Scientific Thinking and Intuition Development Understanding that computers are finite and therefore have limits that affect calculations. Being cognizant that uncertainties in numerical calculations are unavoidable. Understanding how to obtain meaningful results even with a computer s limited precision. Understanding the range of numbers that may be necessary to describe a natural phenomenon. Background It is expected students understand some basic aspects of numbers and their properties. In particular, they should be familiar with the real number systems, integers, rational numbers and irrational numbers, as well as the scientific representation of numbers. A review of these aspects can be found at [UNChem], where there is short Mathematics Review as well as some a useful Calculator Review. Landau s Rules of Education: Much of the educational philosophy applied in these modules is summarized by these three rules: 1. Most of education is learning what the words mean; the concepts are usually quite simple once you understand what you are being told. 2. Confusion is the first step to understanding. 3. Traumatic experiences tend to be the most educational ones. In colloquial usage, the terms accurate and precise are often used interchangeably. In computational science and engineering, precision usually indicates the number of significant figures or meaningful decimal places there are in a measurement or a calculation. In contrast, accuracy is more of a measure of how close a measurement of some quantity is to its true value. Likewise, accuracy sometimes refers to how close a theoretical description or model of some phenomena is to what might actually be happening in nature. You may think of precision as relating to the quality or capability of an instrument, but not necessarily as to whether the measured value is close to the true value. For example, we may have a watch that always reads exactly 11:00.00 AM when the sun is at its zenith, and does this year after year. Since there are approximately π 10 7 seconds in a year, this means that the watch has a precision of better than one part in a million, which is quite precise as it is quite repeatable. However, since the true time should be noon, the watch cannot be said to be an accurate measure of the time, although it would be accurate for measuring time differences. Computer Number Representations (Theory) Regardless of how powerful a computer may be, it is still finite. This means that the computer takes a finite time to complete an operation and that it has only a finite amount of space in which to store 2

3 things. Of course as computers and communication networks get faster, and as the available storage gets to be very large, a computer s response may seem to be instantaneous and its memory may seem to be endless, but if you try to do something like predict the weather from first principles or make a copy of a high-definition DVD, the computer s finiteness becomes evident. In this module we explore one aspect of the finiteness of computers, namely, how they store numbers. And because the basic scheme is used on computers of all sizes, the limitations related to this storage is universal and is often an essential element in learning to think computationally. The problem faced by computer designers is how to represent an arbitrary number using a finite amount of memory. Most computer memories contain magnetic materials in which elementary magnets are aligned to face either up or down. As a consequence, the most elementary units of computer memory are the two binary integers 0 and 1 that form the basis of the binary number system (representing all numbers with just two symbols). The phrase binary integer is usually abbreviated as the word bit. This in turn means that, ultimately, everything stored in a computer memory is just a long strings of zeros and ones, with each bit representing the number of times a power of 2 is to be added in. For example, the decimal 10 is the binary 1010, that is, 10 decimal = 1010 binary. Optional: We will leave discussion of the binary representation of numbers to a math class for now, but for the curious: (1) 1010 binary = , where (2) 2 3 = 8, 2 2 = 4, 2 1 = 2, 2 0 = 1, and (3) 10 decimal = , where (4) 10 1 = 10, 10 0 = 1. As a consequence of this scheme, N bits can store positive integers in the range 0-2 N. While it is no longer essential that you know how to convert numbers between different representations in order to compute (we could tell you war stories about that, but maybe another time), it often is essential to remember that numbers on a computer are stored using a finite number of bits, and that unless the number is a power of 2, the process of converting it to a decimal number introduces a small uncertainty. In computing, an uncertainty is often called an error, although this does not imply that anyone or any computer has done anything wrong. The number of bits that a computer or its operating system uses to store a number is called the word length. For example, you might have heard about 32 bit and 64 bit versions of the Windows operating systems. Well, these just refer to the length of the words that the computer processes. While we are talking about these sorts of things, we should mention that often word lengths or memory sizes are expressed in bytes (a mouthful of bits), where (5) 1 byte = 8 bits = B. 3

4 Conveniently, 1 byte is the amount of memory needed to store a single letter like ``a''. This adds up to a typical printed page requiring approximately 3000 B = 3 KB of storage. Of course with memory sizes continuing to grow, rather than bytes, you hear of kilobytes, megabytes or gigabytes, which mean one thousand, one million or one billion bytes (gega is used for billion since in Europe a billion means a million millions rather than our thousand millions). [If you want to be really technical, the kilobyte of computer memory is really 2 10 = 1024 bytes, but you do not have to worry about that.] Integer Storage In a mathematical sense, integers are real numbers (no imaginary parts) that do not contain a fractional or decimal part. They can be positive or negative and comprise the set {-,..., 2, 1, 0, 1, 2,... }. Integers are also are one of two ways to store numbers on a computer (we get to the second way soon). They are stored exactly, that is, with no fractional part, but because a finite number of bits used to represent them, they do not cover the entire range from - to +. Just what range they do cover, and what happens when you try to go beyond that range is something we shall leave for the exercises. In order to satisfy Landau s first rule of education, you should know that if you try to store a number larger than the hardware or software was designed for, what is called an overflow results. Likewise, if you try to store a number smaller than the hardware or software was designed for, what is called an underflow results. As we shall see, integers do not under- or overflow gracefully, and if either an underor overflow occur in a computation you are undertaking with integers, it is likely that your results are not meaningful ( garbage ). Using 64 bits permits integers in the range Integers in Python cover the range: (6) -2, 147, 483, 648 Integers +2, 147,483, 647 While at first this may seem like a large range, it really is not when compared to the range of sizes encountered in the physical world. As a case in point, the ratio of the size of the universe to the size of a proton is approximately ±10 41, which is way beyond what you can do with integers. Order of Operations Before we run headfirst into actually doing calculations on the computer, it is good to remind you that computers may be very powerful, but they still cannot figure out what you are thinking! (sorry Hal.) So even though you may know what you want when you write (7) =?, the computer may well find this ambiguous. Should it read the operations from left to right, as is done in English, or from right to left, as in done in Hebrew and Arabic? The general rule for order of operations is (8) Please Excuse My Dear Aunt Sally! 4

5 that is, Parentheses, Exponentiation, Multiplication or Division, Addition or Subtraction. This means first do any operation in parentheses, then do any exponentiation, etc. Accordingly the operation in equation 7 is equivalent to (9) 6 + (3 2) = = 12. Exercise: Aunt Sally 1) Use your handy calculator, and then computer, to evaluate i) ii) 6 + (3 2) iii) (6 + 3) 2 iv) v) 6 (3 +2) vi) Integer Arithmetic You can add, subtract and multiply integers on a computer and get just the results you would expect. In contrast, when you divide two integers and a remainder results, a decision must be made about what to do with the fractional part since integers do not have fractional parts. Most computer programs just throw away the fractional part, or in other words, the result is always rounded down, even if the fraction is greater than 0.5. For example, 6 c /2 c = 3 c, but 3 c /2 c = 1 c, where we use the subscript c to indicate that this is computer math. Exercise: Integer Arithmetic Now try some of these exercises on your computer to see the effect of Integer arithmetic =? 2. 6/2 =? 3. 3/2 =? 4. 8/3 =? 5. 2 (6/2) =? /2 =? 7. 2 (3/2) =? 8. 12/2/3 =? 9. 12/(2/3) =? 10. (12/2)/3 =? /(3/2) =? Note that the last 6 exercises are a little tricky in that they involve two arithmetic operations, with the final result possibly depending upon the order in which the operations are preformed. In exercise 5, the parenthesis makes it clear to the computer and you that you want 6 to be divided by 2 before the multiplication occurs. Exercise 6 should produce the same result since division is usually performed before multiplication, but it is always worth checking. In any case, because expressions like those in exercises 6 and 8 are ambiguous, it is we recommend using parenthesis to eliminate possible ambiguities. By the way, in exercise 8, divisions are performed from left to right and so the answer 5

6 should be 2. However, when the integer division in 9 within the parenthesis is carried out, the result is 0, and as you have seen, computers do not permit division by zero. Exercise: Determining Range of Integers Write a program, or sit at a terminal and do this by hand, and so determine experimentally the range of positive and negative integers on your computer system and for your computer language. (The simple Python program Limits.py given later can be modified for this purpose.) You can do this by successive multiplications by 2 until the results change abruptly, which is your signal that something not-quiteright has happened. A sample pseudocode is max = 1 min = -1. do 1 < i < N max = max *2. min = min * 2. write i, max, min end do Hint: we have indicated above that the integers in Python lies between 10 19, which is equivalent to approximately Floating-Point Numbers Figure 1 The approximate limits of double-precision (64 bit) floating-point numbers and the consequences of exceeding these limits. The hash marks represent the values of numbers that can be stored (approximately 16 decimal places); storing a number in between these values leads to round-off error. The shaded areas correspond to over- and underflow. Because integers are represented exactly on a computer, there is no loss of information when using them on a computer (at least if you remain within their range). Yet for many purposes the range of integers is too small, and of course many important numbers (like π) have fractional parts that cannot be represented an integer or even as the ratio of integers (rational numbers). So we also need a more powerful way to represent numbers on a computer. In practice, most scientific computations use the floating point representation of numbers, which otherwise is commonly known as scientific or engineering notation. For example, the speed of light c= m/s in scientific notation 6

7 or in engineering notation. In each of these cases, the number in front is called the mantissa and contains nine significant figures. The power to which 10 is raised is called the exponent, with the plus sign included as a reminder that these numbers may be negative: Floating Point Number = mantissa exponent Often on computers the power is indicated by the letter E meaning exponent; for example, c= E08 or E09. Indeed, deciding whether a number should be represented as an integer or a float is an important aspect of thinking computationally. The problem with using floating point numbers on a computer is that a fixed number of bits is used to represent the number, and so this limits the precision possible and the range of numbers possible. When 32 bits are used to store a floating-point number, we have what is called single precision, or singles, or just floats. When 64 bits are used to store a floating-point number, we have what is called double precision, or doubles. Some computer languages or applications like Maple and Mathematica permit the user to define the precision desired, but this is not usually employed since it slows down the calculation and sort of requires you to know the answer before doing the calculation. Most scientific computations require and use double precision (64 bits). Because only a finite number of bits are used to store the mantissa (the part in front), some numbers like π will have some of their digits furthest from the decimal point (their least significant parts) truncated, and thus will not be stored exactly. In Figure 1 we represent those numbers that can be stored exactly by the vertical hash marks. If the floating point number you try to store on the computer falls between two hash marks, some of the least significant digits are truncated and the number gets stored at the nearest has mark. For example, if you tried to store 1/3 = as a single precision float with 7 digit mantissa, it would be stored as , with nothing beyond the last 3. We have just described how truncation occurs when you try to store a number whose mantissa has more digits than the computer allows. Well, there is also a fixed number of digits allocated to store the exponent of a floating point number, and if you try to store more than that, something untoward happens. If your exponent is positive and is too big, an error condition known as overflow occurs. This usually causes your calculation to stop in its tracks, which is a good thing because otherwise the computer would just be producing garbage. If your exponent is a negative number with too large a magnitude (i.e. the number is too small is too small), an error condition known as underflow occurs. In this case the computer usually sets the full number to zero and continues with the calculation. This may result in some loss of precision, but probably will not produce garbage. The Institute of Electrical and Electronics Engineers (IEEE) has actually set standards for how computers and computer programs deal with floating point numbers. This means that running the same program on different computers should result in the same answers, even though the hardware and software may differ. As we shall define more carefully soon, the result may actually differ somewhat, but that difference would be smaller than the known precision of the floating point numbers being used. In addition, part of the IEEE standard calls for the symbol INF (for infinity) to occur if an overflow occurs, 7

8 and NAN (for not a number) to occur if you try to divide by zero. These symbols cannot be used in any further calculations, but are just given to tell you what the problem is. The actual limits for single and double precision numbers differ, with the increased length of double precision words leading to a greater range and an increased precision. Specifically, single-precision (32- bit) numbers have mantissas with 6.5 decimal places (not an exact number due to binary to decimal conversion), and exponents that limit their range to Single Precision Numbers Double precision (64 bit) numbers have mantissas with 16 decimal places, and exponents that limit their range to Double Precision Numbers But, do not believe everything we tell you. We will ask you to verify these limits for yourself. To repeat, serious scientific calculations almost always require at least 64-bit (double-precision) floats. And if you need double precision in one part of your calculation, you probably need it all over, which means double-precision library routines for all functions used as well. Python and the IEEE 754 Standard Python is a relatively recent language with changes and extensions occurring as its use spreads and as its features mature. It should be no surprise then that Python does not at present adhere to all aspects of the IEEE standard. Probably the most relevant difference for us is that Python does not support single (32 bit) precision floating point numbers. So when we deal with a data type called a float in Python, it is the equivalent of a double in the IEEE standard. Since singles are inadequate for most scientific computing, this is not a loss. However be wary, if you switch over to Java or C you should declare your variables as doubles and not as floats. Exercise: Over and Underflows 1. Write a program, or sit at a terminal and do this by hand, and test for the underflow and overflow limits (within a factor of 2) of your computer system. (The simple Python program Limits.py given later on can be modified for this purpose.) You can do this by successive multiplication and divisions by 2 until the computer tells you that something is wrong. A sample pseudocode is under = 1. over = 1. do 1 < i <N under = under/2. over = over * 2. write out: i, under, over end do 8

10 really precise, so getting the answer within a factor of 2 will be just fine. The basic idea is very simple: start with an arbitrary value of ε m, say ε m = 1, and add that to 1.0. If the answer is not 1.0, then make ε m smaller and again add it to 1.0. Keep repeating the process until you get 1.0 as an answer. The largest value of ε m for which this happens is your machine precision. Implementation Note, if you are doing this by entering the values of ε m by hand, you may want to divide by 10 each time until you get a gross answer, and then do some fine tuning. If you are writing a program, you can divide by 2 and just let the computer churn away for a long time. Here is a sample pseudo code (the basic elements of a computer program not specific to any language): eps = 1. do N times eps = eps/2. one = 1. + eps output one, eps end do # Make smaller # Write loop number, one, eps Python Implementation A model Python program than needs to be extended to actually determine the precision is Limits.py: # Limits.py: Increase N to determine approximate machine precision N = 3 eps = 1.0 for I in range(n): eps = eps/2 one = eps print('eps = ', eps, 'one = ', one) print("enter and return a character to finish") s=raw_input() Vensim: Excel: Summary and Conclusions You must know something about how computers store numbers in order to judge how reliable the results are. Unless you are carrying out symbolic manipulations, computed numbers are never exact, but can still be used to carry out calculations within a stated level of precision. Specifically, floating point numbers can give up to 16 places of precision, while integers can be exact, but have a much more limited range of values. Integers are thus appropriate for counting, such done when looping. 10

11 Where's Computational Scientific Thinking Understanding that computers are finite and therefore have limits. Being cognizant that uncertainties in numerical calculations are unavoidable. Understanding how it is possible to work within the limits of a computer to obtain meaningful results. Understanding the range of numbers that may be necessary to describe a natural phenomenon. Intuition Development References [CP] Landau, R.H., M.J. Paez and C.C. Bordeianu, (2008), A Survey of Computational Physics, Chapter 5, Princeton Univ. Press, Princeton. [UNChem] UNC-Chapel Hill Chemistry Fundamentals Program, Mathematics Review, Using Your Calculator, 11

### Chapter 2. Data Representation in Computer Systems

Chapter 2 Data Representation in Computer Systems Chapter 2 Objectives Understand the fundamentals of numerical data representation and manipulation in digital computers. Master the skill of converting

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

Math 340 Fall 2014, Victor Matveev Binary system, round-off errors, loss of significance, and double precision accuracy. 1. Bits and the binary number system A bit is one digit in a binary representation

### Chapter 1 Operations With Numbers

Chapter 1 Operations With Numbers Part I Negative Numbers You may already know what negative numbers are, but even if you don t, then you have probably seen them several times over the past few days. If

### 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

### fractional quantities are typically represented in computers using floating point format this approach is very much similar to scientific notation

Floating Point Arithmetic fractional quantities are typically represented in computers using floating point format this approach is very much similar to scientific notation for example, fixed point number

### Roundoff Errors and Computer Arithmetic

Jim Lambers Math 105A Summer Session I 2003-04 Lecture 2 Notes These notes correspond to Section 1.2 in the text. Roundoff Errors and Computer Arithmetic In computing the solution to any mathematical problem,

### 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

### Most nonzero floating-point numbers are normalized. This means they can be expressed as. x = ±(1 + f) 2 e. 0 f < 1

Floating-Point Arithmetic Numerical Analysis uses floating-point arithmetic, but it is just one tool in numerical computation. There is an impression that floating point arithmetic is unpredictable and

### 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

### Floating-point representation

Lecture 3-4: Floating-point representation and arithmetic Floating-point representation The notion of real numbers in mathematics is convenient for hand computations and formula manipulations. However,

### 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

### The type of all data used in a C (or C++) program must be specified

The type of all data used in a C (or C++) program must be specified A data type is a description of the data being represented That is, a set of possible values and a set of operations on those values

### 2 Computation with Floating-Point Numbers

2 Computation with Floating-Point Numbers 2.1 Floating-Point Representation The notion of real numbers in mathematics is convenient for hand computations and formula manipulations. However, real numbers

### Basics of Computation. PHY 604:Computational Methods in Physics and Astrophysics II

Basics of Computation Basics of Computation Computers store information and allow us to operate on it. That's basically it. Computers have finite memory, so it is not possible to store the infinite range

### 1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM 1.1 Introduction Given that digital logic and memory devices are based on two electrical states (on and off), it is natural to use a number

### Divisibility Rules and Their Explanations

Divisibility Rules and Their Explanations Increase Your Number Sense These divisibility rules apply to determining the divisibility of a positive integer (1, 2, 3, ) by another positive integer or 0 (although

### 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

### 3.1 DATA REPRESENTATION (PART C)

3.1 DATA REPRESENTATION (PART C) 3.1.3 REAL NUMBERS AND NORMALISED FLOATING-POINT REPRESENTATION In decimal notation, the number 23.456 can be written as 0.23456 x 10 2. This means that in decimal notation,

### Skill 1: Multiplying Polynomials

CS103 Spring 2018 Mathematical Prerequisites Although CS103 is primarily a math class, this course does not require any higher math as a prerequisite. The most advanced level of mathematics you'll need

### Floating Point Arithmetic

Floating Point Arithmetic Clark N. Taylor Department of Electrical and Computer Engineering Brigham Young University clark.taylor@byu.edu 1 Introduction Numerical operations are something at which digital

### Up next. Midterm. Today s lecture. To follow

Up next Midterm Next Friday in class Exams page on web site has info + practice problems Excited for you to rock the exams like you have been the assignments! Today s lecture Back to numbers, bits, data

### Numeric Precision 101

www.sas.com > Service and Support > Technical Support TS Home Intro to Services News and Info Contact TS Site Map FAQ Feedback TS-654 Numeric Precision 101 This paper is intended as a basic introduction

### VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.

Lesson 2 VARIABLES Aim Understanding how computer programs store values, and how they are accessed and used in computer programs. WHAT ARE VARIABLES? When you input data (i.e. information) into a computer

### 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

### 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

### Floating Point Representation in Computers

Floating Point Representation in Computers Floating Point Numbers - What are they? Floating Point Representation Floating Point Operations Where Things can go wrong What are Floating Point Numbers? Any

### Logic, Words, and Integers

Computer Science 52 Logic, Words, and Integers 1 Words and Data The basic unit of information in a computer is the bit; it is simply a quantity that takes one of two values, 0 or 1. A sequence of k bits

### Chapter 2: Number Systems

Chapter 2: Number Systems Logic circuits are used to generate and transmit 1s and 0s to compute and convey information. This two-valued number system is called binary. As presented earlier, there are many

### Section 1.4 Mathematics on the Computer: Floating Point Arithmetic

Section 1.4 Mathematics on the Computer: Floating Point Arithmetic Key terms Floating point arithmetic IEE Standard Mantissa Exponent Roundoff error Pitfalls of floating point arithmetic Structuring computations

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

IT 1204 Section 2.0 Data Representation and Arithmetic 2009, University of Colombo School of Computing 1 What is Analog and Digital The interpretation of an analog signal would correspond to a signal whose

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

University of Illinois at Urbana-Champaign Dept. of Electrical and Computer Engineering ECE 120: Introduction to Computing Fixed- and Floating-Point Representations In Binary, We Have A Binary Point Let

### 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

### Lecture Objectives. Structured Programming & an Introduction to Error. Review the basic good habits of programming

Structured Programming & an Introduction to Error Lecture Objectives Review the basic good habits of programming To understand basic concepts of error and error estimation as it applies to Numerical Methods

### Floating-Point Numbers in Digital Computers

POLYTECHNIC UNIVERSITY Department of Computer and Information Science Floating-Point Numbers in Digital Computers K. Ming Leung Abstract: We explain how floating-point numbers are represented and stored

### 1.3 Floating Point Form

Section 1.3 Floating Point Form 29 1.3 Floating Point Form Floating point numbers are used by computers to approximate real numbers. On the surface, the question is a simple one. There are an infinite

### Floating-Point Numbers in Digital Computers

POLYTECHNIC UNIVERSITY Department of Computer and Information Science Floating-Point Numbers in Digital Computers K. Ming Leung Abstract: We explain how floating-point numbers are represented and stored

### Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

Appendix F Number Systems Binary Numbers Decimal notation represents numbers as powers of 10, for example 1729 1 103 7 102 2 101 9 100 decimal = + + + There is no particular reason for the choice of 10,

### Floating Point. CSC207 Fall 2017

Floating Point CSC207 Fall 2017 Ariane 5 Rocket Launch Ariane 5 rocket explosion In 1996, the European Space Agency s Ariane 5 rocket exploded 40 seconds after launch. During conversion of a 64-bit to

### FLOATING POINT NUMBERS

FLOATING POINT NUMBERS Robert P. Webber, Longwood University We have seen how decimal fractions can be converted to binary. For instance, we can write 6.25 10 as 4 + 2 + ¼ = 2 2 + 2 1 + 2-2 = 1*2 2 + 1*2

### WHAT IS MATLAB?... 1 STARTING MATLAB & USING THE COMMAND LINE... 1 BASIC ARITHMETIC OPERATIONS... 5 ORDER OF OPERATIONS... 7

Contents WHAT IS MATLAB?... 1 STARTING MATLAB & USING THE COMMAND LINE... 1 BASIC ARITHMETIC OPERATIONS... 5 ORDER OF OPERATIONS... 7 WHAT IS MATLAB? MATLAB stands for MATrix LABoratory. It is designed

### Number Systems and Computer Arithmetic

Number Systems and Computer Arithmetic Counting to four billion two fingers at a time What do all those bits mean now? bits (011011011100010...01) instruction R-format I-format... integer data number text

### Classes of Real Numbers 1/2. The Real Line

Classes of Real Numbers All real numbers can be represented by a line: 1/2 π 1 0 1 2 3 4 real numbers The Real Line { integers rational numbers non-integral fractions irrational numbers Rational numbers

### Meeting 1 Introduction to Functions. Part 1 Graphing Points on a Plane (REVIEW) Part 2 What is a function?

Meeting 1 Introduction to Functions Part 1 Graphing Points on a Plane (REVIEW) A plane is a flat, two-dimensional surface. We describe particular locations, or points, on a plane relative to two number

### Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation

Course Schedule CS 221 Computer Architecture Week 3: Information Representation (2) Fall 2001 W1 Sep 11- Sep 14 Introduction W2 Sep 18- Sep 21 Information Representation (1) (Chapter 3) W3 Sep 25- Sep

### Number Systems. Both numbers are positive

Number Systems Range of Numbers and Overflow When arithmetic operation such as Addition, Subtraction, Multiplication and Division are performed on numbers the results generated may exceed the range of

### Numeral Systems. -Numeral System -Positional systems -Decimal -Binary -Octal. Subjects:

Numeral Systems -Numeral System -Positional systems -Decimal -Binary -Octal Subjects: Introduction A numeral system (or system of numeration) is a writing system for expressing numbers, that is a mathematical

### EC121 Mathematical Techniques A Revision Notes

EC Mathematical Techniques A Revision Notes EC Mathematical Techniques A Revision Notes Mathematical Techniques A begins with two weeks of intensive revision of basic arithmetic and algebra, to the level

### CS321. Introduction to Numerical Methods

CS31 Introduction to Numerical Methods Lecture 1 Number Representations and Errors Professor Jun Zhang Department of Computer Science University of Kentucky Lexington, KY 40506 0633 August 5, 017 Number

### ME 261: Numerical Analysis. ME 261: Numerical Analysis

ME 261: Numerical Analysis 3. credit hours Prereq.: ME 163/ME 171 Course content Approximations and error types Roots of polynomials and transcendental equations Determinants and matrices Solution of linear

### 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

### Pre-Algebra Notes Unit One: Variables, Expressions, and Integers

Pre-Algebra Notes Unit One: Variables, Expressions, and Integers Evaluating Algebraic Expressions Syllabus Objective: (.) The student will evaluate variable and numerical expressions using the order of

### What Every Programmer Should Know About Floating-Point Arithmetic

What Every Programmer Should Know About Floating-Point Arithmetic Last updated: October 15, 2015 Contents 1 Why don t my numbers add up? 3 2 Basic Answers 3 2.1 Why don t my numbers, like 0.1 + 0.2 add

### unused unused unused unused unused unused

BCD numbers. In some applications, such as in the financial industry, the errors that can creep in due to converting numbers back and forth between decimal and binary is unacceptable. For these applications

### Project 3: RPN Calculator

ECE267 @ UIC, Spring 2012, Wenjing Rao Project 3: RPN Calculator What to do: Ask the user to input a string of expression in RPN form (+ - * / ), use a stack to evaluate the result and display the result

### Signed umbers. Sign/Magnitude otation

Signed umbers So far we have discussed unsigned number representations. In particular, we have looked at the binary number system and shorthand methods in representing binary codes. With m binary digits,

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

4 Operations On Data 4.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: List the three categories of operations performed on data.

### 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

### Truncation Errors. Applied Numerical Methods with MATLAB for Engineers and Scientists, 2nd ed., Steven C. Chapra, McGraw Hill, 2008, Ch. 4.

Chapter 4: Roundoff and Truncation Errors Applied Numerical Methods with MATLAB for Engineers and Scientists, 2nd ed., Steven C. Chapra, McGraw Hill, 2008, Ch. 4. 1 Outline Errors Accuracy and Precision

### Characters, Strings, and Floats

Characters, Strings, and Floats CS 350: Computer Organization & Assembler Language Programming 9/6: pp.8,9; 9/28: Activity Q.6 A. Why? We need to represent textual characters in addition to numbers. Floating-point

### 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

### The ALU consists of combinational logic. Processes all data in the CPU. ALL von Neuman machines have an ALU loop.

CS 320 Ch 10 Computer Arithmetic The ALU consists of combinational logic. Processes all data in the CPU. ALL von Neuman machines have an ALU loop. Signed integers are typically represented in sign-magnitude

### Is the statement sufficient? If both x and y are odd, is xy odd? 1) xy 2 < 0. Odds & Evens. Positives & Negatives. Answer: Yes, xy is odd

Is the statement sufficient? If both x and y are odd, is xy odd? Is x < 0? 1) xy 2 < 0 Positives & Negatives Answer: Yes, xy is odd Odd numbers can be represented as 2m + 1 or 2n + 1, where m and n are

### CHAPTER 5 Computer Arithmetic and Round-Off Errors

CHAPTER 5 Computer Arithmetic and Round-Off Errors In the two previous chapters we have seen how numbers can be represented in the binary numeral system and how this is the basis for representing numbers

### Lecture Notes: Floating-Point Numbers

Lecture Notes: Floating-Point Numbers CS227-Scientific Computing September 8, 2010 What this Lecture is About How computers represent numbers How this affects the accuracy of computation Positional Number

### Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

Fundamentals We build up instructions from three types of materials Constants Expressions Fundamentals Constants are just that, they are values that don t change as our macros are executing Fundamentals

### Excerpt from "Art of Problem Solving Volume 1: the Basics" 2014 AoPS Inc.

Chapter 5 Using the Integers In spite of their being a rather restricted class of numbers, the integers have a lot of interesting properties and uses. Math which involves the properties of integers is

### The Perils of Floating Point

The Perils of Floating Point by Bruce M. Bush Copyright (c) 1996 Lahey Computer Systems, Inc. Permission to copy is granted with acknowledgement of the source. Many great engineering and scientific advances

### Floating-point numbers. Phys 420/580 Lecture 6

Floating-point numbers Phys 420/580 Lecture 6 Random walk CA Activate a single cell at site i = 0 For all subsequent times steps, let the active site wander to i := i ± 1 with equal probability Random

### 3.4 Equivalent Forms of Rational Numbers: Fractions, Decimals, Percents, and Scientific Notation

3.4 Equivalent Forms of Rational Numbers: Fractions, Decimals, Percents, and Scientific Notation We know that every rational number has an infinite number of equivalent fraction forms. For instance, 1/

### Chapter Fourteen Bonus Lessons: Algorithms and Efficiency

: Algorithms and Efficiency The following lessons take a deeper look at Chapter 14 topics regarding algorithms, efficiency, and Big O measurements. They can be completed by AP students after Chapter 14.

### Basic Arithmetic Operations

Basic Arithmetic Operations Learning Outcome When you complete this module you will be able to: Perform basic arithmetic operations without the use of a calculator. Learning Objectives Here is what you

### IEEE Standard 754 Floating Point Numbers

IEEE Standard 754 Floating Point Numbers Steve Hollasch / Last update 2005-Feb-24 IEEE Standard 754 floating point is the most common representation today for real numbers on computers, including Intel-based

### 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:

### Chapter 4: Data Representations

Chapter 4: Data Representations Integer Representations o unsigned o sign-magnitude o one's complement o two's complement o bias o comparison o sign extension o overflow Character Representations Floating

### Floating Point Considerations

Chapter 6 Floating Point Considerations In the early days of computing, floating point arithmetic capability was found only in mainframes and supercomputers. Although many microprocessors designed in the

### 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

### Numerical Methods in Physics. Lecture 1 Intro & IEEE Variable Types and Arithmetic

Variable types Numerical Methods in Physics Lecture 1 Intro & IEEE Variable Types and Arithmetic Pat Scott Department of Physics, Imperial College November 1, 2016 Slides available from http://astro.ic.ac.uk/pscott/

### Integers and Floating Point

CMPE12 More about Numbers Integers and Floating Point (Rest of Textbook Chapter 2 plus more)" Review: Unsigned Integer A string of 0s and 1s that represent a positive integer." String is X n-1, X n-2,

### 4.1 QUANTIZATION NOISE

DIGITAL SIGNAL PROCESSING UNIT IV FINITE WORD LENGTH EFFECTS Contents : 4.1 Quantization Noise 4.2 Fixed Point and Floating Point Number Representation 4.3 Truncation and Rounding 4.4 Quantization Noise

### APPENDIX B. Fortran Hints

APPENDIX B Fortran Hints This appix contains hints on how to find errors in your programs, and how to avoid some common Fortran errors in the first place. The basics on how to invoke the Fortran compiler

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

4 Operations On Data 4.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: List the three categories of operations performed on data.

### 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

### Representing numbers on the computer. Computer memory/processors consist of items that exist in one of two possible states (binary states).

Representing numbers on the computer. Computer memory/processors consist of items that exist in one of two possible states (binary states). These states are usually labeled 0 and 1. Each item in memory

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

Computational Methods CMSC/AMSC/MAPL 460 Representing numbers in floating point and associated issues Ramani Duraiswami, Dept. of Computer Science Class Outline Computations should be as accurate and as

### 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

### CHAPTER 1: INTEGERS. Image from CHAPTER 1 CONTENTS

CHAPTER 1: INTEGERS Image from www.misterteacher.com CHAPTER 1 CONTENTS 1.1 Introduction to Integers 1. Absolute Value 1. Addition of Integers 1.4 Subtraction of Integers 1.5 Multiplication and Division

### Computer Number Systems Supplement

Computer Number Systems Supplement Dr. Ken Hoganson, All Rights Reserved. SUPPLEMENT CONTENTS S.1 Decimal System: Powers-of-the-Base 2 S.2 Converting to Binary: Division/Remainder Algorithm. 3 S.3 Binary

### Imelda C. Go, South Carolina Department of Education, Columbia, SC

PO 082 Rounding in SAS : Preventing Numeric Representation Problems Imelda C. Go, South Carolina Department of Education, Columbia, SC ABSTRACT As SAS programmers, we come from a variety of backgrounds.

### LABORATORY. 3 Representing Numbers OBJECTIVE REFERENCES. Learn how negative numbers and real numbers are encoded inside computers.

Dmitriy Shironosov/ShutterStock, Inc. LABORATORY 3 Representing Numbers OBJECTIVE Learn how negative numbers and real numbers are encoded inside computers. REFERENCES Software needed: 1) Apps from the

### Data Representation and Introduction to Visualization

Data Representation and Introduction to Visualization Massimo Ricotti ricotti@astro.umd.edu University of Maryland Data Representation and Introduction to Visualization p.1/18 VISUALIZATION Visualization

### Number Systems Using and Converting Between Decimal, Binary, Octal and Hexadecimal Number Systems

Number Systems Using and Converting Between Decimal, Binary, Octal and Hexadecimal Number Systems In everyday life, we humans most often count using decimal or base-10 numbers. In computer science, it

### 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

### Physics 331 Introduction to Numerical Techniques in Physics

Physics 331 Introduction to Numerical Techniques in Physics Instructor: Joaquín Drut Lecture 2 Any logistics questions? Today: Number representation Sources of error Note: typo in HW! Two parts c. Call

### How & Why We Subnet Lab Workbook

i How & Why We Subnet Lab Workbook ii CertificationKits.com How & Why We Subnet Workbook Copyright 2013 CertificationKits LLC All rights reserved. No part of this book maybe be reproduced or transmitted

### CREATING FLOATING POINT VALUES IN MIL-STD-1750A 32 AND 48 BIT FORMATS: ISSUES AND ALGORITHMS

CREATING FLOATING POINT VALUES IN MIL-STD-1750A 32 AND 48 BIT FORMATS: ISSUES AND ALGORITHMS Jeffrey B. Mitchell L3 Communications, Telemetry & Instrumentation Division Storm Control Systems ABSTRACT Experimentation

### IBM 370 Basic Data Types

IBM 370 Basic Data Types This lecture discusses the basic data types used on the IBM 370, 1. Two s complement binary numbers 2. EBCDIC (Extended Binary Coded Decimal Interchange Code) 3. Zoned Decimal

### 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