P1 Engineering Computation

Size: px
Start display at page:

Download "P1 Engineering Computation"

Transcription

1 1EC / 1 P1 Engineering Computation David Murray david.murray@eng.ox.ac.uk dwm/courses/1ec Hilary 2001

2 1EC / 1 Why does Computer Arithmetic introduce Error?

3 1EC / 1 Arithmetic Operations Whenever we write, /, + and in a computer program we invoke built-in subroutines to perform the associated arithmetic operation between two numbers. Can we rely on the results returned? Not entirely. Because computers store numbers and operate on numbers of some restricted wordlength there are predictable uncertainties introduced into the results. These effects are more keenly felt when with floating point numbers, but integer operations can be affected, and we touch on this first.

4 1EC / 1 Representing Integers Within a computer, the representation of integers is exact, as is the performance of integer arithmetic but only within a finite range of numbers determined by the wordlength. Consider a n-bit word. Each bit is 0 or 1 (2 items), and so n bits can represent 2 n different items. One obvious range is from 0 to 2 n 1, the range of unsigned integers. In some applications positive number suffice. For example, a grey-level image has an 8-bit number to represent image brightness on a scale of 0 (black) to 255 (white) at each pixel. More usually though, we need to split the range evenly between positive and negative numbers. To represent the ± sign in front of a number must take 1 bit of information, so within the n-bit wordlength we have now only (n 1) bits to represent the number s modulus.

5 1EC / 1 Integers /ctd Again let us use 8 bits as a concrete example. As shown in the tables, three possible methods are 1 to use sign and modulus directly, setting the most significant bit as sign bit. (Not nice.) 2 to bias the result by to use the 2 s complement representation Sign,Mod Biassed by s complement

6 1EC / 1 Integers /ctd You will learn more about 2 s complement arithmetic in the 1P2 course. Our sole aim here has been just to bring out three points: 1 Finite wordlength imposes restrictions (here on range). Although the word-length of most desktop microprocessors is 32bit with a maximum integer therefore of order 10 9, this is not that large! 2 Within range, integer arithmetic is EXACT. 3 There is no pre-ordained computer representation for numbers.

7 1EC / 1 Floating point arithmetic The 1st and 3rd points just made hold also for floating point arithmetic, but the 2nd does not. That is: 1 Finite wordlength imposes restrictions (on range AND accuracy) 2 Even within range, floating point arithmetic is not necessarily exact 3 There is no pre-ordained representation. What does not necessarily exact mean? Although many floating point numbers can be represented exactly within a restricted word length, others cannot. Now, if an exact number occurs as the result of some extended calculation one cannot be sure whether the number is an exact representation of one of these special numbers; or an inexact representation of one slightly different. Thus we must assume uncertainty in ALL floating point numbers. The error is called roundoff error.

8 1EC / 1 Representation of Floating Point Numbers To assess this uncertainty, we need to specify a representation for a floating point number. We also need a recipe for converting from a decimal representation to the bit pattern and vice versa. Although there is no God-given representation, the IEEE 1 in the US has defined standards to which computer manufacturers adhere. You ll know already that on a calculator scientific notation is an effective way of representing numbers in a large range even though the number of digits on the display is small. That is, one uses rather than The is called the mantissa, and the -7 is called the exponent. The binary recipe is similar except that 2 is raised to a power, not 10, and the exponent is biassed. The number is represented by Sign, Exponent and Mantissa as follows: f = SIGN 2 (EXPONENT Bias) MANTISSA 1 The Institute of Electrical and Electronic Engineers at God s right hand in these matters!

9 1EC / 1 IEEE representation using 32 bits Consider now a 32 bit wordlength: The Sign need only occupy 1bit The Exponent occupies (by choice) 8 bits. You might think that this would be a 2 s complement number, but no. It is a biassed number, and the bias is 127. The Mantissa occupies the remaining bits, and is normalized so that the most significant bit (msb) is 1. At first sight the mantissa must be 23 bits, but actually it is 24 bits long. How can this be? The trick is to notice that if mantissa is always normalized so that its leading bit is 1, then there is no need to explicitly represent the bit! It is referred to a the hidden bit. This gain in accuracy is paid for by the need for a special representation for 0. The binimal point in the mantissa comes just after the hidden bit.

10 1EC / 1 Examples According to these rules, the following are the representations for 1 and 0.5: 1.0 = [+] 2 0 [1] = [+] [1] = [1] = [+] = [+] 2 1 [1] = [+] [1] = [1] It is quite easy to write a program to write out the bits from numbers stored in a computer. Let s see if everything agrees: Look at 32-bit rep of 1.0, -1.0, 0.25, 0.26 and 0.0 on a PC % bit_decomp f 1.0 S:0 E: M:(1) Sign Hidden bit % bit_decomp f -1.0 S:1 E: M:(1)

11 1EC / 1 More examples % bit_decomp f 0.25 S:0 E: M:(1) % bit_decomp f 0.26 S:0 E: M:(1) The special representation of 0.0 mentioned earlier is that if ALL the actual hardware bits are zero, the number is zero. % bit_decomp f 0.0 S:0 E: M:(1) ^ NOT Hardware Remember!

12 1EC / 1 Converting from decimal to binary How does one convert 0.26 to the IEEE format? One way is to find repeatedly the largest fraction 1/2 m which is still less than the unconverted part of the number: 0.26 = = = = = etc 0.26 = etc = etc = et E = M = [1] etc in agreement with the output of the decomposition program. % bit_decomp f 0.26 S:0 E: M:(1) If you carried on, you would find that there is still a remainder even after all the bits were filled in the 24-bit mantissa cannot be represented exactly in a 32 bit floating point number.

13 1EC / 1 The largest and smallest numbers The manual pages tell me that the largest floating point number representable in 32 bits is or e Let s try the program... %bit_decomp f e+38 S:0 E: M:(1) Notice that not all the bits are 1. A number with all 1 s is reserved to represent Infinity, a number not infrequently produced in computer arithmetic by accidentally dividing by zero! The smallest finite number is written as e-45 and this has the bit pattern %bit_decomp f gibber-gibber...e-45 S:0 E: M:(1) Notice the 1 in the least significant bit (rightmost bit) of the mantissa. If it had been zero, the number would be zero.

14 1EC / 1 The accuracy of any number The smallest number is determined by the number of bits in the exponent (here 8 bits). However it is the number of bits in the mantissa that determines the accuracy of any number. In the IEEE representation, the leading hidden bit is 1, and each of the explicit 23 bits of the mantissa is either 0 or 1. However, we have no knowledge of bit 24, and so any finite number is uncertain by an amount 2 24 smaller than the leading bit. H /1 0/1... 0/1 0/1? So, any finite number V is actually V (1±ǫ), where ǫ = ǫ is called the ROUNDING or ROUNDOFF ERROR. It is a relative or fractional error, not an absolute error. This is similar to uncertainty using scientific notation on a calculator. Suppose your calculator has a five digit mantissa E 13± E 13 and so the number is V (1± ) again a relative error.

15 1EC / 1 But surely these round off errors are small... Two pieces of code you have designed for an embedded processor performs a summation every second. Unfortunately, they seem to produce wildly different results. After careful analysis, you find that in a loop in version 1 you are effectively summing ( ) every second, whereas in version 2 involves summing ( ). But both should be summing zero... and therefore give the same results... er, shouldn t they? You write a test program to see the difference over the period of a year... and find that... Sec_in_year * (5-10 * 0.5) = Sec_in_year * (3-10 * 0.3) = These sort of errors can easily build up in shorter periods of time. For example, the loops in the controller for aircraft flight surfaces might run at a 1 khz. A progressive shift on a flight from London to New York does not sound too attractive...

16 1EC / 1 Here s the program... #include <stdio.h> void main() { float pointfive = 0.5, pointthree = 0.3, three = 3.0, five = 5.0, ten = 10.0, siy = 365.0*24.0*3600.0; float answer1,answer2; answer1 = siy*(five-ten*pointfive); answer2 = siy*(three-ten*pointthree); printf("sec_in_year x (5-10 x 0.5) = %20.18f\n",answer1); printf("sec_in_year x (3-10 x 0.3) = %20.18f\n",answer2); }

17 1EC / 1 Sources of Error in Computational Engineering 1. Roundoff error 2. Modelling error In engineering, mathematical equations are generated to represent some physical system. These mathematical models will rarely represent the physical situation precisely, and must therefore give rise to modelling error. One should always question whether making some piece numerical analysis ever more precise is justified if the underlying model is imprecise. 3. Approximation/Truncation/Discretization Error Once you have decided on your model, there may be aspects where you have to make mathematical approximations. For example you may use the approximation e x2 1+x 2 + x 4 /2!+x 6 /3!+x 8 /4! Even with zero roundoff error in the calculation of x n, e x2 will still be in error.

18 1EC / 1 Sources of Error /ctd Measurement Error. Often the raw data for a piece of analysis comes from experiment. In lecture 2 we saw some data from a mass spectrometer which you wished to integrate. Then round-off and discretization errors might be insignificant compared with the measurement uncertainty in each datum. 5. Gross Error a.k.a. Bloopers. These arise in experimental measurements, but lie outside the expected probabilistic variation of a quantity. They may arise from human error (say, writing down 3.8 rather than 8.3), or from an intermittent fault occuring in a piece of apparatus. In the graph we see points with measurement error. The point far away from the fitted line is likely to be a gross error. But then again it could be the first observation of that Nobel

19 1EC / 1 Summary so far... We have seen that using an exponent/mantissa representation (or scientific notation) leads to fractional errors. Suppose your calculator has a five digit mantissa, using decimal: E 13 is actually ( ± )E 13 Indeed any number is V (1± ) So, ROUNDOFF ERROR is a FRACTIONAL or RELATIVE ERROR. Having explored the IEEE 32-bit representation, we found that numbers V are actually V (1±2 24 ) = V (1± ). We also saw that there were several other sources of error, and the question arises of how to combine errors.

20 1EC / 1 Combining Errors When we combine quantities with error in the computation of an expression, the errors interact in a way that depends on the sizes of the quantities and errors, and the formula itself. So, for example, if x 1 and x 2 are in error by some amount, the error in x 1 x 2 is different from that in x 1 + x 2, and so on. How can we evaluate the error? Let us suppose that our quantities x 1, x 2, x 3,... are combined into a function f = f(x 1, x 2, x 3,...). Recall from your lectures on Partial Differentiation that an expression for the total or perfect differential of a function of several variables f = f(x 1, x 2, x 3,...) is ( ) ( ) ( ) f f f df = dx 1 + dx 2 + dx x 1 x 2 x 3 This is taken in the limit as dx 1 etc tend to zero.

21 1EC / 1 Correlated Errors If we relax this condition, and df δf, and dx 1 δx 1 and so on, then we have a 1st order Taylor expansion of the function of several variables. If we equate the δ s with the errors in the various quantities, this would give a way of assessing the size of error in a quantity f. But it assumes we know the relative signs of all the δx i s. That is, we know about the correlation between the quantities and their errors. For correlated errors. δf δx 1 ( f x 1 ) ( ) ( ) f f +δx 2 +δx x 2 x 3

22 1EC / 1 Example of Correlated Errors Daft example of Correlated Errors parallax

23 1EC / 1 For uncorrelated errors. If the errors are uncorrelated, we add the terms incoherently, by summing the squares of each term. This is also known as adding in quadrature. ( ) 2 ( ) 2 ( ) 2 f f f (δf) 2 (δx 1 ) 2 +(δx 2 ) 2 +(δx 3 ) x 1 x 2 x 3

24 1EC / 1 Example 1: Uncorrelated Errors in a Sum Summation. Suppose f = x 1 + x x N = N i=1 x i. Then each f/ x i = 1 and the formula for uncorrelated errors reduces to N (δf) 2 = (δx i ) 2. i=1 In other words, add the absolute errors in quadrature.

25 1EC / 1 Example 2: Uncorrelated Errors in a Product Products. Suppose f = N i=1 x i. Each f/ x i = f/x i, so for uncorrelated errors (δf) 2 = (δx 1 ) 2 ( f x 1 ) 2 +(δx 2 ) 2 ( f x 2 ) 2 +(δx 3 ) 2 ( f x 3 ) Divide through by f 2 and you ll find ( ) 2 δf N ( ) 2 δxi =. f i=1 x i In other words, add the fractional errors in quadrature.

26 1EC / 1 Example 3: Slightly more involved... You perform an experiment to measure the viscosity of custard. Viscosity given by V = Γ [ 1 4πΩ a 2 1 ] b 2 Custard θ Radius a Radius b Ω Perfect differential is: dv = dγ 4πΩ [ 1 a 2 1 b 2 = dγ Γ V dω Ω V + Γ 4πΩ What is the error in V given errors in Γ, Ω, a and b... ] Γ dω [ 1 4πΩ 2 [ 2da a 3 a 2 1 b 2 ] + Γ 4πΩ ] + Γ 4πΩ [ ] 2db b 3 [ 2da a 3 ] + Γ 4πΩ [ ] 2db b 3

27 1EC / 1 Viscosity of custard Let s assume uncorrelated errors! So sum the squares instead... ( ) 2 ( ) 2 ( ) 2 ] δγ δω Γ δa (δv) 2 = V 2 + V [ Γ Ω 4πΩ a 6 + δb2 b 6 Divide Left and Right by V 2 And so ( ) 2 δv = V ( δv V ) 2 = ( ) 2 δγ + Γ ( ) 2 δγ + Γ ( ) 2 δω + Ω [ ( ) 2 δa 2 δω + 4 Ω ] 2 a + δb2 6 b 6 [ 1 a 2 1 b 2 ] [ ( 4 δa (b 2 a 2 ) 2 b 4 a ) 2 ( ) ] 2 δb + a 4 b So, suppose the errors in Γ and Ω were each 1%. Let a be 2cm and b be 3cm, each known to 1%. Then (δv ) 2 = [ ] 10 4 (18) V 25 so the fractional error is

28 1EC / 1 Accumulation of roundoff errors Now suppose we performed some computation with N multiplications between numbers each with roundoff error ǫ P = x 1 x 2... x N Recall that the roundoff error is a relative or fractional error. If the errors are uncorrelated, we add the sums of the squares of the fractional errors. This gives the roundoff error in the product of ǫ P ǫ 2 +ǫ = Nǫ, where we assume that the roundoff error is similar in each number x i. However, the errors can easily be correlated Most obviously when computing x 3 1 using P = x 1 x 1 x 1. Then, using the earlier formula ǫ P ǫ+ǫ+... = Nǫ = 3ǫ

29 1EC / 1 Accumulation of roundoff errors /ctd In fact roundoff error is a little more unkind. The result is not only in error because the individual numbers are in error, but also because of roundoff error in the result itself. If N is large this doesn t matter much, but most often in computer code N = 2. Example using Product. Suppose we take the product of two numbers x 1 and x 2 with roundoff errors ǫ 1 and ǫ 2. Assume that the machine roundoff error is ǫ. Taking the worst case ie correlated errors we have the product Prod = x 1 (1+ǫ 1 )x 2 (1+ǫ 2 )+ǫx 1 x 2 x 1 x 2 (1+ǫ 1 +ǫ 2 +ǫ) The roundoff error in the product must is Same for DIVISION of course! ǫ 12 = Prod (x 1 x 2 ) 1 = ǫ 1 +ǫ 2 +ǫ.

30 1EC / 1 Roundoff error in Sums and differences of quantities Example using Sum. Now consider the sum with correlated errors Sum = x 1 (1+ǫ 1 )+x 2 (1+ǫ 2 )+ǫ( x 1 + x 2 ) Now the roundoff error is TYPO in the NOTES!! Sum 1 = x 1(1+ǫ 1 )+x 2 (1+ǫ 2 )+ǫ( x 1 + x 2 ) 1 x 1 + x 2 x 1 + x 2 Assuming that ǫ 1 1 and ǫ 2 1 Roundoff = ǫ ( x 1 + x 2 ) (x 1 + x 2 ) which is the machine roundoff error AMPLIFIED by ( x 1 + x 2 ) (x 1 + x 2 ) This is very bad news when we are subtracting similarly sized numbers because then x 1 x 2 and the amplification is LARGE!

31 1EC / 1 1e-07 1e-08 "out32" 1e-09 1e Practical example Consider finding the roots to a quadratic f = ax 2 + bx + c. The roots are at "out12" "out22" x 1,2 = ( b ± b 2 4ac)/2a When ac << b 2, the x 2 root should tend to c/b (an exercise for the reader) and hence approach zero. However the obvious code becomes prone to rounding error, as the jagged line in the plot shows. The modulus of the x 2 root plotted as a function of a. As a and c are reduced, the first routine shows the effects of rounding error. In the plot, b = 10 4, a = c and the abscissa is log 10 (a). The ordinate is log 10 ( x 2 ). 1: Quadroots1(a, b, c; x 1, x 2 ) BAD!! 2: x 1

32 1EC / 1 Modified code Also shown are the results for x 2 = c/b and for the routine taken from Numerical Recipes in C. Note that these latter results agree with each other they continue to do so for at least 20 more orders of magnitude of reduction in a and c. How small the code changes appear! 1e-07 Quadroots2(a, b, c; x 1, x 2 ) if (b < 0.0) then sign 1.0; else sign 1.0; end if q (b + sign Sqrt(b b 4.0 a c))/2.0; x 1 q/a; x 2 c/q; "out12" "out22" "out32" 1e-08

33 1EC / 1 And you thought the viscosity of custard was a joke Learn more about the viscosity of custard at and search on custard. Viscosity is an important determinant of custard quality. Two commercial samples of starch based custard powders were cooked on a hot plate according to their packet directions. Viscosity of Brand 1 was three times higher than that of Brand 2. The same brands were then tested in the RVA using milk and the following profile at the recommended concentrations (28.0 g total weight). Brand 1 gave a final viscosity about twice that of Brand 2 (Figure 1), reflecting the trend in the hot plate prepared samples.

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

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

More information

MAT128A: Numerical Analysis Lecture Two: Finite Precision Arithmetic

MAT128A: Numerical Analysis Lecture Two: Finite Precision Arithmetic MAT128A: Numerical Analysis Lecture Two: Finite Precision Arithmetic September 28, 2018 Lecture 1 September 28, 2018 1 / 25 Floating point arithmetic Computers use finite strings of binary digits to represent

More information

Floating-point numbers. Phys 420/580 Lecture 6

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

More information

Floating-Point Numbers in Digital Computers

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

More information

Number Systems. Both numbers are positive

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

More information

2 Computation with Floating-Point Numbers

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

More information

Floating-Point Numbers in Digital Computers

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

More information

2 Computation with Floating-Point Numbers

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

More information

Computational Mathematics: Models, Methods and Analysis. Zhilin Li

Computational Mathematics: Models, Methods and Analysis. Zhilin Li Computational Mathematics: Models, Methods and Analysis Zhilin Li Chapter 1 Introduction Why is this course important (motivations)? What is the role of this class in the problem solving process using

More information

1.3 Floating Point Form

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

More information

ECE232: Hardware Organization and Design

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

More information

Scientific Computing. Error Analysis

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

More information

Introduction to Computers and Programming. Numeric Values

Introduction to Computers and Programming. Numeric Values Introduction to Computers and Programming Prof. I. K. Lundqvist Lecture 5 Reading: B pp. 47-71 Sept 1 003 Numeric Values Storing the value of 5 10 using ASCII: 00110010 00110101 Binary notation: 00000000

More information

Floating-point representation

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,

More information

Chapter 3: Arithmetic for Computers

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

More information

Signed umbers. Sign/Magnitude otation

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,

More information

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

Real Numbers finite subset real numbers floating point numbers Scientific Notation fixed point numbers Real Numbers We have been studying integer arithmetic up to this point. We have discovered that a standard computer can represent a finite subset of the infinite set of integers. The range is determined

More information

Chapter 3. Errors and numerical stability

Chapter 3. Errors and numerical stability Chapter 3 Errors and numerical stability 1 Representation of numbers Binary system : micro-transistor in state off 0 on 1 Smallest amount of stored data bit Object in memory chain of 1 and 0 10011000110101001111010010100010

More information

ME 261: Numerical Analysis. ME 261: Numerical Analysis

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

More information

Floating Point Considerations

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

More information

P1 Engineering Computation

P1 Engineering Computation 1EC 2001 1 / 1 P1 Engineering Computation David Murray david.murray@eng.ox.ac.uk www.robots.ox.ac.uk/ dwm/courses/1ec Hilary 2001 1EC 2001 2 / 1 Algorithms: Design, Constructs and Correctness 1EC 2001

More information

CS321. Introduction to Numerical Methods

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

More information

Bits, Words, and Integers

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

More information

(Refer Slide Time: 02:59)

(Refer Slide Time: 02:59) Numerical Methods and Programming P. B. Sunil Kumar Department of Physics Indian Institute of Technology, Madras Lecture - 7 Error propagation and stability Last class we discussed about the representation

More information

3.1 DATA REPRESENTATION (PART C)

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,

More information

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

Real Numbers finite subset real numbers floating point numbers Scientific Notation fixed point numbers Real Numbers We have been studying integer arithmetic up to this point. We have discovered that a standard computer can represent a finite subset of the infinite set of integers. The range is determined

More information

Class 5. Data Representation and Introduction to Visualization

Class 5. Data Representation and Introduction to Visualization Class 5. Data Representation and Introduction to Visualization Visualization Visualization is useful for: 1. Data entry (initial conditions). 2. Code debugging and performance analysis. 3. Interpretation

More information

Binary floating point encodings

Binary floating point encodings Week 1: Wednesday, Jan 25 Binary floating point encodings Binary floating point arithmetic is essentially scientific notation. Where in decimal scientific notation we write in floating point, we write

More information

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

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

More information

Table : IEEE Single Format ± a a 2 a 3 :::a 8 b b 2 b 3 :::b 23 If exponent bitstring a :::a 8 is Then numerical value represented is ( ) 2 = (

Table : IEEE Single Format ± a a 2 a 3 :::a 8 b b 2 b 3 :::b 23 If exponent bitstring a :::a 8 is Then numerical value represented is ( ) 2 = ( Floating Point Numbers in Java by Michael L. Overton Virtually all modern computers follow the IEEE 2 floating point standard in their representation of floating point numbers. The Java programming language

More information

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

More information

CS321 Introduction To Numerical Methods

CS321 Introduction To Numerical Methods CS3 Introduction To Numerical Methods Fuhua (Frank) Cheng Department of Computer Science University of Kentucky Lexington KY 456-46 - - Table of Contents Errors and Number Representations 3 Error Types

More information

Numbers and Computers. Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras

Numbers and Computers. Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras Numbers and Computers Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras 1 Think of a number between 1 and 15 8 9 10 11 12 13 14 15 4 5 6 7 12 13 14 15 2 3 6 7 10 11 14 15

More information

Data Representation Type of Data Representation Integers Bits Unsigned 2 s Comp Excess 7 Excess 8

Data Representation Type of Data Representation Integers Bits Unsigned 2 s Comp Excess 7 Excess 8 Data Representation At its most basic level, all digital information must reduce to 0s and 1s, which can be discussed as binary, octal, or hex data. There s no practical limit on how it can be interpreted

More information

Mathematical preliminaries and error analysis

Mathematical preliminaries and error analysis Mathematical preliminaries and error analysis Tsung-Ming Huang Department of Mathematics National Taiwan Normal University, Taiwan August 28, 2011 Outline 1 Round-off errors and computer arithmetic IEEE

More information

Introduction to numerical algorithms

Introduction to numerical algorithms Introduction to numerical algorithms Given an algebraic equation or formula, we may want to approximate the value, and while in calculus, we deal with equations or formulas that are well defined at each

More information

Data Representation and Introduction to Visualization

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

More information

2.1.1 Fixed-Point (or Integer) Arithmetic

2.1.1 Fixed-Point (or Integer) Arithmetic x = approximation to true value x error = x x, relative error = x x. x 2.1.1 Fixed-Point (or Integer) Arithmetic A base 2 (base 10) fixed-point number has a fixed number of binary (decimal) places. 1.

More information

Errors in Computation

Errors in Computation Theory of Errors Content Errors in computation Absolute Error Relative Error Roundoff Errors Truncation Errors Floating Point Numbers Normalized Floating Point Numbers Roundoff Error in Floating Point

More information

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

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

More information

Reals 1. Floating-point numbers and their properties. Pitfalls of numeric computation. Horner's method. Bisection. Newton's method.

Reals 1. Floating-point numbers and their properties. Pitfalls of numeric computation. Horner's method. Bisection. Newton's method. Reals 1 13 Reals Floating-point numbers and their properties. Pitfalls of numeric computation. Horner's method. Bisection. Newton's method. 13.1 Floating-point numbers Real numbers, those declared to be

More information

Scientific Computing: An Introductory Survey

Scientific Computing: An Introductory Survey Scientific Computing: An Introductory Survey Chapter 1 Scientific Computing Prof. Michael T. Heath Department of Computer Science University of Illinois at Urbana-Champaign Copyright c 2002. Reproduction

More information

Mark Important Points in Margin. Significant Figures. Determine which digits in a number are significant.

Mark Important Points in Margin. Significant Figures. Determine which digits in a number are significant. Knowledge/Understanding: How and why measurements are rounded. Date: How rounding and significant figures relate to precision and uncertainty. When significant figures do not apply. Skills: Determine which

More information

What Every Programmer Should Know About Floating-Point Arithmetic

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

More information

ECE331: Hardware Organization and Design

ECE331: Hardware Organization and Design ECE331: Hardware Organization and Design Lecture 10: Multiplication & Floating Point Representation Adapted from Computer Organization and Design, Patterson & Hennessy, UCB MIPS Division Two 32-bit registers

More information

Review of Calculus, cont d

Review of Calculus, cont d Jim Lambers MAT 460/560 Fall Semester 2009-10 Lecture 4 Notes These notes correspond to Sections 1.1 1.2 in the text. Review of Calculus, cont d Taylor s Theorem, cont d We conclude our discussion of Taylor

More information

Section 1.4 Mathematics on the Computer: Floating Point Arithmetic

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

More information

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

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

More information

Roundoff Errors and Computer Arithmetic

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,

More information

Classes of Real Numbers 1/2. The Real Line

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

More information

Floating Point Arithmetic

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

More information

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

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

More information

Divide: Paper & Pencil

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

More information

Variables and Data Representation

Variables and Data Representation You will recall that a computer program is a set of instructions that tell a computer how to transform a given set of input into a specific output. Any program, procedural, event driven or object oriented

More information

Floating Point Arithmetic

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

More information

The Perils of Floating Point

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

More information

EC121 Mathematical Techniques A Revision Notes

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

More information

D I G I T A L C I R C U I T S E E

D I G I T A L C I R C U I T S E E D I G I T A L C I R C U I T S E E Digital Circuits Basic Scope and Introduction This book covers theory solved examples and previous year gate question for following topics: Number system, Boolean algebra,

More information

Finite arithmetic and error analysis

Finite arithmetic and error analysis Finite arithmetic and error analysis Escuela de Ingeniería Informática de Oviedo (Dpto de Matemáticas-UniOvi) Numerical Computation Finite arithmetic and error analysis 1 / 45 Outline 1 Number representation:

More information

Introduction to Scientific Computing Lecture 1

Introduction to Scientific Computing Lecture 1 Introduction to Scientific Computing Lecture 1 Professor Hanno Rein Last updated: September 10, 2017 1 Number Representations In this lecture, we will cover two concept that are important to understand

More information

Chapter Three. Arithmetic

Chapter Three. Arithmetic Chapter Three 1 Arithmetic Where we've been: Performance (seconds, cycles, instructions) Abstractions: Instruction Set Architecture Assembly Language and Machine Language What's up ahead: Implementing

More information

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14 Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14 Scan Converting Lines, Circles and Ellipses Hello everybody, welcome again

More information

Section 0.3 The Order of Operations

Section 0.3 The Order of Operations Section 0.3 The Contents: Evaluating an Expression Grouping Symbols OPERATIONS The Distributive Property Answers Focus Exercises Let s be reminded of those operations seen thus far in the course: Operation

More information

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

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

More information

CS 101: Computer Programming and Utilization

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

More information

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

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

More information

Logic, Words, and Integers

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

More information

CS101 Lecture 04: Binary Arithmetic

CS101 Lecture 04: Binary Arithmetic CS101 Lecture 04: Binary Arithmetic Binary Number Addition Two s complement encoding Briefly: real number representation Aaron Stevens (azs@bu.edu) 25 January 2013 What You ll Learn Today Counting in binary

More information

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

Numerical computing. How computers store real numbers and the problems that result Numerical computing How computers store real numbers and the problems that result The scientific method Theory: Mathematical equations provide a description or model Experiment Inference from data Test

More information

Number Systems CHAPTER Positional Number Systems

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

More information

unused unused unused unused unused unused

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

More information

Graphics calculator instructions

Graphics calculator instructions Graphics calculator instructions Contents: A B C D E F G Basic calculations Basic functions Secondary function and alpha keys Memory Lists Statistical graphs Working with functions 10 GRAPHICS CALCULATOR

More information

15213 Recitation 2: Floating Point

15213 Recitation 2: Floating Point 15213 Recitation 2: Floating Point 1 Introduction This handout will introduce and test your knowledge of the floating point representation of real numbers, as defined by the IEEE standard. This information

More information

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS Aleksandar Milenković The LaCASA Laboratory, ECE Department, The University of Alabama in Huntsville Email: milenka@uah.edu Web:

More information

Data Representation Floating Point

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

More information

In this lesson you will learn: how to add and multiply positive binary integers how to work with signed binary numbers using two s complement how fixed and floating point numbers are used to represent

More information

Data Representation 1

Data Representation 1 1 Data Representation Outline Binary Numbers Adding Binary Numbers Negative Integers Other Operations with Binary Numbers Floating Point Numbers Character Representation Image Representation Sound Representation

More information

Number Systems and Computer Arithmetic

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

More information

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS Aleksandar Milenković The LaCASA Laboratory, ECE Department, The University of Alabama in Huntsville Email: milenka@uah.edu Web:

More information

Chapter 5. Radicals. Lesson 1: More Exponent Practice. Lesson 2: Square Root Functions. Lesson 3: Solving Radical Equations

Chapter 5. Radicals. Lesson 1: More Exponent Practice. Lesson 2: Square Root Functions. Lesson 3: Solving Radical Equations Chapter 5 Radicals Lesson 1: More Exponent Practice Lesson 2: Square Root Functions Lesson 3: Solving Radical Equations Lesson 4: Simplifying Radicals Lesson 5: Simplifying Cube Roots This assignment is

More information

Numeric Precision 101

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

More information

More Ways to Solve & Graph Quadratics The Square Root Property If x 2 = a and a R, then x = ± a

More Ways to Solve & Graph Quadratics The Square Root Property If x 2 = a and a R, then x = ± a More Ways to Solve & Graph Quadratics The Square Root Property If x 2 = a and a R, then x = ± a Example: Solve using the square root property. a) x 2 144 = 0 b) x 2 + 144 = 0 c) (x + 1) 2 = 12 Completing

More information

Math 171 Proficiency Packet on Integers

Math 171 Proficiency Packet on Integers Math 171 Proficiency Packet on Integers Section 1: Integers For many of man's purposes the set of whole numbers W = { 0, 1, 2, } is inadequate. It became necessary to invent negative numbers and extend

More information

Chapter 4. Operations on Data

Chapter 4. Operations on Data Chapter 4 Operations on Data 1 OBJECTIVES After reading this chapter, the reader should be able to: List the three categories of operations performed on data. Perform unary and binary logic operations

More information

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

More information

MACHINE LEVEL REPRESENTATION OF DATA

MACHINE LEVEL REPRESENTATION OF DATA MACHINE LEVEL REPRESENTATION OF DATA CHAPTER 2 1 Objectives Understand how integers and fractional numbers are represented in binary Explore the relationship between decimal number system and number systems

More information

Review Questions 26 CHAPTER 1. SCIENTIFIC COMPUTING

Review Questions 26 CHAPTER 1. SCIENTIFIC COMPUTING 26 CHAPTER 1. SCIENTIFIC COMPUTING amples. The IEEE floating-point standard can be found in [131]. A useful tutorial on floating-point arithmetic and the IEEE standard is [97]. Although it is no substitute

More information

Section 1.1 Definitions and Properties

Section 1.1 Definitions and Properties Section 1.1 Definitions and Properties Objectives In this section, you will learn to: To successfully complete this section, you need to understand: Abbreviate repeated addition using Exponents and Square

More information

COMP2121: Microprocessors and Interfacing. Number Systems

COMP2121: Microprocessors and Interfacing. Number Systems COMP2121: Microprocessors and Interfacing Number Systems http://www.cse.unsw.edu.au/~cs2121 Lecturer: Hui Wu Session 2, 2017 1 1 Overview Positional notation Decimal, hexadecimal, octal and binary Converting

More information

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n)

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n) Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Module 10A Lecture - 20 What is a function?

More information

Numerical Computing: An Introduction

Numerical Computing: An Introduction Numerical Computing: An Introduction Gyula Horváth Horvath@inf.u-szeged.hu Tom Verhoeff T.Verhoeff@TUE.NL University of Szeged Hungary Eindhoven University of Technology The Netherlands Numerical Computing

More information

Up next. Midterm. Today s lecture. To follow

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

More information

Data Representation Floating Point

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

More information

MA 1128: Lecture 02 1/22/2018

MA 1128: Lecture 02 1/22/2018 MA 1128: Lecture 02 1/22/2018 Exponents Scientific Notation 1 Exponents Exponents are used to indicate how many copies of a number are to be multiplied together. For example, I like to deal with the signs

More information

Module 2: Computer Arithmetic

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

More information

The type of all data used in a C++ program must be specified

The type of all data used in a C++ program must be specified The type of all data used in a 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 There are

More information

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

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

More information

COMP Overview of Tutorial #2

COMP Overview of Tutorial #2 COMP 1402 Winter 2008 Tutorial #2 Overview of Tutorial #2 Number representation basics Binary conversions Octal conversions Hexadecimal conversions Signed numbers (signed magnitude, one s and two s complement,

More information

Integers. N = sum (b i * 2 i ) where b i = 0 or 1. This is called unsigned binary representation. i = 31. i = 0

Integers. N = sum (b i * 2 i ) where b i = 0 or 1. This is called unsigned binary representation. i = 31. i = 0 Integers So far, we've seen how to convert numbers between bases. How do we represent particular kinds of data in a certain (32-bit) architecture? We will consider integers floating point characters What

More information

Chapter 2. Data Representation in Computer Systems

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

More information